package android.support.v7.app;

import a.b.c.g.p;
import a.b.c.g.t;
import a.b.c.g.u;
import a.b.c.g.v;
import a.b.c.g.w;
import a.b.d.d.b;
import android.R;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.support.v7.app.a;
import android.support.v7.view.menu.h;
import android.support.v7.widget.ActionBarContainer;
import android.support.v7.widget.ActionBarContextView;
import android.support.v7.widget.ActionBarOverlayLayout;
import android.support.v7.widget.Toolbar;
import android.support.v7.widget.b0;
import android.support.v7.widget.m0;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import java.lang.ref.WeakReference;
import java.util.ArrayList;

/* JADX INFO: compiled from: WindowDecorActionBar.java */
/* JADX INFO: loaded from: classes.dex */
public class k extends android.support.v7.app.a implements ActionBarOverlayLayout.d {
    private static final Interpolator B = new AccelerateInterpolator();
    private static final Interpolator C = new DecelerateInterpolator();
    final w A;

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    ActionBarOverlayLayout f822c;

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    ActionBarContextView f825f;
    View g;
    m0 h;
    private boolean i;
    d j;
    a.b.d.d.b k;
    b.a l;
    private boolean m;
    private ArrayList<a.b> n;
    private boolean o;
    private int p;
    boolean q;
    boolean r;
    boolean s;
    private boolean t;
    private boolean u;
    a.b.d.d.h v;
    private boolean w;
    boolean x;
    final u y;
    final u z;

    /* JADX INFO: compiled from: WindowDecorActionBar.java */
    class a extends v {
        a() {
        }

        @Override // a.b.c.g.u
        public void a(View view) {
            View view2;
            k kVar = k.this;
            if (kVar.q && (view2 = kVar.g) != null) {
                view2.setTranslationY(0.0f);
                k.this.f823d.setTranslationY(0.0f);
            }
            k.this.f823d.setVisibility(8);
            k.this.f823d.setTransitioning(false);
            k kVar2 = k.this;
            kVar2.v = null;
            kVar2.x();
            ActionBarOverlayLayout actionBarOverlayLayout = k.this.f822c;
            if (actionBarOverlayLayout != null) {
                p.r(actionBarOverlayLayout);
            }
        }
    }

    /* JADX INFO: compiled from: WindowDecorActionBar.java */
    class b extends v {
        b() {
        }

        @Override // a.b.c.g.u
        public void a(View view) {
            k kVar = k.this;
            kVar.v = null;
            kVar.f823d.requestLayout();
        }
    }

    /* JADX INFO: compiled from: WindowDecorActionBar.java */
    class c implements w {
        c() {
        }

        @Override // a.b.c.g.w
        public void a(View view) {
            ((View) k.this.f823d.getParent()).invalidate();
        }
    }

    /* JADX INFO: compiled from: WindowDecorActionBar.java */
    public class d extends a.b.d.d.b implements h.a {

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        private final Context f829d;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        private final android.support.v7.view.menu.h f830e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        private b.a f831f;
        private WeakReference<View> g;

        public d(Context context, b.a aVar) {
            this.f829d = context;
            this.f831f = aVar;
            android.support.v7.view.menu.h hVar = new android.support.v7.view.menu.h(context);
            hVar.S(1);
            this.f830e = hVar;
            hVar.R(this);
        }

        @Override // android.support.v7.view.menu.h.a
        public void a(android.support.v7.view.menu.h hVar) {
            if (this.f831f == null) {
                return;
            }
            k();
            k.this.f825f.l();
        }

        @Override // android.support.v7.view.menu.h.a
        public boolean b(android.support.v7.view.menu.h hVar, MenuItem menuItem) {
            b.a aVar = this.f831f;
            if (aVar != null) {
                return aVar.b(this, menuItem);
            }
            return false;
        }

