package i;

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.graphics.drawable.Drawable;
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.view.menu.e;
import androidx.appcompat.widget.ActionBarContainer;
import androidx.appcompat.widget.ActionBarContextView;
import androidx.appcompat.widget.ActionBarOverlayLayout;
import androidx.appcompat.widget.Toolbar;
import androidx.appcompat.widget.e0;
import androidx.core.view.b1;
import androidx.core.view.c1;
import androidx.core.view.d1;
import androidx.core.view.e1;
import androidx.core.view.s0;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import n.b;

/* loaded from: classes.dex */
public class n extends i.a implements ActionBarOverlayLayout.d {
    private static final Interpolator D = new AccelerateInterpolator();
    private static final Interpolator E = new DecelerateInterpolator();

    /* renamed from: a, reason: collision with root package name */
    Context f22202a;

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

    /* renamed from: c, reason: collision with root package name */
    private Activity f22204c;

    /* renamed from: d, reason: collision with root package name */
    ActionBarOverlayLayout f22205d;

    /* renamed from: e, reason: collision with root package name */
    ActionBarContainer f22206e;

    /* renamed from: f, reason: collision with root package name */
    e0 f22207f;

    /* renamed from: g, reason: collision with root package name */
    ActionBarContextView f22208g;

    /* renamed from: h, reason: collision with root package name */
    View f22209h;

    /* renamed from: k, reason: collision with root package name */
    private boolean f22212k;

    /* renamed from: l, reason: collision with root package name */
    d f22213l;

    /* renamed from: m, reason: collision with root package name */
    n.b f22214m;

    /* renamed from: n, reason: collision with root package name */
    b.a f22215n;

    /* renamed from: o, reason: collision with root package name */
    private boolean f22216o;

    /* renamed from: q, reason: collision with root package name */
    private boolean f22218q;

    /* renamed from: t, reason: collision with root package name */
    boolean f22221t;

    /* renamed from: u, reason: collision with root package name */
    boolean f22222u;

    /* renamed from: v, reason: collision with root package name */
    private boolean f22223v;

    /* renamed from: x, reason: collision with root package name */
    n.h f22225x;

    /* renamed from: y, reason: collision with root package name */
    private boolean f22226y;

    /* renamed from: z, reason: collision with root package name */
    boolean f22227z;

    /* renamed from: i, reason: collision with root package name */
    private ArrayList f22210i = new ArrayList();

    /* renamed from: j, reason: collision with root package name */
    private int f22211j = -1;

    /* renamed from: p, reason: collision with root package name */
    private ArrayList f22217p = new ArrayList();

    /* renamed from: r, reason: collision with root package name */
    private int f22219r = 0;

    /* renamed from: s, reason: collision with root package name */
    boolean f22220s = true;

    /* renamed from: w, reason: collision with root package name */
    private boolean f22224w = true;
    final c1 A = new a();
    final c1 B = new b();
    final e1 C = new c();

    /* loaded from: classes.dex */
    class a extends d1 {
        a() {
        }

        @Override // androidx.core.view.c1
        public void b(View view) {
            View view2;
            n nVar = n.this;
            if (nVar.f22220s && (view2 = nVar.f22209h) != null) {
                view2.setTranslationY(BitmapDescriptorFactory.HUE_RED);
                n.this.f22206e.setTranslationY(BitmapDescriptorFactory.HUE_RED);
            }
            n.this.f22206e.setVisibility(8);
            n.this.f22206e.setTransitioning(false);
            n nVar2 = n.this;
            nVar2.f22225x = null;
            nVar2.G();
            ActionBarOverlayLayout actionBarOverlayLayout = n.this.f22205d;
            if (actionBarOverlayLayout != null) {
                s0.j0(actionBarOverlayLayout);
            }
        }
    }

    /* loaded from: classes.dex */
    class b extends d1 {
        b() {
        }

        @Override // androidx.core.view.c1
        public void b(View view) {
            n nVar = n.this;
            nVar.f22225x = null;
            nVar.f22206e.requestLayout();
        }
    }

