androidx.core.graphics.drawable.DrawableCompat Java Examples

The following examples show how to use androidx.core.graphics.drawable.DrawableCompat. 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: ArtistAlbumsFragment.java    From odyssey with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Initialize the options menu.
 * Be sure to call {@link #setHasOptionsMenu} before.
 *
 * @param menu         The container for the custom options menu.
 * @param menuInflater The inflater to instantiate the layout.
 */
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater) {
    // Inflate the menu; this adds items to the action bar if it is present.
    menuInflater.inflate(R.menu.options_menu_artist_albums_fragment, menu);

    // get tint color
    int tintColor = ThemeUtils.getThemeColor(getContext(), R.attr.odyssey_color_text_accent);

    Drawable drawable = menu.findItem(R.id.action_add_artist_albums).getIcon();
    drawable = DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, tintColor);
    menu.findItem(R.id.action_add_artist_albums).setIcon(drawable);

    super.onCreateOptionsMenu(menu, menuInflater);
}
 
Example #2
Source File: Utils.java    From butterknife with Apache License 2.0 6 votes vote down vote up
@UiThread // Implicit synchronization for use of shared resource VALUE.
public static Drawable getTintedDrawable(Context context,
    @DrawableRes int id, @AttrRes int tintAttrId) {
  boolean attributeFound = context.getTheme().resolveAttribute(tintAttrId, VALUE, true);
  if (!attributeFound) {
    throw new Resources.NotFoundException("Required tint color attribute with name "
        + context.getResources().getResourceEntryName(tintAttrId)
        + " and attribute ID "
        + tintAttrId
        + " was not found.");
  }

  Drawable drawable = ContextCompat.getDrawable(context, id);
  drawable = DrawableCompat.wrap(drawable.mutate());
  int color = ContextCompat.getColor(context, VALUE.resourceId);
  DrawableCompat.setTint(drawable, color);
  return drawable;
}
 
Example #3
Source File: PlaylistTracksFragment.java    From odyssey with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Initialize the options menu.
 * Be sure to call {@link #setHasOptionsMenu} before.
 *
 * @param menu         The container for the custom options menu.
 * @param menuInflater The inflater to instantiate the layout.
 */
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater) {
    // Inflate the menu; this adds items to the action bar if it is present.
    menuInflater.inflate(R.menu.options_menu_playlist_tracks_fragment, menu);

    // get tint color
    int tintColor = ThemeUtils.getThemeColor(getContext(), R.attr.odyssey_color_text_accent);

    Drawable drawable = menu.findItem(R.id.action_add_playlist_tracks).getIcon();
    drawable = DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, tintColor);
    menu.findItem(R.id.action_add_playlist_tracks).setIcon(drawable);

    super.onCreateOptionsMenu(menu, menuInflater);
}
 
Example #4
Source File: IconCheckboxEntry.java    From bitmask_android with GNU General Public License v3.0 6 votes vote down vote up
public void bind(TetheringDialog.DialogListAdapter.ViewModel model) {
    this.setEnabled(model.enabled);
    textView.setText(model.text);
    textView.setEnabled(model.enabled);

    Drawable checkIcon = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_check_bold)).mutate();
    if (model.enabled) {
        DrawableCompat.setTint(checkIcon, ContextCompat.getColor(getContext(), R.color.colorSuccess));
    } else {
        DrawableCompat.setTint(checkIcon, ContextCompat.getColor(getContext(), R.color.colorDisabled));
    }

    iconView.setImageDrawable(model.image);
    checkedIcon.setImageDrawable(checkIcon);
    setChecked(model.checked);
}
 
Example #5
Source File: AppFilterActivity.java    From Daedalus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    if (Daedalus.isDarkTheme()) {
        setTheme(R.style.AppTheme_Dark_NoActionBar);
    }
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_app_filter);
    Toolbar toolbar = findViewById(R.id.toolbar_filter);
    Drawable drawable = ContextCompat.getDrawable(this, R.drawable.ic_clear);
    RecyclerView recyclerView = findViewById(R.id.recyclerView_app_filter_list);
    LinearLayoutManager manager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(manager);
    Drawable wrappedDrawable = DrawableCompat.wrap(Objects.requireNonNull(drawable));
    DrawableCompat.setTint(wrappedDrawable, Color.WHITE);
    toolbar.setNavigationIcon(drawable);
    toolbar.setNavigationOnClickListener(v -> onBackPressed());
    toolbar.setTitle(R.string.settings_app_filter);
    adapter = new RecyclerViewAdapter();
    recyclerView.setAdapter(adapter);
    new Thread(() -> adapter.updateList(getAppList())).start();
}
 
