1718 lines
57 KiB
Java
1718 lines
57 KiB
Java
package com.google.android.material.tabs;
|
|
|
|
import android.R;
|
|
import android.animation.Animator;
|
|
import android.animation.AnimatorListenerAdapter;
|
|
import android.animation.ValueAnimator;
|
|
import android.annotation.TargetApi;
|
|
import android.content.Context;
|
|
import android.content.res.ColorStateList;
|
|
import android.content.res.Resources;
|
|
import android.content.res.TypedArray;
|
|
import android.database.DataSetObserver;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.Paint;
|
|
import android.graphics.PorterDuff;
|
|
import android.graphics.RectF;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.graphics.drawable.GradientDrawable;
|
|
import android.graphics.drawable.LayerDrawable;
|
|
import android.graphics.drawable.RippleDrawable;
|
|
import android.os.Build;
|
|
import android.text.Layout;
|
|
import android.text.TextUtils;
|
|
import android.util.AttributeSet;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewParent;
|
|
import android.view.accessibility.AccessibilityEvent;
|
|
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.appcompat.app.ActionBar;
|
|
import androidx.appcompat.content.res.AppCompatResources;
|
|
import androidx.appcompat.widget.TooltipCompat;
|
|
import androidx.core.graphics.drawable.DrawableCompat;
|
|
import androidx.core.util.Pools$Pool;
|
|
import androidx.core.util.Pools$SimplePool;
|
|
import androidx.core.util.Pools$SynchronizedPool;
|
|
import androidx.core.view.MarginLayoutParamsCompat;
|
|
import androidx.core.view.PointerIconCompat;
|
|
import androidx.core.view.ViewCompat;
|
|
import androidx.core.widget.TextViewCompat;
|
|
import androidx.viewpager.widget.PagerAdapter;
|
|
import androidx.viewpager.widget.ViewPager;
|
|
import com.google.android.material.R$attr;
|
|
import com.google.android.material.R$dimen;
|
|
import com.google.android.material.R$layout;
|
|
import com.google.android.material.R$style;
|
|
import com.google.android.material.R$styleable;
|
|
import com.google.android.material.animation.AnimationUtils;
|
|
import com.google.android.material.internal.ThemeEnforcement;
|
|
import com.google.android.material.internal.ViewUtils;
|
|
import com.google.android.material.resources.MaterialResources;
|
|
import com.google.android.material.ripple.RippleUtils;
|
|
import java.lang.ref.WeakReference;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
|
|
@ViewPager.DecorView
|
|
/* loaded from: classes.dex */
|
|
public class TabLayout extends HorizontalScrollView {
|
|
private static final Pools$Pool<Tab> P = new Pools$SynchronizedPool(16);
|
|
int A;
|
|
boolean B;
|
|
boolean C;
|
|
boolean D;
|
|
private BaseOnTabSelectedListener E;
|
|
private final ArrayList<BaseOnTabSelectedListener> F;
|
|
private BaseOnTabSelectedListener G;
|
|
private ValueAnimator H;
|
|
ViewPager I;
|
|
private PagerAdapter J;
|
|
private DataSetObserver K;
|
|
private TabLayoutOnPageChangeListener L;
|
|
private AdapterChangeListener M;
|
|
private boolean N;
|
|
private final Pools$Pool<TabView> O;
|
|
private final ArrayList<Tab> a;
|
|
private Tab b;
|
|
private final RectF c;
|
|
private final SlidingTabIndicator d;
|
|
int e;
|
|
int f;
|
|
int g;
|
|
int h;
|
|
int i;
|
|
ColorStateList j;
|
|
ColorStateList k;
|
|
ColorStateList l;
|
|
Drawable m;
|
|
PorterDuff.Mode n;
|
|
float o;
|
|
float p;
|
|
final int q;
|
|
int r;
|
|
private final int s;
|
|
private final int t;
|
|
private final int u;
|
|
private int v;
|
|
int x;
|
|
int y;
|
|
int z;
|
|
|
|
public interface BaseOnTabSelectedListener<T extends Tab> {
|
|
void onTabReselected(T t);
|
|
|
|
void onTabSelected(T t);
|
|
|
|
void onTabUnselected(T t);
|
|
}
|
|
|
|
public interface OnTabSelectedListener extends BaseOnTabSelectedListener<Tab> {
|
|
}
|
|
|
|
private class PagerAdapterObserver extends DataSetObserver {
|
|
PagerAdapterObserver() {
|
|
}
|
|
|
|
@Override // android.database.DataSetObserver
|
|
public void onChanged() {
|
|
TabLayout.this.c();
|
|
}
|
|
|
|
@Override // android.database.DataSetObserver
|
|
public void onInvalidated() {
|
|
TabLayout.this.c();
|
|
}
|
|
}
|
|
|
|
public static class Tab {
|
|
private Object a;
|
|
private Drawable b;
|
|
private CharSequence c;
|
|
private CharSequence d;
|
|
private int e = -1;
|
|
private View f;
|
|
public TabLayout g;
|
|
public TabView h;
|
|
|
|
public int c() {
|
|
return this.e;
|
|
}
|
|
|
|
public Object d() {
|
|
return this.a;
|
|
}
|
|
|
|
public CharSequence e() {
|
|
return this.c;
|
|
}
|
|
|
|
public boolean f() {
|
|
TabLayout tabLayout = this.g;
|
|
if (tabLayout != null) {
|
|
return tabLayout.getSelectedTabPosition() == this.e;
|
|
}
|
|
throw new IllegalArgumentException("Tab not attached to a TabLayout");
|
|
}
|
|
|
|
void g() {
|
|
this.g = null;
|
|
this.h = null;
|
|
this.a = null;
|
|
this.b = null;
|
|
this.c = null;
|
|
this.d = null;
|
|
this.e = -1;
|
|
this.f = null;
|
|
}
|
|
|
|
public void h() {
|
|
TabLayout tabLayout = this.g;
|
|
if (tabLayout == null) {
|
|
throw new IllegalArgumentException("Tab not attached to a TabLayout");
|
|
}
|
|
tabLayout.c(this);
|
|
}
|
|
|
|
void i() {
|
|
TabView tabView = this.h;
|
|
if (tabView != null) {
|
|
tabView.b();
|
|
}
|
|
}
|
|
|
|
public Tab a(Object obj) {
|
|
this.a = obj;
|
|
return this;
|
|
}
|
|
|
|
public Drawable b() {
|
|
return this.b;
|
|
}
|
|
|
|
public View a() {
|
|
return this.f;
|
|
}
|
|
|
|
void b(int i) {
|
|
this.e = i;
|
|
}
|
|
|
|
public Tab a(View view) {
|
|
this.f = view;
|
|
i();
|
|
return this;
|
|
}
|
|
|
|
public Tab b(CharSequence charSequence) {
|
|
if (TextUtils.isEmpty(this.d) && !TextUtils.isEmpty(charSequence)) {
|
|
this.h.setContentDescription(charSequence);
|
|
}
|
|
this.c = charSequence;
|
|
i();
|
|
return this;
|
|
}
|
|
|
|
public Tab a(int i) {
|
|
a(LayoutInflater.from(this.h.getContext()).inflate(i, (ViewGroup) this.h, false));
|
|
return this;
|
|
}
|
|
|
|
public Tab a(Drawable drawable) {
|
|
this.b = drawable;
|
|
i();
|
|
return this;
|
|
}
|
|
|
|
public Tab a(CharSequence charSequence) {
|
|
this.d = charSequence;
|
|
i();
|
|
return this;
|
|
}
|
|
}
|
|
|
|
public static class TabLayoutOnPageChangeListener implements ViewPager.OnPageChangeListener {
|
|
private final WeakReference<TabLayout> a;
|
|
private int b;
|
|
private int c;
|
|
|
|
public TabLayoutOnPageChangeListener(TabLayout tabLayout) {
|
|
this.a = new WeakReference<>(tabLayout);
|
|
}
|
|
|
|
void a() {
|
|
this.c = 0;
|
|
this.b = 0;
|
|
}
|
|
|
|
@Override // androidx.viewpager.widget.ViewPager.OnPageChangeListener
|
|
public void onPageScrollStateChanged(int i) {
|
|
this.b = this.c;
|
|
this.c = i;
|
|
}
|
|
|
|
@Override // androidx.viewpager.widget.ViewPager.OnPageChangeListener
|
|
public void onPageScrolled(int i, float f, int i2) {
|
|
TabLayout tabLayout = this.a.get();
|
|
if (tabLayout != null) {
|
|
tabLayout.a(i, f, this.c != 2 || this.b == 1, (this.c == 2 && this.b == 0) ? false : true);
|
|
}
|
|
}
|
|
|
|
@Override // androidx.viewpager.widget.ViewPager.OnPageChangeListener
|
|
public void onPageSelected(int i) {
|
|
TabLayout tabLayout = this.a.get();
|
|
if (tabLayout == null || tabLayout.getSelectedTabPosition() == i || i >= tabLayout.getTabCount()) {
|
|
return;
|
|
}
|
|
int i2 = this.c;
|
|
tabLayout.b(tabLayout.b(i), i2 == 0 || (i2 == 2 && this.b == 0));
|
|
}
|
|
}
|
|
|
|
class TabView extends LinearLayout {
|
|
private Tab a;
|
|
private TextView b;
|
|
private ImageView c;
|
|
private View d;
|
|
private TextView e;
|
|
private ImageView f;
|
|
private Drawable g;
|
|
private int h;
|
|
|
|
public TabView(Context context) {
|
|
super(context);
|
|
this.h = 2;
|
|
a(context);
|
|
ViewCompat.a(this, TabLayout.this.e, TabLayout.this.f, TabLayout.this.g, TabLayout.this.h);
|
|
setGravity(17);
|
|
setOrientation(!TabLayout.this.B ? 1 : 0);
|
|
setClickable(true);
|
|
ViewCompat.a(this, PointerIconCompat.a(getContext(), 1002));
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public int d() {
|
|
int i = 0;
|
|
int i2 = 0;
|
|
boolean z = false;
|
|
for (View view : new View[]{this.b, this.c, this.d}) {
|
|
if (view != null && view.getVisibility() == 0) {
|
|
i2 = z ? Math.min(i2, view.getLeft()) : view.getLeft();
|
|
i = z ? Math.max(i, view.getRight()) : view.getRight();
|
|
z = true;
|
|
}
|
|
}
|
|
return i - i2;
|
|
}
|
|
|
|
final void b() {
|
|
Tab tab = this.a;
|
|
Drawable drawable = null;
|
|
View a = tab != null ? tab.a() : null;
|
|
if (a != null) {
|
|
ViewParent parent = a.getParent();
|
|
if (parent != this) {
|
|
if (parent != null) {
|
|
((ViewGroup) parent).removeView(a);
|
|
}
|
|
addView(a);
|
|
}
|
|
this.d = a;
|
|
TextView textView = this.b;
|
|
if (textView != null) {
|
|
textView.setVisibility(8);
|
|
}
|
|
ImageView imageView = this.c;
|
|
if (imageView != null) {
|
|
imageView.setVisibility(8);
|
|
this.c.setImageDrawable(null);
|
|
}
|
|
this.e = (TextView) a.findViewById(R.id.text1);
|
|
TextView textView2 = this.e;
|
|
if (textView2 != null) {
|
|
this.h = TextViewCompat.d(textView2);
|
|
}
|
|
this.f = (ImageView) a.findViewById(R.id.icon);
|
|
} else {
|
|
View view = this.d;
|
|
if (view != null) {
|
|
removeView(view);
|
|
this.d = null;
|
|
}
|
|
this.e = null;
|
|
this.f = null;
|
|
}
|
|
boolean z = false;
|
|
if (this.d == null) {
|
|
if (this.c == null) {
|
|
ImageView imageView2 = (ImageView) LayoutInflater.from(getContext()).inflate(R$layout.design_layout_tab_icon, (ViewGroup) this, false);
|
|
addView(imageView2, 0);
|
|
this.c = imageView2;
|
|
}
|
|
if (tab != null && tab.b() != null) {
|
|
drawable = DrawableCompat.h(tab.b()).mutate();
|
|
}
|
|
if (drawable != null) {
|
|
DrawableCompat.a(drawable, TabLayout.this.k);
|
|
PorterDuff.Mode mode = TabLayout.this.n;
|
|
if (mode != null) {
|
|
DrawableCompat.a(drawable, mode);
|
|
}
|
|
}
|
|
if (this.b == null) {
|
|
TextView textView3 = (TextView) LayoutInflater.from(getContext()).inflate(R$layout.design_layout_tab_text, (ViewGroup) this, false);
|
|
addView(textView3);
|
|
this.b = textView3;
|
|
this.h = TextViewCompat.d(this.b);
|
|
}
|
|
TextViewCompat.d(this.b, TabLayout.this.i);
|
|
ColorStateList colorStateList = TabLayout.this.j;
|
|
if (colorStateList != null) {
|
|
this.b.setTextColor(colorStateList);
|
|
}
|
|
a(this.b, this.c);
|
|
} else if (this.e != null || this.f != null) {
|
|
a(this.e, this.f);
|
|
}
|
|
if (tab != null && !TextUtils.isEmpty(tab.d)) {
|
|
setContentDescription(tab.d);
|
|
}
|
|
if (tab != null && tab.f()) {
|
|
z = true;
|
|
}
|
|
setSelected(z);
|
|
}
|
|
|
|
final void c() {
|
|
setOrientation(!TabLayout.this.B ? 1 : 0);
|
|
if (this.e == null && this.f == null) {
|
|
a(this.b, this.c);
|
|
} else {
|
|
a(this.e, this.f);
|
|
}
|
|
}
|
|
|
|
@Override // android.view.ViewGroup, android.view.View
|
|
protected void drawableStateChanged() {
|
|
super.drawableStateChanged();
|
|
int[] drawableState = getDrawableState();
|
|
Drawable drawable = this.g;
|
|
boolean z = false;
|
|
if (drawable != null && drawable.isStateful()) {
|
|
z = false | this.g.setState(drawableState);
|
|
}
|
|
if (z) {
|
|
invalidate();
|
|
TabLayout.this.invalidate();
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
|
|
super.onInitializeAccessibilityEvent(accessibilityEvent);
|
|
accessibilityEvent.setClassName(ActionBar.Tab.class.getName());
|
|
}
|
|
|
|
@Override // android.view.View
|
|
@TargetApi(14)
|
|
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo accessibilityNodeInfo) {
|
|
super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo);
|
|
accessibilityNodeInfo.setClassName(ActionBar.Tab.class.getName());
|
|
}
|
|
|
|
@Override // android.widget.LinearLayout, android.view.View
|
|
public void onMeasure(int i, int i2) {
|
|
Layout layout;
|
|
int size = View.MeasureSpec.getSize(i);
|
|
int mode = View.MeasureSpec.getMode(i);
|
|
int tabMaxWidth = TabLayout.this.getTabMaxWidth();
|
|
if (tabMaxWidth > 0 && (mode == 0 || size > tabMaxWidth)) {
|
|
i = View.MeasureSpec.makeMeasureSpec(TabLayout.this.r, Integer.MIN_VALUE);
|
|
}
|
|
super.onMeasure(i, i2);
|
|
if (this.b != null) {
|
|
float f = TabLayout.this.o;
|
|
int i3 = this.h;
|
|
ImageView imageView = this.c;
|
|
boolean z = true;
|
|
if (imageView == null || imageView.getVisibility() != 0) {
|
|
TextView textView = this.b;
|
|
if (textView != null && textView.getLineCount() > 1) {
|
|
f = TabLayout.this.p;
|
|
}
|
|
} else {
|
|
i3 = 1;
|
|
}
|
|
float textSize = this.b.getTextSize();
|
|
int lineCount = this.b.getLineCount();
|
|
int d = TextViewCompat.d(this.b);
|
|
if (f != textSize || (d >= 0 && i3 != d)) {
|
|
if (TabLayout.this.A == 1 && f > textSize && lineCount == 1 && ((layout = this.b.getLayout()) == null || a(layout, 0, f) > (getMeasuredWidth() - getPaddingLeft()) - getPaddingRight())) {
|
|
z = false;
|
|
}
|
|
if (z) {
|
|
this.b.setTextSize(0, f);
|
|
this.b.setMaxLines(i3);
|
|
super.onMeasure(i, i2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public boolean performClick() {
|
|
boolean performClick = super.performClick();
|
|
if (this.a == null) {
|
|
return performClick;
|
|
}
|
|
if (!performClick) {
|
|
playSoundEffect(0);
|
|
}
|
|
this.a.h();
|
|
return true;
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void setSelected(boolean z) {
|
|
boolean z2 = isSelected() != z;
|
|
super.setSelected(z);
|
|
if (z2 && z && Build.VERSION.SDK_INT < 16) {
|
|
sendAccessibilityEvent(4);
|
|
}
|
|
TextView textView = this.b;
|
|
if (textView != null) {
|
|
textView.setSelected(z);
|
|
}
|
|
ImageView imageView = this.c;
|
|
if (imageView != null) {
|
|
imageView.setSelected(z);
|
|
}
|
|
View view = this.d;
|
|
if (view != null) {
|
|
view.setSelected(z);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
/* JADX WARN: Type inference failed for: r0v3, types: [android.graphics.drawable.RippleDrawable] */
|
|
/* JADX WARN: Type inference failed for: r2v3, types: [android.graphics.drawable.LayerDrawable] */
|
|
public void a(Context context) {
|
|
int i = TabLayout.this.q;
|
|
if (i != 0) {
|
|
this.g = AppCompatResources.c(context, i);
|
|
Drawable drawable = this.g;
|
|
if (drawable != null && drawable.isStateful()) {
|
|
this.g.setState(getDrawableState());
|
|
}
|
|
} else {
|
|
this.g = null;
|
|
}
|
|
GradientDrawable gradientDrawable = new GradientDrawable();
|
|
gradientDrawable.setColor(0);
|
|
if (TabLayout.this.l != null) {
|
|
GradientDrawable gradientDrawable2 = new GradientDrawable();
|
|
gradientDrawable2.setCornerRadius(1.0E-5f);
|
|
gradientDrawable2.setColor(-1);
|
|
ColorStateList a = RippleUtils.a(TabLayout.this.l);
|
|
if (Build.VERSION.SDK_INT >= 21) {
|
|
if (TabLayout.this.D) {
|
|
gradientDrawable = null;
|
|
}
|
|
gradientDrawable = new RippleDrawable(a, gradientDrawable, TabLayout.this.D ? null : gradientDrawable2);
|
|
} else {
|
|
Drawable h = DrawableCompat.h(gradientDrawable2);
|
|
DrawableCompat.a(h, a);
|
|
gradientDrawable = new LayerDrawable(new Drawable[]{gradientDrawable, h});
|
|
}
|
|
}
|
|
ViewCompat.a(this, gradientDrawable);
|
|
TabLayout.this.invalidate();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void a(Canvas canvas) {
|
|
Drawable drawable = this.g;
|
|
if (drawable != null) {
|
|
drawable.setBounds(getLeft(), getTop(), getRight(), getBottom());
|
|
this.g.draw(canvas);
|
|
}
|
|
}
|
|
|
|
void a(Tab tab) {
|
|
if (tab != this.a) {
|
|
this.a = tab;
|
|
b();
|
|
}
|
|
}
|
|
|
|
void a() {
|
|
a((Tab) null);
|
|
setSelected(false);
|
|
}
|
|
|
|
private void a(TextView textView, ImageView imageView) {
|
|
Tab tab = this.a;
|
|
Drawable mutate = (tab == null || tab.b() == null) ? null : DrawableCompat.h(this.a.b()).mutate();
|
|
Tab tab2 = this.a;
|
|
CharSequence e = tab2 != null ? tab2.e() : null;
|
|
if (imageView != null) {
|
|
if (mutate != null) {
|
|
imageView.setImageDrawable(mutate);
|
|
imageView.setVisibility(0);
|
|
setVisibility(0);
|
|
} else {
|
|
imageView.setVisibility(8);
|
|
imageView.setImageDrawable(null);
|
|
}
|
|
}
|
|
boolean z = !TextUtils.isEmpty(e);
|
|
if (textView != null) {
|
|
if (z) {
|
|
textView.setText(e);
|
|
textView.setVisibility(0);
|
|
setVisibility(0);
|
|
} else {
|
|
textView.setVisibility(8);
|
|
textView.setText((CharSequence) null);
|
|
}
|
|
}
|
|
if (imageView != null) {
|
|
ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) imageView.getLayoutParams();
|
|
int a = (z && imageView.getVisibility() == 0) ? TabLayout.this.a(8) : 0;
|
|
if (TabLayout.this.B) {
|
|
if (a != MarginLayoutParamsCompat.a(marginLayoutParams)) {
|
|
MarginLayoutParamsCompat.a(marginLayoutParams, a);
|
|
marginLayoutParams.bottomMargin = 0;
|
|
imageView.setLayoutParams(marginLayoutParams);
|
|
imageView.requestLayout();
|
|
}
|
|
} else if (a != marginLayoutParams.bottomMargin) {
|
|
marginLayoutParams.bottomMargin = a;
|
|
MarginLayoutParamsCompat.a(marginLayoutParams, 0);
|
|
imageView.setLayoutParams(marginLayoutParams);
|
|
imageView.requestLayout();
|
|
}
|
|
}
|
|
Tab tab3 = this.a;
|
|
CharSequence charSequence = tab3 != null ? tab3.d : null;
|
|
if (z) {
|
|
charSequence = null;
|
|
}
|
|
TooltipCompat.a(this, charSequence);
|
|
}
|
|
|
|
private float a(Layout layout, int i, float f) {
|
|
return layout.getLineWidth(i) * (f / layout.getPaint().getTextSize());
|
|
}
|
|
}
|
|
|
|
public static class ViewPagerOnTabSelectedListener implements OnTabSelectedListener {
|
|
private final ViewPager a;
|
|
|
|
public ViewPagerOnTabSelectedListener(ViewPager viewPager) {
|
|
this.a = viewPager;
|
|
}
|
|
|
|
@Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
|
|
public void onTabReselected(Tab tab) {
|
|
}
|
|
|
|
@Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
|
|
public void onTabSelected(Tab tab) {
|
|
this.a.setCurrentItem(tab.c());
|
|
}
|
|
|
|
@Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
|
|
public void onTabUnselected(Tab tab) {
|
|
}
|
|
}
|
|
|
|
public TabLayout(Context context) {
|
|
this(context, null);
|
|
}
|
|
|
|
private TabView e(Tab tab) {
|
|
Pools$Pool<TabView> pools$Pool = this.O;
|
|
TabView a = pools$Pool != null ? pools$Pool.a() : null;
|
|
if (a == null) {
|
|
a = new TabView(getContext());
|
|
}
|
|
a.a(tab);
|
|
a.setFocusable(true);
|
|
a.setMinimumWidth(getTabMinWidth());
|
|
if (TextUtils.isEmpty(tab.d)) {
|
|
a.setContentDescription(tab.c);
|
|
} else {
|
|
a.setContentDescription(tab.d);
|
|
}
|
|
return a;
|
|
}
|
|
|
|
private LinearLayout.LayoutParams f() {
|
|
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -1);
|
|
a(layoutParams);
|
|
return layoutParams;
|
|
}
|
|
|
|
private void g() {
|
|
if (this.H == null) {
|
|
this.H = new ValueAnimator();
|
|
this.H.setInterpolator(AnimationUtils.b);
|
|
this.H.setDuration(this.y);
|
|
this.H.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { // from class: com.google.android.material.tabs.TabLayout.1
|
|
@Override // android.animation.ValueAnimator.AnimatorUpdateListener
|
|
public void onAnimationUpdate(ValueAnimator valueAnimator) {
|
|
TabLayout.this.scrollTo(((Integer) valueAnimator.getAnimatedValue()).intValue(), 0);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
private int getDefaultHeight() {
|
|
int size = this.a.size();
|
|
boolean z = false;
|
|
int i = 0;
|
|
while (true) {
|
|
if (i < size) {
|
|
Tab tab = this.a.get(i);
|
|
if (tab != null && tab.b() != null && !TextUtils.isEmpty(tab.e())) {
|
|
z = true;
|
|
break;
|
|
}
|
|
i++;
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
return (!z || this.B) ? 48 : 72;
|
|
}
|
|
|
|
private int getTabMinWidth() {
|
|
int i = this.s;
|
|
if (i != -1) {
|
|
return i;
|
|
}
|
|
if (this.A == 0) {
|
|
return this.u;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
private int getTabScrollRange() {
|
|
return Math.max(0, ((this.d.getWidth() - getWidth()) - getPaddingLeft()) - getPaddingRight());
|
|
}
|
|
|
|
private void h() {
|
|
int size = this.a.size();
|
|
for (int i = 0; i < size; i++) {
|
|
this.a.get(i).i();
|
|
}
|
|
}
|
|
|
|
private void setSelectedTabView(int i) {
|
|
int childCount = this.d.getChildCount();
|
|
if (i < childCount) {
|
|
int i2 = 0;
|
|
while (i2 < childCount) {
|
|
View childAt = this.d.getChildAt(i2);
|
|
boolean z = true;
|
|
childAt.setSelected(i2 == i);
|
|
if (i2 != i) {
|
|
z = false;
|
|
}
|
|
childAt.setActivated(z);
|
|
i2++;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // android.widget.HorizontalScrollView, android.view.ViewGroup
|
|
public void addView(View view) {
|
|
a(view);
|
|
}
|
|
|
|
public void b(BaseOnTabSelectedListener baseOnTabSelectedListener) {
|
|
this.F.remove(baseOnTabSelectedListener);
|
|
}
|
|
|
|
void c() {
|
|
int currentItem;
|
|
d();
|
|
PagerAdapter pagerAdapter = this.J;
|
|
if (pagerAdapter != null) {
|
|
int count = pagerAdapter.getCount();
|
|
for (int i = 0; i < count; i++) {
|
|
Tab b = b();
|
|
b.b(this.J.getPageTitle(i));
|
|
a(b, false);
|
|
}
|
|
ViewPager viewPager = this.I;
|
|
if (viewPager == null || count <= 0 || (currentItem = viewPager.getCurrentItem()) == getSelectedTabPosition() || currentItem >= getTabCount()) {
|
|
return;
|
|
}
|
|
c(b(currentItem));
|
|
}
|
|
}
|
|
|
|
public void d() {
|
|
for (int childCount = this.d.getChildCount() - 1; childCount >= 0; childCount--) {
|
|
d(childCount);
|
|
}
|
|
Iterator<Tab> it = this.a.iterator();
|
|
while (it.hasNext()) {
|
|
Tab next = it.next();
|
|
it.remove();
|
|
next.g();
|
|
b(next);
|
|
}
|
|
this.b = null;
|
|
}
|
|
|
|
public int getSelectedTabPosition() {
|
|
Tab tab = this.b;
|
|
if (tab != null) {
|
|
return tab.c();
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public int getTabCount() {
|
|
return this.a.size();
|
|
}
|
|
|
|
public int getTabGravity() {
|
|
return this.x;
|
|
}
|
|
|
|
public ColorStateList getTabIconTint() {
|
|
return this.k;
|
|
}
|
|
|
|
public int getTabIndicatorGravity() {
|
|
return this.z;
|
|
}
|
|
|
|
int getTabMaxWidth() {
|
|
return this.r;
|
|
}
|
|
|
|
public int getTabMode() {
|
|
return this.A;
|
|
}
|
|
|
|
public ColorStateList getTabRippleColor() {
|
|
return this.l;
|
|
}
|
|
|
|
public Drawable getTabSelectedIndicator() {
|
|
return this.m;
|
|
}
|
|
|
|
public ColorStateList getTabTextColors() {
|
|
return this.j;
|
|
}
|
|
|
|
@Override // android.view.ViewGroup, android.view.View
|
|
protected void onAttachedToWindow() {
|
|
super.onAttachedToWindow();
|
|
if (this.I == null) {
|
|
ViewParent parent = getParent();
|
|
if (parent instanceof ViewPager) {
|
|
a((ViewPager) parent, true, true);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // android.view.ViewGroup, android.view.View
|
|
protected void onDetachedFromWindow() {
|
|
super.onDetachedFromWindow();
|
|
if (this.N) {
|
|
setupWithViewPager(null);
|
|
this.N = false;
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View
|
|
protected void onDraw(Canvas canvas) {
|
|
for (int i = 0; i < this.d.getChildCount(); i++) {
|
|
View childAt = this.d.getChildAt(i);
|
|
if (childAt instanceof TabView) {
|
|
((TabView) childAt).a(canvas);
|
|
}
|
|
}
|
|
super.onDraw(canvas);
|
|
}
|
|
|
|
@Override // android.widget.HorizontalScrollView, android.widget.FrameLayout, android.view.View
|
|
protected void onMeasure(int i, int i2) {
|
|
int a = a(getDefaultHeight()) + getPaddingTop() + getPaddingBottom();
|
|
int mode = View.MeasureSpec.getMode(i2);
|
|
if (mode == Integer.MIN_VALUE) {
|
|
i2 = View.MeasureSpec.makeMeasureSpec(Math.min(a, View.MeasureSpec.getSize(i2)), 1073741824);
|
|
} else if (mode == 0) {
|
|
i2 = View.MeasureSpec.makeMeasureSpec(a, 1073741824);
|
|
}
|
|
int size = View.MeasureSpec.getSize(i);
|
|
if (View.MeasureSpec.getMode(i) != 0) {
|
|
int i3 = this.t;
|
|
if (i3 <= 0) {
|
|
i3 = size - a(56);
|
|
}
|
|
this.r = i3;
|
|
}
|
|
super.onMeasure(i, i2);
|
|
if (getChildCount() == 1) {
|
|
boolean z = false;
|
|
View childAt = getChildAt(0);
|
|
int i4 = this.A;
|
|
if (i4 == 0 ? childAt.getMeasuredWidth() < getMeasuredWidth() : !(i4 != 1 || childAt.getMeasuredWidth() == getMeasuredWidth())) {
|
|
z = true;
|
|
}
|
|
if (z) {
|
|
childAt.measure(View.MeasureSpec.makeMeasureSpec(getMeasuredWidth(), 1073741824), HorizontalScrollView.getChildMeasureSpec(i2, getPaddingTop() + getPaddingBottom(), childAt.getLayoutParams().height));
|
|
}
|
|
}
|
|
}
|
|
|
|
public void setInlineLabel(boolean z) {
|
|
if (this.B != z) {
|
|
this.B = z;
|
|
for (int i = 0; i < this.d.getChildCount(); i++) {
|
|
View childAt = this.d.getChildAt(i);
|
|
if (childAt instanceof TabView) {
|
|
((TabView) childAt).c();
|
|
}
|
|
}
|
|
e();
|
|
}
|
|
}
|
|
|
|
public void setInlineLabelResource(int i) {
|
|
setInlineLabel(getResources().getBoolean(i));
|
|
}
|
|
|
|
@Deprecated
|
|
public void setOnTabSelectedListener(BaseOnTabSelectedListener baseOnTabSelectedListener) {
|
|
BaseOnTabSelectedListener baseOnTabSelectedListener2 = this.E;
|
|
if (baseOnTabSelectedListener2 != null) {
|
|
b(baseOnTabSelectedListener2);
|
|
}
|
|
this.E = baseOnTabSelectedListener;
|
|
if (baseOnTabSelectedListener != null) {
|
|
a(baseOnTabSelectedListener);
|
|
}
|
|
}
|
|
|
|
void setScrollAnimatorListener(Animator.AnimatorListener animatorListener) {
|
|
g();
|
|
this.H.addListener(animatorListener);
|
|
}
|
|
|
|
public void setSelectedTabIndicator(Drawable drawable) {
|
|
if (this.m != drawable) {
|
|
this.m = drawable;
|
|
ViewCompat.A(this.d);
|
|
}
|
|
}
|
|
|
|
public void setSelectedTabIndicatorColor(int i) {
|
|
this.d.a(i);
|
|
}
|
|
|
|
public void setSelectedTabIndicatorGravity(int i) {
|
|
if (this.z != i) {
|
|
this.z = i;
|
|
ViewCompat.A(this.d);
|
|
}
|
|
}
|
|
|
|
@Deprecated
|
|
public void setSelectedTabIndicatorHeight(int i) {
|
|
this.d.b(i);
|
|
}
|
|
|
|
public void setTabGravity(int i) {
|
|
if (this.x != i) {
|
|
this.x = i;
|
|
e();
|
|
}
|
|
}
|
|
|
|
public void setTabIconTint(ColorStateList colorStateList) {
|
|
if (this.k != colorStateList) {
|
|
this.k = colorStateList;
|
|
h();
|
|
}
|
|
}
|
|
|
|
public void setTabIconTintResource(int i) {
|
|
setTabIconTint(AppCompatResources.b(getContext(), i));
|
|
}
|
|
|
|
public void setTabIndicatorFullWidth(boolean z) {
|
|
this.C = z;
|
|
ViewCompat.A(this.d);
|
|
}
|
|
|
|
public void setTabMode(int i) {
|
|
if (i != this.A) {
|
|
this.A = i;
|
|
e();
|
|
}
|
|
}
|
|
|
|
public void setTabRippleColor(ColorStateList colorStateList) {
|
|
if (this.l != colorStateList) {
|
|
this.l = colorStateList;
|
|
for (int i = 0; i < this.d.getChildCount(); i++) {
|
|
View childAt = this.d.getChildAt(i);
|
|
if (childAt instanceof TabView) {
|
|
((TabView) childAt).a(getContext());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void setTabRippleColorResource(int i) {
|
|
setTabRippleColor(AppCompatResources.b(getContext(), i));
|
|
}
|
|
|
|
public void setTabTextColors(ColorStateList colorStateList) {
|
|
if (this.j != colorStateList) {
|
|
this.j = colorStateList;
|
|
h();
|
|
}
|
|
}
|
|
|
|
@Deprecated
|
|
public void setTabsFromPagerAdapter(PagerAdapter pagerAdapter) {
|
|
a(pagerAdapter, false);
|
|
}
|
|
|
|
public void setUnboundedRipple(boolean z) {
|
|
if (this.D != z) {
|
|
this.D = z;
|
|
for (int i = 0; i < this.d.getChildCount(); i++) {
|
|
View childAt = this.d.getChildAt(i);
|
|
if (childAt instanceof TabView) {
|
|
((TabView) childAt).a(getContext());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void setUnboundedRippleResource(int i) {
|
|
setUnboundedRipple(getResources().getBoolean(i));
|
|
}
|
|
|
|
public void setupWithViewPager(ViewPager viewPager) {
|
|
a(viewPager, true);
|
|
}
|
|
|
|
@Override // android.widget.HorizontalScrollView, android.widget.FrameLayout, android.view.ViewGroup
|
|
public boolean shouldDelayChildPressedState() {
|
|
return getTabScrollRange() > 0;
|
|
}
|
|
|
|
private class AdapterChangeListener implements ViewPager.OnAdapterChangeListener {
|
|
private boolean a;
|
|
|
|
AdapterChangeListener() {
|
|
}
|
|
|
|
@Override // androidx.viewpager.widget.ViewPager.OnAdapterChangeListener
|
|
public void a(ViewPager viewPager, PagerAdapter pagerAdapter, PagerAdapter pagerAdapter2) {
|
|
TabLayout tabLayout = TabLayout.this;
|
|
if (tabLayout.I == viewPager) {
|
|
tabLayout.a(pagerAdapter2, this.a);
|
|
}
|
|
}
|
|
|
|
void a(boolean z) {
|
|
this.a = z;
|
|
}
|
|
}
|
|
|
|
public TabLayout(Context context, AttributeSet attributeSet) {
|
|
this(context, attributeSet, R$attr.tabStyle);
|
|
}
|
|
|
|
public void a(int i, float f, boolean z) {
|
|
a(i, f, z, true);
|
|
}
|
|
|
|
@Override // android.widget.HorizontalScrollView, android.view.ViewGroup
|
|
public void addView(View view, int i) {
|
|
a(view);
|
|
}
|
|
|
|
public Tab b() {
|
|
Tab a = a();
|
|
a.g = this;
|
|
a.h = e(a);
|
|
return a;
|
|
}
|
|
|
|
@Override // android.widget.FrameLayout, android.view.ViewGroup
|
|
public FrameLayout.LayoutParams generateLayoutParams(AttributeSet attributeSet) {
|
|
return generateDefaultLayoutParams();
|
|
}
|
|
|
|
private class SlidingTabIndicator extends LinearLayout {
|
|
private int a;
|
|
private final Paint b;
|
|
private final GradientDrawable c;
|
|
int d;
|
|
float e;
|
|
private int f;
|
|
private int g;
|
|
private int h;
|
|
private ValueAnimator i;
|
|
|
|
SlidingTabIndicator(Context context) {
|
|
super(context);
|
|
this.d = -1;
|
|
this.f = -1;
|
|
this.g = -1;
|
|
this.h = -1;
|
|
setWillNotDraw(false);
|
|
this.b = new Paint();
|
|
this.c = new GradientDrawable();
|
|
}
|
|
|
|
void a(int i) {
|
|
if (this.b.getColor() != i) {
|
|
this.b.setColor(i);
|
|
ViewCompat.A(this);
|
|
}
|
|
}
|
|
|
|
void b(int i) {
|
|
if (this.a != i) {
|
|
this.a = i;
|
|
ViewCompat.A(this);
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void draw(Canvas canvas) {
|
|
Drawable drawable = TabLayout.this.m;
|
|
int i = 0;
|
|
int intrinsicHeight = drawable != null ? drawable.getIntrinsicHeight() : 0;
|
|
int i2 = this.a;
|
|
if (i2 >= 0) {
|
|
intrinsicHeight = i2;
|
|
}
|
|
int i3 = TabLayout.this.z;
|
|
if (i3 == 0) {
|
|
i = getHeight() - intrinsicHeight;
|
|
intrinsicHeight = getHeight();
|
|
} else if (i3 == 1) {
|
|
i = (getHeight() - intrinsicHeight) / 2;
|
|
intrinsicHeight = (getHeight() + intrinsicHeight) / 2;
|
|
} else if (i3 != 2) {
|
|
intrinsicHeight = i3 != 3 ? 0 : getHeight();
|
|
}
|
|
int i4 = this.g;
|
|
if (i4 >= 0 && this.h > i4) {
|
|
Drawable drawable2 = TabLayout.this.m;
|
|
if (drawable2 == null) {
|
|
drawable2 = this.c;
|
|
}
|
|
Drawable h = DrawableCompat.h(drawable2);
|
|
h.setBounds(this.g, i, this.h, intrinsicHeight);
|
|
Paint paint = this.b;
|
|
if (paint != null) {
|
|
if (Build.VERSION.SDK_INT == 21) {
|
|
h.setColorFilter(paint.getColor(), PorterDuff.Mode.SRC_IN);
|
|
} else {
|
|
DrawableCompat.b(h, paint.getColor());
|
|
}
|
|
}
|
|
h.draw(canvas);
|
|
}
|
|
super.draw(canvas);
|
|
}
|
|
|
|
@Override // android.widget.LinearLayout, android.view.ViewGroup, android.view.View
|
|
protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
|
|
super.onLayout(z, i, i2, i3, i4);
|
|
ValueAnimator valueAnimator = this.i;
|
|
if (valueAnimator == null || !valueAnimator.isRunning()) {
|
|
b();
|
|
return;
|
|
}
|
|
this.i.cancel();
|
|
a(this.d, Math.round((1.0f - this.i.getAnimatedFraction()) * this.i.getDuration()));
|
|
}
|
|
|
|
@Override // android.widget.LinearLayout, android.view.View
|
|
protected void onMeasure(int i, int i2) {
|
|
super.onMeasure(i, i2);
|
|
if (View.MeasureSpec.getMode(i) != 1073741824) {
|
|
return;
|
|
}
|
|
TabLayout tabLayout = TabLayout.this;
|
|
boolean z = true;
|
|
if (tabLayout.A == 1 && tabLayout.x == 1) {
|
|
int childCount = getChildCount();
|
|
int i3 = 0;
|
|
for (int i4 = 0; i4 < childCount; i4++) {
|
|
View childAt = getChildAt(i4);
|
|
if (childAt.getVisibility() == 0) {
|
|
i3 = Math.max(i3, childAt.getMeasuredWidth());
|
|
}
|
|
}
|
|
if (i3 <= 0) {
|
|
return;
|
|
}
|
|
if (i3 * childCount <= getMeasuredWidth() - (TabLayout.this.a(16) * 2)) {
|
|
boolean z2 = false;
|
|
for (int i5 = 0; i5 < childCount; i5++) {
|
|
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) getChildAt(i5).getLayoutParams();
|
|
if (layoutParams.width != i3 || layoutParams.weight != 0.0f) {
|
|
layoutParams.width = i3;
|
|
layoutParams.weight = 0.0f;
|
|
z2 = true;
|
|
}
|
|
}
|
|
z = z2;
|
|
} else {
|
|
TabLayout tabLayout2 = TabLayout.this;
|
|
tabLayout2.x = 0;
|
|
tabLayout2.a(false);
|
|
}
|
|
if (z) {
|
|
super.onMeasure(i, i2);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // android.widget.LinearLayout, android.view.View
|
|
public void onRtlPropertiesChanged(int i) {
|
|
super.onRtlPropertiesChanged(i);
|
|
if (Build.VERSION.SDK_INT >= 23 || this.f == i) {
|
|
return;
|
|
}
|
|
requestLayout();
|
|
this.f = i;
|
|
}
|
|
|
|
private void b() {
|
|
int i;
|
|
int i2;
|
|
View childAt = getChildAt(this.d);
|
|
if (childAt == null || childAt.getWidth() <= 0) {
|
|
i = -1;
|
|
i2 = -1;
|
|
} else {
|
|
i = childAt.getLeft();
|
|
i2 = childAt.getRight();
|
|
TabLayout tabLayout = TabLayout.this;
|
|
if (!tabLayout.C && (childAt instanceof TabView)) {
|
|
a((TabView) childAt, tabLayout.c);
|
|
i = (int) TabLayout.this.c.left;
|
|
i2 = (int) TabLayout.this.c.right;
|
|
}
|
|
if (this.e > 0.0f && this.d < getChildCount() - 1) {
|
|
View childAt2 = getChildAt(this.d + 1);
|
|
int left = childAt2.getLeft();
|
|
int right = childAt2.getRight();
|
|
TabLayout tabLayout2 = TabLayout.this;
|
|
if (!tabLayout2.C && (childAt2 instanceof TabView)) {
|
|
a((TabView) childAt2, tabLayout2.c);
|
|
left = (int) TabLayout.this.c.left;
|
|
right = (int) TabLayout.this.c.right;
|
|
}
|
|
float f = this.e;
|
|
i = (int) ((left * f) + ((1.0f - f) * i));
|
|
i2 = (int) ((right * f) + ((1.0f - f) * i2));
|
|
}
|
|
}
|
|
b(i, i2);
|
|
}
|
|
|
|
boolean a() {
|
|
int childCount = getChildCount();
|
|
for (int i = 0; i < childCount; i++) {
|
|
if (getChildAt(i).getWidth() <= 0) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void a(int i, float f) {
|
|
ValueAnimator valueAnimator = this.i;
|
|
if (valueAnimator != null && valueAnimator.isRunning()) {
|
|
this.i.cancel();
|
|
}
|
|
this.d = i;
|
|
this.e = f;
|
|
b();
|
|
}
|
|
|
|
void a(final int i, int i2) {
|
|
ValueAnimator valueAnimator = this.i;
|
|
if (valueAnimator != null && valueAnimator.isRunning()) {
|
|
this.i.cancel();
|
|
}
|
|
View childAt = getChildAt(i);
|
|
if (childAt == null) {
|
|
b();
|
|
return;
|
|
}
|
|
int left = childAt.getLeft();
|
|
int right = childAt.getRight();
|
|
TabLayout tabLayout = TabLayout.this;
|
|
if (!tabLayout.C && (childAt instanceof TabView)) {
|
|
a((TabView) childAt, tabLayout.c);
|
|
left = (int) TabLayout.this.c.left;
|
|
right = (int) TabLayout.this.c.right;
|
|
}
|
|
final int i3 = left;
|
|
final int i4 = right;
|
|
final int i5 = this.g;
|
|
final int i6 = this.h;
|
|
if (i5 == i3 && i6 == i4) {
|
|
return;
|
|
}
|
|
ValueAnimator valueAnimator2 = new ValueAnimator();
|
|
this.i = valueAnimator2;
|
|
valueAnimator2.setInterpolator(AnimationUtils.b);
|
|
valueAnimator2.setDuration(i2);
|
|
valueAnimator2.setFloatValues(0.0f, 1.0f);
|
|
valueAnimator2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { // from class: com.google.android.material.tabs.TabLayout.SlidingTabIndicator.1
|
|
@Override // android.animation.ValueAnimator.AnimatorUpdateListener
|
|
public void onAnimationUpdate(ValueAnimator valueAnimator3) {
|
|
float animatedFraction = valueAnimator3.getAnimatedFraction();
|
|
SlidingTabIndicator.this.b(AnimationUtils.a(i5, i3, animatedFraction), AnimationUtils.a(i6, i4, animatedFraction));
|
|
}
|
|
});
|
|
valueAnimator2.addListener(new AnimatorListenerAdapter() { // from class: com.google.android.material.tabs.TabLayout.SlidingTabIndicator.2
|
|
@Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
|
|
public void onAnimationEnd(Animator animator) {
|
|
SlidingTabIndicator slidingTabIndicator = SlidingTabIndicator.this;
|
|
slidingTabIndicator.d = i;
|
|
slidingTabIndicator.e = 0.0f;
|
|
}
|
|
});
|
|
valueAnimator2.start();
|
|
}
|
|
|
|
void b(int i, int i2) {
|
|
if (i == this.g && i2 == this.h) {
|
|
return;
|
|
}
|
|
this.g = i;
|
|
this.h = i2;
|
|
ViewCompat.A(this);
|
|
}
|
|
|
|
private void a(TabView tabView, RectF rectF) {
|
|
int d = tabView.d();
|
|
if (d < TabLayout.this.a(24)) {
|
|
d = TabLayout.this.a(24);
|
|
}
|
|
int left = (tabView.getLeft() + tabView.getRight()) / 2;
|
|
int i = d / 2;
|
|
rectF.set(left - i, 0.0f, left + i, 0.0f);
|
|
}
|
|
}
|
|
|
|
public TabLayout(Context context, AttributeSet attributeSet, int i) {
|
|
super(context, attributeSet, i);
|
|
this.a = new ArrayList<>();
|
|
this.c = new RectF();
|
|
this.r = Integer.MAX_VALUE;
|
|
this.F = new ArrayList<>();
|
|
this.O = new Pools$SimplePool(12);
|
|
setHorizontalScrollBarEnabled(false);
|
|
this.d = new SlidingTabIndicator(context);
|
|
super.addView(this.d, 0, new FrameLayout.LayoutParams(-2, -1));
|
|
TypedArray c = ThemeEnforcement.c(context, attributeSet, R$styleable.TabLayout, i, R$style.Widget_Design_TabLayout, R$styleable.TabLayout_tabTextAppearance);
|
|
this.d.b(c.getDimensionPixelSize(R$styleable.TabLayout_tabIndicatorHeight, -1));
|
|
this.d.a(c.getColor(R$styleable.TabLayout_tabIndicatorColor, 0));
|
|
setSelectedTabIndicator(MaterialResources.b(context, c, R$styleable.TabLayout_tabIndicator));
|
|
setSelectedTabIndicatorGravity(c.getInt(R$styleable.TabLayout_tabIndicatorGravity, 0));
|
|
setTabIndicatorFullWidth(c.getBoolean(R$styleable.TabLayout_tabIndicatorFullWidth, true));
|
|
int dimensionPixelSize = c.getDimensionPixelSize(R$styleable.TabLayout_tabPadding, 0);
|
|
this.h = dimensionPixelSize;
|
|
this.g = dimensionPixelSize;
|
|
this.f = dimensionPixelSize;
|
|
this.e = dimensionPixelSize;
|
|
this.e = c.getDimensionPixelSize(R$styleable.TabLayout_tabPaddingStart, this.e);
|
|
this.f = c.getDimensionPixelSize(R$styleable.TabLayout_tabPaddingTop, this.f);
|
|
this.g = c.getDimensionPixelSize(R$styleable.TabLayout_tabPaddingEnd, this.g);
|
|
this.h = c.getDimensionPixelSize(R$styleable.TabLayout_tabPaddingBottom, this.h);
|
|
this.i = c.getResourceId(R$styleable.TabLayout_tabTextAppearance, R$style.TextAppearance_Design_Tab);
|
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(this.i, androidx.appcompat.R$styleable.TextAppearance);
|
|
try {
|
|
this.o = obtainStyledAttributes.getDimensionPixelSize(androidx.appcompat.R$styleable.TextAppearance_android_textSize, 0);
|
|
this.j = MaterialResources.a(context, obtainStyledAttributes, androidx.appcompat.R$styleable.TextAppearance_android_textColor);
|
|
obtainStyledAttributes.recycle();
|
|
if (c.hasValue(R$styleable.TabLayout_tabTextColor)) {
|
|
this.j = MaterialResources.a(context, c, R$styleable.TabLayout_tabTextColor);
|
|
}
|
|
if (c.hasValue(R$styleable.TabLayout_tabSelectedTextColor)) {
|
|
this.j = a(this.j.getDefaultColor(), c.getColor(R$styleable.TabLayout_tabSelectedTextColor, 0));
|
|
}
|
|
this.k = MaterialResources.a(context, c, R$styleable.TabLayout_tabIconTint);
|
|
this.n = ViewUtils.a(c.getInt(R$styleable.TabLayout_tabIconTintMode, -1), null);
|
|
this.l = MaterialResources.a(context, c, R$styleable.TabLayout_tabRippleColor);
|
|
this.y = c.getInt(R$styleable.TabLayout_tabIndicatorAnimationDuration, 300);
|
|
this.s = c.getDimensionPixelSize(R$styleable.TabLayout_tabMinWidth, -1);
|
|
this.t = c.getDimensionPixelSize(R$styleable.TabLayout_tabMaxWidth, -1);
|
|
this.q = c.getResourceId(R$styleable.TabLayout_tabBackground, 0);
|
|
this.v = c.getDimensionPixelSize(R$styleable.TabLayout_tabContentStart, 0);
|
|
this.A = c.getInt(R$styleable.TabLayout_tabMode, 1);
|
|
this.x = c.getInt(R$styleable.TabLayout_tabGravity, 0);
|
|
this.B = c.getBoolean(R$styleable.TabLayout_tabInlineLabel, false);
|
|
this.D = c.getBoolean(R$styleable.TabLayout_tabUnboundedRipple, false);
|
|
c.recycle();
|
|
Resources resources = getResources();
|
|
this.p = resources.getDimensionPixelSize(R$dimen.design_tab_text_size_2line);
|
|
this.u = resources.getDimensionPixelSize(R$dimen.design_tab_scrollable_min_width);
|
|
e();
|
|
} catch (Throwable th) {
|
|
obtainStyledAttributes.recycle();
|
|
throw th;
|
|
}
|
|
}
|
|
|
|
private void f(Tab tab) {
|
|
for (int size = this.F.size() - 1; size >= 0; size--) {
|
|
this.F.get(size).onTabReselected(tab);
|
|
}
|
|
}
|
|
|
|
private void h(Tab tab) {
|
|
for (int size = this.F.size() - 1; size >= 0; size--) {
|
|
this.F.get(size).onTabUnselected(tab);
|
|
}
|
|
}
|
|
|
|
void a(int i, float f, boolean z, boolean z2) {
|
|
int round = Math.round(i + f);
|
|
if (round < 0 || round >= this.d.getChildCount()) {
|
|
return;
|
|
}
|
|
if (z2) {
|
|
this.d.a(i, f);
|
|
}
|
|
ValueAnimator valueAnimator = this.H;
|
|
if (valueAnimator != null && valueAnimator.isRunning()) {
|
|
this.H.cancel();
|
|
}
|
|
scrollTo(a(i, f), 0);
|
|
if (z) {
|
|
setSelectedTabView(round);
|
|
}
|
|
}
|
|
|
|
@Override // android.widget.HorizontalScrollView, android.view.ViewGroup, android.view.ViewManager
|
|
public void addView(View view, ViewGroup.LayoutParams layoutParams) {
|
|
a(view);
|
|
}
|
|
|
|
@Override // android.widget.HorizontalScrollView, android.view.ViewGroup
|
|
public void addView(View view, int i, ViewGroup.LayoutParams layoutParams) {
|
|
a(view);
|
|
}
|
|
|
|
public void setSelectedTabIndicator(int i) {
|
|
if (i != 0) {
|
|
setSelectedTabIndicator(AppCompatResources.c(getContext(), i));
|
|
} else {
|
|
setSelectedTabIndicator((Drawable) null);
|
|
}
|
|
}
|
|
|
|
protected boolean b(Tab tab) {
|
|
return P.a(tab);
|
|
}
|
|
|
|
private void g(Tab tab) {
|
|
for (int size = this.F.size() - 1; size >= 0; size--) {
|
|
this.F.get(size).onTabSelected(tab);
|
|
}
|
|
}
|
|
|
|
public Tab b(int i) {
|
|
if (i < 0 || i >= getTabCount()) {
|
|
return null;
|
|
}
|
|
return this.a.get(i);
|
|
}
|
|
|
|
private void b(Tab tab, int i) {
|
|
tab.b(i);
|
|
this.a.add(i, tab);
|
|
int size = this.a.size();
|
|
while (true) {
|
|
i++;
|
|
if (i >= size) {
|
|
return;
|
|
} else {
|
|
this.a.get(i).b(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void c(int i) {
|
|
if (i == -1) {
|
|
return;
|
|
}
|
|
if (getWindowToken() != null && ViewCompat.x(this) && !this.d.a()) {
|
|
int scrollX = getScrollX();
|
|
int a = a(i, 0.0f);
|
|
if (scrollX != a) {
|
|
g();
|
|
this.H.setIntValues(scrollX, a);
|
|
this.H.start();
|
|
}
|
|
this.d.a(i, this.y);
|
|
return;
|
|
}
|
|
a(i, 0.0f, true);
|
|
}
|
|
|
|
private void d(Tab tab) {
|
|
this.d.addView(tab.h, tab.c(), f());
|
|
}
|
|
|
|
private void e() {
|
|
ViewCompat.a(this.d, this.A == 0 ? Math.max(0, this.v - this.e) : 0, 0, 0, 0);
|
|
int i = this.A;
|
|
if (i == 0) {
|
|
this.d.setGravity(8388611);
|
|
} else if (i == 1) {
|
|
this.d.setGravity(1);
|
|
}
|
|
a(true);
|
|
}
|
|
|
|
public void a(Tab tab) {
|
|
a(tab, this.a.isEmpty());
|
|
}
|
|
|
|
private void d(int i) {
|
|
TabView tabView = (TabView) this.d.getChildAt(i);
|
|
this.d.removeViewAt(i);
|
|
if (tabView != null) {
|
|
tabView.a();
|
|
this.O.a(tabView);
|
|
}
|
|
requestLayout();
|
|
}
|
|
|
|
public void a(Tab tab, int i) {
|
|
a(tab, i, this.a.isEmpty());
|
|
}
|
|
|
|
void b(Tab tab, boolean z) {
|
|
Tab tab2 = this.b;
|
|
if (tab2 == tab) {
|
|
if (tab2 != null) {
|
|
f(tab);
|
|
c(tab.c());
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
int c = tab != null ? tab.c() : -1;
|
|
if (z) {
|
|
if ((tab2 == null || tab2.c() == -1) && c != -1) {
|
|
a(c, 0.0f, true);
|
|
} else {
|
|
c(c);
|
|
}
|
|
if (c != -1) {
|
|
setSelectedTabView(c);
|
|
}
|
|
}
|
|
this.b = tab;
|
|
if (tab2 != null) {
|
|
h(tab2);
|
|
}
|
|
if (tab != null) {
|
|
g(tab);
|
|
}
|
|
}
|
|
|
|
public void a(Tab tab, boolean z) {
|
|
a(tab, this.a.size(), z);
|
|
}
|
|
|
|
public void a(Tab tab, int i, boolean z) {
|
|
if (tab.g == this) {
|
|
b(tab, i);
|
|
d(tab);
|
|
if (z) {
|
|
tab.h();
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
throw new IllegalArgumentException("Tab belongs to a different TabLayout.");
|
|
}
|
|
|
|
private void a(TabItem tabItem) {
|
|
Tab b = b();
|
|
CharSequence charSequence = tabItem.a;
|
|
if (charSequence != null) {
|
|
b.b(charSequence);
|
|
}
|
|
Drawable drawable = tabItem.b;
|
|
if (drawable != null) {
|
|
b.a(drawable);
|
|
}
|
|
int i = tabItem.c;
|
|
if (i != 0) {
|
|
b.a(i);
|
|
}
|
|
if (!TextUtils.isEmpty(tabItem.getContentDescription())) {
|
|
b.a(tabItem.getContentDescription());
|
|
}
|
|
a(b);
|
|
}
|
|
|
|
void c(Tab tab) {
|
|
b(tab, true);
|
|
}
|
|
|
|
public void a(BaseOnTabSelectedListener baseOnTabSelectedListener) {
|
|
if (this.F.contains(baseOnTabSelectedListener)) {
|
|
return;
|
|
}
|
|
this.F.add(baseOnTabSelectedListener);
|
|
}
|
|
|
|
protected Tab a() {
|
|
Tab a = P.a();
|
|
return a == null ? new Tab() : a;
|
|
}
|
|
|
|
public void a(ViewPager viewPager, boolean z) {
|
|
a(viewPager, z, false);
|
|
}
|
|
|
|
private void a(ViewPager viewPager, boolean z, boolean z2) {
|
|
ViewPager viewPager2 = this.I;
|
|
if (viewPager2 != null) {
|
|
TabLayoutOnPageChangeListener tabLayoutOnPageChangeListener = this.L;
|
|
if (tabLayoutOnPageChangeListener != null) {
|
|
viewPager2.b(tabLayoutOnPageChangeListener);
|
|
}
|
|
AdapterChangeListener adapterChangeListener = this.M;
|
|
if (adapterChangeListener != null) {
|
|
this.I.b(adapterChangeListener);
|
|
}
|
|
}
|
|
BaseOnTabSelectedListener baseOnTabSelectedListener = this.G;
|
|
if (baseOnTabSelectedListener != null) {
|
|
b(baseOnTabSelectedListener);
|
|
this.G = null;
|
|
}
|
|
if (viewPager != null) {
|
|
this.I = viewPager;
|
|
if (this.L == null) {
|
|
this.L = new TabLayoutOnPageChangeListener(this);
|
|
}
|
|
this.L.a();
|
|
viewPager.a(this.L);
|
|
this.G = new ViewPagerOnTabSelectedListener(viewPager);
|
|
a(this.G);
|
|
PagerAdapter adapter = viewPager.getAdapter();
|
|
if (adapter != null) {
|
|
a(adapter, z);
|
|
}
|
|
if (this.M == null) {
|
|
this.M = new AdapterChangeListener();
|
|
}
|
|
this.M.a(z);
|
|
viewPager.a(this.M);
|
|
a(viewPager.getCurrentItem(), 0.0f, true);
|
|
} else {
|
|
this.I = null;
|
|
a((PagerAdapter) null, false);
|
|
}
|
|
this.N = z2;
|
|
}
|
|
|
|
void a(PagerAdapter pagerAdapter, boolean z) {
|
|
DataSetObserver dataSetObserver;
|
|
PagerAdapter pagerAdapter2 = this.J;
|
|
if (pagerAdapter2 != null && (dataSetObserver = this.K) != null) {
|
|
pagerAdapter2.unregisterDataSetObserver(dataSetObserver);
|
|
}
|
|
this.J = pagerAdapter;
|
|
if (z && pagerAdapter != null) {
|
|
if (this.K == null) {
|
|
this.K = new PagerAdapterObserver();
|
|
}
|
|
pagerAdapter.registerDataSetObserver(this.K);
|
|
}
|
|
c();
|
|
}
|
|
|
|
private void a(View view) {
|
|
if (view instanceof TabItem) {
|
|
a((TabItem) view);
|
|
return;
|
|
}
|
|
throw new IllegalArgumentException("Only TabItem instances can be added to TabLayout");
|
|
}
|
|
|
|
private void a(LinearLayout.LayoutParams layoutParams) {
|
|
if (this.A == 1 && this.x == 0) {
|
|
layoutParams.width = 0;
|
|
layoutParams.weight = 1.0f;
|
|
} else {
|
|
layoutParams.width = -2;
|
|
layoutParams.weight = 0.0f;
|
|
}
|
|
}
|
|
|
|
int a(int i) {
|
|
return Math.round(getResources().getDisplayMetrics().density * i);
|
|
}
|
|
|
|
private int a(int i, float f) {
|
|
if (this.A != 0) {
|
|
return 0;
|
|
}
|
|
View childAt = this.d.getChildAt(i);
|
|
int i2 = i + 1;
|
|
View childAt2 = i2 < this.d.getChildCount() ? this.d.getChildAt(i2) : null;
|
|
int width = childAt != null ? childAt.getWidth() : 0;
|
|
int width2 = childAt2 != null ? childAt2.getWidth() : 0;
|
|
int left = (childAt.getLeft() + (width / 2)) - (getWidth() / 2);
|
|
int i3 = (int) ((width + width2) * 0.5f * f);
|
|
return ViewCompat.k(this) == 0 ? left + i3 : left - i3;
|
|
}
|
|
|
|
void a(boolean z) {
|
|
for (int i = 0; i < this.d.getChildCount(); i++) {
|
|
View childAt = this.d.getChildAt(i);
|
|
childAt.setMinimumWidth(getTabMinWidth());
|
|
a((LinearLayout.LayoutParams) childAt.getLayoutParams());
|
|
if (z) {
|
|
childAt.requestLayout();
|
|
}
|
|
}
|
|
}
|
|
|
|
private static ColorStateList a(int i, int i2) {
|
|
return new ColorStateList(new int[][]{HorizontalScrollView.SELECTED_STATE_SET, HorizontalScrollView.EMPTY_STATE_SET}, new int[]{i2, i});
|
|
}
|
|
}
|