    /* loaded from: classes.dex */
    class c implements e1 {
        c() {
        }

        @Override // androidx.core.view.e1
        public void a(View view) {
            ((View) n.this.f22206e.getParent()).invalidate();
        }
    }

    /* loaded from: classes.dex */
    public class d extends n.b implements e.a {

        /* renamed from: r, reason: collision with root package name */
        private final Context f22231r;

        /* renamed from: s, reason: collision with root package name */
        private final androidx.appcompat.view.menu.e f22232s;

        /* renamed from: t, reason: collision with root package name */
        private b.a f22233t;

        /* renamed from: u, reason: collision with root package name */
        private WeakReference f22234u;

        public d(Context context, b.a aVar) {
            this.f22231r = context;
            this.f22233t = aVar;
            androidx.appcompat.view.menu.e W = new androidx.appcompat.view.menu.e(context).W(1);
            this.f22232s = W;
            W.V(this);
        }

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

        @Override // androidx.appcompat.view.menu.e.a
        public void b(androidx.appcompat.view.menu.e eVar) {
            if (this.f22233t == null) {
                return;
            }
            k();
            n.this.f22208g.l();
        }

        @Override // n.b
        public void c() {
            n nVar = n.this;
            if (nVar.f22213l != this) {
                return;
            }
            if (n.F(nVar.f22221t, nVar.f22222u, false)) {
                this.f22233t.d(this);
            } else {
                n nVar2 = n.this;
                nVar2.f22214m = this;
                nVar2.f22215n = this.f22233t;
            }
            this.f22233t = null;
            n.this.E(false);
            n.this.f22208g.g();
            n nVar3 = n.this;
            nVar3.f22205d.setHideOnContentScrollEnabled(nVar3.f22227z);
            n.this.f22213l = null;
        }

        @Override // n.b
        public View d() {
            WeakReference weakReference = this.f22234u;
            if (weakReference != null) {
                return (View) weakReference.get();
            }
            return null;
        }

        @Override // n.b
        public Menu e() {
            return this.f22232s;
        }

        @Override // n.b
        public MenuInflater f() {
            return new n.g(this.f22231r);
        }

        @Override // n.b
        public CharSequence g() {
            return n.this.f22208g.getSubtitle();
        }

        @Override // n.b
        public CharSequence i() {
            return n.this.f22208g.getTitle();
        }

        @Override // n.b
        public void k() {
            if (n.this.f22213l != this) {
                return;
            }
            this.f22232s.h0();
            try {
                this.f22233t.b(this, this.f22232s);
            } finally {
                this.f22232s.g0();
            }
        }

        @Override // n.b
        public boolean l() {
            return n.this.f22208g.j();
        }

        @Override // n.b
        public void m(View view) {
            n.this.f22208g.setCustomView(view);
            this.f22234u = new WeakReference(view);
        }

        @Override // n.b
        public void n(int i10) {
            o(n.this.f22202a.getResources().getString(i10));
        }

        @Override // n.b
        public void o(CharSequence charSequence) {
            n.this.f22208g.setSubtitle(charSequence);
        }

        @Override // n.b
        public void q(int i10) {
            r(n.this.f22202a.getResources().getString(i10));
        }

        @Override // n.b
        public void r(CharSequence charSequence) {
            n.this.f22208g.setTitle(charSequence);
        }

        @Override // n.b
        public void s(boolean z10) {
            super.s(z10);
            n.this.f22208g.setTitleOptional(z10);
        }

        public boolean t() {
            this.f22232s.h0();
            try {
                return this.f22233t.a(this, this.f22232s);
            } finally {
                this.f22232s.g0();
            }
        }
    }

    public n(Activity activity, boolean z10) {
        this.f22204c = activity;
        View decorView = activity.getWindow().getDecorView();
        M(decorView);
        if (z10) {
            return;
        }
        this.f22209h = decorView.findViewById(R.id.content);
    }

