323 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			323 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package androidx.appcompat.widget;
 | |
| 
 | |
| import android.content.Context;
 | |
| import android.content.res.TypedArray;
 | |
| import android.graphics.drawable.Drawable;
 | |
| import android.util.AttributeSet;
 | |
| import android.view.ActionMode;
 | |
| import android.view.MotionEvent;
 | |
| import android.view.View;
 | |
| import android.view.ViewGroup;
 | |
| import android.widget.FrameLayout;
 | |
| import androidx.appcompat.R;
 | |
| import androidx.core.view.ViewCompat;
 | |
| 
 | |
| /* loaded from: classes.dex */
 | |
| public class ActionBarContainer extends FrameLayout {
 | |
|     private View mActionBarView;
 | |
|     Drawable mBackground;
 | |
|     private View mContextView;
 | |
|     private int mHeight;
 | |
|     boolean mIsSplit;
 | |
|     boolean mIsStacked;
 | |
|     private boolean mIsTransitioning;
 | |
|     Drawable mSplitBackground;
 | |
|     Drawable mStackedBackground;
 | |
|     private View mTabContainer;
 | |
| 
 | |
|     public View getTabContainer() {
 | |
|         return this.mTabContainer;
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.ViewGroup, android.view.ViewParent
 | |
|     public ActionMode startActionModeForChild(View view, ActionMode.Callback callback) {
 | |
|         return null;
 | |
|     }
 | |
| 
 | |
|     public ActionBarContainer(Context context) {
 | |
|         this(context, null);
 | |
|     }
 | |
| 
 | |
|     public ActionBarContainer(Context context, AttributeSet attributeSet) {
 | |
|         super(context, attributeSet);
 | |
|         ViewCompat.setBackground(this, new ActionBarBackgroundDrawable(this));
 | |
|         TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.ActionBar);
 | |
|         this.mBackground = obtainStyledAttributes.getDrawable(R.styleable.ActionBar_background);
 | |
|         this.mStackedBackground = obtainStyledAttributes.getDrawable(R.styleable.ActionBar_backgroundStacked);
 | |
|         this.mHeight = obtainStyledAttributes.getDimensionPixelSize(R.styleable.ActionBar_height, -1);
 | |
|         boolean z = true;
 | |
|         if (getId() == R.id.split_action_bar) {
 | |
|             this.mIsSplit = true;
 | |
|             this.mSplitBackground = obtainStyledAttributes.getDrawable(R.styleable.ActionBar_backgroundSplit);
 | |
|         }
 | |
|         obtainStyledAttributes.recycle();
 | |
|         if (!this.mIsSplit ? this.mBackground != null || this.mStackedBackground != null : this.mSplitBackground != null) {
 | |
|             z = false;
 | |
|         }
 | |
|         setWillNotDraw(z);
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     public void onFinishInflate() {
 | |
|         super.onFinishInflate();
 | |
|         this.mActionBarView = findViewById(R.id.action_bar);
 | |
|         this.mContextView = findViewById(R.id.action_context_bar);
 | |
|     }
 | |
| 
 | |
|     public void setPrimaryBackground(Drawable drawable) {
 | |
|         Drawable drawable2 = this.mBackground;
 | |
|         if (drawable2 != null) {
 | |
|             drawable2.setCallback(null);
 | |
|             unscheduleDrawable(this.mBackground);
 | |
|         }
 | |
|         this.mBackground = drawable;
 | |
|         if (drawable != null) {
 | |
|             drawable.setCallback(this);
 | |
|             View view = this.mActionBarView;
 | |
|             if (view != null) {
 | |
|                 this.mBackground.setBounds(view.getLeft(), this.mActionBarView.getTop(), this.mActionBarView.getRight(), this.mActionBarView.getBottom());
 | |
|             }
 | |
|         }
 | |
|         boolean z = true;
 | |
|         if (!this.mIsSplit ? this.mBackground != null || this.mStackedBackground != null : this.mSplitBackground != null) {
 | |
|             z = false;
 | |
|         }
 | |
|         setWillNotDraw(z);
 | |
|         invalidate();
 | |
|         Api21Impl.invalidateOutline(this);
 | |
|     }
 | |
| 
 | |
|     public void setStackedBackground(Drawable drawable) {
 | |
|         Drawable drawable2;
 | |
|         Drawable drawable3 = this.mStackedBackground;
 | |
|         if (drawable3 != null) {
 | |
|             drawable3.setCallback(null);
 | |
|             unscheduleDrawable(this.mStackedBackground);
 | |
|         }
 | |
|         this.mStackedBackground = drawable;
 | |
|         if (drawable != null) {
 | |
|             drawable.setCallback(this);
 | |
|             if (this.mIsStacked && (drawable2 = this.mStackedBackground) != null) {
 | |
|                 drawable2.setBounds(this.mTabContainer.getLeft(), this.mTabContainer.getTop(), this.mTabContainer.getRight(), this.mTabContainer.getBottom());
 | |
|             }
 | |
|         }
 | |
|         boolean z = true;
 | |
|         if (!this.mIsSplit ? this.mBackground != null || this.mStackedBackground != null : this.mSplitBackground != null) {
 | |
|             z = false;
 | |
|         }
 | |
|         setWillNotDraw(z);
 | |
|         invalidate();
 | |
|         Api21Impl.invalidateOutline(this);
 | |
|     }
 | |
| 
 | |
|     public void setSplitBackground(Drawable drawable) {
 | |
|         Drawable drawable2;
 | |
|         Drawable drawable3 = this.mSplitBackground;
 | |
|         if (drawable3 != null) {
 | |
|             drawable3.setCallback(null);
 | |
|             unscheduleDrawable(this.mSplitBackground);
 | |
|         }
 | |
|         this.mSplitBackground = drawable;
 | |
|         boolean z = false;
 | |
|         if (drawable != null) {
 | |
|             drawable.setCallback(this);
 | |
|             if (this.mIsSplit && (drawable2 = this.mSplitBackground) != null) {
 | |
|                 drawable2.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
 | |
|             }
 | |
|         }
 | |
|         if (!this.mIsSplit ? !(this.mBackground != null || this.mStackedBackground != null) : this.mSplitBackground == null) {
 | |
|             z = true;
 | |
|         }
 | |
|         setWillNotDraw(z);
 | |
|         invalidate();
 | |
|         Api21Impl.invalidateOutline(this);
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     public void setVisibility(int i) {
 | |
|         super.setVisibility(i);
 | |
|         boolean z = i == 0;
 | |
|         Drawable drawable = this.mBackground;
 | |
|         if (drawable != null) {
 | |
|             drawable.setVisible(z, false);
 | |
|         }
 | |
|         Drawable drawable2 = this.mStackedBackground;
 | |
|         if (drawable2 != null) {
 | |
|             drawable2.setVisible(z, false);
 | |
|         }
 | |
|         Drawable drawable3 = this.mSplitBackground;
 | |
|         if (drawable3 != null) {
 | |
|             drawable3.setVisible(z, false);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     protected boolean verifyDrawable(Drawable drawable) {
 | |
|         return (drawable == this.mBackground && !this.mIsSplit) || (drawable == this.mStackedBackground && this.mIsStacked) || ((drawable == this.mSplitBackground && this.mIsSplit) || super.verifyDrawable(drawable));
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.ViewGroup, android.view.View
 | |
|     protected void drawableStateChanged() {
 | |
|         super.drawableStateChanged();
 | |
|         Drawable drawable = this.mBackground;
 | |
|         if (drawable != null && drawable.isStateful()) {
 | |
|             this.mBackground.setState(getDrawableState());
 | |
|         }
 | |
|         Drawable drawable2 = this.mStackedBackground;
 | |
|         if (drawable2 != null && drawable2.isStateful()) {
 | |
|             this.mStackedBackground.setState(getDrawableState());
 | |
|         }
 | |
|         Drawable drawable3 = this.mSplitBackground;
 | |
|         if (drawable3 == null || !drawable3.isStateful()) {
 | |
|             return;
 | |
|         }
 | |
|         this.mSplitBackground.setState(getDrawableState());
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.ViewGroup, android.view.View
 | |
|     public void jumpDrawablesToCurrentState() {
 | |
|         super.jumpDrawablesToCurrentState();
 | |
|         Drawable drawable = this.mBackground;
 | |
|         if (drawable != null) {
 | |
|             drawable.jumpToCurrentState();
 | |
|         }
 | |
|         Drawable drawable2 = this.mStackedBackground;
 | |
|         if (drawable2 != null) {
 | |
|             drawable2.jumpToCurrentState();
 | |
|         }
 | |
|         Drawable drawable3 = this.mSplitBackground;
 | |
|         if (drawable3 != null) {
 | |
|             drawable3.jumpToCurrentState();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public void setTransitioning(boolean z) {
 | |
|         this.mIsTransitioning = z;
 | |
|         setDescendantFocusability(z ? 393216 : 262144);
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.ViewGroup
 | |
|     public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
 | |
|         return this.mIsTransitioning || super.onInterceptTouchEvent(motionEvent);
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     public boolean onTouchEvent(MotionEvent motionEvent) {
 | |
|         super.onTouchEvent(motionEvent);
 | |
|         return true;
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.View
 | |
|     public boolean onHoverEvent(MotionEvent motionEvent) {
 | |
|         super.onHoverEvent(motionEvent);
 | |
|         return true;
 | |
|     }
 | |
| 
 | |
|     public void setTabContainer(ScrollingTabContainerView scrollingTabContainerView) {
 | |
|         View view = this.mTabContainer;
 | |
|         if (view != null) {
 | |
|             removeView(view);
 | |
|         }
 | |
|         this.mTabContainer = scrollingTabContainerView;
 | |
|         if (scrollingTabContainerView != null) {
 | |
|             addView(scrollingTabContainerView);
 | |
|             ViewGroup.LayoutParams layoutParams = scrollingTabContainerView.getLayoutParams();
 | |
|             layoutParams.width = -1;
 | |
|             layoutParams.height = -2;
 | |
|             scrollingTabContainerView.setAllowCollapse(false);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     @Override // android.view.ViewGroup, android.view.ViewParent
 | |
|     public ActionMode startActionModeForChild(View view, ActionMode.Callback callback, int i) {
 | |
|         if (i != 0) {
 | |
|             return super.startActionModeForChild(view, callback, i);
 | |
|         }
 | |
|         return null;
 | |
|     }
 | |
| 
 | |
|     private boolean isCollapsed(View view) {
 | |
|         return view == null || view.getVisibility() == 8 || view.getMeasuredHeight() == 0;
 | |
|     }
 | |
| 
 | |
|     private int getMeasuredHeightWithMargins(View view) {
 | |
|         FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
 | |
|         return view.getMeasuredHeight() + layoutParams.topMargin + layoutParams.bottomMargin;
 | |
|     }
 | |
| 
 | |
|     @Override // android.widget.FrameLayout, android.view.View
 | |
|     public void onMeasure(int i, int i2) {
 | |
|         int measuredHeightWithMargins;
 | |
|         int i3;
 | |
|         if (this.mActionBarView == null && View.MeasureSpec.getMode(i2) == Integer.MIN_VALUE && (i3 = this.mHeight) >= 0) {
 | |
|             i2 = View.MeasureSpec.makeMeasureSpec(Math.min(i3, View.MeasureSpec.getSize(i2)), Integer.MIN_VALUE);
 | |
|         }
 | |
|         super.onMeasure(i, i2);
 | |
|         if (this.mActionBarView == null) {
 | |
|             return;
 | |
|         }
 | |
|         int mode = View.MeasureSpec.getMode(i2);
 | |
|         View view = this.mTabContainer;
 | |
|         if (view == null || view.getVisibility() == 8 || mode == 1073741824) {
 | |
|             return;
 | |
|         }
 | |
|         if (!isCollapsed(this.mActionBarView)) {
 | |
|             measuredHeightWithMargins = getMeasuredHeightWithMargins(this.mActionBarView);
 | |
|         } else {
 | |
|             measuredHeightWithMargins = !isCollapsed(this.mContextView) ? getMeasuredHeightWithMargins(this.mContextView) : 0;
 | |
|         }
 | |
|         setMeasuredDimension(getMeasuredWidth(), Math.min(measuredHeightWithMargins + getMeasuredHeightWithMargins(this.mTabContainer), mode == Integer.MIN_VALUE ? View.MeasureSpec.getSize(i2) : Integer.MAX_VALUE));
 | |
|     }
 | |
| 
 | |
|     @Override // android.widget.FrameLayout, android.view.ViewGroup, android.view.View
 | |
|     public void onLayout(boolean z, int i, int i2, int i3, int i4) {
 | |
|         Drawable drawable;
 | |
|         super.onLayout(z, i, i2, i3, i4);
 | |
|         View view = this.mTabContainer;
 | |
|         boolean z2 = true;
 | |
|         boolean z3 = (view == null || view.getVisibility() == 8) ? false : true;
 | |
|         if (view != null && view.getVisibility() != 8) {
 | |
|             int measuredHeight = getMeasuredHeight();
 | |
|             FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) view.getLayoutParams();
 | |
|             view.layout(i, (measuredHeight - view.getMeasuredHeight()) - layoutParams.bottomMargin, i3, measuredHeight - layoutParams.bottomMargin);
 | |
|         }
 | |
|         if (this.mIsSplit) {
 | |
|             Drawable drawable2 = this.mSplitBackground;
 | |
|             if (drawable2 == null) {
 | |
|                 return;
 | |
|             } else {
 | |
|                 drawable2.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
 | |
|             }
 | |
|         } else {
 | |
|             if (this.mBackground == null) {
 | |
|                 z2 = false;
 | |
|             } else if (this.mActionBarView.getVisibility() == 0) {
 | |
|                 this.mBackground.setBounds(this.mActionBarView.getLeft(), this.mActionBarView.getTop(), this.mActionBarView.getRight(), this.mActionBarView.getBottom());
 | |
|             } else {
 | |
|                 View view2 = this.mContextView;
 | |
|                 if (view2 != null && view2.getVisibility() == 0) {
 | |
|                     this.mBackground.setBounds(this.mContextView.getLeft(), this.mContextView.getTop(), this.mContextView.getRight(), this.mContextView.getBottom());
 | |
|                 } else {
 | |
|                     this.mBackground.setBounds(0, 0, 0, 0);
 | |
|                 }
 | |
|             }
 | |
|             this.mIsStacked = z3;
 | |
|             if (z3 && (drawable = this.mStackedBackground) != null) {
 | |
|                 drawable.setBounds(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
 | |
|             } else if (!z2) {
 | |
|                 return;
 | |
|             }
 | |
|         }
 | |
|         invalidate();
 | |
|     }
 | |
| 
 | |
|     private static class Api21Impl {
 | |
|         private Api21Impl() {
 | |
|         }
 | |
| 
 | |
|         public static void invalidateOutline(ActionBarContainer actionBarContainer) {
 | |
|             actionBarContainer.invalidateOutline();
 | |
|         }
 | |
|     }
 | |
| }
 |