package androidx.core.view; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ValueAnimator; import android.annotation.SuppressLint; import android.os.Build; import android.view.View; import android.view.ViewGroup; import android.view.WindowInsets; import android.view.WindowInsetsAnimation; import android.view.animation.DecelerateInterpolator; import android.view.animation.Interpolator; import androidx.annotation.FloatRange; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.annotation.RestrictTo; import androidx.core.R; import androidx.core.graphics.Insets; import androidx.core.view.WindowInsetsCompat; import b.d.b.a.a; import com.google.android.material.shadow.ShadowDrawableWrapper; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Objects; /* loaded from: classes.dex */ public final class WindowInsetsAnimationCompat { private static final boolean DEBUG = false; private static final String TAG = "WindowInsetsAnimCompat"; private Impl mImpl; /* loaded from: classes.dex */ public static final class BoundsCompat { private final Insets mLowerBound; private final Insets mUpperBound; @RequiresApi(30) private BoundsCompat(@NonNull WindowInsetsAnimation.Bounds bounds) { this.mLowerBound = Impl30.getLowerBounds(bounds); this.mUpperBound = Impl30.getHigherBounds(bounds); } public BoundsCompat(@NonNull Insets insets, @NonNull Insets insets2) { this.mLowerBound = insets; this.mUpperBound = insets2; } @NonNull @RequiresApi(30) public static BoundsCompat toBoundsCompat(@NonNull WindowInsetsAnimation.Bounds bounds) { return new BoundsCompat(bounds); } @NonNull public Insets getLowerBound() { return this.mLowerBound; } @NonNull public Insets getUpperBound() { return this.mUpperBound; } @NonNull public BoundsCompat inset(@NonNull Insets insets) { return new BoundsCompat(WindowInsetsCompat.insetInsets(this.mLowerBound, insets.left, insets.top, insets.right, insets.bottom), WindowInsetsCompat.insetInsets(this.mUpperBound, insets.left, insets.top, insets.right, insets.bottom)); } @NonNull @RequiresApi(30) public WindowInsetsAnimation.Bounds toBounds() { return Impl30.createPlatformBounds(this); } public String toString() { StringBuilder S = a.S("Bounds{lower="); S.append(this.mLowerBound); S.append(" upper="); S.append(this.mUpperBound); S.append("}"); return S.toString(); } } /* loaded from: classes.dex */ public static abstract class Callback { public static final int DISPATCH_MODE_CONTINUE_ON_SUBTREE = 1; public static final int DISPATCH_MODE_STOP = 0; public WindowInsets mDispachedInsets; private final int mDispatchMode; @Retention(RetentionPolicy.SOURCE) @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP}) /* loaded from: classes.dex */ public @interface DispatchMode { } public Callback(int i) { this.mDispatchMode = i; } public final int getDispatchMode() { return this.mDispatchMode; } public void onEnd(@NonNull WindowInsetsAnimationCompat windowInsetsAnimationCompat) { } public void onPrepare(@NonNull WindowInsetsAnimationCompat windowInsetsAnimationCompat) { } @NonNull public abstract WindowInsetsCompat onProgress(@NonNull WindowInsetsCompat windowInsetsCompat, @NonNull List list); @NonNull public BoundsCompat onStart(@NonNull WindowInsetsAnimationCompat windowInsetsAnimationCompat, @NonNull BoundsCompat boundsCompat) { return boundsCompat; } } /* loaded from: classes.dex */ public static class Impl { private float mAlpha; private final long mDurationMillis; private float mFraction; @Nullable private final Interpolator mInterpolator; private final int mTypeMask; public Impl(int i, @Nullable Interpolator interpolator, long j) { this.mTypeMask = i; this.mInterpolator = interpolator; this.mDurationMillis = j; } public float getAlpha() { return this.mAlpha; } public long getDurationMillis() { return this.mDurationMillis; } public float getFraction() { return this.mFraction; } public float getInterpolatedFraction() { Interpolator interpolator = this.mInterpolator; return interpolator != null ? interpolator.getInterpolation(this.mFraction) : this.mFraction; } @Nullable public Interpolator getInterpolator() { return this.mInterpolator; } public int getTypeMask() { return this.mTypeMask; } public void setAlpha(float f) { this.mAlpha = f; } public void setFraction(float f) { this.mFraction = f; } } @RequiresApi(21) /* loaded from: classes.dex */ public static class Impl21 extends Impl { @RequiresApi(21) /* loaded from: classes.dex */ public static class Impl21OnApplyWindowInsetsListener implements View.OnApplyWindowInsetsListener { private static final int COMPAT_ANIMATION_DURATION = 160; public final Callback mCallback; private WindowInsetsCompat mLastInsets; /* renamed from: androidx.core.view.WindowInsetsAnimationCompat$Impl21$Impl21OnApplyWindowInsetsListener$1 reason: invalid class name */ /* loaded from: classes.dex */ public class AnonymousClass1 implements ValueAnimator.AnimatorUpdateListener { public final /* synthetic */ WindowInsetsAnimationCompat val$anim; public final /* synthetic */ int val$animationMask; public final /* synthetic */ WindowInsetsCompat val$startingInsets; public final /* synthetic */ WindowInsetsCompat val$targetInsets; public final /* synthetic */ View val$v; public AnonymousClass1(WindowInsetsAnimationCompat windowInsetsAnimationCompat, WindowInsetsCompat windowInsetsCompat, WindowInsetsCompat windowInsetsCompat2, int i, View view) { this.val$anim = windowInsetsAnimationCompat; this.val$targetInsets = windowInsetsCompat; this.val$startingInsets = windowInsetsCompat2; this.val$animationMask = i; this.val$v = view; } @Override // android.animation.ValueAnimator.AnimatorUpdateListener public void onAnimationUpdate(ValueAnimator valueAnimator) { this.val$anim.setFraction(valueAnimator.getAnimatedFraction()); Impl21.dispatchOnProgress(this.val$v, Impl21.interpolateInsets(this.val$targetInsets, this.val$startingInsets, this.val$anim.getInterpolatedFraction(), this.val$animationMask), Collections.singletonList(this.val$anim)); } } /* renamed from: androidx.core.view.WindowInsetsAnimationCompat$Impl21$Impl21OnApplyWindowInsetsListener$2 reason: invalid class name */ /* loaded from: classes.dex */ public class AnonymousClass2 extends AnimatorListenerAdapter { public final /* synthetic */ WindowInsetsAnimationCompat val$anim; public final /* synthetic */ View val$v; public AnonymousClass2(WindowInsetsAnimationCompat windowInsetsAnimationCompat, View view) { this.val$anim = windowInsetsAnimationCompat; this.val$v = view; } @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener public void onAnimationEnd(Animator animator) { this.val$anim.setFraction(1.0f); Impl21.dispatchOnEnd(this.val$v, this.val$anim); } } /* renamed from: androidx.core.view.WindowInsetsAnimationCompat$Impl21$Impl21OnApplyWindowInsetsListener$3 reason: invalid class name */ /* loaded from: classes.dex */ public class AnonymousClass3 implements Runnable { public final /* synthetic */ WindowInsetsAnimationCompat val$anim; public final /* synthetic */ BoundsCompat val$animationBounds; public final /* synthetic */ ValueAnimator val$animator; public final /* synthetic */ View val$v; public AnonymousClass3(View view, WindowInsetsAnimationCompat windowInsetsAnimationCompat, BoundsCompat boundsCompat, ValueAnimator valueAnimator) { this.val$v = view; this.val$anim = windowInsetsAnimationCompat; this.val$animationBounds = boundsCompat; this.val$animator = valueAnimator; } @Override // java.lang.Runnable public void run() { Impl21.dispatchOnStart(this.val$v, this.val$anim, this.val$animationBounds); this.val$animator.start(); } } public Impl21OnApplyWindowInsetsListener(@NonNull View view, @NonNull Callback callback) { this.mCallback = callback; WindowInsetsCompat rootWindowInsets = ViewCompat.getRootWindowInsets(view); this.mLastInsets = rootWindowInsets != null ? new WindowInsetsCompat.Builder(rootWindowInsets).build() : null; } @Override // android.view.View.OnApplyWindowInsetsListener public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) { int buildAnimationMask; if (!view.isLaidOut()) { this.mLastInsets = WindowInsetsCompat.toWindowInsetsCompat(windowInsets, view); return Impl21.forwardToViewIfNeeded(view, windowInsets); } WindowInsetsCompat windowInsetsCompat = WindowInsetsCompat.toWindowInsetsCompat(windowInsets, view); if (this.mLastInsets == null) { this.mLastInsets = ViewCompat.getRootWindowInsets(view); } if (this.mLastInsets == null) { this.mLastInsets = windowInsetsCompat; return Impl21.forwardToViewIfNeeded(view, windowInsets); } Callback callback = Impl21.getCallback(view); if ((callback == null || !Objects.equals(callback.mDispachedInsets, windowInsets)) && (buildAnimationMask = Impl21.buildAnimationMask(windowInsetsCompat, this.mLastInsets)) != 0) { WindowInsetsCompat windowInsetsCompat2 = this.mLastInsets; WindowInsetsAnimationCompat windowInsetsAnimationCompat = new WindowInsetsAnimationCompat(buildAnimationMask, new DecelerateInterpolator(), 160L); windowInsetsAnimationCompat.setFraction(0.0f); ValueAnimator duration = ValueAnimator.ofFloat(0.0f, 1.0f).setDuration(windowInsetsAnimationCompat.getDurationMillis()); BoundsCompat computeAnimationBounds = Impl21.computeAnimationBounds(windowInsetsCompat, windowInsetsCompat2, buildAnimationMask); Impl21.dispatchOnPrepare(view, windowInsetsAnimationCompat, windowInsets, false); duration.addUpdateListener(new AnonymousClass1(windowInsetsAnimationCompat, windowInsetsCompat, windowInsetsCompat2, buildAnimationMask, view)); duration.addListener(new AnonymousClass2(windowInsetsAnimationCompat, view)); OneShotPreDrawListener.add(view, new AnonymousClass3(view, windowInsetsAnimationCompat, computeAnimationBounds, duration)); this.mLastInsets = windowInsetsCompat; return Impl21.forwardToViewIfNeeded(view, windowInsets); } return Impl21.forwardToViewIfNeeded(view, windowInsets); } } public Impl21(int i, @Nullable Interpolator interpolator, long j) { super(i, interpolator, j); } @SuppressLint({"WrongConstant"}) public static int buildAnimationMask(@NonNull WindowInsetsCompat windowInsetsCompat, @NonNull WindowInsetsCompat windowInsetsCompat2) { int i = 0; for (int i2 = 1; i2 <= 256; i2 <<= 1) { if (!windowInsetsCompat.getInsets(i2).equals(windowInsetsCompat2.getInsets(i2))) { i |= i2; } } return i; } @NonNull public static BoundsCompat computeAnimationBounds(@NonNull WindowInsetsCompat windowInsetsCompat, @NonNull WindowInsetsCompat windowInsetsCompat2, int i) { Insets insets = windowInsetsCompat.getInsets(i); Insets insets2 = windowInsetsCompat2.getInsets(i); return new BoundsCompat(Insets.of(Math.min(insets.left, insets2.left), Math.min(insets.top, insets2.top), Math.min(insets.right, insets2.right), Math.min(insets.bottom, insets2.bottom)), Insets.of(Math.max(insets.left, insets2.left), Math.max(insets.top, insets2.top), Math.max(insets.right, insets2.right), Math.max(insets.bottom, insets2.bottom))); } @NonNull private static View.OnApplyWindowInsetsListener createProxyListener(@NonNull View view, @NonNull Callback callback) { return new Impl21OnApplyWindowInsetsListener(view, callback); } public static void dispatchOnEnd(@NonNull View view, @NonNull WindowInsetsAnimationCompat windowInsetsAnimationCompat) { Callback callback = getCallback(view); if (callback != null) { callback.onEnd(windowInsetsAnimationCompat); if (callback.getDispatchMode() == 0) { return; } } if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; for (int i = 0; i < viewGroup.getChildCount(); i++) { dispatchOnEnd(viewGroup.getChildAt(i), windowInsetsAnimationCompat); } } } public static void dispatchOnPrepare(View view, WindowInsetsAnimationCompat windowInsetsAnimationCompat, WindowInsets windowInsets, boolean z2) { Callback callback = getCallback(view); if (callback != null) { callback.mDispachedInsets = windowInsets; if (!z2) { callback.onPrepare(windowInsetsAnimationCompat); z2 = callback.getDispatchMode() == 0; } } if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; for (int i = 0; i < viewGroup.getChildCount(); i++) { dispatchOnPrepare(viewGroup.getChildAt(i), windowInsetsAnimationCompat, windowInsets, z2); } } } public static void dispatchOnProgress(@NonNull View view, @NonNull WindowInsetsCompat windowInsetsCompat, @NonNull List list) { Callback callback = getCallback(view); if (callback != null) { windowInsetsCompat = callback.onProgress(windowInsetsCompat, list); if (callback.getDispatchMode() == 0) { return; } } if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; for (int i = 0; i < viewGroup.getChildCount(); i++) { dispatchOnProgress(viewGroup.getChildAt(i), windowInsetsCompat, list); } } } public static void dispatchOnStart(View view, WindowInsetsAnimationCompat windowInsetsAnimationCompat, BoundsCompat boundsCompat) { Callback callback = getCallback(view); if (callback != null) { callback.onStart(windowInsetsAnimationCompat, boundsCompat); if (callback.getDispatchMode() == 0) { return; } } if (view instanceof ViewGroup) { ViewGroup viewGroup = (ViewGroup) view; for (int i = 0; i < viewGroup.getChildCount(); i++) { dispatchOnStart(viewGroup.getChildAt(i), windowInsetsAnimationCompat, boundsCompat); } } } @NonNull public static WindowInsets forwardToViewIfNeeded(@NonNull View view, @NonNull WindowInsets windowInsets) { return view.getTag(R.id.tag_on_apply_window_listener) != null ? windowInsets : view.onApplyWindowInsets(windowInsets); } @Nullable public static Callback getCallback(View view) { Object tag = view.getTag(R.id.tag_window_insets_animation_callback); if (tag instanceof Impl21OnApplyWindowInsetsListener) { return ((Impl21OnApplyWindowInsetsListener) tag).mCallback; } return null; } @SuppressLint({"WrongConstant"}) public static WindowInsetsCompat interpolateInsets(WindowInsetsCompat windowInsetsCompat, WindowInsetsCompat windowInsetsCompat2, float f, int i) { WindowInsetsCompat.Builder builder = new WindowInsetsCompat.Builder(windowInsetsCompat); for (int i2 = 1; i2 <= 256; i2 <<= 1) { if ((i & i2) == 0) { builder.setInsets(i2, windowInsetsCompat.getInsets(i2)); } else { Insets insets = windowInsetsCompat.getInsets(i2); Insets insets2 = windowInsetsCompat2.getInsets(i2); float f2 = 1.0f - f; builder.setInsets(i2, WindowInsetsCompat.insetInsets(insets, (int) (((insets.left - insets2.left) * f2) + 0.5d), (int) (((insets.top - insets2.top) * f2) + 0.5d), (int) (((insets.right - insets2.right) * f2) + 0.5d), (int) (((insets.bottom - insets2.bottom) * f2) + 0.5d))); } } return builder.build(); } public static void setCallback(@NonNull View view, @Nullable Callback callback) { Object tag = view.getTag(R.id.tag_on_apply_window_listener); if (callback == null) { view.setTag(R.id.tag_window_insets_animation_callback, null); if (tag == null) { view.setOnApplyWindowInsetsListener(null); return; } return; } View.OnApplyWindowInsetsListener createProxyListener = createProxyListener(view, callback); view.setTag(R.id.tag_window_insets_animation_callback, createProxyListener); if (tag == null) { view.setOnApplyWindowInsetsListener(createProxyListener); } } } @RequiresApi(30) /* loaded from: classes.dex */ public static class Impl30 extends Impl { @NonNull private final WindowInsetsAnimation mWrapped; @RequiresApi(30) /* loaded from: classes.dex */ public static class ProxyCallback extends WindowInsetsAnimation.Callback { private final HashMap mAnimations = new HashMap<>(); private final Callback mCompat; private List mRORunningAnimations; private ArrayList mTmpRunningAnimations; public ProxyCallback(@NonNull Callback callback) { super(callback.getDispatchMode()); this.mCompat = callback; } @NonNull private WindowInsetsAnimationCompat getWindowInsetsAnimationCompat(@NonNull WindowInsetsAnimation windowInsetsAnimation) { WindowInsetsAnimationCompat windowInsetsAnimationCompat = this.mAnimations.get(windowInsetsAnimation); if (windowInsetsAnimationCompat != null) { return windowInsetsAnimationCompat; } WindowInsetsAnimationCompat windowInsetsAnimationCompat2 = WindowInsetsAnimationCompat.toWindowInsetsAnimationCompat(windowInsetsAnimation); this.mAnimations.put(windowInsetsAnimation, windowInsetsAnimationCompat2); return windowInsetsAnimationCompat2; } @Override // android.view.WindowInsetsAnimation.Callback public void onEnd(@NonNull WindowInsetsAnimation windowInsetsAnimation) { this.mCompat.onEnd(getWindowInsetsAnimationCompat(windowInsetsAnimation)); this.mAnimations.remove(windowInsetsAnimation); } @Override // android.view.WindowInsetsAnimation.Callback public void onPrepare(@NonNull WindowInsetsAnimation windowInsetsAnimation) { this.mCompat.onPrepare(getWindowInsetsAnimationCompat(windowInsetsAnimation)); } @Override // android.view.WindowInsetsAnimation.Callback @NonNull public WindowInsets onProgress(@NonNull WindowInsets windowInsets, @NonNull List list) { ArrayList arrayList = this.mTmpRunningAnimations; if (arrayList == null) { ArrayList arrayList2 = new ArrayList<>(list.size()); this.mTmpRunningAnimations = arrayList2; this.mRORunningAnimations = Collections.unmodifiableList(arrayList2); } else { arrayList.clear(); } for (int size = list.size() - 1; size >= 0; size--) { WindowInsetsAnimation windowInsetsAnimation = list.get(size); WindowInsetsAnimationCompat windowInsetsAnimationCompat = getWindowInsetsAnimationCompat(windowInsetsAnimation); windowInsetsAnimationCompat.setFraction(windowInsetsAnimation.getFraction()); this.mTmpRunningAnimations.add(windowInsetsAnimationCompat); } return this.mCompat.onProgress(WindowInsetsCompat.toWindowInsetsCompat(windowInsets), this.mRORunningAnimations).toWindowInsets(); } @Override // android.view.WindowInsetsAnimation.Callback @NonNull public WindowInsetsAnimation.Bounds onStart(@NonNull WindowInsetsAnimation windowInsetsAnimation, @NonNull WindowInsetsAnimation.Bounds bounds) { return this.mCompat.onStart(getWindowInsetsAnimationCompat(windowInsetsAnimation), BoundsCompat.toBoundsCompat(bounds)).toBounds(); } } public Impl30(int i, Interpolator interpolator, long j) { this(new WindowInsetsAnimation(i, interpolator, j)); } public Impl30(@NonNull WindowInsetsAnimation windowInsetsAnimation) { super(0, null, 0L); this.mWrapped = windowInsetsAnimation; } @NonNull public static WindowInsetsAnimation.Bounds createPlatformBounds(@NonNull BoundsCompat boundsCompat) { return new WindowInsetsAnimation.Bounds(boundsCompat.getLowerBound().toPlatformInsets(), boundsCompat.getUpperBound().toPlatformInsets()); } @NonNull public static Insets getHigherBounds(@NonNull WindowInsetsAnimation.Bounds bounds) { return Insets.toCompatInsets(bounds.getUpperBound()); } @NonNull public static Insets getLowerBounds(@NonNull WindowInsetsAnimation.Bounds bounds) { return Insets.toCompatInsets(bounds.getLowerBound()); } public static void setCallback(@NonNull View view, @Nullable Callback callback) { view.setWindowInsetsAnimationCallback(callback != null ? new ProxyCallback(callback) : null); } @Override // androidx.core.view.WindowInsetsAnimationCompat.Impl public long getDurationMillis() { return this.mWrapped.getDurationMillis(); } @Override // androidx.core.view.WindowInsetsAnimationCompat.Impl public float getFraction() { return this.mWrapped.getFraction(); } @Override // androidx.core.view.WindowInsetsAnimationCompat.Impl public float getInterpolatedFraction() { return this.mWrapped.getInterpolatedFraction(); } @Override // androidx.core.view.WindowInsetsAnimationCompat.Impl @Nullable public Interpolator getInterpolator() { return this.mWrapped.getInterpolator(); } @Override // androidx.core.view.WindowInsetsAnimationCompat.Impl public int getTypeMask() { return this.mWrapped.getTypeMask(); } @Override // androidx.core.view.WindowInsetsAnimationCompat.Impl public void setFraction(float f) { this.mWrapped.setFraction(f); } } public WindowInsetsAnimationCompat(int i, @Nullable Interpolator interpolator, long j) { if (Build.VERSION.SDK_INT >= 30) { this.mImpl = new Impl30(i, interpolator, j); } else { this.mImpl = new Impl21(i, interpolator, j); } } @RequiresApi(30) private WindowInsetsAnimationCompat(@NonNull WindowInsetsAnimation windowInsetsAnimation) { this(0, null, 0L); if (Build.VERSION.SDK_INT >= 30) { this.mImpl = new Impl30(windowInsetsAnimation); } } public static void setCallback(@NonNull View view, @Nullable Callback callback) { if (Build.VERSION.SDK_INT >= 30) { Impl30.setCallback(view, callback); } else { Impl21.setCallback(view, callback); } } @RequiresApi(30) public static WindowInsetsAnimationCompat toWindowInsetsAnimationCompat(WindowInsetsAnimation windowInsetsAnimation) { return new WindowInsetsAnimationCompat(windowInsetsAnimation); } @FloatRange(from = ShadowDrawableWrapper.COS_45, to = 1.0d) public float getAlpha() { return this.mImpl.getAlpha(); } public long getDurationMillis() { return this.mImpl.getDurationMillis(); } @FloatRange(from = ShadowDrawableWrapper.COS_45, to = 1.0d) public float getFraction() { return this.mImpl.getFraction(); } public float getInterpolatedFraction() { return this.mImpl.getInterpolatedFraction(); } @Nullable public Interpolator getInterpolator() { return this.mImpl.getInterpolator(); } public int getTypeMask() { return this.mImpl.getTypeMask(); } public void setAlpha(@FloatRange(from = 0.0d, to = 1.0d) float f) { this.mImpl.setAlpha(f); } public void setFraction(@FloatRange(from = 0.0d, to = 1.0d) float f) { this.mImpl.setFraction(f); } }