androidx.core.content.res.ResourcesCompat Java Examples

The following examples show how to use androidx.core.content.res.ResourcesCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NavigationMenuItemView.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
@Override
public void setIcon(@Nullable Drawable icon) {
  if (icon != null) {
    if (hasIconTintList) {
      Drawable.ConstantState state = icon.getConstantState();
      icon = DrawableCompat.wrap(state == null ? icon : state.newDrawable()).mutate();
      DrawableCompat.setTintList(icon, iconTintList);
    }
    icon.setBounds(0, 0, iconSize, iconSize);
  } else if (needsEmptyIcon) {
    if (emptyDrawable == null) {
      emptyDrawable =
          ResourcesCompat.getDrawable(
              getResources(), R.drawable.navigation_empty_icon, getContext().getTheme());
      if (emptyDrawable != null) {
        emptyDrawable.setBounds(0, 0, iconSize, iconSize);
      }
    }
    icon = emptyDrawable;
  }
  TextViewCompat.setCompoundDrawablesRelative(textView, icon, null, null, null);
}
 
Example #2
Source File: ThreadDetailFragment.java    From mimi-reader with Apache License 2.0 6 votes vote down vote up
private void showPostStatus(final String status, final String html) {
    if (getActivity() != null) {
        final View v = getActivity().findViewById(android.R.id.content);
        if (postingSnackbar != null && postingSnackbar.isShown()) {
            postingSnackbar.dismiss();
        }
        Snackbar snackbar = Snackbar.make(v, status, Snackbar.LENGTH_LONG);
        if (!TextUtils.isEmpty(html)) {
            snackbar.setAction(R.string.view,
                    view -> WebActivity
                            .start(getActivity(), html))
                    .setActionTextColor(ResourcesCompat.getColor(getResources(), R.color.md_green_400, getActivity().getTheme()));
        }

        snackbar.show();
    }
}
 
Example #3
Source File: ActionController.java    From science-journal with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the add note button for {@link TextNoteFragment} and {@link GalleryNoteFragment} when
 * a recording starts/stops.
 */
public void attachAddButton(FloatingActionButton button) {
  recordingStatus
      .takeUntil(RxView.detaches(button))
      .subscribe(
          status -> {
            Theme theme = button.getContext().getTheme();
            if (status.state.shouldShowStopButton()) {
              theme = new ContextThemeWrapper(
                  button.getContext(), R.style.RecordingProgressBarColor).getTheme();
            }
            button.setImageDrawable(
                ResourcesCompat.getDrawable(
                    button.getResources(), R.drawable.ic_send_24dp, theme));

            TypedValue iconColor = new TypedValue();
            theme.resolveAttribute(R.attr.icon_color, iconColor, true);

            TypedValue iconBackground = new TypedValue();
            theme.resolveAttribute(R.attr.icon_background, iconBackground, true);

            button.setBackgroundTintList(ColorStateList.valueOf(
                button.getResources().getColor(iconBackground.resourceId)));
            button.setRippleColor(button.getResources().getColor(iconColor.resourceId));
          });
}
 
Example #4
Source File: MainActivity.java    From user-interface-samples with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    TextView textView = findViewById(R.id.styled_text);

    // This is a simple markdown parser, where:
    // Paragraphs starting with “> ” are transformed into quotes. Quotes can't contain
    // other markdown elements
    // Text enclosed in “`” will be transformed into inline code block
    // Lines starting with “+ ” or “* ” will be transformed into bullet points. Bullet
    // points can contain nested markdown elements, like code.
    int bulletPointColor = ContextCompat.getColor(this, R.color.colorAccent);
    int codeBackgroundColor = ContextCompat.getColor(this, R.color.code_background);
    Typeface codeBlockTypeface = ResourcesCompat.getFont(this, R.font.inconsolata);

    CharSequence text = new MarkdownBuilder(bulletPointColor, codeBackgroundColor,
            codeBlockTypeface, new Parser())
            .markdownToSpans(getString(R.string.display_text));
    textView.setText(text);
}
 
Example #5
Source File: AvatarService.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
private static Bitmap getRoundLauncherIcon(Resources resources) {

        final Drawable drawable = ResourcesCompat.getDrawable(resources, R.drawable.ic_launcher, null);
        if (drawable == null) {
            return null;
        }

        if (drawable instanceof BitmapDrawable) {
            return ((BitmapDrawable) drawable).getBitmap();
        }

        Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);

        return bitmap;
    }
 
