package androidx.appcompat.widget; import android.content.Context; import android.content.res.TypedArray; import android.util.AttributeSet; import android.view.View; import android.widget.LinearLayout; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RestrictTo; import androidx.appcompat.R; import androidx.core.view.ViewCompat; @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public class ButtonBarLayout extends LinearLayout { private static final int PEEK_BUTTON_DP = 16; private boolean mAllowStacking; private int mLastWidthSize = -1; private int mMinimumHeight = 0; public ButtonBarLayout(@NonNull Context context, @Nullable AttributeSet attributeSet) { super(context, attributeSet); int[] iArr = R.styleable.ButtonBarLayout; TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, iArr); ViewCompat.saveAttributeDataForStyleable(this, context, iArr, attributeSet, obtainStyledAttributes, 0, 0); this.mAllowStacking = obtainStyledAttributes.getBoolean(R.styleable.ButtonBarLayout_allowStacking, true); obtainStyledAttributes.recycle(); } private int getNextVisibleChildIndex(int i) { int childCount = getChildCount(); while (i < childCount) { if (getChildAt(i).getVisibility() == 0) { return i; } i++; } return -1; } private boolean isStacked() { return getOrientation() == 1; } private void setStacked(boolean z2) { setOrientation(z2 ? 1 : 0); setGravity(z2 ? 5 : 80); View findViewById = findViewById(R.id.spacer); if (findViewById != null) { findViewById.setVisibility(z2 ? 8 : 4); } for (int childCount = getChildCount() - 2; childCount >= 0; childCount--) { bringChildToFront(getChildAt(childCount)); } } @Override // android.view.View public int getMinimumHeight() { return Math.max(this.mMinimumHeight, super.getMinimumHeight()); } @Override // android.widget.LinearLayout, android.view.View public void onMeasure(int i, int i2) { boolean z2; int i3; int size = View.MeasureSpec.getSize(i); int i4 = 0; if (this.mAllowStacking) { if (size > this.mLastWidthSize && isStacked()) { setStacked(false); } this.mLastWidthSize = size; } if (isStacked() || View.MeasureSpec.getMode(i) != 1073741824) { i3 = i; z2 = false; } else { i3 = View.MeasureSpec.makeMeasureSpec(size, Integer.MIN_VALUE); z2 = true; } super.onMeasure(i3, i2); if (this.mAllowStacking && !isStacked()) { if ((getMeasuredWidthAndState() & ViewCompat.MEASURED_STATE_MASK) == 16777216) { setStacked(true); z2 = true; } } if (z2) { super.onMeasure(i, i2); } int nextVisibleChildIndex = getNextVisibleChildIndex(0); if (nextVisibleChildIndex >= 0) { View childAt = getChildAt(nextVisibleChildIndex); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) childAt.getLayoutParams(); int measuredHeight = childAt.getMeasuredHeight() + getPaddingTop() + layoutParams.topMargin + layoutParams.bottomMargin + 0; if (isStacked()) { int nextVisibleChildIndex2 = getNextVisibleChildIndex(nextVisibleChildIndex + 1); i4 = nextVisibleChildIndex2 >= 0 ? getChildAt(nextVisibleChildIndex2).getPaddingTop() + ((int) (getResources().getDisplayMetrics().density * 16.0f)) + measuredHeight : measuredHeight; } else { i4 = getPaddingBottom() + measuredHeight; } } if (ViewCompat.getMinimumHeight(this) != i4) { setMinimumHeight(i4); } } public void setAllowStacking(boolean z2) { if (this.mAllowStacking != z2) { this.mAllowStacking = z2; if (!z2 && getOrientation() == 1) { setStacked(false); } requestLayout(); } } }