package com.google.android.material.tabs;

import android.R;
import android.animation.Animator;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.RippleDrawable;
import android.text.Layout;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.PointerIcon;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.FrameLayout;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.BoolRes;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.Dimension;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.core.view.p0;
import androidx.core.view.s1;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.internal.q0;
import com.google.android.material.internal.w0;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Iterator;
import l.y3;
import x8.l;
import x8.m;
import xyz.stream.utils.a0;

/* JADX INFO: loaded from: classes2.dex */
@ViewPager.DecorView
public class TabLayout extends HorizontalScrollView {

    /* JADX INFO: renamed from: x0, reason: collision with root package name */
    public static final int f23283x0 = l.Widget_Design_TabLayout;

    /* JADX INFO: renamed from: y0, reason: collision with root package name */
    public static final p0.f f23284y0 = new p0.f(16);
    public Drawable Q;
    public int R;
    public final PorterDuff.Mode S;
    public final float T;
    public final float U;
    public final float V;
    public final int W;

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

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

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

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    public final int f23288b0;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final g f23289c;

    /* JADX INFO: renamed from: c0, reason: collision with root package name */
    public final int f23290c0;

    @Nullable
    private d currentVpSelectedListener;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final int f23291d;

    /* JADX INFO: renamed from: d0, reason: collision with root package name */
    public final int f23292d0;

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

    /* JADX INFO: renamed from: e0, reason: collision with root package name */
    public final int f23294e0;

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

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

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

    /* JADX INFO: renamed from: g0, reason: collision with root package name */
    public final int f23298g0;

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

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

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final int f23301i;

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

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final int f23303j;

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public ColorStateList f23305k;

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

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

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

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public ColorStateList f23309m;

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

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

    /* JADX INFO: renamed from: o0, reason: collision with root package name */
    public b f23312o0;

    /* JADX INFO: renamed from: p0, reason: collision with root package name */
    public final TimeInterpolator f23313p0;

    @Nullable
    private w3.a pagerAdapter;

    /* JADX INFO: renamed from: q0, reason: collision with root package name */
    public final ArrayList f23314q0;

    /* JADX INFO: renamed from: r0, reason: collision with root package name */
    public ValueAnimator f23315r0;

    /* JADX INFO: renamed from: s0, reason: collision with root package name */
    public i f23316s0;

    @Nullable
    private d selectedListener;

    @Nullable
    private h selectedTab;

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

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

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

    @Nullable
    ViewPager viewPager;

    /* JADX INFO: renamed from: w0, reason: collision with root package name */
    public final u.h f23320w0;

    @Retention(RetentionPolicy.SOURCE)
    public @interface LabelVisibility {
    }

    @Retention(RetentionPolicy.SOURCE)
    @RestrictTo({RestrictTo.Scope.f556b})
    public @interface Mode {
    }

    @Retention(RetentionPolicy.SOURCE)
    @RestrictTo({RestrictTo.Scope.f556b})
    public @interface TabGravity {
    }

    @Retention(RetentionPolicy.SOURCE)
    @RestrictTo({RestrictTo.Scope.f556b})
    public @interface TabIndicatorAnimationMode {
    }

    @Retention(RetentionPolicy.SOURCE)
    @RestrictTo({RestrictTo.Scope.f556b})
    public @interface TabIndicatorGravity {
    }

    public final class TabView extends LinearLayout {

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public static final /* synthetic */ int f23321f = 0;

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

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public TextView f23323b;

        @Nullable
        private View badgeAnchorView;

        @Nullable
        private z8.a badgeDrawable;

        @Nullable
        private Drawable baseBackgroundDrawable;

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

        @Nullable
        private ImageView customIconView;

        @Nullable
        private TextView customTextView;

        @Nullable
        private View customView;

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

        public TabView(Context context) {
            super(context);
            this.f23325d = 2;
            g(context);
            setPaddingRelative(TabLayout.this.f23291d, TabLayout.this.f23293e, TabLayout.this.f23295f, TabLayout.this.f23297g);
            setGravity(17);
            setOrientation(!TabLayout.this.f23304j0 ? 1 : 0);
            setClickable(true);
            s1.setPointerIcon(this, new p0(PointerIcon.getSystemIcon(getContext(), 1002)));
        }

        public static void a(TabView tabView, Canvas canvas) {
            Drawable drawable = tabView.baseBackgroundDrawable;
            if (drawable != null) {
                drawable.setBounds(tabView.getLeft(), tabView.getTop(), tabView.getRight(), tabView.getBottom());
                tabView.baseBackgroundDrawable.draw(canvas);
            }
        }

        private void addOnLayoutChangeListener(@Nullable View view) {
            if (view == null) {
                return;
            }
            view.addOnLayoutChangeListener(new j(this, view));
        }

        /* JADX INFO: Access modifiers changed from: private */
        @Nullable
        public z8.a getBadge() {
            return this.badgeDrawable;
        }

        @NonNull
        private z8.a getOrCreateBadge() {
            if (this.badgeDrawable == null) {
                this.badgeDrawable = z8.a.b(getContext());
            }
            d();
            z8.a aVar = this.badgeDrawable;
            if (aVar != null) {
                return aVar;
            }
            throw new IllegalStateException("Unable to create badge");
        }

        private void tryAttachBadgeToAnchor(@Nullable View view) {
            if (this.badgeDrawable == null || view == null) {
                return;
            }
            setClipChildren(false);
            setClipToPadding(false);
            ViewGroup viewGroup = (ViewGroup) getParent();
            if (viewGroup != null) {
                viewGroup.setClipChildren(false);
                viewGroup.setClipToPadding(false);
            }
            z8.e.attachBadgeDrawable(this.badgeDrawable, view, null);
            this.badgeAnchorView = view;
        }