Example #6
Source File: MarkDownUtil.java    From nextcloud-notes with GNU General Public License v3.0 6 votes vote down vote up
public static Builder getMarkDownConfiguration(Context context, Boolean darkTheme) {
    return new MarkdownConfiguration.Builder(context)
            .setUnOrderListColor(ResourcesCompat.getColor(context.getResources(),
                    darkTheme ? R.color.widget_fg_dark_theme : R.color.widget_fg_default, null))
            .setHeader2RelativeSize(1.35f)
            .setHeader3RelativeSize(1.25f)
            .setHeader4RelativeSize(1.15f)
            .setHeader5RelativeSize(1.1f)
            .setHeader6RelativeSize(1.05f)
            .setHorizontalRulesHeight(2)
            .setCodeBgColor(darkTheme ? ResourcesCompat.getColor(context.getResources(), R.color.fg_default_high, null) : Color.LTGRAY)
            .setTheme(darkTheme ? new ThemeSonsOfObsidian() : new ThemeDefault())
            .setTodoColor(ResourcesCompat.getColor(context.getResources(),
                    darkTheme ? R.color.widget_fg_dark_theme : R.color.widget_fg_default, null))
            .setTodoDoneColor(ResourcesCompat.getColor(context.getResources(),
                    darkTheme ? R.color.widget_fg_dark_theme : R.color.widget_fg_default, null))
            .setLinkFontColor(ResourcesCompat.getColor(context.getResources(), R.color.defaultBrand, null))
            .setDefaultImageSize(400, 300);
}
 
Example #7
Source File: ActionData.java    From Status with Apache License 2.0 6 votes vote down vote up
@Nullable
public Drawable getIcon(Context context) {
    Resources resources = null;
    PackageInfo packageInfo = null;

    try {
        resources = context.getPackageManager().getResourcesForApplication(packageName);
        packageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException ignored) {
    }

    if (resources == null || packageInfo == null) return null;

    Resources.Theme theme = resources.newTheme();
    theme.applyStyle(packageInfo.applicationInfo.theme, false);

    try {
        return ResourcesCompat.getDrawable(resources, getIcon(), theme);
    } catch (Resources.NotFoundException e) {
        return null;
    }
}
 
Example #8
Source File: NotificationData.java    From Status with Apache License 2.0 6 votes vote down vote up
@Nullable
private Drawable getDrawable(Context context, int resource, String packageName) {
    if (packageName == null) return null;

    Resources resources = null;
    PackageInfo packageInfo = null;

    try {
        resources = context.getPackageManager().getResourcesForApplication(packageName);
        packageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException ignored) {
    }

    if (resources == null || packageInfo == null) return null;

    Resources.Theme theme = resources.newTheme();
    theme.applyStyle(packageInfo.applicationInfo.theme, false);

    try {
        return ResourcesCompat.getDrawable(resources, resource, theme);
    } catch (Resources.NotFoundException | OutOfMemoryError e) {
        return null;
    }
}
 
Example #9
Source File: BindFontTest.java    From butterknife with Apache License 2.0 5 votes vote down vote up
@Test public void typeface() {
  TargetTypeface target = new TargetTypeface();
  Typeface expected = ResourcesCompat.getFont(context, R.font.inconsolata_regular);

  Unbinder unbinder = ButterKnife.bind(target, tree);
  assertThat(target.actual).isSameAs(expected);

  unbinder.unbind();
  assertThat(target.actual).isSameAs(expected);
}
 
Example #10
Source File: IconPackResourcesProvider.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nullable
private Drawable getDrawable(@NonNull String resName) {
    try {
        return ResourcesCompat.getDrawable(
                context.getResources(),
                ResourceUtils.nonNull(getResId(context, resName, "drawable")),
                null
        );
    } catch (Exception e) {
        return null;
    }
}
 
Example #11
Source File: MarkerDemoActivity.java    From android-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Demonstrates converting a {@link Drawable} to a {@link BitmapDescriptor},
 * for use as a marker icon.
 */
