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.fragment.app.w;
import c.f.h.a;

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

    /* JADX INFO: compiled from: FragmentAnim.java */
    class a implements a.InterfaceC0027a {
        final /* synthetic */ Fragment a;

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

        @Override // c.f.h.a.InterfaceC0027a
        public void a() {
            if (this.a.m() != null) {
                View viewM = this.a.m();
                this.a.o1(null);
                viewM.clearAnimation();
            }
            this.a.p1(null);
        }
    }

    /* JADX INFO: compiled from: FragmentAnim.java */
    class b implements Animation.AnimationListener {
        final /* synthetic */ ViewGroup a;

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

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

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        final /* synthetic */ c.f.h.a f752d;

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

            @Override // java.lang.Runnable
            public void run() {
                if (b.this.f750b.m() != null) {
                    b.this.f750b.o1(null);
                    b bVar = b.this;
                    bVar.f751c.a(bVar.f750b, bVar.f752d);
                }
            }
        }

        b(ViewGroup viewGroup, Fragment fragment, w.g gVar, c.f.h.a aVar) {
            this.a = viewGroup;
            this.f750b = fragment;
            this.f751c = gVar;
            this.f752d = aVar;
        }

        @Override // android.view.animation.Animation.AnimationListener
        public void onAnimationEnd(Animation animation) {
            this.a.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 {
        final /* synthetic */ ViewGroup a;

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

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

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

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        final /* synthetic */ c.f.h.a f757e;

        c(ViewGroup viewGroup, View view, Fragment fragment, w.g gVar, c.f.h.a aVar) {
            this.a = viewGroup;
            this.f754b = view;
            this.f755c = fragment;
            this.f756d = gVar;
            this.f757e = aVar;
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationEnd(Animator animator) {
            this.a.endViewTransition(this.f754b);
            Animator animatorN = this.f755c.n();
            this.f755c.p1(null);
            if (animatorN == null || this.a.indexOfChild(this.f754b) >= 0) {
                return;
            }
            this.f756d.a(this.f755c, this.f757e);
        }
    }

    static void a(Fragment fragment, d dVar, w.g gVar) {
        View view = fragment.L;
        ViewGroup viewGroup = fragment.K;
        viewGroup.startViewTransition(view);
        c.f.h.a aVar = new c.f.h.a();
        aVar.c(new a(fragment));
        gVar.b(fragment, aVar);
        if (dVar.a != null) {
            RunnableC0011e runnableC0011e = new RunnableC0011e(dVar.a, viewGroup, view);
            fragment.o1(fragment.L);
            runnableC0011e.setAnimationListener(new b(viewGroup, fragment, gVar, aVar));
            fragment.L.startAnimation(runnableC0011e);
            return;
        }
        Animator animator = dVar.f758b;
        fragment.p1(animator);
        animator.addListener(new c(viewGroup, view, fragment, gVar, aVar));
        animator.setTarget(fragment.L);
        animator.start();
    }

    static d b(Context context, Fragment fragment, boolean z) {
        int iB = fragment.B();
        int iA = fragment.A();
        boolean z2 = false;
        fragment.t1(0);
        ViewGroup viewGroup = fragment.K;
        if (viewGroup != null && viewGroup.getTag(c.i.b.visible_removing_fragment_view_tag) != null) {
            fragment.K.setTag(c.i.b.visible_removing_fragment_view_tag, null);
        }
        ViewGroup viewGroup2 = fragment.K;
        if (viewGroup2 != null && viewGroup2.getLayoutTransition() != null) {
            return null;
        }
        Animation animationK0 = fragment.k0(iB, z, iA);
        if (animationK0 != null) {
            return new d(animationK0);
        }
        Animator animatorL0 = fragment.l0(iB, z, iA);
        if (animatorL0 != null) {
            return new d(animatorL0);
        }
        if (iA == 0 && iB != 0) {
            iA = c(iB, z);
        }
        if (iA != 0) {
            boolean zEquals = "anim".equals(context.getResources().getResourceTypeName(iA));
            if (zEquals) {
                try {
                    Animation animationLoadAnimation = AnimationUtils.loadAnimation(context, iA);
                    if (animationLoadAnimation != null) {
                        return new d(animationLoadAnimation);
                    }
                    z2 = true;
                } catch (Resources.NotFoundException e2) {
                    throw e2;
                } catch (RuntimeException unused) {
                }
            }
            if (!z2) {
                try {
                    Animator animatorLoadAnimator = AnimatorInflater.loadAnimator(context, iA);
                    if (animatorLoadAnimator != null) {
                        return new d(animatorLoadAnimator);
                    }
                } catch (RuntimeException e3) {
                    if (zEquals) {
                        throw e3;
                    }
                    Animation animationLoadAnimation2 = AnimationUtils.loadAnimation(context, iA);
                    if (animationLoadAnimation2 != null) {
                        return new d(animationLoadAnimation2);
                    }
                }
            }
        }
        return null;
    }

    private static int c(int i2, boolean z) {
        if (i2 == 4097) {
            return z ? c.i.a.fragment_open_enter : c.i.a.fragment_open_exit;
        }
        if (i2 == 4099) {
            return z ? c.i.a.fragment_fade_enter : c.i.a.fragment_fade_exit;
        }
        if (i2 != 8194) {
            return -1;
        }
        return z ? c.i.a.fragment_close_enter : c.i.a.fragment_close_exit;
    }

    /* JADX INFO: compiled from: FragmentAnim.java */
    static class d {
        public final Animation a;

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

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

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

    /* JADX INFO: renamed from: androidx.fragment.app.e$e, reason: collision with other inner class name */
    /* JADX INFO: compiled from: FragmentAnim.java */
    static class RunnableC0011e extends AnimationSet implements Runnable {

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

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

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

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

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

        RunnableC0011e(Animation animation, ViewGroup viewGroup, View view) {
            super(false);
            this.f763i = true;
            this.f759b = viewGroup;
            this.f760f = view;
            addAnimation(animation);
            this.f759b.post(this);
        }

        @Override // android.view.animation.AnimationSet, android.view.animation.Animation
        public boolean getTransformation(long j2, Transformation transformation) {
            this.f763i = true;
            if (this.f761g) {
                return !this.f762h;
            }
            if (!super.getTransformation(j2, transformation)) {
                this.f761g = true;
                c.f.l.r.a(this.f759b, this);
            }
            return true;
        }

        @Override // java.lang.Runnable
        public void run() {
            if (this.f761g || !this.f763i) {
                this.f759b.endViewTransition(this.f760f);
                this.f762h = true;
            } else {
                this.f763i = false;
                this.f759b.post(this);
            }
        }

        @Override // android.view.animation.Animation
        public boolean getTransformation(long j2, Transformation transformation, float f2) {
            this.f763i = true;
            if (this.f761g) {
                return !this.f762h;
            }
            if (!super.getTransformation(j2, transformation, f2)) {
                this.f761g = true;
                c.f.l.r.a(this.f759b, this);
            }
            return true;
        }
    }
}