        private void updateTextAndIcon(@Nullable TextView textView, @Nullable ImageView imageView, boolean z10) {
            h hVar = this.f23322a;
            Drawable drawableMutate = (hVar == null || hVar.getIcon() == null) ? null : this.f23322a.getIcon().mutate();
            TabLayout tabLayout = TabLayout.this;
            if (drawableMutate != null) {
                drawableMutate.setTintList(tabLayout.f23307l);
                PorterDuff.Mode mode = tabLayout.S;
                if (mode != null) {
                    drawableMutate.setTintMode(mode);
                }
            }
            h hVar2 = this.f23322a;
            CharSequence text = hVar2 != null ? hVar2.getText() : null;
            if (imageView != null) {
                if (drawableMutate != null) {
                    imageView.setImageDrawable(drawableMutate);
                    imageView.setVisibility(0);
                    setVisibility(0);
                } else {
                    imageView.setVisibility(8);
                    imageView.setImageDrawable(null);
                }
            }
            boolean z11 = true;
            boolean z12 = !TextUtils.isEmpty(text);
            if (textView != null) {
                if (z12) {
                    this.f23322a.getClass();
                } else {
                    z11 = false;
                }
                textView.setText(z12 ? text : null);
                textView.setVisibility(z11 ? 0 : 8);
                if (z12) {
                    setVisibility(0);
                }
            } else {
                z11 = false;
            }
            if (z10 && imageView != null) {
                ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) imageView.getLayoutParams();
                int iD = (z11 && imageView.getVisibility() == 0) ? (int) w0.d(getContext(), 8) : 0;
                if (tabLayout.f23304j0) {
                    if (iD != marginLayoutParams.getMarginEnd()) {
                        marginLayoutParams.setMarginEnd(iD);
                        marginLayoutParams.bottomMargin = 0;
                        imageView.setLayoutParams(marginLayoutParams);
                        imageView.requestLayout();
                    }
                } else if (iD != marginLayoutParams.bottomMargin) {
                    marginLayoutParams.bottomMargin = iD;
                    marginLayoutParams.setMarginEnd(0);
                    imageView.setLayoutParams(marginLayoutParams);
                    imageView.requestLayout();
                }
            }
            h hVar3 = this.f23322a;
            CharSequence charSequence = hVar3 != null ? hVar3.contentDesc : null;
            if (!z12) {
                text = charSequence;
            }
            y3.setTooltipText(this, text);
        }

        public final void c() {
            if (this.badgeDrawable != null) {
                setClipChildren(true);
                setClipToPadding(true);
                ViewGroup viewGroup = (ViewGroup) getParent();
                if (viewGroup != null) {
                    viewGroup.setClipChildren(true);
                    viewGroup.setClipToPadding(true);
                }
                View view = this.badgeAnchorView;
                if (view != null) {
                    z8.e.detachBadgeDrawable(this.badgeDrawable, view);
                    this.badgeAnchorView = null;
                }
            }
        }

        public final void d() {
            h hVar;
            if (this.badgeDrawable != null) {
                if (this.customView != null) {
                    c();
                    return;
                }
                if (this.f23324c != null && (hVar = this.f23322a) != null && hVar.getIcon() != null) {
                    View view = this.badgeAnchorView;
                    ImageView imageView = this.f23324c;
                    if (view == imageView) {
                        e(imageView);
                        return;
                    } else {
                        c();
                        tryAttachBadgeToAnchor(this.f23324c);
                        return;
                    }
                }
                TextView textView = this.f23323b;
                if (textView == null || this.f23322a == null) {
                    c();
                } else if (this.badgeAnchorView == textView) {
                    e(textView);
                } else {
                    c();
                    tryAttachBadgeToAnchor(this.f23323b);
                }
            }
        }

        @Override // android.view.ViewGroup, android.view.View
        public final void drawableStateChanged() {
            super.drawableStateChanged();
            int[] drawableState = getDrawableState();
            Drawable drawable = this.baseBackgroundDrawable;
            if (drawable != null && drawable.isStateful() && this.baseBackgroundDrawable.setState(drawableState)) {
                invalidate();
                TabLayout.this.invalidate();
            }
        }

        public final void e(View view) {
            z8.a aVar = this.badgeDrawable;
            if (aVar == null || view != this.badgeAnchorView) {
                return;
            }
            z8.e.setBadgeDrawableBounds(aVar, view, null);
        }

        /* JADX WARN: Removed duplicated region for block: B:13:0x0020  */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final void f() {
            boolean z10;
            i();
            h hVar = this.f23322a;
            if (hVar == null) {
                z10 = false;
            } else {
                TabLayout tabLayout = hVar.parent;
                if (tabLayout == null) {
                    throw new IllegalArgumentException("Tab not attached to a TabLayout");
                }
                int selectedTabPosition = tabLayout.getSelectedTabPosition();
                if (selectedTabPosition != -1 && selectedTabPosition == hVar.f23336a) {
                    z10 = true;
                }
            }
            setSelected(z10);
        }

        public final void g(Context context) {
            TabLayout tabLayout = TabLayout.this;
            int i10 = tabLayout.W;
            if (i10 != 0) {
                Drawable drawable = f.a.getDrawable(context, i10);
                this.baseBackgroundDrawable = drawable;
                if (drawable != null && drawable.isStateful()) {
                    this.baseBackgroundDrawable.setState(getDrawableState());
                }
            } else {
                this.baseBackgroundDrawable = null;
            }
            GradientDrawable gradientDrawable = new GradientDrawable();
            gradientDrawable.setColor(0);
            Drawable rippleDrawable = gradientDrawable;
            if (tabLayout.f23309m != null) {
                GradientDrawable gradientDrawable2 = new GradientDrawable();
                gradientDrawable2.setCornerRadius(1.0E-5f);
                gradientDrawable2.setColor(-1);
                ColorStateList colorStateListConvertToRippleDrawableColor = r9.a.convertToRippleDrawableColor(tabLayout.f23309m);
                boolean z10 = tabLayout.f23311n0;
                GradientDrawable gradientDrawable3 = gradientDrawable;
                if (z10) {
                    gradientDrawable3 = null;
                }
                rippleDrawable = new RippleDrawable(colorStateListConvertToRippleDrawableColor, gradientDrawable3, z10 ? null : gradientDrawable2);
            }
            setBackground(rippleDrawable);
            tabLayout.invalidate();
        }

        public int getContentHeight() {
            View[] viewArr = {this.f23323b, this.f23324c, this.customView};
            int iMax = 0;
            int iMin = 0;
            boolean z10 = false;
            for (int i10 = 0; i10 < 3; i10++) {
                View view = viewArr[i10];
                if (view != null && view.getVisibility() == 0) {
                    iMin = z10 ? Math.min(iMin, view.getTop()) : view.getTop();
                    iMax = z10 ? Math.max(iMax, view.getBottom()) : view.getBottom();
                    z10 = true;
                }
            }
            return iMax - iMin;
        }

        public int getContentWidth() {
            View[] viewArr = {this.f23323b, this.f23324c, this.customView};
            int iMax = 0;
            int iMin = 0;
            boolean z10 = false;
            for (int i10 = 0; i10 < 3; i10++) {
                View view = viewArr[i10];
                if (view != null && view.getVisibility() == 0) {
                    iMin = z10 ? Math.min(iMin, view.getLeft()) : view.getLeft();
                    iMax = z10 ? Math.max(iMax, view.getRight()) : view.getRight();
                    z10 = true;
                }
            }
            return iMax - iMin;
        }

        @Nullable
        public h getTab() {
            return this.f23322a;
        }

        public final void h() {
            setOrientation(!TabLayout.this.f23304j0 ? 1 : 0);
            TextView textView = this.customTextView;
            if (textView == null && this.customIconView == null) {
                updateTextAndIcon(this.f23323b, this.f23324c, true);
            } else {
                updateTextAndIcon(textView, this.customIconView, false);
            }
        }

