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 c.a.m.b;
import c.f.l.a0;
import c.f.l.t;
import c.f.l.x;
import c.f.l.y;
import c.f.l.z;
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 a0 A;
    Context a;

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

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    c.a.m.b f165k;
    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;
    c.a.m.h v;
    private boolean w;
    boolean x;
    final y y;
    final y z;

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

        @Override // c.f.l.y
        public void b(View view) {
            View view2;
            k kVar = k.this;
            if (kVar.q && (view2 = kVar.f161g) != null) {
                view2.setTranslationY(0.0f);
                k.this.f158d.setTranslationY(0.0f);
            }
            k.this.f158d.setVisibility(8);
            k.this.f158d.setTransitioning(false);
            k kVar2 = k.this;
            kVar2.v = null;
            kVar2.y();
            ActionBarOverlayLayout actionBarOverlayLayout = k.this.f157c;
            if (actionBarOverlayLayout != null) {
                t.T(actionBarOverlayLayout);
            }
        }
    }

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

        @Override // c.f.l.y
        public void b(View view) {
            k kVar = k.this;
            kVar.v = null;
            kVar.f158d.requestLayout();
        }
    }

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

        @Override // c.f.l.a0
        public void a(View view) {
            ((View) k.this.f158d.getParent()).invalidate();
        }
    }

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

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

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

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

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

        public d(Context context, b.a aVar) {
            this.f166g = context;
            this.f168i = aVar;
            androidx.appcompat.view.menu.h hVar = new androidx.appcompat.view.menu.h(context);
            hVar.S(1);
            this.f167h = 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.f168i;
            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.f168i == null) {
                return;
            }
            k();
            k.this.f160f.l();
        }

        @Override // c.a.m.b
        public void c() {
            k kVar = k.this;
            if (kVar.f164j != this) {
                return;
            }
            if (k.x(kVar.r, kVar.s, false)) {
                this.f168i.b(this);
            } else {
                k kVar2 = k.this;
                kVar2.f165k = this;
                kVar2.l = this.f168i;
            }
            this.f168i = null;
            k.this.w(false);
            k.this.f160f.g();
            k.this.f159e.k().sendAccessibilityEvent(32);
            k kVar3 = k.this;
            kVar3.f157c.setHideOnContentScrollEnabled(kVar3.x);
            k.this.f164j = null;
        }

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

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

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

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

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

        @Override // c.a.m.b
        public void k() {
            if (k.this.f164j != this) {
                return;
            }
            this.f167h.d0();
            try {
                this.f168i.a(this, this.f167h);
            } finally {
                this.f167h.c0();
            }
        }

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

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

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

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

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

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

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

        public boolean t() {
            this.f167h.d0();
            try {
                return this.f168i.d(this, this.f167h);
            } finally {
                this.f167h.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();
        E(decorView);
        if (z) {
            return;
        }
        this.f161g = decorView.findViewById(R.id.content);
    }

    /* JADX WARN: Multi-variable type inference failed */
    private b0 B(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 D() {
        if (this.t) {
            this.t = false;
            ActionBarOverlayLayout actionBarOverlayLayout = this.f157c;
            if (actionBarOverlayLayout != null) {
                actionBarOverlayLayout.setShowingForActionMode(false);
            }
            M(false);
        }
    }

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

    private void H(boolean z) {
        this.o = z;
        if (z) {
            this.f158d.setTabContainer(null);
            this.f159e.j(this.f162h);
        } else {
            this.f159e.j(null);
            this.f158d.setTabContainer(this.f162h);
        }
        boolean z2 = C() == 2;
        m0 m0Var = this.f162h;
        if (m0Var != null) {
            if (z2) {
                m0Var.setVisibility(0);
                ActionBarOverlayLayout actionBarOverlayLayout = this.f157c;
                if (actionBarOverlayLayout != null) {
                    t.T(actionBarOverlayLayout);
                }
            } else {
                m0Var.setVisibility(8);
            }
        }
        this.f159e.u(!this.o && z2);
        this.f157c.setHasNonEmbeddedTabs(!this.o && z2);
    }

    private boolean K() {
        return t.H(this.f158d);
    }

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

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

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

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

    public int C() {
        return this.f159e.q();
    }

    public void F(int i2, int i3) {
        int iO = this.f159e.o();
        if ((i3 & 4) != 0) {
            this.f163i = true;
        }
        this.f159e.n((i2 & i3) | ((~i3) & iO));
    }

    public void G(float f2) {
        t.b0(this.f158d, f2);
    }

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

    public void J(boolean z) {
        this.f159e.l(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() {
        c.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.f159e;
        if (b0Var == null || !b0Var.m()) {
            return false;
        }
        this.f159e.collapseActionView();
        return true;
    }

    @Override // androidx.appcompat.app.a
    public void i(boolean z) {
        if (z == this.m) {
            return;
        }
        this.m = 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.f159e.o();
    }

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

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

    @Override // androidx.appcompat.app.a
    public boolean o(int i2, KeyEvent keyEvent) {
        Menu menuE;
        d dVar = this.f164j;
        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.f163i) {
            return;
        }
        s(z);
    }

    @Override // androidx.appcompat.app.a
    public void s(boolean z) {
        F(z ? 4 : 0, 4);
    }

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

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

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

    public void w(boolean z) {
        x xVarR;
        x xVarF;
        if (z) {
            L();
        } else {
            D();
        }
        if (!K()) {
            if (z) {
                this.f159e.i(4);
                this.f160f.setVisibility(0);
                return;
            } else {
                this.f159e.i(0);
                this.f160f.setVisibility(8);
                return;
            }
        }
        if (z) {
            xVarF = this.f159e.r(4, 100L);
            xVarR = this.f160f.f(0, 200L);
        } else {
            xVarR = this.f159e.r(0, 200L);
            xVarF = this.f160f.f(8, 100L);
        }
        c.a.m.h hVar = new c.a.m.h();
        hVar.d(xVarF, xVarR);
        hVar.h();
    }

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

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

    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();
        E(dialog.getWindow().getDecorView());
    }
}
