package X6FRs_4.KQgRr5e_0.LGe8pk_15;

import android.content.Context;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.view.animation.DecelerateInterpolator;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.TextView;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.AppCompatSpinner;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.appcompat.widget.LinearLayoutCompat;
/* compiled from: ScrollingTabContainerView.java */
/* loaded from: classes.dex */
public class H5YG8fq_22 extends HorizontalScrollView implements AdapterView.OnItemSelectedListener {
    public int KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public PGPF6hQ_2 f674KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public Spinner f675KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public LinearLayoutCompat f676KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public Runnable f677KQgRr5e_0;

    /* renamed from: Mqv2r_3  reason: collision with root package name */
    public int f3158Mqv2r_3;
    public int PGPF6hQ_2;
    public int QxJ9d_1;

    /* renamed from: QxJ9d_1  reason: collision with other field name */
    public boolean f678QxJ9d_1;

    /* compiled from: ScrollingTabContainerView.java */
    /* loaded from: classes.dex */
    public class KQgRr5e_0 implements Runnable {

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public final /* synthetic */ View f679KQgRr5e_0;

        public KQgRr5e_0(View view) {
            this.f679KQgRr5e_0 = view;
        }

        @Override // java.lang.Runnable
        public void run() {
            H5YG8fq_22.this.smoothScrollTo(this.f679KQgRr5e_0.getLeft() - ((H5YG8fq_22.this.getWidth() - this.f679KQgRr5e_0.getWidth()) / 2), 0);
            H5YG8fq_22.this.f677KQgRr5e_0 = null;
        }
    }

