package androidx.appcompat.widget;

import android.content.Context;
import android.content.res.Configuration;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;
import android.widget.AdapterView;
import android.widget.HorizontalScrollView;
import android.widget.SpinnerAdapter;
import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;
import l.l;
import l.r2;
import l.s2;
import l.t2;
import l.z1;

/* JADX INFO: loaded from: classes.dex */
@RestrictTo({RestrictTo.Scope.f557c})
public class ScrollingTabContainerView extends HorizontalScrollView implements AdapterView.OnItemSelectedListener {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public l f725a;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public AppCompatSpinner f727c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public boolean f728d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f729e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public int f730f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public int f731g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public int f732h;

    static {
        new DecelerateInterpolator();
    }

    public ScrollingTabContainerView(@NonNull Context context) {
        super(context);
        new t2(this);
        setHorizontalScrollBarEnabled(false);
        j.a aVarA = j.a.a(context);
        setContentHeight(aVarA.c());
        this.f730f = aVarA.f28433a.getResources().getDimensionPixelSize(d.d.abc_action_bar_stacked_tab_max_width);
        LinearLayoutCompat linearLayoutCompat = new LinearLayoutCompat(getContext(), null, d.a.actionBarTabBarStyle);
        linearLayoutCompat.setMeasureWithLargestChildEnabled(true);
        linearLayoutCompat.setGravity(17);
        linearLayoutCompat.setLayoutParams(new z1(-2, -1));
        this.f726b = linearLayoutCompat;
        addView(linearLayoutCompat, new ViewGroup.LayoutParams(-2, -1));
    }

    public final void a() {
        AppCompatSpinner appCompatSpinner = this.f727c;
        if (appCompatSpinner != null && appCompatSpinner.getParent() == this) {
            removeView(this.f727c);
            addView(this.f726b, new ViewGroup.LayoutParams(-2, -1));
            setTabSelected(this.f727c.getSelectedItemPosition());
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onAttachedToWindow() {
        super.onAttachedToWindow();
        l lVar = this.f725a;
        if (lVar != null) {
            post(lVar);
        }
    }

    @Override // android.view.View
    public final void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        j.a aVarA = j.a.a(getContext());
        setContentHeight(aVarA.c());
        this.f730f = aVarA.f28433a.getResources().getDimensionPixelSize(d.d.abc_action_bar_stacked_tab_max_width);
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        l lVar = this.f725a;
        if (lVar != null) {
            removeCallbacks(lVar);
        }
    }

    @Override // android.widget.AdapterView.OnItemSelectedListener
    public final void onItemSelected(AdapterView adapterView, View view, int i10, long j10) {
        ((s2) view).getClass();
        throw null;
    }

    @Override // android.widget.HorizontalScrollView, android.widget.FrameLayout, android.view.View
    public final void onMeasure(int i10, int i11) {
        int mode = View.MeasureSpec.getMode(i10);
        boolean z10 = mode == 1073741824;
        setFillViewport(z10);
        LinearLayoutCompat linearLayoutCompat = this.f726b;
        int childCount = linearLayoutCompat.getChildCount();
        if (childCount <= 1 || !(mode == 1073741824 || mode == Integer.MIN_VALUE)) {
            this.f729e = -1;
        } else {
            if (childCount > 2) {
                this.f729e = (int) (View.MeasureSpec.getSize(i10) * 0.4f);
            } else {
                this.f729e = View.MeasureSpec.getSize(i10) / 2;
            }
            this.f729e = Math.min(this.f729e, this.f730f);
        }
        int iMakeMeasureSpec = View.MeasureSpec.makeMeasureSpec(this.f731g, 1073741824);
        if (z10 || !this.f728d) {
            a();
        } else {
            linearLayoutCompat.measure(0, iMakeMeasureSpec);
            if (linearLayoutCompat.getMeasuredWidth() > View.MeasureSpec.getSize(i10)) {
                AppCompatSpinner appCompatSpinner = this.f727c;
                if (appCompatSpinner == null || appCompatSpinner.getParent() != this) {
                    if (this.f727c == null) {
                        AppCompatSpinner appCompatSpinner2 = new AppCompatSpinner(getContext(), null, d.a.actionDropDownStyle);
                        appCompatSpinner2.setLayoutParams(new z1(-2, -1));
                        appCompatSpinner2.setOnItemSelectedListener(this);
                        this.f727c = appCompatSpinner2;
                    }
                    removeView(linearLayoutCompat);
                    addView(this.f727c, new ViewGroup.LayoutParams(-2, -1));
                    if (this.f727c.getAdapter() == null) {
                        this.f727c.setAdapter((SpinnerAdapter) new r2(this));
                    }
                    Runnable runnable = this.f725a;
                    if (runnable != null) {
                        removeCallbacks(runnable);
                        this.f725a = null;
                    }
                    this.f727c.setSelection(this.f732h);
                }
            } else {
                a();
            }
        }
        int measuredWidth = getMeasuredWidth();
        super.onMeasure(i10, iMakeMeasureSpec);
        int measuredWidth2 = getMeasuredWidth();
        if (!z10 || measuredWidth == measuredWidth2) {
            return;
        }
        setTabSelected(this.f732h);
    }

    @Override // android.widget.AdapterView.OnItemSelectedListener
    public final void onNothingSelected(AdapterView adapterView) {
    }

    public void setAllowCollapse(boolean z10) {
        this.f728d = z10;
    }

    public void setContentHeight(int i10) {
        this.f731g = i10;
        requestLayout();
    }

    public void setTabSelected(int i10) {
        this.f732h = i10;
        LinearLayoutCompat linearLayoutCompat = this.f726b;
        int childCount = linearLayoutCompat.getChildCount();
        int i11 = 0;
        while (i11 < childCount) {
            View childAt = linearLayoutCompat.getChildAt(i11);
            int i12 = 1;
            boolean z10 = i11 == i10;
            childAt.setSelected(z10);
            if (z10) {
                View childAt2 = linearLayoutCompat.getChildAt(i10);
                Runnable runnable = this.f725a;
                if (runnable != null) {
                    removeCallbacks(runnable);
                }
                l lVar = new l(this, childAt2, i12);
                this.f725a = lVar;
                post(lVar);
            }
            i11++;
        }
        AppCompatSpinner appCompatSpinner = this.f727c;
        if (appCompatSpinner == null || i10 < 0) {
            return;
        }
        appCompatSpinner.setSelection(i10);
    }
}
