package androidx.appcompat.app;

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.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 androidx.appcompat.app.a;
import androidx.appcompat.view.menu.h;
import androidx.appcompat.widget.ActionBarContainer;
import androidx.appcompat.widget.ActionBarContextView;
import androidx.appcompat.widget.ActionBarOverlayLayout;
import androidx.appcompat.widget.Toolbar;
import androidx.appcompat.widget.b0;
import androidx.appcompat.widget.m0;
import g.a.m.b;
import g.e.j.o;
import g.e.j.s;
import g.e.j.t;
import g.e.j.u;
import g.e.j.v;
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 androidx.appcompat.app.a implements ActionBarOverlayLayout.d {
    private static final Interpolator B = new AccelerateInterpolator();
    private static final Interpolator C = new DecelerateInterpolator();
    final v A;
    Context a;
    private Context b;
    ActionBarOverlayLayout c;
    ActionBarContainer d;
    b0 e;
    ActionBarContextView f;

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    m0 f33h;

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

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    g.a.m.b f36k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    b.a f37l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private boolean f38m;
    private ArrayList<a.b> n;
    private boolean o;
    private int p;
    boolean q;
    boolean r;
    boolean s;
    private boolean t;
    private boolean u;
    g.a.m.h v;
    private boolean w;
    boolean x;
    final t y;
    final t z;

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

        @Override // g.e.j.t
        public void b(View view) {
            View view2;
            k kVar = k.this;
            if (kVar.q && (view2 = kVar.f32g) != null) {
                view2.setTranslationY(0.0f);
                k.this.d.setTranslationY(0.0f);
            }
            k.this.d.setVisibility(8);
            k.this.d.setTransitioning(false);
            k kVar2 = k.this;
            kVar2.v = null;
            kVar2.x();
            ActionBarOverlayLayout actionBarOverlayLayout = k.this.c;
            if (actionBarOverlayLayout != null) {
                o.r(actionBarOverlayLayout);
            }
        }
    }

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

        @Override // g.e.j.t
        public void b(View view) {
            k kVar = k.this;
            kVar.v = null;
            kVar.d.requestLayout();
        }
    }

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

        @Override // g.e.j.v
        public void a(View view) {
            ((View) k.this.d.getParent()).invalidate();
        }
    }

    /* JADX INFO: compiled from: WindowDecorActionBar.java */
    public class d extends g.a.m.b implements h.a {
        private final Context e;
        private final androidx.appcompat.view.menu.h f;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        private b.a f39g;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        private WeakReference<View> f40h;

        public d(Context context, b.a aVar) {
            this.e = context;
            this.f39g = aVar;
            androidx.appcompat.view.menu.h hVar = new androidx.appcompat.view.menu.h(context);
            hVar.S(1);
            this.f = hVar;
            hVar.R(this);
        }

        @Override // androidx.appcompat.view.menu.h.a
        public boolean a(androidx.appcompat.view.menu.h hVar, MenuItem menuItem) {
            b.a aVar = this.f39g;
            if (aVar != null) {
                return aVar.c(this, menuItem);
            }
            return false;
        }

        @Override // androidx.appcompat.view.menu.h.a
        public void b(androidx.appcompat.view.menu.h hVar) {
            if (this.f39g == null) {
                return;
            }
            k();
            k.this.f.l();
        }

        @Override // g.a.m.b
        public void c() {
            k kVar = k.this;
            if (kVar.f35j != this) {
                return;
            }
            if (k.w(kVar.r, kVar.s, false)) {
                this.f39g.b(this);
            } else {
                k kVar2 = k.this;
                kVar2.f36k = this;
                kVar2.f37l = this.f39g;
            }
            this.f39g = null;
            k.this.v(false);
            k.this.f.g();
            k.this.e.l().sendAccessibilityEvent(32);
            k kVar3 = k.this;
            kVar3.c.setHideOnContentScrollEnabled(kVar3.x);
            k.this.f35j = null;
        }

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

        @Override // g.a.m.b
        public Menu e() {
            return this.f;
        }

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

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

        @Override // g.a.m.b
        public CharSequence i() {
            return k.this.f.getTitle();
        }

        @Override // g.a.m.b
        public void k() {
            if (k.this.f35j != this) {
                return;
            }
            this.f.d0();
            try {
                this.f39g.a(this, this.f);
            } finally {
                this.f.c0();
            }
        }

        @Override // g.a.m.b
        public boolean l() {
            return k.this.f.j();
        }

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

        @Override // g.a.m.b
        public void n(int i2) {
            o(k.this.a.getResources().getString(i2));
        }

        @Override // g.a.m.b
        public void o(CharSequence charSequence) {
            k.this.f.setSubtitle(charSequence);
        }

        @Override // g.a.m.b
        public void q(int i2) {
            r(k.this.a.getResources().getString(i2));
        }

        @Override // g.a.m.b
        public void r(CharSequence charSequence) {
            k.this.f.setTitle(charSequence);
        }

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

        public boolean t() {
            this.f.d0();
            try {
                return this.f39g.d(this, this.f);
            } finally {
                this.f.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.f32g = 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.c;
            if (actionBarOverlayLayout != null) {
                actionBarOverlayLayout.setShowingForActionMode(false);
            }
            M(false);
        }
    }

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

    private void H(boolean z) {
        this.o = z;
        if (z) {
            this.d.setTabContainer(null);
            this.e.k(this.f33h);
        } else {
            this.e.k(null);
            this.d.setTabContainer(this.f33h);
        }
        boolean z2 = B() == 2;
        m0 m0Var = this.f33h;
        if (m0Var != null) {
            if (z2) {
                m0Var.setVisibility(0);
                ActionBarOverlayLayout actionBarOverlayLayout = this.c;
                if (actionBarOverlayLayout != null) {
                    o.r(actionBarOverlayLayout);
                }
            } else {
                m0Var.setVisibility(8);
            }
        }
        this.e.v(!this.o && z2);
        this.c.setHasNonEmbeddedTabs(!this.o && z2);
    }

    private boolean K() {
        return o.m(this.d);
    }

    private void L() {
        if (this.t) {
            return;
        }
        this.t = true;
        ActionBarOverlayLayout actionBarOverlayLayout = this.c;
        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.e.r();
    }

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

    public void F(int i2, int i3) {
        int iP = this.e.p();
        if ((i3 & 4) != 0) {
            this.f34i = true;
        }
        this.e.o((i2 & i3) | ((~i3) & iP));
    }

    public void G(float f) {
        o.w(this.d, f);
    }

    public void I(boolean z) {
        if (z && !this.c.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.c.setHideOnContentScrollEnabled(z);
    }

    public void J(boolean z) {
        this.e.m(z);
    }

    @Override // androidx.appcompat.widget.ActionBarOverlayLayout.d
    public void a() {
        if (this.s) {
            this.s = false;
            M(true);
        }
    }

    @Override // androidx.appcompat.widget.ActionBarOverlayLayout.d
    public void b() {
        g.a.m.h hVar = this.v;
        if (hVar != null) {
            hVar.a();
            this.v = null;
        }
    }

    @Override // androidx.appcompat.widget.ActionBarOverlayLayout.d
    public void c(int i2) {
        this.p = i2;
    }

    @Override // androidx.appcompat.widget.ActionBarOverlayLayout.d
    public void d() {
    }

    @Override // androidx.appcompat.widget.ActionBarOverlayLayout.d
    public void e(boolean z) {
        this.q = z;
    }

    @Override // androidx.appcompat.widget.ActionBarOverlayLayout.d
    public void f() {
        if (this.s) {
            return;
        }
        this.s = true;
        M(true);
    }

    @Override // androidx.appcompat.app.a
    public boolean h() {
        b0 b0Var = this.e;
        if (b0Var == null || !b0Var.n()) {
            return false;
        }
        this.e.collapseActionView();
        return true;
    }

    @Override // androidx.appcompat.app.a
    public void i(boolean z) {
        if (z == this.f38m) {
            return;
        }
        this.f38m = z;
        int size = this.n.size();
        for (int i2 = 0; i2 < size; i2++) {
            this.n.get(i2).a(z);
        }
    }

    @Override // androidx.appcompat.app.a
    public int j() {
        return this.e.p();
    }

    @Override // androidx.appcompat.app.a
    public Context k() {
        if (this.b == null) {
            TypedValue typedValue = new TypedValue();
            this.a.getTheme().resolveAttribute(g.a.a.actionBarWidgetTheme, typedValue, true);
            int i2 = typedValue.resourceId;
            if (i2 != 0) {
                this.b = new ContextThemeWrapper(this.a, i2);
            } else {
                this.b = this.a;
            }
        }
        return this.b;
    }

    @Override // androidx.appcompat.app.a
    public void m(Configuration configuration) {
        H(g.a.m.a.b(this.a).g());
    }

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

    @Override // androidx.appcompat.app.a
    public void r(boolean z) {
        if (this.f34i) {
            return;
        }
        E(z);
    }

    @Override // androidx.appcompat.app.a
    public void s(boolean z) {
        g.a.m.h hVar;
        this.w = z;
        if (z || (hVar = this.v) == null) {
            return;
        }
        hVar.a();
    }

    @Override // androidx.appcompat.app.a
    public void t(CharSequence charSequence) {
        this.e.setWindowTitle(charSequence);
    }

    @Override // androidx.appcompat.app.a
    public g.a.m.b u(b.a aVar) {
        d dVar = this.f35j;
        if (dVar != null) {
            dVar.c();
        }
        this.c.setHideOnContentScrollEnabled(false);
        this.f.k();
        d dVar2 = new d(this.f.getContext(), aVar);
        if (!dVar2.t()) {
            return null;
        }
        this.f35j = dVar2;
        dVar2.k();
        this.f.h(dVar2);
        v(true);
        this.f.sendAccessibilityEvent(32);
        return dVar2;
    }

    public void v(boolean z) {
        s sVarS;
        s sVarF;
        if (z) {
            L();
        } else {
            C();
        }
        if (!K()) {
            if (z) {
                this.e.j(4);
                this.f.setVisibility(0);
                return;
            } else {
                this.e.j(0);
                this.f.setVisibility(8);
                return;
            }
        }
        if (z) {
            sVarF = this.e.s(4, 100L);
            sVarS = this.f.f(0, 200L);
        } else {
            sVarS = this.e.s(0, 200L);
            sVarF = this.f.f(8, 100L);
        }
        g.a.m.h hVar = new g.a.m.h();
        hVar.d(sVarF, sVarS);
        hVar.h();
    }

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

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

    public void z(boolean z) {
        View view;
        View view2;
        g.a.m.h hVar = this.v;
        if (hVar != null) {
            hVar.a();
        }
        this.d.setVisibility(0);
        if (this.p == 0 && (this.w || z)) {
            this.d.setTranslationY(0.0f);
            float f = -this.d.getHeight();
            if (z) {
                this.d.getLocationInWindow(new int[]{0, 0});
                f -= r5[1];
            }
            this.d.setTranslationY(f);
            g.a.m.h hVar2 = new g.a.m.h();
            s sVarA = o.a(this.d);
            sVarA.k(0.0f);
            sVarA.i(this.A);
            hVar2.c(sVarA);
            if (this.q && (view2 = this.f32g) != null) {
                view2.setTranslationY(f);
                s sVarA2 = o.a(this.f32g);
                sVarA2.k(0.0f);
                hVar2.c(sVarA2);
            }
            hVar2.f(C);
            hVar2.e(250L);
            hVar2.g(this.z);
            this.v = hVar2;
            hVar2.h();
        } else {
            this.d.setAlpha(1.0f);
            this.d.setTranslationY(0.0f);
            if (this.q && (view = this.f32g) != null) {
                view.setTranslationY(0.0f);
            }
            this.z.b(null);
        }
        ActionBarOverlayLayout actionBarOverlayLayout = this.c;
        if (actionBarOverlayLayout != null) {
            o.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());
    }
}
