package androidx.fragment.app;

import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.content.res.Resources;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.Transformation;
import androidx.core.os.e;
import androidx.fragment.app.w;

/* JADX INFO: compiled from: FragmentAnim.java */
/* JADX INFO: loaded from: classes.dex */
class f {

    /* JADX INFO: compiled from: FragmentAnim.java */
    class a implements e.b {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        final /* synthetic */ Fragment f2300a;

        a(Fragment fragment) {
            this.f2300a = fragment;
        }

        @Override // androidx.core.os.e.b
        public void a() {
            if (this.f2300a.n() != null) {
                View viewN = this.f2300a.n();
                this.f2300a.q1(null);
                viewN.clearAnimation();
            }
            this.f2300a.s1(null);
        }
    }

    /* JADX INFO: compiled from: FragmentAnim.java */
    class b implements Animation.AnimationListener {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        final /* synthetic */ ViewGroup f2301a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ Fragment f2302b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        final /* synthetic */ w.g f2303c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        final /* synthetic */ androidx.core.os.e f2304d;

        /* JADX INFO: compiled from: FragmentAnim.java */
        class a implements Runnable {
            a() {
            }

            @Override // java.lang.Runnable
            public void run() {
                if (b.this.f2302b.n() != null) {
                    b.this.f2302b.q1(null);
                    b bVar = b.this;
                    bVar.f2303c.a(bVar.f2302b, bVar.f2304d);
                }
            }
        }

        b(ViewGroup viewGroup, Fragment fragment, w.g gVar, androidx.core.os.e eVar) {
            this.f2301a = viewGroup;
            this.f2302b = fragment;
            this.f2303c = gVar;
            this.f2304d = eVar;
        }

        @Override // android.view.animation.Animation.AnimationListener
        public void onAnimationEnd(Animation animation) {
            this.f2301a.post(new a());
        }

        @Override // android.view.animation.Animation.AnimationListener
        public void onAnimationRepeat(Animation animation) {
        }

        @Override // android.view.animation.Animation.AnimationListener
        public void onAnimationStart(Animation animation) {
        }
    }

    /* JADX INFO: compiled from: FragmentAnim.java */
    class c extends AnimatorListenerAdapter {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        final /* synthetic */ ViewGroup f2306a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        final /* synthetic */ View f2307b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        final /* synthetic */ Fragment f2308c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        final /* synthetic */ w.g f2309d;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        final /* synthetic */ androidx.core.os.e f2310e;

        c(ViewGroup viewGroup, View view, Fragment fragment, w.g gVar, androidx.core.os.e eVar) {
            this.f2306a = viewGroup;
            this.f2307b = view;
            this.f2308c = fragment;
            this.f2309d = gVar;
            this.f2310e = eVar;
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationEnd(Animator animator) {
            this.f2306a.endViewTransition(this.f2307b);
            Animator animatorO = this.f2308c.o();
            this.f2308c.s1(null);
            if (animatorO == null || this.f2306a.indexOfChild(this.f2307b) >= 0) {
                return;
            }
            this.f2309d.a(this.f2308c, this.f2310e);
        }
    }

    static void a(Fragment fragment, d dVar, w.g gVar) {
        View view = fragment.L;
        ViewGroup viewGroup = fragment.K;
        viewGroup.startViewTransition(view);
        androidx.core.os.e eVar = new androidx.core.os.e();
        eVar.c(new a(fragment));
        gVar.b(fragment, eVar);
        if (dVar.f2311a != null) {
            e eVar2 = new e(dVar.f2311a, viewGroup, view);
            fragment.q1(fragment.L);
            eVar2.setAnimationListener(new b(viewGroup, fragment, gVar, eVar));
            fragment.L.startAnimation(eVar2);
            return;
        }
        Animator animator = dVar.f2312b;
        fragment.s1(animator);
        animator.addListener(new c(viewGroup, view, fragment, gVar, eVar));
        animator.setTarget(fragment.L);
        animator.start();
    }

    private static int b(Fragment fragment, boolean z2, boolean z3) {
        return z3 ? z2 ? fragment.G() : fragment.H() : z2 ? fragment.s() : fragment.v();
    }