    /* compiled from: ScrollingTabContainerView.java */
    /* loaded from: classes.dex */
    public class PGPF6hQ_2 implements View.OnClickListener {
        public PGPF6hQ_2() {
        }

        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            ((Mqv2r_3) view).KQgRr5e_0().m824KQgRr5e_0();
            int childCount = H5YG8fq_22.this.f676KQgRr5e_0.getChildCount();
            for (int i = 0; i < childCount; i++) {
                View childAt = H5YG8fq_22.this.f676KQgRr5e_0.getChildAt(i);
                childAt.setSelected(childAt == view);
            }
        }
    }

    /* compiled from: ScrollingTabContainerView.java */
    /* loaded from: classes.dex */
    public class QxJ9d_1 extends BaseAdapter {
        public QxJ9d_1() {
        }

        @Override // android.widget.Adapter
        public int getCount() {
            return H5YG8fq_22.this.f676KQgRr5e_0.getChildCount();
        }

        @Override // android.widget.Adapter
        public Object getItem(int i) {
            return ((Mqv2r_3) H5YG8fq_22.this.f676KQgRr5e_0.getChildAt(i)).KQgRr5e_0();
        }

        @Override // android.widget.Adapter
        public long getItemId(int i) {
            return i;
        }

        @Override // android.widget.Adapter
        public View getView(int i, View view, ViewGroup viewGroup) {
            if (view == null) {
                return H5YG8fq_22.this.KQgRr5e_0((ActionBar.QxJ9d_1) getItem(i), true);
            }
            ((Mqv2r_3) view).KQgRr5e_0((ActionBar.QxJ9d_1) getItem(i));
            return view;
        }
    }

    static {
        new DecelerateInterpolator();
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public final boolean m389KQgRr5e_0() {
        Spinner spinner = this.f675KQgRr5e_0;
        return spinner != null && spinner.getParent() == this;
    }

    public final boolean QxJ9d_1() {
        if (m389KQgRr5e_0()) {
            removeView(this.f675KQgRr5e_0);
            addView(this.f676KQgRr5e_0, new ViewGroup.LayoutParams(-2, -1));
            setTabSelected(this.f675KQgRr5e_0.getSelectedItemPosition());
            return false;
        }
        return false;
    }

    @Override // android.view.ViewGroup, android.view.View
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        Runnable runnable = this.f677KQgRr5e_0;
        if (runnable != null) {
            post(runnable);
        }
    }

    @Override // android.view.View
    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        X6FRs_4.KQgRr5e_0.YghfZG_14.KQgRr5e_0 KQgRr5e_02 = X6FRs_4.KQgRr5e_0.YghfZG_14.KQgRr5e_0.KQgRr5e_0(getContext());
        setContentHeight(KQgRr5e_02.Mqv2r_3());
        this.QxJ9d_1 = KQgRr5e_02.PGPF6hQ_2();
    }

    @Override // android.view.ViewGroup, android.view.View
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        Runnable runnable = this.f677KQgRr5e_0;
        if (runnable != null) {
            removeCallbacks(runnable);
        }
    }

    @Override // android.widget.AdapterView.OnItemSelectedListener
    public void onItemSelected(AdapterView<?> adapterView, View view, int i, long j) {
        ((Mqv2r_3) view).KQgRr5e_0().m824KQgRr5e_0();
    }

    @Override // android.widget.HorizontalScrollView, android.widget.FrameLayout, android.view.View
    public void onMeasure(int i, int i2) {
        int mode = View.MeasureSpec.getMode(i);
        boolean z = true;
        boolean z2 = mode == 1073741824;
        setFillViewport(z2);
        int childCount = this.f676KQgRr5e_0.getChildCount();
        if (childCount > 1 && (mode == 1073741824 || mode == Integer.MIN_VALUE)) {
            if (childCount > 2) {
                this.KQgRr5e_0 = (int) (View.MeasureSpec.getSize(i) * 0.4f);
            } else {
                this.KQgRr5e_0 = View.MeasureSpec.getSize(i) / 2;
            }
            this.KQgRr5e_0 = Math.min(this.KQgRr5e_0, this.QxJ9d_1);
        } else {
            this.KQgRr5e_0 = -1;
        }
        int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(this.PGPF6hQ_2, 1073741824);
        if ((z2 || !this.f678QxJ9d_1) ? false : false) {
            this.f676KQgRr5e_0.measure(0, makeMeasureSpec);
            if (this.f676KQgRr5e_0.getMeasuredWidth() > View.MeasureSpec.getSize(i)) {
                m388KQgRr5e_0();
            } else {
                QxJ9d_1();
            }
        } else {
            QxJ9d_1();
        }
        int measuredWidth = getMeasuredWidth();
        super.onMeasure(i, makeMeasureSpec);
        int measuredWidth2 = getMeasuredWidth();
        if (!z2 || measuredWidth == measuredWidth2) {
            return;
        }
        setTabSelected(this.f3158Mqv2r_3);
    }

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

    public void setAllowCollapse(boolean z) {
        this.f678QxJ9d_1 = z;
    }

    public void setContentHeight(int i) {
        this.PGPF6hQ_2 = i;
        requestLayout();
    }

    public void setTabSelected(int i) {
        this.f3158Mqv2r_3 = i;
        int childCount = this.f676KQgRr5e_0.getChildCount();
        int i2 = 0;
        while (i2 < childCount) {
            View childAt = this.f676KQgRr5e_0.getChildAt(i2);
            boolean z = i2 == i;
            childAt.setSelected(z);
            if (z) {
                KQgRr5e_0(i);
            }
            i2++;
        }
        Spinner spinner = this.f675KQgRr5e_0;
        if (spinner == null || i < 0) {
            return;
        }
        spinner.setSelection(i);
    }

    /* compiled from: ScrollingTabContainerView.java */
    /* loaded from: classes.dex */
    public class Mqv2r_3 extends LinearLayout {

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public View f680KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public ImageView f681KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public TextView f682KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public ActionBar.QxJ9d_1 f683KQgRr5e_0;

        /* renamed from: KQgRr5e_0  reason: collision with other field name */
        public final int[] f684KQgRr5e_0;

        public Mqv2r_3(Context context, ActionBar.QxJ9d_1 qxJ9d_1, boolean z) {
            super(context, null, X6FRs_4.KQgRr5e_0.KQgRr5e_0.actionBarTabStyle);
            int[] iArr = {16842964};
            this.f684KQgRr5e_0 = iArr;
            this.f683KQgRr5e_0 = qxJ9d_1;
            NzhupJ_29 KQgRr5e_0 = NzhupJ_29.KQgRr5e_0(context, null, iArr, X6FRs_4.KQgRr5e_0.KQgRr5e_0.actionBarTabStyle, 0);
            if (KQgRr5e_0.m419KQgRr5e_0(0)) {
                setBackgroundDrawable(KQgRr5e_0.m416KQgRr5e_0(0));
            }
            KQgRr5e_0.KQgRr5e_0();
            if (z) {
                setGravity(8388627);
            }
            m390KQgRr5e_0();
        }

        public void KQgRr5e_0(ActionBar.QxJ9d_1 qxJ9d_1) {
            this.f683KQgRr5e_0 = qxJ9d_1;
            m390KQgRr5e_0();
        }

        @Override // android.view.View
        public void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
            super.onInitializeAccessibilityEvent(accessibilityEvent);
            accessibilityEvent.setClassName(ActionBar.QxJ9d_1.class.getName());
        }

        @Override // android.view.View
        public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo accessibilityNodeInfo) {
            super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo);
            accessibilityNodeInfo.setClassName(ActionBar.QxJ9d_1.class.getName());
        }

        @Override // android.widget.LinearLayout, android.view.View
        public void onMeasure(int i, int i2) {
            super.onMeasure(i, i2);
            if (H5YG8fq_22.this.KQgRr5e_0 > 0) {
                int measuredWidth = getMeasuredWidth();
                int i3 = H5YG8fq_22.this.KQgRr5e_0;
                if (measuredWidth > i3) {
                    super.onMeasure(View.MeasureSpec.makeMeasureSpec(i3, 1073741824), i2);
                }
            }
        }

        @Override // android.view.View
        public void setSelected(boolean z) {
            boolean z2 = isSelected() != z;
            super.setSelected(z);
            if (z2 && z) {
                sendAccessibilityEvent(4);
            }
        }

        /* renamed from: KQgRr5e_0  reason: collision with other method in class */
        public void m390KQgRr5e_0() {
            ActionBar.QxJ9d_1 qxJ9d_1 = this.f683KQgRr5e_0;
            View m822KQgRr5e_0 = qxJ9d_1.m822KQgRr5e_0();
            if (m822KQgRr5e_0 != null) {
                ViewParent parent = m822KQgRr5e_0.getParent();
                if (parent != this) {
                    if (parent != null) {
                        ((ViewGroup) parent).removeView(m822KQgRr5e_0);
                    }
                    addView(m822KQgRr5e_0);
                }
                this.f680KQgRr5e_0 = m822KQgRr5e_0;
                TextView textView = this.f682KQgRr5e_0;
                if (textView != null) {
                    textView.setVisibility(8);
                }
                ImageView imageView = this.f681KQgRr5e_0;
                if (imageView != null) {
                    imageView.setVisibility(8);
                    this.f681KQgRr5e_0.setImageDrawable(null);
                    return;
                }
                return;
            }
            View view = this.f680KQgRr5e_0;
            if (view != null) {
                removeView(view);
                this.f680KQgRr5e_0 = null;
            }
            Drawable KQgRr5e_0 = qxJ9d_1.KQgRr5e_0();
            CharSequence QxJ9d_1 = qxJ9d_1.QxJ9d_1();
            if (KQgRr5e_0 != null) {
                if (this.f681KQgRr5e_0 == null) {
                    AppCompatImageView appCompatImageView = new AppCompatImageView(getContext());
                    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -2);
                    layoutParams.gravity = 16;
                    appCompatImageView.setLayoutParams(layoutParams);
                    addView(appCompatImageView, 0);
                    this.f681KQgRr5e_0 = appCompatImageView;
                }
                this.f681KQgRr5e_0.setImageDrawable(KQgRr5e_0);
                this.f681KQgRr5e_0.setVisibility(0);
            } else {
                ImageView imageView2 = this.f681KQgRr5e_0;
                if (imageView2 != null) {
                    imageView2.setVisibility(8);
                    this.f681KQgRr5e_0.setImageDrawable(null);
                }
            }
            boolean z = !TextUtils.isEmpty(QxJ9d_1);
            if (z) {
                if (this.f682KQgRr5e_0 == null) {
                    AppCompatTextView appCompatTextView = new AppCompatTextView(getContext(), null, X6FRs_4.KQgRr5e_0.KQgRr5e_0.actionBarTabTextStyle);
                    appCompatTextView.setEllipsize(TextUtils.TruncateAt.END);
                    LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(-2, -2);
                    layoutParams2.gravity = 16;
                    appCompatTextView.setLayoutParams(layoutParams2);
                    addView(appCompatTextView);
                    this.f682KQgRr5e_0 = appCompatTextView;
                }
                this.f682KQgRr5e_0.setText(QxJ9d_1);
                this.f682KQgRr5e_0.setVisibility(0);
            } else {
                TextView textView2 = this.f682KQgRr5e_0;
                if (textView2 != null) {
                    textView2.setVisibility(8);
                    this.f682KQgRr5e_0.setText((CharSequence) null);
                }
            }
            ImageView imageView3 = this.f681KQgRr5e_0;
            if (imageView3 != null) {
                imageView3.setContentDescription(qxJ9d_1.m823KQgRr5e_0());
            }
            DtqPmDY_31.KQgRr5e_0(this, z ? null : qxJ9d_1.m823KQgRr5e_0());
        }

        public ActionBar.QxJ9d_1 KQgRr5e_0() {
            return this.f683KQgRr5e_0;
        }
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public final void m388KQgRr5e_0() {
        if (m389KQgRr5e_0()) {
            return;
        }
        if (this.f675KQgRr5e_0 == null) {
            this.f675KQgRr5e_0 = KQgRr5e_0();
        }
        removeView(this.f676KQgRr5e_0);
        addView(this.f675KQgRr5e_0, new ViewGroup.LayoutParams(-2, -1));
        if (this.f675KQgRr5e_0.getAdapter() == null) {
            this.f675KQgRr5e_0.setAdapter((SpinnerAdapter) new QxJ9d_1());
        }
        Runnable runnable = this.f677KQgRr5e_0;
        if (runnable != null) {
            removeCallbacks(runnable);
            this.f677KQgRr5e_0 = null;
        }
        this.f675KQgRr5e_0.setSelection(this.f3158Mqv2r_3);
    }

    public final Spinner KQgRr5e_0() {
        AppCompatSpinner appCompatSpinner = new AppCompatSpinner(getContext(), null, X6FRs_4.KQgRr5e_0.KQgRr5e_0.actionDropDownStyle);
        appCompatSpinner.setLayoutParams(new LinearLayoutCompat.LayoutParams(-2, -1));
        appCompatSpinner.setOnItemSelectedListener(this);
        return appCompatSpinner;
    }

    public void KQgRr5e_0(int i) {
        View childAt = this.f676KQgRr5e_0.getChildAt(i);
        Runnable runnable = this.f677KQgRr5e_0;
        if (runnable != null) {
            removeCallbacks(runnable);
        }
        KQgRr5e_0 kQgRr5e_0 = new KQgRr5e_0(childAt);
        this.f677KQgRr5e_0 = kQgRr5e_0;
        post(kQgRr5e_0);
    }

    public Mqv2r_3 KQgRr5e_0(ActionBar.QxJ9d_1 qxJ9d_1, boolean z) {
        Mqv2r_3 mqv2r_3 = new Mqv2r_3(getContext(), qxJ9d_1, z);
        if (z) {
            mqv2r_3.setBackgroundDrawable(null);
            mqv2r_3.setLayoutParams(new AbsListView.LayoutParams(-1, this.PGPF6hQ_2));
        } else {
            mqv2r_3.setFocusable(true);
            if (this.f674KQgRr5e_0 == null) {
                this.f674KQgRr5e_0 = new PGPF6hQ_2();
            }
            mqv2r_3.setOnClickListener(this.f674KQgRr5e_0);
        }
        return mqv2r_3;
    }
}
