private static void setViewStateListAnimator(View view, ViewNodeInfo viewNodeInfo) { StateListAnimator stateListAnimator = viewNodeInfo.getStateListAnimator(); final int stateListAnimatorRes = viewNodeInfo.getStateListAnimatorRes(); if (stateListAnimator == null && stateListAnimatorRes == 0) { return; } if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { throw new IllegalStateException( "MountState has a ViewNodeInfo with stateListAnimator, " + "however the current Android version doesn't support stateListAnimator on Views"); } if (stateListAnimator == null) { stateListAnimator = AnimatorInflater.loadStateListAnimator(view.getContext(), stateListAnimatorRes); } view.setStateListAnimator(stateListAnimator); }
/** * Ports {@link android.view.View#setStateListAnimator(android.animation.StateListAnimator)} * into components world. However, since the aforementioned view's method is available only on * API 21 and above, calling this method on lower APIs will have no effect. On the legit * versions, on the other hand, calling this method will lead to the component being wrapped * into a view */ public T stateListAnimatorRes(@DrawableRes int resId) { if (Build.VERSION.SDK_INT >= 26) { // We cannot do it on the versions prior to Android 8.0 since there is a possible race // condition when loading state list animators, thus we will avoid doing it off the UI // thread return stateListAnimator( AnimatorInflater.loadStateListAnimator(mContext.getAndroidContext(), resId)); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mComponent.getOrCreateCommonPropsHolder().stateListAnimatorRes(resId); } return getThis(); }
private void setStateListAnimator() { StateListAnimator stateListAnimator = AnimatorInflater.loadStateListAnimator(this, R.animator.anim_view_state_change_2); findViewById(R.id.view_puppet2).setStateListAnimator(stateListAnimator); }
@Override public void setStateListAnimator(View view, int id) { view.setStateListAnimator(AnimatorInflater.loadStateListAnimator(view.getContext(), id)); } }
static void setStateListAnimatorFromAttrs(View view, AttributeSet attrs, int defStyleAttr, int defStyleRes) { final Context context = view.getContext(); final TypedArray a = context.obtainStyledAttributes(attrs, STATE_LIST_ANIM_ATTRS, defStyleAttr, defStyleRes); try { if (a.hasValue(0)) { StateListAnimator sla = AnimatorInflater.loadStateListAnimator(context, a.getResourceId(0, 0)); view.setStateListAnimator(sla); } } finally { a.recycle(); } }
private void setStateListAnimator() { StateListAnimator stateListAnimator = AnimatorInflater.loadStateListAnimator(this, R.animator.anim_view_state_change_2); findViewById(R.id.view_puppet2).setStateListAnimator(stateListAnimator); }
public FunnyButton(Context context) { super(context); setPreventCornerOverlap(false); setUseCompatPadding(true); setClickable(true); if (Build.VERSION.SDK_INT >= 21){ stateListAnimator = AnimatorInflater .loadStateListAnimator(context, R.anim.card_ripple_touch); setStateListAnimator(stateListAnimator); } setForeground(ContextCompat.getDrawable(context, R.drawable.card_ripple)); textView = new TextView(context); }
public FunnyButton(Context context, AttributeSet attrs) { super(context, attrs); setPreventCornerOverlap(false); setUseCompatPadding(true); setClickable(true); if (Build.VERSION.SDK_INT >= 21){ stateListAnimator = AnimatorInflater .loadStateListAnimator(context, R.anim.card_ripple_touch); setStateListAnimator(stateListAnimator); } setForeground(ContextCompat.getDrawable(context, R.drawable.card_ripple)); textView = new TextView(context); initButton(context, attrs); }