    static boolean F(boolean z10, boolean z11, boolean z12) {
        if (z12) {
            return true;
        }
        return (z10 || z11) ? false : true;
    }

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

    private void L() {
        if (this.f22223v) {
            this.f22223v = false;
            ActionBarOverlayLayout actionBarOverlayLayout = this.f22205d;
            if (actionBarOverlayLayout != null) {
                actionBarOverlayLayout.setShowingForActionMode(false);
            }
            U(false);
        }
    }

    private void M(View view) {
        ActionBarOverlayLayout actionBarOverlayLayout = (ActionBarOverlayLayout) view.findViewById(h.f.f20232p);
        this.f22205d = actionBarOverlayLayout;
        if (actionBarOverlayLayout != null) {
            actionBarOverlayLayout.setActionBarVisibilityCallback(this);
        }
        this.f22207f = J(view.findViewById(h.f.f20217a));
        this.f22208g = (ActionBarContextView) view.findViewById(h.f.f20222f);
        ActionBarContainer actionBarContainer = (ActionBarContainer) view.findViewById(h.f.f20219c);
        this.f22206e = actionBarContainer;
        e0 e0Var = this.f22207f;
        if (e0Var == null || this.f22208g == null || actionBarContainer == null) {
            throw new IllegalStateException(getClass().getSimpleName() + " can only be used with a compatible window decor layout");
        }
        this.f22202a = e0Var.getContext();
        boolean z10 = (this.f22207f.v() & 4) != 0;
        if (z10) {
            this.f22212k = true;
        }
        n.a b10 = n.a.b(this.f22202a);
        R(b10.a() || z10);
        P(b10.e());
        TypedArray obtainStyledAttributes = this.f22202a.obtainStyledAttributes(null, h.j.f20281a, h.a.f20149c, 0);
        if (obtainStyledAttributes.getBoolean(h.j.f20331k, false)) {
            Q(true);
        }
        int dimensionPixelSize = obtainStyledAttributes.getDimensionPixelSize(h.j.f20321i, 0);
        if (dimensionPixelSize != 0) {
            O(dimensionPixelSize);
        }
        obtainStyledAttributes.recycle();
    }

    private void P(boolean z10) {
        this.f22218q = z10;
        if (z10) {
            this.f22206e.setTabContainer(null);
            this.f22207f.j(null);
        } else {
            this.f22207f.j(null);
            this.f22206e.setTabContainer(null);
        }
        boolean z11 = K() == 2;
        this.f22207f.A(!this.f22218q && z11);
        this.f22205d.setHasNonEmbeddedTabs(!this.f22218q && z11);
    }

    private boolean S() {
        return s0.Q(this.f22206e);
    }

    private void T() {
        if (this.f22223v) {
            return;
        }
        this.f22223v = true;
        ActionBarOverlayLayout actionBarOverlayLayout = this.f22205d;
        if (actionBarOverlayLayout != null) {
            actionBarOverlayLayout.setShowingForActionMode(true);
        }
        U(false);
    }

    private void U(boolean z10) {
        if (F(this.f22221t, this.f22222u, this.f22223v)) {
            if (this.f22224w) {
                return;
            }
            this.f22224w = true;
            I(z10);
            return;
        }
        if (this.f22224w) {
            this.f22224w = false;
            H(z10);
        }
    }

    @Override // i.a
    public void A(CharSequence charSequence) {
        this.f22207f.setTitle(charSequence);
    }

    @Override // i.a
    public void B(CharSequence charSequence) {
        this.f22207f.setWindowTitle(charSequence);
    }

    @Override // i.a
    public void C() {
        if (this.f22221t) {
            this.f22221t = false;
            U(false);
        }
    }

    @Override // i.a
    public n.b D(b.a aVar) {
        d dVar = this.f22213l;
        if (dVar != null) {
            dVar.c();
        }
        this.f22205d.setHideOnContentScrollEnabled(false);
        this.f22208g.k();
        d dVar2 = new d(this.f22208g.getContext(), aVar);
        if (!dVar2.t()) {
            return null;
        }
        this.f22213l = dVar2;
        dVar2.k();
        this.f22208g.h(dVar2);
        E(true);
        return dVar2;
    }

