Example usage for android.view View getDrawableState

List of usage examples for android.view View getDrawableState

Introduction

In this page you can find the example usage for android.view View getDrawableState.

Prototype

public final int[] getDrawableState() 

Source Link

Document

Return an array of resource IDs of the drawable states representing the current state of the view.

Usage

From source file:com.facebook.litho.ComponentHostUtils.java

/**
 * Sets the state on a drawable if it is clickable or should duplicate its parent's state.
 *//*  ww  w  .  j  a va2s .  c  om*/
static void maybeSetDrawableState(View view, Drawable drawable, int flags, NodeInfo nodeInfo) {
    final boolean shouldSetState = (nodeInfo != null && nodeInfo.hasTouchEventHandlers())
            || MountItem.isDuplicateParentState(flags);

    if (shouldSetState && drawable.isStateful()) {
        drawable.setState(view.getDrawableState());
    }
}

From source file:android.support.v7.internal.widget.TintManager.java

public static void tintViewBackground(View view, TintInfo tint) {
    final Drawable background = view.getBackground();
    if (tint.mTintList != null) {
        tintDrawableUsingColorFilter(background,
                tint.mTintList.getColorForState(view.getDrawableState(), tint.mTintList.getDefaultColor()),
                tint.mTintMode != null ? tint.mTintMode : DEFAULT_MODE);
    } else {/*from  w w w  .j ava 2s . c  o  m*/
        background.clearColorFilter();
    }
}

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

public static void tintViewDrawable(View view, Drawable drawable, TintInfo tint) {
    if (view == null || drawable == null)
        return;//from   w w w .  j a  v a  2  s.c o m
    if (tint.mHasTintList || tint.mHasTintMode) {
        drawable.mutate();
        if (drawable instanceof ColorDrawable) {
            ((ColorDrawable) drawable).setColor(ThemeUtils.replaceColor(view.getContext(), tint.mTintList
                    .getColorForState(view.getDrawableState(), tint.mTintList.getDefaultColor())));
        } else {
            drawable.setColorFilter(
                    createTintFilter(view.getContext(), tint.mHasTintList ? tint.mTintList : null,
                            tint.mHasTintMode ? tint.mTintMode : DEFAULT_MODE, view.getDrawableState()));
        }
    } else {
        drawable.clearColorFilter();
    }

    if (Build.VERSION.SDK_INT <= 23) {
        // On Gingerbread, GradientDrawable does not invalidate itself when it's ColorFilter
        // has changed, so we need to force an invalidation
        drawable.invalidateSelf();
    }
}

From source file:poche.fm.potunes.utils.TintManager.java

public static void tintViewBackground(View view, TintInfo tint) {
    Drawable background;/*  w  w  w . j  a  v  a  2  s  .c o  m*/
    if (view == null || (background = view.getBackground()) == null)
        return;

    if (tint.mHasTintList || tint.mHasTintMode) {
        background.mutate();
        if (background instanceof ColorDrawable) {
            ((ColorDrawable) background).setColor(ThemeUtils.replaceColor(view.getContext(), tint.mTintList
                    .getColorForState(view.getDrawableState(), tint.mTintList.getDefaultColor())));
        } else {
            background.setColorFilter(
                    createTintFilter(view.getContext(), tint.mHasTintList ? tint.mTintList : null,
                            tint.mHasTintMode ? tint.mTintMode : DEFAULT_MODE, view.getDrawableState()));
        }
    } else {
        background.clearColorFilter();
    }

    if (Build.VERSION.SDK_INT <= 23) {
        // On Gingerbread, GradientDrawable does not invalidate itself when it's ColorFilter
        // has changed, so we need to force an invalidation
        background.invalidateSelf();
    }
}

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

public static void tintViewBackground(View view, com.bilibili.magicasakura.utils.TintInfo tint) {
    Drawable background;/*from w w w. ja  v  a  2 s . c  om*/
    if (view == null || (background = view.getBackground()) == null)
        return;

    if (tint.mHasTintList || tint.mHasTintMode) {
        background.mutate();
        if (background instanceof ColorDrawable) {
            ((ColorDrawable) background).setColor(ThemeUtils.replaceColor(view.getContext(), tint.mTintList
                    .getColorForState(view.getDrawableState(), tint.mTintList.getDefaultColor())));
        } else {
            background.setColorFilter(
                    createTintFilter(view.getContext(), tint.mHasTintList ? tint.mTintList : null,
                            tint.mHasTintMode ? tint.mTintMode : DEFAULT_MODE, view.getDrawableState()));
        }
    } else {
        background.clearColorFilter();
    }

    if (Build.VERSION.SDK_INT <= 23) {
        // On Gingerbread, GradientDrawable does not invalidate itself when it's ColorFilter
        // has changed, so we need to force an invalidation
        background.invalidateSelf();
    }
}

From source file:xyz.berial.textinputlayout.TintManager.java

public static void tintViewBackground(View view, TintInfo tint) {
    final Drawable background = view.getBackground();
    if (tint.mHasTintList || tint.mHasTintMode) {
        background.setColorFilter(createTintFilter(tint.mHasTintList ? tint.mTintList : null,
                tint.mHasTintMode ? tint.mTintMode : DEFAULT_MODE, view.getDrawableState()));
    } else {//from  w  w  w  . j  a  va 2s .c o  m
        background.clearColorFilter();
    }

    if (Build.VERSION.SDK_INT <= 10) {
        // On Gingerbread, GradientDrawable does not invalidate itself when it's ColorFilter
        // has changed, so we need to force an invalidation
        view.invalidate();
    }
}