private BitmapDescriptor vectorToBitmap(@DrawableRes int id, @ColorInt int color) {
    Drawable vectorDrawable = ResourcesCompat.getDrawable(getResources(), id, null);
    Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
            vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    DrawableCompat.setTint(vectorDrawable, color);
    vectorDrawable.draw(canvas);
    return BitmapDescriptorFactory.fromBitmap(bitmap);
}
 
Example #12
Source File: MarkerDemoActivity.java    From android-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Demonstrates converting a {@link Drawable} to a {@link BitmapDescriptor},
 * for use as a marker icon.
 */
private BitmapDescriptor vectorToBitmap(@DrawableRes int id, @ColorInt int color) {
    Drawable vectorDrawable = ResourcesCompat.getDrawable(getResources(), id, null);
    Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
            vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    DrawableCompat.setTint(vectorDrawable, color);
    vectorDrawable.draw(canvas);
    return BitmapDescriptorFactory.fromBitmap(bitmap);
}
 
Example #13
Source File: AlbumItemViewModel.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private static void defaultColors(Context context, ObservableInt title, ObservableInt artist,
                                  ObservableInt background) {

    Resources res = context.getResources();
    Resources.Theme theme = context.getTheme();

    title.set(ResourcesCompat.getColor(res, R.color.grid_text, theme));
    artist.set(ResourcesCompat.getColor(res, R.color.grid_detail_text, theme));
    background.set(ResourcesCompat.getColor(res, R.color.grid_background_default, theme));
}
 
Example #14
Source File: AlbumItemViewModel.java    From Jockey with Apache License 2.0 5 votes vote down vote up
public void setAlbum(Album album) {
    mAlbum = album;

    mArtistImage = new ObservableField<>();
    mTitleTextColor = new ObservableInt();
    mArtistTextColor = new ObservableInt();
    mBackgroundColor = new ObservableInt();

    defaultColors();

    if (mAlbum.getArtUri() != null) {
        int imageSize = mContext.getResources().getDimensionPixelSize(R.dimen.grid_width);

        Glide.with(mContext)
                .load(new File(mAlbum.getArtUri()))
                .placeholder(R.drawable.art_default)
                .error(R.drawable.art_default)
                .listener(new PaletteListener(mTitleTextColor, mArtistTextColor,
                        mBackgroundColor))
                .into(new ObservableTarget(imageSize, mArtistImage));
    } else {
        Drawable fallback = ResourcesCompat.getDrawable(mContext.getResources(),
                R.drawable.art_default, mContext.getTheme());

        mArtistImage.set(fallback);
    }

    notifyChange();
}
 
Example #15
Source File: CreatePlaylistDialogFragment.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private void updateDialogButtons(boolean error) {
    Button button = mDialog.getButton(AlertDialog.BUTTON_POSITIVE);
    button.setEnabled(!error);

    if (error) {
        button.setTextColor(ResourcesCompat.getColor(getResources(),
                R.color.secondary_text_disabled, getActivity().getTheme()));
    } else {
        button.setTextColor(mThemeStore.getAccentColor());
    }
}
 
Example #16
Source File: CategoryHelper.java    From nearby-android with Apache License 2.0 5 votes vote down vote up
/**
 * Return appropriate drawable base on place type
 * @param p - Place item
 * @param a - Activity
 * @return - Drawable
 */
public static Drawable getDrawableForPlace(final Place p, final Activity a){

  final String placeType = p.getType();
  final String category = CategoryHelper.getCategoryForFoodType(placeType);
  final Drawable d;
  switch (category){
    case "Pizza":
      d = ResourcesCompat.getDrawable(a.getResources(), R.drawable.ic_local_pizza_black_24dp,null);
      break;
    case "Hotel":
      d = ResourcesCompat.getDrawable(a.getResources(), R.drawable.ic_hotel_black_24dp,null);
      break;
    case "Food":
      d = ResourcesCompat.getDrawable(a.getResources(), R.drawable.ic_local_dining_black_24dp,null);
      break;
    case "Bar or Pub":
      d = ResourcesCompat.getDrawable(a.getResources(), R.drawable.ic_local_bar_black_24dp,null);
      break;
    case "Coffee Shop":
      d = ResourcesCompat.getDrawable(a.getResources(), R.drawable.ic_local_cafe_black_24dp,null);
      break;
    default:
      d = ResourcesCompat.getDrawable(a.getResources(), R.drawable.ic_place_black_24dp,null);
  }
  return d;
}
 
