androidx.appcompat.widget.AppCompatDrawableManager Java Examples
The following examples show how to use
androidx.appcompat.widget.AppCompatDrawableManager.
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: FloatingActionButton.java From material-components-android with Apache License 2.0 | 6 votes |
private void onApplySupportImageTint() { Drawable drawable = getDrawable(); if (drawable == null) { return; } if (imageTint == null) { DrawableCompat.clearColorFilter(drawable); return; } int color = imageTint.getColorForState(getDrawableState(), Color.TRANSPARENT); Mode mode = imageMode; if (mode == null) { mode = Mode.SRC_IN; } drawable .mutate() .setColorFilter(AppCompatDrawableManager.getPorterDuffColorFilter(color, mode)); }
Example #2
Source File: DrawableUtils.java From candybar with Apache License 2.0 | 5 votes |
public static Drawable getDrawable(Context context, int res) { try { Drawable drawable = AppCompatDrawableManager.get().getDrawable(context, res); return drawable.mutate(); } catch (OutOfMemoryError e) { return null; } }
Example #3
Source File: ProfileManagerActivity.java From ShadowsocksRR with Apache License 2.0 | 5 votes |
@SuppressLint("RestrictedApi") public void initFab() { menu = (FloatingActionMenu) findViewById(R.id.menu); menu.setClosedOnTouchOutside(true); AppCompatDrawableManager dm = AppCompatDrawableManager.get(); FloatingActionButton manualAddFAB = (FloatingActionButton) findViewById(R.id.fab_manual_add); manualAddFAB.setImageDrawable(dm.getDrawable(this, R.drawable.ic_content_create)); manualAddFAB.setOnClickListener(this); final FloatingActionButton qrcodeAddFAB = (FloatingActionButton) findViewById(R.id.fab_qrcode_add); qrcodeAddFAB.setImageDrawable(dm.getDrawable(this, R.drawable.ic_image_camera_alt)); qrcodeAddFAB.setOnClickListener(this); FloatingActionButton nfcAddFAB = (FloatingActionButton) findViewById(R.id.fab_nfc_add); nfcAddFAB.setImageDrawable(dm.getDrawable(this, R.drawable.ic_device_nfc)); nfcAddFAB.setOnClickListener(this); FloatingActionButton importAddFAB = (FloatingActionButton) findViewById(R.id.fab_import_add); importAddFAB.setImageDrawable(dm.getDrawable(this, R.drawable.ic_content_paste)); importAddFAB.setOnClickListener(this); FloatingActionButton ssrsubAddFAB = (FloatingActionButton) findViewById(R.id.fab_ssr_sub); ssrsubAddFAB.setImageDrawable(dm.getDrawable(this, R.drawable.ic_rss)); ssrsubAddFAB.setOnClickListener(this); menu.setOnMenuToggleListener(new FloatingActionMenu.OnMenuToggleListener() { @Override public void onMenuToggle(boolean opened) { if (opened) { int visible = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA) ? View.VISIBLE : View.GONE; qrcodeAddFAB.setVisibility(visible); } } }); }
Example #4
Source File: ProfileManagerActivity.java From Maying with Apache License 2.0 | 5 votes |
@SuppressLint("RestrictedApi") public void initFab() { menu = findViewById(R.id.menu); menu.setClosedOnTouchOutside(true); AppCompatDrawableManager dm = AppCompatDrawableManager.get(); FloatingActionButton manualAddFAB = findViewById(R.id.fab_manual_add); manualAddFAB.setImageDrawable(dm.getDrawable(this, R.drawable.ic_content_create)); manualAddFAB.setOnClickListener(this); final FloatingActionButton qrcodeAddFAB = findViewById(R.id.fab_qrcode_add); qrcodeAddFAB.setImageDrawable(dm.getDrawable(this, R.drawable.ic_image_camera_alt)); qrcodeAddFAB.setOnClickListener(this); FloatingActionButton nfcAddFAB = findViewById(R.id.fab_nfc_add); nfcAddFAB.setImageDrawable(dm.getDrawable(this, R.drawable.ic_device_nfc)); nfcAddFAB.setOnClickListener(this); FloatingActionButton importAddFAB = findViewById(R.id.fab_import_add); importAddFAB.setImageDrawable(dm.getDrawable(this, R.drawable.ic_content_paste)); importAddFAB.setOnClickListener(this); FloatingActionButton ssrsubAddFAB = findViewById(R.id.fab_ssr_sub); ssrsubAddFAB.setImageDrawable(dm.getDrawable(this, R.drawable.ic_rss)); ssrsubAddFAB.setOnClickListener(this); menu.setOnMenuToggleListener(opened -> { if (opened) { int visible = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA) ? View.VISIBLE : View.GONE; qrcodeAddFAB.setVisibility(visible); } }); }
Example #5
Source File: DrawableHelper.java From GetApk with MIT License | 5 votes |
public static void tintDrawable(@NonNull Drawable drawable, @ColorInt int color, PorterDuff.Mode mode) { if (DrawableUtils.canSafelyMutateDrawable(drawable) && drawable.mutate() != drawable) { Log.e(TAG, "Mutated drawable is not the same instance as the input."); return; } drawable.setColorFilter(AppCompatDrawableManager.getPorterDuffColorFilter(color, mode == null ? PorterDuff.Mode.SRC_IN : mode)); }
Example #6
Source File: DrawableHelper.java From GetApk with MIT License | 5 votes |
public static Drawable tintDrawable(@NonNull Context context, @NonNull Drawable drawable, int colorAttr, int alpha, PorterDuff.Mode tintMode) { if (DrawableUtils.canSafelyMutateDrawable(drawable)) { drawable = drawable.mutate(); } final int color = getThemeAttrColor(context, colorAttr); drawable.setColorFilter(AppCompatDrawableManager.getPorterDuffColorFilter(color, tintMode)); if (alpha != -1) { drawable.setAlpha(alpha); } return drawable; }
Example #7
Source File: DrawableHelper.java From GetApk with MIT License | 5 votes |
private static PorterDuffColorFilter createTintFilter(ColorStateList tint, PorterDuff.Mode tintMode, final int[] state) { if (tint == null || tintMode == null) { return null; } final int color = tint.getColorForState(state, Color.TRANSPARENT); return AppCompatDrawableManager.getPorterDuffColorFilter(color, tintMode); }
Example #8
Source File: TextInputLayout.java From material-components-android with Apache License 2.0 | 5 votes |
void updateEditTextBackground() { // Only update the color filter for the legacy text field, since we can directly change the // Paint colors of the MaterialShapeDrawable box background without having to use color filters. if (editText == null || boxBackgroundMode != BOX_BACKGROUND_NONE) { return; } Drawable editTextBackground = editText.getBackground(); if (editTextBackground == null) { return; } if (androidx.appcompat.widget.DrawableUtils.canSafelyMutateDrawable(editTextBackground)) { editTextBackground = editTextBackground.mutate(); } if (indicatorViewController.errorShouldBeShown()) { // Set a color filter for the error color editTextBackground.setColorFilter( AppCompatDrawableManager.getPorterDuffColorFilter( indicatorViewController.getErrorViewCurrentTextColor(), PorterDuff.Mode.SRC_IN)); } else if (counterOverflowed && counterView != null) { // Set a color filter of the counter color editTextBackground.setColorFilter( AppCompatDrawableManager.getPorterDuffColorFilter( counterView.getCurrentTextColor(), PorterDuff.Mode.SRC_IN)); } else { // Else reset the color filter and refresh the drawable state so that the // normal tint is used DrawableCompat.clearColorFilter(editTextBackground); editText.refreshDrawableState(); } }
Example #9
Source File: FastScroll.java From RecyclerExt with Apache License 2.0 | 5 votes |
/** * A utility method to retrieve a drawable that correctly abides by the * theme in Lollipop (API 23) + * * @param resourceId The resource id for the drawable * @return The drawable associated with {@code resourceId} */ @Nullable @SuppressLint("RestrictedApi") protected Drawable getDrawable(@DrawableRes int resourceId) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return getResources().getDrawable(resourceId, getContext().getTheme()); } return AppCompatDrawableManager.get().getDrawable(getContext(), resourceId); }
Example #10
Source File: FastScroll.java From RecyclerExt with Apache License 2.0 | 5 votes |
/** * Retrieves the specified image drawable in a manner that will correctly * wrap VectorDrawables on platforms that don't natively support them * * @param typedArray The TypedArray containing the attributes for the view * @param index The index in the {@code typedArray} for the drawable */ @Nullable @SuppressLint("RestrictedApi") protected Drawable getDrawable(@NonNull TypedArray typedArray, int index) { int imageResId = typedArray.getResourceId(index, 0); if (imageResId == 0) { return null; } return AppCompatDrawableManager.get().getDrawable(getContext(), imageResId); }