        public final void i() {
            int i10;
            ViewParent parent;
            h hVar = this.f23322a;
            View customView = hVar != null ? hVar.getCustomView() : null;
            if (customView != null) {
                ViewParent parent2 = customView.getParent();
                if (parent2 != this) {
                    if (parent2 != null) {
                        ((ViewGroup) parent2).removeView(customView);
                    }
                    View view = this.customView;
                    if (view != null && (parent = view.getParent()) != null) {
                        ((ViewGroup) parent).removeView(this.customView);
                    }
                    addView(customView);
                }
                this.customView = customView;
                TextView textView = this.f23323b;
                if (textView != null) {
                    textView.setVisibility(8);
                }
                ImageView imageView = this.f23324c;
                if (imageView != null) {
                    imageView.setVisibility(8);
                    this.f23324c.setImageDrawable(null);
                }
                TextView textView2 = (TextView) customView.findViewById(R.id.text1);
                this.customTextView = textView2;
                if (textView2 != null) {
                    this.f23325d = textView2.getMaxLines();
                }
                this.customIconView = (ImageView) customView.findViewById(R.id.icon);
            } else {
                View view2 = this.customView;
                if (view2 != null) {
                    removeView(view2);
                    this.customView = null;
                }
                this.customTextView = null;
                this.customIconView = null;
            }
            if (this.customView == null) {
                if (this.f23324c == null) {
                    ImageView imageView2 = (ImageView) LayoutInflater.from(getContext()).inflate(x8.i.design_layout_tab_icon, (ViewGroup) this, false);
                    this.f23324c = imageView2;
                    addView(imageView2, 0);
                }
                if (this.f23323b == null) {
                    TextView textView3 = (TextView) LayoutInflater.from(getContext()).inflate(x8.i.design_layout_tab_text, (ViewGroup) this, false);
                    this.f23323b = textView3;
                    addView(textView3);
                    this.f23325d = this.f23323b.getMaxLines();
                }
                TextView textView4 = this.f23323b;
                TabLayout tabLayout = TabLayout.this;
                textView4.setTextAppearance(tabLayout.f23299h);
                if (!isSelected() || (i10 = tabLayout.f23303j) == -1) {
                    this.f23323b.setTextAppearance(tabLayout.f23301i);
                } else {
                    this.f23323b.setTextAppearance(i10);
                }
                ColorStateList colorStateList = tabLayout.f23305k;
                if (colorStateList != null) {
                    this.f23323b.setTextColor(colorStateList);
                }
                updateTextAndIcon(this.f23323b, this.f23324c, true);
                d();
                addOnLayoutChangeListener(this.f23324c);
                addOnLayoutChangeListener(this.f23323b);
            } else {
                TextView textView5 = this.customTextView;
                if (textView5 != null || this.customIconView != null) {
                    updateTextAndIcon(textView5, this.customIconView, false);
                }
            }
            if (hVar == null || TextUtils.isEmpty(hVar.contentDesc)) {
                return;
            }
            setContentDescription(hVar.contentDesc);
        }

