package androidx.appcompat.widget;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

/* JADX INFO: loaded from: classes.dex */
public class ActionBarContextView extends androidx.appcompat.widget.a {

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private CharSequence f609m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    private CharSequence f610n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    private View f611o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    private View f612p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    private View f613q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    private LinearLayout f614r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    private TextView f615s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    private TextView f616t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    private int f617u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    private int f618v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    private boolean f619w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    private int f620x;

    class a implements View.OnClickListener {

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        final /* synthetic */ androidx.appcompat.view.b f621e;

        a(ActionBarContextView actionBarContextView, androidx.appcompat.view.b bVar) {
            this.f621e = bVar;
        }

        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            this.f621e.c();
        }
    }

    public ActionBarContextView(Context context) {
        this(context, null);
    }

    private void i() {
        if (this.f614r == null) {
            LayoutInflater.from(getContext()).inflate(c.g.f3252a, this);
            LinearLayout linearLayout = (LinearLayout) getChildAt(getChildCount() - 1);
            this.f614r = linearLayout;
            this.f615s = (TextView) linearLayout.findViewById(c.f.f3230e);
            this.f616t = (TextView) this.f614r.findViewById(c.f.f3229d);
            if (this.f617u != 0) {
                this.f615s.setTextAppearance(getContext(), this.f617u);
            }
            if (this.f618v != 0) {
                this.f616t.setTextAppearance(getContext(), this.f618v);
            }
        }
        this.f615s.setText(this.f609m);
        this.f616t.setText(this.f610n);
        boolean z2 = !TextUtils.isEmpty(this.f609m);
        boolean z3 = !TextUtils.isEmpty(this.f610n);
        int i3 = 0;
        this.f616t.setVisibility(z3 ? 0 : 8);
        LinearLayout linearLayout2 = this.f614r;
        if (!z2 && !z3) {
            i3 = 8;
        }
        linearLayout2.setVisibility(i3);
        if (this.f614r.getParent() == null) {
            addView(this.f614r);
        }
    }

    public void g() {
        if (this.f611o == null) {
            k();
        }
    }

    @Override // android.view.ViewGroup
    protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
        return new ViewGroup.MarginLayoutParams(-1, -2);
    }

    @Override // android.view.ViewGroup
    public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attributeSet) {
        return new ViewGroup.MarginLayoutParams(getContext(), attributeSet);
    }

    @Override // androidx.appcompat.widget.a
    public /* bridge */ /* synthetic */ int getAnimatedVisibility() {
        return super.getAnimatedVisibility();
    }

    @Override // androidx.appcompat.widget.a
    public /* bridge */ /* synthetic */ int getContentHeight() {
        return super.getContentHeight();
    }

    public CharSequence getSubtitle() {
        return this.f610n;
    }

    public CharSequence getTitle() {
        return this.f609m;
    }

    public void h(androidx.appcompat.view.b bVar) {
        View view = this.f611o;
        if (view == null) {
            View viewInflate = LayoutInflater.from(getContext()).inflate(this.f620x, (ViewGroup) this, false);
            this.f611o = viewInflate;
            addView(viewInflate);
        } else if (view.getParent() == null) {
            addView(this.f611o);
        }
        View viewFindViewById = this.f611o.findViewById(c.f.f3234i);
        this.f612p = viewFindViewById;
        viewFindViewById.setOnClickListener(new a(this, bVar));
        androidx.appcompat.view.menu.g gVar = (androidx.appcompat.view.menu.g) bVar.e();
        c cVar = this.f767h;
        if (cVar != null) {
            cVar.y();
        }
        c cVar2 = new c(getContext());
        this.f767h = cVar2;
        cVar2.J(true);
        ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(-2, -1);
        gVar.c(this.f767h, this.f765f);
        ActionMenuView actionMenuView = (ActionMenuView) this.f767h.o(this);
        this.f766g = actionMenuView;
        androidx.core.view.y.v0(actionMenuView, null);
        addView(this.f766g, layoutParams);
    }

    public boolean j() {
        return this.f619w;
    }

    public void k() {
        removeAllViews();
        this.f613q = null;
        this.f766g = null;
        this.f767h = null;
        View view = this.f612p;
        if (view != null) {
            view.setOnClickListener(null);
        }
    }

    public boolean l() {
        c cVar = this.f767h;
        if (cVar != null) {
            return cVar.K();
        }
        return false;
    }

    @Override // android.view.ViewGroup, android.view.View
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        c cVar = this.f767h;
        if (cVar != null) {
            cVar.B();
            this.f767h.C();
        }
    }

    @Override // android.view.ViewGroup, android.view.View
    protected void onLayout(boolean z2, int i3, int i4, int i5, int i6) {
        boolean zB = j1.b(this);
        int paddingRight = zB ? (i5 - i3) - getPaddingRight() : getPaddingLeft();
        int paddingTop = getPaddingTop();
        int paddingTop2 = ((i6 - i4) - getPaddingTop()) - getPaddingBottom();
        View view = this.f611o;
        if (view != null && view.getVisibility() != 8) {
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) this.f611o.getLayoutParams();
            int i7 = zB ? marginLayoutParams.rightMargin : marginLayoutParams.leftMargin;
            int i8 = zB ? marginLayoutParams.leftMargin : marginLayoutParams.rightMargin;
            int iD = androidx.appcompat.widget.a.d(paddingRight, i7, zB);
            paddingRight = androidx.appcompat.widget.a.d(iD + e(this.f611o, iD, paddingTop, paddingTop2, zB), i8, zB);
        }
        int iE = paddingRight;
        LinearLayout linearLayout = this.f614r;
        if (linearLayout != null && this.f613q == null && linearLayout.getVisibility() != 8) {
            iE += e(this.f614r, iE, paddingTop, paddingTop2, zB);
        }
        int i9 = iE;
        View view2 = this.f613q;
        if (view2 != null) {
            e(view2, i9, paddingTop, paddingTop2, zB);
        }
        int paddingLeft = zB ? getPaddingLeft() : (i5 - i3) - getPaddingRight();
        ActionMenuView actionMenuView = this.f766g;
        if (actionMenuView != null) {
            e(actionMenuView, paddingLeft, paddingTop, paddingTop2, !zB);
        }
    }

    @Override // android.view.View
    protected void onMeasure(int i3, int i4) {
        if (View.MeasureSpec.getMode(i3) != 1073741824) {
            throw new IllegalStateException(getClass().getSimpleName() + " can only be used with android:layout_width=\"match_parent\" (or fill_parent)");
        }
        if (View.MeasureSpec.getMode(i4) == 0) {
            throw new IllegalStateException(getClass().getSimpleName() + " can only be used with android:layout_height=\"wrap_content\"");
        }
        int size = View.MeasureSpec.getSize(i3);
        int size2 = this.f768i;
        if (size2 <= 0) {
            size2 = View.MeasureSpec.getSize(i4);
        }
        int paddingTop = getPaddingTop() + getPaddingBottom();
        int paddingLeft = (size - getPaddingLeft()) - getPaddingRight();
        int iMin = size2 - paddingTop;
        int iMakeMeasureSpec = View.MeasureSpec.makeMeasureSpec(iMin, Integer.MIN_VALUE);
        View view = this.f611o;
        if (view != null) {
            int iC = c(view, paddingLeft, iMakeMeasureSpec, 0);
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) this.f611o.getLayoutParams();
            paddingLeft = iC - (marginLayoutParams.leftMargin + marginLayoutParams.rightMargin);
        }
        ActionMenuView actionMenuView = this.f766g;
        if (actionMenuView != null && actionMenuView.getParent() == this) {
            paddingLeft = c(this.f766g, paddingLeft, iMakeMeasureSpec, 0);
        }
        LinearLayout linearLayout = this.f614r;
        if (linearLayout != null && this.f613q == null) {
            if (this.f619w) {
                this.f614r.measure(View.MeasureSpec.makeMeasureSpec(0, 0), iMakeMeasureSpec);
                int measuredWidth = this.f614r.getMeasuredWidth();
                boolean z2 = measuredWidth <= paddingLeft;
                if (z2) {
                    paddingLeft -= measuredWidth;
                }
                this.f614r.setVisibility(z2 ? 0 : 8);
            } else {
                paddingLeft = c(linearLayout, paddingLeft, iMakeMeasureSpec, 0);
            }
        }
        View view2 = this.f613q;
        if (view2 != null) {
            ViewGroup.LayoutParams layoutParams = view2.getLayoutParams();
            int i5 = layoutParams.width;
            int i6 = i5 != -2 ? 1073741824 : Integer.MIN_VALUE;
            if (i5 >= 0) {
                paddingLeft = Math.min(i5, paddingLeft);
            }
            int i7 = layoutParams.height;
            int i8 = i7 == -2 ? Integer.MIN_VALUE : 1073741824;
            if (i7 >= 0) {
                iMin = Math.min(i7, iMin);
            }
            this.f613q.measure(View.MeasureSpec.makeMeasureSpec(paddingLeft, i6), View.MeasureSpec.makeMeasureSpec(iMin, i8));
        }
        if (this.f768i > 0) {
            setMeasuredDimension(size, size2);
            return;
        }
        int childCount = getChildCount();
        int i9 = 0;
        for (int i10 = 0; i10 < childCount; i10++) {
            int measuredHeight = getChildAt(i10).getMeasuredHeight() + paddingTop;
            if (measuredHeight > i9) {
                i9 = measuredHeight;
            }
        }
        setMeasuredDimension(size, i9);
    }

    @Override // androidx.appcompat.widget.a
    public void setContentHeight(int i3) {
        this.f768i = i3;
    }

    public void setCustomView(View view) {
        LinearLayout linearLayout;
        View view2 = this.f613q;
        if (view2 != null) {
            removeView(view2);
        }
        this.f613q = view;
        if (view != null && (linearLayout = this.f614r) != null) {
            removeView(linearLayout);
            this.f614r = null;
        }
        if (view != null) {
            addView(view);
        }
        requestLayout();
    }

    public void setSubtitle(CharSequence charSequence) {
        this.f610n = charSequence;
        i();
    }

    public void setTitle(CharSequence charSequence) {
        this.f609m = charSequence;
        i();
        androidx.core.view.y.u0(this, charSequence);
    }

    public void setTitleOptional(boolean z2) {
        if (z2 != this.f619w) {
            requestLayout();
        }
        this.f619w = z2;
    }

    @Override // androidx.appcompat.widget.a, android.view.View
    public /* bridge */ /* synthetic */ void setVisibility(int i3) {
        super.setVisibility(i3);
    }

    @Override // android.view.ViewGroup
    public boolean shouldDelayChildPressedState() {
        return false;
    }

    public ActionBarContextView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, c.a.f3159j);
    }

    public ActionBarContextView(Context context, AttributeSet attributeSet, int i3) {
        super(context, attributeSet, i3);
        a1 a1VarV = a1.v(context, attributeSet, c.j.f3368x, i3, 0);
        androidx.core.view.y.v0(this, a1VarV.g(c.j.f3371y));
        this.f617u = a1VarV.n(c.j.C, 0);
        this.f618v = a1VarV.n(c.j.B, 0);
        this.f768i = a1VarV.m(c.j.A, 0);
        this.f620x = a1VarV.n(c.j.f3374z, c.g.f3255d);
        a1VarV.w();
    }
}
