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.view.menu.g;
import androidx.appcompat.view.menu.m;
import androidx.appcompat.widget.ActionMenuView;
import com.seewo.libmcuservice.constant.ITouchConstants;
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 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 j0 K;
    private androidx.appcompat.widget.c L;
    private d M;
    private m.a N;
    private g.a O;
    private boolean P;
    private final Runnable Q;

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

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

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private ImageView f513g;
    private Drawable h;
    private CharSequence i;
    ImageButton j;
    View k;
    private Context l;
    private int m;
    private int n;
    private int o;
    int p;
    private int q;
    private int r;
    private int s;
    private int t;
    private int u;
    private a0 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.G();
        }
    }

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

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

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

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        androidx.appcompat.view.menu.g f517c;

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

        d() {
        }

        @Override // androidx.appcompat.view.menu.m
        public void a(androidx.appcompat.view.menu.g gVar, boolean z) {
        }

        @Override // androidx.appcompat.view.menu.m
        public void b(boolean z) {
            if (this.f518d != null) {
                androidx.appcompat.view.menu.g gVar = this.f517c;
                boolean z2 = false;
                if (gVar != null) {
                    int size = gVar.size();
                    int i = 0;
                    while (true) {
                        if (i >= size) {
                            break;
                        }
                        if (this.f517c.getItem(i) == this.f518d) {
                            z2 = true;
                            break;
                        }
                        i++;
                    }
                }
                if (z2) {
                    return;
                }
                d(this.f517c, this.f518d);
            }
        }

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

        @Override // androidx.appcompat.view.menu.m
        public boolean d(androidx.appcompat.view.menu.g gVar, androidx.appcompat.view.menu.h hVar) {
            KeyEvent.Callback callback = Toolbar.this.k;
            if (callback instanceof a.a.m.b) {
                ((a.a.m.b) callback).c();
            }
            Toolbar toolbar = Toolbar.this;
            toolbar.removeView(toolbar.k);
            Toolbar toolbar2 = Toolbar.this;
            toolbar2.removeView(toolbar2.j);
            Toolbar toolbar3 = Toolbar.this;
            toolbar3.k = null;
            toolbar3.a();
            this.f518d = null;
            Toolbar.this.requestLayout();
            hVar.r(false);
            return true;
        }

        @Override // androidx.appcompat.view.menu.m
        public boolean f(androidx.appcompat.view.menu.g gVar, androidx.appcompat.view.menu.h hVar) {
            Toolbar.this.e();
            ViewParent parent = Toolbar.this.j.getParent();
            Toolbar toolbar = Toolbar.this;
            if (parent != toolbar) {
                if (parent instanceof ViewGroup) {
                    ((ViewGroup) parent).removeView(toolbar.j);
                }
                Toolbar toolbar2 = Toolbar.this;
                toolbar2.addView(toolbar2.j);
            }
            Toolbar.this.k = hVar.getActionView();
            this.f518d = hVar;
            ViewParent parent2 = Toolbar.this.k.getParent();
            Toolbar toolbar3 = Toolbar.this;
            if (parent2 != toolbar3) {
                if (parent2 instanceof ViewGroup) {
                    ((ViewGroup) parent2).removeView(toolbar3.k);
                }
                e eVarGenerateDefaultLayoutParams = Toolbar.this.generateDefaultLayoutParams();
                Toolbar toolbar4 = Toolbar.this;
                eVarGenerateDefaultLayoutParams.f372a = 8388611 | (toolbar4.p & ITouchConstants.ACTION_OUT_GET_CAP_TOUCH_UPGRADE_ACK);
                eVarGenerateDefaultLayoutParams.f520b = 2;
                toolbar4.k.setLayoutParams(eVarGenerateDefaultLayoutParams);
                Toolbar toolbar5 = Toolbar.this;
                toolbar5.addView(toolbar5.k);
            }
            Toolbar.this.A();
            Toolbar.this.requestLayout();
            hVar.r(true);
            KeyEvent.Callback callback = Toolbar.this.k;
            if (callback instanceof a.a.m.b) {
                ((a.a.m.b) callback).b();
            }
            return true;
        }

        @Override // androidx.appcompat.view.menu.m
        public void j(Context context, androidx.appcompat.view.menu.g gVar) {
            androidx.appcompat.view.menu.h hVar;
            androidx.appcompat.view.menu.g gVar2 = this.f517c;
            if (gVar2 != null && (hVar = this.f518d) != null) {
                gVar2.e(hVar);
            }
            this.f517c = gVar;
        }

        @Override // androidx.appcompat.view.menu.m
        public boolean l(androidx.appcompat.view.menu.s sVar) {
            return false;
        }
    }

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

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

    private boolean E() {
        if (!this.P) {
            return false;
        }
        int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            View childAt = getChildAt(i);
            if (F(childAt) && childAt.getMeasuredWidth() > 0 && childAt.getMeasuredHeight() > 0) {
                return false;
            }
        }
        return true;
    }

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

    private void b(List<View> list, int i) {
        boolean z = a.c.i.l.c(this) == 1;
        int childCount = getChildCount();
        int iA = a.c.i.c.a(i, a.c.i.l.c(this));
        list.clear();
        if (!z) {
            for (int i2 = 0; i2 < childCount; i2++) {
                View childAt = getChildAt(i2);
                e eVar = (e) childAt.getLayoutParams();
                if (eVar.f520b == 0 && F(childAt) && n(eVar.f372a) == iA) {
                    list.add(childAt);
                }
            }
            return;
        }
        for (int i3 = childCount - 1; i3 >= 0; i3--) {
            View childAt2 = getChildAt(i3);
            e eVar2 = (e) childAt2.getLayoutParams();
            if (eVar2.f520b == 0 && F(childAt2) && n(eVar2.f372a) == 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.f520b = 1;
        if (!z || this.k == null) {
            addView(view, eVarGenerateDefaultLayoutParams);
        } else {
            view.setLayoutParams(eVarGenerateDefaultLayoutParams);
            this.G.add(view);
        }
    }

    private void f() {
        if (this.v == null) {
            this.v = new a0();
        }
    }

    private void g() {
        if (this.f513g == null) {
            this.f513g = new k(getContext());
        }
    }

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

    private void h() {
        i();
        if (this.f509c.I() == null) {
            androidx.appcompat.view.menu.g gVar = (androidx.appcompat.view.menu.g) this.f509c.getMenu();
            if (this.M == null) {
                this.M = new d();
            }
            this.f509c.setExpandedActionViewsExclusive(true);
            gVar.b(this.M, this.l);
        }
    }

    private void i() {
        if (this.f509c == null) {
            ActionMenuView actionMenuView = new ActionMenuView(getContext());
            this.f509c = actionMenuView;
            actionMenuView.setPopupTheme(this.m);
            this.f509c.setOnMenuItemClickListener(this.J);
            this.f509c.J(this.N, this.O);
            e eVarGenerateDefaultLayoutParams = generateDefaultLayoutParams();
            eVarGenerateDefaultLayoutParams.f372a = 8388613 | (this.p & ITouchConstants.ACTION_OUT_GET_CAP_TOUCH_UPGRADE_ACK);
            this.f509c.setLayoutParams(eVarGenerateDefaultLayoutParams);
            c(this.f509c, false);
        }
    }

    private void j() {
        if (this.f512f == null) {
            this.f512f = new i(getContext(), null, a.a.a.u);
            e eVarGenerateDefaultLayoutParams = generateDefaultLayoutParams();
            eVarGenerateDefaultLayoutParams.f372a = 8388611 | (this.p & ITouchConstants.ACTION_OUT_GET_CAP_TOUCH_UPGRADE_ACK);
            this.f512f.setLayoutParams(eVarGenerateDefaultLayoutParams);
        }
    }

    private int n(int i) {
        int iC = a.c.i.l.c(this);
        int iA = a.c.i.c.a(i, iC) & 7;
        return (iA == 1 || iA == 3 || iA == 5) ? iA : iC == 1 ? 5 : 3;
    }

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

    private int p(int i) {
        int i2 = i & ITouchConstants.ACTION_OUT_GET_CAP_TOUCH_UPGRADE_ACK;
        return (i2 == 16 || i2 == 48 || i2 == 80) ? i2 : this.y & ITouchConstants.ACTION_OUT_GET_CAP_TOUCH_UPGRADE_ACK;
    }

    private int q(View view) {
        ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
        return a.c.i.d.b(marginLayoutParams) + a.c.i.d.a(marginLayoutParams);
    }

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

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

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

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

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

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

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

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

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

    public void B(int i, int i2) {
        f();
        this.v.g(i, i2);
    }

    public void C(Context context, int i) {
        this.o = i;
        TextView textView = this.f511e;
        if (textView != null) {
            textView.setTextAppearance(context, i);
        }
    }

    public void D(Context context, int i) {
        this.n = i;
        TextView textView = this.f510d;
        if (textView != null) {
            textView.setTextAppearance(context, i);
        }
    }

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

    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 void d() {
        d dVar = this.M;
        androidx.appcompat.view.menu.h hVar = dVar == null ? null : dVar.f518d;
        if (hVar != null) {
            hVar.collapseActionView();
        }
    }

    void e() {
        if (this.j == null) {
            i iVar = new i(getContext(), null, a.a.a.u);
            this.j = iVar;
            iVar.setImageDrawable(this.h);
            this.j.setContentDescription(this.i);
            e eVarGenerateDefaultLayoutParams = generateDefaultLayoutParams();
            eVarGenerateDefaultLayoutParams.f372a = 8388611 | (this.p & ITouchConstants.ACTION_OUT_GET_CAP_TOUCH_UPGRADE_ACK);
            eVarGenerateDefaultLayoutParams.f520b = 2;
            this.j.setLayoutParams(eVarGenerateDefaultLayoutParams);
            this.j.setOnClickListener(new c());
        }
    }

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

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

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

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

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

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

    public int getCurrentContentInsetEnd() {
        androidx.appcompat.view.menu.g gVarI;
        ActionMenuView actionMenuView = this.f509c;
        return actionMenuView != null && (gVarI = actionMenuView.I()) != null && gVarI.hasVisibleItems() ? Math.max(getContentInsetEnd(), Math.max(this.x, 0)) : getContentInsetEnd();
    }

    public int getCurrentContentInsetLeft() {
        return a.c.i.l.c(this) == 1 ? getCurrentContentInsetEnd() : getCurrentContentInsetStart();
    }

    public int getCurrentContentInsetRight() {
        return a.c.i.l.c(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.f513g;
        if (imageView != null) {
            return imageView.getDrawable();
        }
        return null;
    }

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

    public Menu getMenu() {
        h();
        return this.f509c.getMenu();
    }

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

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

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

    public Drawable getOverflowIcon() {
        h();
        return this.f509c.getOverflowIcon();
    }

    Context getPopupContext() {
        return this.l;
    }

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

    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 q getWrapper() {
        if (this.K == null) {
            this.K = new j0(this, true);
        }
        return this.K;
    }

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

    @Override // android.view.ViewGroup
    /* JADX INFO: renamed from: l, 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: m, reason: merged with bridge method [inline-methods] */
    public e generateLayoutParams(ViewGroup.LayoutParams layoutParams) {
        return layoutParams instanceof e ? new e((e) layoutParams) : layoutParams instanceof androidx.appcompat.app.a ? new e((androidx.appcompat.app.a) 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:0x029f A[LOOP:0: B:104:0x029d->B:105:0x029f, LOOP_END] */
    /* JADX WARN: Removed duplicated region for block: B:108:0x02c1 A[LOOP:1: B:107:0x02bf->B:108:0x02c1, LOOP_END] */
    /* JADX WARN: Removed duplicated region for block: B:112:0x02eb  */
    /* JADX WARN: Removed duplicated region for block: B:117:0x02fa A[LOOP:2: B:116:0x02f8->B:117:0x02fa, 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:0x0227  */
    @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: 783
            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 i, int i2) {
        char c2;
        char c3;
        int measuredWidth;
        int iMax;
        int iCombineMeasuredStates;
        int measuredWidth2;
        int measuredHeight;
        int iCombineMeasuredStates2;
        int iMax2;
        int[] iArr = this.H;
        if (o0.b(this)) {
            c3 = 1;
            c2 = 0;
        } else {
            c2 = 1;
            c3 = 0;
        }
        if (F(this.f512f)) {
            y(this.f512f, i, 0, i2, 0, this.q);
            measuredWidth = this.f512f.getMeasuredWidth() + q(this.f512f);
            iMax = Math.max(0, this.f512f.getMeasuredHeight() + r(this.f512f));
            iCombineMeasuredStates = View.combineMeasuredStates(0, this.f512f.getMeasuredState());
        } else {
            measuredWidth = 0;
            iMax = 0;
            iCombineMeasuredStates = 0;
        }
        if (F(this.j)) {
            y(this.j, i, 0, i2, 0, this.q);
            measuredWidth = this.j.getMeasuredWidth() + q(this.j);
            iMax = Math.max(iMax, this.j.getMeasuredHeight() + r(this.j));
            iCombineMeasuredStates = View.combineMeasuredStates(iCombineMeasuredStates, this.j.getMeasuredState());
        }
        int currentContentInsetStart = getCurrentContentInsetStart();
        int iMax3 = 0 + Math.max(currentContentInsetStart, measuredWidth);
        iArr[c3] = Math.max(0, currentContentInsetStart - measuredWidth);
        if (F(this.f509c)) {
            y(this.f509c, i, iMax3, i2, 0, this.q);
            measuredWidth2 = this.f509c.getMeasuredWidth() + q(this.f509c);
            iMax = Math.max(iMax, this.f509c.getMeasuredHeight() + r(this.f509c));
            iCombineMeasuredStates = View.combineMeasuredStates(iCombineMeasuredStates, this.f509c.getMeasuredState());
        } else {
            measuredWidth2 = 0;
        }
        int currentContentInsetEnd = getCurrentContentInsetEnd();
        int iMax4 = iMax3 + Math.max(currentContentInsetEnd, measuredWidth2);
        iArr[c2] = Math.max(0, currentContentInsetEnd - measuredWidth2);
        if (F(this.k)) {
            iMax4 += x(this.k, i, iMax4, i2, 0, iArr);
            iMax = Math.max(iMax, this.k.getMeasuredHeight() + r(this.k));
            iCombineMeasuredStates = View.combineMeasuredStates(iCombineMeasuredStates, this.k.getMeasuredState());
        }
        if (F(this.f513g)) {
            iMax4 += x(this.f513g, i, iMax4, i2, 0, iArr);
            iMax = Math.max(iMax, this.f513g.getMeasuredHeight() + r(this.f513g));
            iCombineMeasuredStates = View.combineMeasuredStates(iCombineMeasuredStates, this.f513g.getMeasuredState());
        }
        int childCount = getChildCount();
        for (int i3 = 0; i3 < childCount; i3++) {
            View childAt = getChildAt(i3);
            if (((e) childAt.getLayoutParams()).f520b == 0 && F(childAt)) {
                iMax4 += x(childAt, i, iMax4, i2, 0, iArr);
                iMax = Math.max(iMax, childAt.getMeasuredHeight() + r(childAt));
                iCombineMeasuredStates = View.combineMeasuredStates(iCombineMeasuredStates, childAt.getMeasuredState());
            }
        }
        int i4 = this.t + this.u;
        int i5 = this.r + this.s;
        if (F(this.f510d)) {
            x(this.f510d, i, iMax4 + i5, i2, i4, iArr);
            int measuredWidth3 = this.f510d.getMeasuredWidth() + q(this.f510d);
            measuredHeight = this.f510d.getMeasuredHeight() + r(this.f510d);
            iCombineMeasuredStates2 = View.combineMeasuredStates(iCombineMeasuredStates, this.f510d.getMeasuredState());
            iMax2 = measuredWidth3;
        } else {
            measuredHeight = 0;
            iCombineMeasuredStates2 = iCombineMeasuredStates;
            iMax2 = 0;
        }
        if (F(this.f511e)) {
            iMax2 = Math.max(iMax2, x(this.f511e, i, iMax4 + i5, i2, measuredHeight + i4, iArr));
            measuredHeight += this.f511e.getMeasuredHeight() + r(this.f511e);
            iCombineMeasuredStates2 = View.combineMeasuredStates(iCombineMeasuredStates2, this.f511e.getMeasuredState());
        }
        setMeasuredDimension(View.resolveSizeAndState(Math.max(iMax4 + iMax2 + getPaddingLeft() + getPaddingRight(), getSuggestedMinimumWidth()), i, (-16777216) & iCombineMeasuredStates2), E() ? 0 : View.resolveSizeAndState(Math.max(Math.max(iMax, measuredHeight) + getPaddingTop() + getPaddingBottom(), getSuggestedMinimumHeight()), i2, 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.f509c;
        androidx.appcompat.view.menu.g gVarI = actionMenuView != null ? actionMenuView.I() : null;
        int i = gVar.f521e;
        if (i != 0 && this.M != null && gVarI != null && (menuItemFindItem = gVarI.findItem(i)) != null) {
            menuItemFindItem.expandActionView();
        }
        if (gVar.f522f) {
            z();
        }
    }

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

    @Override // android.view.View
    protected Parcelable onSaveInstanceState() {
        androidx.appcompat.view.menu.h hVar;
        g gVar = new g(super.onSaveInstanceState());
        d dVar = this.M;
        if (dVar != null && (hVar = dVar.f518d) != null) {
            gVar.f521e = hVar.getItemId();
        }
        gVar.f522f = u();
        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 i) {
        if (i < 0) {
            i = Integer.MIN_VALUE;
        }
        if (i != this.x) {
            this.x = i;
            if (getNavigationIcon() != null) {
                requestLayout();
            }
        }
    }

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

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

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

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

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

    public void setNavigationOnClickListener(View.OnClickListener onClickListener) {
        j();
        this.f512f.setOnClickListener(onClickListener);
    }

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

    public void setOverflowIcon(Drawable drawable) {
        h();
        this.f509c.setOverflowIcon(drawable);
    }

    public void setPopupTheme(int i) {
        if (this.m != i) {
            this.m = i;
            if (i == 0) {
                this.l = getContext();
            } else {
                this.l = new ContextThemeWrapper(getContext(), i);
            }
        }
    }

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

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

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

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

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

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

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

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

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

    public static class e extends androidx.appcompat.app.a {

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

        public e(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
            this.f520b = 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 i, int i2) {
            super(i, i2);
            this.f520b = 0;
            this.f372a = 8388627;
        }

        public e(e eVar) {
            super((androidx.appcompat.app.a) eVar);
            this.f520b = 0;
            this.f520b = eVar.f520b;
        }

        public e(androidx.appcompat.app.a aVar) {
            super(aVar);
            this.f520b = 0;
        }

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

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

    public Toolbar(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.y = 8388627;
        this.F = new ArrayList<>();
        this.G = new ArrayList<>();
        this.H = new int[2];
        this.J = new a();
        this.Q = new b();
        i0 i0VarS = i0.s(getContext(), attributeSet, a.a.j.t2, i, 0);
        this.n = i0VarS.l(a.a.j.U2, 0);
        this.o = i0VarS.l(a.a.j.L2, 0);
        this.y = i0VarS.j(a.a.j.u2, this.y);
        this.p = i0VarS.j(a.a.j.v2, 48);
        int iD = i0VarS.d(a.a.j.O2, 0);
        int i2 = a.a.j.T2;
        iD = i0VarS.p(i2) ? i0VarS.d(i2, iD) : iD;
        this.u = iD;
        this.t = iD;
        this.s = iD;
        this.r = iD;
        int iD2 = i0VarS.d(a.a.j.R2, -1);
        if (iD2 >= 0) {
            this.r = iD2;
        }
        int iD3 = i0VarS.d(a.a.j.Q2, -1);
        if (iD3 >= 0) {
            this.s = iD3;
        }
        int iD4 = i0VarS.d(a.a.j.S2, -1);
        if (iD4 >= 0) {
            this.t = iD4;
        }
        int iD5 = i0VarS.d(a.a.j.P2, -1);
        if (iD5 >= 0) {
            this.u = iD5;
        }
        this.q = i0VarS.e(a.a.j.G2, -1);
        int iD6 = i0VarS.d(a.a.j.C2, Integer.MIN_VALUE);
        int iD7 = i0VarS.d(a.a.j.y2, Integer.MIN_VALUE);
        int iE = i0VarS.e(a.a.j.A2, 0);
        int iE2 = i0VarS.e(a.a.j.B2, 0);
        f();
        this.v.e(iE, iE2);
        if (iD6 != Integer.MIN_VALUE || iD7 != Integer.MIN_VALUE) {
            this.v.g(iD6, iD7);
        }
        this.w = i0VarS.d(a.a.j.D2, Integer.MIN_VALUE);
        this.x = i0VarS.d(a.a.j.z2, Integer.MIN_VALUE);
        this.h = i0VarS.f(a.a.j.x2);
        this.i = i0VarS.n(a.a.j.w2);
        CharSequence charSequenceN = i0VarS.n(a.a.j.N2);
        if (!TextUtils.isEmpty(charSequenceN)) {
            setTitle(charSequenceN);
        }
        CharSequence charSequenceN2 = i0VarS.n(a.a.j.K2);
        if (!TextUtils.isEmpty(charSequenceN2)) {
            setSubtitle(charSequenceN2);
        }
        this.l = getContext();
        setPopupTheme(i0VarS.l(a.a.j.J2, 0));
        Drawable drawableF = i0VarS.f(a.a.j.I2);
        if (drawableF != null) {
            setNavigationIcon(drawableF);
        }
        CharSequence charSequenceN3 = i0VarS.n(a.a.j.H2);
        if (!TextUtils.isEmpty(charSequenceN3)) {
            setNavigationContentDescription(charSequenceN3);
        }
        Drawable drawableF2 = i0VarS.f(a.a.j.E2);
        if (drawableF2 != null) {
            setLogo(drawableF2);
        }
        CharSequence charSequenceN4 = i0VarS.n(a.a.j.F2);
        if (!TextUtils.isEmpty(charSequenceN4)) {
            setLogoDescription(charSequenceN4);
        }
        int i3 = a.a.j.V2;
        if (i0VarS.p(i3)) {
            setTitleTextColor(i0VarS.b(i3, -1));
        }
        int i4 = a.a.j.M2;
        if (i0VarS.p(i4)) {
            setSubtitleTextColor(i0VarS.b(i4, -1));
        }
        i0VarS.t();
    }

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

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

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

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

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

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

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

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

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

        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 i) {
                return new g[i];
            }
        }

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

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

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