package androidx.viewpager.widget;

import android.R;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.database.DataSetObserver;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.FocusFinder;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.SoundEffectConstants;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.accessibility.AccessibilityEvent;
import android.view.animation.Interpolator;
import android.widget.EdgeEffect;
import android.widget.Scroller;
import androidx.core.view.h0;
import androidx.core.view.h1;
import androidx.core.view.s0;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.firebase.crashlytics.internal.metadata.UserMetadata;
import com.google.firebase.perf.util.Constants;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/* loaded from: classes.dex */
public class ViewPager extends ViewGroup {

    /* renamed from: u0, reason: collision with root package name */
    static final int[] f5724u0 = {R.attr.layout_gravity};

    /* renamed from: v0, reason: collision with root package name */
    private static final Comparator f5725v0 = new a();

    /* renamed from: w0, reason: collision with root package name */
    private static final Interpolator f5726w0 = new b();

    /* renamed from: x0, reason: collision with root package name */
    private static final m f5727x0 = new m();
    private k A;
    private int B;
    private Drawable C;
    private int D;
    private int E;
    private float F;
    private float G;
    private int H;
    private int I;
    private boolean J;
    private boolean K;
    private boolean L;
    private int M;
    private boolean N;
    private boolean O;
    private int P;
    private int Q;
    private int R;
    private float S;
    private float T;
    private float U;
    private float V;
    private int W;

    /* renamed from: a0, reason: collision with root package name */
    private VelocityTracker f5728a0;

    /* renamed from: b0, reason: collision with root package name */
    private int f5729b0;

    /* renamed from: c0, reason: collision with root package name */
    private int f5730c0;

    /* renamed from: d0, reason: collision with root package name */
    private int f5731d0;

    /* renamed from: e0, reason: collision with root package name */
    private int f5732e0;

    /* renamed from: f0, reason: collision with root package name */
    private boolean f5733f0;

    /* renamed from: g0, reason: collision with root package name */
    private EdgeEffect f5734g0;

    /* renamed from: h0, reason: collision with root package name */
    private EdgeEffect f5735h0;

    /* renamed from: i0, reason: collision with root package name */
    private boolean f5736i0;

    /* renamed from: j0, reason: collision with root package name */
    private boolean f5737j0;

    /* renamed from: k0, reason: collision with root package name */
    private boolean f5738k0;

    /* renamed from: l0, reason: collision with root package name */
    private int f5739l0;

    /* renamed from: m0, reason: collision with root package name */
    private List f5740m0;

    /* renamed from: n0, reason: collision with root package name */
    private j f5741n0;

    /* renamed from: o0, reason: collision with root package name */
    private j f5742o0;

    /* renamed from: p, reason: collision with root package name */
    private int f5743p;

    /* renamed from: p0, reason: collision with root package name */
    private List f5744p0;

    /* renamed from: q, reason: collision with root package name */
    private final ArrayList f5745q;

    /* renamed from: q0, reason: collision with root package name */
    private int f5746q0;

    /* renamed from: r, reason: collision with root package name */
    private final f f5747r;

    /* renamed from: r0, reason: collision with root package name */
    private ArrayList f5748r0;

    /* renamed from: s, reason: collision with root package name */
    private final Rect f5749s;

    /* renamed from: s0, reason: collision with root package name */
    private final Runnable f5750s0;

    /* renamed from: t, reason: collision with root package name */
    androidx.viewpager.widget.a f5751t;

    /* renamed from: t0, reason: collision with root package name */
    private int f5752t0;

    /* renamed from: u, reason: collision with root package name */
    int f5753u;

    /* renamed from: v, reason: collision with root package name */
    private int f5754v;

    /* renamed from: w, reason: collision with root package name */
    private Parcelable f5755w;

    /* renamed from: x, reason: collision with root package name */
    private ClassLoader f5756x;

    /* renamed from: y, reason: collision with root package name */
    private Scroller f5757y;

    /* renamed from: z, reason: collision with root package name */
    private boolean f5758z;

    /* loaded from: classes.dex */
    static class a implements Comparator {
        a() {
        }

        @Override // java.util.Comparator
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public int compare(f fVar, f fVar2) {
            return fVar.f5763b - fVar2.f5763b;
        }
    }

    /* loaded from: classes.dex */
    static class b implements Interpolator {
        b() {
        }

        @Override // android.animation.TimeInterpolator
        public float getInterpolation(float f10) {
            float f11 = f10 - 1.0f;
            return (f11 * f11 * f11 * f11 * f11) + 1.0f;
        }
    }

    /* loaded from: classes.dex */
    class c implements Runnable {
        c() {
        }

