mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-14 01:47:17 +01:00
124 lines
4.6 KiB
Java
124 lines
4.6 KiB
Java
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.GravityCompat;
|
|
import androidx.core.view.ViewCompat;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
/* loaded from: classes.dex */
|
|
public class ButtonBarLayout extends LinearLayout {
|
|
private static final int PEEK_BUTTON_DP = 16;
|
|
private boolean mAllowStacking;
|
|
private int mLastWidthSize;
|
|
private boolean mStacked;
|
|
|
|
public ButtonBarLayout(@NonNull Context context, @Nullable AttributeSet attributeSet) {
|
|
super(context, attributeSet);
|
|
this.mLastWidthSize = -1;
|
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.ButtonBarLayout);
|
|
ViewCompat.saveAttributeDataForStyleable(this, context, R.styleable.ButtonBarLayout, attributeSet, obtainStyledAttributes, 0, 0);
|
|
this.mAllowStacking = obtainStyledAttributes.getBoolean(R.styleable.ButtonBarLayout_allowStacking, true);
|
|
obtainStyledAttributes.recycle();
|
|
if (getOrientation() == 1) {
|
|
setStacked(this.mAllowStacking);
|
|
}
|
|
}
|
|
|
|
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 this.mStacked;
|
|
}
|
|
|
|
private void setStacked(boolean z) {
|
|
if (this.mStacked != z) {
|
|
if (!z || this.mAllowStacking) {
|
|
this.mStacked = z;
|
|
setOrientation(z ? 1 : 0);
|
|
setGravity(z ? GravityCompat.END : 80);
|
|
View findViewById = findViewById(R.id.spacer);
|
|
if (findViewById != null) {
|
|
findViewById.setVisibility(z ? 8 : 4);
|
|
}
|
|
for (int childCount = getChildCount() - 2; childCount >= 0; childCount--) {
|
|
bringChildToFront(getChildAt(childCount));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // android.widget.LinearLayout, android.view.View
|
|
public void onMeasure(int i, int i2) {
|
|
int i3;
|
|
boolean z;
|
|
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;
|
|
z = false;
|
|
} else {
|
|
i3 = View.MeasureSpec.makeMeasureSpec(size, Integer.MIN_VALUE);
|
|
z = true;
|
|
}
|
|
super.onMeasure(i3, i2);
|
|
if (this.mAllowStacking && !isStacked() && (getMeasuredWidthAndState() & ViewCompat.MEASURED_STATE_MASK) == 16777216) {
|
|
setStacked(true);
|
|
z = true;
|
|
}
|
|
if (z) {
|
|
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;
|
|
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);
|
|
if (i2 == 0) {
|
|
super.onMeasure(i, i2);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void setAllowStacking(boolean z) {
|
|
if (this.mAllowStacking != z) {
|
|
this.mAllowStacking = z;
|
|
if (!z && isStacked()) {
|
|
setStacked(false);
|
|
}
|
|
requestLayout();
|
|
}
|
|
}
|
|
}
|