package android.support.v7.widget;

import android.R;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v7.view.menu.o;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.Window;

/* JADX INFO: compiled from: ToolbarWidgetWrapper.java */
/* JADX INFO: loaded from: classes.dex */
public class u0 implements b0 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    Toolbar f1131a;

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

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

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private Drawable f1136f;
    private Drawable g;
    private boolean h;
    CharSequence i;
    private CharSequence j;
    private CharSequence k;
    Window.Callback l;
    boolean m;
    private c n;
    private int o;
    private int p;
    private Drawable q;

    /* JADX INFO: compiled from: ToolbarWidgetWrapper.java */
    class a implements View.OnClickListener {

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

        a() {
            this.f1137b = new android.support.v7.view.menu.a(u0.this.f1131a.getContext(), 0, R.id.home, 0, 0, u0.this.i);
        }

        @Override // android.view.View.OnClickListener
        public void onClick(View view) {
            u0 u0Var = u0.this;
            Window.Callback callback = u0Var.l;
            if (callback == null || !u0Var.m) {
                return;
            }
            callback.onMenuItemSelected(0, this.f1137b);
        }
    }

    /* JADX INFO: compiled from: ToolbarWidgetWrapper.java */
    class b extends a.b.c.g.v {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private boolean f1139a = false;

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

        b(int i) {
            this.f1140b = i;
        }

        @Override // a.b.c.g.u
        public void a(View view) {
            if (this.f1139a) {
                return;
            }
            u0.this.f1131a.setVisibility(this.f1140b);
        }

        @Override // a.b.c.g.v, a.b.c.g.u
        public void b(View view) {
            u0.this.f1131a.setVisibility(0);
        }

        @Override // a.b.c.g.v, a.b.c.g.u
        public void c(View view) {
            this.f1139a = true;
        }
    }

    public u0(Toolbar toolbar, boolean z) {
        this(toolbar, z, a.b.d.a.h.abc_action_bar_up_description, a.b.d.a.e.abc_ic_ab_back_material);
    }

    private void F(CharSequence charSequence) {
        this.i = charSequence;
        if ((this.f1132b & 8) != 0) {
            this.f1131a.setTitle(charSequence);
        }
    }

    private void G() {
        if ((this.f1132b & 4) != 0) {
            if (TextUtils.isEmpty(this.k)) {
                this.f1131a.setNavigationContentDescription(this.p);
            } else {
                this.f1131a.setNavigationContentDescription(this.k);
            }
        }
    }

    private void H() {
        if ((this.f1132b & 4) == 0) {
            this.f1131a.setNavigationIcon((Drawable) null);
            return;
        }
        Toolbar toolbar = this.f1131a;
        Drawable drawable = this.g;
        if (drawable == null) {
            drawable = this.q;
        }
        toolbar.setNavigationIcon(drawable);
    }

    private void I() {
        Drawable drawable;
        int i = this.f1132b;
        if ((i & 2) == 0) {
            drawable = null;
        } else if ((i & 1) == 0 || (drawable = this.f1136f) == null) {
            drawable = this.f1135e;
        }
        this.f1131a.setLogo(drawable);
    }

    private int w() {
        if (this.f1131a.getNavigationIcon() == null) {
            return 11;
        }
        this.q = this.f1131a.getNavigationIcon();
        return 15;
    }

    public void A(int i) {
        B(i == 0 ? null : d().getString(i));
    }

    public void B(CharSequence charSequence) {
        this.k = charSequence;
        G();
    }

    public void C(Drawable drawable) {
        this.g = drawable;
        H();
    }

    public void D(CharSequence charSequence) {
        this.j = charSequence;
        if ((this.f1132b & 8) != 0) {
            this.f1131a.setSubtitle(charSequence);
        }
    }

    public void E(CharSequence charSequence) {
        this.h = true;
        F(charSequence);
    }

    @Override // android.support.v7.widget.b0
    public boolean a() {
        return this.f1131a.y();
    }

    @Override // android.support.v7.widget.b0
    public boolean b() {
        return this.f1131a.z();
    }

    @Override // android.support.v7.widget.b0
    public void c(Menu menu, o.a aVar) {
        if (this.n == null) {
            c cVar = new c(this.f1131a.getContext());
            this.n = cVar;
            cVar.p(a.b.d.a.f.action_menu_presenter);
        }
        this.n.f(aVar);
        this.f1131a.H((android.support.v7.view.menu.h) menu, this.n);
    }

    @Override // android.support.v7.widget.b0
    public void collapseActionView() {
        this.f1131a.e();
    }

    @Override // android.support.v7.widget.b0
    public Context d() {
        return this.f1131a.getContext();
    }

    @Override // android.support.v7.widget.b0
    public boolean e() {
        return this.f1131a.w();
    }

    @Override // android.support.v7.widget.b0
    public boolean f() {
        return this.f1131a.M();
    }

    @Override // android.support.v7.widget.b0
    public void g() {
        this.m = true;
    }

    @Override // android.support.v7.widget.b0
    public CharSequence getTitle() {
        return this.f1131a.getTitle();
    }

    @Override // android.support.v7.widget.b0
    public boolean h() {
        return this.f1131a.d();
    }

    @Override // android.support.v7.widget.b0
    public void i() {
        this.f1131a.f();
    }

    @Override // android.support.v7.widget.b0
    public int j() {
        return this.f1132b;
    }

    @Override // android.support.v7.widget.b0
    public void k(int i) {
        this.f1131a.setVisibility(i);
    }

    @Override // android.support.v7.widget.b0
    public void l(int i) {
        z(i != 0 ? a.b.d.b.a.a.d(d(), i) : null);
    }

    @Override // android.support.v7.widget.b0
    public ViewGroup m() {
        return this.f1131a;
    }

    @Override // android.support.v7.widget.b0
    public void n(boolean z) {
    }

    @Override // android.support.v7.widget.b0
    public int o() {
        return this.o;
    }

    @Override // android.support.v7.widget.b0
    public void p(m0 m0Var) {
        View view = this.f1133c;
        if (view != null) {
            ViewParent parent = view.getParent();
            Toolbar toolbar = this.f1131a;
            if (parent == toolbar) {
                toolbar.removeView(this.f1133c);
            }
        }
        this.f1133c = m0Var;
        if (m0Var == null || this.o != 2) {
            return;
        }
        this.f1131a.addView(m0Var, 0);
        Toolbar.e eVar = (Toolbar.e) this.f1133c.getLayoutParams();
        ((ViewGroup.MarginLayoutParams) eVar).width = -2;
        ((ViewGroup.MarginLayoutParams) eVar).height = -2;
        eVar.f762a = 8388691;
        m0Var.setAllowCollapse(true);
    }

    @Override // android.support.v7.widget.b0
    public a.b.c.g.t q(int i, long j) {
        a.b.c.g.t tVarA = a.b.c.g.p.a(this.f1131a);
        tVarA.a(i == 0 ? 1.0f : 0.0f);
        tVarA.d(j);
        tVarA.f(new b(i));
        return tVarA;
    }

    @Override // android.support.v7.widget.b0
    public void r() {
        Log.i("ToolbarWidgetWrapper", "Progress display unsupported");
    }

    @Override // android.support.v7.widget.b0
    public boolean s() {
        return this.f1131a.v();
    }

    @Override // android.support.v7.widget.b0
    public void setIcon(int i) {
        setIcon(i != 0 ? a.b.d.b.a.a.d(d(), i) : null);
    }

    @Override // android.support.v7.widget.b0
    public void setWindowCallback(Window.Callback callback) {
        this.l = callback;
    }

    @Override // android.support.v7.widget.b0
    public void setWindowTitle(CharSequence charSequence) {
        if (this.h) {
            return;
        }
        F(charSequence);
    }

    @Override // android.support.v7.widget.b0
    public void t() {
        Log.i("ToolbarWidgetWrapper", "Progress display unsupported");
    }

    @Override // android.support.v7.widget.b0
    public void u(boolean z) {
        this.f1131a.setCollapsible(z);
    }

    @Override // android.support.v7.widget.b0
    public void v(int i) {
        View view;
        int i2 = this.f1132b ^ i;
        this.f1132b = i;
        if (i2 != 0) {
            if ((i2 & 4) != 0) {
                if ((i & 4) != 0) {
                    G();
                }
                H();
            }
            if ((i2 & 3) != 0) {
                I();
            }
            if ((i2 & 8) != 0) {
                if ((i & 8) != 0) {
                    this.f1131a.setTitle(this.i);
                    this.f1131a.setSubtitle(this.j);
                } else {
                    this.f1131a.setTitle((CharSequence) null);
                    this.f1131a.setSubtitle((CharSequence) null);
                }
            }
            if ((i2 & 16) == 0 || (view = this.f1134d) == null) {
                return;
            }
            if ((i & 16) != 0) {
                this.f1131a.addView(view);
            } else {
                this.f1131a.removeView(view);
            }
        }
    }

    public void x(View view) {
        View view2 = this.f1134d;
        if (view2 != null && (this.f1132b & 16) != 0) {
            this.f1131a.removeView(view2);
        }
        this.f1134d = view;
        if (view == null || (this.f1132b & 16) == 0) {
            return;
        }
        this.f1131a.addView(view);
    }

    public void y(int i) {
        if (i == this.p) {
            return;
        }
        this.p = i;
        if (TextUtils.isEmpty(this.f1131a.getNavigationContentDescription())) {
            A(this.p);
        }
    }

    public void z(Drawable drawable) {
        this.f1136f = drawable;
        I();
    }

    public u0(Toolbar toolbar, boolean z, int i, int i2) {
        Drawable drawable;
        this.o = 0;
        this.p = 0;
        this.f1131a = toolbar;
        this.i = toolbar.getTitle();
        this.j = toolbar.getSubtitle();
        this.h = this.i != null;
        this.g = toolbar.getNavigationIcon();
        t0 t0VarT = t0.t(toolbar.getContext(), null, a.b.d.a.j.ActionBar, a.b.d.a.a.actionBarStyle, 0);
        this.q = t0VarT.f(a.b.d.a.j.ActionBar_homeAsUpIndicator);
        if (z) {
            CharSequence charSequenceO = t0VarT.o(a.b.d.a.j.ActionBar_title);
            if (!TextUtils.isEmpty(charSequenceO)) {
                E(charSequenceO);
            }
            CharSequence charSequenceO2 = t0VarT.o(a.b.d.a.j.ActionBar_subtitle);
            if (!TextUtils.isEmpty(charSequenceO2)) {
                D(charSequenceO2);
            }
            Drawable drawableF = t0VarT.f(a.b.d.a.j.ActionBar_logo);
            if (drawableF != null) {
                z(drawableF);
            }
            Drawable drawableF2 = t0VarT.f(a.b.d.a.j.ActionBar_icon);
            if (drawableF2 != null) {
                setIcon(drawableF2);
            }
            if (this.g == null && (drawable = this.q) != null) {
                C(drawable);
            }
            v(t0VarT.j(a.b.d.a.j.ActionBar_displayOptions, 0));
            int iM = t0VarT.m(a.b.d.a.j.ActionBar_customNavigationLayout, 0);
            if (iM != 0) {
                x(LayoutInflater.from(this.f1131a.getContext()).inflate(iM, (ViewGroup) this.f1131a, false));
                v(this.f1132b | 16);
            }
            int iL = t0VarT.l(a.b.d.a.j.ActionBar_height, 0);
            if (iL > 0) {
                ViewGroup.LayoutParams layoutParams = this.f1131a.getLayoutParams();
                layoutParams.height = iL;
                this.f1131a.setLayoutParams(layoutParams);
            }
            int iD = t0VarT.d(a.b.d.a.j.ActionBar_contentInsetStart, -1);
            int iD2 = t0VarT.d(a.b.d.a.j.ActionBar_contentInsetEnd, -1);
            if (iD >= 0 || iD2 >= 0) {
                this.f1131a.G(Math.max(iD, 0), Math.max(iD2, 0));
            }
            int iM2 = t0VarT.m(a.b.d.a.j.ActionBar_titleTextStyle, 0);
            if (iM2 != 0) {
                Toolbar toolbar2 = this.f1131a;
                toolbar2.J(toolbar2.getContext(), iM2);
            }
            int iM3 = t0VarT.m(a.b.d.a.j.ActionBar_subtitleTextStyle, 0);
            if (iM3 != 0) {
                Toolbar toolbar3 = this.f1131a;
                toolbar3.I(toolbar3.getContext(), iM3);
            }
            int iM4 = t0VarT.m(a.b.d.a.j.ActionBar_popupTheme, 0);
            if (iM4 != 0) {
                this.f1131a.setPopupTheme(iM4);
            }
        } else {
            this.f1132b = w();
        }
        t0VarT.u();
        y(i);
        this.k = this.f1131a.getNavigationContentDescription();
        this.f1131a.setNavigationOnClickListener(new a());
    }

    @Override // android.support.v7.widget.b0
    public void setIcon(Drawable drawable) {
        this.f1135e = drawable;
        I();
    }
}