Example #6
Source File: AppBarLayout.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/**
 * Set the drawable to use for the status bar foreground drawable. Providing null will disable the
 * scrim functionality.
 *
 * <p>This scrim is only shown when we have been given a top system inset.
 *
 * @param drawable the drawable to display
 * @attr ref R.styleable#AppBarLayout_statusBarForeground
 * @see #getStatusBarForeground()
 */
public void setStatusBarForeground(@Nullable Drawable drawable) {
  if (statusBarForeground != drawable) {
    if (statusBarForeground != null) {
      statusBarForeground.setCallback(null);
    }
    statusBarForeground = drawable != null ? drawable.mutate() : null;
    if (statusBarForeground != null) {
      if (statusBarForeground.isStateful()) {
        statusBarForeground.setState(getDrawableState());
      }
      DrawableCompat.setLayoutDirection(statusBarForeground, ViewCompat.getLayoutDirection(this));
      statusBarForeground.setVisible(getVisibility() == VISIBLE, false);
      statusBarForeground.setCallback(this);
    }
    updateWillNotDraw();
    ViewCompat.postInvalidateOnAnimation(this);
  }
}
 
Example #7
Source File: MediaActionSwitchView.java    From sandriosCamera with MIT License 6 votes vote down vote up
private void initializeView() {
        photoDrawable = ContextCompat.getDrawable(context, R.drawable.ic_photo_camera_white_24dp);
        photoDrawable = DrawableCompat.wrap(photoDrawable);
        DrawableCompat.setTintList(photoDrawable.mutate(), ContextCompat.getColorStateList(context, R.drawable.switch_camera_mode_selector));

        videoDrawable = ContextCompat.getDrawable(context, R.drawable.ic_videocam_white_24dp);
        videoDrawable = DrawableCompat.wrap(videoDrawable);
        DrawableCompat.setTintList(videoDrawable.mutate(), ContextCompat.getColorStateList(context, R.drawable.switch_camera_mode_selector));

        setBackgroundResource(R.drawable.circle_frame_background_dark);
//        setBackgroundResource(R.drawable.circle_frame_background);

        setOnClickListener(new MediaActionClickListener());
        setIcons();
        padding = Utils.convertDpToPixel(padding);
        setPadding(padding, padding, padding, padding);
    }
 
Example #8
Source File: CollapsingToolbarLayout.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/**
 * Set the drawable to use for the status bar scrim from resources. Providing null will disable
 * the scrim functionality.
 *
 * <p>This scrim is only shown when we have been given a top system inset.
 *
 * @param drawable the drawable to display
 * @attr ref R.styleable#CollapsingToolbarLayout_statusBarScrim
 * @see #getStatusBarScrim()
 */
public void setStatusBarScrim(@Nullable Drawable drawable) {
  if (statusBarScrim != drawable) {
    if (statusBarScrim != null) {
      statusBarScrim.setCallback(null);
    }
    statusBarScrim = drawable != null ? drawable.mutate() : null;
    if (statusBarScrim != null) {
      if (statusBarScrim.isStateful()) {
        statusBarScrim.setState(getDrawableState());
      }
      DrawableCompat.setLayoutDirection(statusBarScrim, ViewCompat.getLayoutDirection(this));
      statusBarScrim.setVisible(getVisibility() == VISIBLE, false);
      statusBarScrim.setCallback(this);
      statusBarScrim.setAlpha(scrimAlpha);
    }
    ViewCompat.postInvalidateOnAnimation(this);
  }
}
 
Example #9
Source File: ChipDrawable.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/**
 * Calculates the chip icon's ChipDrawable-absolute bounds (top-left is <code>
 * [ChipDrawable.getBounds().left, ChipDrawable.getBounds().top]</code>).
 */
private void calculateChipIconBounds(@NonNull Rect bounds, @NonNull RectF outBounds) {
  outBounds.setEmpty();

  if (showsChipIcon() || showsCheckedIcon()) {
    float offsetFromStart = chipStartPadding + iconStartPadding;
    float chipWidth = getCurrentChipIconWidth();

    if (DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) {
      outBounds.left = bounds.left + offsetFromStart;
      outBounds.right = outBounds.left + chipWidth;
    } else {
      outBounds.right = bounds.right - offsetFromStart;
      outBounds.left = outBounds.right - chipWidth;
    }

    float chipHeight = getCurrentChipIconHeight();
    outBounds.top = bounds.exactCenterY() - chipHeight / 2f;
    outBounds.bottom = outBounds.top + chipHeight;
  }
}
 