        @Override // a.b.d.d.b
        public void c() {
            k kVar = k.this;
            if (kVar.j != this) {
                return;
            }
            if (k.w(kVar.r, kVar.s, false)) {
                this.f831f.a(this);
            } else {
                k kVar2 = k.this;
                kVar2.k = this;
                kVar2.l = this.f831f;
            }
            this.f831f = null;
            k.this.v(false);
            k.this.f825f.g();
            k.this.f824e.m().sendAccessibilityEvent(32);
            k kVar3 = k.this;
            kVar3.f822c.setHideOnContentScrollEnabled(kVar3.x);
            k.this.j = null;
        }

        @Override // a.b.d.d.b
        public View d() {
            WeakReference<View> weakReference = this.g;
            if (weakReference != null) {
                return weakReference.get();
            }
            return null;
        }

        @Override // a.b.d.d.b
        public Menu e() {
            return this.f830e;
        }

        @Override // a.b.d.d.b
        public MenuInflater f() {
            return new a.b.d.d.g(this.f829d);
        }

        @Override // a.b.d.d.b
        public CharSequence g() {
            return k.this.f825f.getSubtitle();
        }

        @Override // a.b.d.d.b
        public CharSequence i() {
            return k.this.f825f.getTitle();
        }

        @Override // a.b.d.d.b
        public void k() {
            if (k.this.j != this) {
                return;
            }
            this.f830e.d0();
            try {
                this.f831f.d(this, this.f830e);
            } finally {
                this.f830e.c0();
            }
        }

        @Override // a.b.d.d.b
        public boolean l() {
            return k.this.f825f.j();
        }

        @Override // a.b.d.d.b
        public void m(View view) {
            k.this.f825f.setCustomView(view);
            this.g = new WeakReference<>(view);
        }

        @Override // a.b.d.d.b
        public void n(int i) {
            o(k.this.f820a.getResources().getString(i));
        }

        @Override // a.b.d.d.b
        public void o(CharSequence charSequence) {
            k.this.f825f.setSubtitle(charSequence);
        }

        @Override // a.b.d.d.b
        public void q(int i) {
            r(k.this.f820a.getResources().getString(i));
        }

        @Override // a.b.d.d.b
        public void r(CharSequence charSequence) {
            k.this.f825f.setTitle(charSequence);
        }

        @Override // a.b.d.d.b
        public void s(boolean z) {
            super.s(z);
            k.this.f825f.setTitleOptional(z);
        }

        public boolean t() {
            this.f830e.d0();
            try {
                return this.f831f.c(this, this.f830e);
            } finally {
                this.f830e.c0();
            }
        }
    }

    public k(Activity activity, boolean z) {
        new ArrayList();
        this.n = new ArrayList<>();
        this.p = 0;
        this.q = true;
        this.u = true;
        this.y = new a();
        this.z = new b();
        this.A = new c();
        View decorView = activity.getWindow().getDecorView();
        D(decorView);
        if (z) {
            return;
        }
        this.g = decorView.findViewById(R.id.content);
    }

    /* JADX WARN: Multi-variable type inference failed */
    private b0 A(View view) {
        if (view instanceof b0) {
            return (b0) view;
        }
        if (view instanceof Toolbar) {
            return ((Toolbar) view).getWrapper();
        }
        StringBuilder sb = new StringBuilder();
        sb.append("Can't make a decor toolbar out of ");
        sb.append(view != 0 ? view.getClass().getSimpleName() : "null");
        throw new IllegalStateException(sb.toString());
    }

    private void C() {
        if (this.t) {
            this.t = false;
            ActionBarOverlayLayout actionBarOverlayLayout = this.f822c;
            if (actionBarOverlayLayout != null) {
                actionBarOverlayLayout.setShowingForActionMode(false);
            }
            M(false);
        }
    }

