/** * Gets the icon with an applied color filter * for the correct theme. * * @param context the context to use. * @param res the drawable resource to use. * @param dark true for icon suitable for use with a dark theme, * false for icon suitable for use with a light theme. * @return a themed icon. */ @NonNull public static Bitmap getThemedBitmap(@NonNull Context context, @DrawableRes int res, boolean dark) { int color = dark ? getIconDarkThemeColor(context) : getIconLightThemeColor(context); Bitmap sourceBitmap = getBitmapFromVectorDrawable(context, res); Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap.getWidth(), sourceBitmap.getHeight(), Bitmap.Config.ARGB_8888); Paint p = new Paint(); ColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN); p.setColorFilter(filter); Canvas canvas = new Canvas(resultBitmap); canvas.drawBitmap(sourceBitmap, 0, 0, p); sourceBitmap.recycle(); return resultBitmap; }
public void applyTheme(boolean dark) { ColorFilter cf = new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP); for (Drawable d : mIcons) { if (dark) { d.setColorFilter(cf); } else { d.clearColorFilter(); } } }
@Override public void setColorFilter(ColorFilter cf) { if (cf == mColorFilter) { return; } mColorFilter = cf; applyColorFilter(); invalidate(); }
private void renderGo(Canvas canvas, ColorFilter filter, Paint paint, int i) { if (i >= 0 && i <= 8) { renderByProvince1(i); } else if (i >= 9 && i <= 19) { renderByProvince2(i); } else if (i >= 20 && i <= 29) { renderByProvince3(i); } else if (i >= 29 && i <= 33) { renderByProvince4(i); } mRenderPath.addPath(mPath, mFinalPathMatrix); paint.setStrokeJoin(Paint.Join.MITER); paint.setStrokeCap(Paint.Cap.BUTT); paint.setStrokeMiter(4.0f); paint.setColorFilter(filter); canvas.drawPath(mRenderPath, paint); // Region mRegion = mRegionList.get(i); mRegion.setPath(mRenderPath, mGlobalRegion); mRegionList.set(i, mRegion); mPath.reset(); mRenderPath.reset(); mFinalPathMatrix.setValues( new float[]{1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f} ); mFinalPathMatrix.postScale(scaleX, scaleY); }
public void setColorFilter(ColorFilter colorFilter) { if (this.mDelegateDrawable != null) { this.mDelegateDrawable.setColorFilter(colorFilter); } else { this.mAnimatedVectorState.mVectorDrawable.setColorFilter(colorFilter); } }
/** * @see android.graphics.drawable.Drawable#getColorFilter(). */ @SuppressWarnings("NewApi") public static ColorFilter getColorFilter(Drawable drawable) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return drawable.getColorFilter(); } else { return null; } }
@Override public void setColorFilter(ColorFilter colorFilter) { if (mAnimationBackend != null) { mAnimationBackend.setColorFilter(colorFilter); } mColorFilter = colorFilter; }
@Test public void testSetDrawablePropertiesDefault() { DrawableProperties properties = new DrawableProperties(); Drawable drawableTo = mock(Drawable.class); DrawableUtils.setDrawableProperties(drawableTo, properties); verify(drawableTo, never()).setAlpha(anyInt()); verify(drawableTo, never()).setColorFilter(any(ColorFilter.class)); verify(drawableTo, never()).setDither(anyBoolean()); verify(drawableTo, never()).setFilterBitmap(anyBoolean()); }
/** * Set the icon color for the Alert * * @param colorFilter ColorFilter * @return This Alerter */ public Alerter setIconColorFilter(@NonNull final ColorFilter colorFilter) { if (getAlert() != null) { getAlert().setIconColorFilter(colorFilter); } return this; }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public ColorFilter getColorFilter() { return mDrawable.getColorFilter(); }
@Override public void setColorFilter(ColorFilter colorFilter) { mRing.setColorFilter(colorFilter); }
public void setColorFilter(ColorFilter filter) { mPaint.setColorFilter(filter); invalidateSelf(); }
@Override public void setColorFilter(ColorFilter cf) { mPaint.setColorFilter(cf); }
@Override public void setColorFilter(ColorFilter cf) { mPaint.setColorFilter(cf); mCornerShadowPaint.setColorFilter(cf); mEdgeShadowPaint.setColorFilter(cf); }
/** * Applies a {@link ColorFilter} to the paint objects used to render the SVG. */ public SVGBuilder setColorFilter(ColorFilter colorFilter) { this.strokeColorFilter = this.fillColorFilter = colorFilter; return this; }
@Override public void setColorFilter(@Nullable ColorFilter cf) { }
@Override public ColorFilter getColorFilter() { return mBitmapPaint.getColorFilter(); }
@Override protected void setColorFilter(ColorFilter cf) { mPaint.setColorFilter(cf); }
public static ColorFilter setImageViewTintColor(ImageView imageView, @ColorInt int tintColor) { LightingColorFilter colorFilter = new LightingColorFilter(Color.argb(255, 0, 0, 0), tintColor); imageView.setColorFilter(colorFilter); return colorFilter; }
/** */ @Override public void setColorFilter(ColorFilter colorFilter) { PAINT.setColorFilter(colorFilter); }
/** * Do not support Color Filter */ @Override public void setColorFilter(ColorFilter cf) { }
@Override public void setColorFilter(ColorFilter cf) { if (mDrawable != null) { mDrawable.setColorFilter(cf); } }
public Drawable findMatch(ScriptC_find_region findRegion, RenderScript mRs, Bitmap image) { Rect mRoiBounds = mFindRegion.findMatch(findRegion, mRs, image); int cutOffsetX = mFindRegion.getCutOffsetX(); int cutOffsetY = mFindRegion.getCutOffsetY(); final Path path = new Path(); for (int i = 0; i < mPointsXY.length; i += 2) { if (i == 0) { path.moveTo(mPointsXY[i] - mRoiBounds.left + cutOffsetX, mPointsXY[i + 1] - mRoiBounds.top + cutOffsetY); } else { path.lineTo(mPointsXY[i] - mRoiBounds.left + cutOffsetX, mPointsXY[i + 1] - mRoiBounds.top + cutOffsetY); } } path.close(); Drawable d = new Drawable() { Paint paint = new Paint(); { paint.setStyle(Paint.Style.STROKE); } @Override public void draw(Canvas canvas) { canvas.drawPath(path, paint); } @Override public void setAlpha(int alpha) { } @Override public void setColorFilter(ColorFilter cf) { } @Override public int getOpacity() { return 0; } }; return d; }
@Override public void setColorFilter(ColorFilter cf) { mBitmapPaint.setColorFilter(cf); invalidateSelf(); }
@Override public void setColorFilter(ColorFilter colorFilter) { paint.setColorFilter(colorFilter); }
public PaintScript colorFilter(@Nullable ColorFilter filter) { paint.setColorFilter(filter); return this; }
public ColorFilter getColorFilter() { return this.mBitmapPaint.getColorFilter(); }
public static ColorFilter getColorFilter(Drawable drawable) { return IMPL.getColorFilter(drawable); }
@Override public void setColorFilter(@Nullable ColorFilter colorFilter) { mPaint.setColorFilter(colorFilter); }