类android.graphics.drawable.AnimatedStateListDrawable源码实例Demo

下面列出了怎么用android.graphics.drawable.AnimatedStateListDrawable的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: ListItemView   文件: AnimationHelper.java
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);
    }
}
 
源代码2 项目: ListItemView   文件: AnimationHelper.java
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);
    }
}
 
源代码3 项目: v2ex   文件: LUtils.java
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();
    }
}
 
源代码4 项目: relight   文件: StateListBuilder.java
@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;
        }
    };
}
 
源代码5 项目: timecat   文件: TintRadioButton.java
@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();
        }
    }
}
 
源代码6 项目: timecat   文件: TintCheckBox.java
@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();
        }
    }
}
 
源代码7 项目: ListItemView   文件: AnimationHelper.java
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);
    }
}
 
源代码8 项目: MagicaSakura   文件: TintRadioButton.java
@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();
        }
    }
}
 
源代码9 项目: MagicaSakura   文件: TintCheckBox.java
@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();
        }
    }
}
 
源代码10 项目: MagicaSakura   文件: TintSwitchCompat.java
@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();
        }
    }
}
 
 类方法
 同包方法