List of usage examples for android.graphics PorterDuffColorFilter PorterDuffColorFilter
public PorterDuffColorFilter(@ColorInt int color, @NonNull PorterDuff.Mode mode)
From source file:com.dunrite.xpaper.utility.Utils.java
/** * Creates drawable for the wallpaper/*from w w w. j a va 2 s . c om*/ * @param context current app context * @param foreground foreground drawable * @param bgColor color of background * @param fgColor color of foreground * @param isPreview if this is for the preview or not * @return the final, constructed wallpaper */ public static Drawable constructWallpaper(Context context, Drawable foreground, int bgColor, int fgColor, boolean isPreview) { final int WIDTH = 2560; final int HEIGHT = 1440; Canvas comboImage; Bitmap cs, fg; Paint fgPaint = new Paint(); //create bitmap from foreground drawable fg = ((BitmapDrawable) foreground).getBitmap(); if (isPreview) cs = Bitmap.createBitmap(WIDTH / 2, HEIGHT / 2, Bitmap.Config.ARGB_8888); else cs = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888); comboImage = new Canvas(cs); fgPaint.setFilterBitmap(false); fgPaint.setColorFilter(new PorterDuffColorFilter(fgColor, PorterDuff.Mode.SRC_ATOP)); comboImage.drawRGB(Color.red(bgColor), Color.green(bgColor), Color.blue(bgColor)); if (isPreview) comboImage.drawBitmap(Bitmap.createScaledBitmap(fg, WIDTH / 2, HEIGHT / 2, true), 0, 0, fgPaint); else comboImage.drawBitmap(fg, 0, 0, fgPaint); return new BitmapDrawable(context.getResources(), cs); }
From source file:com.agenmate.lollipop.util.ViewUtils.java
public static void setColor(final Drawable drawable, final int color) { drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY)); }
From source file:com.googlecode.eyesfree.widget.RadialMenuView.java
public RadialMenuView(Context context, RadialMenu menu, boolean useNodeProvider) { super(context); mRootMenu = menu;//from w w w. j av a 2s . com mRootMenu.setLayoutListener(mLayoutListener); mPaint = new Paint(); mPaint.setAntiAlias(true); mHandler = new LongPressHandler(context); mHandler.setListener(mLongPressListener); final SurfaceHolder holder = getHolder(); holder.setFormat(PixelFormat.TRANSLUCENT); holder.addCallback(mSurfaceCallback); final Resources res = context.getResources(); final ViewConfiguration config = ViewConfiguration.get(context); mSingleTapRadiusSq = config.getScaledTouchSlop(); // Dimensions. mInnerRadius = res.getDimensionPixelSize(R.dimen.inner_radius); mOuterRadius = res.getDimensionPixelSize(R.dimen.outer_radius); mCornerRadius = res.getDimensionPixelSize(R.dimen.corner_radius); mExtremeRadius = res.getDimensionPixelSize(R.dimen.extreme_radius); mSpacing = res.getDimensionPixelOffset(R.dimen.spacing); mTextSize = res.getDimensionPixelSize(R.dimen.text_size); mTextShadowRadius = res.getDimensionPixelSize(R.dimen.text_shadow_radius); mShadowRadius = res.getDimensionPixelSize(R.dimen.shadow_radius); // Colors. mOuterFillColor = res.getColor(R.color.outer_fill); mTextFillColor = res.getColor(R.color.text_fill); mCornerFillColor = res.getColor(R.color.corner_fill); mCornerTextFillColor = res.getColor(R.color.corner_text_fill); mDotFillColor = res.getColor(R.color.dot_fill); mDotStrokeColor = res.getColor(R.color.dot_stroke); mSelectionColor = res.getColor(R.color.selection_fill); mSelectionTextFillColor = res.getColor(R.color.selection_text_fill); mSelectionShadowColor = res.getColor(R.color.selection_shadow); mCenterFillColor = res.getColor(R.color.center_fill); mCenterTextFillColor = res.getColor(R.color.center_text_fill); mTextShadowColor = res.getColor(R.color.text_shadow); // Gradient colors. final int gradientInnerColor = res.getColor(R.color.gradient_inner); final int gradientOuterColor = res.getColor(R.color.gradient_outer); final int[] colors = new int[] { gradientInnerColor, gradientOuterColor }; mGradientBackground = new GradientDrawable(Orientation.TOP_BOTTOM, colors); mGradientBackground.setGradientType(GradientDrawable.RADIAL_GRADIENT); mGradientBackground.setGradientRadius(mExtremeRadius * 2.0f); final int subMenuOverlayColor = res.getColor(R.color.submenu_overlay); // Lighting filters generated from colors. mSubMenuFilter = new PorterDuffColorFilter(subMenuOverlayColor, PorterDuff.Mode.SCREEN); mInnerRadiusSq = (mInnerRadius * mInnerRadius); mExtremeRadiusSq = (mExtremeRadius * mExtremeRadius); mUseNodeProvider = useNodeProvider; if (mUseNodeProvider) { mTouchExplorer = new RadialMenuHelper(this); ViewCompat.setAccessibilityDelegate(this, mTouchExplorer); } // Corner shapes only need to be invalidated and cached once. initializeCachedShapes(); }
From source file:com.bilibili.magicasakura.utils.TintManager.java
private static PorterDuffColorFilter getPorterDuffColorFilter(int color, PorterDuff.Mode mode) { // First, lets see if the cache already contains the color filter PorterDuffColorFilter filter = COLOR_FILTER_CACHE.get(color, mode); if (filter == null) { // Cache miss, so create a color filter and add it to the cache filter = new PorterDuffColorFilter(color, mode); COLOR_FILTER_CACHE.put(color, mode, filter); }/*from w w w .j a v a2s.c om*/ return filter; }
From source file:com.cnh.library.materialdrawer.view.BezelImageView.java
/** * Sets the color of the selector to be draw over the * CircularImageView. Be sure to provide some opacity. * * @param selectorColor The color (including alpha) to set for the selector overlay. *///w w w . j a v a 2 s .c om public void setSelectorColor(int selectorColor) { this.mSelectorColor = selectorColor; this.mSelectorFilter = new PorterDuffColorFilter(Color.argb(mSelectorAlpha, Color.red(mSelectorColor), Color.green(mSelectorColor), Color.blue(mSelectorColor)), PorterDuff.Mode.SRC_ATOP); this.invalidate(); }
From source file:com.crystal.CrystalBeanWallpapers.Wallpaper.java
private Bitmap getColoredBitmap(Bitmap src, int color) { int width = src.getWidth(); int height = src.getHeight(); Bitmap dest = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); Canvas canvas = new Canvas(dest); Paint paint = new Paint(); paint.setColorFilter(new PorterDuffColorFilter(color, Mode.OVERLAY)); canvas.drawBitmap(src, 0, 0, paint); return dest;//from w w w . j ava2 s .c om }
From source file:com.android.screenspeak.contextmenu.RadialMenuView.java
public RadialMenuView(Context context, RadialMenu menu, boolean useNodeProvider) { super(context); mRootMenu = menu;//ww w . ja v a2 s.co m mRootMenu.setLayoutListener(new RadialMenu.MenuLayoutListener() { @Override public void onLayoutChanged() { invalidate(); } }); mPaint = new Paint(); mPaint.setAntiAlias(true); mHandler = new LongPressHandler(context); mHandler.setListener(new LongPressHandler.LongPressListener() { @Override public void onLongPress() { onItemLongPressed(mFocusedItem); } }); final SurfaceHolder holder = getHolder(); holder.setFormat(PixelFormat.TRANSLUCENT); holder.addCallback(new SurfaceHolder.Callback() { @Override public void surfaceCreated(SurfaceHolder holder) { mHolder = holder; } @Override public void surfaceDestroyed(SurfaceHolder holder) { mHolder = null; } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { invalidate(); } }); final Resources res = context.getResources(); final ViewConfiguration config = ViewConfiguration.get(context); mSingleTapRadiusSq = config.getScaledTouchSlop(); // Dimensions. mInnerRadius = res.getDimensionPixelSize(R.dimen.inner_radius); mOuterRadius = res.getDimensionPixelSize(R.dimen.outer_radius); mCornerRadius = res.getDimensionPixelSize(R.dimen.corner_radius); mExtremeRadius = res.getDimensionPixelSize(R.dimen.extreme_radius); mSpacing = res.getDimensionPixelOffset(R.dimen.spacing); mTextSize = res.getDimensionPixelSize(R.dimen.text_size); mTextShadowRadius = res.getDimensionPixelSize(R.dimen.text_shadow_radius); mShadowRadius = res.getDimensionPixelSize(R.dimen.shadow_radius); // Colors. mOuterFillColor = res.getColor(R.color.outer_fill); mTextFillColor = res.getColor(R.color.text_fill); mCornerFillColor = res.getColor(R.color.corner_fill); mCornerTextFillColor = res.getColor(R.color.corner_text_fill); mDotFillColor = res.getColor(R.color.dot_fill); mDotStrokeColor = res.getColor(R.color.dot_stroke); mSelectionColor = res.getColor(R.color.selection_fill); mSelectionTextFillColor = res.getColor(R.color.selection_text_fill); mSelectionShadowColor = res.getColor(R.color.selection_shadow); mCenterFillColor = res.getColor(R.color.center_fill); mCenterTextFillColor = res.getColor(R.color.center_text_fill); mTextShadowColor = res.getColor(R.color.text_shadow); // Gradient colors. final int gradientInnerColor = res.getColor(R.color.gradient_inner); final int gradientOuterColor = res.getColor(R.color.gradient_outer); final int[] colors = new int[] { gradientInnerColor, gradientOuterColor }; mGradientBackground = new GradientDrawable(Orientation.TOP_BOTTOM, colors); mGradientBackground.setGradientType(GradientDrawable.RADIAL_GRADIENT); mGradientBackground.setGradientRadius(mExtremeRadius * 2.0f); final int subMenuOverlayColor = res.getColor(R.color.submenu_overlay); // Lighting filters generated from colors. mSubMenuFilter = new PorterDuffColorFilter(subMenuOverlayColor, PorterDuff.Mode.SCREEN); mInnerRadiusSq = (mInnerRadius * mInnerRadius); mExtremeRadiusSq = (mExtremeRadius * mExtremeRadius); mUseNodeProvider = useNodeProvider; if (mUseNodeProvider) { // Lazily-constructed node provider helper. ViewCompat.setAccessibilityDelegate(this, new RadialMenuHelper(this)); } // Corner shapes only need to be invalidated and cached once. initializeCachedShapes(); }
From source file:jahirfiquitiva.iconshowcase.utilities.color.ToolbarTinter.java
/** * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the * OverflowMenuButton.</p>//from w ww. ja va 2s .c o m * <p> * <p>Call this method after inflating/creating your menu in * {@link Activity#onCreateOptionsMenu(Menu)}.</p> * <p> * <p>Note: This is targeted for the native ActionBar/Toolbar, not AppCompat.</p> * * @param activity the activity to apply the menu tinting on. */ public void apply(final Activity activity) { if (menu != null) { if (forceIcons) { forceMenuIcons(menu); } for (int i = 0, size = menu.size(); i < size; i++) { MenuItem item = menu.getItem(i); colorMenuItem(item, iconsColor, iconsAlpha); if (reApplyOnChange) { View view = item.getActionView(); if (view != null) { if (item instanceof MenuItemImpl) { ((MenuItemImpl) item) .setSupportOnActionExpandListener(new SupportActionExpandListener(this)); } else { item.setOnActionExpandListener(new NativeActionExpandListener(this)); } } } } } actionBarView = findActionBar(activity); if (actionBarView == null) { Log.w(TAG, "Could not find the ActionBar"); return; } // We must wait for the view to be created to set a color filter on the drawables. actionBarView.post(new Runnable() { @Override public void run() { for (int i = 0; i < actionBarView.getChildCount(); i++) { final View v = actionBarView.getChildAt(i); //Step 1 : Changing the color of back button (or open drawer button). if (v instanceof ImageButton) { //Action Bar back button ((ImageButton) v).getDrawable() .setColorFilter(new PorterDuffColorFilter(iconsColor, PorterDuff.Mode.SRC_ATOP)); } } if (menu != null) { for (int i = 0, size = menu.size(); i < size; i++) { MenuItem menuItem = menu.getItem(i); if (isInOverflow(menuItem)) { colorMenuItem(menuItem, iconsColor, iconsAlpha); } if (menuItem.hasSubMenu()) { SubMenu subMenu = menuItem.getSubMenu(); for (int j = 0; j < subMenu.size(); j++) { colorMenuItem(subMenu.getItem(j), iconsColor, iconsAlpha); } } } if (iconsColor != null) { overflowButton = findOverflowMenuButton(activity, actionBarView); colorOverflowMenuItem(overflowButton); } } } }); }
From source file:com.paranoid.ParanoidWallpapers.Wallpaper.java
private Bitmap getColoredBitmap(Bitmap src, int color) { int width = src.getWidth(); int height = src.getHeight(); Bitmap dest = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565); Canvas canvas = new Canvas(dest); Paint paint = new Paint(); try {/* w w w . j av a 2 s .co m*/ Mode m = (Mode) Mode.class.getField("OVERLAY").get(null); paint.setColorFilter(new PorterDuffColorFilter(color, m)); } catch (Exception e) { paint = new Paint(); ColorFilter filter = new LightingColorFilter(color, 1); paint.setColorFilter(filter); } canvas.drawBitmap(src, 0, 0, paint); return dest; }
From source file:android.support.graphics.drawable.VectorDrawableCompat.java
/** * Ensures the tint filter is consistent with the current tint color and * mode./* w w w .j a va 2 s .c o m*/ */ PorterDuffColorFilter updateTintFilter(PorterDuffColorFilter tintFilter, ColorStateList tint, PorterDuff.Mode tintMode) { if (tint == null || tintMode == null) { return null; } // setMode, setColor of PorterDuffColorFilter are not public method in SDK v7. // Therefore we create a new one all the time here. Don't expect this is called often. final int color = tint.getColorForState(getState(), Color.TRANSPARENT); return new PorterDuffColorFilter(color, tintMode); }