    public void E(boolean z10) {
        b1 f10;
        b1 b1Var;
        if (z10) {
            T();
        } else {
            L();
        }
        if (!S()) {
            if (z10) {
                this.f22207f.s(4);
                this.f22208g.setVisibility(0);
                return;
            } else {
                this.f22207f.s(0);
                this.f22208g.setVisibility(8);
                return;
            }
        }
        if (z10) {
            f10 = this.f22207f.p(4, 100L);
            b1Var = this.f22208g.f(0, 200L);
        } else {
            b1 p10 = this.f22207f.p(0, 200L);
            f10 = this.f22208g.f(8, 100L);
            b1Var = p10;
        }
        n.h hVar = new n.h();
        hVar.d(f10, b1Var);
        hVar.h();
    }

    void G() {
        b.a aVar = this.f22215n;
        if (aVar != null) {
            aVar.d(this.f22214m);
            this.f22214m = null;
            this.f22215n = null;
        }
    }

    public void H(boolean z10) {
        View view;
        n.h hVar = this.f22225x;
        if (hVar != null) {
            hVar.a();
        }
        if (this.f22219r != 0 || (!this.f22226y && !z10)) {
            this.A.b(null);
            return;
        }
        this.f22206e.setAlpha(1.0f);
        this.f22206e.setTransitioning(true);
        n.h hVar2 = new n.h();
        float f10 = -this.f22206e.getHeight();
        if (z10) {
            this.f22206e.getLocationInWindow(new int[]{0, 0});
            f10 -= r5[1];
        }
        b1 m10 = s0.e(this.f22206e).m(f10);
        m10.k(this.C);
        hVar2.c(m10);
        if (this.f22220s && (view = this.f22209h) != null) {
            hVar2.c(s0.e(view).m(f10));
        }
        hVar2.f(D);
        hVar2.e(250L);
        hVar2.g(this.A);
        this.f22225x = hVar2;
        hVar2.h();
    }

    public void I(boolean z10) {
        View view;
        View view2;
        n.h hVar = this.f22225x;
        if (hVar != null) {
            hVar.a();
        }
        this.f22206e.setVisibility(0);
        if (this.f22219r == 0 && (this.f22226y || z10)) {
            this.f22206e.setTranslationY(BitmapDescriptorFactory.HUE_RED);
            float f10 = -this.f22206e.getHeight();
            if (z10) {
                this.f22206e.getLocationInWindow(new int[]{0, 0});
                f10 -= r5[1];
            }
            this.f22206e.setTranslationY(f10);
            n.h hVar2 = new n.h();
            b1 m10 = s0.e(this.f22206e).m(BitmapDescriptorFactory.HUE_RED);
            m10.k(this.C);
            hVar2.c(m10);
            if (this.f22220s && (view2 = this.f22209h) != null) {
                view2.setTranslationY(f10);
                hVar2.c(s0.e(this.f22209h).m(BitmapDescriptorFactory.HUE_RED));
            }
            hVar2.f(E);
            hVar2.e(250L);
            hVar2.g(this.B);
            this.f22225x = hVar2;
            hVar2.h();
        } else {
            this.f22206e.setAlpha(1.0f);
            this.f22206e.setTranslationY(BitmapDescriptorFactory.HUE_RED);
            if (this.f22220s && (view = this.f22209h) != null) {
                view.setTranslationY(BitmapDescriptorFactory.HUE_RED);
            }
            this.B.b(null);
        }
        ActionBarOverlayLayout actionBarOverlayLayout = this.f22205d;
        if (actionBarOverlayLayout != null) {
            s0.j0(actionBarOverlayLayout);
        }
    }

    public int K() {
        return this.f22207f.o();
    }

    public void N(int i10, int i11) {
        int v10 = this.f22207f.v();
        if ((i11 & 4) != 0) {
            this.f22212k = true;
        }
        this.f22207f.l((i10 & i11) | ((~i11) & v10));
    }

