package androidx.appcompat.widget;

import android.R;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.database.DataSetObserver;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.ThemedSpinnerAdapter;
import androidx.appcompat.app.a;

/* loaded from: classes.dex */
public class y extends Spinner {

    /* renamed from: x, reason: collision with root package name */
    private static final int[] f1221x = {R.attr.spinnerMode};

    /* renamed from: p, reason: collision with root package name */
    private final androidx.appcompat.widget.e f1222p;

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

    /* renamed from: r, reason: collision with root package name */
    private i0 f1224r;

    /* renamed from: s, reason: collision with root package name */
    private SpinnerAdapter f1225s;

    /* renamed from: t, reason: collision with root package name */
    private final boolean f1226t;

    /* renamed from: u, reason: collision with root package name */
    private g f1227u;

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

    /* renamed from: w, reason: collision with root package name */
    final Rect f1229w;

    /* loaded from: classes.dex */
    class a extends i0 {

        /* renamed from: y, reason: collision with root package name */
        final /* synthetic */ e f1230y;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        a(View view, e eVar) {
            super(view);
            this.f1230y = eVar;
        }

        @Override // androidx.appcompat.widget.i0
        public o.e b() {
            return this.f1230y;
        }

        @Override // androidx.appcompat.widget.i0
        public boolean c() {
            if (y.this.getInternalPopup().c()) {
                return true;
            }
            y.this.b();
            return true;
        }
    }

    /* loaded from: classes.dex */
    class b implements ViewTreeObserver.OnGlobalLayoutListener {
        b() {
        }

        @Override // android.view.ViewTreeObserver.OnGlobalLayoutListener
        public void onGlobalLayout() {
            if (!y.this.getInternalPopup().c()) {
                y.this.b();
            }
            ViewTreeObserver viewTreeObserver = y.this.getViewTreeObserver();
            if (viewTreeObserver != null) {
                viewTreeObserver.removeOnGlobalLayoutListener(this);
            }
        }
    }

    /* loaded from: classes.dex */
    class c implements g, DialogInterface.OnClickListener {

        /* renamed from: p, reason: collision with root package name */
        androidx.appcompat.app.a f1233p;

        /* renamed from: q, reason: collision with root package name */
        private ListAdapter f1234q;

        /* renamed from: r, reason: collision with root package name */
        private CharSequence f1235r;

        c() {
        }

        @Override // androidx.appcompat.widget.y.g
        public void b(Drawable drawable) {
            Log.e("AppCompatSpinner", "Cannot set popup background for MODE_DIALOG, ignoring");
        }

        @Override // androidx.appcompat.widget.y.g
        public boolean c() {
            androidx.appcompat.app.a aVar = this.f1233p;
            if (aVar != null) {
                return aVar.isShowing();
            }
            return false;
        }

        @Override // androidx.appcompat.widget.y.g
        public int d() {
            return 0;
        }

        @Override // androidx.appcompat.widget.y.g
        public void dismiss() {
            androidx.appcompat.app.a aVar = this.f1233p;
            if (aVar != null) {
                aVar.dismiss();
                this.f1233p = null;
            }
        }

        @Override // androidx.appcompat.widget.y.g
        public void f(int i10) {
            Log.e("AppCompatSpinner", "Cannot set horizontal offset for MODE_DIALOG, ignoring");
        }

        @Override // androidx.appcompat.widget.y.g
        public CharSequence g() {
            return this.f1235r;
        }

        @Override // androidx.appcompat.widget.y.g
        public Drawable i() {
            return null;
        }

        @Override // androidx.appcompat.widget.y.g
        public void j(CharSequence charSequence) {
            this.f1235r = charSequence;
        }

        @Override // androidx.appcompat.widget.y.g
        public void l(int i10) {
            Log.e("AppCompatSpinner", "Cannot set vertical offset for MODE_DIALOG, ignoring");
        }

        @Override // androidx.appcompat.widget.y.g
        public void m(int i10) {
            Log.e("AppCompatSpinner", "Cannot set horizontal (original) offset for MODE_DIALOG, ignoring");
        }

