content: package androidx.appcompat.widget;
  
  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.util.AttributeSet;
  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.view.animation.Interpolator;
  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.TextView;
  import androidx.appcompat.R;
  import androidx.appcompat.app.ActionBar;
  import androidx.appcompat.view.ActionBarPolicy;
  import androidx.appcompat.widget.LinearLayoutCompat;
  import androidx.constraintlayout.core.widgets.analyzer.BasicMeasure;
  
  public class ScrollingTabContainerView extends HorizontalScrollView implements AdapterView.OnItemSelectedListener {
      private static final int FADE_DURATION = 200;
      private static final String TAG = "ScrollingTabContainerView";
      private static final Interpolator sAlphaInterpolator = new DecelerateInterpolator();
      private boolean mAllowCollapse;
      private int mContentHeight;
      int mMaxTabWidth;
      private int mSelectedTabIndex;
      int mStackedTabMaxWidth;
      private TabClickListener mTabClickListener;
      LinearLayoutCompat mTabLayout;
      Runnable mTabSelector;
      private Spinner mTabSpinner;
      protected final VisibilityAnimListener mVisAnimListener = new VisibilityAnimListener();
      protected ViewPropertyAnimator mVisibilityAnim;
  
      private class TabAdapter extends BaseAdapter {
          TabAdapter() {
          }
  
          public int getCount() {
              return ScrollingTabContainerView.this.mTabLayout.getChildCount();
          }
  
          public Object getItem(int position) {
              return ((TabView) ScrollingTabContainerView.this.mTabLayout.getChildAt(position)).getTab();
          }
  
          public long getItemId(int position) {
              return (long) position;
          }
  
          public View getView(int position, View convertView, ViewGroup parent) {
              if (convertView == null) {
                  return ScrollingTabContainerView.this.createTabView((ActionBar.Tab) getItem(position), true);
              }
              ((TabView) convertView).bindTab((ActionBar.Tab) getItem(position));
              return convertView;
          }
      }
  
      private class TabClickListener implements View.OnClickListener {
          TabClickListener() {
          }
  
          public void onClick(View view) {
              ((TabView) view).getTab().select();
              int childCount = ScrollingTabContainerView.this.mTabLayout.getChildCount();
              for (int i = 0; i < childCount; i++) {
                  View childAt = ScrollingTabContainerView.this.mTabLayout.getChildAt(i);
                  childAt.setSelected(childAt == view);
              }
          }
      }
  
      private class TabView extends LinearLayout {
          private static final String ACCESSIBILITY_CLASS_NAME = "androidx.appcompat.app.ActionBar$Tab";
          private final int[] BG_ATTRS;
          private View mCustomView;
          private ImageView mIconView;
          private ActionBar.Tab mTab;
          private TextView mTextView;
  
          public TabView(Context context, ActionBar.Tab tab, boolean forList) {
              super(context, (AttributeSet) null, R.attr.actionBarTabStyle);
              int[] iArr = {16842964};
              this.BG_ATTRS = iArr;
              this.mTab = tab;
              TintTypedArray obtainStyledAttributes = TintTypedArray.obtainStyledAttributes(context, (AttributeSet) null, iArr, R.attr.actionBarTabStyle, 0);
              if (obtainStyledAttributes.hasValue(0)) {
                  setBackgroundDrawable(obtainStyledAttributes.getDrawable(0));
              }
              obtainStyledAttributes.recycle();
              if (forList) {
                  setGravity(8388627);
              }
              update();
          }
  
          public void bindTab(ActionBar.Tab tab) {
              this.mTab = tab;
              update();
          }
  
          public ActionBar.Tab getTab() {
              return this.mTab;
          }
  
          public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
              super.onInitializeAccessibilityEvent(event);
              event.setClassName(ACCESSIBILITY_CLASS_NAME);
          }
  
          public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
              super.onInitializeAccessibilityNodeInfo(info);
              info.setClassName(ACCESSIBILITY_CLASS_NAME);
          }
  
          public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
              super.onMeasure(widthMeasureSpec, heightMeasureSpec);
              if (ScrollingTabContainerView.this.mMaxTabWidth > 0 && getMeasuredWidth() > ScrollingTabContainerView.this.mMaxTabWidth) {
                  super.onMeasure(View.MeasureSpec.makeMeasureSpec(ScrollingTabContainerView.this.mMaxTabWidth, BasicMeasure.EXACTLY), heightMeasureSpec);
              }
          }
  
          public void setSelected(boolean selected) {
              boolean z = isSelected() != selected;
              super.setSelected(selected);
              if (z && selected) {
                  sendAccessibilityEvent(4);
              }
          }
  
          public void update() {
              ActionBar.Tab tab = this.mTab;
              View customView = tab.getCustomView();
              CharSequence charSequence = null;
              if (customView != null) {
                  ViewParent parent = customView.getParent();
                  if (parent != this) {
                      if (parent != null) {
                          ((ViewGroup) parent).removeView(customView);
                      }
                      addView(customView);
                  }
                  this.mCustomView = customView;
                  TextView textView = this.mTextView;
                  if (textView != null) {
                      textView.setVisibility(8);
                  }
                  ImageView imageView = this.mIconView;
                  if (imageView != null) {
                      imageView.setVisibility(8);
                      this.mIconView.setImageDrawable((Drawable) null);
                      return;
                  }
                  return;
              }
              View view = this.mCustomView;
              if (view != null) {
                  removeView(view);
                  this.mCustomView = null;
              }
              Drawable icon = tab.getIcon();
              CharSequence text = tab.getText();
              if (icon != null) {
                  if (this.mIconView == null) {
                      AppCompatImageView appCompatImageView = new AppCompatImageView(getContext());
                      LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -2);
                      layoutParams.gravity = 16;
                      appCompatImageView.setLayoutParams(layoutParams);
                      addView(appCompatImageView, 0);
                      this.mIconView = appCompatImageView;
                  }
                  this.mIconView.setImageDrawable(icon);
                  this.mIconView.setVisibility(0);
              } else {
                  ImageView imageView2 = this.mIconView;
                  if (imageView2 != null) {
                      imageView2.setVisibility(8);
                      this.mIconView.setImageDrawable((Drawable) null);
                  }
              }
              boolean z = !TextUtils.isEmpty(text);
              if (z) {
                  if (this.mTextView == null) {
                      AppCompatTextView appCompatTextView = new AppCompatTextView(getContext(), (AttributeSet) 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.mTextView = appCompatTextView;
                  }
                  this.mTextView.setText(text);
                  this.mTextView.setVisibility(0);
              } else {
                  TextView textView2 = this.mTextView;
                  if (textView2 != null) {
                      textView2.setVisibility(8);
                      this.mTextView.setText((CharSequence) null);
                  }
              }
              ImageView imageView3 = this.mIconView;
              if (imageView3 != null) {
                  imageView3.setContentDescription(tab.getContentDescription());
              }
              if (!z) {
                  charSequence = tab.getContentDescription();
              }
              TooltipCompat.setTooltipText(this, charSequence);
          }
      }
  
      protected class VisibilityAnimListener extends AnimatorListenerAdapter {
          private boolean mCanceled = false;
          private int mFinalVisibility;
  
          protected VisibilityAnimListener() {
          }
  
          public void onAnimationCancel(Animator animator) {
              this.mCanceled = true;
          }
  
          public void onAnimationEnd(Animator animator) {
              if (!this.mCanceled) {
                  ScrollingTabContainerView.this.mVisibilityAnim = null;
                  ScrollingTabContainerView.this.setVisibility(this.mFinalVisibility);
              }
          }
  
          public void onAnimationStart(Animator animator) {
              ScrollingTabContainerView.this.setVisibility(0);
              this.mCanceled = false;
          }
  
          public VisibilityAnimListener withFinalVisibility(ViewPropertyAnimator animation, int visibility) {
              this.mFinalVisibility = visibility;
              ScrollingTabContainerView.this.mVisibilityAnim = animation;
              return this;
          }
      }
  
      public ScrollingTabContainerView(Context context) {
          super(context);
          setHorizontalScrollBarEnabled(false);
          ActionBarPolicy actionBarPolicy = ActionBarPolicy.get(context);
          setContentHeight(actionBarPolicy.getTabContainerHeight());
          this.mStackedTabMaxWidth = actionBarPolicy.getStackedTabMaxWidth();
          LinearLayoutCompat createTabLayout = createTabLayout();
          this.mTabLayout = createTabLayout;
          addView(createTabLayout, new ViewGroup.LayoutParams(-2, -1));
      }
  
      private Spinner createSpinner() {
          AppCompatSpinner appCompatSpinner = new AppCompatSpinner(getContext(), (AttributeSet) null, R.attr.actionDropDownStyle);
          appCompatSpinner.setLayoutParams(new LinearLayoutCompat.LayoutParams(-2, -1));
          appCompatSpinner.setOnItemSelectedListener(this);
          return appCompatSpinner;
      }
  
      private LinearLayoutCompat createTabLayout() {
          LinearLayoutCompat linearLayoutCompat = new LinearLayoutCompat(getContext(), (AttributeSet) null, R.attr.actionBarTabBarStyle);
          linearLayoutCompat.setMeasureWithLargestChildEnabled(true);
          linearLayoutCompat.setGravity(17);
          linearLayoutCompat.setLayoutParams(new LinearLayoutCompat.LayoutParams(-2, -1));
          return linearLayoutCompat;
      }
  
      private boolean isCollapsed() {
          Spinner spinner = this.mTabSpinner;
          return spinner != null && spinner.getParent() == this;
      }
  
      private void performCollapse() {
          if (!isCollapsed()) {
              if (this.mTabSpinner == null) {
                  this.mTabSpinner = createSpinner();
              }
              removeView(this.mTabLayout);
              addView(this.mTabSpinner, new ViewGroup.LayoutParams(-2, -1));
              if (this.mTabSpinner.getAdapter() == null) {
                  this.mTabSpinner.setAdapter(new TabAdapter());
              }
              Runnable runnable = this.mTabSelector;
              if (runnable != null) {
                  removeCallbacks(runnable);
                  this.mTabSelector = null;
              }
              this.mTabSpinner.setSelection(this.mSelectedTabIndex);
          }
      }
  
      private boolean performExpand() {
          if (!isCollapsed()) {
              return false;
          }
          removeView(this.mTabSpinner);
          addView(this.mTabLayout, new ViewGroup.LayoutParams(-2, -1));
          setTabSelected(this.mTabSpinner.getSelectedItemPosition());
          return false;
      }
  
      public void addTab(ActionBar.Tab tab, int position, boolean setSelected) {
          TabView createTabView = createTabView(tab, false);
          this.mTabLayout.addView(createTabView, position, new LinearLayoutCompat.LayoutParams(0, -1, 1.0f));
          Spinner spinner = this.mTabSpinner;
          if (spinner != null) {
              ((TabAdapter) spinner.getAdapter()).notifyDataSetChanged();
          }
          if (setSelected) {
              createTabView.setSelected(true);
          }
          if (this.mAllowCollapse) {
              requestLayout();
          }
      }
  
      public void addTab(ActionBar.Tab tab, boolean setSelected) {
          TabView createTabView = createTabView(tab, false);
          this.mTabLayout.addView(createTabView, new LinearLayoutCompat.LayoutParams(0, -1, 1.0f));
          Spinner spinner = this.mTabSpinner;
          if (spinner != null) {
              ((TabAdapter) spinner.getAdapter()).notifyDataSetChanged();
          }
          if (setSelected) {
              createTabView.setSelected(true);
          }
          if (this.mAllowCollapse) {
              requestLayout();
          }
      }
  
      public void animateToTab(int position) {
          final View childAt = this.mTabLayout.getChildAt(position);
          Runnable runnable = this.mTabSelector;
          if (runnable != null) {
              removeCallbacks(runnable);
          }
          AnonymousClass1 r1 = new Runnable() {
              public void run() {
                  ScrollingTabContainerView.this.smoothScrollTo(childAt.getLeft() - ((ScrollingTabContainerView.this.getWidth() - childAt.getWidth()) / 2), 0);
                  ScrollingTabContainerView.this.mTabSelector = null;
              }
          };
          this.mTabSelector = r1;
          post(r1);
      }
  
      public void animateToVisibility(int visibility) {
          ViewPropertyAnimator viewPropertyAnimator = this.mVisibilityAnim;
          if (viewPropertyAnimator != null) {
              viewPropertyAnimator.cancel();
          }
          if (visibility == 0) {
              if (getVisibility() != 0) {
                  setAlpha(0.0f);
              }
              ViewPropertyAnimator alpha = animate().alpha(1.0f);
              alpha.setDuration(200);
              alpha.setInterpolator(sAlphaInterpolator);
              alpha.setListener(this.mVisAnimListener.withFinalVisibility(alpha, visibility));
              alpha.start();
              return;
          }
          ViewPropertyAnimator alpha2 = animate().alpha(0.0f);
          alpha2.setDuration(200);
          alpha2.setInterpolator(sAlphaInterpolator);
          alpha2.setListener(this.mVisAnimListener.withFinalVisibility(alpha2, visibility));
          alpha2.start();
      }
  
      /* access modifiers changed from: package-private */
      public TabView createTabView(ActionBar.Tab tab, boolean forAdapter) {
          TabView tabView = new TabView(getContext(), tab, forAdapter);
          if (forAdapter) {
              tabView.setBackgroundDrawable((Drawable) null);
              tabView.setLayoutParams(new AbsListView.LayoutParams(-1, this.mContentHeight));
          } else {
              tabView.setFocusable(true);
              if (this.mTabClickListener == null) {
                  this.mTabClickListener = new TabClickListener();
              }
              tabView.setOnClickListener(this.mTabClickListener);
          }
          return tabView;
      }
  
      public void onAttachedToWindow() {
          super.onAttachedToWindow();
          Runnable runnable = this.mTabSelector;
          if (runnable != null) {
              post(runnable);
          }
      }
  
      /* access modifiers changed from: protected */
      public void onConfigurationChanged(Configuration newConfig) {
          super.onConfigurationChanged(newConfig);
          ActionBarPolicy actionBarPolicy = ActionBarPolicy.get(getContext());
          setContentHeight(actionBarPolicy.getTabContainerHeight());
          this.mStackedTabMaxWidth = actionBarPolicy.getStackedTabMaxWidth();
      }
  
      public void onDetachedFromWindow() {
          super.onDetachedFromWindow();
          Runnable runnable = this.mTabSelector;
          if (runnable != null) {
              removeCallbacks(runnable);
          }
      }
  
      public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
          ((TabView) view).getTab().select();
      }
  
      public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          int mode = View.MeasureSpec.getMode(widthMeasureSpec);
          boolean z = true;
          boolean z2 = mode == 1073741824;
          setFillViewport(z2);
          int childCount = this.mTabLayout.getChildCount();
          if (childCount <= 1 || !(mode == 1073741824 || mode == Integer.MIN_VALUE)) {
              this.mMaxTabWidth = -1;
          } else {
              if (childCount > 2) {
                  this.mMaxTabWidth = (int) (((float) View.MeasureSpec.getSize(widthMeasureSpec)) * 0.4f);
              } else {
                  this.mMaxTabWidth = View.MeasureSpec.getSize(widthMeasureSpec) / 2;
              }
              this.mMaxTabWidth = Math.min(this.mMaxTabWidth, this.mStackedTabMaxWidth);
          }
          int heightMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(this.mContentHeight, BasicMeasure.EXACTLY);
          if (z2 || !this.mAllowCollapse) {
              z = false;
          }
          if (z) {
              this.mTabLayout.measure(0, heightMeasureSpec2);
              if (this.mTabLayout.getMeasuredWidth() > View.MeasureSpec.getSize(widthMeasureSpec)) {
                  performCollapse();
              } else {
                  performExpand();
              }
          } else {
              performExpand();
          }
          int measuredWidth = getMeasuredWidth();
          super.onMeasure(widthMeasureSpec, heightMeasureSpec2);
          int measuredWidth2 = getMeasuredWidth();
          if (z2 && measuredWidth != measuredWidth2) {
              setTabSelected(this.mSelectedTabIndex);
          }
      }
  
      public void onNothingSelected(AdapterView<?> adapterView) {
      }
  
      public void removeAllTabs() {
          this.mTabLayout.removeAllViews();
          Spinner spinner = this.mTabSpinner;
          if (spinner != null) {
              ((TabAdapter) spinner.getAdapter()).notifyDataSetChanged();
          }
          if (this.mAllowCollapse) {
              requestLayout();
          }
      }
  
      public void removeTabAt(int position) {
          this.mTabLayout.removeViewAt(position);
          Spinner spinner = this.mTabSpinner;
          if (spinner != null) {
              ((TabAdapter) spinner.getAdapter()).notifyDataSetChanged();
          }
          if (this.mAllowCollapse) {
              requestLayout();
          }
      }
  
      public void setAllowCollapse(boolean allowCollapse) {
          this.mAllowCollapse = allowCollapse;
      }
  
      public void setContentHeight(int contentHeight) {
          this.mContentHeight = contentHeight;
          requestLayout();
      }
  
      public void setTabSelected(int position) {
          this.mSelectedTabIndex = position;
          int childCount = this.mTabLayout.getChildCount();
          int i = 0;
          while (i < childCount) {
              View childAt = this.mTabLayout.getChildAt(i);
              boolean z = i == position;
              childAt.setSelected(z);
              if (z) {
                  animateToTab(position);
              }
              i++;
          }
          Spinner spinner = this.mTabSpinner;
          if (spinner != null && position >= 0) {
              spinner.setSelection(position);
          }
      }
  
      public void updateTab(int position) {
          ((TabView) this.mTabLayout.getChildAt(position)).update();
          Spinner spinner = this.mTabSpinner;
          if (spinner != null) {
              ((TabAdapter) spinner.getAdapter()).notifyDataSetChanged();
          }
          if (this.mAllowCollapse) {
              requestLayout();
          }
      }
  }
  