package com.google.android.material.tabs;

import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.LinearLayout;
import com.google.android.material.internal.w0;

/* JADX INFO: loaded from: classes2.dex */
public final class g extends LinearLayout {

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

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final /* synthetic */ TabLayout f23335b;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public g(TabLayout tabLayout, Context context) {
        super(context);
        this.f23335b = tabLayout;
        setWillNotDraw(false);
    }

    public final void a(int i10) {
        TabLayout tabLayout = this.f23335b;
        if (tabLayout.f23319v0 == 0 || (tabLayout.getTabSelectedIndicator().getBounds().left == -1 && tabLayout.getTabSelectedIndicator().getBounds().right == -1)) {
            View childAt = getChildAt(i10);
            b bVar = tabLayout.f23312o0;
            Drawable drawable = tabLayout.Q;
            bVar.getClass();
            RectF rectFCalculateIndicatorWidthForTab = b.calculateIndicatorWidthForTab(tabLayout, childAt);
            drawable.setBounds((int) rectFCalculateIndicatorWidthForTab.left, drawable.getBounds().top, (int) rectFCalculateIndicatorWidthForTab.right, drawable.getBounds().bottom);
            tabLayout.f23285a = i10;
        }
    }

    public final void b(int i10) {
        TabLayout tabLayout = this.f23335b;
        Rect bounds = tabLayout.Q.getBounds();
        tabLayout.Q.setBounds(bounds.left, 0, bounds.right, i10);
        requestLayout();
    }

    public final void c(View view, View view2, float f10) {
        if (view == null || view.getWidth() <= 0) {
            TabLayout tabLayout = this.f23335b;
            Drawable drawable = tabLayout.Q;
            drawable.setBounds(-1, drawable.getBounds().top, -1, tabLayout.Q.getBounds().bottom);
        } else {
            TabLayout tabLayout2 = this.f23335b;
            tabLayout2.f23312o0.a(tabLayout2, view, view2, f10, tabLayout2.Q);
        }
        postInvalidateOnAnimation();
    }

    public final void d(int i10, int i11, boolean z10) {
        TabLayout tabLayout = this.f23335b;
        if (tabLayout.f23285a == i10) {
            return;
        }
        View childAt = getChildAt(tabLayout.getSelectedTabPosition());
        View childAt2 = getChildAt(i10);
        if (childAt2 == null) {
            a(tabLayout.getSelectedTabPosition());
            return;
        }
        tabLayout.f23285a = i10;
        f fVar = new f(this, childAt, childAt2);
        if (!z10) {
            this.f23334a.removeAllUpdateListeners();
            this.f23334a.addUpdateListener(fVar);
            return;
        }
        ValueAnimator valueAnimator = new ValueAnimator();
        this.f23334a = valueAnimator;
        valueAnimator.setInterpolator(tabLayout.f23313p0);
        valueAnimator.setDuration(i11);
        valueAnimator.setFloatValues(0.0f, 1.0f);
        valueAnimator.addUpdateListener(fVar);
        valueAnimator.start();
    }

    @Override // android.view.View
    public final void draw(Canvas canvas) {
        int height;
        TabLayout tabLayout = this.f23335b;
        int iHeight = tabLayout.Q.getBounds().height();
        if (iHeight < 0) {
            iHeight = tabLayout.Q.getIntrinsicHeight();
        }
        int i10 = tabLayout.f23300h0;
        if (i10 == 0) {
            height = getHeight() - iHeight;
            iHeight = getHeight();
        } else if (i10 != 1) {
            height = 0;
            if (i10 != 2) {
                iHeight = i10 != 3 ? 0 : getHeight();
            }
        } else {
            height = (getHeight() - iHeight) / 2;
            iHeight = (getHeight() + iHeight) / 2;
        }
        if (tabLayout.Q.getBounds().width() > 0) {
            Rect bounds = tabLayout.Q.getBounds();
            tabLayout.Q.setBounds(bounds.left, height, bounds.right, iHeight);
            tabLayout.Q.draw(canvas);
        }
        super.draw(canvas);
    }

    @Override // android.widget.LinearLayout, android.view.ViewGroup, android.view.View
    public final void onLayout(boolean z10, int i10, int i11, int i12, int i13) {
        super.onLayout(z10, i10, i11, i12, i13);
        ValueAnimator valueAnimator = this.f23334a;
        TabLayout tabLayout = this.f23335b;
        if (valueAnimator != null && valueAnimator.isRunning()) {
            d(tabLayout.getSelectedTabPosition(), -1, false);
            return;
        }
        if (tabLayout.f23285a == -1) {
            tabLayout.f23285a = tabLayout.getSelectedTabPosition();
        }
        a(tabLayout.f23285a);
    }

    @Override // android.widget.LinearLayout, android.view.View
    public final void onMeasure(int i10, int i11) {
        super.onMeasure(i10, i11);
        if (View.MeasureSpec.getMode(i10) != 1073741824) {
            return;
        }
        TabLayout tabLayout = this.f23335b;
        if (tabLayout.f23296f0 == 1 || tabLayout.f23302i0 == 2) {
            int childCount = getChildCount();
            int iMax = 0;
            for (int i12 = 0; i12 < childCount; i12++) {
                View childAt = getChildAt(i12);
                if (childAt.getVisibility() == 0) {
                    iMax = Math.max(iMax, childAt.getMeasuredWidth());
                }
            }
            if (iMax <= 0) {
                return;
            }
            if (iMax * childCount <= getMeasuredWidth() - (((int) w0.d(getContext(), 16)) * 2)) {
                boolean z10 = false;
                for (int i13 = 0; i13 < childCount; i13++) {
                    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) getChildAt(i13).getLayoutParams();
                    if (layoutParams.width != iMax || layoutParams.weight != 0.0f) {
                        layoutParams.width = iMax;
                        layoutParams.weight = 0.0f;
                        z10 = true;
                    }
                }
                if (!z10) {
                    return;
                }
            } else {
                tabLayout.f23296f0 = 0;
                tabLayout.i(false);
            }
            super.onMeasure(i10, i11);
        }
    }

    @Override // android.widget.LinearLayout, android.view.View
    public final void onRtlPropertiesChanged(int i10) {
        super.onRtlPropertiesChanged(i10);
    }
}
