402 lines
13 KiB
Java
402 lines
13 KiB
Java
package androidx.appcompat.widget;
|
|
|
|
import android.R;
|
|
import android.content.Context;
|
|
import android.content.res.Configuration;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.text.TextUtils;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewParent;
|
|
import android.view.accessibility.AccessibilityEvent;
|
|
import android.view.accessibility.AccessibilityNodeInfo;
|
|
import android.view.animation.DecelerateInterpolator;
|
|
import android.widget.AbsListView;
|
|
import android.widget.AdapterView;
|
|
import android.widget.BaseAdapter;
|
|
import android.widget.HorizontalScrollView;
|
|
import android.widget.ImageView;
|
|
import android.widget.LinearLayout;
|
|
import android.widget.Spinner;
|
|
import android.widget.SpinnerAdapter;
|
|
import android.widget.TextView;
|
|
import androidx.appcompat.R$attr;
|
|
import androidx.appcompat.app.ActionBar;
|
|
import androidx.appcompat.view.ActionBarPolicy;
|
|
import androidx.appcompat.widget.LinearLayoutCompat;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class ScrollingTabContainerView extends HorizontalScrollView implements AdapterView.OnItemSelectedListener {
|
|
Runnable a;
|
|
private TabClickListener b;
|
|
LinearLayoutCompat c;
|
|
private Spinner d;
|
|
private boolean e;
|
|
int f;
|
|
int g;
|
|
private int h;
|
|
private int i;
|
|
|
|
private class TabAdapter extends BaseAdapter {
|
|
TabAdapter() {
|
|
}
|
|
|
|
@Override // android.widget.Adapter
|
|
public int getCount() {
|
|
return ScrollingTabContainerView.this.c.getChildCount();
|
|
}
|
|
|
|
@Override // android.widget.Adapter
|
|
public Object getItem(int i) {
|
|
return ((TabView) ScrollingTabContainerView.this.c.getChildAt(i)).a();
|
|
}
|
|
|
|
@Override // android.widget.Adapter
|
|
public long getItemId(int i) {
|
|
return i;
|
|
}
|
|
|
|
@Override // android.widget.Adapter
|
|
public View getView(int i, View view, ViewGroup viewGroup) {
|
|
if (view == null) {
|
|
return ScrollingTabContainerView.this.a((ActionBar.Tab) getItem(i), true);
|
|
}
|
|
((TabView) view).a((ActionBar.Tab) getItem(i));
|
|
return view;
|
|
}
|
|
}
|
|
|
|
private class TabClickListener implements View.OnClickListener {
|
|
TabClickListener() {
|
|
}
|
|
|
|
@Override // android.view.View.OnClickListener
|
|
public void onClick(View view) {
|
|
((TabView) view).a().e();
|
|
int childCount = ScrollingTabContainerView.this.c.getChildCount();
|
|
for (int i = 0; i < childCount; i++) {
|
|
View childAt = ScrollingTabContainerView.this.c.getChildAt(i);
|
|
childAt.setSelected(childAt == view);
|
|
}
|
|
}
|
|
}
|
|
|
|
static {
|
|
new DecelerateInterpolator();
|
|
}
|
|
|
|
private Spinner a() {
|
|
AppCompatSpinner appCompatSpinner = new AppCompatSpinner(getContext(), null, R$attr.actionDropDownStyle);
|
|
appCompatSpinner.setLayoutParams(new LinearLayoutCompat.LayoutParams(-2, -1));
|
|
appCompatSpinner.setOnItemSelectedListener(this);
|
|
return appCompatSpinner;
|
|
}
|
|
|
|
private boolean b() {
|
|
Spinner spinner = this.d;
|
|
return spinner != null && spinner.getParent() == this;
|
|
}
|
|
|
|
private void c() {
|
|
if (b()) {
|
|
return;
|
|
}
|
|
if (this.d == null) {
|
|
this.d = a();
|
|
}
|
|
removeView(this.c);
|
|
addView(this.d, new ViewGroup.LayoutParams(-2, -1));
|
|
if (this.d.getAdapter() == null) {
|
|
this.d.setAdapter((SpinnerAdapter) new TabAdapter());
|
|
}
|
|
Runnable runnable = this.a;
|
|
if (runnable != null) {
|
|
removeCallbacks(runnable);
|
|
this.a = null;
|
|
}
|
|
this.d.setSelection(this.i);
|
|
}
|
|
|
|
private boolean d() {
|
|
if (!b()) {
|
|
return false;
|
|
}
|
|
removeView(this.d);
|
|
addView(this.c, new ViewGroup.LayoutParams(-2, -1));
|
|
setTabSelected(this.d.getSelectedItemPosition());
|
|
return false;
|
|
}
|
|
|
|
@Override // android.view.ViewGroup, android.view.View
|
|
public void onAttachedToWindow() {
|
|
super.onAttachedToWindow();
|
|
Runnable runnable = this.a;
|
|
if (runnable != null) {
|
|
post(runnable);
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View
|
|
protected void onConfigurationChanged(Configuration configuration) {
|
|
super.onConfigurationChanged(configuration);
|
|
ActionBarPolicy a = ActionBarPolicy.a(getContext());
|
|
setContentHeight(a.e());
|
|
this.g = a.d();
|
|
}
|
|
|
|
@Override // android.view.ViewGroup, android.view.View
|
|
public void onDetachedFromWindow() {
|
|
super.onDetachedFromWindow();
|
|
Runnable runnable = this.a;
|
|
if (runnable != null) {
|
|
removeCallbacks(runnable);
|
|
}
|
|
}
|
|
|
|
@Override // android.widget.AdapterView.OnItemSelectedListener
|
|
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long j) {
|
|
((TabView) view).a().e();
|
|
}
|
|
|
|
@Override // android.widget.HorizontalScrollView, android.widget.FrameLayout, android.view.View
|
|
public void onMeasure(int i, int i2) {
|
|
int mode = View.MeasureSpec.getMode(i);
|
|
boolean z = mode == 1073741824;
|
|
setFillViewport(z);
|
|
int childCount = this.c.getChildCount();
|
|
if (childCount <= 1 || !(mode == 1073741824 || mode == Integer.MIN_VALUE)) {
|
|
this.f = -1;
|
|
} else {
|
|
if (childCount > 2) {
|
|
this.f = (int) (View.MeasureSpec.getSize(i) * 0.4f);
|
|
} else {
|
|
this.f = View.MeasureSpec.getSize(i) / 2;
|
|
}
|
|
this.f = Math.min(this.f, this.g);
|
|
}
|
|
int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(this.h, 1073741824);
|
|
if (!z && this.e) {
|
|
this.c.measure(0, makeMeasureSpec);
|
|
if (this.c.getMeasuredWidth() > View.MeasureSpec.getSize(i)) {
|
|
c();
|
|
} else {
|
|
d();
|
|
}
|
|
} else {
|
|
d();
|
|
}
|
|
int measuredWidth = getMeasuredWidth();
|
|
super.onMeasure(i, makeMeasureSpec);
|
|
int measuredWidth2 = getMeasuredWidth();
|
|
if (!z || measuredWidth == measuredWidth2) {
|
|
return;
|
|
}
|
|
setTabSelected(this.i);
|
|
}
|
|
|
|
@Override // android.widget.AdapterView.OnItemSelectedListener
|
|
public void onNothingSelected(AdapterView<?> adapterView) {
|
|
}
|
|
|
|
public void setAllowCollapse(boolean z) {
|
|
this.e = z;
|
|
}
|
|
|
|
public void setContentHeight(int i) {
|
|
this.h = i;
|
|
requestLayout();
|
|
}
|
|
|
|
public void setTabSelected(int i) {
|
|
this.i = i;
|
|
int childCount = this.c.getChildCount();
|
|
int i2 = 0;
|
|
while (i2 < childCount) {
|
|
View childAt = this.c.getChildAt(i2);
|
|
boolean z = i2 == i;
|
|
childAt.setSelected(z);
|
|
if (z) {
|
|
a(i);
|
|
}
|
|
i2++;
|
|
}
|
|
Spinner spinner = this.d;
|
|
if (spinner == null || i < 0) {
|
|
return;
|
|
}
|
|
spinner.setSelection(i);
|
|
}
|
|
|
|
private class TabView extends LinearLayout {
|
|
private final int[] a;
|
|
private ActionBar.Tab b;
|
|
private TextView c;
|
|
private ImageView d;
|
|
private View e;
|
|
|
|
public TabView(Context context, ActionBar.Tab tab, boolean z) {
|
|
super(context, null, R$attr.actionBarTabStyle);
|
|
this.a = new int[]{R.attr.background};
|
|
this.b = tab;
|
|
TintTypedArray a = TintTypedArray.a(context, null, this.a, R$attr.actionBarTabStyle, 0);
|
|
if (a.g(0)) {
|
|
setBackgroundDrawable(a.b(0));
|
|
}
|
|
a.a();
|
|
if (z) {
|
|
setGravity(8388627);
|
|
}
|
|
b();
|
|
}
|
|
|
|
public void a(ActionBar.Tab tab) {
|
|
this.b = tab;
|
|
b();
|
|
}
|
|
|
|
public void b() {
|
|
ActionBar.Tab tab = this.b;
|
|
View b = tab.b();
|
|
if (b != null) {
|
|
ViewParent parent = b.getParent();
|
|
if (parent != this) {
|
|
if (parent != null) {
|
|
((ViewGroup) parent).removeView(b);
|
|
}
|
|
addView(b);
|
|
}
|
|
this.e = b;
|
|
TextView textView = this.c;
|
|
if (textView != null) {
|
|
textView.setVisibility(8);
|
|
}
|
|
ImageView imageView = this.d;
|
|
if (imageView != null) {
|
|
imageView.setVisibility(8);
|
|
this.d.setImageDrawable(null);
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
View view = this.e;
|
|
if (view != null) {
|
|
removeView(view);
|
|
this.e = null;
|
|
}
|
|
Drawable c = tab.c();
|
|
CharSequence d = tab.d();
|
|
if (c != null) {
|
|
if (this.d == null) {
|
|
AppCompatImageView appCompatImageView = new AppCompatImageView(getContext());
|
|
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -2);
|
|
layoutParams.gravity = 16;
|
|
appCompatImageView.setLayoutParams(layoutParams);
|
|
addView(appCompatImageView, 0);
|
|
this.d = appCompatImageView;
|
|
}
|
|
this.d.setImageDrawable(c);
|
|
this.d.setVisibility(0);
|
|
} else {
|
|
ImageView imageView2 = this.d;
|
|
if (imageView2 != null) {
|
|
imageView2.setVisibility(8);
|
|
this.d.setImageDrawable(null);
|
|
}
|
|
}
|
|
boolean z = !TextUtils.isEmpty(d);
|
|
if (z) {
|
|
if (this.c == null) {
|
|
AppCompatTextView appCompatTextView = new AppCompatTextView(getContext(), null, R$attr.actionBarTabTextStyle);
|
|
appCompatTextView.setEllipsize(TextUtils.TruncateAt.END);
|
|
LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(-2, -2);
|
|
layoutParams2.gravity = 16;
|
|
appCompatTextView.setLayoutParams(layoutParams2);
|
|
addView(appCompatTextView);
|
|
this.c = appCompatTextView;
|
|
}
|
|
this.c.setText(d);
|
|
this.c.setVisibility(0);
|
|
} else {
|
|
TextView textView2 = this.c;
|
|
if (textView2 != null) {
|
|
textView2.setVisibility(8);
|
|
this.c.setText((CharSequence) null);
|
|
}
|
|
}
|
|
ImageView imageView3 = this.d;
|
|
if (imageView3 != null) {
|
|
imageView3.setContentDescription(tab.a());
|
|
}
|
|
TooltipCompat.a(this, z ? null : tab.a());
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
|
|
super.onInitializeAccessibilityEvent(accessibilityEvent);
|
|
accessibilityEvent.setClassName(ActionBar.Tab.class.getName());
|
|
}
|
|
|
|
@Override // android.view.View
|
|
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) {
|
|
super.onMeasure(i, i2);
|
|
if (ScrollingTabContainerView.this.f > 0) {
|
|
int measuredWidth = getMeasuredWidth();
|
|
int i3 = ScrollingTabContainerView.this.f;
|
|
if (measuredWidth > i3) {
|
|
super.onMeasure(View.MeasureSpec.makeMeasureSpec(i3, 1073741824), i2);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void setSelected(boolean z) {
|
|
boolean z2 = isSelected() != z;
|
|
super.setSelected(z);
|
|
if (z2 && z) {
|
|
sendAccessibilityEvent(4);
|
|
}
|
|
}
|
|
|
|
public ActionBar.Tab a() {
|
|
return this.b;
|
|
}
|
|
}
|
|
|
|
public void a(int i) {
|
|
final View childAt = this.c.getChildAt(i);
|
|
Runnable runnable = this.a;
|
|
if (runnable != null) {
|
|
removeCallbacks(runnable);
|
|
}
|
|
this.a = new Runnable() { // from class: androidx.appcompat.widget.ScrollingTabContainerView.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
ScrollingTabContainerView.this.smoothScrollTo(childAt.getLeft() - ((ScrollingTabContainerView.this.getWidth() - childAt.getWidth()) / 2), 0);
|
|
ScrollingTabContainerView.this.a = null;
|
|
}
|
|
};
|
|
post(this.a);
|
|
}
|
|
|
|
TabView a(ActionBar.Tab tab, boolean z) {
|
|
TabView tabView = new TabView(getContext(), tab, z);
|
|
if (z) {
|
|
tabView.setBackgroundDrawable(null);
|
|
tabView.setLayoutParams(new AbsListView.LayoutParams(-1, this.h));
|
|
} else {
|
|
tabView.setFocusable(true);
|
|
if (this.b == null) {
|
|
this.b = new TabClickListener();
|
|
}
|
|
tabView.setOnClickListener(this.b);
|
|
}
|
|
return tabView;
|
|
}
|
|
}
|