Example #17
Source File: RouteDirectionsFragment.java    From nearby-android with Apache License 2.0 5 votes vote down vote up
private Drawable getRoutingIcon(final DirectionManeuverType maneuver) {

      try {
        Integer id = getResourceIdForManeuverType(maneuver);
        return ResourcesCompat.getDrawable(getActivity().getResources(),id,null);
      } catch (final Resources.NotFoundException e) {
        Log.w(RouteDirectionsFragment.TAG, "No drawable found for" + maneuver.name());
        return null;
      }
    }
 
Example #18
Source File: BindFontTest.java    From butterknife with Apache License 2.0 5 votes vote down vote up
@Test public void style() {
  TargetStyle target = new TargetStyle();
  Typeface expected =
      Typeface.create(ResourcesCompat.getFont(context, R.font.inconsolata_regular), BOLD);

  Unbinder unbinder = ButterKnife.bind(target, tree);
  assertThat(target.actual).isSameAs(expected);

  unbinder.unbind();
  assertThat(target.actual).isSameAs(expected);
}
 
Example #19
Source File: ThreadListAdapter.java    From mimi-reader with Apache License 2.0 5 votes vote down vote up
public ThreadListAdapter(@NonNull final ChanThread thread) {
    this.items.addAll(thread.getPosts());
    this.boardName = thread.getBoardName();
    this.threadId = thread.getThreadId();
    final Context context = MimiApplication.getInstance().getApplicationContext();

    this.flagUrl = MimiUtil.https() + context.getString(R.string.flag_int_link);
    this.trollUrl = MimiUtil.https() + context.getString(R.string.flag_pol_link);

    if (MimiUtil.getInstance().getTheme() == MimiUtil.THEME_LIGHT) {
        defaultPostBackground = R.color.row_item_background_light;
        highlightPostBackground = R.color.post_highlight_light;
        highlightTextBackground = ResourcesCompat.getColor(context.getResources(), R.color.text_highlight_background_light, context.getTheme());
        selectedTextBackground = ResourcesCompat.getColor(context.getResources(), R.color.text_select_background_light, context.getTheme());
    } else if (MimiUtil.getInstance().getTheme() == MimiUtil.THEME_DARK) {
        defaultPostBackground = R.color.row_item_background_dark;
        highlightPostBackground = R.color.post_highlight_dark;
        highlightTextBackground = ResourcesCompat.getColor(context.getResources(), R.color.text_highlight_background_dark, context.getTheme());
        selectedTextBackground = ResourcesCompat.getColor(context.getResources(), R.color.text_select_background_dark, context.getTheme());
    } else {
        defaultPostBackground = R.color.row_item_background_black;
        highlightPostBackground = R.color.post_highlight_black;
        highlightTextBackground = ResourcesCompat.getColor(context.getResources(), R.color.text_highlight_background_black, context.getTheme());
        selectedTextBackground = ResourcesCompat.getColor(context.getResources(), R.color.text_select_background_black, context.getTheme());
    }

    Pair<VectorDrawableCompat, VectorDrawableCompat> metadataDrawables = initMetadataDrawables();
    pinDrawable = metadataDrawables.first;
    lockDrawable = metadataDrawables.second;

    Context appContext = MimiApplication.getInstance().getApplicationContext();
    imageSpoilersEnabled = MimiPrefs.imageSpoilersEnabled(appContext);
    spoilerUrl = MimiUtil.https() + appContext.getString(R.string.spoiler_link) + appContext.getString(R.string.spoiler_path);
    customSpoilerUrl = MimiUtil.https() + appContext.getString(R.string.spoiler_link) + appContext.getString(R.string.custom_spoiler_path);

    setupThread();

}
 
Example #20
Source File: PresetThemeStore.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@Override
public Drawable getLargeAppIcon() {
    Drawable icon = ResourcesCompat.getDrawableForDensity(mContext.getResources(), getIconId(),
            getLargerDisplayDensity(), mContext.getTheme());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && icon instanceof AdaptiveIconDrawable) {
        return ((AdaptiveIconDrawable) icon).getForeground();
    } else {
        return icon;
    }
}
 