    static d c(Context context, Fragment fragment, boolean z2, boolean z3) {
        int iC = fragment.C();
        int iB = b(fragment, z2, z3);
        boolean z4 = false;
        fragment.r1(0, 0, 0, 0);
        ViewGroup viewGroup = fragment.K;
        if (viewGroup != null) {
            int i3 = a0.b.f10c;
            if (viewGroup.getTag(i3) != null) {
                fragment.K.setTag(i3, null);
            }
        }
        ViewGroup viewGroup2 = fragment.K;
        if (viewGroup2 != null && viewGroup2.getLayoutTransition() != null) {
            return null;
        }
        Animation animationM0 = fragment.m0(iC, z2, iB);
        if (animationM0 != null) {
            return new d(animationM0);
        }
        Animator animatorN0 = fragment.n0(iC, z2, iB);
        if (animatorN0 != null) {
            return new d(animatorN0);
        }
        if (iB == 0 && iC != 0) {
            iB = d(iC, z2);
        }
        if (iB != 0) {
            boolean zEquals = "anim".equals(context.getResources().getResourceTypeName(iB));
            if (zEquals) {
                try {
                    Animation animationLoadAnimation = AnimationUtils.loadAnimation(context, iB);
                    if (animationLoadAnimation != null) {
                        return new d(animationLoadAnimation);
                    }
                    z4 = true;
                } catch (Resources.NotFoundException e3) {
                    throw e3;
                } catch (RuntimeException unused) {
                }
            }
            if (!z4) {
                try {
                    Animator animatorLoadAnimator = AnimatorInflater.loadAnimator(context, iB);
                    if (animatorLoadAnimator != null) {
                        return new d(animatorLoadAnimator);
                    }
                } catch (RuntimeException e4) {
                    if (zEquals) {
                        throw e4;
                    }
                    Animation animationLoadAnimation2 = AnimationUtils.loadAnimation(context, iB);
                    if (animationLoadAnimation2 != null) {
                        return new d(animationLoadAnimation2);
                    }
                }
            }
        }
        return null;
    }

    private static int d(int i3, boolean z2) {
        if (i3 == 4097) {
            return z2 ? a0.a.f6e : a0.a.f7f;
        }
        if (i3 == 4099) {
            return z2 ? a0.a.f4c : a0.a.f5d;
        }
        if (i3 != 8194) {
            return -1;
        }
        return z2 ? a0.a.f2a : a0.a.f3b;
    }

    /* JADX INFO: compiled from: FragmentAnim.java */
    static class d {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public final Animation f2311a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public final Animator f2312b;

        d(Animation animation) {
            this.f2311a = animation;
            this.f2312b = null;
            if (animation == null) {
                throw new IllegalStateException("Animation cannot be null");
            }
        }

        d(Animator animator) {
            this.f2311a = null;
            this.f2312b = animator;
            if (animator == null) {
                throw new IllegalStateException("Animator cannot be null");
            }
        }
    }

    /* JADX INFO: compiled from: FragmentAnim.java */
    static class e extends AnimationSet implements Runnable {

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        private final ViewGroup f2313e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        private final View f2314f;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        private boolean f2315g;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        private boolean f2316h;

        /* JADX INFO: renamed from: i, reason: collision with root package name */
        private boolean f2317i;

        e(Animation animation, ViewGroup viewGroup, View view) {
            super(false);
            this.f2317i = true;
            this.f2313e = viewGroup;
            this.f2314f = view;
            addAnimation(animation);
            viewGroup.post(this);
        }

        @Override // android.view.animation.AnimationSet, android.view.animation.Animation
        public boolean getTransformation(long j3, Transformation transformation) {
            this.f2317i = true;
            if (this.f2315g) {
                return !this.f2316h;
            }
            if (!super.getTransformation(j3, transformation)) {
                this.f2315g = true;
                androidx.core.view.v.a(this.f2313e, this);
            }
            return true;
        }

        @Override // java.lang.Runnable
        public void run() {
            if (this.f2315g || !this.f2317i) {
                this.f2313e.endViewTransition(this.f2314f);
                this.f2316h = true;
            } else {
                this.f2317i = false;
                this.f2313e.post(this);
            }
        }

        @Override // android.view.animation.Animation
        public boolean getTransformation(long j3, Transformation transformation, float f3) {
            this.f2317i = true;
            if (this.f2315g) {
                return !this.f2316h;
            }
            if (!super.getTransformation(j3, transformation, f3)) {
                this.f2315g = true;
                androidx.core.view.v.a(this.f2313e, this);
            }
            return true;
        }
    }
}
