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.View; import android.view.ViewConfiguration; import androidx.core.content.ContextCompat; import androidx.core.view.ViewCompat; /* loaded from: classes2.dex */ public class PagerTabStrip extends PagerTitleStrip { private static final int FULL_UNDERLINE_HEIGHT = 1; private static final int INDICATOR_HEIGHT = 3; private static final int MIN_PADDING_BOTTOM = 6; private static final int MIN_STRIP_HEIGHT = 32; private static final int MIN_TEXT_SPACING = 64; private static final int TAB_PADDING = 16; private static final int TAB_SPACING = 32; private static final String TAG = "PagerTabStrip"; private boolean mDrawFullUnderline; private boolean mDrawFullUnderlineSet; private int mFullUnderlineHeight; private boolean mIgnoreTap; private int mIndicatorColor; private int mIndicatorHeight; private float mInitialMotionX; private float mInitialMotionY; private int mMinPaddingBottom; private int mMinStripHeight; private int mMinTextSpacing; private int mTabAlpha; private int mTabPadding; private final Paint mTabPaint; private final Rect mTempRect; private int mTouchSlop; public boolean getDrawFullUnderline() { return this.mDrawFullUnderline; } public int getTabIndicatorColor() { return this.mIndicatorColor; } public PagerTabStrip(Context context) { this(context, null); } public PagerTabStrip(Context context, AttributeSet attributeSet) { super(context, attributeSet); Paint paint = new Paint(); this.mTabPaint = paint; this.mTempRect = new Rect(); this.mTabAlpha = 255; this.mDrawFullUnderline = false; this.mDrawFullUnderlineSet = false; int i = this.mTextColor; this.mIndicatorColor = i; paint.setColor(i); float f = context.getResources().getDisplayMetrics().density; this.mIndicatorHeight = (int) ((3.0f * f) + 0.5f); this.mMinPaddingBottom = (int) ((6.0f * f) + 0.5f); this.mMinTextSpacing = (int) (64.0f * f); this.mTabPadding = (int) ((16.0f * f) + 0.5f); this.mFullUnderlineHeight = (int) ((1.0f * f) + 0.5f); this.mMinStripHeight = (int) ((f * 32.0f) + 0.5f); this.mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); setPadding(getPaddingLeft(), getPaddingTop(), getPaddingRight(), getPaddingBottom()); setTextSpacing(getTextSpacing()); setWillNotDraw(false); this.mPrevText.setFocusable(true); this.mPrevText.setOnClickListener(new View.OnClickListener() { // from class: androidx.viewpager.widget.PagerTabStrip.1 @Override // android.view.View.OnClickListener public void onClick(View view) { PagerTabStrip.this.mPager.setCurrentItem(PagerTabStrip.this.mPager.getCurrentItem() - 1); } }); this.mNextText.setFocusable(true); this.mNextText.setOnClickListener(new View.OnClickListener() { // from class: androidx.viewpager.widget.PagerTabStrip.2 @Override // android.view.View.OnClickListener public void onClick(View view) { PagerTabStrip.this.mPager.setCurrentItem(PagerTabStrip.this.mPager.getCurrentItem() + 1); } }); if (getBackground() == null) { this.mDrawFullUnderline = true; } } public void setTabIndicatorColor(int i) { this.mIndicatorColor = i; this.mTabPaint.setColor(i); invalidate(); } public void setTabIndicatorColorResource(int i) { setTabIndicatorColor(ContextCompat.getColor(getContext(), i)); } @Override // android.view.View public void setPadding(int i, int i2, int i3, int i4) { int i5 = this.mMinPaddingBottom; if (i4 < i5) { i4 = i5; } super.setPadding(i, i2, i3, i4); } @Override // androidx.viewpager.widget.PagerTitleStrip public void setTextSpacing(int i) { int i2 = this.mMinTextSpacing; if (i < i2) { i = i2; } super.setTextSpacing(i); } @Override // android.view.View public void setBackgroundDrawable(Drawable drawable) { super.setBackgroundDrawable(drawable); if (this.mDrawFullUnderlineSet) { return; } this.mDrawFullUnderline = drawable == null; } @Override // android.view.View public void setBackgroundColor(int i) { super.setBackgroundColor(i); if (this.mDrawFullUnderlineSet) { return; } this.mDrawFullUnderline = (i & ViewCompat.MEASURED_STATE_MASK) == 0; } @Override // android.view.View public void setBackgroundResource(int i) { super.setBackgroundResource(i); if (this.mDrawFullUnderlineSet) { return; } this.mDrawFullUnderline = i == 0; } public void setDrawFullUnderline(boolean z) { this.mDrawFullUnderline = z; this.mDrawFullUnderlineSet = true; invalidate(); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // androidx.viewpager.widget.PagerTitleStrip public int getMinHeight() { return Math.max(super.getMinHeight(), this.mMinStripHeight); } @Override // android.view.View public boolean onTouchEvent(MotionEvent motionEvent) { int action = motionEvent.getAction(); if (action != 0 && this.mIgnoreTap) { return false; } float x = motionEvent.getX(); float y = motionEvent.getY(); if (action == 0) { this.mInitialMotionX = x; this.mInitialMotionY = y; this.mIgnoreTap = false; } else if (action != 1) { if (action == 2 && (Math.abs(x - this.mInitialMotionX) > this.mTouchSlop || Math.abs(y - this.mInitialMotionY) > this.mTouchSlop)) { this.mIgnoreTap = true; } } else if (x < this.mCurrText.getLeft() - this.mTabPadding) { this.mPager.setCurrentItem(this.mPager.getCurrentItem() - 1); } else if (x > this.mCurrText.getRight() + this.mTabPadding) { this.mPager.setCurrentItem(this.mPager.getCurrentItem() + 1); } return true; } @Override // android.view.View protected void onDraw(Canvas canvas) { super.onDraw(canvas); int height = getHeight(); int left = this.mCurrText.getLeft() - this.mTabPadding; int right = this.mCurrText.getRight() + this.mTabPadding; int i = height - this.mIndicatorHeight; this.mTabPaint.setColor((this.mTabAlpha << 24) | (this.mIndicatorColor & ViewCompat.MEASURED_SIZE_MASK)); float f = height; canvas.drawRect(left, i, right, f, this.mTabPaint); if (this.mDrawFullUnderline) { this.mTabPaint.setColor((this.mIndicatorColor & ViewCompat.MEASURED_SIZE_MASK) | ViewCompat.MEASURED_STATE_MASK); canvas.drawRect(getPaddingLeft(), height - this.mFullUnderlineHeight, getWidth() - getPaddingRight(), f, this.mTabPaint); } } /* JADX INFO: Access modifiers changed from: package-private */ @Override // androidx.viewpager.widget.PagerTitleStrip public void updateTextPositions(int i, float f, boolean z) { Rect rect = this.mTempRect; int height = getHeight(); int left = this.mCurrText.getLeft() - this.mTabPadding; int right = this.mCurrText.getRight() + this.mTabPadding; int i2 = height - this.mIndicatorHeight; rect.set(left, i2, right, height); super.updateTextPositions(i, f, z); this.mTabAlpha = (int) (Math.abs(f - 0.5f) * 2.0f * 255.0f); rect.union(this.mCurrText.getLeft() - this.mTabPadding, i2, this.mCurrText.getRight() + this.mTabPadding, height); invalidate(rect); } }