    private void D(View view) {
        ActionBarOverlayLayout actionBarOverlayLayout = (ActionBarOverlayLayout) view.findViewById(a.b.d.a.f.decor_content_parent);
        this.f822c = actionBarOverlayLayout;
        if (actionBarOverlayLayout != null) {
            actionBarOverlayLayout.setActionBarVisibilityCallback(this);
        }
        this.f824e = A(view.findViewById(a.b.d.a.f.action_bar));
        this.f825f = (ActionBarContextView) view.findViewById(a.b.d.a.f.action_context_bar);
        ActionBarContainer actionBarContainer = (ActionBarContainer) view.findViewById(a.b.d.a.f.action_bar_container);
        this.f823d = actionBarContainer;
        b0 b0Var = this.f824e;
        if (b0Var == null || this.f825f == null || actionBarContainer == null) {
            throw new IllegalStateException(k.class.getSimpleName() + " can only be used with a compatible window decor layout");
        }
        this.f820a = b0Var.d();
        boolean z = (this.f824e.j() & 4) != 0;
        if (z) {
            this.i = true;
        }
        a.b.d.d.a aVarB = a.b.d.d.a.b(this.f820a);
        J(aVarB.a() || z);
        H(aVarB.g());
        TypedArray typedArrayObtainStyledAttributes = this.f820a.obtainStyledAttributes(null, a.b.d.a.j.ActionBar, a.b.d.a.a.actionBarStyle, 0);
        if (typedArrayObtainStyledAttributes.getBoolean(a.b.d.a.j.ActionBar_hideOnContentScroll, false)) {
            I(true);
        }
        int dimensionPixelSize = typedArrayObtainStyledAttributes.getDimensionPixelSize(a.b.d.a.j.ActionBar_elevation, 0);
        if (dimensionPixelSize != 0) {
            G(dimensionPixelSize);
        }
        typedArrayObtainStyledAttributes.recycle();
    }

    private void H(boolean z) {
        this.o = z;
        if (z) {
            this.f823d.setTabContainer(null);
            this.f824e.p(this.h);
        } else {
            this.f824e.p(null);
            this.f823d.setTabContainer(this.h);
        }
        boolean z2 = B() == 2;
        m0 m0Var = this.h;
        if (m0Var != null) {
            if (z2) {
                m0Var.setVisibility(0);
                ActionBarOverlayLayout actionBarOverlayLayout = this.f822c;
                if (actionBarOverlayLayout != null) {
                    p.r(actionBarOverlayLayout);
                }
            } else {
                m0Var.setVisibility(8);
            }
        }
        this.f824e.u(!this.o && z2);
        this.f822c.setHasNonEmbeddedTabs(!this.o && z2);
    }

    private boolean K() {
        return p.m(this.f823d);
    }

    private void L() {
        if (this.t) {
            return;
        }
        this.t = true;
        ActionBarOverlayLayout actionBarOverlayLayout = this.f822c;
        if (actionBarOverlayLayout != null) {
            actionBarOverlayLayout.setShowingForActionMode(true);
        }
        M(false);
    }

    private void M(boolean z) {
        if (w(this.r, this.s, this.t)) {
            if (this.u) {
                return;
            }
            this.u = true;
            z(z);
            return;
        }
        if (this.u) {
            this.u = false;
            y(z);
        }
    }

    static boolean w(boolean z, boolean z2, boolean z3) {
        if (z3) {
            return true;
        }
        return (z || z2) ? false : true;
    }

    public int B() {
        return this.f824e.o();
    }

    public void E(boolean z) {
        F(z ? 4 : 0, 4);
    }

    public void F(int i, int i2) {
        int iJ = this.f824e.j();
        if ((i2 & 4) != 0) {
            this.i = true;
        }
        this.f824e.v((i & i2) | ((~i2) & iJ));
    }

    public void G(float f2) {
        p.w(this.f823d, f2);
    }

