android.graphics.drawable.AnimatedStateListDrawable Java Examples

The following examples show how to use android.graphics.drawable.AnimatedStateListDrawable. 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: AnimationHelper.java    From ListItemView with Apache License 2.0 6 votes vote down vote up
public void setupRadioButton(ListItemView listItemView) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        AnimatedStateListDrawable asl = new AnimatedStateListDrawable();
        asl.addState(
                new int[]{android.R.attr.state_checked},
                AppCompatResources.getDrawable(mContext, R.drawable.vd_radiobutton_checked),
                R.id.checked);
        asl.addState(
                new int[0],
                AppCompatResources.getDrawable(mContext, R.drawable.vd_radiobutton_unchecked),
                R.id.unchecked);
        asl.addTransition(
                R.id.unchecked,
                R.id.checked,
                AnimatedVectorDrawableCompat.create(mContext, R.drawable.avd_radiobutton_unchecked_to_checked),
                false);
        asl.addTransition(
                R.id.checked,
                R.id.unchecked,
                AnimatedVectorDrawableCompat.create(mContext, R.drawable.avd_radiobutton_checked_to_unchecked),
                false);
        listItemView.setIconDrawable(asl);
    } else {
        listItemView.setIconResId(R.drawable.selector_ic_radio);
    }
}
 
Example #2
Source File: AnimationHelper.java    From ListItemView with Apache License 2.0 6 votes vote down vote up
public void setupCheckBox(ListItemView listItemView) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        AnimatedStateListDrawable asl = new AnimatedStateListDrawable();
        asl.addState(
                new int[]{android.R.attr.state_checked},
                AppCompatResources.getDrawable(mContext, R.drawable.vd_checkbox_checked),
                R.id.checked);
        asl.addState(
                new int[0],
                AppCompatResources.getDrawable(mContext, R.drawable.vd_checkbox_unchecked),
                R.id.unchecked);
        asl.addTransition(
                R.id.unchecked,
                R.id.checked,
                AnimatedVectorDrawableCompat.create(mContext, R.drawable.avd_checkbox_unchecked_to_checked),
                false);
        asl.addTransition(
                R.id.checked,
                R.id.unchecked,
                AnimatedVectorDrawableCompat.create(mContext, R.drawable.avd_checkbox_checked_to_unchecked),
                false);
        listItemView.setIconDrawable(asl);
    } else {
        listItemView.setIconResId(R.drawable.selector_ic_check);
    }
}
 
Example #3
Source File: LUtils.java    From v2ex with Apache License 2.0 6 votes vote down vote up
public void setOrAnimatePlusCheckIcon(final ImageView imageView, boolean isCheck,
                                      boolean allowAnimate) {
    if (!hasL()) {
        compatSetOrAnimatePlusCheckIcon(imageView, isCheck, allowAnimate);
        return;
    }

    Drawable drawable = imageView.getDrawable();
    if (!(drawable instanceof AnimatedStateListDrawable)) {
        drawable = mActivity.getResources().getDrawable(R.drawable.add_schedule_fab_icon_anim);
        imageView.setImageDrawable(drawable);
    }
    imageView.setColorFilter(isCheck ?
            mActivity.getResources().getColor(R.color.theme_accent_1) : Color.WHITE);
    if (allowAnimate) {
        imageView.setImageState(isCheck ? STATE_UNCHECKED : STATE_CHECKED, false);
        drawable.jumpToCurrentState();
        imageView.setImageState(isCheck ? STATE_CHECKED : STATE_UNCHECKED, false);
    } else {
        imageView.setImageState(isCheck ? STATE_CHECKED : STATE_UNCHECKED, false);
        drawable.jumpToCurrentState();
    }
}
 
Example #4
Source File: StateListBuilder.java    From relight with Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = VERSION_CODES.LOLLIPOP)
public static StateListBuilder<Drawable, AnimatedStateListDrawable> animatedDrawableBuilder() {
    return new StateListBuilder<Drawable, AnimatedStateListDrawable>() {
        @Override
        public AnimatedStateListDrawable build() {
            AnimatedStateListDrawable drawable = new AnimatedStateListDrawable();
            int[][] states = getStates();
            Drawable[] values = getValues(new Drawable[this.values.size()]);
            for (int i = 0; i < states.length; i++) {
                drawable.addState(states[i], values[i]);
            }
            return drawable;
        }
    };
}
 
Example #5
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 #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: AnimationHelper.java    From ListItemView with Apache License 2.0 5 votes vote down vote up
public void setupCheckBoxMenu(ListItemView listItemView) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        AnimatedStateListDrawable asl = new AnimatedStateListDrawable();
        asl.addState(
                new int[]{android.R.attr.state_checked},
                AppCompatResources.getDrawable(mContext, R.drawable.vd_checkbox_checked),
                R.id.checked);
        asl.addState(
                new int[0],
                AppCompatResources.getDrawable(mContext, R.drawable.vd_checkbox_unchecked),
                R.id.unchecked);
        asl.addTransition(
                R.id.unchecked,
                R.id.checked,
                AnimatedVectorDrawableCompat.create(mContext, R.drawable.avd_checkbox_unchecked_to_checked),
                false);
        asl.addTransition(
                R.id.checked,
                R.id.unchecked,
                AnimatedVectorDrawableCompat.create(mContext, R.drawable.avd_checkbox_checked_to_unchecked),
                false);

        listItemView.inflateMenu(R.menu.checkable_action_menu);
        ImageView imageView = (ImageView) listItemView.findMenuItem(R.id.action_checkable).getActionView();
        imageView.setImageDrawable(asl);
        asl.jumpToCurrentState();
    } else {
        listItemView.inflateMenu(R.menu.checkable_action_menu);
    }
}
 
Example #8
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 #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();
        }
    }
}