Example #10
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 #11
Source File: ChipDrawable.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
public void setCloseIcon(@Nullable Drawable closeIcon) {
  Drawable oldCloseIcon = getCloseIcon();
  if (oldCloseIcon != closeIcon) {
    float oldCloseIconWidth = calculateCloseIconWidth();
    this.closeIcon = closeIcon != null ? DrawableCompat.wrap(closeIcon).mutate() : null;
    if (RippleUtils.USE_FRAMEWORK_RIPPLE) {
      updateFrameworkCloseIconRipple();
    }
    float newCloseIconWidth = calculateCloseIconWidth();

    unapplyChildDrawable(oldCloseIcon);
    if (showsCloseIcon()) {
      applyChildDrawable(this.closeIcon);
    }

    invalidateSelf();
    if (oldCloseIconWidth != newCloseIconWidth) {
      onSizeChange();
    }
  }
}
 
Example #12
Source File: ChipDrawable.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private void calculateCloseIconTouchBounds(@NonNull Rect bounds, @NonNull RectF outBounds) {
  outBounds.setEmpty();

  if (showsCloseIcon()) {
    float offsetFromEnd =
        chipEndPadding
            + closeIconEndPadding
            + closeIconSize
            + closeIconStartPadding
            + textEndPadding;

    if (DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) {
      outBounds.right = bounds.right;
      outBounds.left = outBounds.right - offsetFromEnd;
    } else {
      outBounds.left = bounds.left;
      outBounds.right = bounds.left + offsetFromEnd;
    }

    outBounds.top = bounds.top;
    outBounds.bottom = bounds.bottom;
  }
}
 
Example #13
Source File: ServerListFragment.java    From igniter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();
    inflater.inflate(R.menu.menu_server_list, menu);
    MenuItem qrCodeItem = menu.findItem(R.id.action_scan_qr_code).setVisible(!mBatchOperationMode);
    menu.findItem(R.id.action_import_from_file).setVisible(!mBatchOperationMode);
    menu.findItem(R.id.action_export_to_file).setVisible(!mBatchOperationMode);
    menu.findItem(R.id.action_enter_batch_mode).setVisible(!mBatchOperationMode);
    menu.findItem(R.id.action_exit_batch_operation).setVisible(mBatchOperationMode);
    menu.findItem(R.id.action_select_all_servers).setVisible(mBatchOperationMode);
    menu.findItem(R.id.action_deselect_all_servers).setVisible(mBatchOperationMode);
    menu.findItem(R.id.action_batch_delete_servers).setVisible(mBatchOperationMode);
    // Tint scan QRCode icon to white.
    if (qrCodeItem.getIcon() != null) {
        Drawable drawable = qrCodeItem.getIcon();
        Drawable wrapper = DrawableCompat.wrap(drawable);
        drawable.mutate();
        DrawableCompat.setTint(wrapper, ContextCompat.getColor(mContext, android.R.color.white));
        qrCodeItem.setIcon(drawable);
    }
}
 
Example #14
Source File: MessagesActivity.java    From android with MIT License 6 votes vote down vote up
public SwipeToDeleteCallback(ListMessageAdapter adapter) {
    super(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT);
    this.adapter = adapter;

    int backgroundColorId =
            ContextCompat.getColor(MessagesActivity.this, R.color.swipeBackground);
    int iconColorId = ContextCompat.getColor(MessagesActivity.this, R.color.swipeIcon);

    Drawable drawable =
            ContextCompat.getDrawable(MessagesActivity.this, R.drawable.ic_delete);
    icon = null;
    if (drawable != null) {
        icon = DrawableCompat.wrap(drawable.mutate());
        DrawableCompat.setTint(icon, iconColorId);
    }

    background = new ColorDrawable(backgroundColorId);
}
 
Example #15
Source File: SubtitleCollapsingToolbarLayout.java    From collapsingtoolbarlayout-subtitle with Apache License 2.0 6 votes vote down vote up
/**
 * Set the drawable to use for the status bar scrim from resources. Providing null will disable
 * the scrim functionality.
 * <p>
 * <p>This scrim is only shown when we have been given a top system inset.
 *
 * @param drawable the drawable to display
 * @attr ref R.styleable#SubtitleCollapsingToolbarLayout_statusBarScrim
 * @see #getStatusBarScrim()
 */
