package android.support.v7.widget;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.v7.app.a;
import android.support.v7.view.menu.h;
import android.support.v7.view.menu.o;
import android.support.v7.widget.ActionMenuView;
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 java.util.ArrayList;
import java.util.List;

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

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

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

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

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

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

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

        @Override // android.support.v7.widget.ActionMenuView.e
        public boolean onMenuItemClick(MenuItem menuItem) {
            f fVar = Toolbar.this.H;
            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 android.support.v7.view.menu.o {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        android.support.v7.view.menu.h f982b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        android.support.v7.view.menu.j f983c;

        d() {
        }

        @Override // android.support.v7.view.menu.o
        public void a(android.support.v7.view.menu.h hVar, boolean z) {
        }

        @Override // android.support.v7.view.menu.o
        public boolean b(android.support.v7.view.menu.u uVar) {
            return false;
        }

        @Override // android.support.v7.view.menu.o
        public boolean d() {
            return false;
        }

        @Override // android.support.v7.view.menu.o
        public boolean e(android.support.v7.view.menu.h hVar, android.support.v7.view.menu.j jVar) {
            KeyEvent.Callback callback = Toolbar.this.j;
            if (callback instanceof a.b.d.d.c) {
                ((a.b.d.d.c) callback).d();
            }
            Toolbar toolbar = Toolbar.this;
            toolbar.removeView(toolbar.j);
            Toolbar toolbar2 = Toolbar.this;
            toolbar2.removeView(toolbar2.i);
            Toolbar toolbar3 = Toolbar.this;
            toolbar3.j = null;
            toolbar3.a();
            this.f983c = null;
            Toolbar.this.requestLayout();
            jVar.r(false);
            return true;
        }

        @Override // android.support.v7.view.menu.o
        public void f(o.a aVar) {
        }

        @Override // android.support.v7.view.menu.o
        public void g(Context context, android.support.v7.view.menu.h hVar) {
            android.support.v7.view.menu.j jVar;
            android.support.v7.view.menu.h hVar2 = this.f982b;
            if (hVar2 != null && (jVar = this.f983c) != null) {
                hVar2.f(jVar);
            }
            this.f982b = hVar;
        }

        @Override // android.support.v7.view.menu.o
        public boolean j(android.support.v7.view.menu.h hVar, android.support.v7.view.menu.j jVar) {
            Toolbar.this.g();
            ViewParent parent = Toolbar.this.i.getParent();
            Toolbar toolbar = Toolbar.this;
            if (parent != toolbar) {
                if (parent instanceof ViewGroup) {
                    ((ViewGroup) parent).removeView(toolbar.i);
                }
                Toolbar toolbar2 = Toolbar.this;
                toolbar2.addView(toolbar2.i);
            }
            Toolbar.this.j = jVar.getActionView();
            this.f983c = jVar;
            ViewParent parent2 = Toolbar.this.j.getParent();
            Toolbar toolbar3 = Toolbar.this;
            if (parent2 != toolbar3) {
                if (parent2 instanceof ViewGroup) {
                    ((ViewGroup) parent2).removeView(toolbar3.j);
                }
                e eVarGenerateDefaultLayoutParams = Toolbar.this.generateDefaultLayoutParams();
                Toolbar toolbar4 = Toolbar.this;
                eVarGenerateDefaultLayoutParams.f762a = 8388611 | (toolbar4.o & 112);
                eVarGenerateDefaultLayoutParams.f985b = 2;
                toolbar4.j.setLayoutParams(eVarGenerateDefaultLayoutParams);
                Toolbar toolbar5 = Toolbar.this;
                toolbar5.addView(toolbar5.j);
            }
            Toolbar.this.F();
            Toolbar.this.requestLayout();
            jVar.r(true);
            KeyEvent.Callback callback = Toolbar.this.j;
            if (callback instanceof a.b.d.d.c) {
                ((a.b.d.d.c) callback).b();
            }
            return true;
        }

        @Override // android.support.v7.view.menu.o
        public void k(boolean z) {
            if (this.f983c != null) {
                android.support.v7.view.menu.h hVar = this.f982b;
                boolean z2 = false;
                if (hVar != null) {
                    int size = hVar.size();
                    int i = 0;
                    while (true) {
                        if (i >= size) {
                            break;
                        }
                        if (this.f982b.getItem(i) == this.f983c) {
                            z2 = true;
                            break;
                        }
                        i++;
                    }
                }
                if (z2) {
                    return;
                }
                e(this.f982b, this.f983c);
            }
        }
    }

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

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

    private int A(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 iQ = q(view, i2);
        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 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 iQ = q(view, i2);
        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 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 D(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, 1073741824);
        }
        view.measure(childMeasureSpec, childMeasureSpec2);
    }

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

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

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

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

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

    private void j() {
        k();
        if (this.f974b.L() == null) {
            android.support.v7.view.menu.h hVar = (android.support.v7.view.menu.h) this.f974b.getMenu();
            if (this.L == null) {
                this.L = new d();
            }
            this.f974b.setExpandedActionViewsExclusive(true);
            hVar.c(this.L, this.k);
        }
    }

    private void k() {
        if (this.f974b == null) {
            ActionMenuView actionMenuView = new ActionMenuView(getContext());
            this.f974b = actionMenuView;
            actionMenuView.setPopupTheme(this.l);
            this.f974b.setOnMenuItemClickListener(this.I);
            this.f974b.M(this.M, this.N);
            e eVarGenerateDefaultLayoutParams = generateDefaultLayoutParams();
            eVarGenerateDefaultLayoutParams.f762a = 8388613 | (this.o & 112);
            this.f974b.setLayoutParams(eVarGenerateDefaultLayoutParams);
            c(this.f974b, false);
        }
    }

    private void l() {
        if (this.f977e == null) {
            this.f977e = new m(getContext(), null, a.b.d.a.a.toolbarNavigationButtonStyle);
            e eVarGenerateDefaultLayoutParams = generateDefaultLayoutParams();
            eVarGenerateDefaultLayoutParams.f762a = 8388611 | (this.o & 112);
            this.f977e.setLayoutParams(eVarGenerateDefaultLayoutParams);
        }
    }

    private int p(int i) {
        int iF = a.b.c.g.p.f(this);
        int iA = a.b.c.g.d.a(i, iF) & 7;
        return (iA == 1 || iA == 3 || iA == 5) ? iA : iF == 1 ? 5 : 3;
    }

    private int q(View view, int i) {
        e eVar = (e) view.getLayoutParams();
        int measuredHeight = view.getMeasuredHeight();
        int i2 = i > 0 ? (measuredHeight - i) / 2 : 0;
        int iR = r(eVar.f762a);
        if (iR == 48) {
            return getPaddingTop() - i2;
        }
        if (iR == 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 r(int i) {
        int i2 = i & 112;
        return (i2 == 16 || i2 == 48 || i2 == 80) ? i2 : this.x & 112;
    }

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

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

    private int u(List<View> list, int[] iArr) {
        int 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 x(View view) {
        return view.getParent() == this || this.F.contains(view);
    }

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

    public void G(int i, int i2) {
        h();
        this.u.g(i, i2);
    }

    public void H(android.support.v7.view.menu.h hVar, android.support.v7.widget.c cVar) {
        if (hVar == null && this.f974b == null) {
            return;
        }
        k();
        android.support.v7.view.menu.h hVarL = this.f974b.L();
        if (hVarL == hVar) {
            return;
        }
        if (hVarL != null) {
            hVarL.O(this.K);
            hVarL.O(this.L);
        }
        if (this.L == null) {
            this.L = new d();
        }
        cVar.F(true);
        if (hVar != null) {
            hVar.c(cVar, this.k);
            hVar.c(this.L, this.k);
        } else {
            cVar.g(this.k, null);
            this.L.g(this.k, null);
            cVar.k(true);
            this.L.k(true);
        }
        this.f974b.setPopupTheme(this.l);
        this.f974b.setPresenter(cVar);
        this.K = cVar;
    }

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

    public void J(Context context, int i) {
        this.m = i;
        TextView textView = this.f975c;
        if (textView != null) {
            textView.setTextAppearance(context, i);
        }
    }

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

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

    public void e() {
        d dVar = this.L;
        android.support.v7.view.menu.j jVar = dVar == null ? null : dVar.f983c;
        if (jVar != null) {
            jVar.collapseActionView();
        }
    }

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

    void g() {
        if (this.i == null) {
            m mVar = new m(getContext(), null, a.b.d.a.a.toolbarNavigationButtonStyle);
            this.i = mVar;
            mVar.setImageDrawable(this.g);
            this.i.setContentDescription(this.h);
            e eVarGenerateDefaultLayoutParams = generateDefaultLayoutParams();
            eVarGenerateDefaultLayoutParams.f762a = 8388611 | (this.o & 112);
            eVarGenerateDefaultLayoutParams.f985b = 2;
            this.i.setLayoutParams(eVarGenerateDefaultLayoutParams);
            this.i.setOnClickListener(new c());
        }
    }

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

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

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

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

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

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

    public int getCurrentContentInsetEnd() {
        android.support.v7.view.menu.h hVarL;
        ActionMenuView actionMenuView = this.f974b;
        return actionMenuView != null && (hVarL = actionMenuView.L()) != null && hVarL.hasVisibleItems() ? Math.max(getContentInsetEnd(), Math.max(this.w, 0)) : getContentInsetEnd();
    }

    public int getCurrentContentInsetLeft() {
        return a.b.c.g.p.f(this) == 1 ? getCurrentContentInsetEnd() : getCurrentContentInsetStart();
    }

    public int getCurrentContentInsetRight() {
        return a.b.c.g.p.f(this) == 1 ? getCurrentContentInsetStart() : getCurrentContentInsetEnd();
    }

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

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

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

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

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

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

    android.support.v7.widget.c getOuterActionMenuPresenter() {
        return this.K;
    }

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

    Context getPopupContext() {
        return this.k;
    }

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

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

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

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

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

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

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

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

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

    @Override // android.view.View
    public boolean onHoverEvent(MotionEvent motionEvent) {
        int actionMasked = motionEvent.getActionMasked();
        if (actionMasked == 9) {
            this.D = false;
        }
        if (!this.D) {
            boolean zOnHoverEvent = super.onHoverEvent(motionEvent);
            if (actionMasked == 9 && !zOnHoverEvent) {
                this.D = true;
            }
        }
        if (actionMasked == 10 || actionMasked == 3) {
            this.D = 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: android.support.v7.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.G;
        if (z0.b(this)) {
            c3 = 1;
            c2 = 0;
        } else {
            c2 = 1;
            c3 = 0;
        }
        if (L(this.f977e)) {
            D(this.f977e, i, 0, i2, 0, this.p);
            measuredWidth = this.f977e.getMeasuredWidth() + s(this.f977e);
            iMax = Math.max(0, this.f977e.getMeasuredHeight() + t(this.f977e));
            iCombineMeasuredStates = View.combineMeasuredStates(0, this.f977e.getMeasuredState());
        } else {
            measuredWidth = 0;
            iMax = 0;
            iCombineMeasuredStates = 0;
        }
        if (L(this.i)) {
            D(this.i, i, 0, i2, 0, this.p);
            measuredWidth = this.i.getMeasuredWidth() + s(this.i);
            iMax = Math.max(iMax, this.i.getMeasuredHeight() + t(this.i));
            iCombineMeasuredStates = View.combineMeasuredStates(iCombineMeasuredStates, this.i.getMeasuredState());
        }
        int currentContentInsetStart = getCurrentContentInsetStart();
        int iMax3 = 0 + Math.max(currentContentInsetStart, measuredWidth);
        iArr[c3] = Math.max(0, currentContentInsetStart - measuredWidth);
        if (L(this.f974b)) {
            D(this.f974b, i, iMax3, i2, 0, this.p);
            measuredWidth2 = this.f974b.getMeasuredWidth() + s(this.f974b);
            iMax = Math.max(iMax, this.f974b.getMeasuredHeight() + t(this.f974b));
            iCombineMeasuredStates = View.combineMeasuredStates(iCombineMeasuredStates, this.f974b.getMeasuredState());
        } else {
            measuredWidth2 = 0;
        }
        int currentContentInsetEnd = getCurrentContentInsetEnd();
        int iMax4 = iMax3 + Math.max(currentContentInsetEnd, measuredWidth2);
        iArr[c2] = Math.max(0, currentContentInsetEnd - measuredWidth2);
        if (L(this.j)) {
            iMax4 += C(this.j, i, iMax4, i2, 0, iArr);
            iMax = Math.max(iMax, this.j.getMeasuredHeight() + t(this.j));
            iCombineMeasuredStates = View.combineMeasuredStates(iCombineMeasuredStates, this.j.getMeasuredState());
        }
        if (L(this.f978f)) {
            iMax4 += C(this.f978f, i, iMax4, i2, 0, iArr);
            iMax = Math.max(iMax, this.f978f.getMeasuredHeight() + t(this.f978f));
            iCombineMeasuredStates = View.combineMeasuredStates(iCombineMeasuredStates, this.f978f.getMeasuredState());
        }
        int childCount = getChildCount();
        for (int i3 = 0; i3 < childCount; i3++) {
            View childAt = getChildAt(i3);
            if (((e) childAt.getLayoutParams()).f985b == 0 && L(childAt)) {
                iMax4 += C(childAt, i, iMax4, i2, 0, iArr);
                iMax = Math.max(iMax, childAt.getMeasuredHeight() + t(childAt));
                iCombineMeasuredStates = View.combineMeasuredStates(iCombineMeasuredStates, childAt.getMeasuredState());
            }
        }
        int i4 = this.s + this.t;
        int i5 = this.q + this.r;
        if (L(this.f975c)) {
            C(this.f975c, i, iMax4 + i5, i2, i4, iArr);
            int measuredWidth3 = this.f975c.getMeasuredWidth() + s(this.f975c);
            measuredHeight = this.f975c.getMeasuredHeight() + t(this.f975c);
            iCombineMeasuredStates2 = View.combineMeasuredStates(iCombineMeasuredStates, this.f975c.getMeasuredState());
            iMax2 = measuredWidth3;
        } else {
            measuredHeight = 0;
            iCombineMeasuredStates2 = iCombineMeasuredStates;
            iMax2 = 0;
        }
        if (L(this.f976d)) {
            iMax2 = Math.max(iMax2, C(this.f976d, i, iMax4 + i5, i2, measuredHeight + i4, iArr));
            measuredHeight += this.f976d.getMeasuredHeight() + t(this.f976d);
            iCombineMeasuredStates2 = View.combineMeasuredStates(iCombineMeasuredStates2, this.f976d.getMeasuredState());
        }
        setMeasuredDimension(View.resolveSizeAndState(Math.max(iMax4 + iMax2 + getPaddingLeft() + getPaddingRight(), getSuggestedMinimumWidth()), i, (-16777216) & iCombineMeasuredStates2), K() ? 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.f974b;
        android.support.v7.view.menu.h hVarL = actionMenuView != null ? actionMenuView.L() : null;
        int i = gVar.f986d;
        if (i != 0 && this.L != null && hVarL != null && (menuItemFindItem = hVarL.findItem(i)) != null) {
            menuItemFindItem.expandActionView();
        }
        if (gVar.f987e) {
            E();
        }
    }

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

    @Override // android.view.View
    protected Parcelable onSaveInstanceState() {
        android.support.v7.view.menu.j jVar;
        g gVar = new g(super.onSaveInstanceState());
        d dVar = this.L;
        if (dVar != null && (jVar = dVar.f983c) != null) {
            gVar.f986d = jVar.getItemId();
        }
        gVar.f987e = z();
        return gVar;
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    public static class e extends a.C0022a {

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

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

        public e(e eVar) {
            super((a.C0022a) eVar);
            this.f985b = 0;
            this.f985b = eVar.f985b;
        }

        public e(a.C0022a c0022a) {
            super(c0022a);
            this.f985b = 0;
        }

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

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

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

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

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

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

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

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

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

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

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

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

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

        @Override // a.b.c.g.a, android.os.Parcelable
        public void writeToParcel(Parcel parcel, int i) {
            super.writeToParcel(parcel, i);
            parcel.writeInt(this.f986d);
            parcel.writeInt(this.f987e ? 1 : 0);
        }

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