List of usage examples for android.graphics PorterDuffColorFilter PorterDuffColorFilter
public PorterDuffColorFilter(@ColorInt int color, @NonNull PorterDuff.Mode mode)
From source file:jahirfiquitiva.iconshowcase.utilities.color.ToolbarColorizer.java
/** * Use this method to colorize toolbar icons to the desired target color * * @param toolbar toolbar view being colored * @param toolbarIconsColor the target color of toolbar icons *//* w w w.j a v a2 s . com*/ public static void colorizeToolbar(Toolbar toolbar, final int toolbarIconsColor) { final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(toolbarIconsColor, PorterDuff.Mode.SRC_IN); for (int i = 0; i < toolbar.getChildCount(); i++) { final View v = toolbar.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(colorFilter); } if (v instanceof ActionMenuView) { for (int j = 0; j < ((ActionMenuView) v).getChildCount(); j++) { //Step 2: Changing the color of any ActionMenuViews - icons that are not back button, nor text, nor overflow menu icon. //Colorize the ActionViews -> all icons that are NOT: back button | overflow menu final View innerView = ((ActionMenuView) v).getChildAt(j); if (innerView instanceof ActionMenuItemView) { for (int k = 0; k < ((ActionMenuItemView) innerView).getCompoundDrawables().length; k++) { if (((ActionMenuItemView) innerView).getCompoundDrawables()[k] != null) { final int finalK = k; //Important to set the color filter in separate thread, by adding it to the message queue //Won't work otherwise. innerView.post(new Runnable() { @Override public void run() { ((ActionMenuItemView) innerView).getCompoundDrawables()[finalK] .setColorFilter(colorFilter); } }); } } } } } } //Step 3: Changing the color of title and subtitle. toolbar.setTitleTextColor(toolbarIconsColor); toolbar.setSubtitleTextColor(toolbarIconsColor); }
From source file:codetail.graphics.drawables.DrawableReflectiveUtils.java
public static PorterDuffColorFilter setColor(PorterDuffColorFilter cf, int color, Mode mode) { if (!Android.isLollipop()) { // 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 ava2s . c o m return filter; } /** * Otherwise invoke native one */ tryInvoke(cf, "setColor", INT_ARG, color); return cf; }
From source file:me.selinali.tribbble.utils.ViewUtils.java
public static void applyColorFilter(ImageView imageView, @ColorRes int resId) { imageView.setColorFilter(new PorterDuffColorFilter(TribbbleApp.color(resId), PorterDuff.Mode.SRC_ATOP)); }
From source file:android.support.v7.app.MediaRouteExpandCollapseButton.java
public MediaRouteExpandCollapseButton(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mExpandAnimationDrawable = (AnimationDrawable) ContextCompat.getDrawable(context, R.drawable.ic_expand); mCollapseAnimationDrawable = (AnimationDrawable) ContextCompat.getDrawable(context, R.drawable.ic_collapse); ColorFilter filter = new PorterDuffColorFilter( MediaRouterThemeHelper.getControllerColor(context, defStyleAttr), PorterDuff.Mode.SRC_IN); mExpandAnimationDrawable.setColorFilter(filter); mCollapseAnimationDrawable.setColorFilter(filter); mExpandGroupDescription = context.getString(R.string.mr_controller_expand_group); mCollapseGroupDescription = context.getString(R.string.mr_controller_collapse_group); setImageDrawable(mExpandAnimationDrawable.getFrame(0)); setContentDescription(mExpandGroupDescription); super.setOnClickListener(new OnClickListener() { @Override/*from www .jav a 2 s . co m*/ public void onClick(View view) { mIsGroupExpanded = !mIsGroupExpanded; if (mIsGroupExpanded) { setImageDrawable(mExpandAnimationDrawable); mExpandAnimationDrawable.start(); setContentDescription(mCollapseGroupDescription); } else { setImageDrawable(mCollapseAnimationDrawable); mCollapseAnimationDrawable.start(); setContentDescription(mExpandGroupDescription); } if (mListener != null) { mListener.onClick(view); } } }); }
From source file:ir.besteveryeverapp.ui.Cells.DrawerActionCell.java
public void setTextAndIcon(String text, int resId) { try {//from ww w . j a va 2 s . co m textView.setText(text); Drawable d = ContextCompat.getDrawable(getContext(), resId); d.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)); textView.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null); } catch (Throwable e) { FileLog.e("tmessages", e); } }
From source file:org.opensilk.common.ui.widget.TintImageButton.java
public TintImageButton(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); if (attrs == null) return;/* w w w.j a va2 s . c om*/ final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TintImageButton, defStyleAttr, 0); if (a == null) return; if (a.hasValue(R.styleable.TintImageButton_tibTint)) { final int color = a.getColor(R.styleable.TintImageButton_tibTint, 0); if (color != 0) { // XXX From AOSP see TintManager // First, lets see if the cache already contains the color filter PorterDuffColorFilter filter = COLOR_FILTER_CACHE.get(color, TINT_MODE); if (filter == null) { // Cache miss, so create a color filter and add it to the cache filter = new PorterDuffColorFilter(color, TINT_MODE); COLOR_FILTER_CACHE.put(color, TINT_MODE, filter); } // Finally set the color filter getDrawable().setColorFilter(filter); } } a.recycle(); }
From source file:org.telegram.ui.Cells.TextColorCell.java
public void setTextAndColor(String text, int color, boolean divider) { textView.setText(text);//from w w w. j av a 2 s .c o m needDivider = divider; currentColor = color; colorDrawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY)); setWillNotDraw(!needDivider && currentColor == 0); invalidate(); }
From source file:com.hctrom.romcontrol.licenseadapter.LicenseDialogoAlerta.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ThemeSelectorUtility theme = new ThemeSelectorUtility(getActivity()); theme.onActivityCreateSetTheme(getActivity()); final View view = inflater.inflate(R.layout.license_app, container, false); titulo = (TextView) view.findViewById(R.id.textViewTitulo); licenses = (Button) view.findViewById(R.id.imageButtonCompartir); buttonBack = (ActionButton) view.findViewById(R.id.boton_flotante_back); email = (ImageView) view.findViewById(R.id.mail); apache = (TextView) view.findViewById(R.id.textViewApache); Linkify.addLinks(apache, Linkify.WEB_URLS); applyBlurMaskFilter(titulo, BlurMaskFilter.Blur.OUTER); getDialog().setCanceledOnTouchOutside(false); licenses.setOnClickListener(this); buttonBack.setOnClickListener(new View.OnClickListener() { @Override/*from w ww . ja v a2 s .co m*/ public void onClick(View v) { getDialog().cancel(); } }); email.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: { Drawable mDrawable = getActivity().getResources().getDrawable(R.drawable.mail); mDrawable.setColorFilter(new PorterDuffColorFilter( getActivity().getResources().getColor(R.color.selector), PorterDuff.Mode.MULTIPLY)); email.setAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.fab_close)); email.invalidate(); break; } case MotionEvent.ACTION_UP: { Drawable mDrawable = getActivity().getResources().getDrawable(R.drawable.mail); mDrawable.setColorFilter(new PorterDuffColorFilter( getActivity().getResources().getColor(R.color.selector), PorterDuff.Mode.MULTIPLY)); email.setAnimation(AnimationUtils.loadAnimation(getActivity(), R.anim.fab_open)); email.invalidate(); break; } } return false; } }); email.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(getActivity(), Mail.class)); } }); return view; }
From source file:com.john.main.Utils.java
/** * Ensures the tint filter is consistent with the current tint color and * mode./*from ww w. j a v a 2s. c o m*/ */ static PorterDuffColorFilter updateTintFilter(Drawable drawable, PorterDuffColorFilter tintFilter, ColorStateList tint, Mode tintMode) { if (tint == null || tintMode == null) { return null; } final int color = tint.getColorForState(drawable.getState(), Color.TRANSPARENT); if (tintFilter == null || !LOLLIPOP_PLUS) { // TODO worth caching them? return new PorterDuffColorFilter(color, tintMode); } tryInvoke(tintFilter, "setColor", INT_ARG, color); tryInvoke(tintFilter, "setMode", MODE_ARG, tintMode); return tintFilter; }
From source file:com.telly.mrvector.Utils.java
/** * Ensures the tint filter is consistent with the current tint color and * mode./*from w w w . j a v a2 s . c o m*/ */ static PorterDuffColorFilter updateTintFilter(Drawable drawable, PorterDuffColorFilter tintFilter, ColorStateList tint, PorterDuff.Mode tintMode) { if (tint == null || tintMode == null) { return null; } final int color = tint.getColorForState(drawable.getState(), Color.TRANSPARENT); if (tintFilter == null || !LOLLIPOP_PLUS) { // TODO worth caching them? return new PorterDuffColorFilter(color, tintMode); } tryInvoke(tintFilter, "setColor", INT_ARG, color); tryInvoke(tintFilter, "setMode", MODE_ARG, tintMode); return tintFilter; }