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 com.cvte.vman.instance.InvokeCmd;
import java.util.ArrayList;
import java.util.List;

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

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

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

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

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    ImageButton f137j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    View f138k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private Context f139l;

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

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

        @Override // androidx.appcompat.widget.ActionMenuView.e
        public boolean onMenuItemClick(MenuItem menuItem) {
            f fVar = Toolbar.this.I;
            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 {
        androidx.appcompat.view.menu.h b;
        androidx.appcompat.view.menu.j d;

        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.b;
            if (hVar2 != null && (jVar = this.d) != null) {
                hVar2.f(jVar);
            }
            this.b = 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.d != null) {
                androidx.appcompat.view.menu.h hVar = this.b;
                boolean z2 = false;
                if (hVar != null) {
                    int size = hVar.size();
                    int i2 = 0;
                    while (true) {
                        if (i2 >= size) {
                            break;
                        }
                        if (this.b.getItem(i2) == this.d) {
                            z2 = true;
                            break;
                        }
                        i2++;
                    }
                }
                if (z2) {
                    return;
                }
                h(this.b, this.d);
            }
        }

        @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.f138k;
            if (callback instanceof g.a.m.c) {
                ((g.a.m.c) callback).d();
            }
            Toolbar toolbar = Toolbar.this;
            toolbar.removeView(toolbar.f138k);
            Toolbar toolbar2 = Toolbar.this;
            toolbar2.removeView(toolbar2.f137j);
            Toolbar toolbar3 = Toolbar.this;
            toolbar3.f138k = null;
            toolbar3.a();
            this.d = null;
            Toolbar.this.requestLayout();
            jVar.r(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.f137j.getParent();
            Toolbar toolbar = Toolbar.this;
            if (parent != toolbar) {
                if (parent instanceof ViewGroup) {
                    ((ViewGroup) parent).removeView(toolbar.f137j);
                }
                Toolbar toolbar2 = Toolbar.this;
                toolbar2.addView(toolbar2.f137j);
            }
            Toolbar.this.f138k = jVar.getActionView();
            this.d = jVar;
            ViewParent parent2 = Toolbar.this.f138k.getParent();
            Toolbar toolbar3 = Toolbar.this;
            if (parent2 != toolbar3) {
                if (parent2 instanceof ViewGroup) {
                    ((ViewGroup) parent2).removeView(toolbar3.f138k);
                }
                e eVarGenerateDefaultLayoutParams = Toolbar.this.generateDefaultLayoutParams();
                Toolbar toolbar4 = Toolbar.this;
                eVarGenerateDefaultLayoutParams.a = 8388611 | (toolbar4.p & InvokeCmd.CMD_SYSTEMCTRL_GET_AENA_STATE);
                eVarGenerateDefaultLayoutParams.b = 2;
                toolbar4.f138k.setLayoutParams(eVarGenerateDefaultLayoutParams);
                Toolbar toolbar5 = Toolbar.this;
                toolbar5.addView(toolbar5.f138k);
            }
            Toolbar.this.F();
            Toolbar.this.requestLayout();
            jVar.r(true);
            KeyEvent.Callback callback = Toolbar.this.f138k;
            if (callback instanceof g.a.m.c) {
                ((g.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, g.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, 1073741824);
        }
        view.measure(childMeasureSpec, childMeasureSpec2);
    }

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

    private boolean K() {
        if (!this.P) {
            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 = g.e.j.o.f(this) == 1;
        int childCount = getChildCount();
        int iA = g.e.j.c.a(i2, g.e.j.o.f(this));
        list.clear();
        if (!z) {
            for (int i3 = 0; i3 < childCount; i3++) {
                View childAt = getChildAt(i3);
                e eVar = (e) childAt.getLayoutParams();
                if (eVar.b == 0 && L(childAt) && p(eVar.a) == iA) {
                    list.add(childAt);
                }
            }
            return;
        }
        for (int i4 = childCount - 1; i4 >= 0; i4--) {
            View childAt2 = getChildAt(i4);
            e eVar2 = (e) childAt2.getLayoutParams();
            if (eVar2.b == 0 && L(childAt2) && p(eVar2.a) == iA) {
                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.b = 1;
        if (!z || this.f138k == null) {
            addView(view, eVarGenerateDefaultLayoutParams);
        } else {
            view.setLayoutParams(eVarGenerateDefaultLayoutParams);
            this.G.add(view);
        }
    }

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

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

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

    private void j() {
        k();
        if (this.b.L() == null) {
            androidx.appcompat.view.menu.h hVar = (androidx.appcompat.view.menu.h) this.b.getMenu();
            if (this.M == null) {
                this.M = new d();
            }
            this.b.setExpandedActionViewsExclusive(true);
            hVar.c(this.M, this.f139l);
        }
    }

    private void k() {
        if (this.b == null) {
            ActionMenuView actionMenuView = new ActionMenuView(getContext());
            this.b = actionMenuView;
            actionMenuView.setPopupTheme(this.f140m);
            this.b.setOnMenuItemClickListener(this.J);
            this.b.M(this.N, this.O);
            e eVarGenerateDefaultLayoutParams = generateDefaultLayoutParams();
            eVarGenerateDefaultLayoutParams.a = 8388613 | (this.p & InvokeCmd.CMD_SYSTEMCTRL_GET_AENA_STATE);
            this.b.setLayoutParams(eVarGenerateDefaultLayoutParams);
            c(this.b, false);
        }
    }

    private void l() {
        if (this.f == null) {
            this.f = new m(getContext(), null, g.a.a.toolbarNavigationButtonStyle);
            e eVarGenerateDefaultLayoutParams = generateDefaultLayoutParams();
            eVarGenerateDefaultLayoutParams.a = 8388611 | (this.p & InvokeCmd.CMD_SYSTEMCTRL_GET_AENA_STATE);
            this.f.setLayoutParams(eVarGenerateDefaultLayoutParams);
        }
    }

    private int p(int i2) {
        int iF = g.e.j.o.f(this);
        int iA = g.e.j.c.a(i2, iF) & 7;
        return (iA == 1 || iA == 3 || iA == 5) ? iA : iF == 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 & InvokeCmd.CMD_SYSTEMCTRL_GET_AENA_STATE;
        return (i3 == 16 || i3 == 48 || i3 == 80) ? i3 : this.y & InvokeCmd.CMD_SYSTEMCTRL_GET_AENA_STATE;
    }

    private int s(View view) {
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        return g.e.j.f.b(marginLayoutParams) + g.e.j.f.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.G.contains(view);
    }

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

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

    public void H(androidx.appcompat.view.menu.h hVar, androidx.appcompat.widget.c cVar) {
        if (hVar == null && this.b == null) {
            return;
        }
        k();
        androidx.appcompat.view.menu.h hVarL = this.b.L();
        if (hVarL == hVar) {
            return;
        }
        if (hVarL != null) {
            hVarL.O(this.L);
            hVarL.O(this.M);
        }
        if (this.M == null) {
            this.M = new d();
        }
        cVar.F(true);
        if (hVar != null) {
            hVar.c(cVar, this.f139l);
            hVar.c(this.M, this.f139l);
        } else {
            cVar.c(this.f139l, null);
            this.M.c(this.f139l, null);
            cVar.f(true);
            this.M.f(true);
        }
        this.b.setPopupTheme(this.f140m);
        this.b.setPresenter(cVar);
        this.L = cVar;
    }

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

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

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

    void a() {
        for (int size = this.G.size() - 1; size >= 0; size--) {
            addView(this.G.get(size));
        }
        this.G.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.b) != null && actionMenuView.I();
    }

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

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

    void g() {
        if (this.f137j == null) {
            m mVar = new m(getContext(), null, g.a.a.toolbarNavigationButtonStyle);
            this.f137j = mVar;
            mVar.setImageDrawable(this.f135h);
            this.f137j.setContentDescription(this.f136i);
            e eVarGenerateDefaultLayoutParams = generateDefaultLayoutParams();
            eVarGenerateDefaultLayoutParams.a = 8388611 | (this.p & InvokeCmd.CMD_SYSTEMCTRL_GET_AENA_STATE);
            eVarGenerateDefaultLayoutParams.b = 2;
            this.f137j.setLayoutParams(eVarGenerateDefaultLayoutParams);
            this.f137j.setOnClickListener(new c());
        }
    }

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

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

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

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

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

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

    public int getCurrentContentInsetEnd() {
        androidx.appcompat.view.menu.h hVarL;
        ActionMenuView actionMenuView = this.b;
        return actionMenuView != null && (hVarL = actionMenuView.L()) != null && hVarL.hasVisibleItems() ? Math.max(getContentInsetEnd(), Math.max(this.x, 0)) : getContentInsetEnd();
    }

    public int getCurrentContentInsetLeft() {
        return g.e.j.o.f(this) == 1 ? getCurrentContentInsetEnd() : getCurrentContentInsetStart();
    }

    public int getCurrentContentInsetRight() {
        return g.e.j.o.f(this) == 1 ? getCurrentContentInsetStart() : getCurrentContentInsetEnd();
    }

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

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

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

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

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

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

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

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

    Context getPopupContext() {
        return this.f139l;
    }

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

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

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

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

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

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

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

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

    /* 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.C0000a ? new e((a.C0000a) 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.Q);
    }

    @Override // android.view.View
    public boolean onHoverEvent(MotionEvent motionEvent) {
        int actionMasked = motionEvent.getActionMasked();
        if (actionMasked == 9) {
            this.E = false;
        }
        if (!this.E) {
            boolean zOnHoverEvent = super.onHoverEvent(motionEvent);
            if (actionMasked == 9 && !zOnHoverEvent) {
                this.E = true;
            }
        }
        if (actionMasked == 10 || actionMasked == 3) {
            this.E = 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.H;
        if (z0.b(this)) {
            c3 = 1;
            c2 = 0;
        } else {
            c2 = 1;
            c3 = 0;
        }
        if (L(this.f)) {
            D(this.f, i2, 0, i3, 0, this.q);
            measuredWidth = this.f.getMeasuredWidth() + s(this.f);
            iMax = Math.max(0, this.f.getMeasuredHeight() + t(this.f));
            iCombineMeasuredStates = View.combineMeasuredStates(0, this.f.getMeasuredState());
        } else {
            measuredWidth = 0;
            iMax = 0;
            iCombineMeasuredStates = 0;
        }
        if (L(this.f137j)) {
            D(this.f137j, i2, 0, i3, 0, this.q);
            measuredWidth = this.f137j.getMeasuredWidth() + s(this.f137j);
            iMax = Math.max(iMax, this.f137j.getMeasuredHeight() + t(this.f137j));
            iCombineMeasuredStates = View.combineMeasuredStates(iCombineMeasuredStates, this.f137j.getMeasuredState());
        }
        int currentContentInsetStart = getCurrentContentInsetStart();
        int iMax3 = 0 + Math.max(currentContentInsetStart, measuredWidth);
        iArr[c3] = Math.max(0, currentContentInsetStart - measuredWidth);
        if (L(this.b)) {
            D(this.b, i2, iMax3, i3, 0, this.q);
            measuredWidth2 = this.b.getMeasuredWidth() + s(this.b);
            iMax = Math.max(iMax, this.b.getMeasuredHeight() + t(this.b));
            iCombineMeasuredStates = View.combineMeasuredStates(iCombineMeasuredStates, this.b.getMeasuredState());
        } else {
            measuredWidth2 = 0;
        }
        int currentContentInsetEnd = getCurrentContentInsetEnd();
        int iMax4 = iMax3 + Math.max(currentContentInsetEnd, measuredWidth2);
        iArr[c2] = Math.max(0, currentContentInsetEnd - measuredWidth2);
        if (L(this.f138k)) {
            iMax4 += C(this.f138k, i2, iMax4, i3, 0, iArr);
            iMax = Math.max(iMax, this.f138k.getMeasuredHeight() + t(this.f138k));
            iCombineMeasuredStates = View.combineMeasuredStates(iCombineMeasuredStates, this.f138k.getMeasuredState());
        }
        if (L(this.f134g)) {
            iMax4 += C(this.f134g, i2, iMax4, i3, 0, iArr);
            iMax = Math.max(iMax, this.f134g.getMeasuredHeight() + t(this.f134g));
            iCombineMeasuredStates = View.combineMeasuredStates(iCombineMeasuredStates, this.f134g.getMeasuredState());
        }
        int childCount = getChildCount();
        for (int i4 = 0; i4 < childCount; i4++) {
            View childAt = getChildAt(i4);
            if (((e) childAt.getLayoutParams()).b == 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.t + this.u;
        int i6 = this.r + this.s;
        if (L(this.d)) {
            C(this.d, i2, iMax4 + i6, i3, i5, iArr);
            int measuredWidth3 = this.d.getMeasuredWidth() + s(this.d);
            measuredHeight = this.d.getMeasuredHeight() + t(this.d);
            iCombineMeasuredStates2 = View.combineMeasuredStates(iCombineMeasuredStates, this.d.getMeasuredState());
            iMax2 = measuredWidth3;
        } else {
            measuredHeight = 0;
            iCombineMeasuredStates2 = iCombineMeasuredStates;
            iMax2 = 0;
        }
        if (L(this.e)) {
            iMax2 = Math.max(iMax2, C(this.e, i2, iMax4 + i6, i3, measuredHeight + i5, iArr));
            measuredHeight += this.e.getMeasuredHeight() + t(this.e);
            iCombineMeasuredStates2 = View.combineMeasuredStates(iCombineMeasuredStates2, this.e.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.b;
        androidx.appcompat.view.menu.h hVarL = actionMenuView != null ? actionMenuView.L() : null;
        int i2 = gVar.e;
        if (i2 != 0 && this.M != null && hVarL != null && (menuItemFindItem = hVarL.findItem(i2)) != null) {
            menuItemFindItem.expandActionView();
        }
        if (gVar.f) {
            E();
        }
    }

    @Override // android.view.View
    public void onRtlPropertiesChanged(int i2) {
        if (Build.VERSION.SDK_INT >= 17) {
            super.onRtlPropertiesChanged(i2);
        }
        h();
        this.v.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.M;
        if (dVar != null && (jVar = dVar.d) != null) {
            gVar.e = jVar.getItemId();
        }
        gVar.f = z();
        return gVar;
    }

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

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

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

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

    public void setLogo(int i2) {
        setLogo(g.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(g.a.k.a.a.d(getContext(), i2));
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    public static class e extends a.C0000a {
        int b;

        public e(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
            this.b = 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.b = 0;
            this.a = 8388627;
        }

        public e(e eVar) {
            super((a.C0000a) eVar);
            this.b = 0;
            this.b = eVar.b;
        }

        public e(a.C0000a c0000a) {
            super(c0000a);
            this.b = 0;
        }

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

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

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

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

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

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

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

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

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

    public static class g extends g.g.a.a {
        public static final Parcelable.Creator<g> CREATOR = new a();
        int e;
        boolean f;

        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.e = parcel.readInt();
            this.f = parcel.readInt() != 0;
        }

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

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