package o;

import android.R;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Parcelable;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ListAdapter;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.ThemedSpinnerAdapter;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.t8, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C2501t8 extends Spinner {
    public static final int[] t = {R.attr.spinnerMode};
    public final C2689v7 l;
    public final Context m;
    public final C1552j8 n;

    /* renamed from: o, reason: collision with root package name */
    public SpinnerAdapter f726o;
    public final boolean p;
    public final InterfaceC2406s8 q;
    public int r;
    public final Rect s;

    /* JADX WARN: Removed duplicated region for block: B:25:0x0062  */
    /* JADX WARN: Removed duplicated region for block: B:28:0x0098  */
    /* JADX WARN: Removed duplicated region for block: B:31:0x00ab  */
    /* JADX WARN: Removed duplicated region for block: B:34:0x00c5  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public C2501t8(android.content.Context r13, android.util.AttributeSet r14) throws java.lang.Throwable {
        /*
            r12 = this;
            r0 = 2130904043(0x7f0303eb, float:1.7414921E38)
            r12.<init>(r13, r14, r0)
            android.graphics.Rect r1 = new android.graphics.Rect
            r1.<init>()
            r12.s = r1
            android.content.Context r1 = r12.getContext()
            o.AbstractC1498if0.a(r12, r1)
            int[] r1 = o.YZ.u
            o.C70 r2 = o.C70.r(r13, r14, r1, r0)
            java.lang.Object r3 = r2.n
            android.content.res.TypedArray r3 = (android.content.res.TypedArray) r3
            o.v7 r4 = new o.v7
            r4.<init>(r12)
            r12.l = r4
            r4 = 4
            r5 = 0
            int r4 = r3.getResourceId(r4, r5)
            if (r4 == 0) goto L35
            o.Hm r6 = new o.Hm
            r6.<init>(r13, r4)
            r12.m = r6
            goto L37
        L35:
            r12.m = r13
        L37:
            r4 = -1
            r6 = 0
            int[] r7 = o.C2501t8.t     // Catch: java.lang.Throwable -> L51 java.lang.Exception -> L53
            android.content.res.TypedArray r7 = r13.obtainStyledAttributes(r14, r7, r0, r5)     // Catch: java.lang.Throwable -> L51 java.lang.Exception -> L53
            boolean r8 = r7.hasValue(r5)     // Catch: java.lang.Throwable -> L4a java.lang.Exception -> L5b
            if (r8 == 0) goto L4d
            int r4 = r7.getInt(r5, r5)     // Catch: java.lang.Throwable -> L4a java.lang.Exception -> L5b
            goto L4d
        L4a:
            r13 = move-exception
            r6 = r7
            goto L55
        L4d:
            r7.recycle()
            goto L5e
        L51:
            r13 = move-exception
            goto L55
        L53:
            r7 = r6
            goto L5b
        L55:
            if (r6 == 0) goto L5a
            r6.recycle()
        L5a:
            throw r13
        L5b:
            if (r7 == 0) goto L5e
            goto L4d
        L5e:
            r7 = 2
            r8 = 1
            if (r4 == 0) goto L98
            if (r4 == r8) goto L65
            goto La5
        L65:
            o.q8 r4 = new o.q8
            android.content.Context r9 = r12.m
            r4.<init>(r12, r9, r14)
            android.content.Context r9 = r12.m
            o.C70 r1 = o.C70.r(r9, r14, r1, r0)
            java.lang.Object r9 = r1.n
            android.content.res.TypedArray r9 = (android.content.res.TypedArray) r9
            r10 = 3
            r11 = -2
            int r9 = r9.getLayoutDimension(r10, r11)
            r12.r = r9
            android.graphics.drawable.Drawable r9 = r1.m(r8)
            r4.j(r9)
            java.lang.String r7 = r3.getString(r7)
            r4.N = r7
            r1.t()
            r12.q = r4
            o.j8 r1 = new o.j8
            r1.<init>(r12, r12, r4)
            r12.n = r1
            goto La5
        L98:
            o.m8 r1 = new o.m8
            r1.<init>(r12)
            r12.q = r1
            java.lang.String r4 = r3.getString(r7)
            r1.n = r4
        La5:
            java.lang.CharSequence[] r1 = r3.getTextArray(r5)
            if (r1 == 0) goto Lbc
            android.widget.ArrayAdapter r3 = new android.widget.ArrayAdapter
            r4 = 17367048(0x1090008, float:2.5162948E-38)
            r3.<init>(r13, r4, r1)
            r13 = 2131427446(0x7f0b0076, float:1.8476508E38)
            r3.setDropDownViewResource(r13)
            r12.setAdapter(r3)
        Lbc:
            r2.t()
            r12.p = r8
            android.widget.SpinnerAdapter r13 = r12.f726o
            if (r13 == 0) goto Lca
            r12.setAdapter(r13)
            r12.f726o = r6
        Lca:
            o.v7 r13 = r12.l
            r13.m(r14, r0)
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: o.C2501t8.<init>(android.content.Context, android.util.AttributeSet):void");
    }

    public final int a(SpinnerAdapter spinnerAdapter, Drawable drawable) {
        int i = 0;
        if (spinnerAdapter == null) {
            return 0;
        }
        int iMakeMeasureSpec = View.MeasureSpec.makeMeasureSpec(getMeasuredWidth(), 0);
        int iMakeMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(getMeasuredHeight(), 0);
        int iMax = Math.max(0, getSelectedItemPosition());
        int iMin = Math.min(spinnerAdapter.getCount(), iMax + 15);
        View view = null;
        int iMax2 = 0;
        for (int iMax3 = Math.max(0, iMax - (15 - (iMin - iMax))); iMax3 < iMin; iMax3++) {
            int itemViewType = spinnerAdapter.getItemViewType(iMax3);
            if (itemViewType != i) {
                view = null;
                i = itemViewType;
            }
            view = spinnerAdapter.getView(iMax3, view, this);
            if (view.getLayoutParams() == null) {
                view.setLayoutParams(new ViewGroup.LayoutParams(-2, -2));
            }
            view.measure(iMakeMeasureSpec, iMakeMeasureSpec2);
            iMax2 = Math.max(iMax2, view.getMeasuredWidth());
        }
        if (drawable == null) {
            return iMax2;
        }
        Rect rect = this.s;
        drawable.getPadding(rect);
        return rect.left + rect.right + iMax2;
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void drawableStateChanged() {
        super.drawableStateChanged();
        C2689v7 c2689v7 = this.l;
        if (c2689v7 != null) {
            c2689v7.i();
        }
    }

    @Override // android.widget.Spinner
    public int getDropDownHorizontalOffset() {
        InterfaceC2406s8 interfaceC2406s8 = this.q;
        return interfaceC2406s8 != null ? interfaceC2406s8.c() : super.getDropDownHorizontalOffset();
    }

    @Override // android.widget.Spinner
    public int getDropDownVerticalOffset() {
        InterfaceC2406s8 interfaceC2406s8 = this.q;
        return interfaceC2406s8 != null ? interfaceC2406s8.o() : super.getDropDownVerticalOffset();
    }

    @Override // android.widget.Spinner
    public int getDropDownWidth() {
        return this.q != null ? this.r : super.getDropDownWidth();
    }

    public final InterfaceC2406s8 getInternalPopup() {
        return this.q;
    }

    @Override // android.widget.Spinner
    public Drawable getPopupBackground() {
        InterfaceC2406s8 interfaceC2406s8 = this.q;
        return interfaceC2406s8 != null ? interfaceC2406s8.g() : super.getPopupBackground();
    }

    @Override // android.widget.Spinner
    public Context getPopupContext() {
        return this.m;
    }

    @Override // android.widget.Spinner
    public CharSequence getPrompt() {
        InterfaceC2406s8 interfaceC2406s8 = this.q;
        return interfaceC2406s8 != null ? interfaceC2406s8.p() : super.getPrompt();
    }

    public ColorStateList getSupportBackgroundTintList() {
        C2689v7 c2689v7 = this.l;
        if (c2689v7 != null) {
            return c2689v7.j();
        }
        return null;
    }

    public PorterDuff.Mode getSupportBackgroundTintMode() {
        C2689v7 c2689v7 = this.l;
        if (c2689v7 != null) {
            return c2689v7.k();
        }
        return null;
    }

    @Override // android.widget.Spinner, android.widget.AdapterView, android.view.ViewGroup, android.view.View
    public final void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        InterfaceC2406s8 interfaceC2406s8 = this.q;
        if (interfaceC2406s8 == null || !interfaceC2406s8.b()) {
            return;
        }
        interfaceC2406s8.dismiss();
    }

    @Override // android.widget.Spinner, android.widget.AbsSpinner, android.view.View
    public final void onMeasure(int i, int i2) {
        super.onMeasure(i, i2);
        if (this.q == null || View.MeasureSpec.getMode(i) != Integer.MIN_VALUE) {
            return;
        }
        setMeasuredDimension(Math.min(Math.max(getMeasuredWidth(), a(getAdapter(), getBackground())), View.MeasureSpec.getSize(i)), getMeasuredHeight());
    }

    @Override // android.widget.Spinner, android.widget.AbsSpinner, android.view.View
    public final void onRestoreInstanceState(Parcelable parcelable) {
        ViewTreeObserver viewTreeObserver;
        C2311r8 c2311r8 = (C2311r8) parcelable;
        super.onRestoreInstanceState(c2311r8.getSuperState());
        if (!c2311r8.l || (viewTreeObserver = getViewTreeObserver()) == null) {
            return;
        }
        viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserverOnGlobalLayoutListenerC1647k8(0, this));
    }

    @Override // android.widget.Spinner, android.widget.AbsSpinner, android.view.View
    public final Parcelable onSaveInstanceState() {
        C2311r8 c2311r8 = new C2311r8(super.onSaveInstanceState());
        InterfaceC2406s8 interfaceC2406s8 = this.q;
        c2311r8.l = interfaceC2406s8 != null && interfaceC2406s8.b();
        return c2311r8;
    }

    @Override // android.widget.Spinner, android.view.View
    public final boolean onTouchEvent(MotionEvent motionEvent) {
        C1552j8 c1552j8 = this.n;
        if (c1552j8 == null || !c1552j8.onTouch(this, motionEvent)) {
            return super.onTouchEvent(motionEvent);
        }
        return true;
    }

    @Override // android.widget.Spinner, android.view.View
    public final boolean performClick() {
        InterfaceC2406s8 interfaceC2406s8 = this.q;
        if (interfaceC2406s8 == null) {
            return super.performClick();
        }
        if (interfaceC2406s8.b()) {
            return true;
        }
        interfaceC2406s8.n(getTextDirection(), getTextAlignment());
        return true;
    }

    @Override // android.view.View
    public void setBackgroundDrawable(Drawable drawable) {
        super.setBackgroundDrawable(drawable);
        C2689v7 c2689v7 = this.l;
        if (c2689v7 != null) {
            c2689v7.o();
        }
    }

    @Override // android.view.View
    public void setBackgroundResource(int i) {
        super.setBackgroundResource(i);
        C2689v7 c2689v7 = this.l;
        if (c2689v7 != null) {
            c2689v7.p(i);
        }
    }

    @Override // android.widget.Spinner
    public void setDropDownHorizontalOffset(int i) {
        InterfaceC2406s8 interfaceC2406s8 = this.q;
        if (interfaceC2406s8 == null) {
            super.setDropDownHorizontalOffset(i);
        } else {
            interfaceC2406s8.l(i);
            interfaceC2406s8.m(i);
        }
    }

    @Override // android.widget.Spinner
    public void setDropDownVerticalOffset(int i) {
        InterfaceC2406s8 interfaceC2406s8 = this.q;
        if (interfaceC2406s8 != null) {
            interfaceC2406s8.k(i);
        } else {
            super.setDropDownVerticalOffset(i);
        }
    }

    @Override // android.widget.Spinner
    public void setDropDownWidth(int i) {
        if (this.q != null) {
            this.r = i;
        } else {
            super.setDropDownWidth(i);
        }
    }

    @Override // android.widget.Spinner
    public void setPopupBackgroundDrawable(Drawable drawable) {
        InterfaceC2406s8 interfaceC2406s8 = this.q;
        if (interfaceC2406s8 != null) {
            interfaceC2406s8.j(drawable);
        } else {
            super.setPopupBackgroundDrawable(drawable);
        }
    }

    @Override // android.widget.Spinner
    public void setPopupBackgroundResource(int i) {
        setPopupBackgroundDrawable(C80.x(getPopupContext(), i));
    }

    @Override // android.widget.Spinner
    public void setPrompt(CharSequence charSequence) {
        InterfaceC2406s8 interfaceC2406s8 = this.q;
        if (interfaceC2406s8 != null) {
            interfaceC2406s8.i(charSequence);
        } else {
            super.setPrompt(charSequence);
        }
    }

    public void setSupportBackgroundTintList(ColorStateList colorStateList) {
        C2689v7 c2689v7 = this.l;
        if (c2689v7 != null) {
            c2689v7.r(colorStateList);
        }
    }

    public void setSupportBackgroundTintMode(PorterDuff.Mode mode) {
        C2689v7 c2689v7 = this.l;
        if (c2689v7 != null) {
            c2689v7.s(mode);
        }
    }

    @Override // android.widget.AdapterView
    public void setAdapter(SpinnerAdapter spinnerAdapter) {
        if (!this.p) {
            this.f726o = spinnerAdapter;
            return;
        }
        super.setAdapter(spinnerAdapter);
        InterfaceC2406s8 interfaceC2406s8 = this.q;
        if (interfaceC2406s8 != null) {
            Context context = this.m;
            if (context == null) {
                context = getContext();
            }
            Resources.Theme theme = context.getTheme();
            C1932n8 c1932n8 = new C1932n8();
            c1932n8.a = spinnerAdapter;
            if (spinnerAdapter instanceof ListAdapter) {
                c1932n8.b = (ListAdapter) spinnerAdapter;
            }
            if (theme != null && (spinnerAdapter instanceof ThemedSpinnerAdapter)) {
                AbstractC1742l8.a((ThemedSpinnerAdapter) spinnerAdapter, theme);
            }
            interfaceC2406s8.q(c1932n8);
        }
    }
}
