List of usage examples for android.graphics.drawable Drawable mutate
public @NonNull Drawable mutate()
From source file:com.todoroo.astrid.tags.TagsControlSet.java
@Nullable @Override/*from w w w. j a va 2 s.c om*/ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); ArrayList<String> newTags; if (savedInstanceState != null) { selectedTags = savedInstanceState.getParcelableArrayList(EXTRA_SELECTED_TAGS); newTags = savedInstanceState.getStringArrayList(EXTRA_NEW_TAGS); } else { selectedTags = tagService.getTagDataForTask(taskId); newTags = newArrayList(); } allTags = tagService.getTagList(); dialogView = inflater.inflate(R.layout.control_set_tag_list, null); newTagLayout = (LinearLayout) dialogView.findViewById(R.id.newTags); tagListView = (ListView) dialogView.findViewById(R.id.existingTags); tagListView.setAdapter(new ArrayAdapter<TagData>(getActivity(), R.layout.simple_list_item_multiple_choice_themed, allTags) { @NonNull @SuppressLint("NewApi") @Override public View getView(int position, View convertView, @NonNull ViewGroup parent) { CheckedTextView view = (CheckedTextView) super.getView(position, convertView, parent); TagData tagData = allTags.get(position); ThemeColor themeColor = themeCache.getThemeColor(tagData.getColor() >= 0 ? tagData.getColor() : 19); view.setText(tagData.getName()); Drawable original = ContextCompat.getDrawable(getContext(), R.drawable.ic_label_24dp); Drawable wrapped = DrawableCompat.wrap(original.mutate()); DrawableCompat.setTint(wrapped, themeColor.getPrimaryColor()); if (atLeastJellybeanMR1()) { view.setCompoundDrawablesRelativeWithIntrinsicBounds(wrapped, null, null, null); } else { view.setCompoundDrawablesWithIntrinsicBounds(wrapped, null, null, null); } return view; } }); for (String newTag : newTags) { addTag(newTag); } addTag(""); for (TagData tag : selectedTags) { setTagSelected(tag); } refreshDisplayView(); return view; }
From source file:jp.tkgktyk.xposed.forcetouchdetector.app.util.fab.FloatingActionButtonEclairMr1.java
@Override void setBackgroundDrawable(Drawable originalBackground, ColorStateList backgroundTint, PorterDuff.Mode backgroundTintMode, int rippleColor, int borderWidth) { // Now we need to tint the original background with the tint, using // an InsetDrawable if we have a border width mShapeDrawable = DrawableCompat.wrap(originalBackground.mutate()); DrawableCompat.setTintList(mShapeDrawable, backgroundTint); if (backgroundTintMode != null) { DrawableCompat.setTintMode(mShapeDrawable, backgroundTintMode); }//from w w w. j a va 2s . com // Now we created a mask Drawable which will be used for touch feedback. // As we don't know the actual outline of mShapeDrawable, we'll just guess that it's a // circle GradientDrawable touchFeedbackShape = new GradientDrawable(); touchFeedbackShape.setShape(GradientDrawable.OVAL); touchFeedbackShape.setColor(Color.WHITE); touchFeedbackShape.setCornerRadius(mShadowViewDelegate.getRadius()); // We'll now wrap that touch feedback mask drawable with a ColorStateList. We do not need // to inset for any border here as LayerDrawable will nest the padding for us mRippleDrawable = DrawableCompat.wrap(touchFeedbackShape); DrawableCompat.setTintList(mRippleDrawable, createColorStateList(rippleColor)); DrawableCompat.setTintMode(mRippleDrawable, PorterDuff.Mode.MULTIPLY); final Drawable[] layers; if (borderWidth > 0) { mBorderDrawable = createBorderDrawable(borderWidth, backgroundTint); layers = new Drawable[] { mBorderDrawable, mShapeDrawable, mRippleDrawable }; } else { mBorderDrawable = null; layers = new Drawable[] { mShapeDrawable, mRippleDrawable }; } mShadowDrawable = new ShadowDrawableWrapper(mView.getResources(), new LayerDrawable(layers), mShadowViewDelegate.getRadius(), mElevation, mElevation + mPressedTranslationZ); mShadowDrawable.setAddPaddingForCorners(false); mShadowViewDelegate.setBackgroundDrawable(mShadowDrawable); updatePadding(); }
From source file:android.support.v7.internal.widget.TintManager.java
public Drawable getDrawable(int resId) { Drawable drawable = ContextCompat.getDrawable(mContext, resId); if (drawable != null) { drawable = drawable.mutate(); if (arrayContains(TINT_COLOR_CONTROL_STATE_LIST, resId)) { ColorStateList colorStateList = getColorStateListForKnownDrawableId(resId); PorterDuff.Mode tintMode = DEFAULT_MODE; if (resId == R.drawable.abc_switch_thumb_material) { tintMode = PorterDuff.Mode.MULTIPLY; }//from w w w . j a v a 2 s . com if (colorStateList != null) { drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTintList(drawable, colorStateList); DrawableCompat.setTintMode(drawable, tintMode); } } else if (arrayContains(CONTAINERS_WITH_TINT_CHILDREN, resId)) { drawable = mResources.getDrawable(resId); } else { tintDrawable(resId, drawable); } } return drawable; }
From source file:org.ciasaboark.tacere.activity.fragment.EventsFragment.java
private void drawStartQuicksilenceActionButton() { FloatingActionButton quickSilenceImageButton = (FloatingActionButton) rootView .findViewById(R.id.quickSilenceButton); quickSilenceImageButton.setColorNormal(context.getResources().getColor(R.color.fab_quicksilence_normal)); quickSilenceImageButton.setColorPressed(context.getResources().getColor(R.color.fab_quicksilence_pressed)); Drawable quicksilenceDrawable = context.getResources().getDrawable(R.drawable.fab_silent); quicksilenceDrawable.mutate().setColorFilter( context.getResources().getColor(R.color.fab_quicksilence_icon_tint), PorterDuff.Mode.MULTIPLY); quickSilenceImageButton.setImageDrawable(quicksilenceDrawable); }
From source file:org.ciasaboark.tacere.activity.fragment.EventsFragment.java
private void drawStopQuicksilenceActionButton() { FloatingActionButton quickSilenceImageButton = (FloatingActionButton) rootView .findViewById(R.id.quickSilenceButton); quickSilenceImageButton.setColorNormal(context.getResources().getColor(R.color.fab_stop_normal)); quickSilenceImageButton.setColorPressed(context.getResources().getColor(R.color.fab_stop_pressed)); Drawable quicksilenceDrawable = context.getResources().getDrawable(R.drawable.fab_normal); quicksilenceDrawable.mutate().setColorFilter(context.getResources().getColor(R.color.fab_stop_icon_tint), PorterDuff.Mode.MULTIPLY);/*from w w w .j a va 2s . c o m*/ quickSilenceImageButton.setImageDrawable(quicksilenceDrawable); }
From source file:com.apptentive.android.sdk.module.engagement.interaction.fragment.ApptentiveBaseFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(getMenuResourceId(), menu); // Make menu icon color same as toolbar up arrow. Both use ?colorControlNormal // By default colorControlNormal has same value as textColorPrimary defined in toolbar theme overlay int colorControlNormal = Util.getThemeColor(ApptentiveInternal.getInstance().getApptentiveToolbarTheme(), R.attr.colorControlNormal);// w ww . j a v a 2 s . co m for (int i = 0; i < menu.size(); i++) { Drawable drawable = menu.getItem(i).getIcon(); if (drawable != null) { drawable.mutate(); drawable.setColorFilter(colorControlNormal, PorterDuff.Mode.SRC_ATOP); } } attachFragmentMenuListeners(menu); super.onCreateOptionsMenu(menu, inflater); }
From source file:android.support.v17.leanback.graphics.CompositeDrawable.java
@Override public Drawable mutate() { if (!mMutated && super.mutate() == this) { mState = new CompositeState(mState, this, null); final ArrayList<ChildDrawable> children = mState.mChildren; for (int i = 0, n = children.size(); i < n; i++) { final Drawable dr = children.get(i).mDrawable; if (dr != null) { dr.mutate(); }/* ww w. j av a2 s.c o m*/ } mMutated = true; } return this; }
From source file:baasi.hackathon.sja.TalkActivity.java
private Drawable getColoredArrow() { Drawable arrowDrawable = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha); Drawable wrapped = DrawableCompat.wrap(arrowDrawable); if (arrowDrawable != null && wrapped != null) { arrowDrawable.mutate(); DrawableCompat.setTint(wrapped, Color.WHITE); }/* ww w . ja v a 2s. c o m*/ return wrapped; }
From source file:com.ez.gallery.ucrop.UCropActivity.java
@Override public boolean onCreateOptionsMenu(final Menu menu) { getMenuInflater().inflate(R.menu.ucrop_menu_activity, menu); // Change the next menu icon color to match the rest of the UI colors MenuItem next = menu.findItem(R.id.menu_crop); Drawable defaultIcon = next.getIcon(); if (defaultIcon != null) { defaultIcon.mutate(); defaultIcon.setColorFilter(mToolbarTextColor, PorterDuff.Mode.SRC_ATOP); next.setIcon(defaultIcon);/* w ww . j a v a 2 s . co m*/ } return true; }
From source file:com.landenlabs.all_UiDemo.frag.ImageScalesFrag.java
private void setScaledVector(ImageView imageView, int imageRes) { Drawable rawDrawable; if (Build.VERSION.SDK_INT >= 21) { rawDrawable = getResources().getDrawable(imageRes, getTheme()); } else {/* www . jav a2 s.com*/ rawDrawable = getResources().getDrawable(imageRes); } Drawable drawable = rawDrawable.mutate(); /* int pad = 50; drawable.setBounds(0, pad, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); */ // ScaleDrawable does nothing !!!! if (false) { ScaleDrawable scaleDrawable = new ScaleDrawable(rawDrawable, Gravity.TOP | Gravity.LEFT, 2.0f, 0.8f); scaleDrawable.setLevel(8000); drawable = scaleDrawable.getDrawable(); } if (false) { int tintColor = 0x80ff0000; ColorStateList colorStateList = new ColorStateList(new int[][] { new int[] {} }, new int[] { tintColor }); drawable = DrawableCompat.wrap(drawable.mutate()); DrawableCompat.setTintList(drawable, colorStateList); DrawableCompat.setTintMode(drawable, PorterDuff.Mode.MULTIPLY); } //imageView.setScaleType(ImageView.ScaleType.CENTER); imageView.setImageDrawable(drawable); // imageView.setImageDrawable(null); // imageView.setBackgroundDrawable(drawable); }