package androidx.appcompat.graphics.drawable; import android.animation.ObjectAnimator; import android.animation.TimeInterpolator; import android.content.Context; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.drawable.Animatable; import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.Drawable; import android.os.Build; import android.util.AttributeSet; import android.util.StateSet; import androidx.appcompat.R$styleable; import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.graphics.drawable.DrawableContainer; import androidx.appcompat.graphics.drawable.StateListDrawable; import androidx.collection.LongSparseArray; import androidx.collection.SparseArrayCompat; import androidx.core.content.res.TypedArrayUtils; import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat; import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat; import java.io.IOException; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; /* loaded from: classes.dex */ public class AnimatedStateListDrawableCompat extends StateListDrawable { private AnimatedStateListState o; private Transition p; private int q; private int r; private boolean s; private static class AnimatableTransition extends Transition { private final Animatable a; AnimatableTransition(Animatable animatable) { super(); this.a = animatable; } @Override // androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat.Transition public void c() { this.a.start(); } @Override // androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat.Transition public void d() { this.a.stop(); } } static class AnimatedStateListState extends StateListDrawable.StateListState { LongSparseArray K; SparseArrayCompat L; AnimatedStateListState(AnimatedStateListState animatedStateListState, AnimatedStateListDrawableCompat animatedStateListDrawableCompat, Resources resources) { super(animatedStateListState, animatedStateListDrawableCompat, resources); if (animatedStateListState != null) { this.K = animatedStateListState.K; this.L = animatedStateListState.L; } else { this.K = new LongSparseArray<>(); this.L = new SparseArrayCompat<>(); } } private static long f(int i, int i2) { return i2 | (i << 32); } int a(int i, int i2, Drawable drawable, boolean z) { int a = super.a(drawable); long f = f(i, i2); long j = z ? 8589934592L : 0L; long j2 = a; this.K.a(f, Long.valueOf(j2 | j)); if (z) { this.K.a(f(i2, i), Long.valueOf(4294967296L | j2 | j)); } return a; } int b(int[] iArr) { int a = super.a(iArr); return a >= 0 ? a : super.a(StateSet.WILD_CARD); } int c(int i, int i2) { return (int) this.K.b(f(i, i2), -1L).longValue(); } int d(int i) { if (i < 0) { return 0; } return this.L.b(i, 0).intValue(); } boolean e(int i, int i2) { return (this.K.b(f(i, i2), -1L).longValue() & 8589934592L) != 0; } @Override // androidx.appcompat.graphics.drawable.StateListDrawable.StateListState, androidx.appcompat.graphics.drawable.DrawableContainer.DrawableContainerState void m() { this.K = this.K.m0clone(); this.L = this.L.m1clone(); } @Override // androidx.appcompat.graphics.drawable.StateListDrawable.StateListState, android.graphics.drawable.Drawable.ConstantState public Drawable newDrawable() { return new AnimatedStateListDrawableCompat(this, null); } boolean d(int i, int i2) { return (this.K.b(f(i, i2), -1L).longValue() & 4294967296L) != 0; } @Override // androidx.appcompat.graphics.drawable.StateListDrawable.StateListState, android.graphics.drawable.Drawable.ConstantState public Drawable newDrawable(Resources resources) { return new AnimatedStateListDrawableCompat(this, resources); } int a(int[] iArr, Drawable drawable, int i) { int a = super.a(iArr, drawable); this.L.c(a, Integer.valueOf(i)); return a; } } private static class AnimatedVectorDrawableTransition extends Transition { private final AnimatedVectorDrawableCompat a; AnimatedVectorDrawableTransition(AnimatedVectorDrawableCompat animatedVectorDrawableCompat) { super(); this.a = animatedVectorDrawableCompat; } @Override // androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat.Transition public void c() { this.a.start(); } @Override // androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat.Transition public void d() { this.a.stop(); } } private static class AnimationDrawableTransition extends Transition { private final ObjectAnimator a; private final boolean b; AnimationDrawableTransition(AnimationDrawable animationDrawable, boolean z, boolean z2) { super(); int numberOfFrames = animationDrawable.getNumberOfFrames(); int i = z ? numberOfFrames - 1 : 0; int i2 = z ? 0 : numberOfFrames - 1; FrameInterpolator frameInterpolator = new FrameInterpolator(animationDrawable, z); ObjectAnimator ofInt = ObjectAnimator.ofInt(animationDrawable, "currentIndex", i, i2); if (Build.VERSION.SDK_INT >= 18) { ofInt.setAutoCancel(true); } ofInt.setDuration(frameInterpolator.a()); ofInt.setInterpolator(frameInterpolator); this.b = z2; this.a = ofInt; } @Override // androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat.Transition public boolean a() { return this.b; } @Override // androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat.Transition public void b() { this.a.reverse(); } @Override // androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat.Transition public void c() { this.a.start(); } @Override // androidx.appcompat.graphics.drawable.AnimatedStateListDrawableCompat.Transition public void d() { this.a.cancel(); } } private static abstract class Transition { private Transition() { } public boolean a() { return false; } public void b() { } public abstract void c(); public abstract void d(); } public AnimatedStateListDrawableCompat() { this(null, null); } public static AnimatedStateListDrawableCompat b(Context context, Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) throws IOException, XmlPullParserException { String name = xmlPullParser.getName(); if (name.equals("animated-selector")) { AnimatedStateListDrawableCompat animatedStateListDrawableCompat = new AnimatedStateListDrawableCompat(); animatedStateListDrawableCompat.a(context, resources, xmlPullParser, attributeSet, theme); return animatedStateListDrawableCompat; } throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": invalid animated-selector tag " + name); } private void c() { onStateChange(getState()); } private int d(Context context, Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) throws XmlPullParserException, IOException { int next; TypedArray a = TypedArrayUtils.a(resources, theme, attributeSet, R$styleable.AnimatedStateListDrawableItem); int resourceId = a.getResourceId(R$styleable.AnimatedStateListDrawableItem_android_id, 0); int resourceId2 = a.getResourceId(R$styleable.AnimatedStateListDrawableItem_android_drawable, -1); Drawable c = resourceId2 > 0 ? AppCompatResources.c(context, resourceId2) : null; a.recycle(); int[] a2 = a(attributeSet); if (c == null) { do { next = xmlPullParser.next(); } while (next == 4); if (next != 2) { throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": tag requires a 'drawable' attribute or child tag defining a drawable"); } c = xmlPullParser.getName().equals("vector") ? VectorDrawableCompat.createFromXmlInner(resources, xmlPullParser, attributeSet, theme) : Build.VERSION.SDK_INT >= 21 ? Drawable.createFromXmlInner(resources, xmlPullParser, attributeSet, theme) : Drawable.createFromXmlInner(resources, xmlPullParser, attributeSet); } if (c != null) { return this.o.a(a2, c, resourceId); } throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": tag requires a 'drawable' attribute or child tag defining a drawable"); } private int e(Context context, Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) throws XmlPullParserException, IOException { int next; TypedArray a = TypedArrayUtils.a(resources, theme, attributeSet, R$styleable.AnimatedStateListDrawableTransition); int resourceId = a.getResourceId(R$styleable.AnimatedStateListDrawableTransition_android_fromId, -1); int resourceId2 = a.getResourceId(R$styleable.AnimatedStateListDrawableTransition_android_toId, -1); int resourceId3 = a.getResourceId(R$styleable.AnimatedStateListDrawableTransition_android_drawable, -1); Drawable c = resourceId3 > 0 ? AppCompatResources.c(context, resourceId3) : null; boolean z = a.getBoolean(R$styleable.AnimatedStateListDrawableTransition_android_reversible, false); a.recycle(); if (c == null) { do { next = xmlPullParser.next(); } while (next == 4); if (next != 2) { throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": tag requires a 'drawable' attribute or child tag defining a drawable"); } c = xmlPullParser.getName().equals("animated-vector") ? AnimatedVectorDrawableCompat.a(context, resources, xmlPullParser, attributeSet, theme) : Build.VERSION.SDK_INT >= 21 ? Drawable.createFromXmlInner(resources, xmlPullParser, attributeSet, theme) : Drawable.createFromXmlInner(resources, xmlPullParser, attributeSet); } if (c == null) { throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": tag requires a 'drawable' attribute or child tag defining a drawable"); } if (resourceId != -1 && resourceId2 != -1) { return this.o.a(resourceId, resourceId2, c, z); } throw new XmlPullParserException(xmlPullParser.getPositionDescription() + ": tag requires 'fromId' & 'toId' attributes"); } @Override // androidx.appcompat.graphics.drawable.StateListDrawable, android.graphics.drawable.Drawable public boolean isStateful() { return true; } @Override // androidx.appcompat.graphics.drawable.DrawableContainer, android.graphics.drawable.Drawable public void jumpToCurrentState() { super.jumpToCurrentState(); Transition transition = this.p; if (transition != null) { transition.d(); this.p = null; a(this.q); this.q = -1; this.r = -1; } } @Override // androidx.appcompat.graphics.drawable.StateListDrawable, androidx.appcompat.graphics.drawable.DrawableContainer, android.graphics.drawable.Drawable public Drawable mutate() { if (!this.s) { super.mutate(); if (this == this) { this.o.m(); this.s = true; } } return this; } @Override // androidx.appcompat.graphics.drawable.StateListDrawable, androidx.appcompat.graphics.drawable.DrawableContainer, android.graphics.drawable.Drawable protected boolean onStateChange(int[] iArr) { int b = this.o.b(iArr); boolean z = b != b() && (b(b) || a(b)); Drawable current = getCurrent(); return current != null ? z | current.setState(iArr) : z; } @Override // androidx.appcompat.graphics.drawable.DrawableContainer, android.graphics.drawable.Drawable public boolean setVisible(boolean z, boolean z2) { boolean visible = super.setVisible(z, z2); if (this.p != null && (visible || z2)) { if (z) { this.p.c(); } else { jumpToCurrentState(); } } return visible; } AnimatedStateListDrawableCompat(AnimatedStateListState animatedStateListState, Resources resources) { super(null); this.q = -1; this.r = -1; a(new AnimatedStateListState(animatedStateListState, this, resources)); onStateChange(getState()); jumpToCurrentState(); } private void c(Context context, Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) throws XmlPullParserException, IOException { int depth = xmlPullParser.getDepth() + 1; while (true) { int next = xmlPullParser.next(); if (next == 1) { return; } int depth2 = xmlPullParser.getDepth(); if (depth2 < depth && next == 3) { return; } if (next == 2 && depth2 <= depth) { if (xmlPullParser.getName().equals("item")) { d(context, resources, xmlPullParser, attributeSet, theme); } else if (xmlPullParser.getName().equals("transition")) { e(context, resources, xmlPullParser, attributeSet, theme); } } } } public void a(Context context, Resources resources, XmlPullParser xmlPullParser, AttributeSet attributeSet, Resources.Theme theme) throws XmlPullParserException, IOException { TypedArray a = TypedArrayUtils.a(resources, theme, attributeSet, R$styleable.AnimatedStateListDrawableCompat); setVisible(a.getBoolean(R$styleable.AnimatedStateListDrawableCompat_android_visible, true), true); a(a); a(resources); a.recycle(); c(context, resources, xmlPullParser, attributeSet, theme); c(); } private boolean b(int i) { int b; int c; Transition animatableTransition; Transition transition = this.p; if (transition != null) { if (i == this.q) { return true; } if (i == this.r && transition.a()) { transition.b(); this.q = this.r; this.r = i; return true; } b = this.q; transition.d(); } else { b = b(); } this.p = null; this.r = -1; this.q = -1; AnimatedStateListState animatedStateListState = this.o; int d = animatedStateListState.d(b); int d2 = animatedStateListState.d(i); if (d2 == 0 || d == 0 || (c = animatedStateListState.c(d, d2)) < 0) { return false; } boolean e = animatedStateListState.e(d, d2); a(c); Object current = getCurrent(); if (current instanceof AnimationDrawable) { animatableTransition = new AnimationDrawableTransition((AnimationDrawable) current, animatedStateListState.d(d, d2), e); } else if (current instanceof AnimatedVectorDrawableCompat) { animatableTransition = new AnimatedVectorDrawableTransition((AnimatedVectorDrawableCompat) current); } else { if (current instanceof Animatable) { animatableTransition = new AnimatableTransition((Animatable) current); } return false; } animatableTransition.c(); this.p = animatableTransition; this.r = b; this.q = i; return true; } private static class FrameInterpolator implements TimeInterpolator { private int[] a; private int b; private int c; FrameInterpolator(AnimationDrawable animationDrawable, boolean z) { a(animationDrawable, z); } int a(AnimationDrawable animationDrawable, boolean z) { int numberOfFrames = animationDrawable.getNumberOfFrames(); this.b = numberOfFrames; int[] iArr = this.a; if (iArr == null || iArr.length < numberOfFrames) { this.a = new int[numberOfFrames]; } int[] iArr2 = this.a; int i = 0; for (int i2 = 0; i2 < numberOfFrames; i2++) { int duration = animationDrawable.getDuration(z ? (numberOfFrames - i2) - 1 : i2); iArr2[i2] = duration; i += duration; } this.c = i; return i; } @Override // android.animation.TimeInterpolator public float getInterpolation(float f) { int i = (int) ((f * this.c) + 0.5f); int i2 = this.b; int[] iArr = this.a; int i3 = 0; while (i3 < i2 && i >= iArr[i3]) { i -= iArr[i3]; i3++; } return (i3 / i2) + (i3 < i2 ? i / this.c : 0.0f); } int a() { return this.c; } } private void a(TypedArray typedArray) { AnimatedStateListState animatedStateListState = this.o; if (Build.VERSION.SDK_INT >= 21) { animatedStateListState.d |= typedArray.getChangingConfigurations(); } animatedStateListState.b(typedArray.getBoolean(R$styleable.AnimatedStateListDrawableCompat_android_variablePadding, animatedStateListState.i)); animatedStateListState.a(typedArray.getBoolean(R$styleable.AnimatedStateListDrawableCompat_android_constantSize, animatedStateListState.l)); animatedStateListState.b(typedArray.getInt(R$styleable.AnimatedStateListDrawableCompat_android_enterFadeDuration, animatedStateListState.A)); animatedStateListState.c(typedArray.getInt(R$styleable.AnimatedStateListDrawableCompat_android_exitFadeDuration, animatedStateListState.B)); setDither(typedArray.getBoolean(R$styleable.AnimatedStateListDrawableCompat_android_dither, animatedStateListState.x)); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // androidx.appcompat.graphics.drawable.StateListDrawable, androidx.appcompat.graphics.drawable.DrawableContainer public AnimatedStateListState a() { return new AnimatedStateListState(this.o, this, null); } @Override // androidx.appcompat.graphics.drawable.StateListDrawable, androidx.appcompat.graphics.drawable.DrawableContainer protected void a(DrawableContainer.DrawableContainerState drawableContainerState) { super.a(drawableContainerState); if (drawableContainerState instanceof AnimatedStateListState) { this.o = (AnimatedStateListState) drawableContainerState; } } }