content: package androidx.appcompat.widget;
  
  import android.content.Context;
  import android.graphics.drawable.Drawable;
  import android.text.TextUtils;
  import android.util.AttributeSet;
  import android.view.LayoutInflater;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  import androidx.appcompat.R;
  import androidx.appcompat.view.ActionMode;
  import androidx.appcompat.view.menu.MenuBuilder;
  import androidx.constraintlayout.core.widgets.analyzer.BasicMeasure;
  import androidx.core.view.ViewCompat;
  import androidx.core.view.ViewPropertyAnimatorCompat;
  
  public class ActionBarContextView extends AbsActionBarView {
      private View mClose;
      private View mCloseButton;
      private int mCloseItemLayout;
      private View mCustomView;
      private CharSequence mSubtitle;
      private int mSubtitleStyleRes;
      private TextView mSubtitleView;
      private CharSequence mTitle;
      private LinearLayout mTitleLayout;
      private boolean mTitleOptional;
      private int mTitleStyleRes;
      private TextView mTitleView;
  
      public ActionBarContextView(Context context) {
          this(context, (AttributeSet) null);
      }
  
      public ActionBarContextView(Context context, AttributeSet attrs) {
          this(context, attrs, R.attr.actionModeStyle);
      }
  
      public ActionBarContextView(Context context, AttributeSet attrs, int defStyle) {
          super(context, attrs, defStyle);
          TintTypedArray obtainStyledAttributes = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.ActionMode, defStyle, 0);
          ViewCompat.setBackground(this, obtainStyledAttributes.getDrawable(R.styleable.ActionMode_background));
          this.mTitleStyleRes = obtainStyledAttributes.getResourceId(R.styleable.ActionMode_titleTextStyle, 0);
          this.mSubtitleStyleRes = obtainStyledAttributes.getResourceId(R.styleable.ActionMode_subtitleTextStyle, 0);
          this.mContentHeight = obtainStyledAttributes.getLayoutDimension(R.styleable.ActionMode_height, 0);
          this.mCloseItemLayout = obtainStyledAttributes.getResourceId(R.styleable.ActionMode_closeItemLayout, R.layout.abc_action_mode_close_item_material);
          obtainStyledAttributes.recycle();
      }
  
      private void initTitle() {
          if (this.mTitleLayout == null) {
              LayoutInflater.from(getContext()).inflate(R.layout.abc_action_bar_title_item, this);
              LinearLayout linearLayout = (LinearLayout) getChildAt(getChildCount() - 1);
              this.mTitleLayout = linearLayout;
              this.mTitleView = (TextView) linearLayout.findViewById(R.id.action_bar_title);
              this.mSubtitleView = (TextView) this.mTitleLayout.findViewById(R.id.action_bar_subtitle);
              if (this.mTitleStyleRes != 0) {
                  this.mTitleView.setTextAppearance(getContext(), this.mTitleStyleRes);
              }
              if (this.mSubtitleStyleRes != 0) {
                  this.mSubtitleView.setTextAppearance(getContext(), this.mSubtitleStyleRes);
              }
          }
          this.mTitleView.setText(this.mTitle);
          this.mSubtitleView.setText(this.mSubtitle);
          boolean z = !TextUtils.isEmpty(this.mTitle);
          boolean z2 = !TextUtils.isEmpty(this.mSubtitle);
          int i = 0;
          this.mSubtitleView.setVisibility(z2 ? 0 : 8);
          LinearLayout linearLayout2 = this.mTitleLayout;
          if (!z && !z2) {
              i = 8;
          }
          linearLayout2.setVisibility(i);
          if (this.mTitleLayout.getParent() == null) {
              addView(this.mTitleLayout);
          }
      }
  
      public /* bridge */ /* synthetic */ void animateToVisibility(int i) {
          super.animateToVisibility(i);
      }
  
      public /* bridge */ /* synthetic */ boolean canShowOverflowMenu() {
          return super.canShowOverflowMenu();
      }
  
      public void closeMode() {
          if (this.mClose == null) {
              killMode();
          }
      }
  
      public /* bridge */ /* synthetic */ void dismissPopupMenus() {
          super.dismissPopupMenus();
      }
  
      /* access modifiers changed from: protected */
      public ViewGroup.LayoutParams generateDefaultLayoutParams() {
          return new ViewGroup.MarginLayoutParams(-1, -2);
      }
  
      public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
          return new ViewGroup.MarginLayoutParams(getContext(), attrs);
      }
  
      public /* bridge */ /* synthetic */ int getAnimatedVisibility() {
          return super.getAnimatedVisibility();
      }
  
      public /* bridge */ /* synthetic */ int getContentHeight() {
          return super.getContentHeight();
      }
  
      public CharSequence getSubtitle() {
          return this.mSubtitle;
      }
  
      public CharSequence getTitle() {
          return this.mTitle;
      }
  
      public boolean hideOverflowMenu() {
          if (this.mActionMenuPresenter != null) {
              return this.mActionMenuPresenter.hideOverflowMenu();
          }
          return false;
      }
  
      public void initForMode(final ActionMode mode) {
          View view = this.mClose;
          if (view == null) {
              View inflate = LayoutInflater.from(getContext()).inflate(this.mCloseItemLayout, this, false);
              this.mClose = inflate;
              addView(inflate);
          } else if (view.getParent() == null) {
              addView(this.mClose);
          }
          View findViewById = this.mClose.findViewById(R.id.action_mode_close_button);
          this.mCloseButton = findViewById;
          findViewById.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  mode.finish();
              }
          });
          MenuBuilder menuBuilder = (MenuBuilder) mode.getMenu();
          if (this.mActionMenuPresenter != null) {
              this.mActionMenuPresenter.dismissPopupMenus();
          }
          this.mActionMenuPresenter = new ActionMenuPresenter(getContext());
          this.mActionMenuPresenter.setReserveOverflow(true);
          ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(-2, -1);
          menuBuilder.addMenuPresenter(this.mActionMenuPresenter, this.mPopupContext);
          this.mMenuView = (ActionMenuView) this.mActionMenuPresenter.getMenuView(this);
          ViewCompat.setBackground(this.mMenuView, (Drawable) null);
          addView(this.mMenuView, layoutParams);
      }
  
      public /* bridge */ /* synthetic */ boolean isOverflowMenuShowPending() {
          return super.isOverflowMenuShowPending();
      }
  
      public boolean isOverflowMenuShowing() {
          if (this.mActionMenuPresenter != null) {
              return this.mActionMenuPresenter.isOverflowMenuShowing();
          }
          return false;
      }
  
      public /* bridge */ /* synthetic */ boolean isOverflowReserved() {
          return super.isOverflowReserved();
      }
  
      public boolean isTitleOptional() {
          return this.mTitleOptional;
      }
  
      public void killMode() {
          removeAllViews();
          this.mCustomView = null;
          this.mMenuView = null;
          this.mActionMenuPresenter = null;
          View view = this.mCloseButton;
          if (view != null) {
              view.setOnClickListener((View.OnClickListener) null);
          }
      }
  
      public void onDetachedFromWindow() {
          super.onDetachedFromWindow();
          if (this.mActionMenuPresenter != null) {
              this.mActionMenuPresenter.hideOverflowMenu();
              this.mActionMenuPresenter.hideSubMenus();
          }
      }
  
      public /* bridge */ /* synthetic */ boolean onHoverEvent(MotionEvent motionEvent) {
          return super.onHoverEvent(motionEvent);
      }
  
      /* access modifiers changed from: protected */
      public void onLayout(boolean changed, int l, int t, int r, int b) {
          int i;
          boolean isLayoutRtl = ViewUtils.isLayoutRtl(this);
          int paddingRight = isLayoutRtl ? (r - l) - getPaddingRight() : getPaddingLeft();
          int paddingTop = getPaddingTop();
          int paddingTop2 = ((b - t) - getPaddingTop()) - getPaddingBottom();
          View view = this.mClose;
          if (view == null || view.getVisibility() == 8) {
              i = paddingRight;
          } else {
              ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) this.mClose.getLayoutParams();
              int i2 = isLayoutRtl ? marginLayoutParams.rightMargin : marginLayoutParams.leftMargin;
              int i3 = isLayoutRtl ? marginLayoutParams.leftMargin : marginLayoutParams.rightMargin;
              int next = next(paddingRight, i2, isLayoutRtl);
              i = next(next + positionChild(this.mClose, next, paddingTop, paddingTop2, isLayoutRtl), i3, isLayoutRtl);
          }
          LinearLayout linearLayout = this.mTitleLayout;
          if (!(linearLayout == null || this.mCustomView != null || linearLayout.getVisibility() == 8)) {
              i += positionChild(this.mTitleLayout, i, paddingTop, paddingTop2, isLayoutRtl);
          }
          View view2 = this.mCustomView;
          if (view2 != null) {
              int positionChild = i + positionChild(view2, i, paddingTop, paddingTop2, isLayoutRtl);
          }
          int paddingLeft = isLayoutRtl ? getPaddingLeft() : (r - l) - getPaddingRight();
          if (this.mMenuView != null) {
              int positionChild2 = paddingLeft + positionChild(this.mMenuView, paddingLeft, paddingTop, paddingTop2, !isLayoutRtl);
          }
      }
  
      /* access modifiers changed from: protected */
      public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          int mode = View.MeasureSpec.getMode(widthMeasureSpec);
          int i = BasicMeasure.EXACTLY;
          if (mode != 1073741824) {
              int i2 = mode;
              throw new IllegalStateException(getClass().getSimpleName() + " can only be used with android:layout_width=\"match_parent\" (or fill_parent)");
          } else if (View.MeasureSpec.getMode(heightMeasureSpec) != 0) {
              int size = View.MeasureSpec.getSize(widthMeasureSpec);
              int size2 = this.mContentHeight > 0 ? this.mContentHeight : View.MeasureSpec.getSize(heightMeasureSpec);
              int paddingTop = getPaddingTop() + getPaddingBottom();
              int paddingLeft = (size - getPaddingLeft()) - getPaddingRight();
              int i3 = size2 - paddingTop;
              int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(i3, Integer.MIN_VALUE);
              View view = this.mClose;
              int i4 = 0;
              if (view != null) {
                  int measureChildView = measureChildView(view, paddingLeft, makeMeasureSpec, 0);
                  ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) this.mClose.getLayoutParams();
                  paddingLeft = measureChildView - (marginLayoutParams.leftMargin + marginLayoutParams.rightMargin);
              }
              if (this.mMenuView != null && this.mMenuView.getParent() == this) {
                  paddingLeft = measureChildView(this.mMenuView, paddingLeft, makeMeasureSpec, 0);
              }
              LinearLayout linearLayout = this.mTitleLayout;
              if (linearLayout != null && this.mCustomView == null) {
                  if (this.mTitleOptional) {
                      this.mTitleLayout.measure(View.MeasureSpec.makeMeasureSpec(0, 0), makeMeasureSpec);
                      int measuredWidth = this.mTitleLayout.getMeasuredWidth();
                      boolean z = measuredWidth <= paddingLeft;
                      if (z) {
                          paddingLeft -= measuredWidth;
                      }
                      LinearLayout linearLayout2 = this.mTitleLayout;
                      if (!z) {
                          i4 = 8;
                      }
                      linearLayout2.setVisibility(i4);
                  } else {
                      paddingLeft = measureChildView(linearLayout, paddingLeft, makeMeasureSpec, 0);
                  }
              }
              View view2 = this.mCustomView;
              if (view2 != null) {
                  ViewGroup.LayoutParams layoutParams = view2.getLayoutParams();
                  int i5 = layoutParams.width != -2 ? 1073741824 : Integer.MIN_VALUE;
                  int min = layoutParams.width >= 0 ? Math.min(layoutParams.width, paddingLeft) : paddingLeft;
                  if (layoutParams.height == -2) {
                      i = Integer.MIN_VALUE;
                  }
                  int i6 = mode;
                  this.mCustomView.measure(View.MeasureSpec.makeMeasureSpec(min, i5), View.MeasureSpec.makeMeasureSpec(layoutParams.height >= 0 ? Math.min(layoutParams.height, i3) : i3, i));
              } else {
                  int i7 = mode;
              }
              if (this.mContentHeight <= 0) {
                  int i8 = 0;
                  int childCount = getChildCount();
                  for (int i9 = 0; i9 < childCount; i9++) {
                      int measuredHeight = getChildAt(i9).getMeasuredHeight() + paddingTop;
                      if (measuredHeight > i8) {
                          i8 = measuredHeight;
                      }
                  }
                  setMeasuredDimension(size, i8);
                  return;
              }
              setMeasuredDimension(size, size2);
          } else {
              int i10 = mode;
              throw new IllegalStateException(getClass().getSimpleName() + " can only be used with android:layout_height=\"wrap_content\"");
          }
      }
  
      public /* bridge */ /* synthetic */ boolean onTouchEvent(MotionEvent motionEvent) {
          return super.onTouchEvent(motionEvent);
      }
  
      public /* bridge */ /* synthetic */ void postShowOverflowMenu() {
          super.postShowOverflowMenu();
      }
  
      public void setContentHeight(int height) {
          this.mContentHeight = height;
      }
  
      public void setCustomView(View view) {
          LinearLayout linearLayout;
          View view2 = this.mCustomView;
          if (view2 != null) {
              removeView(view2);
          }
          this.mCustomView = view;
          if (!(view == null || (linearLayout = this.mTitleLayout) == null)) {
              removeView(linearLayout);
              this.mTitleLayout = null;
          }
          if (view != null) {
              addView(view);
          }
          requestLayout();
      }
  
      public void setSubtitle(CharSequence subtitle) {
          this.mSubtitle = subtitle;
          initTitle();
      }
  
      public void setTitle(CharSequence title) {
          this.mTitle = title;
          initTitle();
          ViewCompat.setAccessibilityPaneTitle(this, title);
      }
  
      public void setTitleOptional(boolean titleOptional) {
          if (titleOptional != this.mTitleOptional) {
              requestLayout();
          }
          this.mTitleOptional = titleOptional;
      }
  
      public /* bridge */ /* synthetic */ void setVisibility(int i) {
          super.setVisibility(i);
      }
  
      public /* bridge */ /* synthetic */ ViewPropertyAnimatorCompat setupAnimatorToVisibility(int i, long j) {
          return super.setupAnimatorToVisibility(i, j);
      }
  
      public boolean shouldDelayChildPressedState() {
          return false;
      }
  
      public boolean showOverflowMenu() {
          if (this.mActionMenuPresenter != null) {
              return this.mActionMenuPresenter.showOverflowMenu();
          }
          return false;
      }
  }
  