        @Override // android.view.View
        public final void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo accessibilityNodeInfo) {
            super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo);
            q0.f fVar = new q0.f(accessibilityNodeInfo);
            z8.a aVar = this.badgeDrawable;
            if (aVar != null && aVar.isVisible()) {
                fVar.m(this.badgeDrawable.getContentDescription());
            }
            fVar.l(q0.d.a(0, 1, this.f23322a.f23336a, 1, false, isSelected()));
            if (isSelected()) {
                accessibilityNodeInfo.setClickable(false);
                fVar.h(q0.c.f32061g);
            }
            fVar.setRoleDescription(getResources().getString(x8.k.item_view_role_description));
        }

        @Override // android.widget.LinearLayout, android.view.View
        public final void onMeasure(int i10, int i11) {
            int size = View.MeasureSpec.getSize(i10);
            int mode = View.MeasureSpec.getMode(i10);
            TabLayout tabLayout = TabLayout.this;
            int tabMaxWidth = tabLayout.getTabMaxWidth();
            if (tabMaxWidth > 0 && (mode == 0 || size > tabMaxWidth)) {
                i10 = View.MeasureSpec.makeMeasureSpec(tabLayout.f23286a0, Integer.MIN_VALUE);
            }
            super.onMeasure(i10, i11);
            if (this.f23323b != null) {
                float f10 = tabLayout.T;
                if (isSelected() && tabLayout.f23303j != -1) {
                    f10 = tabLayout.U;
                }
                int i12 = this.f23325d;
                ImageView imageView = this.f23324c;
                if (imageView == null || imageView.getVisibility() != 0) {
                    TextView textView = this.f23323b;
                    if (textView != null && textView.getLineCount() > 1) {
                        f10 = tabLayout.V;
                    }
                } else {
                    i12 = 1;
                }
                float textSize = this.f23323b.getTextSize();
                int lineCount = this.f23323b.getLineCount();
                int maxLines = this.f23323b.getMaxLines();
                if (f10 != textSize || (maxLines >= 0 && i12 != maxLines)) {
                    if (tabLayout.f23302i0 == 1 && f10 > textSize && lineCount == 1) {
                        Layout layout = this.f23323b.getLayout();
                        if (layout == null) {
                            return;
                        }
                        if ((f10 / layout.getPaint().getTextSize()) * layout.getLineWidth(0) > (getMeasuredWidth() - getPaddingLeft()) - getPaddingRight()) {
                            return;
                        }
                    }
                    this.f23323b.setTextSize(0, f10);
                    this.f23323b.setMaxLines(i12);
                    super.onMeasure(i10, i11);
                }
            }
        }

        @Override // android.view.View
        public final boolean performClick() {
            boolean zPerformClick = super.performClick();
            if (this.f23322a == null) {
                return zPerformClick;
            }
            if (!zPerformClick) {
                playSoundEffect(0);
            }
            h hVar = this.f23322a;
            TabLayout tabLayout = hVar.parent;
            if (tabLayout == null) {
                throw new IllegalArgumentException("Tab not attached to a TabLayout");
            }
            tabLayout.selectTab(hVar);
            return true;
        }

        @Override // android.view.View
        public void setSelected(boolean z10) {
            isSelected();
            super.setSelected(z10);
            TextView textView = this.f23323b;
            if (textView != null) {
                textView.setSelected(z10);
            }
            ImageView imageView = this.f23324c;
            if (imageView != null) {
                imageView.setSelected(z10);
            }
            View view = this.customView;
            if (view != null) {
                view.setSelected(z10);
            }
        }

        public void setTab(@Nullable h hVar) {
            if (hVar != this.f23322a) {
                this.f23322a = hVar;
                f();
            }
        }
    }

    public TabLayout(@NonNull Context context) {
        this(context, null);
    }

    public static ColorStateList e(int i10, int i11) {
        return new ColorStateList(new int[][]{HorizontalScrollView.SELECTED_STATE_SET, HorizontalScrollView.EMPTY_STATE_SET}, new int[]{i11, i10});
    }

    @Dimension(unit = 0)
    private int getDefaultHeight() {
        ArrayList arrayList = this.f23287b;
        int size = arrayList.size();
        int i10 = 0;
        while (true) {
            if (i10 >= size) {
                break;
            }
            h hVar = (h) arrayList.get(i10);
            if (hVar == null || hVar.getIcon() == null || TextUtils.isEmpty(hVar.getText())) {
                i10++;
            } else if (!this.f23304j0) {
                return 72;
            }
        }
        return 48;
    }

    private int getTabMinWidth() {
        int i10 = this.f23288b0;
        if (i10 != -1) {
            return i10;
        }
        int i11 = this.f23302i0;
        if (i11 == 0 || i11 == 2) {
            return this.f23292d0;
        }
        return 0;
    }

    private int getTabScrollRange() {
        return Math.max(0, ((this.f23289c.getWidth() - getWidth()) - getPaddingLeft()) - getPaddingRight());
    }

    private void setSelectedTabView(int i10) {
        g gVar = this.f23289c;
        int childCount = gVar.getChildCount();
        if (i10 < childCount) {
            int i11 = 0;
            while (i11 < childCount) {
                View childAt = gVar.getChildAt(i11);
                if ((i11 != i10 || childAt.isSelected()) && (i11 == i10 || !childAt.isSelected())) {
                    childAt.setSelected(i11 == i10);
                    childAt.setActivated(i11 == i10);
                } else {
                    childAt.setSelected(i11 == i10);
                    childAt.setActivated(i11 == i10);
                    if (childAt instanceof TabView) {
                        ((TabView) childAt).i();
                    }
                }
                i11++;
            }
        }
    }

    private void setupWithViewPager(@Nullable ViewPager viewPager, boolean z10, boolean z11) {
        ArrayList arrayList;
        ArrayList arrayList2;
        ViewPager viewPager2 = this.viewPager;
        if (viewPager2 != null) {
            i iVar = this.f23316s0;
            if (iVar != null && (arrayList2 = viewPager2.f4380j0) != null) {
                arrayList2.remove(iVar);
            }
            c cVar = this.f23317t0;
            if (cVar != null && (arrayList = this.viewPager.f4386m0) != null) {
                arrayList.remove(cVar);
            }
        }
        d dVar = this.currentVpSelectedListener;
        if (dVar != null) {
            removeOnTabSelectedListener(dVar);
            this.currentVpSelectedListener = null;
        }
        if (viewPager != null) {
            this.viewPager = viewPager;
            if (this.f23316s0 == null) {
                this.f23316s0 = new i(this);
            }
            i iVar2 = this.f23316s0;
            iVar2.f23341c = 0;
            iVar2.f23340b = 0;
            if (viewPager.f4380j0 == null) {
                viewPager.f4380j0 = new ArrayList();
            }
            viewPager.f4380j0.add(iVar2);
            k kVar = new k(viewPager);
            this.currentVpSelectedListener = kVar;
            addOnTabSelectedListener(kVar);
            viewPager.getAdapter();
            if (this.f23317t0 == null) {
                this.f23317t0 = new c(this);
            }
            c cVar2 = this.f23317t0;
            cVar2.f23328a = z10;
            if (viewPager.f4386m0 == null) {
                viewPager.f4386m0 = new ArrayList();
            }
            viewPager.f4386m0.add(cVar2);
            setScrollPosition(viewPager.getCurrentItem(), 0.0f, true);
        } else {
            this.viewPager = null;
            setPagerAdapter(null, false);
        }
        this.f23318u0 = z11;
    }

    public final void a(View view) {
        if (!(view instanceof TabItem)) {
            throw new IllegalArgumentException("Only TabItem instances can be added to TabLayout");
        }
        TabItem tabItem = (TabItem) view;
        h hVar = (h) f23284y0.acquire();
        if (hVar == null) {
            hVar = new h();
            hVar.f23336a = -1;
            hVar.f23338c = -1;
        }
        hVar.parent = this;
        u.h hVar2 = this.f23320w0;
        TabView tabView = hVar2 != null ? (TabView) hVar2.acquire() : null;
        if (tabView == null) {
            tabView = new TabView(getContext());
        }
        tabView.setTab(hVar);
        tabView.setFocusable(true);
        tabView.setMinimumWidth(getTabMinWidth());
        if (TextUtils.isEmpty(hVar.contentDesc)) {
            tabView.setContentDescription(hVar.text);
        } else {
            tabView.setContentDescription(hVar.contentDesc);
        }
        hVar.f23337b = tabView;
        int i10 = hVar.f23338c;
        if (i10 != -1) {
            tabView.setId(i10);
        }
        CharSequence charSequence = tabItem.f23280a;
        if (charSequence != null) {
            hVar.setText(charSequence);
        }
        Drawable drawable = tabItem.f23281b;
        if (drawable != null) {
            hVar.setIcon(drawable);
        }
        int i11 = tabItem.f23282c;
        if (i11 != 0) {
            hVar.setCustomView(LayoutInflater.from(hVar.f23337b.getContext()).inflate(i11, (ViewGroup) hVar.f23337b, false));
        }
        if (!TextUtils.isEmpty(tabItem.getContentDescription())) {
            hVar.setContentDescription(tabItem.getContentDescription());
        }
        ArrayList arrayList = this.f23287b;
        boolean zIsEmpty = arrayList.isEmpty();
        int size = arrayList.size();
        if (hVar.parent != this) {
            throw new IllegalArgumentException("Tab belongs to a different TabLayout.");
        }
        hVar.f23336a = size;
        arrayList.add(size, hVar);
        int size2 = arrayList.size();
        int i12 = -1;
        for (int i13 = size + 1; i13 < size2; i13++) {
            if (((h) arrayList.get(i13)).f23336a == this.f23285a) {
                i12 = i13;
            }
            ((h) arrayList.get(i13)).f23336a = i13;
        }
        this.f23285a = i12;
        TabView tabView2 = hVar.f23337b;
        tabView2.setSelected(false);
        tabView2.setActivated(false);
        int i14 = hVar.f23336a;
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -1);
        if (this.f23302i0 == 1 && this.f23296f0 == 0) {
            layoutParams.width = 0;
            layoutParams.weight = 1.0f;
        } else {
            layoutParams.width = -2;
            layoutParams.weight = 0.0f;
        }
        this.f23289c.addView(tabView2, i14, layoutParams);
        if (zIsEmpty) {
            TabLayout tabLayout = hVar.parent;
            if (tabLayout == null) {
                throw new IllegalArgumentException("Tab not attached to a TabLayout");
            }
            tabLayout.selectTab(hVar);
        }
    }

    @Deprecated
    public void addOnTabSelectedListener(@Nullable d dVar) {
        ArrayList arrayList = this.f23314q0;
        if (arrayList.contains(dVar)) {
            return;
        }
        arrayList.add(dVar);
    }

    @Override // android.widget.HorizontalScrollView, android.view.ViewGroup
    public final void addView(View view) {
        a(view);
    }

    public final void b(int i10) {
        if (i10 == -1) {
            return;
        }
        if (getWindowToken() != null && isLaidOut()) {
            g gVar = this.f23289c;
            int childCount = gVar.getChildCount();
            for (int i11 = 0; i11 < childCount; i11++) {
                if (gVar.getChildAt(i11).getWidth() > 0) {
                }
            }
            int scrollX = getScrollX();
            int iD = d(0.0f, i10);
            if (scrollX != iD) {
                f();
                this.f23315r0.setIntValues(scrollX, iD);
                this.f23315r0.start();
            }
            ValueAnimator valueAnimator = gVar.f23334a;
            if (valueAnimator != null && valueAnimator.isRunning() && gVar.f23335b.f23285a != i10) {
                gVar.f23334a.cancel();
            }
            gVar.d(i10, this.f23298g0, true);
            return;
        }
        setScrollPosition(i10, 0.0f, true);
    }

    /* JADX WARN: Removed duplicated region for block: B:20:0x0034  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void c() {
        int i10 = this.f23302i0;
        int iMax = (i10 == 0 || i10 == 2) ? Math.max(0, this.f23294e0 - this.f23291d) : 0;
        g gVar = this.f23289c;
        gVar.setPaddingRelative(iMax, 0, 0, 0);
        int i11 = this.f23302i0;
        if (i11 == 0) {
            int i12 = this.f23296f0;
            if (i12 == 0) {
                gVar.setGravity(8388611);
            } else if (i12 == 1) {
                gVar.setGravity(1);
            } else if (i12 == 2) {
            }
        } else if (i11 == 1 || i11 == 2) {
            gVar.setGravity(1);
        }
        i(true);
    }

    public final int d(float f10, int i10) {
        g gVar;
        View childAt;
        int i11 = this.f23302i0;
        if ((i11 != 0 && i11 != 2) || (childAt = (gVar = this.f23289c).getChildAt(i10)) == null) {
            return 0;
        }
        int i12 = i10 + 1;
        View childAt2 = i12 < gVar.getChildCount() ? gVar.getChildAt(i12) : null;
        int width = childAt.getWidth();
        int width2 = childAt2 != null ? childAt2.getWidth() : 0;
        int left = ((width / 2) + childAt.getLeft()) - (getWidth() / 2);
        int i13 = (int) ((width + width2) * 0.5f * f10);
        return getLayoutDirection() == 0 ? left + i13 : left - i13;
    }

    public final void f() {
        if (this.f23315r0 == null) {
            ValueAnimator valueAnimator = new ValueAnimator();
            this.f23315r0 = valueAnimator;
            valueAnimator.setInterpolator(this.f23313p0);
            this.f23315r0.setDuration(this.f23298g0);
            this.f23315r0.addUpdateListener(new r6.d(this, 1));
        }
    }

    public final void g() {
        g gVar = this.f23289c;
        int childCount = gVar.getChildCount();
        while (true) {
            childCount--;
            if (childCount < 0) {
                break;
            }
            TabView tabView = (TabView) gVar.getChildAt(childCount);
            gVar.removeViewAt(childCount);
            if (tabView != null) {
                tabView.setTab(null);
                tabView.setSelected(false);
                this.f23320w0.a(tabView);
            }
            requestLayout();
        }
        Iterator it = this.f23287b.iterator();
        while (it.hasNext()) {
            h hVar = (h) it.next();
            it.remove();
            hVar.c();
            f23284y0.a(hVar);
        }
        this.selectedTab = null;
    }

    public int getSelectedTabPosition() {
        h hVar = this.selectedTab;
        if (hVar != null) {
            return hVar.f23336a;
        }
        return -1;
    }

    @Nullable
    public h getTabAt(int i10) {
        if (i10 < 0 || i10 >= getTabCount()) {
            return null;
        }
        return (h) this.f23287b.get(i10);
    }

    public int getTabCount() {
        return this.f23287b.size();
    }

    public int getTabGravity() {
        return this.f23296f0;
    }

    @Nullable
    public ColorStateList getTabIconTint() {
        return this.f23307l;
    }

    public int getTabIndicatorAnimationMode() {
        return this.f23310m0;
    }

    public int getTabIndicatorGravity() {
        return this.f23300h0;
    }

    public int getTabMaxWidth() {
        return this.f23286a0;
    }

    public int getTabMode() {
        return this.f23302i0;
    }

    @Nullable
    public ColorStateList getTabRippleColor() {
        return this.f23309m;
    }

    @NonNull
    public Drawable getTabSelectedIndicator() {
        return this.Q;
    }

    @Nullable
    public ColorStateList getTabTextColors() {
        return this.f23305k;
    }

    /* JADX WARN: Removed duplicated region for block: B:44:0x0092  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void h(int i10, float f10, boolean z10, boolean z11, boolean z12) {
        float f11 = i10 + f10;
        int iRound = Math.round(f11);
        if (iRound >= 0) {
            g gVar = this.f23289c;
            if (iRound >= gVar.getChildCount()) {
                return;
            }
            if (z11) {
                gVar.getClass();
                gVar.f23335b.f23285a = Math.round(f11);
                ValueAnimator valueAnimator = gVar.f23334a;
                if (valueAnimator != null && valueAnimator.isRunning()) {
                    gVar.f23334a.cancel();
                }
                gVar.c(gVar.getChildAt(i10), gVar.getChildAt(i10 + 1), f10);
            }
            ValueAnimator valueAnimator2 = this.f23315r0;
            if (valueAnimator2 != null && valueAnimator2.isRunning()) {
                this.f23315r0.cancel();
            }
            int iD = d(f10, i10);
            int scrollX = getScrollX();
            boolean z13 = (i10 < getSelectedTabPosition() && iD >= scrollX) || (i10 > getSelectedTabPosition() && iD <= scrollX) || i10 == getSelectedTabPosition();
            if (getLayoutDirection() != 1 ? z13 : (i10 < getSelectedTabPosition() && iD <= scrollX) || ((i10 > getSelectedTabPosition() && iD >= scrollX) || i10 == getSelectedTabPosition())) {
                if (i10 < 0) {
                    iD = 0;
                }
                scrollTo(iD, 0);
            } else if (this.f23319v0 == 1 || z12) {
            }
            if (z10) {
                setSelectedTabView(iRound);
            }
        }
    }

    public final void i(boolean z10) {
        int i10 = 0;
        while (true) {
            g gVar = this.f23289c;
            if (i10 >= gVar.getChildCount()) {
                return;
            }
            View childAt = gVar.getChildAt(i10);
            childAt.setMinimumWidth(getTabMinWidth());
            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) childAt.getLayoutParams();
            if (this.f23302i0 == 1 && this.f23296f0 == 0) {
                layoutParams.width = 0;
                layoutParams.weight = 1.0f;
            } else {
                layoutParams.width = -2;
                layoutParams.weight = 0.0f;
            }
            if (z10) {
                childAt.requestLayout();
            }
            i10++;
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onAttachedToWindow() {
        super.onAttachedToWindow();
        com.bumptech.glide.f.u(this);
        if (this.viewPager == null) {
            ViewParent parent = getParent();
            if (parent instanceof ViewPager) {
                setupWithViewPager((ViewPager) parent, true, true);
            }
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        if (this.f23318u0) {
            setupWithViewPager(null);
            this.f23318u0 = false;
        }
    }

    @Override // android.view.View
    public final void onDraw(Canvas canvas) {
        int i10 = 0;
        while (true) {
            g gVar = this.f23289c;
            if (i10 >= gVar.getChildCount()) {
                super.onDraw(canvas);
                return;
            }
            View childAt = gVar.getChildAt(i10);
            if (childAt instanceof TabView) {
                TabView.a((TabView) childAt, canvas);
            }
            i10++;
        }
    }

    @Override // android.view.View
    public final void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo accessibilityNodeInfo) {
        super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo);
        new q0.f(accessibilityNodeInfo).k(a0.y(1, getTabCount(), 1, false));
    }

    @Override // android.widget.HorizontalScrollView, android.view.ViewGroup
    public final boolean onInterceptTouchEvent(MotionEvent motionEvent) {
        return (getTabMode() == 0 || getTabMode() == 2) && super.onInterceptTouchEvent(motionEvent);
    }

    /* JADX WARN: Removed duplicated region for block: B:36:? A[RETURN, SYNTHETIC] */
    @Override // android.widget.HorizontalScrollView, android.widget.FrameLayout, android.view.View
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void onMeasure(int i10, int i11) {
        int iRound = Math.round(w0.d(getContext(), getDefaultHeight()));
        int mode = View.MeasureSpec.getMode(i11);
        if (mode != Integer.MIN_VALUE) {
            if (mode == 0) {
                i11 = View.MeasureSpec.makeMeasureSpec(getPaddingBottom() + getPaddingTop() + iRound, 1073741824);
            }
        } else if (getChildCount() == 1 && View.MeasureSpec.getSize(i11) >= iRound) {
            getChildAt(0).setMinimumHeight(iRound);
        }
        int size = View.MeasureSpec.getSize(i10);
        if (View.MeasureSpec.getMode(i10) != 0) {
            int iD = this.f23290c0;
            if (iD <= 0) {
                iD = (int) (size - w0.d(getContext(), 56));
            }
            this.f23286a0 = iD;
        }
        super.onMeasure(i10, i11);
        if (getChildCount() == 1) {
            View childAt = getChildAt(0);
            int i12 = this.f23302i0;
            if (i12 == 0) {
                if (childAt.getMeasuredWidth() >= getMeasuredWidth()) {
                    return;
                }
            } else if (i12 != 1) {
                if (i12 != 2) {
                    return;
                }
                if (childAt.getMeasuredWidth() >= getMeasuredWidth()) {
                }
            } else if (childAt.getMeasuredWidth() == getMeasuredWidth()) {
                return;
            }
            childAt.measure(View.MeasureSpec.makeMeasureSpec(getMeasuredWidth(), 1073741824), ViewGroup.getChildMeasureSpec(i11, getPaddingBottom() + getPaddingTop(), childAt.getLayoutParams().height));
        }
    }

    @Override // android.widget.HorizontalScrollView, android.view.View
    public final boolean onTouchEvent(MotionEvent motionEvent) {
        if (motionEvent.getActionMasked() != 8 || getTabMode() == 0 || getTabMode() == 2) {
            return super.onTouchEvent(motionEvent);
        }
        return false;
    }

    @Deprecated
    public void removeOnTabSelectedListener(@Nullable d dVar) {
        this.f23314q0.remove(dVar);
    }

    public void selectTab(@Nullable h hVar) {
        selectTab(hVar, true);
    }

    @Override // android.view.View
    public void setElevation(float f10) {
        super.setElevation(f10);
        com.bumptech.glide.f.t(this, f10);
    }

    public void setInlineLabel(boolean z10) {
        if (this.f23304j0 == z10) {
            return;
        }
        this.f23304j0 = z10;
        int i10 = 0;
        while (true) {
            g gVar = this.f23289c;
            if (i10 >= gVar.getChildCount()) {
                c();
                return;
            }
            View childAt = gVar.getChildAt(i10);
            if (childAt instanceof TabView) {
                ((TabView) childAt).h();
            }
            i10++;
        }
    }

    public void setInlineLabelResource(@BoolRes int i10) {
        setInlineLabel(getResources().getBoolean(i10));
    }

    @Deprecated
    public void setOnTabSelectedListener(@Nullable e eVar) {
        setOnTabSelectedListener((d) eVar);
    }

    public void setPagerAdapter(@Nullable w3.a aVar, boolean z10) {
        g();
    }

    public void setScrollAnimatorListener(Animator.AnimatorListener animatorListener) {
        f();
        this.f23315r0.addListener(animatorListener);
    }

    public void setScrollPosition(int i10, float f10, boolean z10) {
        setScrollPosition(i10, f10, z10, true);
    }

    public void setSelectedTabIndicator(@Nullable Drawable drawable) {
        if (drawable == null) {
            drawable = new GradientDrawable();
        }
        Drawable drawableMutate = drawable.mutate();
        this.Q = drawableMutate;
        int i10 = this.R;
        if (i10 != 0) {
            drawableMutate.setTint(i10);
        } else {
            drawableMutate.setTintList(null);
        }
        int intrinsicHeight = this.f23308l0;
        if (intrinsicHeight == -1) {
            intrinsicHeight = this.Q.getIntrinsicHeight();
        }
        this.f23289c.b(intrinsicHeight);
    }

    public void setSelectedTabIndicatorColor(@ColorInt int i10) {
        this.R = i10;
        Drawable drawable = this.Q;
        if (i10 != 0) {
            drawable.setTint(i10);
        } else {
            drawable.setTintList(null);
        }
        i(false);
    }

    public void setSelectedTabIndicatorGravity(int i10) {
        if (this.f23300h0 != i10) {
            this.f23300h0 = i10;
            this.f23289c.postInvalidateOnAnimation();
        }
    }

    @Deprecated
    public void setSelectedTabIndicatorHeight(int i10) {
        this.f23308l0 = i10;
        this.f23289c.b(i10);
    }

    public void setTabGravity(int i10) {
        if (this.f23296f0 != i10) {
            this.f23296f0 = i10;
            c();
        }
    }

    public void setTabIconTint(@Nullable ColorStateList colorStateList) {
        if (this.f23307l != colorStateList) {
            this.f23307l = colorStateList;
            ArrayList arrayList = this.f23287b;
            int size = arrayList.size();
            for (int i10 = 0; i10 < size; i10++) {
                TabView tabView = ((h) arrayList.get(i10)).f23337b;
                if (tabView != null) {
                    tabView.f();
                }
            }
        }
    }

    public void setTabIconTintResource(@ColorRes int i10) {
        setTabIconTint(g0.d.getColorStateList(getContext(), i10));
    }

    public void setTabIndicatorAnimationMode(int i10) {
        this.f23310m0 = i10;
        if (i10 == 0) {
            this.f23312o0 = new b();
            return;
        }
        int i11 = 1;
        if (i10 == 1) {
            this.f23312o0 = new a(0);
        } else {
            if (i10 == 2) {
                this.f23312o0 = new a(i11);
                return;
            }
            throw new IllegalArgumentException(i10 + " is not a valid TabIndicatorAnimationMode");
        }
    }

    public void setTabIndicatorFullWidth(boolean z10) {
        this.f23306k0 = z10;
        int i10 = g.f23333c;
        g gVar = this.f23289c;
        gVar.a(gVar.f23335b.getSelectedTabPosition());
        gVar.postInvalidateOnAnimation();
    }

    public void setTabMode(int i10) {
        if (i10 != this.f23302i0) {
            this.f23302i0 = i10;
            c();
        }
    }

    public void setTabRippleColor(@Nullable ColorStateList colorStateList) {
        if (this.f23309m == colorStateList) {
            return;
        }
        this.f23309m = colorStateList;
        int i10 = 0;
        while (true) {
            g gVar = this.f23289c;
            if (i10 >= gVar.getChildCount()) {
                return;
            }
            View childAt = gVar.getChildAt(i10);
            if (childAt instanceof TabView) {
                Context context = getContext();
                int i11 = TabView.f23321f;
                ((TabView) childAt).g(context);
            }
            i10++;
        }
    }

    public void setTabRippleColorResource(@ColorRes int i10) {
        setTabRippleColor(g0.d.getColorStateList(getContext(), i10));
    }

    public void setTabTextColors(int i10, int i11) {
        setTabTextColors(e(i10, i11));
    }

    @Deprecated
    public void setTabsFromPagerAdapter(@Nullable w3.a aVar) {
        setPagerAdapter(aVar, false);
    }

    public void setUnboundedRipple(boolean z10) {
        if (this.f23311n0 == z10) {
            return;
        }
        this.f23311n0 = z10;
        int i10 = 0;
        while (true) {
            g gVar = this.f23289c;
            if (i10 >= gVar.getChildCount()) {
                return;
            }
            View childAt = gVar.getChildAt(i10);
            if (childAt instanceof TabView) {
                Context context = getContext();
                int i11 = TabView.f23321f;
                ((TabView) childAt).g(context);
            }
            i10++;
        }
    }

    public void setUnboundedRippleResource(@BoolRes int i10) {
        setUnboundedRipple(getResources().getBoolean(i10));
    }

    @Override // android.widget.HorizontalScrollView, android.widget.FrameLayout, android.view.ViewGroup
    public final boolean shouldDelayChildPressedState() {
        return getTabScrollRange() > 0;
    }

    public TabLayout(@NonNull Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, x8.c.tabStyle);
    }

    @Override // android.widget.HorizontalScrollView, android.view.ViewGroup
    public final void addView(View view, int i10) {
        a(view);
    }

    @Override // android.widget.FrameLayout, android.view.ViewGroup
    public final FrameLayout.LayoutParams generateLayoutParams(AttributeSet attributeSet) {
        return generateDefaultLayoutParams();
    }

    public void selectTab(@Nullable h hVar, boolean z10) {
        h hVar2 = this.selectedTab;
        ArrayList arrayList = this.f23314q0;
        if (hVar2 == hVar) {
            if (hVar2 != null) {
                for (int size = arrayList.size() - 1; size >= 0; size--) {
                    ((d) arrayList.get(size)).getClass();
                }
                b(hVar.f23336a);
                return;
            }
            return;
        }
        int i10 = hVar != null ? hVar.f23336a : -1;
        if (z10) {
            if ((hVar2 == null || hVar2.f23336a == -1) && i10 != -1) {
                setScrollPosition(i10, 0.0f, true);
            } else {
                b(i10);
            }
            if (i10 != -1) {
                setSelectedTabView(i10);
            }
        }
        this.selectedTab = hVar;
        if (hVar2 != null && hVar2.parent != null) {
            for (int size2 = arrayList.size() - 1; size2 >= 0; size2--) {
                ((d) arrayList.get(size2)).getClass();
            }
        }
        if (hVar != null) {
            for (int size3 = arrayList.size() - 1; size3 >= 0; size3--) {
                k kVar = (k) ((d) arrayList.get(size3));
                kVar.getClass();
                kVar.f23344a.setCurrentItem(hVar.f23336a);
            }
        }
    }

    @Deprecated
    public void setOnTabSelectedListener(@Nullable d dVar) {
        d dVar2 = this.selectedListener;
        if (dVar2 != null) {
            removeOnTabSelectedListener(dVar2);
        }
        this.selectedListener = dVar;
        if (dVar != null) {
            addOnTabSelectedListener(dVar);
        }
    }

    public void setScrollPosition(int i10, float f10, boolean z10, boolean z11) {
        h(i10, f10, z10, z11, true);
    }

    public void setTabTextColors(@Nullable ColorStateList colorStateList) {
        if (this.f23305k != colorStateList) {
            this.f23305k = colorStateList;
            ArrayList arrayList = this.f23287b;
            int size = arrayList.size();
            for (int i10 = 0; i10 < size; i10++) {
                TabView tabView = ((h) arrayList.get(i10)).f23337b;
                if (tabView != null) {
                    tabView.f();
                }
            }
        }
    }

    /* JADX WARN: Illegal instructions before constructor call */
    public TabLayout(@NonNull Context context, @Nullable AttributeSet attributeSet, int i10) {
        int i11 = f23283x0;
        super(x9.a.wrap(context, attributeSet, i10, i11), attributeSet, i10);
        this.f23285a = -1;
        this.f23287b = new ArrayList();
        this.f23303j = -1;
        this.R = 0;
        this.f23286a0 = Integer.MAX_VALUE;
        this.f23308l0 = -1;
        this.f23314q0 = new ArrayList();
        this.f23320w0 = new u.h(12, 1);
        Context context2 = getContext();
        setHorizontalScrollBarEnabled(false);
        g gVar = new g(this, context2);
        this.f23289c = gVar;
        super.addView(gVar, 0, new FrameLayout.LayoutParams(-2, -1));
        int[] iArr = m.TabLayout;
        int i12 = m.TabLayout_tabTextAppearance;
        TypedArray typedArrayC = q0.c(context2, attributeSet, iArr, i10, i11, i12);
        ColorStateList colorStateListOrNull = j9.c.getColorStateListOrNull(getBackground());
        if (colorStateListOrNull != null) {
            com.google.android.material.shape.k kVar = new com.google.android.material.shape.k();
            kVar.setFillColor(colorStateListOrNull);
            kVar.s(context2);
            kVar.w(getElevation());
            setBackground(kVar);
        }
        setSelectedTabIndicator(q9.d.getDrawable(context2, typedArrayC, m.TabLayout_tabIndicator));
        setSelectedTabIndicatorColor(typedArrayC.getColor(m.TabLayout_tabIndicatorColor, 0));
        gVar.b(typedArrayC.getDimensionPixelSize(m.TabLayout_tabIndicatorHeight, -1));
        setSelectedTabIndicatorGravity(typedArrayC.getInt(m.TabLayout_tabIndicatorGravity, 0));
        setTabIndicatorAnimationMode(typedArrayC.getInt(m.TabLayout_tabIndicatorAnimationMode, 0));
        setTabIndicatorFullWidth(typedArrayC.getBoolean(m.TabLayout_tabIndicatorFullWidth, true));
        int dimensionPixelSize = typedArrayC.getDimensionPixelSize(m.TabLayout_tabPadding, 0);
        this.f23297g = dimensionPixelSize;
        this.f23295f = dimensionPixelSize;
        this.f23293e = dimensionPixelSize;
        this.f23291d = dimensionPixelSize;
        this.f23291d = typedArrayC.getDimensionPixelSize(m.TabLayout_tabPaddingStart, dimensionPixelSize);
        this.f23293e = typedArrayC.getDimensionPixelSize(m.TabLayout_tabPaddingTop, dimensionPixelSize);
        this.f23295f = typedArrayC.getDimensionPixelSize(m.TabLayout_tabPaddingEnd, dimensionPixelSize);
        this.f23297g = typedArrayC.getDimensionPixelSize(m.TabLayout_tabPaddingBottom, dimensionPixelSize);
        if (q9.c.a(context2, x8.c.isMaterial3Theme, false)) {
            this.f23299h = x8.c.textAppearanceTitleSmall;
        } else {
            this.f23299h = x8.c.textAppearanceButton;
        }
        int resourceId = typedArrayC.getResourceId(i12, l.TextAppearance_Design_Tab);
        this.f23301i = resourceId;
        int[] iArr2 = d.j.TextAppearance;
        TypedArray typedArrayObtainStyledAttributes = context2.obtainStyledAttributes(resourceId, iArr2);
        try {
            this.T = typedArrayObtainStyledAttributes.getDimensionPixelSize(d.j.TextAppearance_android_textSize, 0);
            int i13 = d.j.TextAppearance_android_textColor;
            this.f23305k = q9.d.getColorStateList(context2, typedArrayObtainStyledAttributes, i13);
            typedArrayObtainStyledAttributes.recycle();
            int i14 = m.TabLayout_tabSelectedTextAppearance;
            if (typedArrayC.hasValue(i14)) {
                this.f23303j = typedArrayC.getResourceId(i14, resourceId);
            }
            int i15 = this.f23303j;
            if (i15 != -1) {
                typedArrayObtainStyledAttributes = context2.obtainStyledAttributes(i15, iArr2);
                try {
                    this.U = typedArrayObtainStyledAttributes.getDimensionPixelSize(r2, (int) r3);
                    ColorStateList colorStateList = q9.d.getColorStateList(context2, typedArrayObtainStyledAttributes, i13);
                    if (colorStateList != null) {
                        this.f23305k = e(this.f23305k.getDefaultColor(), colorStateList.getColorForState(new int[]{R.attr.state_selected}, colorStateList.getDefaultColor()));
                    }
                } finally {
                }
            }
            int i16 = m.TabLayout_tabTextColor;
            if (typedArrayC.hasValue(i16)) {
                this.f23305k = q9.d.getColorStateList(context2, typedArrayC, i16);
            }
            int i17 = m.TabLayout_tabSelectedTextColor;
            if (typedArrayC.hasValue(i17)) {
                this.f23305k = e(this.f23305k.getDefaultColor(), typedArrayC.getColor(i17, 0));
            }
            this.f23307l = q9.d.getColorStateList(context2, typedArrayC, m.TabLayout_tabIconTint);
            this.S = w0.f(typedArrayC.getInt(m.TabLayout_tabIconTintMode, -1), null);
            this.f23309m = q9.d.getColorStateList(context2, typedArrayC, m.TabLayout_tabRippleColor);
            this.f23298g0 = typedArrayC.getInt(m.TabLayout_tabIndicatorAnimationDuration, 300);
            this.f23313p0 = com.bumptech.glide.f.p(context2, x8.c.motionEasingEmphasizedInterpolator, y8.a.f36865b);
            this.f23288b0 = typedArrayC.getDimensionPixelSize(m.TabLayout_tabMinWidth, -1);
            this.f23290c0 = typedArrayC.getDimensionPixelSize(m.TabLayout_tabMaxWidth, -1);
            this.W = typedArrayC.getResourceId(m.TabLayout_tabBackground, 0);
            this.f23294e0 = typedArrayC.getDimensionPixelSize(m.TabLayout_tabContentStart, 0);
            this.f23302i0 = typedArrayC.getInt(m.TabLayout_tabMode, 1);
            this.f23296f0 = typedArrayC.getInt(m.TabLayout_tabGravity, 0);
            this.f23304j0 = typedArrayC.getBoolean(m.TabLayout_tabInlineLabel, false);
            this.f23311n0 = typedArrayC.getBoolean(m.TabLayout_tabUnboundedRipple, false);
            typedArrayC.recycle();
            Resources resources = getResources();
            this.V = resources.getDimensionPixelSize(x8.e.design_tab_text_size_2line);
            this.f23292d0 = resources.getDimensionPixelSize(x8.e.design_tab_scrollable_min_width);
            c();
        } finally {
        }
    }

    @Override // android.widget.HorizontalScrollView, android.view.ViewGroup, android.view.ViewManager
    public final void addView(View view, ViewGroup.LayoutParams layoutParams) {
        a(view);
    }

    @Override // android.widget.HorizontalScrollView, android.view.ViewGroup
    public final void addView(View view, int i10, ViewGroup.LayoutParams layoutParams) {
        a(view);
    }

    public void setSelectedTabIndicator(@DrawableRes int i10) {
        if (i10 != 0) {
            setSelectedTabIndicator(f.a.getDrawable(getContext(), i10));
        } else {
            setSelectedTabIndicator((Drawable) null);
        }
    }

    public void setupWithViewPager(@Nullable ViewPager viewPager) {
        setupWithViewPager(viewPager, true);
    }

    public void setupWithViewPager(@Nullable ViewPager viewPager, boolean z10) {
        setupWithViewPager(viewPager, z10, false);
    }
}