        @Override // java.lang.Runnable
        public void run() {
            ViewPager.this.setScrollState(0);
            ViewPager.this.E();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class d implements h0 {

        /* renamed from: p, reason: collision with root package name */
        private final Rect f5760p = new Rect();

        d() {
        }

        @Override // androidx.core.view.h0
        public h1 a(View view, h1 h1Var) {
            h1 Y = s0.Y(view, h1Var);
            if (Y.o()) {
                return Y;
            }
            Rect rect = this.f5760p;
            rect.left = Y.j();
            rect.top = Y.l();
            rect.right = Y.k();
            rect.bottom = Y.i();
            int childCount = ViewPager.this.getChildCount();
            for (int i10 = 0; i10 < childCount; i10++) {
                h1 g10 = s0.g(ViewPager.this.getChildAt(i10), Y);
                rect.left = Math.min(g10.j(), rect.left);
                rect.top = Math.min(g10.l(), rect.top);
                rect.right = Math.min(g10.k(), rect.right);
                rect.bottom = Math.min(g10.i(), rect.bottom);
            }
            return Y.q(rect.left, rect.top, rect.right, rect.bottom);
        }
    }

    @Retention(RetentionPolicy.RUNTIME)
    /* loaded from: classes.dex */
    public @interface e {
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static class f {

        /* renamed from: a, reason: collision with root package name */
        Object f5762a;

        /* renamed from: b, reason: collision with root package name */
        int f5763b;

        /* renamed from: c, reason: collision with root package name */
        boolean f5764c;

        /* renamed from: d, reason: collision with root package name */
        float f5765d;

        /* renamed from: e, reason: collision with root package name */
        float f5766e;

        f() {
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class h extends androidx.core.view.a {
        h() {
        }

        private boolean n() {
            androidx.viewpager.widget.a aVar = ViewPager.this.f5751t;
            return aVar != null && aVar.c() > 1;
        }

        @Override // androidx.core.view.a
        public void f(View view, AccessibilityEvent accessibilityEvent) {
            androidx.viewpager.widget.a aVar;
            super.f(view, accessibilityEvent);
            accessibilityEvent.setClassName(ViewPager.class.getName());
            accessibilityEvent.setScrollable(n());
            if (accessibilityEvent.getEventType() != 4096 || (aVar = ViewPager.this.f5751t) == null) {
                return;
            }
            accessibilityEvent.setItemCount(aVar.c());
            accessibilityEvent.setFromIndex(ViewPager.this.f5753u);
            accessibilityEvent.setToIndex(ViewPager.this.f5753u);
        }

        @Override // androidx.core.view.a
        public void g(View view, t3.h hVar) {
            super.g(view, hVar);
            hVar.g0(ViewPager.class.getName());
            hVar.H0(n());
            if (ViewPager.this.canScrollHorizontally(1)) {
                hVar.a(4096);
            }
            if (ViewPager.this.canScrollHorizontally(-1)) {
                hVar.a(UserMetadata.MAX_INTERNAL_KEY_SIZE);
            }
        }

        @Override // androidx.core.view.a
        public boolean j(View view, int i10, Bundle bundle) {
            if (super.j(view, i10, bundle)) {
                return true;
            }
            if (i10 == 4096) {
                if (!ViewPager.this.canScrollHorizontally(1)) {
                    return false;
                }
                ViewPager viewPager = ViewPager.this;
                viewPager.setCurrentItem(viewPager.f5753u + 1);
                return true;
            }
            if (i10 != 8192 || !ViewPager.this.canScrollHorizontally(-1)) {
                return false;
            }
            ViewPager viewPager2 = ViewPager.this;
            viewPager2.setCurrentItem(viewPager2.f5753u - 1);
            return true;
        }
    }

    /* loaded from: classes.dex */
    public interface i {
        void a(ViewPager viewPager, androidx.viewpager.widget.a aVar, androidx.viewpager.widget.a aVar2);
    }

    /* loaded from: classes.dex */
    public interface j {
        void a(int i10, float f10, int i11);

        void b(int i10);

        void c(int i10);
    }

    /* loaded from: classes.dex */
    private class k extends DataSetObserver {
        k() {
        }

        @Override // android.database.DataSetObserver
        public void onChanged() {
            ViewPager.this.i();
        }

        @Override // android.database.DataSetObserver
        public void onInvalidated() {
            ViewPager.this.i();
        }
    }

    /* loaded from: classes.dex */
    public static class l extends z3.a {
        public static final Parcelable.Creator<l> CREATOR = new a();

        /* renamed from: r, reason: collision with root package name */
        int f5775r;

        /* renamed from: s, reason: collision with root package name */
        Parcelable f5776s;

        /* renamed from: t, reason: collision with root package name */
        ClassLoader f5777t;

        /* loaded from: classes.dex */
        static class a implements Parcelable.ClassLoaderCreator {
            a() {
            }

            @Override // android.os.Parcelable.Creator
            /* renamed from: a, reason: merged with bridge method [inline-methods] */
            public l createFromParcel(Parcel parcel) {
                return new l(parcel, null);
            }

            @Override // android.os.Parcelable.ClassLoaderCreator
            /* renamed from: b, reason: merged with bridge method [inline-methods] */
            public l createFromParcel(Parcel parcel, ClassLoader classLoader) {
                return new l(parcel, classLoader);
            }

            @Override // android.os.Parcelable.Creator
            /* renamed from: c, reason: merged with bridge method [inline-methods] */
            public l[] newArray(int i10) {
                return new l[i10];
            }
        }

        public l(Parcelable parcelable) {
            super(parcelable);
        }

        public String toString() {
            return "FragmentPager.SavedState{" + Integer.toHexString(System.identityHashCode(this)) + " position=" + this.f5775r + "}";
        }

        @Override // z3.a, android.os.Parcelable
        public void writeToParcel(Parcel parcel, int i10) {
            super.writeToParcel(parcel, i10);
            parcel.writeInt(this.f5775r);
            parcel.writeParcelable(this.f5776s, i10);
        }

        l(Parcel parcel, ClassLoader classLoader) {
            super(parcel, classLoader);
            classLoader = classLoader == null ? getClass().getClassLoader() : classLoader;
            this.f5775r = parcel.readInt();
            this.f5776s = parcel.readParcelable(classLoader);
            this.f5777t = classLoader;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static class m implements Comparator {
        m() {
        }

        @Override // java.util.Comparator
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public int compare(View view, View view2) {
            g gVar = (g) view.getLayoutParams();
            g gVar2 = (g) view2.getLayoutParams();
            boolean z10 = gVar.f5767a;
            return z10 != gVar2.f5767a ? z10 ? 1 : -1 : gVar.f5771e - gVar2.f5771e;
        }
    }

    public ViewPager(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f5745q = new ArrayList();
        this.f5747r = new f();
        this.f5749s = new Rect();
        this.f5754v = -1;
        this.f5755w = null;
        this.f5756x = null;
        this.F = -3.4028235E38f;
        this.G = Float.MAX_VALUE;
        this.M = 1;
        this.W = -1;
        this.f5736i0 = true;
        this.f5737j0 = false;
        this.f5750s0 = new c();
        this.f5752t0 = 0;
        v();
    }

    private boolean C(int i10) {
        if (this.f5745q.size() == 0) {
            if (this.f5736i0) {
                return false;
            }
            this.f5738k0 = false;
            y(0, BitmapDescriptorFactory.HUE_RED, 0);
            if (this.f5738k0) {
                return false;
            }
            throw new IllegalStateException("onPageScrolled did not call superclass implementation");
        }
        f t10 = t();
        int clientWidth = getClientWidth();
        int i11 = this.B;
        int i12 = clientWidth + i11;
        float f10 = clientWidth;
        int i13 = t10.f5763b;
        float f11 = ((i10 / f10) - t10.f5766e) / (t10.f5765d + (i11 / f10));
        this.f5738k0 = false;
        y(i13, f11, (int) (i12 * f11));
        if (this.f5738k0) {
            return true;
        }
        throw new IllegalStateException("onPageScrolled did not call superclass implementation");
    }

    private boolean D(float f10) {
        boolean z10;
        boolean z11;
        float f11 = this.S - f10;
        this.S = f10;
        float scrollX = getScrollX() + f11;
        float clientWidth = getClientWidth();
        float f12 = this.F * clientWidth;
        float f13 = this.G * clientWidth;
        boolean z12 = false;
        f fVar = (f) this.f5745q.get(0);
        ArrayList arrayList = this.f5745q;
        f fVar2 = (f) arrayList.get(arrayList.size() - 1);
        if (fVar.f5763b != 0) {
            f12 = fVar.f5766e * clientWidth;
            z10 = false;
        } else {
            z10 = true;
        }
        if (fVar2.f5763b != this.f5751t.c() - 1) {
            f13 = fVar2.f5766e * clientWidth;
            z11 = false;
        } else {
            z11 = true;
        }
        if (scrollX < f12) {
            if (z10) {
                this.f5734g0.onPull(Math.abs(f12 - scrollX) / clientWidth);
                z12 = true;
            }
            scrollX = f12;
        } else if (scrollX > f13) {
            if (z11) {
                this.f5735h0.onPull(Math.abs(scrollX - f13) / clientWidth);
                z12 = true;
            }
            scrollX = f13;
        }
        int i10 = (int) scrollX;
        this.S += scrollX - i10;
        scrollTo(i10, getScrollY());
        C(i10);
        return z12;
    }

    private void G(int i10, int i11, int i12, int i13) {
        if (i11 > 0 && !this.f5745q.isEmpty()) {
            if (!this.f5757y.isFinished()) {
                this.f5757y.setFinalX(getCurrentItem() * getClientWidth());
                return;
            } else {
                scrollTo((int) ((getScrollX() / (((i11 - getPaddingLeft()) - getPaddingRight()) + i13)) * (((i10 - getPaddingLeft()) - getPaddingRight()) + i12)), getScrollY());
                return;
            }
        }
        f u10 = u(this.f5753u);
        int min = (int) ((u10 != null ? Math.min(u10.f5766e, this.G) : BitmapDescriptorFactory.HUE_RED) * ((i10 - getPaddingLeft()) - getPaddingRight()));
        if (min != getScrollX()) {
            h(false);
            scrollTo(min, getScrollY());
        }
    }

    private void H() {
        int i10 = 0;
        while (i10 < getChildCount()) {
            if (!((g) getChildAt(i10).getLayoutParams()).f5767a) {
                removeViewAt(i10);
                i10--;
            }
            i10++;
        }
    }

    private void K(boolean z10) {
        ViewParent parent = getParent();
        if (parent != null) {
            parent.requestDisallowInterceptTouchEvent(z10);
        }
    }

    private boolean L() {
        this.W = -1;
        o();
        this.f5734g0.onRelease();
        this.f5735h0.onRelease();
        return this.f5734g0.isFinished() || this.f5735h0.isFinished();
    }

    private void M(int i10, boolean z10, int i11, boolean z11) {
        f u10 = u(i10);
        int clientWidth = u10 != null ? (int) (getClientWidth() * Math.max(this.F, Math.min(u10.f5766e, this.G))) : 0;
        if (z10) {
            Q(clientWidth, 0, i11);
            if (z11) {
                l(i10);
                return;
            }
            return;
        }
        if (z11) {
            l(i10);
        }
        h(false);
        scrollTo(clientWidth, 0);
        C(clientWidth);
    }

    private void R() {
        if (this.f5746q0 != 0) {
            ArrayList arrayList = this.f5748r0;
            if (arrayList == null) {
                this.f5748r0 = new ArrayList();
            } else {
                arrayList.clear();
            }
            int childCount = getChildCount();
            for (int i10 = 0; i10 < childCount; i10++) {
                this.f5748r0.add(getChildAt(i10));
            }
            Collections.sort(this.f5748r0, f5727x0);
        }
    }

    private void e(f fVar, int i10, f fVar2) {
        int i11;
        int i12;
        f fVar3;
        f fVar4;
        int c10 = this.f5751t.c();
        int clientWidth = getClientWidth();
        float f10 = clientWidth > 0 ? this.B / clientWidth : BitmapDescriptorFactory.HUE_RED;
        if (fVar2 != null) {
            int i13 = fVar2.f5763b;
            int i14 = fVar.f5763b;
            if (i13 < i14) {
                float f11 = fVar2.f5766e + fVar2.f5765d + f10;
                int i15 = i13 + 1;
                int i16 = 0;
                while (i15 <= fVar.f5763b && i16 < this.f5745q.size()) {
                    Object obj = this.f5745q.get(i16);
                    while (true) {
                        fVar4 = (f) obj;
                        if (i15 <= fVar4.f5763b || i16 >= this.f5745q.size() - 1) {
                            break;
                        }
                        i16++;
                        obj = this.f5745q.get(i16);
                    }
                    while (i15 < fVar4.f5763b) {
                        f11 += this.f5751t.f(i15) + f10;
                        i15++;
                    }
                    fVar4.f5766e = f11;
                    f11 += fVar4.f5765d + f10;
                    i15++;
                }
            } else if (i13 > i14) {
                int size = this.f5745q.size() - 1;
                float f12 = fVar2.f5766e;
                while (true) {
                    i13--;
                    if (i13 < fVar.f5763b || size < 0) {
                        break;
                    }
                    Object obj2 = this.f5745q.get(size);
                    while (true) {
                        fVar3 = (f) obj2;
                        if (i13 >= fVar3.f5763b || size <= 0) {
                            break;
                        }
                        size--;
                        obj2 = this.f5745q.get(size);
                    }
                    while (i13 > fVar3.f5763b) {
                        f12 -= this.f5751t.f(i13) + f10;
                        i13--;
                    }
                    f12 -= fVar3.f5765d + f10;
                    fVar3.f5766e = f12;
                }
            }
        }
        int size2 = this.f5745q.size();
        float f13 = fVar.f5766e;
        int i17 = fVar.f5763b;
        int i18 = i17 - 1;
        this.F = i17 == 0 ? f13 : -3.4028235E38f;
        int i19 = c10 - 1;
        this.G = i17 == i19 ? (fVar.f5765d + f13) - 1.0f : Float.MAX_VALUE;
        int i20 = i10 - 1;
        while (i20 >= 0) {
            f fVar5 = (f) this.f5745q.get(i20);
            while (true) {
                i12 = fVar5.f5763b;
                if (i18 <= i12) {
                    break;
                }
                f13 -= this.f5751t.f(i18) + f10;
                i18--;
            }
            f13 -= fVar5.f5765d + f10;
            fVar5.f5766e = f13;
            if (i12 == 0) {
                this.F = f13;
            }
            i20--;
            i18--;
        }
        float f14 = fVar.f5766e + fVar.f5765d + f10;
        int i21 = fVar.f5763b + 1;
        int i22 = i10 + 1;
        while (i22 < size2) {
            f fVar6 = (f) this.f5745q.get(i22);
            while (true) {
                i11 = fVar6.f5763b;
                if (i21 >= i11) {
                    break;
                }
                f14 += this.f5751t.f(i21) + f10;
                i21++;
            }
            if (i11 == i19) {
                this.G = (fVar6.f5765d + f14) - 1.0f;
            }
            fVar6.f5766e = f14;
            f14 += fVar6.f5765d + f10;
            i22++;
            i21++;
        }
        this.f5737j0 = false;
    }

    private int getClientWidth() {
        return (getMeasuredWidth() - getPaddingLeft()) - getPaddingRight();
    }

    private void h(boolean z10) {
        boolean z11 = this.f5752t0 == 2;
        if (z11) {
            setScrollingCacheEnabled(false);
            if (!this.f5757y.isFinished()) {
                this.f5757y.abortAnimation();
                int scrollX = getScrollX();
                int scrollY = getScrollY();
                int currX = this.f5757y.getCurrX();
                int currY = this.f5757y.getCurrY();
                if (scrollX != currX || scrollY != currY) {
                    scrollTo(currX, currY);
                    if (currX != scrollX) {
                        C(currX);
                    }
                }
            }
        }
        this.L = false;
        for (int i10 = 0; i10 < this.f5745q.size(); i10++) {
            f fVar = (f) this.f5745q.get(i10);
            if (fVar.f5764c) {
                fVar.f5764c = false;
                z11 = true;
            }
        }
        if (z11) {
            if (z10) {
                s0.e0(this, this.f5750s0);
            } else {
                this.f5750s0.run();
            }
        }
    }

    private int j(int i10, float f10, int i11, int i12) {
        if (Math.abs(i12) <= this.f5731d0 || Math.abs(i11) <= this.f5729b0) {
            i10 += (int) (f10 + (i10 >= this.f5753u ? 0.4f : 0.6f));
        } else if (i11 <= 0) {
            i10++;
        }
        if (this.f5745q.size() <= 0) {
            return i10;
        }
        return Math.max(((f) this.f5745q.get(0)).f5763b, Math.min(i10, ((f) this.f5745q.get(r1.size() - 1)).f5763b));
    }

    private void k(int i10, float f10, int i11) {
        j jVar = this.f5741n0;
        if (jVar != null) {
            jVar.a(i10, f10, i11);
        }
        List list = this.f5740m0;
        if (list != null) {
            int size = list.size();
            for (int i12 = 0; i12 < size; i12++) {
                j jVar2 = (j) this.f5740m0.get(i12);
                if (jVar2 != null) {
                    jVar2.a(i10, f10, i11);
                }
            }
        }
        j jVar3 = this.f5742o0;
        if (jVar3 != null) {
            jVar3.a(i10, f10, i11);
        }
    }

    private void l(int i10) {
        j jVar = this.f5741n0;
        if (jVar != null) {
            jVar.c(i10);
        }
        List list = this.f5740m0;
        if (list != null) {
            int size = list.size();
            for (int i11 = 0; i11 < size; i11++) {
                j jVar2 = (j) this.f5740m0.get(i11);
                if (jVar2 != null) {
                    jVar2.c(i10);
                }
            }
        }
        j jVar3 = this.f5742o0;
        if (jVar3 != null) {
            jVar3.c(i10);
        }
    }

    private void m(int i10) {
        j jVar = this.f5741n0;
        if (jVar != null) {
            jVar.b(i10);
        }
        List list = this.f5740m0;
        if (list != null) {
            int size = list.size();
            for (int i11 = 0; i11 < size; i11++) {
                j jVar2 = (j) this.f5740m0.get(i11);
                if (jVar2 != null) {
                    jVar2.b(i10);
                }
            }
        }
        j jVar3 = this.f5742o0;
        if (jVar3 != null) {
            jVar3.b(i10);
        }
    }

    private void o() {
        this.N = false;
        this.O = false;
        VelocityTracker velocityTracker = this.f5728a0;
        if (velocityTracker != null) {
            velocityTracker.recycle();
            this.f5728a0 = null;
        }
    }

    private Rect q(Rect rect, View view) {
        if (rect == null) {
            rect = new Rect();
        }
        if (view == null) {
            rect.set(0, 0, 0, 0);
            return rect;
        }
        rect.left = view.getLeft();
        rect.right = view.getRight();
        rect.top = view.getTop();
        rect.bottom = view.getBottom();
        ViewParent parent = view.getParent();
        while ((parent instanceof ViewGroup) && parent != this) {
            ViewGroup viewGroup = (ViewGroup) parent;
            rect.left += viewGroup.getLeft();
            rect.right += viewGroup.getRight();
            rect.top += viewGroup.getTop();
            rect.bottom += viewGroup.getBottom();
            parent = viewGroup.getParent();
        }
        return rect;
    }

    private void setScrollingCacheEnabled(boolean z10) {
        if (this.K != z10) {
            this.K = z10;
        }
    }

    private f t() {
        int i10;
        int clientWidth = getClientWidth();
        float f10 = BitmapDescriptorFactory.HUE_RED;
        float scrollX = clientWidth > 0 ? getScrollX() / clientWidth : 0.0f;
        float f11 = clientWidth > 0 ? this.B / clientWidth : 0.0f;
        int i11 = 0;
        boolean z10 = true;
        f fVar = null;
        int i12 = -1;
        float f12 = 0.0f;
        while (i11 < this.f5745q.size()) {
            f fVar2 = (f) this.f5745q.get(i11);
            if (!z10 && fVar2.f5763b != (i10 = i12 + 1)) {
                fVar2 = this.f5747r;
                fVar2.f5766e = f10 + f12 + f11;
                fVar2.f5763b = i10;
                fVar2.f5765d = this.f5751t.f(i10);
                i11--;
            }
            f fVar3 = fVar2;
            f10 = fVar3.f5766e;
            float f13 = fVar3.f5765d + f10 + f11;
            if (!z10 && scrollX < f10) {
                return fVar;
            }
            if (scrollX < f13 || i11 == this.f5745q.size() - 1) {
                return fVar3;
            }
            int i13 = fVar3.f5763b;
            float f14 = fVar3.f5765d;
            i11++;
            z10 = false;
            i12 = i13;
            f12 = f14;
            fVar = fVar3;
        }
        return fVar;
    }

    private static boolean w(View view) {
        return view.getClass().getAnnotation(e.class) != null;
    }

    private boolean x(float f10, float f11) {
        return (f10 < ((float) this.Q) && f11 > BitmapDescriptorFactory.HUE_RED) || (f10 > ((float) (getWidth() - this.Q)) && f11 < BitmapDescriptorFactory.HUE_RED);
    }

    private void z(MotionEvent motionEvent) {
        int actionIndex = motionEvent.getActionIndex();
        if (motionEvent.getPointerId(actionIndex) == this.W) {
            int i10 = actionIndex == 0 ? 1 : 0;
            this.S = motionEvent.getX(i10);
            this.W = motionEvent.getPointerId(i10);
            VelocityTracker velocityTracker = this.f5728a0;
            if (velocityTracker != null) {
                velocityTracker.clear();
            }
        }
    }

    boolean A() {
        int i10 = this.f5753u;
        if (i10 <= 0) {
            return false;
        }
        N(i10 - 1, true);
        return true;
    }

    boolean B() {
        androidx.viewpager.widget.a aVar = this.f5751t;
        if (aVar == null || this.f5753u >= aVar.c() - 1) {
            return false;
        }
        N(this.f5753u + 1, true);
        return true;
    }

    void E() {
        F(this.f5753u);
    }

    /* JADX WARN: Code restructure failed: missing block: B:25:0x0060, code lost:
    
        if (r9 == r10) goto L28;
     */
    /* JADX WARN: Code restructure failed: missing block: B:26:0x0066, code lost:
    
        r8 = null;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    void F(int i10) {
        f fVar;
        String hexString;
        f fVar2;
        f s10;
        f fVar3;
        int i11 = this.f5753u;
        if (i11 != i10) {
            fVar = u(i11);
            this.f5753u = i10;
        } else {
            fVar = null;
        }
        if (this.f5751t == null) {
            R();
            return;
        }
        if (this.L) {
            R();
            return;
        }
        if (getWindowToken() == null) {
            return;
        }
        this.f5751t.n(this);
        int i12 = this.M;
        int max = Math.max(0, this.f5753u - i12);
        int c10 = this.f5751t.c();
        int min = Math.min(c10 - 1, this.f5753u + i12);
        if (c10 != this.f5743p) {
            try {
                hexString = getResources().getResourceName(getId());
            } catch (Resources.NotFoundException unused) {
                hexString = Integer.toHexString(getId());
            }
            throw new IllegalStateException("The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged! Expected adapter item count: " + this.f5743p + ", found: " + c10 + " Pager id: " + hexString + " Pager class: " + getClass() + " Problematic adapter: " + this.f5751t.getClass());
        }
        int i13 = 0;
        while (true) {
            if (i13 >= this.f5745q.size()) {
                break;
            }
            fVar2 = (f) this.f5745q.get(i13);
            int i14 = fVar2.f5763b;
            int i15 = this.f5753u;
            if (i14 < i15) {
                i13++;
            }
        }
        if (fVar2 == null && c10 > 0) {
            fVar2 = a(this.f5753u, i13);
        }
        if (fVar2 != null) {
            int i16 = i13 - 1;
            f fVar4 = i16 >= 0 ? (f) this.f5745q.get(i16) : null;
            int clientWidth = getClientWidth();
            float paddingLeft = clientWidth <= 0 ? 0.0f : (2.0f - fVar2.f5765d) + (getPaddingLeft() / clientWidth);
            float f10 = 0.0f;
            for (int i17 = this.f5753u - 1; i17 >= 0; i17--) {
                if (f10 >= paddingLeft && i17 < max) {
                    if (fVar4 == null) {
                        break;
                    }
                    if (i17 == fVar4.f5763b && !fVar4.f5764c) {
                        this.f5745q.remove(i16);
                        this.f5751t.a(this, i17, fVar4.f5762a);
                        i16--;
                        i13--;
                        if (i16 >= 0) {
                            fVar3 = (f) this.f5745q.get(i16);
                            fVar4 = fVar3;
                        }
                        fVar3 = null;
                        fVar4 = fVar3;
                    }
                } else if (fVar4 == null || i17 != fVar4.f5763b) {
                    f10 += a(i17, i16 + 1).f5765d;
                    i13++;
                    if (i16 >= 0) {
                        fVar3 = (f) this.f5745q.get(i16);
                        fVar4 = fVar3;
                    }
                    fVar3 = null;
                    fVar4 = fVar3;
                } else {
                    f10 += fVar4.f5765d;
                    i16--;
                    if (i16 >= 0) {
                        fVar3 = (f) this.f5745q.get(i16);
                        fVar4 = fVar3;
                    }
                    fVar3 = null;
                    fVar4 = fVar3;
                }
            }
            float f11 = fVar2.f5765d;
            int i18 = i13 + 1;
            if (f11 < 2.0f) {
                f fVar5 = i18 < this.f5745q.size() ? (f) this.f5745q.get(i18) : null;
                float paddingRight = clientWidth <= 0 ? 0.0f : (getPaddingRight() / clientWidth) + 2.0f;
                int i19 = this.f5753u;
                while (true) {
                    i19++;
                    if (i19 >= c10) {
                        break;
                    }
                    if (f11 >= paddingRight && i19 > min) {
                        if (fVar5 == null) {
                            break;
                        }
                        if (i19 == fVar5.f5763b && !fVar5.f5764c) {
                            this.f5745q.remove(i18);
                            this.f5751t.a(this, i19, fVar5.f5762a);
                            if (i18 < this.f5745q.size()) {
                                fVar5 = (f) this.f5745q.get(i18);
                            }
                        }
                    } else if (fVar5 == null || i19 != fVar5.f5763b) {
                        f a10 = a(i19, i18);
                        i18++;
                        f11 += a10.f5765d;
                        fVar5 = i18 < this.f5745q.size() ? (f) this.f5745q.get(i18) : null;
                    } else {
                        f11 += fVar5.f5765d;
                        i18++;
                        if (i18 < this.f5745q.size()) {
                            fVar5 = (f) this.f5745q.get(i18);
                        }
                    }
                }
            }
            e(fVar2, i13, fVar);
            this.f5751t.l(this, this.f5753u, fVar2.f5762a);
        }
        this.f5751t.b(this);
        int childCount = getChildCount();
        for (int i20 = 0; i20 < childCount; i20++) {
            View childAt = getChildAt(i20);
            g gVar = (g) childAt.getLayoutParams();
            gVar.f5772f = i20;
            if (!gVar.f5767a && gVar.f5769c == BitmapDescriptorFactory.HUE_RED && (s10 = s(childAt)) != null) {
                gVar.f5769c = s10.f5765d;
                gVar.f5771e = s10.f5763b;
            }
        }
        R();
        if (hasFocus()) {
            View findFocus = findFocus();
            f r10 = findFocus != null ? r(findFocus) : null;
            if (r10 == null || r10.f5763b != this.f5753u) {
                for (int i21 = 0; i21 < getChildCount(); i21++) {
                    View childAt2 = getChildAt(i21);
                    f s11 = s(childAt2);
                    if (s11 != null && s11.f5763b == this.f5753u && childAt2.requestFocus(2)) {
                        return;
                    }
                }
            }
        }
    }

    public void I(i iVar) {
        List list = this.f5744p0;
        if (list != null) {
            list.remove(iVar);
        }
    }

    public void J(j jVar) {
        List list = this.f5740m0;
        if (list != null) {
            list.remove(jVar);
        }
    }

    public void N(int i10, boolean z10) {
        this.L = false;
        O(i10, z10, false);
    }

    void O(int i10, boolean z10, boolean z11) {
        P(i10, z10, z11, 0);
    }

    void P(int i10, boolean z10, boolean z11, int i11) {
        androidx.viewpager.widget.a aVar = this.f5751t;
        if (aVar == null || aVar.c() <= 0) {
            setScrollingCacheEnabled(false);
            return;
        }
        if (!z11 && this.f5753u == i10 && this.f5745q.size() != 0) {
            setScrollingCacheEnabled(false);
            return;
        }
        if (i10 < 0) {
            i10 = 0;
        } else if (i10 >= this.f5751t.c()) {
            i10 = this.f5751t.c() - 1;
        }
        int i12 = this.M;
        int i13 = this.f5753u;
        if (i10 > i13 + i12 || i10 < i13 - i12) {
            for (int i14 = 0; i14 < this.f5745q.size(); i14++) {
                ((f) this.f5745q.get(i14)).f5764c = true;
            }
        }
        boolean z12 = this.f5753u != i10;
        if (!this.f5736i0) {
            F(i10);
            M(i10, z10, i11, z12);
        } else {
            this.f5753u = i10;
            if (z12) {
                l(i10);
            }
            requestLayout();
        }
    }

    void Q(int i10, int i11, int i12) {
        int scrollX;
        if (getChildCount() == 0) {
            setScrollingCacheEnabled(false);
            return;
        }
        Scroller scroller = this.f5757y;
        if ((scroller == null || scroller.isFinished()) ? false : true) {
            scrollX = this.f5758z ? this.f5757y.getCurrX() : this.f5757y.getStartX();
            this.f5757y.abortAnimation();
            setScrollingCacheEnabled(false);
        } else {
            scrollX = getScrollX();
        }
        int i13 = scrollX;
        int scrollY = getScrollY();
        int i14 = i10 - i13;
        int i15 = i11 - scrollY;
        if (i14 == 0 && i15 == 0) {
            h(false);
            E();
            setScrollState(0);
            return;
        }
        setScrollingCacheEnabled(true);
        setScrollState(2);
        int clientWidth = getClientWidth();
        int i16 = clientWidth / 2;
        float f10 = clientWidth;
        float f11 = i16;
        float n10 = f11 + (n(Math.min(1.0f, (Math.abs(i14) * 1.0f) / f10)) * f11);
        int abs = Math.abs(i12);
        int min = Math.min(abs > 0 ? Math.round(Math.abs(n10 / abs) * 1000.0f) * 4 : (int) (((Math.abs(i14) / ((f10 * this.f5751t.f(this.f5753u)) + this.B)) + 1.0f) * 100.0f), 600);
        this.f5758z = false;
        this.f5757y.startScroll(i13, scrollY, i14, i15, min);
        s0.d0(this);
    }

    f a(int i10, int i11) {
        f fVar = new f();
        fVar.f5763b = i10;
        fVar.f5762a = this.f5751t.g(this, i10);
        fVar.f5765d = this.f5751t.f(i10);
        if (i11 < 0 || i11 >= this.f5745q.size()) {
            this.f5745q.add(fVar);
        } else {
            this.f5745q.add(i11, fVar);
        }
        return fVar;
    }

    @Override // android.view.ViewGroup, android.view.View
    public void addFocusables(ArrayList arrayList, int i10, int i11) {
        f s10;
        int size = arrayList.size();
        int descendantFocusability = getDescendantFocusability();
        if (descendantFocusability != 393216) {
            for (int i12 = 0; i12 < getChildCount(); i12++) {
                View childAt = getChildAt(i12);
                if (childAt.getVisibility() == 0 && (s10 = s(childAt)) != null && s10.f5763b == this.f5753u) {
                    childAt.addFocusables(arrayList, i10, i11);
                }
            }
        }
        if ((descendantFocusability != 262144 || size == arrayList.size()) && isFocusable()) {
            if ((i11 & 1) == 1 && isInTouchMode() && !isFocusableInTouchMode()) {
                return;
            }
            arrayList.add(this);
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public void addTouchables(ArrayList arrayList) {
        f s10;
        for (int i10 = 0; i10 < getChildCount(); i10++) {
            View childAt = getChildAt(i10);
            if (childAt.getVisibility() == 0 && (s10 = s(childAt)) != null && s10.f5763b == this.f5753u) {
                childAt.addTouchables(arrayList);
            }
        }
    }

    @Override // android.view.ViewGroup
    public void addView(View view, int i10, ViewGroup.LayoutParams layoutParams) {
        if (!checkLayoutParams(layoutParams)) {
            layoutParams = generateLayoutParams(layoutParams);
        }
        g gVar = (g) layoutParams;
        boolean w10 = gVar.f5767a | w(view);
        gVar.f5767a = w10;
        if (!this.J) {
            super.addView(view, i10, layoutParams);
        } else {
            if (w10) {
                throw new IllegalStateException("Cannot add pager decor view during layout");
            }
            gVar.f5770d = true;
            addViewInLayout(view, i10, layoutParams);
        }
    }

    public void b(i iVar) {
        if (this.f5744p0 == null) {
            this.f5744p0 = new ArrayList();
        }
        this.f5744p0.add(iVar);
    }

    public void c(j jVar) {
        if (this.f5740m0 == null) {
            this.f5740m0 = new ArrayList();
        }
        this.f5740m0.add(jVar);
    }

    @Override // android.view.View
    public boolean canScrollHorizontally(int i10) {
        if (this.f5751t == null) {
            return false;
        }
        int clientWidth = getClientWidth();
        int scrollX = getScrollX();
        return i10 < 0 ? scrollX > ((int) (((float) clientWidth) * this.F)) : i10 > 0 && scrollX < ((int) (((float) clientWidth) * this.G));
    }

    @Override // android.view.ViewGroup
    protected boolean checkLayoutParams(ViewGroup.LayoutParams layoutParams) {
        return (layoutParams instanceof g) && super.checkLayoutParams(layoutParams);
    }

    @Override // android.view.View
    public void computeScroll() {
        this.f5758z = true;
        if (this.f5757y.isFinished() || !this.f5757y.computeScrollOffset()) {
            h(true);
            return;
        }
        int scrollX = getScrollX();
        int scrollY = getScrollY();
        int currX = this.f5757y.getCurrX();
        int currY = this.f5757y.getCurrY();
        if (scrollX != currX || scrollY != currY) {
            scrollTo(currX, currY);
            if (!C(currX)) {
                this.f5757y.abortAnimation();
                scrollTo(0, currY);
            }
        }
        s0.d0(this);
    }

    /* JADX WARN: Removed duplicated region for block: B:14:0x00cf  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public boolean d(int i10) {
        boolean z10;
        View findNextFocus;
        boolean requestFocus;
        View findFocus = findFocus();
        boolean z11 = false;
        if (findFocus != this) {
            if (findFocus != null) {
                ViewParent parent = findFocus.getParent();
                while (true) {
                    if (!(parent instanceof ViewGroup)) {
                        z10 = false;
                        break;
                    }
                    if (parent == this) {
                        z10 = true;
                        break;
                    }
                    parent = parent.getParent();
                }
                if (!z10) {
                    StringBuilder sb2 = new StringBuilder();
                    sb2.append(findFocus.getClass().getSimpleName());
                    for (ViewParent parent2 = findFocus.getParent(); parent2 instanceof ViewGroup; parent2 = parent2.getParent()) {
                        sb2.append(" => ");
                        sb2.append(parent2.getClass().getSimpleName());
                    }
                    Log.e("ViewPager", "arrowScroll tried to find focus based on non-child current focused view " + sb2.toString());
                }
            }
            findNextFocus = FocusFinder.getInstance().findNextFocus(this, findFocus, i10);
            if (findNextFocus == null && findNextFocus != findFocus) {
                if (i10 == 17) {
                    requestFocus = (findFocus == null || q(this.f5749s, findNextFocus).left < q(this.f5749s, findFocus).left) ? findNextFocus.requestFocus() : A();
                } else if (i10 == 66) {
                    requestFocus = (findFocus == null || q(this.f5749s, findNextFocus).left > q(this.f5749s, findFocus).left) ? findNextFocus.requestFocus() : B();
                }
                z11 = requestFocus;
            } else if (i10 != 17 || i10 == 1) {
                z11 = A();
            } else if (i10 == 66 || i10 == 2) {
                z11 = B();
            }
            if (z11) {
                playSoundEffect(SoundEffectConstants.getContantForFocusDirection(i10));
            }
            return z11;
        }
        findFocus = null;
        findNextFocus = FocusFinder.getInstance().findNextFocus(this, findFocus, i10);
        if (findNextFocus == null) {
        }
        if (i10 != 17) {
        }
        z11 = A();
        if (z11) {
        }
        return z11;
    }

    @Override // android.view.ViewGroup, android.view.View
    public boolean dispatchKeyEvent(KeyEvent keyEvent) {
        return super.dispatchKeyEvent(keyEvent) || p(keyEvent);
    }

    @Override // android.view.View
    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
        f s10;
        if (accessibilityEvent.getEventType() == 4096) {
            return super.dispatchPopulateAccessibilityEvent(accessibilityEvent);
        }
        int childCount = getChildCount();
        for (int i10 = 0; i10 < childCount; i10++) {
            View childAt = getChildAt(i10);
            if (childAt.getVisibility() == 0 && (s10 = s(childAt)) != null && s10.f5763b == this.f5753u && childAt.dispatchPopulateAccessibilityEvent(accessibilityEvent)) {
                return true;
            }
        }
        return false;
    }

    @Override // android.view.View
    public void draw(Canvas canvas) {
        androidx.viewpager.widget.a aVar;
        super.draw(canvas);
        int overScrollMode = getOverScrollMode();
        boolean z10 = false;
        if (overScrollMode == 0 || (overScrollMode == 1 && (aVar = this.f5751t) != null && aVar.c() > 1)) {
            if (!this.f5734g0.isFinished()) {
                int save = canvas.save();
                int height = (getHeight() - getPaddingTop()) - getPaddingBottom();
                int width = getWidth();
                canvas.rotate(270.0f);
                canvas.translate((-height) + getPaddingTop(), this.F * width);
                this.f5734g0.setSize(height, width);
                z10 = false | this.f5734g0.draw(canvas);
                canvas.restoreToCount(save);
            }
            if (!this.f5735h0.isFinished()) {
                int save2 = canvas.save();
                int width2 = getWidth();
                int height2 = (getHeight() - getPaddingTop()) - getPaddingBottom();
                canvas.rotate(90.0f);
                canvas.translate(-getPaddingTop(), (-(this.G + 1.0f)) * width2);
                this.f5735h0.setSize(height2, width2);
                z10 |= this.f5735h0.draw(canvas);
                canvas.restoreToCount(save2);
            }
        } else {
            this.f5734g0.finish();
            this.f5735h0.finish();
        }
        if (z10) {
            s0.d0(this);
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    protected void drawableStateChanged() {
        super.drawableStateChanged();
        Drawable drawable = this.C;
        if (drawable == null || !drawable.isStateful()) {
            return;
        }
        drawable.setState(getDrawableState());
    }

    protected boolean f(View view, boolean z10, int i10, int i11, int i12) {
        int i13;
        if (view instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) view;
            int scrollX = view.getScrollX();
            int scrollY = view.getScrollY();
            for (int childCount = viewGroup.getChildCount() - 1; childCount >= 0; childCount--) {
                View childAt = viewGroup.getChildAt(childCount);
                int i14 = i11 + scrollX;
                if (i14 >= childAt.getLeft() && i14 < childAt.getRight() && (i13 = i12 + scrollY) >= childAt.getTop() && i13 < childAt.getBottom() && f(childAt, true, i10, i14 - childAt.getLeft(), i13 - childAt.getTop())) {
                    return true;
                }
            }
        }
        return z10 && view.canScrollHorizontally(-i10);
    }

    public void g() {
        List list = this.f5740m0;
        if (list != null) {
            list.clear();
        }
    }

    @Override // android.view.ViewGroup
    protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
        return new g();
    }

    @Override // android.view.ViewGroup
    protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams layoutParams) {
        return generateDefaultLayoutParams();
    }

    public androidx.viewpager.widget.a getAdapter() {
        return this.f5751t;
    }

    @Override // android.view.ViewGroup
    protected int getChildDrawingOrder(int i10, int i11) {
        if (this.f5746q0 == 2) {
            i11 = (i10 - 1) - i11;
        }
        return ((g) ((View) this.f5748r0.get(i11)).getLayoutParams()).f5772f;
    }

    public int getCurrentItem() {
        return this.f5753u;
    }

    public int getOffscreenPageLimit() {
        return this.M;
    }

    public int getPageMargin() {
        return this.B;
    }

    void i() {
        int c10 = this.f5751t.c();
        this.f5743p = c10;
        boolean z10 = this.f5745q.size() < (this.M * 2) + 1 && this.f5745q.size() < c10;
        int i10 = this.f5753u;
        int i11 = 0;
        boolean z11 = false;
        while (i11 < this.f5745q.size()) {
            f fVar = (f) this.f5745q.get(i11);
            int d10 = this.f5751t.d(fVar.f5762a);
            if (d10 != -1) {
                if (d10 == -2) {
                    this.f5745q.remove(i11);
                    i11--;
                    if (!z11) {
                        this.f5751t.n(this);
                        z11 = true;
                    }
                    this.f5751t.a(this, fVar.f5763b, fVar.f5762a);
                    int i12 = this.f5753u;
                    if (i12 == fVar.f5763b) {
                        i10 = Math.max(0, Math.min(i12, c10 - 1));
                    }
                } else {
                    int i13 = fVar.f5763b;
                    if (i13 != d10) {
                        if (i13 == this.f5753u) {
                            i10 = d10;
                        }
                        fVar.f5763b = d10;
                    }
                }
                z10 = true;
            }
            i11++;
        }
        if (z11) {
            this.f5751t.b(this);
        }
        Collections.sort(this.f5745q, f5725v0);
        if (z10) {
            int childCount = getChildCount();
            for (int i14 = 0; i14 < childCount; i14++) {
                g gVar = (g) getChildAt(i14).getLayoutParams();
                if (!gVar.f5767a) {
                    gVar.f5769c = BitmapDescriptorFactory.HUE_RED;
                }
            }
            O(i10, false, true);
            requestLayout();
        }
    }

    float n(float f10) {
        return (float) Math.sin((f10 - 0.5f) * 0.47123894f);
    }

    @Override // android.view.ViewGroup, android.view.View
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        this.f5736i0 = true;
    }

    @Override // android.view.ViewGroup, android.view.View
    protected void onDetachedFromWindow() {
        removeCallbacks(this.f5750s0);
        Scroller scroller = this.f5757y;
        if (scroller != null && !scroller.isFinished()) {
            this.f5757y.abortAnimation();
        }
        super.onDetachedFromWindow();
    }

    @Override // android.view.View
    protected void onDraw(Canvas canvas) {
        int i10;
        float f10;
        float f11;
        super.onDraw(canvas);
        if (this.B <= 0 || this.C == null || this.f5745q.size() <= 0 || this.f5751t == null) {
            return;
        }
        int scrollX = getScrollX();
        float width = getWidth();
        float f12 = this.B / width;
        int i11 = 0;
        f fVar = (f) this.f5745q.get(0);
        float f13 = fVar.f5766e;
        int size = this.f5745q.size();
        int i12 = fVar.f5763b;
        int i13 = ((f) this.f5745q.get(size - 1)).f5763b;
        while (i12 < i13) {
            while (true) {
                i10 = fVar.f5763b;
                if (i12 <= i10 || i11 >= size) {
                    break;
                }
                i11++;
                fVar = (f) this.f5745q.get(i11);
            }
            if (i12 == i10) {
                float f14 = fVar.f5766e;
                float f15 = fVar.f5765d;
                f10 = (f14 + f15) * width;
                f13 = f14 + f15 + f12;
            } else {
                float f16 = this.f5751t.f(i12);
                f10 = (f13 + f16) * width;
                f13 += f16 + f12;
            }
            if (this.B + f10 > scrollX) {
                f11 = f12;
                this.C.setBounds(Math.round(f10), this.D, Math.round(this.B + f10), this.E);
                this.C.draw(canvas);
            } else {
                f11 = f12;
            }
            if (f10 > scrollX + r2) {
                return;
            }
            i12++;
            f12 = f11;
        }
    }

    @Override // android.view.ViewGroup
    public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
        int action = motionEvent.getAction() & Constants.MAX_HOST_LENGTH;
        if (action == 3 || action == 1) {
            L();
            return false;
        }
        if (action != 0) {
            if (this.N) {
                return true;
            }
            if (this.O) {
                return false;
            }
        }
        if (action == 0) {
            float x10 = motionEvent.getX();
            this.U = x10;
            this.S = x10;
            float y10 = motionEvent.getY();
            this.V = y10;
            this.T = y10;
            this.W = motionEvent.getPointerId(0);
            this.O = false;
            this.f5758z = true;
            this.f5757y.computeScrollOffset();
            if (this.f5752t0 != 2 || Math.abs(this.f5757y.getFinalX() - this.f5757y.getCurrX()) <= this.f5732e0) {
                h(false);
                this.N = false;
            } else {
                this.f5757y.abortAnimation();
                this.L = false;
                E();
                this.N = true;
                K(true);
                setScrollState(1);
            }
        } else if (action == 2) {
            int i10 = this.W;
            if (i10 != -1) {
                int findPointerIndex = motionEvent.findPointerIndex(i10);
                float x11 = motionEvent.getX(findPointerIndex);
                float f10 = x11 - this.S;
                float abs = Math.abs(f10);
                float y11 = motionEvent.getY(findPointerIndex);
                float abs2 = Math.abs(y11 - this.V);
                if (f10 != BitmapDescriptorFactory.HUE_RED && !x(this.S, f10) && f(this, false, (int) f10, (int) x11, (int) y11)) {
                    this.S = x11;
                    this.T = y11;
                    this.O = true;
                    return false;
                }
                int i11 = this.R;
                if (abs > i11 && abs * 0.5f > abs2) {
                    this.N = true;
                    K(true);
                    setScrollState(1);
                    float f11 = this.U;
                    float f12 = this.R;
                    this.S = f10 > BitmapDescriptorFactory.HUE_RED ? f11 + f12 : f11 - f12;
                    this.T = y11;
                    setScrollingCacheEnabled(true);
                } else if (abs2 > i11) {
                    this.O = true;
                }
                if (this.N && D(x11)) {
                    s0.d0(this);
                }
            }
        } else if (action == 6) {
            z(motionEvent);
        }
        if (this.f5728a0 == null) {
            this.f5728a0 = VelocityTracker.obtain();
        }
        this.f5728a0.addMovement(motionEvent);
        return this.N;
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x0071  */
    /* JADX WARN: Removed duplicated region for block: B:28:0x008e  */
    @Override // android.view.ViewGroup, android.view.View
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    protected void onLayout(boolean z10, int i10, int i11, int i12, int i13) {
        boolean z11;
        f s10;
        int max;
        int i14;
        int max2;
        int i15;
        int childCount = getChildCount();
        int i16 = i12 - i10;
        int i17 = i13 - i11;
        int paddingLeft = getPaddingLeft();
        int paddingTop = getPaddingTop();
        int paddingRight = getPaddingRight();
        int paddingBottom = getPaddingBottom();
        int scrollX = getScrollX();
        int i18 = 0;
        for (int i19 = 0; i19 < childCount; i19++) {
            View childAt = getChildAt(i19);
            if (childAt.getVisibility() != 8) {
                g gVar = (g) childAt.getLayoutParams();
                if (gVar.f5767a) {
                    int i20 = gVar.f5768b;
                    int i21 = i20 & 7;
                    int i22 = i20 & 112;
                    if (i21 != 1) {
                        if (i21 == 3) {
                            i14 = childAt.getMeasuredWidth() + paddingLeft;
                        } else if (i21 != 5) {
                            i14 = paddingLeft;
                        } else {
                            max = (i16 - paddingRight) - childAt.getMeasuredWidth();
                            paddingRight += childAt.getMeasuredWidth();
                        }
                        if (i22 == 16) {
                            if (i22 == 48) {
                                i15 = childAt.getMeasuredHeight() + paddingTop;
                            } else if (i22 != 80) {
                                i15 = paddingTop;
                            } else {
                                max2 = (i17 - paddingBottom) - childAt.getMeasuredHeight();
                                paddingBottom += childAt.getMeasuredHeight();
                            }
                            int i23 = paddingLeft + scrollX;
                            childAt.layout(i23, paddingTop, childAt.getMeasuredWidth() + i23, paddingTop + childAt.getMeasuredHeight());
                            i18++;
                            paddingTop = i15;
                            paddingLeft = i14;
                        } else {
                            max2 = Math.max((i17 - childAt.getMeasuredHeight()) / 2, paddingTop);
                        }
                        int i24 = max2;
                        i15 = paddingTop;
                        paddingTop = i24;
                        int i232 = paddingLeft + scrollX;
                        childAt.layout(i232, paddingTop, childAt.getMeasuredWidth() + i232, paddingTop + childAt.getMeasuredHeight());
                        i18++;
                        paddingTop = i15;
                        paddingLeft = i14;
                    } else {
                        max = Math.max((i16 - childAt.getMeasuredWidth()) / 2, paddingLeft);
                    }
                    int i25 = max;
                    i14 = paddingLeft;
                    paddingLeft = i25;
                    if (i22 == 16) {
                    }
                    int i242 = max2;
                    i15 = paddingTop;
                    paddingTop = i242;
                    int i2322 = paddingLeft + scrollX;
                    childAt.layout(i2322, paddingTop, childAt.getMeasuredWidth() + i2322, paddingTop + childAt.getMeasuredHeight());
                    i18++;
                    paddingTop = i15;
                    paddingLeft = i14;
                }
            }
        }
        int i26 = (i16 - paddingLeft) - paddingRight;
        for (int i27 = 0; i27 < childCount; i27++) {
            View childAt2 = getChildAt(i27);
            if (childAt2.getVisibility() != 8) {
                g gVar2 = (g) childAt2.getLayoutParams();
                if (!gVar2.f5767a && (s10 = s(childAt2)) != null) {
                    float f10 = i26;
                    int i28 = ((int) (s10.f5766e * f10)) + paddingLeft;
                    if (gVar2.f5770d) {
                        gVar2.f5770d = false;
                        childAt2.measure(View.MeasureSpec.makeMeasureSpec((int) (f10 * gVar2.f5769c), 1073741824), View.MeasureSpec.makeMeasureSpec((i17 - paddingTop) - paddingBottom, 1073741824));
                    }
                    childAt2.layout(i28, paddingTop, childAt2.getMeasuredWidth() + i28, childAt2.getMeasuredHeight() + paddingTop);
                }
            }
        }
        this.D = paddingTop;
        this.E = i17 - paddingBottom;
        this.f5739l0 = i18;
        if (this.f5736i0) {
            z11 = false;
            M(this.f5753u, false, 0, false);
        } else {
            z11 = false;
        }
        this.f5736i0 = z11;
    }

    @Override // android.view.View
    protected void onMeasure(int i10, int i11) {
        g gVar;
        g gVar2;
        int i12;
        setMeasuredDimension(View.getDefaultSize(0, i10), View.getDefaultSize(0, i11));
        int measuredWidth = getMeasuredWidth();
        this.Q = Math.min(measuredWidth / 10, this.P);
        int paddingLeft = (measuredWidth - getPaddingLeft()) - getPaddingRight();
        int measuredHeight = (getMeasuredHeight() - getPaddingTop()) - getPaddingBottom();
        int childCount = getChildCount();
        int i13 = 0;
        while (true) {
            boolean z10 = true;
            int i14 = 1073741824;
            if (i13 >= childCount) {
                break;
            }
            View childAt = getChildAt(i13);
            if (childAt.getVisibility() != 8 && (gVar2 = (g) childAt.getLayoutParams()) != null && gVar2.f5767a) {
                int i15 = gVar2.f5768b;
                int i16 = i15 & 7;
                int i17 = i15 & 112;
                boolean z11 = i17 == 48 || i17 == 80;
                if (i16 != 3 && i16 != 5) {
                    z10 = false;
                }
                int i18 = Integer.MIN_VALUE;
                if (z11) {
                    i12 = Integer.MIN_VALUE;
                    i18 = 1073741824;
                } else {
                    i12 = z10 ? 1073741824 : Integer.MIN_VALUE;
                }
                int i19 = ((ViewGroup.LayoutParams) gVar2).width;
                if (i19 != -2) {
                    if (i19 == -1) {
                        i19 = paddingLeft;
                    }
                    i18 = 1073741824;
                } else {
                    i19 = paddingLeft;
                }
                int i20 = ((ViewGroup.LayoutParams) gVar2).height;
                if (i20 == -2) {
                    i20 = measuredHeight;
                    i14 = i12;
                } else if (i20 == -1) {
                    i20 = measuredHeight;
                }
                childAt.measure(View.MeasureSpec.makeMeasureSpec(i19, i18), View.MeasureSpec.makeMeasureSpec(i20, i14));
                if (z11) {
                    measuredHeight -= childAt.getMeasuredHeight();
                } else if (z10) {
                    paddingLeft -= childAt.getMeasuredWidth();
                }
            }
            i13++;
        }
        this.H = View.MeasureSpec.makeMeasureSpec(paddingLeft, 1073741824);
        this.I = View.MeasureSpec.makeMeasureSpec(measuredHeight, 1073741824);
        this.J = true;
        E();
        this.J = false;
        int childCount2 = getChildCount();
        for (int i21 = 0; i21 < childCount2; i21++) {
            View childAt2 = getChildAt(i21);
            if (childAt2.getVisibility() != 8 && ((gVar = (g) childAt2.getLayoutParams()) == null || !gVar.f5767a)) {
                childAt2.measure(View.MeasureSpec.makeMeasureSpec((int) (paddingLeft * gVar.f5769c), 1073741824), this.I);
            }
        }
    }

    @Override // android.view.ViewGroup
    protected boolean onRequestFocusInDescendants(int i10, Rect rect) {
        int i11;
        int i12;
        int i13;
        f s10;
        int childCount = getChildCount();
        if ((i10 & 2) != 0) {
            i12 = childCount;
            i11 = 0;
            i13 = 1;
        } else {
            i11 = childCount - 1;
            i12 = -1;
            i13 = -1;
        }
        while (i11 != i12) {
            View childAt = getChildAt(i11);
            if (childAt.getVisibility() == 0 && (s10 = s(childAt)) != null && s10.f5763b == this.f5753u && childAt.requestFocus(i10, rect)) {
                return true;
            }
            i11 += i13;
        }
        return false;
    }

    @Override // android.view.View
    public void onRestoreInstanceState(Parcelable parcelable) {
        if (!(parcelable instanceof l)) {
            super.onRestoreInstanceState(parcelable);
            return;
        }
        l lVar = (l) parcelable;
        super.onRestoreInstanceState(lVar.a());
        androidx.viewpager.widget.a aVar = this.f5751t;
        if (aVar != null) {
            aVar.j(lVar.f5776s, lVar.f5777t);
            O(lVar.f5775r, false, true);
        } else {
            this.f5754v = lVar.f5775r;
            this.f5755w = lVar.f5776s;
            this.f5756x = lVar.f5777t;
        }
    }

    @Override // android.view.View
    public Parcelable onSaveInstanceState() {
        l lVar = new l(super.onSaveInstanceState());
        lVar.f5775r = this.f5753u;
        androidx.viewpager.widget.a aVar = this.f5751t;
        if (aVar != null) {
            lVar.f5776s = aVar.k();
        }
        return lVar;
    }

    @Override // android.view.View
    protected void onSizeChanged(int i10, int i11, int i12, int i13) {
        super.onSizeChanged(i10, i11, i12, i13);
        if (i10 != i12) {
            int i14 = this.B;
            G(i10, i12, i14, i14);
        }
    }

    @Override // android.view.View
    public boolean onTouchEvent(MotionEvent motionEvent) {
        androidx.viewpager.widget.a aVar;
        if (this.f5733f0) {
            return true;
        }
        boolean z10 = false;
        if ((motionEvent.getAction() == 0 && motionEvent.getEdgeFlags() != 0) || (aVar = this.f5751t) == null || aVar.c() == 0) {
            return false;
        }
        if (this.f5728a0 == null) {
            this.f5728a0 = VelocityTracker.obtain();
        }
        this.f5728a0.addMovement(motionEvent);
        int action = motionEvent.getAction() & Constants.MAX_HOST_LENGTH;
        if (action == 0) {
            this.f5757y.abortAnimation();
            this.L = false;
            E();
            float x10 = motionEvent.getX();
            this.U = x10;
            this.S = x10;
            float y10 = motionEvent.getY();
            this.V = y10;
            this.T = y10;
            this.W = motionEvent.getPointerId(0);
        } else if (action != 1) {
            if (action == 2) {
                if (!this.N) {
                    int findPointerIndex = motionEvent.findPointerIndex(this.W);
                    if (findPointerIndex == -1) {
                        z10 = L();
                    } else {
                        float x11 = motionEvent.getX(findPointerIndex);
                        float abs = Math.abs(x11 - this.S);
                        float y11 = motionEvent.getY(findPointerIndex);
                        float abs2 = Math.abs(y11 - this.T);
                        if (abs > this.R && abs > abs2) {
                            this.N = true;
                            K(true);
                            float f10 = this.U;
                            this.S = x11 - f10 > BitmapDescriptorFactory.HUE_RED ? f10 + this.R : f10 - this.R;
                            this.T = y11;
                            setScrollState(1);
                            setScrollingCacheEnabled(true);
                            ViewParent parent = getParent();
                            if (parent != null) {
                                parent.requestDisallowInterceptTouchEvent(true);
                            }
                        }
                    }
                }
                if (this.N) {
                    z10 = false | D(motionEvent.getX(motionEvent.findPointerIndex(this.W)));
                }
            } else if (action != 3) {
                if (action == 5) {
                    int actionIndex = motionEvent.getActionIndex();
                    this.S = motionEvent.getX(actionIndex);
                    this.W = motionEvent.getPointerId(actionIndex);
                } else if (action == 6) {
                    z(motionEvent);
                    this.S = motionEvent.getX(motionEvent.findPointerIndex(this.W));
                }
            } else if (this.N) {
                M(this.f5753u, true, 0, false);
                z10 = L();
            }
        } else if (this.N) {
            VelocityTracker velocityTracker = this.f5728a0;
            velocityTracker.computeCurrentVelocity(1000, this.f5730c0);
            int xVelocity = (int) velocityTracker.getXVelocity(this.W);
            this.L = true;
            int clientWidth = getClientWidth();
            int scrollX = getScrollX();
            f t10 = t();
            float f11 = clientWidth;
            P(j(t10.f5763b, ((scrollX / f11) - t10.f5766e) / (t10.f5765d + (this.B / f11)), xVelocity, (int) (motionEvent.getX(motionEvent.findPointerIndex(this.W)) - this.U)), true, true, xVelocity);
            z10 = L();
        }
        if (z10) {
            s0.d0(this);
        }
        return true;
    }

    public boolean p(KeyEvent keyEvent) {
        if (keyEvent.getAction() == 0) {
            int keyCode = keyEvent.getKeyCode();
            if (keyCode == 21) {
                return keyEvent.hasModifiers(2) ? A() : d(17);
            }
            if (keyCode == 22) {
                return keyEvent.hasModifiers(2) ? B() : d(66);
            }
            if (keyCode == 61) {
                if (keyEvent.hasNoModifiers()) {
                    return d(2);
                }
                if (keyEvent.hasModifiers(1)) {
                    return d(1);
                }
            }
        }
        return false;
    }

    f r(View view) {
        while (true) {
            Object parent = view.getParent();
            if (parent == this) {
                return s(view);
            }
            if (parent == null || !(parent instanceof View)) {
                return null;
            }
            view = (View) parent;
        }
    }

    @Override // android.view.ViewGroup, android.view.ViewManager
    public void removeView(View view) {
        if (this.J) {
            removeViewInLayout(view);
        } else {
            super.removeView(view);
        }
    }

    f s(View view) {
        for (int i10 = 0; i10 < this.f5745q.size(); i10++) {
            f fVar = (f) this.f5745q.get(i10);
            if (this.f5751t.h(view, fVar.f5762a)) {
                return fVar;
            }
        }
        return null;
    }

    public void setAdapter(androidx.viewpager.widget.a aVar) {
        androidx.viewpager.widget.a aVar2 = this.f5751t;
        if (aVar2 != null) {
            aVar2.m(null);
            this.f5751t.n(this);
            for (int i10 = 0; i10 < this.f5745q.size(); i10++) {
                f fVar = (f) this.f5745q.get(i10);
                this.f5751t.a(this, fVar.f5763b, fVar.f5762a);
            }
            this.f5751t.b(this);
            this.f5745q.clear();
            H();
            this.f5753u = 0;
            scrollTo(0, 0);
        }
        androidx.viewpager.widget.a aVar3 = this.f5751t;
        this.f5751t = aVar;
        this.f5743p = 0;
        if (aVar != null) {
            if (this.A == null) {
                this.A = new k();
            }
            this.f5751t.m(this.A);
            this.L = false;
            boolean z10 = this.f5736i0;
            this.f5736i0 = true;
            this.f5743p = this.f5751t.c();
            if (this.f5754v >= 0) {
                this.f5751t.j(this.f5755w, this.f5756x);
                O(this.f5754v, false, true);
                this.f5754v = -1;
                this.f5755w = null;
                this.f5756x = null;
            } else if (z10) {
                requestLayout();
            } else {
                E();
            }
        }
        List list = this.f5744p0;
        if (list == null || list.isEmpty()) {
            return;
        }
        int size = this.f5744p0.size();
        for (int i11 = 0; i11 < size; i11++) {
            ((i) this.f5744p0.get(i11)).a(this, aVar3, aVar);
        }
    }

    public void setCurrentItem(int i10) {
        this.L = false;
        O(i10, !this.f5736i0, false);
    }

    public void setOffscreenPageLimit(int i10) {
        if (i10 < 1) {
            Log.w("ViewPager", "Requested offscreen page limit " + i10 + " too small; defaulting to 1");
            i10 = 1;
        }
        if (i10 != this.M) {
            this.M = i10;
            E();
        }
    }

    @Deprecated
    public void setOnPageChangeListener(j jVar) {
        this.f5741n0 = jVar;
    }

    public void setPageMargin(int i10) {
        int i11 = this.B;
        this.B = i10;
        int width = getWidth();
        G(width, width, i10, i11);
        requestLayout();
    }

    public void setPageMarginDrawable(Drawable drawable) {
        this.C = drawable;
        if (drawable != null) {
            refreshDrawableState();
        }
        setWillNotDraw(drawable == null);
        invalidate();
    }

    void setScrollState(int i10) {
        if (this.f5752t0 == i10) {
            return;
        }
        this.f5752t0 = i10;
        m(i10);
    }

    f u(int i10) {
        for (int i11 = 0; i11 < this.f5745q.size(); i11++) {
            f fVar = (f) this.f5745q.get(i11);
            if (fVar.f5763b == i10) {
                return fVar;
            }
        }
        return null;
    }

    void v() {
        setWillNotDraw(false);
        setDescendantFocusability(262144);
        setFocusable(true);
        Context context = getContext();
        this.f5757y = new Scroller(context, f5726w0);
        ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
        float f10 = context.getResources().getDisplayMetrics().density;
        this.R = viewConfiguration.getScaledPagingTouchSlop();
        this.f5729b0 = (int) (400.0f * f10);
        this.f5730c0 = viewConfiguration.getScaledMaximumFlingVelocity();
        this.f5734g0 = new EdgeEffect(context);
        this.f5735h0 = new EdgeEffect(context);
        this.f5731d0 = (int) (25.0f * f10);
        this.f5732e0 = (int) (2.0f * f10);
        this.P = (int) (f10 * 16.0f);
        s0.m0(this, new h());
        if (s0.x(this) == 0) {
            s0.x0(this, 1);
        }
        s0.A0(this, new d());
    }

    @Override // android.view.View
    protected boolean verifyDrawable(Drawable drawable) {
        return super.verifyDrawable(drawable) || drawable == this.C;
    }

    /* JADX WARN: Removed duplicated region for block: B:16:0x0063  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    protected void y(int i10, float f10, int i11) {
        int max;
        int i12;
        int left;
        if (this.f5739l0 > 0) {
            int scrollX = getScrollX();
            int paddingLeft = getPaddingLeft();
            int paddingRight = getPaddingRight();
            int width = getWidth();
            int childCount = getChildCount();
            for (int i13 = 0; i13 < childCount; i13++) {
                View childAt = getChildAt(i13);
                g gVar = (g) childAt.getLayoutParams();
                if (gVar.f5767a) {
                    int i14 = gVar.f5768b & 7;
                    if (i14 != 1) {
                        if (i14 == 3) {
                            i12 = childAt.getWidth() + paddingLeft;
                        } else if (i14 != 5) {
                            i12 = paddingLeft;
                        } else {
                            max = (width - paddingRight) - childAt.getMeasuredWidth();
                            paddingRight += childAt.getMeasuredWidth();
                        }
                        left = (paddingLeft + scrollX) - childAt.getLeft();
                        if (left != 0) {
                            childAt.offsetLeftAndRight(left);
                        }
                        paddingLeft = i12;
                    } else {
                        max = Math.max((width - childAt.getMeasuredWidth()) / 2, paddingLeft);
                    }
                    int i15 = max;
                    i12 = paddingLeft;
                    paddingLeft = i15;
                    left = (paddingLeft + scrollX) - childAt.getLeft();
                    if (left != 0) {
                    }
                    paddingLeft = i12;
                }
            }
        }
        k(i10, f10, i11);
        this.f5738k0 = true;
    }

    /* loaded from: classes.dex */
    public static class g extends ViewGroup.LayoutParams {

        /* renamed from: a, reason: collision with root package name */
        public boolean f5767a;

        /* renamed from: b, reason: collision with root package name */
        public int f5768b;

        /* renamed from: c, reason: collision with root package name */
        float f5769c;

        /* renamed from: d, reason: collision with root package name */
        boolean f5770d;

        /* renamed from: e, reason: collision with root package name */
        int f5771e;

        /* renamed from: f, reason: collision with root package name */
        int f5772f;

        public g() {
            super(-1, -1);
            this.f5769c = BitmapDescriptorFactory.HUE_RED;
        }

        public g(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
            this.f5769c = BitmapDescriptorFactory.HUE_RED;
            TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, ViewPager.f5724u0);
            this.f5768b = obtainStyledAttributes.getInteger(0, 48);
            obtainStyledAttributes.recycle();
        }
    }

    @Override // android.view.ViewGroup
    public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attributeSet) {
        return new g(getContext(), attributeSet);
    }

    public void setPageMarginDrawable(int i10) {
        setPageMarginDrawable(androidx.core.content.a.getDrawable(getContext(), i10));
    }
}
