Java Code Examples for android.graphics.drawable.AnimatedStateListDrawable#addTransition()

The following examples show how to use android.graphics.drawable.AnimatedStateListDrawable#addTransition() . 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: 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);
    }
}