package androidx.viewpager.widget;

import android.R;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.TextView;
import androidx.annotation.ColorInt;
import androidx.annotation.FloatRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;
import java.util.ArrayList;
import w3.c;
import w3.d;
import w3.h;

/* JADX INFO: loaded from: classes.dex */
@ViewPager.DecorView
public class PagerTitleStrip extends ViewGroup {
    public static final int[] Q = {R.attr.textAppearance, R.attr.textSize, R.attr.textColor, R.attr.gravity};
    public static final int[] R = {R.attr.textAllCaps};

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    private static void setSingleLineAllCaps(TextView textView) {
        Context context = textView.getContext();
        d dVar = new d();
        dVar.f34172a = context.getResources().getConfiguration().locale;
        textView.setTransformationMethod(dVar);
    }

    public final void a() {
        ViewPager viewPager = this.f4345a;
        if (viewPager != null) {
            this.f4349e = -1;
            this.f4350f = -1.0f;
            b(viewPager.getCurrentItem());
            requestLayout();
        }
    }

    public final void b(int i10) {
        this.f4353i = true;
        TextView textView = this.f4346b;
        textView.setText((CharSequence) null);
        TextView textView2 = this.f4347c;
        textView2.setText((CharSequence) null);
        TextView textView3 = this.f4348d;
        textView3.setText((CharSequence) null);
        int iMakeMeasureSpec = View.MeasureSpec.makeMeasureSpec(Math.max(0, (int) (((getWidth() - getPaddingLeft()) - getPaddingRight()) * 0.8f)), Integer.MIN_VALUE);
        int iMakeMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(Math.max(0, (getHeight() - getPaddingTop()) - getPaddingBottom()), Integer.MIN_VALUE);
        textView.measure(iMakeMeasureSpec, iMakeMeasureSpec2);
        textView2.measure(iMakeMeasureSpec, iMakeMeasureSpec2);
        textView3.measure(iMakeMeasureSpec, iMakeMeasureSpec2);
        this.f4349e = i10;
        if (!this.f4354j) {
            c(i10, this.f4350f, false);
        }
        this.f4353i = false;
    }

    public void c(int i10, float f10, boolean z10) {
        int i11;
        int i12;
        int i13;
        int i14;
        if (i10 != this.f4349e) {
            this.f4345a.getAdapter();
            b(i10);
        } else if (!z10 && f10 == this.f4350f) {
            return;
        }
        this.f4354j = true;
        TextView textView = this.f4346b;
        int measuredWidth = textView.getMeasuredWidth();
        TextView textView2 = this.f4347c;
        int measuredWidth2 = textView2.getMeasuredWidth();
        TextView textView3 = this.f4348d;
        int measuredWidth3 = textView3.getMeasuredWidth();
        int i15 = measuredWidth2 / 2;
        int width = getWidth();
        int height = getHeight();
        int paddingLeft = getPaddingLeft();
        int paddingRight = getPaddingRight();
        int paddingTop = getPaddingTop();
        int paddingBottom = getPaddingBottom();
        int i16 = paddingRight + i15;
        int i17 = (width - (paddingLeft + i15)) - i16;
        float f11 = f10 + 0.5f;
        if (f11 > 1.0f) {
            f11 -= 1.0f;
        }
        int i18 = ((width - i16) - ((int) (i17 * f11))) - i15;
        int i19 = measuredWidth2 + i18;
        int baseline = textView.getBaseline();
        int baseline2 = textView2.getBaseline();
        int baseline3 = textView3.getBaseline();
        int iMax = Math.max(Math.max(baseline, baseline2), baseline3);
        int i20 = iMax - baseline;
        int i21 = iMax - baseline2;
        int i22 = iMax - baseline3;
        int iMax2 = Math.max(Math.max(textView.getMeasuredHeight() + i20, textView2.getMeasuredHeight() + i21), textView3.getMeasuredHeight() + i22);
        int i23 = this.f4352h & 112;
        if (i23 == 16) {
            i11 = (((height - paddingTop) - paddingBottom) - iMax2) / 2;
        } else {
            if (i23 != 80) {
                i12 = i20 + paddingTop;
                i13 = i21 + paddingTop;
                i14 = paddingTop + i22;
                textView2.layout(i18, i13, i19, textView2.getMeasuredHeight() + i13);
                int iMin = Math.min(paddingLeft, (i18 - this.f4351g) - measuredWidth);
                textView.layout(iMin, i12, measuredWidth + iMin, textView.getMeasuredHeight() + i12);
                int iMax3 = Math.max((width - paddingRight) - measuredWidth3, i19 + this.f4351g);
                textView3.layout(iMax3, i14, iMax3 + measuredWidth3, textView3.getMeasuredHeight() + i14);
                this.f4350f = f10;
                this.f4354j = false;
            }
            i11 = (height - paddingBottom) - iMax2;
        }
        i12 = i20 + i11;
        i13 = i21 + i11;
        i14 = i11 + i22;
        textView2.layout(i18, i13, i19, textView2.getMeasuredHeight() + i13);
        int iMin2 = Math.min(paddingLeft, (i18 - this.f4351g) - measuredWidth);
        textView.layout(iMin2, i12, measuredWidth + iMin2, textView.getMeasuredHeight() + i12);
        int iMax32 = Math.max((width - paddingRight) - measuredWidth3, i19 + this.f4351g);
        textView3.layout(iMax32, i14, iMax32 + measuredWidth3, textView3.getMeasuredHeight() + i14);
        this.f4350f = f10;
        this.f4354j = false;
    }

