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.core.view.s1;
import d.f;
import d.j;
import java.util.WeakHashMap;

/* JADX INFO: loaded from: classes.dex */
@RestrictTo({RestrictTo.Scope.f557c})
public class ButtonBarLayout extends LinearLayout {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public boolean f698a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public boolean f699b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f700c;

    public ButtonBarLayout(@NonNull Context context, @Nullable AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f700c = -1;
        int[] iArr = j.ButtonBarLayout;
        TypedArray typedArrayObtainStyledAttributes = context.obtainStyledAttributes(attributeSet, iArr);
        s1.saveAttributeDataForStyleable(this, context, iArr, attributeSet, typedArrayObtainStyledAttributes, 0, 0);
        this.f698a = typedArrayObtainStyledAttributes.getBoolean(j.ButtonBarLayout_allowStacking, true);
        typedArrayObtainStyledAttributes.recycle();
        if (getOrientation() == 1) {
            setStacked(this.f698a);
        }
    }

    private void setStacked(boolean z10) {
        if (this.f699b != z10) {
            if (!z10 || this.f698a) {
                this.f699b = z10;
                setOrientation(z10 ? 1 : 0);
                setGravity(z10 ? 8388613 : 80);
                View viewFindViewById = findViewById(f.spacer);
                if (viewFindViewById != null) {
                    viewFindViewById.setVisibility(z10 ? 8 : 4);
                }
                for (int childCount = getChildCount() - 2; childCount >= 0; childCount--) {
                    bringChildToFront(getChildAt(childCount));
                }
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:28:0x0054  */
    /* JADX WARN: Removed duplicated region for block: B:34:0x0065  */
    /* JADX WARN: Removed duplicated region for block: B:48:0x00c4  */
    /* JADX WARN: Removed duplicated region for block: B:52:0x0062 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:56:? A[RETURN, SYNTHETIC] */
    @Override // android.widget.LinearLayout, android.view.View
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void onMeasure(int i10, int i11) {
        int iMakeMeasureSpec;
        boolean z10;
        int childCount;
        int i12;
        int i13;
        int size = View.MeasureSpec.getSize(i10);
        int paddingBottom = 0;
        if (this.f698a) {
            if (size > this.f700c && this.f699b) {
                setStacked(false);
            }
            this.f700c = size;
        }
        if (this.f699b || View.MeasureSpec.getMode(i10) != 1073741824) {
            iMakeMeasureSpec = i10;
            z10 = false;
        } else {
            iMakeMeasureSpec = View.MeasureSpec.makeMeasureSpec(size, Integer.MIN_VALUE);
            z10 = true;
        }
        super.onMeasure(iMakeMeasureSpec, i11);
        if (!this.f698a || this.f699b || (getMeasuredWidthAndState() & (-16777216)) != 16777216) {
            if (z10) {
            }
            childCount = getChildCount();
            i12 = 0;
            while (true) {
                i13 = -1;
                if (i12 < childCount) {
                    i12 = -1;
                    break;
                } else if (getChildAt(i12).getVisibility() == 0) {
                    break;
                } else {
                    i12++;
                }
            }
            if (i12 >= 0) {
                View childAt = getChildAt(i12);
                LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) childAt.getLayoutParams();
                int measuredHeight = childAt.getMeasuredHeight() + getPaddingTop() + layoutParams.topMargin + layoutParams.bottomMargin;
                if (this.f699b) {
                    int i14 = i12 + 1;
                    int childCount2 = getChildCount();
                    while (true) {
                        if (i14 >= childCount2) {
                            break;
                        }
                        if (getChildAt(i14).getVisibility() == 0) {
                            i13 = i14;
                            break;
                        }
                        i14++;
                    }
                    paddingBottom = i13 >= 0 ? getChildAt(i13).getPaddingTop() + ((int) (getResources().getDisplayMetrics().density * 16.0f)) + measuredHeight : measuredHeight;
                } else {
                    paddingBottom = getPaddingBottom() + measuredHeight;
                }
            }
            WeakHashMap weakHashMap = s1.f1815a;
            if (getMinimumHeight() == paddingBottom) {
                setMinimumHeight(paddingBottom);
                if (i11 == 0) {
                    super.onMeasure(i10, i11);
                    return;
                }
                return;
            }
            return;
        }
        setStacked(true);
        super.onMeasure(i10, i11);
        childCount = getChildCount();
        i12 = 0;
        while (true) {
            i13 = -1;
            if (i12 < childCount) {
            }
            i12++;
        }
        if (i12 >= 0) {
        }
        WeakHashMap weakHashMap2 = s1.f1815a;
        if (getMinimumHeight() == paddingBottom) {
        }
    }

    public void setAllowStacking(boolean z10) {
        if (this.f698a != z10) {
            this.f698a = z10;
            if (!z10 && this.f699b) {
                setStacked(false);
            }
            requestLayout();
        }
    }
}
