package androidx.appcompat.widget; import android.R; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; 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.ViewPropertyAnimator; 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.widget.LinearLayoutCompat; import o.AuZ; import o.C0683McA; import o.C6286cOZ; import o.SYO; import o.pwE; /* loaded from: classes.dex */ public class ScrollingTabContainerView extends HorizontalScrollView implements AdapterView.OnItemSelectedListener { Runnable a; int b; LinearLayoutCompat c; protected final LWm d; int e; private Spinner f; private int g; protected ViewPropertyAnimator h; private boolean i; private int j; private Sts mTabClickListener; @Override // android.widget.AdapterView.OnItemSelectedListener public void onNothingSelected(AdapterView adapterView) { } static { new DecelerateInterpolator(); } public ScrollingTabContainerView(Context context) { super(context); this.d = new LWm(this); setHorizontalScrollBarEnabled(false); AuZ auZ = new AuZ(context); setContentHeight(auZ.b()); this.g = auZ.c.getResources().getDimensionPixelSize(SYO.Sts.abc_action_bar_stacked_tab_max_width); LinearLayoutCompat linearLayoutCompat = new LinearLayoutCompat(getContext(), null, SYO.IeS.actionBarTabBarStyle); linearLayoutCompat.setMeasureWithLargestChildEnabled(true); linearLayoutCompat.setGravity(17); linearLayoutCompat.setLayoutParams(new LinearLayoutCompat.RVV(-2, -1)); this.c = linearLayoutCompat; addView(linearLayoutCompat, new ViewGroup.LayoutParams(-2, -1)); } @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.e = -1; } else { if (childCount > 2) { this.e = (int) (View.MeasureSpec.getSize(i) * 0.4f); } else { this.e = View.MeasureSpec.getSize(i) / 2; } this.e = Math.min(this.e, this.g); } int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(this.b, 1073741824); if (!z && this.i) { this.c.measure(0, makeMeasureSpec); if (this.c.getMeasuredWidth() <= View.MeasureSpec.getSize(i)) { e(); } else { Spinner spinner = this.f; if (spinner == null || spinner.getParent() != this) { if (this.f == null) { AppCompatSpinner appCompatSpinner = new AppCompatSpinner(getContext(), null, SYO.IeS.actionDropDownStyle); appCompatSpinner.setLayoutParams(new LinearLayoutCompat.RVV(-2, -1)); appCompatSpinner.setOnItemSelectedListener(this); this.f = appCompatSpinner; } removeView(this.c); addView(this.f, new ViewGroup.LayoutParams(-2, -1)); if (this.f.getAdapter() == null) { this.f.setAdapter((SpinnerAdapter) new HBt(this)); } Runnable runnable = this.a; if (runnable != null) { removeCallbacks(runnable); this.a = null; } this.f.setSelection(this.j); } } } else { e(); } int measuredWidth = getMeasuredWidth(); super.onMeasure(i, makeMeasureSpec); int measuredWidth2 = getMeasuredWidth(); if (!z || measuredWidth == measuredWidth2) { return; } setTabSelected(this.j); } private boolean e() { Spinner spinner = this.f; if (spinner != null && spinner.getParent() == this) { removeView(this.f); addView(this.c, new ViewGroup.LayoutParams(-2, -1)); setTabSelected(this.f.getSelectedItemPosition()); } return false; } public void setTabSelected(int i) { this.j = 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) { View childAt2 = this.c.getChildAt(i); Runnable runnable = this.a; if (runnable != null) { removeCallbacks(runnable); } Runnable runnable2 = new Runnable(this, childAt2) { // from class: androidx.appcompat.widget.ScrollingTabContainerView.2 final View a; final ScrollingTabContainerView d; { this.d = this; this.a = childAt2; } @Override // java.lang.Runnable public final void run() { this.d.smoothScrollTo(this.a.getLeft() - ((this.d.getWidth() - this.a.getWidth()) / 2), 0); this.d.a = null; } }; this.a = runnable2; post(runnable2); } i2++; } Spinner spinner = this.f; if (spinner == null || i < 0) { return; } spinner.setSelection(i); } public void setContentHeight(int i) { this.b = i; requestLayout(); } @Override // android.view.View protected void onConfigurationChanged(Configuration configuration) { super.onConfigurationChanged(configuration); AuZ auZ = new AuZ(getContext()); setContentHeight(auZ.b()); this.g = auZ.c.getResources().getDimensionPixelSize(SYO.Sts.abc_action_bar_stacked_tab_max_width); } @Override // android.view.ViewGroup, android.view.View public void onAttachedToWindow() { super.onAttachedToWindow(); Runnable runnable = this.a; if (runnable != null) { post(runnable); } } @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) { pwE.RVV rvv = ((TabView) view).e; } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public class TabView extends LinearLayout { private final int[] a; final ScrollingTabContainerView b; private View c; private ImageView d; pwE.RVV e; private TextView j; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ public TabView(ScrollingTabContainerView scrollingTabContainerView, Context context, pwE.RVV rvv) { super(context, null, SYO.IeS.actionBarTabStyle); this.b = scrollingTabContainerView; int[] iArr = {R.attr.background}; this.a = iArr; this.e = rvv; C0683McA c0683McA = new C0683McA(context, context.obtainStyledAttributes(null, iArr, SYO.IeS.actionBarTabStyle, 0)); if (c0683McA.d.hasValue(0)) { setBackgroundDrawable(c0683McA.jL_(0)); } c0683McA.d.recycle(); setGravity(8388627); e(); } @Override // android.view.View public void setSelected(boolean z) { boolean z2 = isSelected() != z; super.setSelected(z); if (z2 && z) { sendAccessibilityEvent(4); } } @Override // android.view.View public void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent) { super.onInitializeAccessibilityEvent(accessibilityEvent); accessibilityEvent.setClassName("o.pwE$RVV"); } @Override // android.view.View public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo accessibilityNodeInfo) { super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo); accessibilityNodeInfo.setClassName("o.pwE$RVV"); } @Override // android.widget.LinearLayout, android.view.View public void onMeasure(int i, int i2) { super.onMeasure(i, i2); if (this.b.e <= 0 || getMeasuredWidth() <= this.b.e) { return; } super.onMeasure(View.MeasureSpec.makeMeasureSpec(this.b.e, 1073741824), i2); } public final void e() { pwE.RVV rvv = this.e; View a = rvv.a(); if (a != null) { ViewParent parent = a.getParent(); if (parent != this) { if (parent != null) { ((ViewGroup) parent).removeView(a); } addView(a); } this.c = a; TextView textView = this.j; 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.c; if (view != null) { removeView(view); this.c = null; } Drawable bR_ = rvv.bR_(); CharSequence e = rvv.e(); if (bR_ != 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(bR_); this.d.setVisibility(0); } else { ImageView imageView2 = this.d; if (imageView2 != null) { imageView2.setVisibility(8); this.d.setImageDrawable(null); } } boolean z = !TextUtils.isEmpty(e); if (z) { if (this.j == null) { AppCompatTextView appCompatTextView = new AppCompatTextView(getContext(), null, SYO.IeS.actionBarTabTextStyle); appCompatTextView.setEllipsize(TextUtils.TruncateAt.END); LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(-2, -2); layoutParams2.gravity = 16; appCompatTextView.setLayoutParams(layoutParams2); addView(appCompatTextView); this.j = appCompatTextView; } this.j.setText(e); this.j.setVisibility(0); } else { TextView textView2 = this.j; if (textView2 != null) { textView2.setVisibility(8); this.j.setText((CharSequence) null); } } ImageView imageView3 = this.d; if (imageView3 != null) { imageView3.setContentDescription(rvv.c()); } C6286cOZ.e(this, z ? null : rvv.c()); } } /* loaded from: classes.dex */ class HBt extends BaseAdapter { final ScrollingTabContainerView e; @Override // android.widget.Adapter public final long getItemId(int i) { return i; } HBt(ScrollingTabContainerView scrollingTabContainerView) { this.e = scrollingTabContainerView; } @Override // android.widget.Adapter public final int getCount() { return this.e.c.getChildCount(); } @Override // android.widget.Adapter public final Object getItem(int i) { return ((TabView) this.e.c.getChildAt(i)).e; } @Override // android.widget.Adapter public final View getView(int i, View view, ViewGroup viewGroup) { if (view == null) { ScrollingTabContainerView scrollingTabContainerView = this.e; TabView tabView = new TabView(scrollingTabContainerView, scrollingTabContainerView.getContext(), (pwE.RVV) getItem(i)); tabView.setBackgroundDrawable(null); tabView.setLayoutParams(new AbsListView.LayoutParams(-1, scrollingTabContainerView.b)); return tabView; } TabView tabView2 = (TabView) view; tabView2.e = (pwE.RVV) getItem(i); tabView2.e(); return view; } } /* loaded from: classes.dex */ class Sts implements View.OnClickListener { final ScrollingTabContainerView a; @Override // android.view.View.OnClickListener public void onClick(View view) { pwE.RVV rvv = ((TabView) view).e; int childCount = this.a.c.getChildCount(); for (int i = 0; i < childCount; i++) { View childAt = this.a.c.getChildAt(i); childAt.setSelected(childAt == view); } } } /* loaded from: classes.dex */ protected class LWm extends AnimatorListenerAdapter { final ScrollingTabContainerView a; private boolean c = false; private int e; protected LWm(ScrollingTabContainerView scrollingTabContainerView) { this.a = scrollingTabContainerView; } @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener public final void onAnimationStart(Animator animator) { this.a.setVisibility(0); this.c = false; } @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener public final void onAnimationEnd(Animator animator) { if (this.c) { return; } this.a.h = null; this.a.setVisibility(0); } @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener public final void onAnimationCancel(Animator animator) { this.c = true; } } public void setAllowCollapse(boolean z) { this.i = z; } }