118 lines
3.6 KiB
Java
118 lines
3.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.appcompat.R$id;
|
|
import androidx.appcompat.R$styleable;
|
|
import androidx.core.view.ViewCompat;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class ButtonBarLayout extends LinearLayout {
|
|
private boolean a;
|
|
private int b;
|
|
private int c;
|
|
|
|
public ButtonBarLayout(Context context, AttributeSet attributeSet) {
|
|
super(context, attributeSet);
|
|
this.b = -1;
|
|
this.c = 0;
|
|
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R$styleable.ButtonBarLayout);
|
|
this.a = obtainStyledAttributes.getBoolean(R$styleable.ButtonBarLayout_allowStacking, true);
|
|
obtainStyledAttributes.recycle();
|
|
}
|
|
|
|
private int a(int i) {
|
|
int childCount = getChildCount();
|
|
while (i < childCount) {
|
|
if (getChildAt(i).getVisibility() == 0) {
|
|
return i;
|
|
}
|
|
i++;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
private void setStacked(boolean z) {
|
|
setOrientation(z ? 1 : 0);
|
|
setGravity(z ? 5 : 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.view.View
|
|
public int getMinimumHeight() {
|
|
return Math.max(this.c, super.getMinimumHeight());
|
|
}
|
|
|
|
@Override // android.widget.LinearLayout, android.view.View
|
|
protected void onMeasure(int i, int i2) {
|
|
int i3;
|
|
boolean z;
|
|
int size = View.MeasureSpec.getSize(i);
|
|
int i4 = 0;
|
|
if (this.a) {
|
|
if (size > this.b && a()) {
|
|
setStacked(false);
|
|
}
|
|
this.b = size;
|
|
}
|
|
if (a() || 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.a && !a()) {
|
|
if ((getMeasuredWidthAndState() & (-16777216)) == 16777216) {
|
|
setStacked(true);
|
|
z = true;
|
|
}
|
|
}
|
|
if (z) {
|
|
super.onMeasure(i, i2);
|
|
}
|
|
int a = a(0);
|
|
if (a >= 0) {
|
|
View childAt = getChildAt(a);
|
|
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) childAt.getLayoutParams();
|
|
int paddingTop = getPaddingTop() + childAt.getMeasuredHeight() + layoutParams.topMargin + layoutParams.bottomMargin + 0;
|
|
if (a()) {
|
|
int a2 = a(a + 1);
|
|
if (a2 >= 0) {
|
|
paddingTop += getChildAt(a2).getPaddingTop() + ((int) (getResources().getDisplayMetrics().density * 16.0f));
|
|
}
|
|
i4 = paddingTop;
|
|
} else {
|
|
i4 = paddingTop + getPaddingBottom();
|
|
}
|
|
}
|
|
if (ViewCompat.l(this) != i4) {
|
|
setMinimumHeight(i4);
|
|
}
|
|
}
|
|
|
|
public void setAllowStacking(boolean z) {
|
|
if (this.a != z) {
|
|
this.a = z;
|
|
if (!this.a && getOrientation() == 1) {
|
|
setStacked(false);
|
|
}
|
|
requestLayout();
|
|
}
|
|
}
|
|
|
|
private boolean a() {
|
|
return getOrientation() == 1;
|
|
}
|
|
}
|