public void setStatusBarScrim(@Nullable Drawable drawable) {
    if (statusBarScrim != drawable) {
        if (statusBarScrim != null) {
            statusBarScrim.setCallback(null);
        }
        statusBarScrim = drawable != null ? drawable.mutate() : null;
        if (statusBarScrim != null) {
            if (statusBarScrim.isStateful()) {
                statusBarScrim.setState(getDrawableState());
            }
            DrawableCompat.setLayoutDirection(statusBarScrim, ViewCompat.getLayoutDirection(this));
            statusBarScrim.setVisible(getVisibility() == VISIBLE, false);
            statusBarScrim.setCallback(this);
            statusBarScrim.setAlpha(scrimAlpha);
        }
        ViewCompat.postInvalidateOnAnimation(this);
    }
}
 
Example #16
Source File: TextInputLayout.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private void applyIconTint(
    @NonNull CheckableImageButton iconView,
    boolean hasIconTintList,
    ColorStateList iconTintList,
    boolean hasIconTintMode,
    PorterDuff.Mode iconTintMode) {
  Drawable icon = iconView.getDrawable();
  if (icon != null && (hasIconTintList || hasIconTintMode)) {
    icon = DrawableCompat.wrap(icon).mutate();

    if (hasIconTintList) {
      DrawableCompat.setTintList(icon, iconTintList);
    }
    if (hasIconTintMode) {
      DrawableCompat.setTintMode(icon, iconTintMode);
    }
  }

  if (iconView.getDrawable() != icon) {
    iconView.setImageDrawable(icon);
  }
}
 
Example #17
Source File: ChipDrawable.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
/** Calculates the chip text's origin and alignment based on the ChipDrawable-absolute bounds. */
@NonNull
Align calculateTextOriginAndAlignment(@NonNull Rect bounds, @NonNull PointF pointF) {
  pointF.set(0, 0);
  Align align = Align.LEFT;

  if (text != null) {
    float offsetFromStart = chipStartPadding + calculateChipIconWidth() + textStartPadding;

    if (DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) {
      pointF.x = bounds.left + offsetFromStart;
      align = Align.LEFT;
    } else {
      pointF.x = bounds.right - offsetFromStart;
      align = Align.RIGHT;
    }

    pointF.y = bounds.centerY() - calculateTextCenterFromBaseline();
  }

  return align;
}
 
Example #18
Source File: FastScroller.java    From HaoReader with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Set the color of the scroll handle.
 *
 * @param color The color for the scroll handle
 */
public void setHandleColor(@ColorInt int color) {
    handleColor = color;

    if (handleImage == null) {
        Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.fastscroll_handle);

        if (drawable != null) {
            handleImage = DrawableCompat.wrap(drawable);
            handleImage.mutate();
        }
    }

    DrawableCompat.setTint(handleImage, handleColor);
    handleView.setImageDrawable(handleImage);
}
 
Example #19
Source File: BaseActivity.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressLint("RestrictedApi")
protected boolean applyMenuItemTheme(Menu menu) {
    if (customThemeWrapper != null) {
        int size = Math.min(menu.size(), 2);
        for (int i = 0; i < size; i++) {
            MenuItem item = menu.getItem(i);
            if (((MenuItemImpl) item).requestsActionButton()) {
                Drawable drawable = item.getIcon();
                if (drawable != null) {
                    DrawableCompat.setTint(drawable, customThemeWrapper.getToolbarPrimaryTextAndIconColor());
                    item.setIcon(drawable);
                }
            }
        }
    }
    return true;
}
 
Example #20
Source File: ChipDrawable.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
public void setChipIcon(@Nullable Drawable chipIcon) {
  Drawable oldChipIcon = getChipIcon();
  if (oldChipIcon != chipIcon) {
    float oldChipIconWidth = calculateChipIconWidth();
    this.chipIcon = chipIcon != null ? DrawableCompat.wrap(chipIcon).mutate() : null;
    float newChipIconWidth = calculateChipIconWidth();

    unapplyChildDrawable(oldChipIcon);
    if (showsChipIcon()) {
      applyChildDrawable(this.chipIcon);
    }

    invalidateSelf();
    if (oldChipIconWidth != newChipIconWidth) {
      onSizeChange();
    }
  }
}
 
Example #21
Source File: Utils.java    From DateTimePicker with Apache License 2.0 5 votes vote down vote up
public static Drawable tintDrawable(Context context, Drawable drawable, int tintAttr) {
    // start of FIX - tinting the drawable manually because the android:tint attribute crashes the app
    Drawable wrapped = DrawableCompat.wrap(drawable);

    TypedArray arr = context.obtainStyledAttributes(new int[]{tintAttr});
    ColorStateList tintList = Utils.getColorStateList(context, arr, 0);
    arr.recycle();

    if (tintList != null) {
        DrawableCompat.setTintList(wrapped, tintList);
    }

    return wrapped;
    // end of FIX
}
 
