Example usage for android.support.v4.graphics.drawable DrawableCompat setTintMode

List of usage examples for android.support.v4.graphics.drawable DrawableCompat setTintMode

Introduction

In this page you can find the example usage for android.support.v4.graphics.drawable DrawableCompat setTintMode.

Prototype

public static void setTintMode(Drawable drawable, Mode mode) 

Source Link

Usage

From source file:android.support.design.widget.FloatingActionButtonEclairMr1.java

@Override
void setBackgroundDrawable(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(createShapeDrawable());
    DrawableCompat.setTintList(mShapeDrawable, backgroundTint);
    if (backgroundTintMode != null) {
        DrawableCompat.setTintMode(mShapeDrawable, backgroundTintMode);
    }/*  w w  w.java  2 s .c  o  m*/

    // Now we created a mask Drawable which will be used for touch feedback.
    GradientDrawable touchFeedbackShape = createShapeDrawable();

    // 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));

    final Drawable[] layers;
    if (borderWidth > 0) {
        mBorderDrawable = createBorderDrawable(borderWidth, backgroundTint);
        layers = new Drawable[] { mBorderDrawable, mShapeDrawable, mRippleDrawable };
    } else {
        mBorderDrawable = null;
        layers = new Drawable[] { mShapeDrawable, mRippleDrawable };
    }

    mContentBackground = new LayerDrawable(layers);

    mShadowDrawable = new ShadowDrawableWrapper(mView.getResources(), mContentBackground,
            mShadowViewDelegate.getRadius(), mElevation, mElevation + mPressedTranslationZ);
    mShadowDrawable.setAddPaddingForCorners(false);
    mShadowViewDelegate.setBackgroundDrawable(mShadowDrawable);
}

From source file:android.support.design.widget.FloatingActionButtonGingerbread.java

@Override
void setBackgroundDrawable(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(createShapeDrawable());
    DrawableCompat.setTintList(mShapeDrawable, backgroundTint);
    if (backgroundTintMode != null) {
        DrawableCompat.setTintMode(mShapeDrawable, backgroundTintMode);
    }/*from   w ww . j a  va 2 s .  c o  m*/

    // Now we created a mask Drawable which will be used for touch feedback.
    GradientDrawable touchFeedbackShape = createShapeDrawable();

    // 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));

    final Drawable[] layers;
    if (borderWidth > 0) {
        mBorderDrawable = createBorderDrawable(borderWidth, backgroundTint);
        layers = new Drawable[] { mBorderDrawable, mShapeDrawable, mRippleDrawable };
    } else {
        mBorderDrawable = null;
        layers = new Drawable[] { mShapeDrawable, mRippleDrawable };
    }

    mContentBackground = new LayerDrawable(layers);

    mShadowDrawable = new ShadowDrawableWrapper(mView.getContext(), mContentBackground,
            mShadowViewDelegate.getRadius(), mElevation, mElevation + mPressedTranslationZ);
    mShadowDrawable.setAddPaddingForCorners(false);
    mShadowViewDelegate.setBackgroundDrawable(mShadowDrawable);
}

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 v a2 s  . 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:com.tevinjeffrey.njitct.ui.utils.TintImageView.java

public Drawable tintDrawable(Drawable drawable, @ColorInt int color) {
    Drawable wrappedDrawable = DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(wrappedDrawable, color);
    DrawableCompat.setTintMode(wrappedDrawable, PorterDuff.Mode.SRC_IN);
    return wrappedDrawable;
}

From source file:android.support.v7.widget.AppCompatCompoundButtonHelper.java

void applyButtonTint() {
    Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable(mView);

    if (buttonDrawable != null && (mHasButtonTint || mHasButtonTintMode)) {
        buttonDrawable = DrawableCompat.wrap(buttonDrawable);
        buttonDrawable = buttonDrawable.mutate();
        if (mHasButtonTint) {
            DrawableCompat.setTintList(buttonDrawable, mButtonTintList);
        }/*www .  ja  v  a 2 s.co m*/
        if (mHasButtonTintMode) {
            DrawableCompat.setTintMode(buttonDrawable, mButtonTintMode);
        }
        // The drawable (or one of its children) may not have been
        // stateful before applying the tint, so let's try again.
        if (buttonDrawable.isStateful()) {
            buttonDrawable.setState(mView.getDrawableState());
        }
        mView.setButtonDrawable(buttonDrawable);
    }
}

From source file:com.bilibili.magicasakura.utils.ThemeUtils.java

public static Drawable tintDrawable(Drawable drawable, ColorStateList cls, PorterDuff.Mode mode) {
    if (drawable == null)
        return null;
    Drawable wrapper = DrawableCompat.wrap(drawable.mutate());
    DrawableCompat.setTintList(wrapper, cls);
    DrawableCompat.setTintMode(drawable, mode);
    return wrapper;
}

From source file:android.support.design.widget.FloatingActionButtonEclairMr1.java

@Override
void setBackgroundTintMode(PorterDuff.Mode tintMode) {
    if (mShapeDrawable != null) {
        DrawableCompat.setTintMode(mShapeDrawable, tintMode);
    }
}