Example #21
Source File: ChatsAdapter.java    From tindroid with Apache License 2.0 5 votes vote down vote up
ChatsAdapter(Context context, ClickListener clickListener) {
    super();

    mClickListener = clickListener;

    setHasStableIds(true);

    sColorOffline = ResourcesCompat.getColor(context.getResources(),
            R.color.offline, context.getTheme());
    sColorOnline = ResourcesCompat.getColor(context.getResources(),
            R.color.online, context.getTheme());
}
 
Example #22
Source File: ChronusResourceProvider.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nullable
private Drawable getDrawable(@NonNull String resName) {
    try {
        return ResourcesCompat.getDrawable(
                context.getResources(),
                ResourceUtils.nonNull(getResId(context, resName, "drawable")),
                null
        );
    } catch (Exception e) {
        return null;
    }
}
 
Example #23
Source File: BadgeDrawableTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testSavedState() {
  int testBackgroundColor =
      ResourcesCompat.getColor(
          context.getResources(), android.R.color.holo_purple, context.getTheme());
  int testBadgeTextColor =
      ResourcesCompat.getColor(context.getResources(), android.R.color.white, context.getTheme());
  BadgeDrawable badgeDrawable = BadgeDrawable.create(context);
  SavedState drawableState = badgeDrawable.getSavedState();
  badgeDrawable.setNumber(TEST_BADGE_NUMBER);
  badgeDrawable.setBadgeGravity(BadgeDrawable.TOP_START);

  badgeDrawable.setHorizontalOffset(TEST_BADGE_HORIZONTAL_OFFSET);
  badgeDrawable.setVerticalOffset(TEST_BADGE_VERTICAL_OFFSET);

  badgeDrawable.setBackgroundColor(testBackgroundColor);
  badgeDrawable.setBadgeTextColor(testBadgeTextColor);

  Parcel parcel = Parcel.obtain();
  drawableState.writeToParcel(parcel, drawableState.describeContents());
  parcel.setDataPosition(0);

  SavedState createdFromParcel = SavedState.CREATOR.createFromParcel(parcel);
  BadgeDrawable restoredBadgeDrawable =
      BadgeDrawable.createFromSavedState(context, createdFromParcel);
  assertThat(restoredBadgeDrawable.getNumber()).isEqualTo(TEST_BADGE_NUMBER);
  assertThat(restoredBadgeDrawable.getBackgroundColor()).isEqualTo(testBackgroundColor);
  assertThat(restoredBadgeDrawable.getBadgeTextColor()).isEqualTo(testBadgeTextColor);
  // Values based on the default badge style.
  assertThat(restoredBadgeDrawable.getAlpha()).isEqualTo(255);
  assertThat(restoredBadgeDrawable.getMaxCharacterCount()).isEqualTo(4);
  assertThat(restoredBadgeDrawable.getBadgeGravity()).isEqualTo(BadgeDrawable.TOP_START);
  // badge offsets
  assertThat(restoredBadgeDrawable.getHorizontalOffset()).isEqualTo(TEST_BADGE_HORIZONTAL_OFFSET);
  assertThat(restoredBadgeDrawable.getVerticalOffset()).isEqualTo(TEST_BADGE_VERTICAL_OFFSET);
}
 
Example #24
Source File: DefaultResourceProvider.java    From GeometricWeather with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Nullable
private Drawable getDrawable(@NonNull String resName) {
    try {
        return ResourcesCompat.getDrawable(
                context.getResources(),
                ResourceUtils.nonNull(getResId(context, resName, "drawable")),
                null
        );
    } catch (Exception e) {
        return null;
    }
}
 
Example #25
Source File: OtpView.java    From android-otpview-pinview with MIT License 5 votes vote down vote up
/**
 * Set the item background to a given resource. The resource should refer to
 * a Drawable object or 0 to remove the item background.
 *
 * @param resId The identifier of the resource.
 * @attr ref R.styleable#OtpView_android_itemBackground
 */
public void setItemBackgroundResources(@DrawableRes int resId) {
  if (resId != 0 && itemBackgroundResource != resId) {
    return;
  }
  itemBackground = ResourcesCompat.getDrawable(getResources(), resId, getContext().getTheme());
  setItemBackground(itemBackground);
  itemBackgroundResource = resId;
}
 
