package androidx.appcompat.widget;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.ContextThemeWrapper;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.a;
import androidx.appcompat.view.menu.h;
import androidx.appcompat.view.menu.o;
import androidx.appcompat.widget.ActionMenuView;
import io.netty.util.internal.shaded.org.jctools.util.Pow2;
import java.util.ArrayList;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class Toolbar extends ViewGroup {
    private int A;
    private CharSequence B;
    private CharSequence C;
    private int D;
    private int E;
    private boolean F;
    private boolean G;
    private final ArrayList<View> H;
    private final ArrayList<View> I;
    private final int[] J;
    f K;
    private final ActionMenuView.e L;
    private u0 M;
    private androidx.appcompat.widget.c N;
    private d O;
    private o.a P;
    private h.a Q;
    private boolean R;
    private final Runnable S;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private ActionMenuView f345b;

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

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private ImageButton f348h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private ImageView f349i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private Drawable f350j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private CharSequence f351k;
    ImageButton l;
    View m;
    private Context n;
    private int o;
    private int p;
    private int q;
    int r;
    private int s;
    private int t;
    private int u;
    private int v;
    private int w;
    private l0 x;
    private int y;
    private int z;

    class a implements ActionMenuView.e {
        a() {
        }

        @Override // androidx.appcompat.widget.ActionMenuView.e
        public boolean onMenuItemClick(MenuItem menuItem) {
            f fVar = Toolbar.this.K;
            if (fVar != null) {
                return fVar.onMenuItemClick(menuItem);
            }
            return false;
        }
    }

    class b implements Runnable {
        b() {
        }

        @Override // java.lang.Runnable
        public void run() {
            Toolbar.this.M();
        }
    }

    class c implements View.OnClickListener {
        c() {
        }

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

    private class d implements androidx.appcompat.view.menu.o {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        androidx.appcompat.view.menu.h f354b;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        androidx.appcompat.view.menu.j f355f;

        d() {
        }

        @Override // androidx.appcompat.view.menu.o
        public void a(androidx.appcompat.view.menu.h hVar, boolean z) {
        }

        @Override // androidx.appcompat.view.menu.o
        public void c(Context context, androidx.appcompat.view.menu.h hVar) {
            androidx.appcompat.view.menu.j jVar;
            androidx.appcompat.view.menu.h hVar2 = this.f354b;
            if (hVar2 != null && (jVar = this.f355f) != null) {
                hVar2.f(jVar);
            }
            this.f354b = hVar;
        }

        @Override // androidx.appcompat.view.menu.o
        public boolean e(androidx.appcompat.view.menu.u uVar) {
            return false;
        }

        @Override // androidx.appcompat.view.menu.o
        public void f(boolean z) {
            if (this.f355f != null) {
                androidx.appcompat.view.menu.h hVar = this.f354b;
                boolean z2 = false;
                if (hVar != null) {
                    int size = hVar.size();
                    int i2 = 0;
                    while (true) {
                        if (i2 >= size) {
                            break;
                        }
                        if (this.f354b.getItem(i2) == this.f355f) {
                            z2 = true;
                            break;
                        }
                        i2++;
                    }
                }
                if (z2) {
                    return;
                }
                h(this.f354b, this.f355f);
            }
        }

        @Override // androidx.appcompat.view.menu.o
        public boolean g() {
            return false;
        }

        @Override // androidx.appcompat.view.menu.o
        public boolean h(androidx.appcompat.view.menu.h hVar, androidx.appcompat.view.menu.j jVar) {
            KeyEvent.Callback callback = Toolbar.this.m;
            if (callback instanceof c.a.m.c) {
                ((c.a.m.c) callback).f();
            }
            Toolbar toolbar = Toolbar.this;
            toolbar.removeView(toolbar.m);
            Toolbar toolbar2 = Toolbar.this;
            toolbar2.removeView(toolbar2.l);
            Toolbar toolbar3 = Toolbar.this;
            toolbar3.m = null;
            toolbar3.a();
            this.f355f = null;
            Toolbar.this.requestLayout();
            jVar.q(false);
            return true;
        }

        @Override // androidx.appcompat.view.menu.o
        public boolean j(androidx.appcompat.view.menu.h hVar, androidx.appcompat.view.menu.j jVar) {
            Toolbar.this.g();
            ViewParent parent = Toolbar.this.l.getParent();
            Toolbar toolbar = Toolbar.this;
            if (parent != toolbar) {
                if (parent instanceof ViewGroup) {
                    ((ViewGroup) parent).removeView(toolbar.l);
                }
                Toolbar toolbar2 = Toolbar.this;
                toolbar2.addView(toolbar2.l);
            }
            Toolbar.this.m = jVar.getActionView();
            this.f355f = jVar;
            ViewParent parent2 = Toolbar.this.m.getParent();
            Toolbar toolbar3 = Toolbar.this;
            if (parent2 != toolbar3) {
                if (parent2 instanceof ViewGroup) {
                    ((ViewGroup) parent2).removeView(toolbar3.m);
                }
                e eVarGenerateDefaultLayoutParams = Toolbar.this.generateDefaultLayoutParams();
                Toolbar toolbar4 = Toolbar.this;
                eVarGenerateDefaultLayoutParams.a = 8388611 | (toolbar4.r & 112);
                eVarGenerateDefaultLayoutParams.f357b = 2;
                toolbar4.m.setLayoutParams(eVarGenerateDefaultLayoutParams);
                Toolbar toolbar5 = Toolbar.this;
                toolbar5.addView(toolbar5.m);
            }
            Toolbar.this.F();
            Toolbar.this.requestLayout();
            jVar.q(true);
            KeyEvent.Callback callback = Toolbar.this.m;
            if (callback instanceof c.a.m.c) {
                ((c.a.m.c) callback).c();
            }
            return true;
        }

        @Override // androidx.appcompat.view.menu.o
        public void k(o.a aVar) {
        }
    }

    public interface f {
        boolean onMenuItemClick(MenuItem menuItem);
    }

    public Toolbar(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, c.a.a.toolbarStyle);
    }

    private int A(View view, int i2, int[] iArr, int i3) {
        e eVar = (e) view.getLayoutParams();
        int i4 = ((ViewGroup.MarginLayoutParams) eVar).leftMargin - iArr[0];
        int iMax = i2 + Math.max(0, i4);
        iArr[0] = Math.max(0, -i4);
        int iQ = q(view, i3);
        int measuredWidth = view.getMeasuredWidth();
        view.layout(iMax, iQ, iMax + measuredWidth, view.getMeasuredHeight() + iQ);
        return iMax + measuredWidth + ((ViewGroup.MarginLayoutParams) eVar).rightMargin;
    }

    private int B(View view, int i2, int[] iArr, int i3) {
        e eVar = (e) view.getLayoutParams();
        int i4 = ((ViewGroup.MarginLayoutParams) eVar).rightMargin - iArr[1];
        int iMax = i2 - Math.max(0, i4);
        iArr[1] = Math.max(0, -i4);
        int iQ = q(view, i3);
        int measuredWidth = view.getMeasuredWidth();
        view.layout(iMax - measuredWidth, iQ, iMax, view.getMeasuredHeight() + iQ);
        return iMax - (measuredWidth + ((ViewGroup.MarginLayoutParams) eVar).leftMargin);
    }

    private int C(View view, int i2, int i3, int i4, int i5, int[] iArr) {
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        int i6 = marginLayoutParams.leftMargin - iArr[0];
        int i7 = marginLayoutParams.rightMargin - iArr[1];
        int iMax = Math.max(0, i6) + Math.max(0, i7);
        iArr[0] = Math.max(0, -i6);
        iArr[1] = Math.max(0, -i7);
        view.measure(ViewGroup.getChildMeasureSpec(i2, getPaddingLeft() + getPaddingRight() + iMax + i3, marginLayoutParams.width), ViewGroup.getChildMeasureSpec(i4, getPaddingTop() + getPaddingBottom() + marginLayoutParams.topMargin + marginLayoutParams.bottomMargin + i5, marginLayoutParams.height));
        return view.getMeasuredWidth() + iMax;
    }

    private void D(View view, int i2, int i3, int i4, int i5, int i6) {
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        int childMeasureSpec = ViewGroup.getChildMeasureSpec(i2, getPaddingLeft() + getPaddingRight() + marginLayoutParams.leftMargin + marginLayoutParams.rightMargin + i3, marginLayoutParams.width);
        int childMeasureSpec2 = ViewGroup.getChildMeasureSpec(i4, getPaddingTop() + getPaddingBottom() + marginLayoutParams.topMargin + marginLayoutParams.bottomMargin + i5, marginLayoutParams.height);
        int mode = View.MeasureSpec.getMode(childMeasureSpec2);
        if (mode != 1073741824 && i6 >= 0) {
            if (mode != 0) {
                i6 = Math.min(View.MeasureSpec.getSize(childMeasureSpec2), i6);
            }
            childMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(i6, Pow2.MAX_POW2);
        }
        view.measure(childMeasureSpec, childMeasureSpec2);
    }

    private void E() {
        removeCallbacks(this.S);
        post(this.S);
    }

    private boolean K() {
        if (!this.R) {
            return false;
        }
        int childCount = getChildCount();
        for (int i2 = 0; i2 < childCount; i2++) {
            View childAt = getChildAt(i2);
            if (L(childAt) && childAt.getMeasuredWidth() > 0 && childAt.getMeasuredHeight() > 0) {
                return false;
            }
        }
        return true;
    }

    private boolean L(View view) {
        return (view == null || view.getParent() != this || view.getVisibility() == 8) ? false : true;
    }

    private void b(List<View> list, int i2) {
        boolean z = c.f.l.t.u(this) == 1;
        int childCount = getChildCount();
        int iB = c.f.l.d.b(i2, c.f.l.t.u(this));
        list.clear();
        if (!z) {
            for (int i3 = 0; i3 < childCount; i3++) {
                View childAt = getChildAt(i3);
                e eVar = (e) childAt.getLayoutParams();
                if (eVar.f357b == 0 && L(childAt) && p(eVar.a) == iB) {
                    list.add(childAt);
                }
            }
            return;
        }
        for (int i4 = childCount - 1; i4 >= 0; i4--) {
            View childAt2 = getChildAt(i4);
            e eVar2 = (e) childAt2.getLayoutParams();
            if (eVar2.f357b == 0 && L(childAt2) && p(eVar2.a) == iB) {
                list.add(childAt2);
            }
        }
    }

    private void c(View view, boolean z) {
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        e eVarGenerateDefaultLayoutParams = layoutParams == null ? generateDefaultLayoutParams() : !checkLayoutParams(layoutParams) ? generateLayoutParams(layoutParams) : (e) layoutParams;
        eVarGenerateDefaultLayoutParams.f357b = 1;
        if (!z || this.m == null) {
            addView(view, eVarGenerateDefaultLayoutParams);
        } else {
            view.setLayoutParams(eVarGenerateDefaultLayoutParams);
            this.I.add(view);
        }
    }

    private MenuInflater getMenuInflater() {
        return new c.a.m.g(getContext());
    }

    private void h() {
        if (this.x == null) {
            this.x = new l0();
        }
    }

    private void i() {
        if (this.f349i == null) {
            this.f349i = new o(getContext());
        }
    }

    private void j() {
        k();
        if (this.f345b.N() == null) {
            androidx.appcompat.view.menu.h hVar = (androidx.appcompat.view.menu.h) this.f345b.getMenu();
            if (this.O == null) {
                this.O = new d();
            }
            this.f345b.setExpandedActionViewsExclusive(true);
            hVar.c(this.O, this.n);
        }
    }

    private void k() {
        if (this.f345b == null) {
            ActionMenuView actionMenuView = new ActionMenuView(getContext());
            this.f345b = actionMenuView;
            actionMenuView.setPopupTheme(this.o);
            this.f345b.setOnMenuItemClickListener(this.L);
            this.f345b.O(this.P, this.Q);
            e eVarGenerateDefaultLayoutParams = generateDefaultLayoutParams();
            eVarGenerateDefaultLayoutParams.a = 8388613 | (this.r & 112);
            this.f345b.setLayoutParams(eVarGenerateDefaultLayoutParams);
            c(this.f345b, false);
        }
    }

    private void l() {
        if (this.f348h == null) {
            this.f348h = new m(getContext(), null, c.a.a.toolbarNavigationButtonStyle);
            e eVarGenerateDefaultLayoutParams = generateDefaultLayoutParams();
            eVarGenerateDefaultLayoutParams.a = 8388611 | (this.r & 112);
            this.f348h.setLayoutParams(eVarGenerateDefaultLayoutParams);
        }
    }

    private int p(int i2) {
        int iU = c.f.l.t.u(this);
        int iB = c.f.l.d.b(i2, iU) & 7;
        return (iB == 1 || iB == 3 || iB == 5) ? iB : iU == 1 ? 5 : 3;
    }

    private int q(View view, int i2) {
        e eVar = (e) view.getLayoutParams();
        int measuredHeight = view.getMeasuredHeight();
        int i3 = i2 > 0 ? (measuredHeight - i2) / 2 : 0;
        int iR = r(eVar.a);
        if (iR == 48) {
            return getPaddingTop() - i3;
        }
        if (iR == 80) {
            return (((getHeight() - getPaddingBottom()) - measuredHeight) - ((ViewGroup.MarginLayoutParams) eVar).bottomMargin) - i3;
        }
        int paddingTop = getPaddingTop();
        int paddingBottom = getPaddingBottom();
        int height = getHeight();
        int iMax = (((height - paddingTop) - paddingBottom) - measuredHeight) / 2;
        int i4 = ((ViewGroup.MarginLayoutParams) eVar).topMargin;
        if (iMax < i4) {
            iMax = i4;
        } else {
            int i5 = (((height - paddingBottom) - measuredHeight) - iMax) - paddingTop;
            int i6 = ((ViewGroup.MarginLayoutParams) eVar).bottomMargin;
            if (i5 < i6) {
                iMax = Math.max(0, iMax - (i6 - i5));
            }
        }
        return paddingTop + iMax;
    }

    private int r(int i2) {
        int i3 = i2 & 112;
        return (i3 == 16 || i3 == 48 || i3 == 80) ? i3 : this.A & 112;
    }

    private int s(View view) {
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        return c.f.l.g.b(marginLayoutParams) + c.f.l.g.a(marginLayoutParams);
    }

    private int t(View view) {
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        return marginLayoutParams.topMargin + marginLayoutParams.bottomMargin;
    }

    private int u(List<View> list, int[] iArr) {
        int i2 = iArr[0];
        int i3 = iArr[1];
        int size = list.size();
        int i4 = 0;
        int measuredWidth = 0;
        while (i4 < size) {
            View view = list.get(i4);
            e eVar = (e) view.getLayoutParams();
            int i5 = ((ViewGroup.MarginLayoutParams) eVar).leftMargin - i2;
            int i6 = ((ViewGroup.MarginLayoutParams) eVar).rightMargin - i3;
            int iMax = Math.max(0, i5);
            int iMax2 = Math.max(0, i6);
            int iMax3 = Math.max(0, -i5);
            int iMax4 = Math.max(0, -i6);
            measuredWidth += iMax + view.getMeasuredWidth() + iMax2;
            i4++;
            i3 = iMax4;
            i2 = iMax3;
        }
        return measuredWidth;
    }

    private boolean x(View view) {
        return view.getParent() == this || this.I.contains(view);
    }

    void F() {
        for (int childCount = getChildCount() - 1; childCount >= 0; childCount--) {
            View childAt = getChildAt(childCount);
            if (((e) childAt.getLayoutParams()).f357b != 2 && childAt != this.f345b) {
                removeViewAt(childCount);
                this.I.add(childAt);
            }
        }
    }

    public void G(int i2, int i3) {
        h();
        this.x.g(i2, i3);
    }

    public void H(androidx.appcompat.view.menu.h hVar, androidx.appcompat.widget.c cVar) {
        if (hVar == null && this.f345b == null) {
            return;
        }
        k();
        androidx.appcompat.view.menu.h hVarN = this.f345b.N();
        if (hVarN == hVar) {
            return;
        }
        if (hVarN != null) {
            hVarN.O(this.N);
            hVarN.O(this.O);
        }
        if (this.O == null) {
            this.O = new d();
        }
        cVar.F(true);
        if (hVar != null) {
            hVar.c(cVar, this.n);
            hVar.c(this.O, this.n);
        } else {
            cVar.c(this.n, null);
            this.O.c(this.n, null);
            cVar.f(true);
            this.O.f(true);
        }
        this.f345b.setPopupTheme(this.o);
        this.f345b.setPresenter(cVar);
        this.N = cVar;
    }

    public void I(Context context, int i2) {
        this.q = i2;
        TextView textView = this.f347g;
        if (textView != null) {
            textView.setTextAppearance(context, i2);
        }
    }

    public void J(Context context, int i2) {
        this.p = i2;
        TextView textView = this.f346f;
        if (textView != null) {
            textView.setTextAppearance(context, i2);
        }
    }

    public boolean M() {
        ActionMenuView actionMenuView = this.f345b;
        return actionMenuView != null && actionMenuView.P();
    }

    void a() {
        for (int size = this.I.size() - 1; size >= 0; size--) {
            addView(this.I.get(size));
        }
        this.I.clear();
    }

    @Override // android.view.ViewGroup
    protected boolean checkLayoutParams(ViewGroup.LayoutParams layoutParams) {
        return super.checkLayoutParams(layoutParams) && (layoutParams instanceof e);
    }

    public boolean d() {
        ActionMenuView actionMenuView;
        return getVisibility() == 0 && (actionMenuView = this.f345b) != null && actionMenuView.K();
    }

    public void e() {
        d dVar = this.O;
        androidx.appcompat.view.menu.j jVar = dVar == null ? null : dVar.f355f;
        if (jVar != null) {
            jVar.collapseActionView();
        }
    }

    public void f() {
        ActionMenuView actionMenuView = this.f345b;
        if (actionMenuView != null) {
            actionMenuView.B();
        }
    }

    void g() {
        if (this.l == null) {
            m mVar = new m(getContext(), null, c.a.a.toolbarNavigationButtonStyle);
            this.l = mVar;
            mVar.setImageDrawable(this.f350j);
            this.l.setContentDescription(this.f351k);
            e eVarGenerateDefaultLayoutParams = generateDefaultLayoutParams();
            eVarGenerateDefaultLayoutParams.a = 8388611 | (this.r & 112);
            eVarGenerateDefaultLayoutParams.f357b = 2;
            this.l.setLayoutParams(eVarGenerateDefaultLayoutParams);
            this.l.setOnClickListener(new c());
        }
    }

    public int getContentInsetEnd() {
        l0 l0Var = this.x;
        if (l0Var != null) {
            return l0Var.a();
        }
        return 0;
    }

    public int getContentInsetEndWithActions() {
        int i2 = this.z;
        return i2 != Integer.MIN_VALUE ? i2 : getContentInsetEnd();
    }

    public int getContentInsetLeft() {
        l0 l0Var = this.x;
        if (l0Var != null) {
            return l0Var.b();
        }
        return 0;
    }

    public int getContentInsetRight() {
        l0 l0Var = this.x;
        if (l0Var != null) {
            return l0Var.c();
        }
        return 0;
    }

    public int getContentInsetStart() {
        l0 l0Var = this.x;
        if (l0Var != null) {
            return l0Var.d();
        }
        return 0;
    }

    public int getContentInsetStartWithNavigation() {
        int i2 = this.y;
        return i2 != Integer.MIN_VALUE ? i2 : getContentInsetStart();
    }

    public int getCurrentContentInsetEnd() {
        androidx.appcompat.view.menu.h hVarN;
        ActionMenuView actionMenuView = this.f345b;
        return actionMenuView != null && (hVarN = actionMenuView.N()) != null && hVarN.hasVisibleItems() ? Math.max(getContentInsetEnd(), Math.max(this.z, 0)) : getContentInsetEnd();
    }

    public int getCurrentContentInsetLeft() {
        return c.f.l.t.u(this) == 1 ? getCurrentContentInsetEnd() : getCurrentContentInsetStart();
    }

    public int getCurrentContentInsetRight() {
        return c.f.l.t.u(this) == 1 ? getCurrentContentInsetStart() : getCurrentContentInsetEnd();
    }

    public int getCurrentContentInsetStart() {
        return getNavigationIcon() != null ? Math.max(getContentInsetStart(), Math.max(this.y, 0)) : getContentInsetStart();
    }

    public Drawable getLogo() {
        ImageView imageView = this.f349i;
        if (imageView != null) {
            return imageView.getDrawable();
        }
        return null;
    }

    public CharSequence getLogoDescription() {
        ImageView imageView = this.f349i;
        if (imageView != null) {
            return imageView.getContentDescription();
        }
        return null;
    }

    public Menu getMenu() {
        j();
        return this.f345b.getMenu();
    }

    public CharSequence getNavigationContentDescription() {
        ImageButton imageButton = this.f348h;
        if (imageButton != null) {
            return imageButton.getContentDescription();
        }
        return null;
    }

    public Drawable getNavigationIcon() {
        ImageButton imageButton = this.f348h;
        if (imageButton != null) {
            return imageButton.getDrawable();
        }
        return null;
    }

    androidx.appcompat.widget.c getOuterActionMenuPresenter() {
        return this.N;
    }

    public Drawable getOverflowIcon() {
        j();
        return this.f345b.getOverflowIcon();
    }

    Context getPopupContext() {
        return this.n;
    }

    public int getPopupTheme() {
        return this.o;
    }

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

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

    public int getTitleMarginBottom() {
        return this.w;
    }

    public int getTitleMarginEnd() {
        return this.u;
    }

    public int getTitleMarginStart() {
        return this.t;
    }

    public int getTitleMarginTop() {
        return this.v;
    }

    public b0 getWrapper() {
        if (this.M == null) {
            this.M = new u0(this, true);
        }
        return this.M;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // android.view.ViewGroup
    /* JADX INFO: renamed from: m, reason: merged with bridge method [inline-methods] */
    public e generateDefaultLayoutParams() {
        return new e(-2, -2);
    }

    @Override // android.view.ViewGroup
    /* JADX INFO: renamed from: n, reason: merged with bridge method [inline-methods] */
    public e generateLayoutParams(AttributeSet attributeSet) {
        return new e(getContext(), attributeSet);
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // android.view.ViewGroup
    /* JADX INFO: renamed from: o, reason: merged with bridge method [inline-methods] */
    public e generateLayoutParams(ViewGroup.LayoutParams layoutParams) {
        return layoutParams instanceof e ? new e((e) layoutParams) : layoutParams instanceof a.C0003a ? new e((a.C0003a) layoutParams) : layoutParams instanceof ViewGroup.MarginLayoutParams ? new e((ViewGroup.MarginLayoutParams) layoutParams) : new e(layoutParams);
    }

    @Override // android.view.ViewGroup, android.view.View
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        removeCallbacks(this.S);
    }

    @Override // android.view.View
    public boolean onHoverEvent(MotionEvent motionEvent) {
        int actionMasked = motionEvent.getActionMasked();
        if (actionMasked == 9) {
            this.G = false;
        }
        if (!this.G) {
            boolean zOnHoverEvent = super.onHoverEvent(motionEvent);
            if (actionMasked == 9 && !zOnHoverEvent) {
                this.G = true;
            }
        }
        if (actionMasked == 10 || actionMasked == 3) {
            this.G = false;
        }
        return true;
    }

    /* JADX WARN: Removed duplicated region for block: B:105:0x02a3 A[LOOP:0: B:104:0x02a1->B:105:0x02a3, LOOP_END] */
    /* JADX WARN: Removed duplicated region for block: B:108:0x02c5 A[LOOP:1: B:107:0x02c3->B:108:0x02c5, LOOP_END] */
    /* JADX WARN: Removed duplicated region for block: B:112:0x02ef  */
    /* JADX WARN: Removed duplicated region for block: B:117:0x02fe A[LOOP:2: B:116:0x02fc->B:117:0x02fe, LOOP_END] */
    /* JADX WARN: Removed duplicated region for block: B:19:0x005f  */
    /* JADX WARN: Removed duplicated region for block: B:24:0x0076  */
    /* JADX WARN: Removed duplicated region for block: B:29:0x00b3  */
    /* JADX WARN: Removed duplicated region for block: B:34:0x00ca  */
    /* JADX WARN: Removed duplicated region for block: B:39:0x00e7  */
    /* JADX WARN: Removed duplicated region for block: B:40:0x0100  */
    /* JADX WARN: Removed duplicated region for block: B:42:0x0105  */
    /* JADX WARN: Removed duplicated region for block: B:43:0x011d  */
    /* JADX WARN: Removed duplicated region for block: B:49:0x012b  */
    /* JADX WARN: Removed duplicated region for block: B:50:0x012d  */
    /* JADX WARN: Removed duplicated region for block: B:51:0x0130  */
    /* JADX WARN: Removed duplicated region for block: B:53:0x0134  */
    /* JADX WARN: Removed duplicated region for block: B:54:0x0137  */
    /* JADX WARN: Removed duplicated region for block: B:66:0x0168  */
    /* JADX WARN: Removed duplicated region for block: B:76:0x01a6  */
    /* JADX WARN: Removed duplicated region for block: B:78:0x01b7  */
    /* JADX WARN: Removed duplicated region for block: B:91:0x0229  */
    @Override // android.view.ViewGroup, android.view.View
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    protected void onLayout(boolean r20, int r21, int r22, int r23, int r24) {
        /*
            Method dump skipped, instruction units count: 787
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: androidx.appcompat.widget.Toolbar.onLayout(boolean, int, int, int, int):void");
    }

    @Override // android.view.View
    protected void onMeasure(int i2, int i3) {
        char c2;
        char c3;
        int measuredWidth;
        int iMax;
        int iCombineMeasuredStates;
        int measuredWidth2;
        int measuredHeight;
        int iCombineMeasuredStates2;
        int iMax2;
        int[] iArr = this.J;
        if (z0.b(this)) {
            c3 = 1;
            c2 = 0;
        } else {
            c2 = 1;
            c3 = 0;
        }
        if (L(this.f348h)) {
            D(this.f348h, i2, 0, i3, 0, this.s);
            measuredWidth = this.f348h.getMeasuredWidth() + s(this.f348h);
            iMax = Math.max(0, this.f348h.getMeasuredHeight() + t(this.f348h));
            iCombineMeasuredStates = View.combineMeasuredStates(0, this.f348h.getMeasuredState());
        } else {
            measuredWidth = 0;
            iMax = 0;
            iCombineMeasuredStates = 0;
        }
        if (L(this.l)) {
            D(this.l, i2, 0, i3, 0, this.s);
            measuredWidth = this.l.getMeasuredWidth() + s(this.l);
            iMax = Math.max(iMax, this.l.getMeasuredHeight() + t(this.l));
            iCombineMeasuredStates = View.combineMeasuredStates(iCombineMeasuredStates, this.l.getMeasuredState());
        }
        int currentContentInsetStart = getCurrentContentInsetStart();
        int iMax3 = 0 + Math.max(currentContentInsetStart, measuredWidth);
        iArr[c3] = Math.max(0, currentContentInsetStart - measuredWidth);
        if (L(this.f345b)) {
            D(this.f345b, i2, iMax3, i3, 0, this.s);
            measuredWidth2 = this.f345b.getMeasuredWidth() + s(this.f345b);
            iMax = Math.max(iMax, this.f345b.getMeasuredHeight() + t(this.f345b));
            iCombineMeasuredStates = View.combineMeasuredStates(iCombineMeasuredStates, this.f345b.getMeasuredState());
        } else {
            measuredWidth2 = 0;
        }
        int currentContentInsetEnd = getCurrentContentInsetEnd();
        int iMax4 = iMax3 + Math.max(currentContentInsetEnd, measuredWidth2);
        iArr[c2] = Math.max(0, currentContentInsetEnd - measuredWidth2);
        if (L(this.m)) {
            iMax4 += C(this.m, i2, iMax4, i3, 0, iArr);
            iMax = Math.max(iMax, this.m.getMeasuredHeight() + t(this.m));
            iCombineMeasuredStates = View.combineMeasuredStates(iCombineMeasuredStates, this.m.getMeasuredState());
        }
        if (L(this.f349i)) {
            iMax4 += C(this.f349i, i2, iMax4, i3, 0, iArr);
            iMax = Math.max(iMax, this.f349i.getMeasuredHeight() + t(this.f349i));
            iCombineMeasuredStates = View.combineMeasuredStates(iCombineMeasuredStates, this.f349i.getMeasuredState());
        }
        int childCount = getChildCount();
        for (int i4 = 0; i4 < childCount; i4++) {
            View childAt = getChildAt(i4);
            if (((e) childAt.getLayoutParams()).f357b == 0 && L(childAt)) {
                iMax4 += C(childAt, i2, iMax4, i3, 0, iArr);
                iMax = Math.max(iMax, childAt.getMeasuredHeight() + t(childAt));
                iCombineMeasuredStates = View.combineMeasuredStates(iCombineMeasuredStates, childAt.getMeasuredState());
            }
        }
        int i5 = this.v + this.w;
        int i6 = this.t + this.u;
        if (L(this.f346f)) {
            C(this.f346f, i2, iMax4 + i6, i3, i5, iArr);
            int measuredWidth3 = this.f346f.getMeasuredWidth() + s(this.f346f);
            measuredHeight = this.f346f.getMeasuredHeight() + t(this.f346f);
            iCombineMeasuredStates2 = View.combineMeasuredStates(iCombineMeasuredStates, this.f346f.getMeasuredState());
            iMax2 = measuredWidth3;
        } else {
            measuredHeight = 0;
            iCombineMeasuredStates2 = iCombineMeasuredStates;
            iMax2 = 0;
        }
        if (L(this.f347g)) {
            iMax2 = Math.max(iMax2, C(this.f347g, i2, iMax4 + i6, i3, measuredHeight + i5, iArr));
            measuredHeight += this.f347g.getMeasuredHeight() + t(this.f347g);
            iCombineMeasuredStates2 = View.combineMeasuredStates(iCombineMeasuredStates2, this.f347g.getMeasuredState());
        }
        setMeasuredDimension(View.resolveSizeAndState(Math.max(iMax4 + iMax2 + getPaddingLeft() + getPaddingRight(), getSuggestedMinimumWidth()), i2, (-16777216) & iCombineMeasuredStates2), K() ? 0 : View.resolveSizeAndState(Math.max(Math.max(iMax, measuredHeight) + getPaddingTop() + getPaddingBottom(), getSuggestedMinimumHeight()), i3, iCombineMeasuredStates2 << 16));
    }

    @Override // android.view.View
    protected void onRestoreInstanceState(Parcelable parcelable) {
        MenuItem menuItemFindItem;
        if (!(parcelable instanceof g)) {
            super.onRestoreInstanceState(parcelable);
            return;
        }
        g gVar = (g) parcelable;
        super.onRestoreInstanceState(gVar.a());
        ActionMenuView actionMenuView = this.f345b;
        androidx.appcompat.view.menu.h hVarN = actionMenuView != null ? actionMenuView.N() : null;
        int i2 = gVar.f358g;
        if (i2 != 0 && this.O != null && hVarN != null && (menuItemFindItem = hVarN.findItem(i2)) != null) {
            menuItemFindItem.expandActionView();
        }
        if (gVar.f359h) {
            E();
        }
    }

    @Override // android.view.View
    public void onRtlPropertiesChanged(int i2) {
        if (Build.VERSION.SDK_INT >= 17) {
            super.onRtlPropertiesChanged(i2);
        }
        h();
        this.x.f(i2 == 1);
    }

    @Override // android.view.View
    protected Parcelable onSaveInstanceState() {
        androidx.appcompat.view.menu.j jVar;
        g gVar = new g(super.onSaveInstanceState());
        d dVar = this.O;
        if (dVar != null && (jVar = dVar.f355f) != null) {
            gVar.f358g = jVar.getItemId();
        }
        gVar.f359h = z();
        return gVar;
    }

    @Override // android.view.View
    public boolean onTouchEvent(MotionEvent motionEvent) {
        int actionMasked = motionEvent.getActionMasked();
        if (actionMasked == 0) {
            this.F = false;
        }
        if (!this.F) {
            boolean zOnTouchEvent = super.onTouchEvent(motionEvent);
            if (actionMasked == 0 && !zOnTouchEvent) {
                this.F = true;
            }
        }
        if (actionMasked == 1 || actionMasked == 3) {
            this.F = false;
        }
        return true;
    }

    public void setCollapsible(boolean z) {
        this.R = z;
        requestLayout();
    }

    public void setContentInsetEndWithActions(int i2) {
        if (i2 < 0) {
            i2 = Integer.MIN_VALUE;
        }
        if (i2 != this.z) {
            this.z = i2;
            if (getNavigationIcon() != null) {
                requestLayout();
            }
        }
    }

    public void setContentInsetStartWithNavigation(int i2) {
        if (i2 < 0) {
            i2 = Integer.MIN_VALUE;
        }
        if (i2 != this.y) {
            this.y = i2;
            if (getNavigationIcon() != null) {
                requestLayout();
            }
        }
    }

    public void setLogo(int i2) {
        setLogo(c.a.k.a.a.d(getContext(), i2));
    }

    public void setLogoDescription(int i2) {
        setLogoDescription(getContext().getText(i2));
    }

    public void setNavigationContentDescription(int i2) {
        setNavigationContentDescription(i2 != 0 ? getContext().getText(i2) : null);
    }

    public void setNavigationIcon(int i2) {
        setNavigationIcon(c.a.k.a.a.d(getContext(), i2));
    }

    public void setNavigationOnClickListener(View.OnClickListener onClickListener) {
        l();
        this.f348h.setOnClickListener(onClickListener);
    }

    public void setOnMenuItemClickListener(f fVar) {
        this.K = fVar;
    }

    public void setOverflowIcon(Drawable drawable) {
        j();
        this.f345b.setOverflowIcon(drawable);
    }

    public void setPopupTheme(int i2) {
        if (this.o != i2) {
            this.o = i2;
            if (i2 == 0) {
                this.n = getContext();
            } else {
                this.n = new ContextThemeWrapper(getContext(), i2);
            }
        }
    }

    public void setSubtitle(int i2) {
        setSubtitle(getContext().getText(i2));
    }

    public void setSubtitleTextColor(int i2) {
        this.E = i2;
        TextView textView = this.f347g;
        if (textView != null) {
            textView.setTextColor(i2);
        }
    }

    public void setTitle(int i2) {
        setTitle(getContext().getText(i2));
    }

    public void setTitleMarginBottom(int i2) {
        this.w = i2;
        requestLayout();
    }

    public void setTitleMarginEnd(int i2) {
        this.u = i2;
        requestLayout();
    }

    public void setTitleMarginStart(int i2) {
        this.t = i2;
        requestLayout();
    }

    public void setTitleMarginTop(int i2) {
        this.v = i2;
        requestLayout();
    }

    public void setTitleTextColor(int i2) {
        this.D = i2;
        TextView textView = this.f346f;
        if (textView != null) {
            textView.setTextColor(i2);
        }
    }

    public boolean v() {
        d dVar = this.O;
        return (dVar == null || dVar.f355f == null) ? false : true;
    }

    public boolean w() {
        ActionMenuView actionMenuView = this.f345b;
        return actionMenuView != null && actionMenuView.H();
    }

    public boolean y() {
        ActionMenuView actionMenuView = this.f345b;
        return actionMenuView != null && actionMenuView.I();
    }

    public boolean z() {
        ActionMenuView actionMenuView = this.f345b;
        return actionMenuView != null && actionMenuView.J();
    }

    public static class e extends a.C0003a {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        int f357b;

        public e(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
            this.f357b = 0;
        }

        void a(ViewGroup.MarginLayoutParams marginLayoutParams) {
            ((ViewGroup.MarginLayoutParams) this).leftMargin = marginLayoutParams.leftMargin;
            ((ViewGroup.MarginLayoutParams) this).topMargin = marginLayoutParams.topMargin;
            ((ViewGroup.MarginLayoutParams) this).rightMargin = marginLayoutParams.rightMargin;
            ((ViewGroup.MarginLayoutParams) this).bottomMargin = marginLayoutParams.bottomMargin;
        }

        public e(int i2, int i3) {
            super(i2, i3);
            this.f357b = 0;
            this.a = 8388627;
        }

        public e(e eVar) {
            super((a.C0003a) eVar);
            this.f357b = 0;
            this.f357b = eVar.f357b;
        }

        public e(a.C0003a c0003a) {
            super(c0003a);
            this.f357b = 0;
        }

        public e(ViewGroup.MarginLayoutParams marginLayoutParams) {
            super(marginLayoutParams);
            this.f357b = 0;
            a(marginLayoutParams);
        }

        public e(ViewGroup.LayoutParams layoutParams) {
            super(layoutParams);
            this.f357b = 0;
        }
    }

    public Toolbar(Context context, AttributeSet attributeSet, int i2) {
        super(context, attributeSet, i2);
        this.A = 8388627;
        this.H = new ArrayList<>();
        this.I = new ArrayList<>();
        this.J = new int[2];
        this.L = new a();
        this.S = new b();
        t0 t0VarT = t0.t(getContext(), attributeSet, c.a.j.Toolbar, i2, 0);
        this.p = t0VarT.m(c.a.j.Toolbar_titleTextAppearance, 0);
        this.q = t0VarT.m(c.a.j.Toolbar_subtitleTextAppearance, 0);
        this.A = t0VarT.k(c.a.j.Toolbar_android_gravity, this.A);
        this.r = t0VarT.k(c.a.j.Toolbar_buttonGravity, 48);
        int iD = t0VarT.d(c.a.j.Toolbar_titleMargin, 0);
        iD = t0VarT.q(c.a.j.Toolbar_titleMargins) ? t0VarT.d(c.a.j.Toolbar_titleMargins, iD) : iD;
        this.w = iD;
        this.v = iD;
        this.u = iD;
        this.t = iD;
        int iD2 = t0VarT.d(c.a.j.Toolbar_titleMarginStart, -1);
        if (iD2 >= 0) {
            this.t = iD2;
        }
        int iD3 = t0VarT.d(c.a.j.Toolbar_titleMarginEnd, -1);
        if (iD3 >= 0) {
            this.u = iD3;
        }
        int iD4 = t0VarT.d(c.a.j.Toolbar_titleMarginTop, -1);
        if (iD4 >= 0) {
            this.v = iD4;
        }
        int iD5 = t0VarT.d(c.a.j.Toolbar_titleMarginBottom, -1);
        if (iD5 >= 0) {
            this.w = iD5;
        }
        this.s = t0VarT.e(c.a.j.Toolbar_maxButtonHeight, -1);
        int iD6 = t0VarT.d(c.a.j.Toolbar_contentInsetStart, Integer.MIN_VALUE);
        int iD7 = t0VarT.d(c.a.j.Toolbar_contentInsetEnd, Integer.MIN_VALUE);
        int iE = t0VarT.e(c.a.j.Toolbar_contentInsetLeft, 0);
        int iE2 = t0VarT.e(c.a.j.Toolbar_contentInsetRight, 0);
        h();
        this.x.e(iE, iE2);
        if (iD6 != Integer.MIN_VALUE || iD7 != Integer.MIN_VALUE) {
            this.x.g(iD6, iD7);
        }
        this.y = t0VarT.d(c.a.j.Toolbar_contentInsetStartWithNavigation, Integer.MIN_VALUE);
        this.z = t0VarT.d(c.a.j.Toolbar_contentInsetEndWithActions, Integer.MIN_VALUE);
        this.f350j = t0VarT.f(c.a.j.Toolbar_collapseIcon);
        this.f351k = t0VarT.o(c.a.j.Toolbar_collapseContentDescription);
        CharSequence charSequenceO = t0VarT.o(c.a.j.Toolbar_title);
        if (!TextUtils.isEmpty(charSequenceO)) {
            setTitle(charSequenceO);
        }
        CharSequence charSequenceO2 = t0VarT.o(c.a.j.Toolbar_subtitle);
        if (!TextUtils.isEmpty(charSequenceO2)) {
            setSubtitle(charSequenceO2);
        }
        this.n = getContext();
        setPopupTheme(t0VarT.m(c.a.j.Toolbar_popupTheme, 0));
        Drawable drawableF = t0VarT.f(c.a.j.Toolbar_navigationIcon);
        if (drawableF != null) {
            setNavigationIcon(drawableF);
        }
        CharSequence charSequenceO3 = t0VarT.o(c.a.j.Toolbar_navigationContentDescription);
        if (!TextUtils.isEmpty(charSequenceO3)) {
            setNavigationContentDescription(charSequenceO3);
        }
        Drawable drawableF2 = t0VarT.f(c.a.j.Toolbar_logo);
        if (drawableF2 != null) {
            setLogo(drawableF2);
        }
        CharSequence charSequenceO4 = t0VarT.o(c.a.j.Toolbar_logoDescription);
        if (!TextUtils.isEmpty(charSequenceO4)) {
            setLogoDescription(charSequenceO4);
        }
        if (t0VarT.q(c.a.j.Toolbar_titleTextColor)) {
            setTitleTextColor(t0VarT.b(c.a.j.Toolbar_titleTextColor, -1));
        }
        if (t0VarT.q(c.a.j.Toolbar_subtitleTextColor)) {
            setSubtitleTextColor(t0VarT.b(c.a.j.Toolbar_subtitleTextColor, -1));
        }
        t0VarT.u();
    }

    public void setLogo(Drawable drawable) {
        if (drawable != null) {
            i();
            if (!x(this.f349i)) {
                c(this.f349i, true);
            }
        } else {
            ImageView imageView = this.f349i;
            if (imageView != null && x(imageView)) {
                removeView(this.f349i);
                this.I.remove(this.f349i);
            }
        }
        ImageView imageView2 = this.f349i;
        if (imageView2 != null) {
            imageView2.setImageDrawable(drawable);
        }
    }

    public void setLogoDescription(CharSequence charSequence) {
        if (!TextUtils.isEmpty(charSequence)) {
            i();
        }
        ImageView imageView = this.f349i;
        if (imageView != null) {
            imageView.setContentDescription(charSequence);
        }
    }

    public void setNavigationContentDescription(CharSequence charSequence) {
        if (!TextUtils.isEmpty(charSequence)) {
            l();
        }
        ImageButton imageButton = this.f348h;
        if (imageButton != null) {
            imageButton.setContentDescription(charSequence);
        }
    }

    public void setNavigationIcon(Drawable drawable) {
        if (drawable != null) {
            l();
            if (!x(this.f348h)) {
                c(this.f348h, true);
            }
        } else {
            ImageButton imageButton = this.f348h;
            if (imageButton != null && x(imageButton)) {
                removeView(this.f348h);
                this.I.remove(this.f348h);
            }
        }
        ImageButton imageButton2 = this.f348h;
        if (imageButton2 != null) {
            imageButton2.setImageDrawable(drawable);
        }
    }

    public void setSubtitle(CharSequence charSequence) {
        if (TextUtils.isEmpty(charSequence)) {
            TextView textView = this.f347g;
            if (textView != null && x(textView)) {
                removeView(this.f347g);
                this.I.remove(this.f347g);
            }
        } else {
            if (this.f347g == null) {
                Context context = getContext();
                y yVar = new y(context);
                this.f347g = yVar;
                yVar.setSingleLine();
                this.f347g.setEllipsize(TextUtils.TruncateAt.END);
                int i2 = this.q;
                if (i2 != 0) {
                    this.f347g.setTextAppearance(context, i2);
                }
                int i3 = this.E;
                if (i3 != 0) {
                    this.f347g.setTextColor(i3);
                }
            }
            if (!x(this.f347g)) {
                c(this.f347g, true);
            }
        }
        TextView textView2 = this.f347g;
        if (textView2 != null) {
            textView2.setText(charSequence);
        }
        this.C = charSequence;
    }

    public void setTitle(CharSequence charSequence) {
        if (TextUtils.isEmpty(charSequence)) {
            TextView textView = this.f346f;
            if (textView != null && x(textView)) {
                removeView(this.f346f);
                this.I.remove(this.f346f);
            }
        } else {
            if (this.f346f == null) {
                Context context = getContext();
                y yVar = new y(context);
                this.f346f = yVar;
                yVar.setSingleLine();
                this.f346f.setEllipsize(TextUtils.TruncateAt.END);
                int i2 = this.p;
                if (i2 != 0) {
                    this.f346f.setTextAppearance(context, i2);
                }
                int i3 = this.D;
                if (i3 != 0) {
                    this.f346f.setTextColor(i3);
                }
            }
            if (!x(this.f346f)) {
                c(this.f346f, true);
            }
        }
        TextView textView2 = this.f346f;
        if (textView2 != null) {
            textView2.setText(charSequence);
        }
        this.B = charSequence;
    }

    public static class g extends c.h.a.a {
        public static final Parcelable.Creator<g> CREATOR = new a();

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        int f358g;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        boolean f359h;

        static class a implements Parcelable.ClassLoaderCreator<g> {
            a() {
            }

            @Override // android.os.Parcelable.Creator
            /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
            public g createFromParcel(Parcel parcel) {
                return new g(parcel, null);
            }

            @Override // android.os.Parcelable.ClassLoaderCreator
            /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
            public g createFromParcel(Parcel parcel, ClassLoader classLoader) {
                return new g(parcel, classLoader);
            }

            @Override // android.os.Parcelable.Creator
            /* JADX INFO: renamed from: c, reason: merged with bridge method [inline-methods] */
            public g[] newArray(int i2) {
                return new g[i2];
            }
        }

        public g(Parcel parcel, ClassLoader classLoader) {
            super(parcel, classLoader);
            this.f358g = parcel.readInt();
            this.f359h = parcel.readInt() != 0;
        }

        @Override // c.h.a.a, android.os.Parcelable
        public void writeToParcel(Parcel parcel, int i2) {
            super.writeToParcel(parcel, i2);
            parcel.writeInt(this.f358g);
            parcel.writeInt(this.f359h ? 1 : 0);
        }

        public g(Parcelable parcelable) {
            super(parcelable);
        }
    }
}