    public int getMinHeight() {
        Drawable background = getBackground();
        if (background != null) {
            return background.getIntrinsicHeight();
        }
        return 0;
    }

    public int getTextSpacing() {
        return this.f4351g;
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onAttachedToWindow() {
        super.onAttachedToWindow();
        ViewParent parent = getParent();
        if (!(parent instanceof ViewPager)) {
            throw new IllegalStateException("PagerTitleStrip must be a direct child of a ViewPager.");
        }
        ViewPager viewPager = (ViewPager) parent;
        viewPager.getAdapter();
        c cVar = this.f4355k;
        viewPager.f4384l0 = cVar;
        if (viewPager.f4386m0 == null) {
            viewPager.f4386m0 = new ArrayList();
        }
        viewPager.f4386m0.add(cVar);
        this.f4345a = viewPager;
        a();
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        ViewPager viewPager = this.f4345a;
        if (viewPager != null) {
            viewPager.getAdapter();
            a();
            ViewPager viewPager2 = this.f4345a;
            h hVar = viewPager2.f4384l0;
            viewPager2.f4384l0 = null;
            ArrayList arrayList = viewPager2.f4386m0;
            if (arrayList != null) {
                arrayList.remove(this.f4355k);
            }
            this.f4345a = null;
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onLayout(boolean z10, int i10, int i11, int i12, int i13) {
        if (this.f4345a != null) {
            float f10 = this.f4350f;
            if (f10 < 0.0f) {
                f10 = 0.0f;
            }
            c(this.f4349e, f10, true);
        }
    }

    @Override // android.view.View
    public final void onMeasure(int i10, int i11) {
        int iMax;
        if (View.MeasureSpec.getMode(i10) != 1073741824) {
            throw new IllegalStateException("Must measure with an exact width");
        }
        int paddingBottom = getPaddingBottom() + getPaddingTop();
        int childMeasureSpec = ViewGroup.getChildMeasureSpec(i11, paddingBottom, -2);
        int size = View.MeasureSpec.getSize(i10);
        int childMeasureSpec2 = ViewGroup.getChildMeasureSpec(i10, (int) (size * 0.2f), -2);
        this.f4346b.measure(childMeasureSpec2, childMeasureSpec);
        TextView textView = this.f4347c;
        textView.measure(childMeasureSpec2, childMeasureSpec);
        this.f4348d.measure(childMeasureSpec2, childMeasureSpec);
        if (View.MeasureSpec.getMode(i11) == 1073741824) {
            iMax = View.MeasureSpec.getSize(i11);
        } else {
            iMax = Math.max(getMinHeight(), textView.getMeasuredHeight() + paddingBottom);
        }
        setMeasuredDimension(size, View.resolveSizeAndState(iMax, i11, textView.getMeasuredState() << 16));
    }

    @Override // android.view.View, android.view.ViewParent
    public final void requestLayout() {
        if (this.f4353i) {
            return;
        }
        super.requestLayout();
    }

    public void setGravity(int i10) {
        this.f4352h = i10;
        requestLayout();
    }

    public void setNonPrimaryAlpha(@FloatRange(from = 0.0d, to = 1.0d) float f10) {
        int i10 = ((int) (f10 * 255.0f)) & 255;
        this.f4356l = i10;
        int i11 = (i10 << 24) | (this.f4357m & 16777215);
        this.f4346b.setTextColor(i11);
        this.f4348d.setTextColor(i11);
    }

    public void setTextColor(@ColorInt int i10) {
        this.f4357m = i10;
        this.f4347c.setTextColor(i10);
        int i11 = (this.f4356l << 24) | (this.f4357m & 16777215);
        this.f4346b.setTextColor(i11);
        this.f4348d.setTextColor(i11);
    }

    public void setTextSize(int i10, float f10) {
        this.f4346b.setTextSize(i10, f10);
        this.f4347c.setTextSize(i10, f10);
        this.f4348d.setTextSize(i10, f10);
    }

    public void setTextSpacing(int i10) {
        this.f4351g = i10;
        requestLayout();
    }

    /* JADX WARN: Removed duplicated region for block: B:16:0x00a6  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public PagerTitleStrip(@NonNull Context context, @Nullable AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f4349e = -1;
        this.f4350f = -1.0f;
        this.f4355k = new c(this);
        TextView textView = new TextView(context);
        this.f4346b = textView;
        addView(textView);
        TextView textView2 = new TextView(context);
        this.f4347c = textView2;
        addView(textView2);
        TextView textView3 = new TextView(context);
        this.f4348d = textView3;
        addView(textView3);
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, Q);
        int resourceId = typedArrayObtainStyledAttributes.getResourceId(0, 0);
        if (resourceId != 0) {
            textView.setTextAppearance(resourceId);
            textView2.setTextAppearance(resourceId);
            textView3.setTextAppearance(resourceId);
        }
        int dimensionPixelSize = typedArrayObtainStyledAttributes.getDimensionPixelSize(1, 0);
        if (dimensionPixelSize != 0) {
            setTextSize(0, dimensionPixelSize);
        }
        if (typedArrayObtainStyledAttributes.hasValue(2)) {
            int color = typedArrayObtainStyledAttributes.getColor(2, 0);
            textView.setTextColor(color);
            textView2.setTextColor(color);
            textView3.setTextColor(color);
        }
        this.f4352h = typedArrayObtainStyledAttributes.getInteger(3, 80);
        typedArrayObtainStyledAttributes.recycle();
        this.f4357m = textView2.getTextColors().getDefaultColor();
        setNonPrimaryAlpha(0.6f);
        TextUtils.TruncateAt truncateAt = TextUtils.TruncateAt.END;
        textView.setEllipsize(truncateAt);
        textView2.setEllipsize(truncateAt);
        textView3.setEllipsize(truncateAt);
        if (resourceId != 0) {
            TypedArray typedArrayObtainStyledAttributes2 = context.obtainStyledAttributes(resourceId, R);
            boolean z10 = typedArrayObtainStyledAttributes2.getBoolean(0, false);
            typedArrayObtainStyledAttributes2.recycle();
            if (z10) {
                setSingleLineAllCaps(textView);
                setSingleLineAllCaps(textView2);
                setSingleLineAllCaps(textView3);
            } else {
                textView.setSingleLine();
                textView2.setSingleLine();
                textView3.setSingleLine();
            }
        }
        this.f4351g = (int) (context.getResources().getDisplayMetrics().density * 16.0f);
    }
}