Example #22
Source File: TintHelper.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
@CheckResult
@Nullable
public static Drawable createTintedDrawable(@Nullable Drawable drawable, @ColorInt int color) {
    if (drawable == null) return null;
    drawable = DrawableCompat.wrap(drawable.mutate());
    DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_IN);
    DrawableCompat.setTint(drawable, color);
    return drawable;
}
 
Example #23
Source File: MenuTintDelegate.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unused")
public void setIcon(MenuItem item, @DrawableRes int icon) {
    item.setIcon(icon);
    Drawable drawable = item.getIcon();
    drawable = DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, mTextColorPrimary);
}
 
Example #24
Source File: DrawableHelper.java    From GetApk with MIT License 5 votes vote down vote up
@Nullable
public static Drawable getTintDrawable(@NonNull Context context, @DrawableRes int resId) {
    Drawable drawable = ContextCompat.getDrawable(context, resId);
    if (drawable != null) {
        if (DrawableUtils.canSafelyMutateDrawable(drawable)) {
            drawable = drawable.mutate();
        }
        drawable = DrawableCompat.wrap(drawable);
    }
    return drawable;
}
 
Example #25
Source File: ThemePreferencesManager.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("RestrictTo")
public void showChooseThemePopup(View anchor) {
  PopupMenu popupMenu = new PopupMenu(context, anchor);
  popupMenu.inflate(R.menu.mtrl_choose_theme_menu);
  if (popupMenu.getMenu() instanceof MenuBuilder) {
    MenuBuilder menuBuilder = (MenuBuilder) popupMenu.getMenu();

    menuBuilder.setOptionalIconsVisible(true);

    ColorStateList defaultColor =
        AppCompatResources.getColorStateList(
            context, R.color.material_on_surface_emphasis_medium);
    int selectedColor = MaterialColors.getColor(anchor, resourceProvider.getPrimaryColor());
    int currentThemeId = getCurrentThemeId();
    for (int i = 0; i < menuBuilder.size(); i++) {
      MenuItem item = menuBuilder.getItem(i);
      if (item.getItemId() == currentThemeId) {
        DrawableCompat.setTint(item.getIcon(), selectedColor);

        SpannableString s = new SpannableString(item.getTitle());
        s.setSpan(new ForegroundColorSpan(selectedColor), 0, s.length(), 0);
        item.setTitle(s);
      } else {
        DrawableCompat.setTintList(item.getIcon(), defaultColor);
      }
    }
  }
  popupMenu.setOnMenuItemClickListener(
      item -> {
        saveAndApplyTheme(item.getItemId());
        return false;
      });
  popupMenu.show();
}
 
Example #26
Source File: MaterialButtonHelper.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
void setSupportBackgroundTintMode(@Nullable Mode mode) {
  if (backgroundTintMode != mode) {
    backgroundTintMode = mode;
    if (getMaterialShapeDrawable() != null && backgroundTintMode != null) {
      DrawableCompat.setTintMode(getMaterialShapeDrawable(), backgroundTintMode);
    }
  }
}
 
Example #27
Source File: LayerDrawable.java    From Carbon with Apache License 2.0 5 votes vote down vote up
@Override
public void setHotspot(float x, float y) {
    final ChildDrawable[] array = mLayerState.mChildren;
    final int N = mLayerState.mNum;
    for (int i = 0; i < N; i++) {
        final Drawable dr = array[i].mDrawable;
        if (dr != null) {
            DrawableCompat.setHotspot(dr, x, y);
        }
    }
}
 
Example #28
Source File: TintableTextView.java    From materialistic with Apache License 2.0 5 votes vote down vote up
private Drawable tint(@Nullable Drawable drawable) {
    if (drawable == null) {
        return null;
    }
    drawable = DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, mTextColor);
    return drawable;
}
 
Example #29
Source File: PagerBullet.java    From PagerBullet with MIT License 5 votes vote down vote up
public static Drawable wrapTintDrawable(Drawable sourceDrawable, int color) {
    if (color != 0) {
        final Drawable wrapDrawable = DrawableCompat.wrap(sourceDrawable);
        DrawableCompat.setTint(wrapDrawable, color);
        wrapDrawable.setBounds(
                0, 0,
                wrapDrawable.getIntrinsicWidth(),
                wrapDrawable.getIntrinsicHeight()
        );
        return wrapDrawable;

    } else {
        return sourceDrawable;
    }
}
 
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);
    }
}