    public void I(boolean z) {
        if (z && !this.f822c.v()) {
            throw new IllegalStateException("Action bar must be in overlay mode (Window.FEATURE_OVERLAY_ACTION_BAR) to enable hide on content scroll");
        }
        this.x = z;
        this.f822c.setHideOnContentScrollEnabled(z);
    }

    public void J(boolean z) {
        this.f824e.n(z);
    }

    @Override // android.support.v7.widget.ActionBarOverlayLayout.d
    public void a(boolean z) {
        this.q = z;
    }

    @Override // android.support.v7.widget.ActionBarOverlayLayout.d
    public void b() {
        if (this.s) {
            this.s = false;
            M(true);
        }
    }

    @Override // android.support.v7.widget.ActionBarOverlayLayout.d
    public void c() {
        a.b.d.d.h hVar = this.v;
        if (hVar != null) {
            hVar.a();
            this.v = null;
        }
    }

    @Override // android.support.v7.widget.ActionBarOverlayLayout.d
    public void d(int i) {
        this.p = i;
    }

    @Override // android.support.v7.widget.ActionBarOverlayLayout.d
    public void e() {
        if (this.s) {
            return;
        }
        this.s = true;
        M(true);
    }

    @Override // android.support.v7.widget.ActionBarOverlayLayout.d
    public void f() {
    }

    @Override // android.support.v7.app.a
    public boolean h() {
        b0 b0Var = this.f824e;
        if (b0Var == null || !b0Var.s()) {
            return false;
        }
        this.f824e.collapseActionView();
        return true;
    }

    @Override // android.support.v7.app.a
    public void i(boolean z) {
        if (z == this.m) {
            return;
        }
        this.m = z;
        int size = this.n.size();
        for (int i = 0; i < size; i++) {
            this.n.get(i).a(z);
        }
    }

    @Override // android.support.v7.app.a
    public int j() {
        return this.f824e.j();
    }

    @Override // android.support.v7.app.a
    public Context k() {
        if (this.f821b == null) {
            TypedValue typedValue = new TypedValue();
            this.f820a.getTheme().resolveAttribute(a.b.d.a.a.actionBarWidgetTheme, typedValue, true);
            int i = typedValue.resourceId;
            if (i != 0) {
                this.f821b = new ContextThemeWrapper(this.f820a, i);
            } else {
                this.f821b = this.f820a;
            }
        }
        return this.f821b;
    }

    @Override // android.support.v7.app.a
    public void m(Configuration configuration) {
        H(a.b.d.d.a.b(this.f820a).g());
    }

    @Override // android.support.v7.app.a
    public boolean o(int i, KeyEvent keyEvent) {
        Menu menuE;
        d dVar = this.j;
        if (dVar == null || (menuE = dVar.e()) == null) {
            return false;
        }
        menuE.setQwertyMode(KeyCharacterMap.load(keyEvent != null ? keyEvent.getDeviceId() : -1).getKeyboardType() != 1);
        return menuE.performShortcut(i, keyEvent, 0);
    }

    @Override // android.support.v7.app.a
    public void r(boolean z) {
        if (this.i) {
            return;
        }
        E(z);
    }

    @Override // android.support.v7.app.a
    public void s(boolean z) {
        a.b.d.d.h hVar;
        this.w = z;
        if (z || (hVar = this.v) == null) {
            return;
        }
        hVar.a();
    }

    @Override // android.support.v7.app.a
    public void t(CharSequence charSequence) {
        this.f824e.setWindowTitle(charSequence);
    }

    @Override // android.support.v7.app.a
    public a.b.d.d.b u(b.a aVar) {
        d dVar = this.j;
        if (dVar != null) {
            dVar.c();
        }
        this.f822c.setHideOnContentScrollEnabled(false);
        this.f825f.k();
        d dVar2 = new d(this.f825f.getContext(), aVar);
        if (!dVar2.t()) {
            return null;
        }
        this.j = dVar2;
        dVar2.k();
        this.f825f.h(dVar2);
        v(true);
        this.f825f.sendAccessibilityEvent(32);
        return dVar2;
    }