    public void O(float f10) {
        s0.u0(this.f22206e, f10);
    }

    public void Q(boolean z10) {
        if (z10 && !this.f22205d.w()) {
            throw new IllegalStateException("Action bar must be in overlay mode (Window.FEATURE_OVERLAY_ACTION_BAR) to enable hide on content scroll");
        }
        this.f22227z = z10;
        this.f22205d.setHideOnContentScrollEnabled(z10);
    }

    public void R(boolean z10) {
        this.f22207f.u(z10);
    }

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

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

    @Override // androidx.appcompat.widget.ActionBarOverlayLayout.d
    public void c(boolean z10) {
        this.f22220s = z10;
    }

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

    @Override // androidx.appcompat.widget.ActionBarOverlayLayout.d
    public void e() {
        n.h hVar = this.f22225x;
        if (hVar != null) {
            hVar.a();
            this.f22225x = null;
        }
    }

    @Override // androidx.appcompat.widget.ActionBarOverlayLayout.d
    public void f(int i10) {
        this.f22219r = i10;
    }

    @Override // i.a
    public boolean h() {
        e0 e0Var = this.f22207f;
        if (e0Var == null || !e0Var.k()) {
            return false;
        }
        this.f22207f.collapseActionView();
        return true;
    }

    @Override // i.a
    public void i(boolean z10) {
        if (z10 == this.f22216o) {
            return;
        }
        this.f22216o = z10;
        if (this.f22217p.size() <= 0) {
            return;
        }
        android.support.v4.media.session.b.a(this.f22217p.get(0));
        throw null;
    }

    @Override // i.a
    public int j() {
        return this.f22207f.v();
    }

    @Override // i.a
    public Context k() {
        if (this.f22203b == null) {
            TypedValue typedValue = new TypedValue();
            this.f22202a.getTheme().resolveAttribute(h.a.f20151e, typedValue, true);
            int i10 = typedValue.resourceId;
            if (i10 != 0) {
                this.f22203b = new ContextThemeWrapper(this.f22202a, i10);
            } else {
                this.f22203b = this.f22202a;
            }
        }
        return this.f22203b;
    }

    @Override // i.a
    public void l() {
        if (this.f22221t) {
            return;
        }
        this.f22221t = true;
        U(false);
    }

    @Override // i.a
    public void n(Configuration configuration) {
        P(n.a.b(this.f22202a).e());
    }

    @Override // i.a
    public boolean p(int i10, KeyEvent keyEvent) {
        Menu e10;
        d dVar = this.f22213l;
        if (dVar == null || (e10 = dVar.e()) == null) {
            return false;
        }
        e10.setQwertyMode(KeyCharacterMap.load(keyEvent != null ? keyEvent.getDeviceId() : -1).getKeyboardType() != 1);
        return e10.performShortcut(i10, keyEvent, 0);
    }

    @Override // i.a
    public void s(Drawable drawable) {
        this.f22206e.setPrimaryBackground(drawable);
    }

    @Override // i.a
    public void t(boolean z10) {
        if (this.f22212k) {
            return;
        }
        u(z10);
    }

    @Override // i.a
    public void u(boolean z10) {
        N(z10 ? 4 : 0, 4);
    }

    @Override // i.a
    public void v(boolean z10) {
        N(z10 ? 8 : 0, 8);
    }

    @Override // i.a
    public void w(int i10) {
        this.f22207f.w(i10);
    }

    @Override // i.a
    public void x(int i10) {
        this.f22207f.q(i10);
    }

    @Override // i.a
    public void y(Drawable drawable) {
        this.f22207f.z(drawable);
    }

    @Override // i.a
    public void z(boolean z10) {
        n.h hVar;
        this.f22226y = z10;
        if (z10 || (hVar = this.f22225x) == null) {
            return;
        }
        hVar.a();
    }

    public n(Dialog dialog) {
        M(dialog.getWindow().getDecorView());
    }
}