        @Override // androidx.appcompat.widget.y.g
        public void n(int i10, int i11) {
            if (this.f1234q == null) {
                return;
            }
            a.C0023a c0023a = new a.C0023a(y.this.getPopupContext());
            CharSequence charSequence = this.f1235r;
            if (charSequence != null) {
                c0023a.p(charSequence);
            }
            androidx.appcompat.app.a a10 = c0023a.o(this.f1234q, y.this.getSelectedItemPosition(), this).a();
            this.f1233p = a10;
            ListView f10 = a10.f();
            f10.setTextDirection(i10);
            f10.setTextAlignment(i11);
            this.f1233p.show();
        }

        @Override // androidx.appcompat.widget.y.g
        public int o() {
            return 0;
        }

        @Override // android.content.DialogInterface.OnClickListener
        public void onClick(DialogInterface dialogInterface, int i10) {
            y.this.setSelection(i10);
            if (y.this.getOnItemClickListener() != null) {
                y.this.performItemClick(null, i10, this.f1234q.getItemId(i10));
            }
            dismiss();
        }

        @Override // androidx.appcompat.widget.y.g
        public void p(ListAdapter listAdapter) {
            this.f1234q = listAdapter;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class d implements ListAdapter, SpinnerAdapter {

        /* renamed from: p, reason: collision with root package name */
        private SpinnerAdapter f1237p;

        /* renamed from: q, reason: collision with root package name */
        private ListAdapter f1238q;

        public d(SpinnerAdapter spinnerAdapter, Resources.Theme theme) {
            this.f1237p = spinnerAdapter;
            if (spinnerAdapter instanceof ListAdapter) {
                this.f1238q = (ListAdapter) spinnerAdapter;
            }
            if (theme == null || !(spinnerAdapter instanceof ThemedSpinnerAdapter)) {
                return;
            }
            ThemedSpinnerAdapter themedSpinnerAdapter = (ThemedSpinnerAdapter) spinnerAdapter;
            if (themedSpinnerAdapter.getDropDownViewTheme() != theme) {
                themedSpinnerAdapter.setDropDownViewTheme(theme);
            }
        }

        @Override // android.widget.ListAdapter
        public boolean areAllItemsEnabled() {
            ListAdapter listAdapter = this.f1238q;
            if (listAdapter != null) {
                return listAdapter.areAllItemsEnabled();
            }
            return true;
        }

        @Override // android.widget.Adapter
        public int getCount() {
            SpinnerAdapter spinnerAdapter = this.f1237p;
            if (spinnerAdapter == null) {
                return 0;
            }
            return spinnerAdapter.getCount();
        }

        @Override // android.widget.SpinnerAdapter
        public View getDropDownView(int i10, View view, ViewGroup viewGroup) {
            SpinnerAdapter spinnerAdapter = this.f1237p;
            if (spinnerAdapter == null) {
                return null;
            }
            return spinnerAdapter.getDropDownView(i10, view, viewGroup);
        }

        @Override // android.widget.Adapter
        public Object getItem(int i10) {
            SpinnerAdapter spinnerAdapter = this.f1237p;
            if (spinnerAdapter == null) {
                return null;
            }
            return spinnerAdapter.getItem(i10);
        }

        @Override // android.widget.Adapter
        public long getItemId(int i10) {
            SpinnerAdapter spinnerAdapter = this.f1237p;
            if (spinnerAdapter == null) {
                return -1L;
            }
            return spinnerAdapter.getItemId(i10);
        }

        @Override // android.widget.Adapter
        public int getItemViewType(int i10) {
            return 0;
        }

        @Override // android.widget.Adapter
        public View getView(int i10, View view, ViewGroup viewGroup) {
            return getDropDownView(i10, view, viewGroup);
        }

        @Override // android.widget.Adapter
        public int getViewTypeCount() {
            return 1;
        }

        @Override // android.widget.Adapter
        public boolean hasStableIds() {
            SpinnerAdapter spinnerAdapter = this.f1237p;
            return spinnerAdapter != null && spinnerAdapter.hasStableIds();
        }

        @Override // android.widget.Adapter
        public boolean isEmpty() {
            return getCount() == 0;
        }

        @Override // android.widget.ListAdapter
        public boolean isEnabled(int i10) {
            ListAdapter listAdapter = this.f1238q;
            if (listAdapter != null) {
                return listAdapter.isEnabled(i10);
            }
            return true;
        }

        @Override // android.widget.Adapter
        public void registerDataSetObserver(DataSetObserver dataSetObserver) {
            SpinnerAdapter spinnerAdapter = this.f1237p;
            if (spinnerAdapter != null) {
                spinnerAdapter.registerDataSetObserver(dataSetObserver);
            }
        }

        @Override // android.widget.Adapter
        public void unregisterDataSetObserver(DataSetObserver dataSetObserver) {
            SpinnerAdapter spinnerAdapter = this.f1237p;
            if (spinnerAdapter != null) {
                spinnerAdapter.unregisterDataSetObserver(dataSetObserver);
            }
        }
    }

    /* loaded from: classes.dex */
    class e extends j0 implements g {
        private CharSequence V;
        ListAdapter W;
        private final Rect X;
        private int Y;

        /* loaded from: classes.dex */
        class a implements AdapterView.OnItemClickListener {

            /* renamed from: p, reason: collision with root package name */
            final /* synthetic */ y f1239p;

            a(y yVar) {
                this.f1239p = yVar;
            }

            @Override // android.widget.AdapterView.OnItemClickListener
            public void onItemClick(AdapterView adapterView, View view, int i10, long j10) {
                y.this.setSelection(i10);
                if (y.this.getOnItemClickListener() != null) {
                    e eVar = e.this;
                    y.this.performItemClick(view, i10, eVar.W.getItemId(i10));
                }
                e.this.dismiss();
            }
        }

        /* loaded from: classes.dex */
        class b implements ViewTreeObserver.OnGlobalLayoutListener {
            b() {
            }

            @Override // android.view.ViewTreeObserver.OnGlobalLayoutListener
            public void onGlobalLayout() {
                e eVar = e.this;
                if (!eVar.U(y.this)) {
                    e.this.dismiss();
                } else {
                    e.this.S();
                    e.super.a();
                }
            }
        }

        /* loaded from: classes.dex */
        class c implements PopupWindow.OnDismissListener {

            /* renamed from: p, reason: collision with root package name */
            final /* synthetic */ ViewTreeObserver.OnGlobalLayoutListener f1242p;

            c(ViewTreeObserver.OnGlobalLayoutListener onGlobalLayoutListener) {
                this.f1242p = onGlobalLayoutListener;
            }

            @Override // android.widget.PopupWindow.OnDismissListener
            public void onDismiss() {
                ViewTreeObserver viewTreeObserver = y.this.getViewTreeObserver();
                if (viewTreeObserver != null) {
                    viewTreeObserver.removeGlobalOnLayoutListener(this.f1242p);
                }
            }
        }

        public e(Context context, AttributeSet attributeSet, int i10) {
            super(context, attributeSet, i10);
            this.X = new Rect();
            D(y.this);
            J(true);
            O(0);
            L(new a(y.this));
        }

        void S() {
            int i10;
            Drawable i11 = i();
            if (i11 != null) {
                i11.getPadding(y.this.f1229w);
                i10 = a1.b(y.this) ? y.this.f1229w.right : -y.this.f1229w.left;
            } else {
                Rect rect = y.this.f1229w;
                rect.right = 0;
                rect.left = 0;
                i10 = 0;
            }
            int paddingLeft = y.this.getPaddingLeft();
            int paddingRight = y.this.getPaddingRight();
            int width = y.this.getWidth();
            y yVar = y.this;
            int i12 = yVar.f1228v;
            if (i12 == -2) {
                int a10 = yVar.a((SpinnerAdapter) this.W, i());
                int i13 = y.this.getContext().getResources().getDisplayMetrics().widthPixels;
                Rect rect2 = y.this.f1229w;
                int i14 = (i13 - rect2.left) - rect2.right;
                if (a10 > i14) {
                    a10 = i14;
                }
                F(Math.max(a10, (width - paddingLeft) - paddingRight));
            } else if (i12 == -1) {
                F((width - paddingLeft) - paddingRight);
            } else {
                F(i12);
            }
            f(a1.b(y.this) ? i10 + (((width - paddingRight) - z()) - T()) : i10 + paddingLeft + T());
        }

        public int T() {
            return this.Y;
        }

        boolean U(View view) {
            return androidx.core.view.s0.P(view) && view.getGlobalVisibleRect(this.X);
        }

        @Override // androidx.appcompat.widget.y.g
        public CharSequence g() {
            return this.V;
        }

        @Override // androidx.appcompat.widget.y.g
        public void j(CharSequence charSequence) {
            this.V = charSequence;
        }

        @Override // androidx.appcompat.widget.y.g
        public void m(int i10) {
            this.Y = i10;
        }

        @Override // androidx.appcompat.widget.y.g
        public void n(int i10, int i11) {
            ViewTreeObserver viewTreeObserver;
            boolean c10 = c();
            S();
            I(2);
            super.a();
            ListView k10 = k();
            k10.setChoiceMode(1);
            k10.setTextDirection(i10);
            k10.setTextAlignment(i11);
            P(y.this.getSelectedItemPosition());
            if (c10 || (viewTreeObserver = y.this.getViewTreeObserver()) == null) {
                return;
            }
            b bVar = new b();
            viewTreeObserver.addOnGlobalLayoutListener(bVar);
            K(new c(bVar));
        }

        @Override // androidx.appcompat.widget.j0, androidx.appcompat.widget.y.g
        public void p(ListAdapter listAdapter) {
            super.p(listAdapter);
            this.W = listAdapter;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static class f extends View.BaseSavedState {
        public static final Parcelable.Creator<f> CREATOR = new a();

        /* renamed from: p, reason: collision with root package name */
        boolean f1244p;

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

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

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

        f(Parcelable parcelable) {
            super(parcelable);
        }

        @Override // android.view.View.BaseSavedState, android.view.AbsSavedState, android.os.Parcelable
        public void writeToParcel(Parcel parcel, int i10) {
            super.writeToParcel(parcel, i10);
            parcel.writeByte(this.f1244p ? (byte) 1 : (byte) 0);
        }

        f(Parcel parcel) {
            super(parcel);
            this.f1244p = parcel.readByte() != 0;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public interface g {
        void b(Drawable drawable);

        boolean c();

        int d();

        void dismiss();

        void f(int i10);

        CharSequence g();

        Drawable i();

        void j(CharSequence charSequence);

        void l(int i10);

        void m(int i10);

        void n(int i10, int i11);

        int o();

        void p(ListAdapter listAdapter);
    }

    public y(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, h.a.J);
    }

    int a(SpinnerAdapter spinnerAdapter, Drawable drawable) {
        int i10 = 0;
        if (spinnerAdapter == null) {
            return 0;
        }
        int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(getMeasuredWidth(), 0);
        int makeMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(getMeasuredHeight(), 0);
        int max = Math.max(0, getSelectedItemPosition());
        int min = Math.min(spinnerAdapter.getCount(), max + 15);
        View view = null;
        int i11 = 0;
        for (int max2 = Math.max(0, max - (15 - (min - max))); max2 < min; max2++) {
            int itemViewType = spinnerAdapter.getItemViewType(max2);
            if (itemViewType != i10) {
                view = null;
                i10 = itemViewType;
            }
            view = spinnerAdapter.getView(max2, view, this);
            if (view.getLayoutParams() == null) {
                view.setLayoutParams(new ViewGroup.LayoutParams(-2, -2));
            }
            view.measure(makeMeasureSpec, makeMeasureSpec2);
            i11 = Math.max(i11, view.getMeasuredWidth());
        }
        if (drawable == null) {
            return i11;
        }
        drawable.getPadding(this.f1229w);
        Rect rect = this.f1229w;
        return i11 + rect.left + rect.right;
    }

    void b() {
        this.f1227u.n(getTextDirection(), getTextAlignment());
    }

    @Override // android.view.ViewGroup, android.view.View
    protected void drawableStateChanged() {
        super.drawableStateChanged();
        androidx.appcompat.widget.e eVar = this.f1222p;
        if (eVar != null) {
            eVar.b();
        }
    }

    @Override // android.widget.Spinner
    public int getDropDownHorizontalOffset() {
        g gVar = this.f1227u;
        return gVar != null ? gVar.d() : super.getDropDownHorizontalOffset();
    }

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

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

    final g getInternalPopup() {
        return this.f1227u;
    }

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

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

    @Override // android.widget.Spinner
    public CharSequence getPrompt() {
        g gVar = this.f1227u;
        return gVar != null ? gVar.g() : super.getPrompt();
    }

    public ColorStateList getSupportBackgroundTintList() {
        androidx.appcompat.widget.e eVar = this.f1222p;
        if (eVar != null) {
            return eVar.c();
        }
        return null;
    }

    public PorterDuff.Mode getSupportBackgroundTintMode() {
        androidx.appcompat.widget.e eVar = this.f1222p;
        if (eVar != null) {
            return eVar.d();
        }
        return null;
    }

    @Override // android.widget.Spinner, android.widget.AdapterView, android.view.ViewGroup, android.view.View
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        g gVar = this.f1227u;
        if (gVar == null || !gVar.c()) {
            return;
        }
        this.f1227u.dismiss();
    }

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

    @Override // android.widget.Spinner, android.widget.AbsSpinner, android.view.View
    public void onRestoreInstanceState(Parcelable parcelable) {
        ViewTreeObserver viewTreeObserver;
        f fVar = (f) parcelable;
        super.onRestoreInstanceState(fVar.getSuperState());
        if (!fVar.f1244p || (viewTreeObserver = getViewTreeObserver()) == null) {
            return;
        }
        viewTreeObserver.addOnGlobalLayoutListener(new b());
    }

    @Override // android.widget.Spinner, android.widget.AbsSpinner, android.view.View
    public Parcelable onSaveInstanceState() {
        f fVar = new f(super.onSaveInstanceState());
        g gVar = this.f1227u;
        fVar.f1244p = gVar != null && gVar.c();
        return fVar;
    }

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

    @Override // android.widget.Spinner, android.view.View
    public boolean performClick() {
        g gVar = this.f1227u;
        if (gVar == null) {
            return super.performClick();
        }
        if (gVar.c()) {
            return true;
        }
        b();
        return true;
    }

    @Override // android.view.View
    public void setBackgroundDrawable(Drawable drawable) {
        super.setBackgroundDrawable(drawable);
        androidx.appcompat.widget.e eVar = this.f1222p;
        if (eVar != null) {
            eVar.f(drawable);
        }
    }

    @Override // android.view.View
    public void setBackgroundResource(int i10) {
        super.setBackgroundResource(i10);
        androidx.appcompat.widget.e eVar = this.f1222p;
        if (eVar != null) {
            eVar.g(i10);
        }
    }

    @Override // android.widget.Spinner
    public void setDropDownHorizontalOffset(int i10) {
        g gVar = this.f1227u;
        if (gVar == null) {
            super.setDropDownHorizontalOffset(i10);
        } else {
            gVar.m(i10);
            this.f1227u.f(i10);
        }
    }

    @Override // android.widget.Spinner
    public void setDropDownVerticalOffset(int i10) {
        g gVar = this.f1227u;
        if (gVar != null) {
            gVar.l(i10);
        } else {
            super.setDropDownVerticalOffset(i10);
        }
    }

    @Override // android.widget.Spinner
    public void setDropDownWidth(int i10) {
        if (this.f1227u != null) {
            this.f1228v = i10;
        } else {
            super.setDropDownWidth(i10);
        }
    }

    @Override // android.widget.Spinner
    public void setPopupBackgroundDrawable(Drawable drawable) {
        g gVar = this.f1227u;
        if (gVar != null) {
            gVar.b(drawable);
        } else {
            super.setPopupBackgroundDrawable(drawable);
        }
    }

    @Override // android.widget.Spinner
    public void setPopupBackgroundResource(int i10) {
        setPopupBackgroundDrawable(j.a.b(getPopupContext(), i10));
    }

    @Override // android.widget.Spinner
    public void setPrompt(CharSequence charSequence) {
        g gVar = this.f1227u;
        if (gVar != null) {
            gVar.j(charSequence);
        } else {
            super.setPrompt(charSequence);
        }
    }

    public void setSupportBackgroundTintList(ColorStateList colorStateList) {
        androidx.appcompat.widget.e eVar = this.f1222p;
        if (eVar != null) {
            eVar.i(colorStateList);
        }
    }

    public void setSupportBackgroundTintMode(PorterDuff.Mode mode) {
        androidx.appcompat.widget.e eVar = this.f1222p;
        if (eVar != null) {
            eVar.j(mode);
        }
    }

    public y(Context context, AttributeSet attributeSet, int i10) {
        this(context, attributeSet, i10, -1);
    }

    @Override // android.widget.AdapterView
    public void setAdapter(SpinnerAdapter spinnerAdapter) {
        if (!this.f1226t) {
            this.f1225s = spinnerAdapter;
            return;
        }
        super.setAdapter(spinnerAdapter);
        if (this.f1227u != null) {
            Context context = this.f1223q;
            if (context == null) {
                context = getContext();
            }
            this.f1227u.p(new d(spinnerAdapter, context.getTheme()));
        }
    }

    public y(Context context, AttributeSet attributeSet, int i10, int i11) {
        this(context, attributeSet, i10, i11, null);
    }

    /* JADX WARN: Code restructure failed: missing block: B:32:0x0060, code lost:
    
        if (r11 == null) goto L30;
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r11v10 */
    /* JADX WARN: Type inference failed for: r11v11 */
    /* JADX WARN: Type inference failed for: r11v12 */
    /* JADX WARN: Type inference failed for: r11v3 */
    /* JADX WARN: Type inference failed for: r11v4 */
    /* JADX WARN: Type inference failed for: r11v7, types: [android.content.res.TypedArray] */
    /* JADX WARN: Type inference failed for: r6v0, types: [android.view.View, androidx.appcompat.widget.y] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public y(Context context, AttributeSet attributeSet, int i10, int i11, Resources.Theme theme) {
        super(context, attributeSet, i10);
        TypedArray typedArray;
        this.f1229w = new Rect();
        r0.a(this, getContext());
        v0 v10 = v0.v(context, attributeSet, h.j.F2, i10, 0);
        this.f1222p = new androidx.appcompat.widget.e(this);
        if (theme != null) {
            this.f1223q = new n.d(context, theme);
        } else {
            int n10 = v10.n(h.j.K2, 0);
            if (n10 != 0) {
                this.f1223q = new n.d(context, n10);
            } else {
                this.f1223q = context;
            }
        }
        ?? r11 = -1;
        TypedArray typedArray2 = null;
        try {
            if (i11 == -1) {
                try {
                    typedArray = context.obtainStyledAttributes(attributeSet, f1221x, i10, 0);
                    try {
                        boolean hasValue = typedArray.hasValue(0);
                        r11 = typedArray;
                        if (hasValue) {
                            i11 = typedArray.getInt(0, 0);
                            r11 = typedArray;
                        }
                    } catch (Exception e10) {
                        e = e10;
                        Log.i("AppCompatSpinner", "Could not read android:spinnerMode", e);
                        r11 = typedArray;
                    }
                } catch (Exception e11) {
                    e = e11;
                    typedArray = null;
                } catch (Throwable th2) {
                    th = th2;
                    if (typedArray2 != null) {
                        typedArray2.recycle();
                    }
                    throw th;
                }
                r11.recycle();
            }
            if (i11 == 0) {
                c cVar = new c();
                this.f1227u = cVar;
                cVar.j(v10.o(h.j.I2));
            } else if (i11 == 1) {
                e eVar = new e(this.f1223q, attributeSet, i10);
                v0 v11 = v0.v(this.f1223q, attributeSet, h.j.F2, i10, 0);
                this.f1228v = v11.m(h.j.J2, -2);
                eVar.b(v11.g(h.j.H2));
                eVar.j(v10.o(h.j.I2));
                v11.w();
                this.f1227u = eVar;
                this.f1224r = new a(this, eVar);
            }
            CharSequence[] q10 = v10.q(h.j.G2);
            if (q10 != null) {
                ArrayAdapter arrayAdapter = new ArrayAdapter(context, R.layout.simple_spinner_item, q10);
                arrayAdapter.setDropDownViewResource(h.g.f20261s);
                setAdapter(arrayAdapter);
            }
            v10.w();
            this.f1226t = true;
            SpinnerAdapter spinnerAdapter = this.f1225s;
            if (spinnerAdapter != null) {
                setAdapter(spinnerAdapter);
                this.f1225s = null;
            }
            this.f1222p.e(attributeSet, i10);
        } catch (Throwable th3) {
            th = th3;
            typedArray2 = r11;
        }
    }
}
