package androidx.viewpager.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewConfiguration;
import android.widget.TextView;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import g0.d;
import w3.b;

/* JADX INFO: loaded from: classes.dex */
public class PagerTabStrip extends PagerTitleStrip {
    public int S;
    public final int T;
    public final int U;
    public final int V;
    public final int W;

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

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

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

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

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

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

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

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

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

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

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

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

    @Override // androidx.viewpager.widget.PagerTitleStrip
    public final void c(int i10, float f10, boolean z10) {
        int height = getHeight();
        TextView textView = this.f4347c;
        int left = textView.getLeft();
        int i11 = this.f4334a0;
        int right = textView.getRight() + i11;
        int i12 = height - this.T;
        Rect rect = this.f4336c0;
        rect.set(left - i11, i12, right, height);
        super.c(i10, f10, z10);
        this.f4337d0 = (int) (Math.abs(f10 - 0.5f) * 2.0f * 255.0f);
        rect.union(textView.getLeft() - i11, i12, textView.getRight() + i11, height);
        invalidate(rect);
    }

    public boolean getDrawFullUnderline() {
        return this.f4338e0;
    }

    @Override // androidx.viewpager.widget.PagerTitleStrip
    public int getMinHeight() {
        return Math.max(super.getMinHeight(), this.W);
    }

    @ColorInt
    public int getTabIndicatorColor() {
        return this.S;
    }

    @Override // android.view.View
    public final void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int height = getHeight();
        TextView textView = this.f4347c;
        int left = textView.getLeft();
        int i10 = this.f4334a0;
        int i11 = left - i10;
        int right = textView.getRight() + i10;
        int i12 = height - this.T;
        Paint paint = this.f4335b0;
        paint.setColor((this.f4337d0 << 24) | (this.S & 16777215));
        float f10 = right;
        float f11 = height;
        canvas.drawRect(i11, i12, f10, f11, paint);
        if (this.f4338e0) {
            paint.setColor((this.S & 16777215) | (-16777216));
            canvas.drawRect(getPaddingLeft(), height - this.f4340g0, getWidth() - getPaddingRight(), f11, paint);
        }
    }

    @Override // android.view.View
    public final boolean onTouchEvent(MotionEvent motionEvent) {
        int action = motionEvent.getAction();
        if (action != 0 && this.f4341h0) {
            return false;
        }
        float x10 = motionEvent.getX();
        float y10 = motionEvent.getY();
        if (action == 0) {
            this.f4342i0 = x10;
            this.f4343j0 = y10;
            this.f4341h0 = false;
        } else if (action == 1) {
            int left = this.f4347c.getLeft();
            int i10 = this.f4334a0;
            if (x10 < left - i10) {
                ViewPager viewPager = this.f4345a;
                viewPager.setCurrentItem(viewPager.getCurrentItem() - 1);
            } else if (x10 > r5.getRight() + i10) {
                ViewPager viewPager2 = this.f4345a;
                viewPager2.setCurrentItem(viewPager2.getCurrentItem() + 1);
            }
        } else if (action == 2) {
            float fAbs = Math.abs(x10 - this.f4342i0);
            int i11 = this.f4344k0;
            if (fAbs > i11 || Math.abs(y10 - this.f4343j0) > i11) {
                this.f4341h0 = true;
            }
        }
        return true;
    }

    @Override // android.view.View
    public void setBackgroundColor(@ColorInt int i10) {
        super.setBackgroundColor(i10);
        if (this.f4339f0) {
            return;
        }
        this.f4338e0 = (i10 & (-16777216)) == 0;
    }

    @Override // android.view.View
    public void setBackgroundDrawable(Drawable drawable) {
        super.setBackgroundDrawable(drawable);
        if (this.f4339f0) {
            return;
        }
        this.f4338e0 = drawable == null;
    }

    @Override // android.view.View
    public void setBackgroundResource(@DrawableRes int i10) {
        super.setBackgroundResource(i10);
        if (this.f4339f0) {
            return;
        }
        this.f4338e0 = i10 == 0;
    }

    public void setDrawFullUnderline(boolean z10) {
        this.f4338e0 = z10;
        this.f4339f0 = true;
        invalidate();
    }

    @Override // android.view.View
    public void setPadding(int i10, int i11, int i12, int i13) {
        int i14 = this.U;
        if (i13 < i14) {
            i13 = i14;
        }
        super.setPadding(i10, i11, i12, i13);
    }

    public void setTabIndicatorColor(@ColorInt int i10) {
        this.S = i10;
        this.f4335b0.setColor(i10);
        invalidate();
    }

    public void setTabIndicatorColorResource(@ColorRes int i10) {
        Context context = getContext();
        Object obj = d.f26125a;
        setTabIndicatorColor(context.getColor(i10));
    }

    @Override // androidx.viewpager.widget.PagerTitleStrip
    public void setTextSpacing(int i10) {
        int i11 = this.V;
        if (i10 < i11) {
            i10 = i11;
        }
        super.setTextSpacing(i10);
    }

    public PagerTabStrip(@NonNull Context context, @Nullable AttributeSet attributeSet) {
        super(context, attributeSet);
        Paint paint = new Paint();
        this.f4335b0 = paint;
        this.f4336c0 = new Rect();
        this.f4337d0 = 255;
        this.f4338e0 = false;
        this.f4339f0 = false;
        int i10 = this.f4357m;
        this.S = i10;
        paint.setColor(i10);
        float f10 = context.getResources().getDisplayMetrics().density;
        this.T = (int) ((3.0f * f10) + 0.5f);
        this.U = (int) ((6.0f * f10) + 0.5f);
        this.V = (int) (64.0f * f10);
        this.f4334a0 = (int) ((16.0f * f10) + 0.5f);
        this.f4340g0 = (int) ((1.0f * f10) + 0.5f);
        this.W = (int) ((f10 * 32.0f) + 0.5f);
        this.f4344k0 = ViewConfiguration.get(context).getScaledTouchSlop();
        setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), getPaddingBottom());
        setTextSpacing(getTextSpacing());
        setWillNotDraw(false);
        this.f4346b.setFocusable(true);
        this.f4346b.setOnClickListener(new b(this, 0));
        this.f4348d.setFocusable(true);
        this.f4348d.setOnClickListener(new b(this, 1));
        if (getBackground() == null) {
            this.f4338e0 = true;
        }
    }
}