    public void v(boolean z) {
        t tVarQ;
        t tVarF;
        if (z) {
            L();
        } else {
            C();
        }
        if (!K()) {
            if (z) {
                this.f824e.k(4);
                this.f825f.setVisibility(0);
                return;
            } else {
                this.f824e.k(0);
                this.f825f.setVisibility(8);
                return;
            }
        }
        if (z) {
            tVarF = this.f824e.q(4, 100L);
            tVarQ = this.f825f.f(0, 200L);
        } else {
            tVarQ = this.f824e.q(0, 200L);
            tVarF = this.f825f.f(8, 100L);
        }
        a.b.d.d.h hVar = new a.b.d.d.h();
        hVar.d(tVarF, tVarQ);
        hVar.h();
    }

    void x() {
        b.a aVar = this.l;
        if (aVar != null) {
            aVar.a(this.k);
            this.k = null;
            this.l = null;
        }
    }

    public void y(boolean z) {
        View view;
        a.b.d.d.h hVar = this.v;
        if (hVar != null) {
            hVar.a();
        }
        if (this.p != 0 || (!this.w && !z)) {
            this.y.a(null);
            return;
        }
        this.f823d.setAlpha(1.0f);
        this.f823d.setTransitioning(true);
        a.b.d.d.h hVar2 = new a.b.d.d.h();
        float f2 = -this.f823d.getHeight();
        if (z) {
            this.f823d.getLocationInWindow(new int[]{0, 0});
            f2 -= r5[1];
        }
        t tVarA = p.a(this.f823d);
        tVarA.k(f2);
        tVarA.i(this.A);
        hVar2.c(tVarA);
        if (this.q && (view = this.g) != null) {
            t tVarA2 = p.a(view);
            tVarA2.k(f2);
            hVar2.c(tVarA2);
        }
        hVar2.f(B);
        hVar2.e(250L);
        hVar2.g(this.y);
        this.v = hVar2;
        hVar2.h();
    }

    public void z(boolean z) {
        View view;
        View view2;
        a.b.d.d.h hVar = this.v;
        if (hVar != null) {
            hVar.a();
        }
        this.f823d.setVisibility(0);
        if (this.p == 0 && (this.w || z)) {
            this.f823d.setTranslationY(0.0f);
            float f2 = -this.f823d.getHeight();
            if (z) {
                this.f823d.getLocationInWindow(new int[]{0, 0});
                f2 -= r5[1];
            }
            this.f823d.setTranslationY(f2);
            a.b.d.d.h hVar2 = new a.b.d.d.h();
            t tVarA = p.a(this.f823d);
            tVarA.k(0.0f);
            tVarA.i(this.A);
            hVar2.c(tVarA);
            if (this.q && (view2 = this.g) != null) {
                view2.setTranslationY(f2);
                t tVarA2 = p.a(this.g);
                tVarA2.k(0.0f);
                hVar2.c(tVarA2);
            }
            hVar2.f(C);
            hVar2.e(250L);
            hVar2.g(this.z);
            this.v = hVar2;
            hVar2.h();
        } else {
            this.f823d.setAlpha(1.0f);
            this.f823d.setTranslationY(0.0f);
            if (this.q && (view = this.g) != null) {
                view.setTranslationY(0.0f);
            }
            this.z.a(null);
        }
        ActionBarOverlayLayout actionBarOverlayLayout = this.f822c;
        if (actionBarOverlayLayout != null) {
            p.r(actionBarOverlayLayout);
        }
    }

    public k(Dialog dialog) {
        new ArrayList();
        this.n = new ArrayList<>();
        this.p = 0;
        this.q = true;
        this.u = true;
        this.y = new a();
        this.z = new b();
        this.A = new c();
        D(dialog.getWindow().getDecorView());
    }
}
