Java Code Examples for android.graphics.drawable.Drawable#clearColorFilter()
The following examples show how to use
android.graphics.drawable.Drawable#clearColorFilter() .
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: FolderIcon.java From LaunchEnr with GNU General Public License v3.0 | 6 votes |
private void drawPreviewItem(Canvas canvas, PreviewItemDrawingParams params) { canvas.save(Canvas.MATRIX_SAVE_FLAG); canvas.translate(params.transX, params.transY); canvas.scale(params.scale, params.scale); Drawable d = params.drawable; if (d != null) { mTempBounds.set(d.getBounds()); d.setBounds(0, 0, mIntrinsicIconSize, mIntrinsicIconSize); if (d instanceof FastBitmapDrawable) { FastBitmapDrawable fd = (FastBitmapDrawable) d; fd.drawWithBrightness(canvas, params.overlayAlpha); } else { d.setColorFilter(Color.argb((int) (params.overlayAlpha * 255), 255, 255, 255), PorterDuff.Mode.SRC_ATOP); d.draw(canvas); d.clearColorFilter(); } d.setBounds(mTempBounds); } canvas.restore(); }
Example 2
Source File: TintManager.java From MagicaSakura with Apache License 2.0 | 6 votes |
public static void tintViewDrawable(View view, Drawable drawable, TintInfo tint) { if (view == null || drawable == null) return; if (tint.mHasTintList || tint.mHasTintMode) { drawable.mutate(); if (drawable instanceof ColorDrawable) { ((ColorDrawable) drawable).setColor(ThemeUtils.replaceColor(view.getContext(), tint.mTintList.getColorForState(view.getDrawableState(), tint.mTintList.getDefaultColor()))); } else { drawable.setColorFilter(createTintFilter(view.getContext(), tint.mHasTintList ? tint.mTintList : null, tint.mHasTintMode ? tint.mTintMode : DEFAULT_MODE, view.getDrawableState())); } } else { drawable.clearColorFilter(); } if (Build.VERSION.SDK_INT <= 23) { // On Gingerbread, GradientDrawable does not invalidate itself when it's ColorFilter // has changed, so we need to force an invalidation drawable.invalidateSelf(); } }
Example 3
Source File: TintManager.java From MagicaSakura with Apache License 2.0 | 6 votes |
public static void tintViewBackground(View view, TintInfo tint) { Drawable background; if (view == null || (background = view.getBackground()) == null) return; if (tint.mHasTintList || tint.mHasTintMode) { background.mutate(); if (background instanceof ColorDrawable) { ((ColorDrawable) background).setColor(ThemeUtils.replaceColor(view.getContext(), tint.mTintList.getColorForState(view.getDrawableState(), tint.mTintList.getDefaultColor()))); } else { background.setColorFilter(createTintFilter(view.getContext(), tint.mHasTintList ? tint.mTintList : null, tint.mHasTintMode ? tint.mTintMode : DEFAULT_MODE, view.getDrawableState())); } } else { background.clearColorFilter(); } if (Build.VERSION.SDK_INT <= 23) { // On Gingerbread, GradientDrawable does not invalidate itself when it's ColorFilter // has changed, so we need to force an invalidation background.invalidateSelf(); } }
Example 4
Source File: ModStatusbarColor.java From GravityBox with Apache License 2.0 | 6 votes |
private static Drawable getColoredDrawable(Context ctx, String pkg, Icon icon) { if (icon == null) return null; Drawable d = null; if (pkg == null || PACKAGE_NAME.equals(pkg)) { final int iconId = (int) XposedHelpers.callMethod(icon, "getResId"); d = SysUiManagers.IconManager.getBasicIcon(iconId); if (d != null) { return d; } } d = icon.loadDrawable(ctx); if (d != null) { if (SysUiManagers.IconManager.isColoringEnabled()) { d = SysUiManagers.IconManager.applyColorFilter(d.mutate(), PorterDuff.Mode.SRC_IN); } else { d.clearColorFilter(); } } return d; }
Example 5
Source File: FolderIcon.java From TurboLauncher with Apache License 2.0 | 6 votes |
private void drawPreviewItem(Canvas canvas, PreviewItemDrawingParams params) { canvas.save(); canvas.translate(params.transX + mPreviewOffsetX, params.transY + mPreviewOffsetY); canvas.scale(params.scale, params.scale); Drawable d = params.drawable; if (d != null) { mOldBounds.set(d.getBounds()); d.setBounds(0, 0, mIntrinsicIconSize, mIntrinsicIconSize); d.setColorFilter(Color.argb(params.overlayAlpha, 255, 255, 255), PorterDuff.Mode.SRC_ATOP); d.draw(canvas); d.clearColorFilter(); d.setBounds(mOldBounds); } canvas.restore(); }
Example 6
Source File: MaskableImageView.java From FriendBook with GNU General Public License v3.0 | 6 votes |
private void handlerPressed(boolean pressed) { if (pressed) { Drawable drawable = getDrawable(); if (drawable != null) { // drawable.mutate().setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY); drawable.setColorFilter(Color.GRAY, PorterDuff.Mode.MULTIPLY); ViewCompat.postInvalidateOnAnimation(this); } } else { Drawable drawableUp = getDrawable(); if (drawableUp != null) { // drawableUp.mutate().clearColorFilter(); drawableUp.clearColorFilter(); ViewCompat.postInvalidateOnAnimation(this); } } }
Example 7
Source File: EmTintManager.java From AndroidTint with Apache License 2.0 | 6 votes |
public static void tintDrawable(Drawable drawable, TintInfo tint, int[] state) { if (shouldMutateBackground(drawable) && drawable.mutate() != drawable) { Log.d(TAG, "Mutated drawable is not the same instance as the input."); return; } if (tint.mHasTintList || tint.mHasTintMode) { drawable.setColorFilter(createTintFilter( tint.mHasTintList ? tint.mTintList : null, tint.mHasTintMode ? tint.mTintMode : DEFAULT_MODE, state)); } else { drawable.clearColorFilter(); } if (Build.VERSION.SDK_INT <= 10) { // On Gingerbread, GradientDrawable does not invalidate itself when it's // ColorFilter has changed, so we need to force an invalidation drawable.invalidateSelf(); } }
Example 8
Source File: DrawableHelper.java From GetApk with MIT License | 6 votes |
public static void tintDrawable(@NonNull Drawable drawable, ColorStateList tintList, PorterDuff.Mode mode, int[] state) { if (DrawableUtils.canSafelyMutateDrawable(drawable) && drawable.mutate() != drawable) { Log.e(TAG, "Mutated drawable is not the same instance as the input."); return; } if (tintList != null || mode != null) { drawable.setColorFilter(createTintFilter(tintList, mode == null ? PorterDuff.Mode.SRC_IN : mode, state)); } else { drawable.clearColorFilter(); } if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) { // Pre-v23 there is no guarantee that a state change will invoke an invalidation, // so we force it ourselves drawable.invalidateSelf(); } }
Example 9
Source File: DrawableHelper.java From GetApk with MIT License | 6 votes |
public static void tintProgressDrawable(@NonNull Drawable drawable, @ColorInt int... colors) { if (DrawableUtils.canSafelyMutateDrawable(drawable) && drawable.mutate() != drawable) { Log.e(TAG, "Mutated drawable is not the same instance as the input."); return; } if (colors == null || colors.length == 0) { drawable.clearColorFilter(); return; } if (drawable instanceof LayerDrawable) { LayerDrawable ld = (LayerDrawable) drawable; tintDrawable(ld.findDrawableByLayerId(android.R.id.background), colors[0], null); tintDrawable(ld.findDrawableByLayerId(android.R.id.secondaryProgress), colors.length > 1 ? colors[1] : colors[0], null); tintDrawable(ld.findDrawableByLayerId(android.R.id.progress), colors.length > 2 ? colors[2] : colors[0], null); } else { tintDrawable(drawable, colors[0], null); } }
Example 10
Source File: Overlay.java From android_frameworks_mapsv1 with Apache License 2.0 | 6 votes |
@OriginalApi protected static void drawAt(Canvas canvas, Drawable drawable, int x, int y, boolean shadow) { if (shadow) { drawable.setColorFilter(Color.argb(128, 0, 0, 0), PorterDuff.Mode.SRC_IN); } canvas.save(); canvas.translate(x, y); if (shadow) { canvas.skew(SHADOW_X_SKEW, 0); canvas.scale(1, SHADOW_Y_SCALE); } drawable.draw(canvas); if (shadow) { drawable.clearColorFilter(); } canvas.restore(); }
Example 11
Source File: FolderIcon.java From LB-Launcher with Apache License 2.0 | 6 votes |
private void drawPreviewItem(Canvas canvas, PreviewItemDrawingParams params) { canvas.save(); canvas.translate(params.transX + mPreviewOffsetX, params.transY + mPreviewOffsetY); canvas.scale(params.scale, params.scale); Drawable d = params.drawable; if (d != null) { mOldBounds.set(d.getBounds()); d.setBounds(0, 0, mIntrinsicIconSize, mIntrinsicIconSize); if (d instanceof FastBitmapDrawable) { FastBitmapDrawable fd = (FastBitmapDrawable) d; int oldBrightness = fd.getBrightness(); fd.setBrightness(params.overlayAlpha); d.draw(canvas); fd.setBrightness(oldBrightness); } else { d.setColorFilter(Color.argb(params.overlayAlpha, 255, 255, 255), PorterDuff.Mode.SRC_ATOP); d.draw(canvas); d.clearColorFilter(); } d.setBounds(mOldBounds); } canvas.restore(); }
Example 12
Source File: ReactTextInputManager.java From react-native-GPay with MIT License | 5 votes |
@ReactProp(name = "underlineColorAndroid", customType = "Color") public void setUnderlineColor(ReactEditText view, @Nullable Integer underlineColor) { // Drawable.mutate() can sometimes crash due to an AOSP bug: // See https://code.google.com/p/android/issues/detail?id=191754 for more info Drawable background = view.getBackground(); Drawable drawableToMutate = background.getConstantState() != null ? background.mutate() : background; if (underlineColor == null) { drawableToMutate.clearColorFilter(); } else { drawableToMutate.setColorFilter(underlineColor, PorterDuff.Mode.SRC_IN); } }
Example 13
Source File: ReactSliderManager.java From react-native-GPay with MIT License | 5 votes |
@ReactProp(name = "minimumTrackTintColor", customType = "Color") public void setMinimumTrackTintColor(ReactSlider view, Integer color) { LayerDrawable drawable = (LayerDrawable) view.getProgressDrawable().getCurrent(); Drawable progress = drawable.findDrawableByLayerId(android.R.id.progress); if (color == null) { progress.clearColorFilter(); } else { progress.setColorFilter(color, PorterDuff.Mode.SRC_IN); } }
Example 14
Source File: ReactSliderManager.java From react-native-GPay with MIT License | 5 votes |
@ReactProp(name = "maximumTrackTintColor", customType = "Color") public void setMaximumTrackTintColor(ReactSlider view, Integer color) { LayerDrawable drawable = (LayerDrawable) view.getProgressDrawable().getCurrent(); Drawable background = drawable.findDrawableByLayerId(android.R.id.background); if (color == null) { background.clearColorFilter(); } else { background.setColorFilter(color, PorterDuff.Mode.SRC_IN); } }
Example 15
Source File: NotificationHelper.java From NotificationPeekPort with Apache License 2.0 | 5 votes |
public static View.OnTouchListener getHighlightTouchListener(final int color) { return new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { Drawable drawable = ((ImageView) view).getDrawable(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: LightingColorFilter lighten = new LightingColorFilter(color, color); drawable.setColorFilter(lighten); break; case MotionEvent.ACTION_UP: drawable.clearColorFilter(); break; case MotionEvent.ACTION_MOVE: Rect rect = new Rect(); view.getLocalVisibleRect(rect); if (!rect.contains((int) event.getX(), (int) event.getY())) { drawable.clearColorFilter(); } break; case MotionEvent.ACTION_OUTSIDE: case MotionEvent.ACTION_CANCEL: drawable.clearColorFilter(); break; } return false; } }; }
Example 16
Source File: MaskableImageView.java From FriendBook with GNU General Public License v3.0 | 5 votes |
public void setEnabledMaskable(boolean enabledMaskable) { isEnabledMaskable = enabledMaskable; Drawable drawableUp = getDrawable(); if (drawableUp != null) { // drawableUp.mutate().clearColorFilter(); drawableUp.clearColorFilter(); ViewCompat.postInvalidateOnAnimation(this); } }
Example 17
Source File: BottomSheetGrid.java From BottomSheet with Apache License 2.0 | 5 votes |
public BottomSheetGrid setIcon(@DrawableRes int resId, @ColorInt int color) { Drawable icon = ContextCompat.getDrawable(getContext(), resId); if (icon != null) { icon.clearColorFilter(); icon.mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY); } iconView.setImageDrawable(icon); return this; }
Example 18
Source File: BottomSheetGrid.java From BottomSheet with Apache License 2.0 | 5 votes |
public BottomSheetGrid setIcon(Drawable resId, @ColorInt int color) { Drawable icon = resId; if (icon != null) { icon.clearColorFilter(); icon.mutate().setColorFilter(color, PorterDuff.Mode.MULTIPLY); } iconView.setImageDrawable(icon); return this; }
Example 19
Source File: ChromaDoze.java From chromadoze with GNU General Public License v3.0 | 5 votes |
private Drawable getLockIcon() { Drawable d = ContextCompat.getDrawable(this, mUiState.getLocked() ? R.drawable.action_unlock : R.drawable.action_lock); if (mUiState.getLockBusy()) { d.setColorFilter(0xFFFF4444, Mode.SRC_IN); } else { d.clearColorFilter(); } return d; }
Example 20
Source File: Utils.java From onpc with GNU General Public License v3.0 | 5 votes |
public static void setDrawableColorAttr(Context c, Drawable drawable, @AttrRes int resId) { if (drawable != null) { drawable.clearColorFilter(); drawable.setColorFilter(getThemeColorAttr(c, resId), PorterDuff.Mode.SRC_ATOP); } }