Example #26
Source File: ActionController.java    From science-journal with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the title bar for {@link ActionFragment} when a recording starts/stops.
 */
public void attachTitleBar(View titleBarView, boolean isTwoPane, OnClickListener listener,
    boolean hideDuringRecording, int titleResource, int iconResource) {
  titleBarView
      .findViewById(R.id.title_bar_close)
      .setOnClickListener(listener);
  ((TextView) titleBarView.findViewById(R.id.title_bar_text))
      .setText(titleResource);
  ImageView icon = titleBarView.findViewById(R.id.title_bar_icon);
    if (isTwoPane) {
      recordingStatus
          .takeUntil(RxView.detaches(titleBarView))
          .subscribe(
              status -> {
                Theme theme = titleBarView.getContext().getTheme();
                if (status.state.shouldShowStopButton()) {
                  theme = new ContextThemeWrapper(
                      titleBarView.getContext(), R.style.RecordingProgressBarColor).getTheme();
                  if (hideDuringRecording) {
                    titleBarView.setVisibility(View.GONE);
                  }
                } else {
                  titleBarView.setVisibility(View.VISIBLE);
                }
                icon.setImageDrawable(
                    ResourcesCompat.getDrawable(
                        titleBarView.getResources(), iconResource, theme));
              });
    } else {
      titleBarView.setVisibility(View.GONE);
    }
}
 
Example #27
Source File: FourChanCommentParser.java    From mimi-reader with Apache License 2.0 5 votes vote down vote up
public CommentParser build() {
    if (replyColor == -1) {
        replyColor = ResourcesCompat.getColor(context.getResources(), R.color.reply, context.getTheme());
    }

    if (highlightColor == -1) {
        highlightColor = ResourcesCompat.getColor(context.getResources(), R.color.reply_highlight, context.getTheme());
    }

    if (quoteColor == -1) {
        quoteColor = ResourcesCompat.getColor(context.getResources(), R.color.quote, context.getTheme());
    }

    if (linkColor == -1) {
        linkColor = ResourcesCompat.getColor(context.getResources(), R.color.link, context.getTheme());
    }

    return new FourChanCommentParser(
            replies,
            userPostIds,
            highlightedPosts,
            context,
            comment,
            boardName,
            opTag,
            youTag,
            threadId,
            replyColor,
            highlightColor,
            quoteColor,
            linkColor,
            demoMode);
}
 
Example #28
Source File: ColorUtil.java    From BLE-Indoor-Positioning with Apache License 2.0 5 votes vote down vote up
private static int[] getColors(@NonNull Context context, int[] colorResourceIds) {
    Resources resources = context.getResources();
    int[] colors = new int[colorResourceIds.length];
    for (int colorIndex = 0; colorIndex < colorResourceIds.length; colorIndex++) {
        colors[colorIndex] = ResourcesCompat.getColor(resources, colorResourceIds[colorIndex], null);
    }
    return colors;
}
 
Example #29
Source File: CheckRadioView.java    From Matisse with Apache License 2.0 5 votes vote down vote up
private void init() {
    mSelectedColor = ResourcesCompat.getColor(
            getResources(), R.color.zhihu_item_checkCircle_backgroundColor,
            getContext().getTheme());
    mUnSelectUdColor = ResourcesCompat.getColor(
            getResources(), R.color.zhihu_check_original_radio_disable,
            getContext().getTheme());
    setChecked(false);
}
 
Example #30
Source File: MainActivity.java    From lbry-android with MIT License 5 votes vote down vote up
public void showNavigationBackIcon() {
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    if (toggle != null) {
        TypedArray a = getTheme().obtainStyledAttributes(R.style.AppTheme, new int[] {R.attr.homeAsUpIndicator});
        int attributeResourceId = a.getResourceId(0, 0);
        Drawable drawable = ResourcesCompat.getDrawable(getResources(), attributeResourceId, null);
        DrawableCompat.setTint(drawable, ContextCompat.getColor(this, R.color.actionBarForeground));

        toggle.setDrawerIndicatorEnabled(false);
        toggle.setHomeAsUpIndicator(drawable);
    }
}