From source file:com.wanderingcan.persistentsearch.SearchMenuItem.java

/**
 * Sets the drawable for the action icon for the SearchMenuItem
 * @param icon The drawable for the action icon
 *///from  w  w w  .j  a  v a2s .co  m
public SearchMenuItem setActionIcon(Drawable icon) {
    mDefaultAction = false;
    mActionDrawable = DrawableCompat.wrap(icon);
    if (mActionTint != null) {
        DrawableCompat.setTintList(mActionDrawable, mActionTint);
    }
    if (mActionTintMode != null) {
        DrawableCompat.setTintMode(mActionDrawable, mActionTintMode);
    }
    notifyItemChanged();
    return this;
}

From source file:com.bilibili.magicasakura.widgets.AppCompatImageHelper.java

private boolean applySupportImageTint() {
    Drawable image = ((ImageView) mView).getDrawable();
    if (image != null && mImageTintInfo != null && mImageTintInfo.mHasTintList) {
        Drawable tintDrawable = image.mutate();
        tintDrawable = DrawableCompat.wrap(tintDrawable);
        if (mImageTintInfo.mHasTintList) {
            DrawableCompat.setTintList(tintDrawable, mImageTintInfo.mTintList);
        }//from ww w. j av a  2 s .  com
        if (mImageTintInfo.mHasTintMode) {
            DrawableCompat.setTintMode(tintDrawable, mImageTintInfo.mTintMode);
        }
        if (tintDrawable.isStateful()) {
            tintDrawable.setState(mView.getDrawableState());
        }
        setImageDrawable(tintDrawable);
        if (image == tintDrawable) {
            tintDrawable.invalidateSelf();
        }
        return true;
    }
    return false;
}

From source file:com.landenlabs.all_UiDemo.frag.RadioBtnFrag.java

private void addTabBar(RadioGroup tabHolder, float weight, int padding) {
    final int maxTabs = 4;
    // tabHolder.removeAllViews();

    int[][] states = new int[][] { new int[] { android.R.attr.state_checked }, new int[] {} };
    ColorStateList colorStateList = new ColorStateList(states, new int[] { 0xff00ff00, 0x80ff0000 });

    RadioGroup.LayoutParams lp = new RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT, weight);

    /*// w  w w.j a  va2  s  . co m
    ViewOutlineProvider outlineBoundary;
    if (Build.VERSION.SDK_INT >= 21) {
    outlineBoundary = new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            outline.setRect(0, 0, 200, 60); // view.getMeasuredWidth(), view.getMeasuredHeight());
        }
    };
    }
    */

    String[] pageNames = new String[] { "Home", "Map", "Hourly", "Daily" };
    int tabCnt = 0;
    for (String pageName : pageNames) {
        RadioButton button = new RadioButton(tabHolder.getContext());

        String resName = "tab_" + pageName.toLowerCase();
        int resID = getResources().getIdentifier(resName, "drawable", this.getContext().getPackageName());
        Drawable tabBtnIcon = getResources().getDrawable(resID);
        if (tabBtnIcon != null) {

            if (tabBtnIcon != null && Build.VERSION.SDK_INT >= 21) {
                tabBtnIcon.setTintMode(PorterDuff.Mode.MULTIPLY);
                tabBtnIcon.setTintList(colorStateList);
            } else {
                tabBtnIcon = DrawableCompat.wrap(tabBtnIcon);
                DrawableCompat.setTintList(tabBtnIcon.mutate(), colorStateList);
                DrawableCompat.setTintMode(tabBtnIcon.mutate(), PorterDuff.Mode.MULTIPLY);
            }

            // tabBtnIcon = tabHolder.getResources().getDrawable(android.R.drawable.btn_radio);
            if (Build.VERSION.SDK_INT >= 21) {
                // Hide standard radio button but leave ripple effect
                button.setButtonDrawable(null);
            } else {
                // Hide standard radio button
                button.setButtonDrawable(new StateListDrawable());
            }
            button.setCompoundDrawablesWithIntrinsicBounds(null, tabBtnIcon, null, null);

            /*
            // button.setBackgroundResource(R.drawable.ripple_boarderless);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                    
            button.setCompoundDrawablesWithIntrinsicBounds(null, tabBtnIcon, null, null);
            // button.setCompoundDrawablesRelativeWithIntrinsicBounds(null, tabBtnIcon, null, null);
            // tabBtnIcon.setBounds(0, 0, 50, 100); // img.getMinimumWidth(), img.getMinimumHeight());
            // button.setCompoundDrawables(null, tabBtnIcon, null, null);
            } else {
            button.setCompoundDrawablesWithIntrinsicBounds(null, tabBtnIcon, null, null);
            }
            */

            button.setBackgroundResource(R.drawable.ripple_boarderless);
            button.setPadding(padding, padding, padding, padding);
            button.setGravity(Gravity.CENTER);
            button.setTextColor(colorStateList);
            button.setText(pageName);

            tabHolder.addView(button, lp);

            if (++tabCnt == maxTabs)
                break;
        }
    }
}