Java Code Examples for android.support.v4.widget.CompoundButtonCompat#getButtonDrawable()

The following examples show how to use android.support.v4.widget.CompoundButtonCompat#getButtonDrawable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppCompatCompoundButtonHelper.java    From timecat with Apache License 2.0 6 votes vote down vote up
public boolean applySupportButtonDrawableTint() {
    Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable((CompoundButton) mView);
    if (buttonDrawable != null && mCompoundButtonTintInfo != null && mCompoundButtonTintInfo.mHasTintList) {
        buttonDrawable = DrawableCompat.wrap(buttonDrawable);
        buttonDrawable = buttonDrawable.mutate();
        if (mCompoundButtonTintInfo.mHasTintList) {
            DrawableCompat.setTintList(buttonDrawable, mCompoundButtonTintInfo.mTintList);
        }
        if (mCompoundButtonTintInfo.mHasTintMode) {
            DrawableCompat.setTintMode(buttonDrawable, mCompoundButtonTintInfo.mTintMode);
        }
        // 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());
        }
        setButtonDrawable(buttonDrawable);
        return true;
    }
    return false;
}
 
Example 2
Source File: AppCompatCompoundButtonHelper.java    From MagicaSakura with Apache License 2.0 6 votes vote down vote up
public boolean applySupportButtonDrawableTint() {
    Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable(mView);
    if (buttonDrawable != null && mCompoundButtonTintInfo != null && mCompoundButtonTintInfo.mHasTintList) {
        buttonDrawable = DrawableCompat.wrap(buttonDrawable);
        buttonDrawable = buttonDrawable.mutate();
        if (mCompoundButtonTintInfo.mHasTintList) {
            DrawableCompat.setTintList(buttonDrawable, mCompoundButtonTintInfo.mTintList);
        }
        if (mCompoundButtonTintInfo.mHasTintMode) {
            DrawableCompat.setTintMode(buttonDrawable, mCompoundButtonTintInfo.mTintMode);
        }
        // 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());
        }
        setButtonDrawable(buttonDrawable);
        return true;
    }
    return false;
}
 
Example 3
Source File: FlexboxHelper.java    From Collection-Android with MIT License 5 votes vote down vote up
/**
 * Compound buttons (ex. {{@link android.widget.CheckBox}}, {@link android.widget.ToggleButton})
 * have a button drawable with minimum height and width specified for them.
 * To align the behavior with CSS Flexbox we want to respect these minimum measurement to avoid
 * these drawables from being cut off during calculation. When the compound button has a minimum
 * width or height already specified we will not make any change since we assume those were
 * voluntarily set by the user.
 *
 * @param compoundButton the compound button that need to be evaluated
 */
private void evaluateMinimumSizeForCompoundButton(CompoundButton compoundButton) {
    FlexItem flexItem = (FlexItem) compoundButton.getLayoutParams();
    int minWidth = flexItem.getMinWidth();
    int minHeight = flexItem.getMinHeight();

    Drawable drawable = CompoundButtonCompat.getButtonDrawable(compoundButton);
    int drawableMinWidth = drawable == null ? 0 : drawable.getMinimumWidth();
    int drawableMinHeight = drawable == null ? 0 : drawable.getMinimumHeight();
    flexItem.setMinWidth(minWidth == NOT_SET ? drawableMinWidth : minWidth);
    flexItem.setMinHeight(minHeight == NOT_SET ? drawableMinHeight : minHeight);
}
 
Example 4
Source File: TintRadioButton.java    From timecat with Apache License 2.0 5 votes vote down vote up
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    if (ThemeUtils.isSkipAnimatedSelector()) {
        Drawable drawable = CompoundButtonCompat.getButtonDrawable(this);
        try {
            if (ThemeUtils.getWrapperDrawable(drawable) instanceof AnimatedStateListDrawable) {
                drawable.jumpToCurrentState();
            }
        } catch (NoClassDefFoundError error) {
            error.printStackTrace();
        }
    }
}
 
Example 5
Source File: AppCompatCompoundButtonHelper.java    From timecat with Apache License 2.0 5 votes vote down vote up
public int getCompoundPaddingLeft(int superValue) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        // Before JB-MR1 the button drawable wasn't taken into account for padding. We'll
        // workaround that here
        Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable((CompoundButton) mView);
        if (buttonDrawable != null) {
            superValue += buttonDrawable.getIntrinsicWidth();
        }
    }
    return superValue;
}
 
Example 6
Source File: TintCheckBox.java    From timecat with Apache License 2.0 5 votes vote down vote up
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    if (ThemeUtils.isSkipAnimatedSelector()) {
        Drawable drawable = CompoundButtonCompat.getButtonDrawable(this);
        try {
            if (ThemeUtils.getWrapperDrawable(drawable) instanceof AnimatedStateListDrawable) {
                drawable.jumpToCurrentState();
            }
        } catch (NoClassDefFoundError error) {
            error.printStackTrace();
        }
    }
}
 
Example 7
Source File: TintRadioButton.java    From MagicaSakura with Apache License 2.0 5 votes vote down vote up
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    if (ThemeUtils.isSkipAnimatedSelector()) {
        Drawable drawable = CompoundButtonCompat.getButtonDrawable(this);
        try {
            if (ThemeUtils.getWrapperDrawable(drawable) instanceof AnimatedStateListDrawable) {
                drawable.jumpToCurrentState();
            }
        } catch (NoClassDefFoundError error) {
            error.printStackTrace();
        }
    }
}
 
Example 8
Source File: AppCompatCompoundButtonHelper.java    From MagicaSakura with Apache License 2.0 5 votes vote down vote up
public int getCompoundPaddingLeft(int superValue) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        // Before JB-MR1 the button drawable wasn't taken into account for padding. We'll
        // workaround that here
        Drawable buttonDrawable = CompoundButtonCompat.getButtonDrawable(mView);
        if (buttonDrawable != null) {
            superValue += buttonDrawable.getIntrinsicWidth();
        }
    }
    return superValue;
}
 
Example 9
Source File: TintCheckBox.java    From MagicaSakura with Apache License 2.0 5 votes vote down vote up
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    if (ThemeUtils.isSkipAnimatedSelector()) {
        Drawable drawable = CompoundButtonCompat.getButtonDrawable(this);
        try {
            if (ThemeUtils.getWrapperDrawable(drawable) instanceof AnimatedStateListDrawable) {
                drawable.jumpToCurrentState();
            }
        } catch (NoClassDefFoundError error) {
            error.printStackTrace();
        }
    }
}
 
Example 10
Source File: TintSwitchCompat.java    From MagicaSakura with Apache License 2.0 5 votes vote down vote up
@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    if (ThemeUtils.isSkipAnimatedSelector()) {
        Drawable drawable = CompoundButtonCompat.getButtonDrawable(this);
        try {
            if (ThemeUtils.getWrapperDrawable(drawable) instanceof AnimatedStateListDrawable) {
                drawable.jumpToCurrentState();
            }
        } catch (NoClassDefFoundError error) {
            error.printStackTrace();
        }
    }
}