package androidx.appcompat.app;

import android.R;
import android.app.Activity;
import android.app.Dialog;
import android.app.UiModeManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.AndroidRuntimeException;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.ActionMode;
import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import android.view.KeyboardShortcutGroup;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import androidx.appcompat.view.menu.h;
import androidx.appcompat.view.menu.o;
import androidx.appcompat.view.menu.p;
import androidx.appcompat.widget.ActionBarContextView;
import androidx.appcompat.widget.ContentFrameLayout;
import androidx.appcompat.widget.ViewStubCompat;
import androidx.appcompat.widget.a0;
import androidx.appcompat.widget.e0;
import androidx.appcompat.widget.t0;
import androidx.appcompat.widget.y0;
import androidx.appcompat.widget.z0;
import com.cvte.vman.impl.FwUpgradeManager;
import g.a.m.b;
import g.a.m.f;
import g.e.j.d;
import g.e.j.o;
import g.e.j.s;
import g.e.j.u;
import g.e.j.w;
import java.lang.Thread;
import java.util.List;
import org.xmlpull.v1.XmlPullParser;

/* JADX INFO: compiled from: AppCompatDelegateImpl.java */
/* JADX INFO: loaded from: classes.dex */
class f extends androidx.appcompat.app.e implements h.a, LayoutInflater.Factory2 {
    private static final boolean U;
    private static final int[] V;
    private static boolean W;
    boolean A;
    boolean B;
    boolean C;
    boolean D;
    boolean E;
    private boolean F;
    private m[] G;
    private m H;
    private boolean I;
    boolean J;
    private boolean L;
    private k M;
    boolean N;
    int O;
    private boolean Q;
    private Rect R;
    private Rect S;
    private AppCompatViewInflater T;
    final Context d;
    final Window e;
    final Window.Callback f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    final Window.Callback f15g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    final androidx.appcompat.app.d f16h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    androidx.appcompat.app.a f17i;

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private CharSequence f19k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private a0 f20l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private h f21m;
    private n n;
    g.a.m.b o;
    ActionBarContextView p;
    PopupWindow q;
    Runnable r;
    private boolean u;
    private ViewGroup v;
    private TextView w;
    private View x;
    private boolean y;
    private boolean z;
    s s = null;
    private boolean t = true;
    private int K = -100;
    private final Runnable P = new b();

    /* JADX INFO: compiled from: AppCompatDelegateImpl.java */
    static class a implements Thread.UncaughtExceptionHandler {
        final /* synthetic */ Thread.UncaughtExceptionHandler a;

        a(Thread.UncaughtExceptionHandler uncaughtExceptionHandler) {
            this.a = uncaughtExceptionHandler;
        }

        private boolean a(Throwable th) {
            String message;
            if (!(th instanceof Resources.NotFoundException) || (message = th.getMessage()) == null) {
                return false;
            }
            return message.contains("drawable") || message.contains("Drawable");
        }

        @Override // java.lang.Thread.UncaughtExceptionHandler
        public void uncaughtException(Thread thread, Throwable th) {
            if (!a(th)) {
                this.a.uncaughtException(thread, th);
                return;
            }
            Resources.NotFoundException notFoundException = new Resources.NotFoundException(th.getMessage() + ". If the resource you are trying to use is a vector resource, you may be referencing it in an unsupported way. See AppCompatDelegate.setCompatVectorFromResourcesEnabled() for more info.");
            notFoundException.initCause(th.getCause());
            notFoundException.setStackTrace(th.getStackTrace());
            this.a.uncaughtException(thread, notFoundException);
        }
    }

    /* JADX INFO: compiled from: AppCompatDelegateImpl.java */
    class b implements Runnable {
        b() {
        }

        @Override // java.lang.Runnable
        public void run() {
            f fVar = f.this;
            if ((fVar.O & 1) != 0) {
                fVar.I(0);
            }
            f fVar2 = f.this;
            if ((fVar2.O & 4096) != 0) {
                fVar2.I(108);
            }
            f fVar3 = f.this;
            fVar3.N = false;
            fVar3.O = 0;
        }
    }

    /* JADX INFO: compiled from: AppCompatDelegateImpl.java */
    class c implements g.e.j.m {
        c() {
        }

        @Override // g.e.j.m
        public w a(View view, w wVar) {
            int iD = wVar.d();
            int iV0 = f.this.v0(iD);
            if (iD != iV0) {
                wVar = wVar.e(wVar.b(), iV0, wVar.c(), wVar.a());
            }
            return o.n(view, wVar);
        }
    }

    /* JADX INFO: compiled from: AppCompatDelegateImpl.java */
    class d implements e0.a {
        d() {
        }

        @Override // androidx.appcompat.widget.e0.a
        public void a(Rect rect) {
            rect.top = f.this.v0(rect.top);
        }
    }

    /* JADX INFO: compiled from: AppCompatDelegateImpl.java */
    class e implements ContentFrameLayout.a {
        e() {
        }

        @Override // androidx.appcompat.widget.ContentFrameLayout.a
        public void a() {
        }

        @Override // androidx.appcompat.widget.ContentFrameLayout.a
        public void onDetachedFromWindow() {
            f.this.G();
        }
    }

    /* JADX INFO: renamed from: androidx.appcompat.app.f$f, reason: collision with other inner class name */
    /* JADX INFO: compiled from: AppCompatDelegateImpl.java */
    class RunnableC0001f implements Runnable {

        /* JADX INFO: renamed from: androidx.appcompat.app.f$f$a */
        /* JADX INFO: compiled from: AppCompatDelegateImpl.java */
        class a extends u {
            a() {
            }

            @Override // g.e.j.t
            public void b(View view) {
                f.this.p.setAlpha(1.0f);
                f.this.s.f(null);
                f.this.s = null;
            }

            @Override // g.e.j.u, g.e.j.t
            public void c(View view) {
                f.this.p.setVisibility(0);
            }
        }

        RunnableC0001f() {
        }

        @Override // java.lang.Runnable
        public void run() {
            f fVar = f.this;
            fVar.q.showAtLocation(fVar.p, 55, 0, 0);
            f.this.J();
            if (!f.this.o0()) {
                f.this.p.setAlpha(1.0f);
                f.this.p.setVisibility(0);
                return;
            }
            f.this.p.setAlpha(0.0f);
            f fVar2 = f.this;
            s sVarA = o.a(fVar2.p);
            sVarA.a(1.0f);
            fVar2.s = sVarA;
            f.this.s.f(new a());
        }
    }

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

        @Override // g.e.j.t
        public void b(View view) {
            f.this.p.setAlpha(1.0f);
            f.this.s.f(null);
            f.this.s = null;
        }

        @Override // g.e.j.u, g.e.j.t
        public void c(View view) {
            f.this.p.setVisibility(0);
            f.this.p.sendAccessibilityEvent(32);
            if (f.this.p.getParent() instanceof View) {
                o.r((View) f.this.p.getParent());
            }
        }
    }

    /* JADX INFO: compiled from: AppCompatDelegateImpl.java */
    private final class h implements o.a {
        h() {
        }

        @Override // androidx.appcompat.view.menu.o.a
        public void a(androidx.appcompat.view.menu.h hVar, boolean z) {
            f.this.B(hVar);
        }

        @Override // androidx.appcompat.view.menu.o.a
        public boolean b(androidx.appcompat.view.menu.h hVar) {
            Window.Callback callbackR = f.this.R();
            if (callbackR == null) {
                return true;
            }
            callbackR.onMenuOpened(108, hVar);
            return true;
        }
    }

    /* JADX INFO: compiled from: AppCompatDelegateImpl.java */
    class i implements b.a {
        private b.a a;

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

            @Override // g.e.j.t
            public void b(View view) {
                f.this.p.setVisibility(8);
                f fVar = f.this;
                PopupWindow popupWindow = fVar.q;
                if (popupWindow != null) {
                    popupWindow.dismiss();
                } else if (fVar.p.getParent() instanceof View) {
                    g.e.j.o.r((View) f.this.p.getParent());
                }
                f.this.p.removeAllViews();
                f.this.s.f(null);
                f.this.s = null;
            }
        }

        public i(b.a aVar) {
            this.a = aVar;
        }

        @Override // g.a.m.b.a
        public boolean a(g.a.m.b bVar, Menu menu) {
            return this.a.a(bVar, menu);
        }

        @Override // g.a.m.b.a
        public void b(g.a.m.b bVar) {
            this.a.b(bVar);
            f fVar = f.this;
            if (fVar.q != null) {
                fVar.e.getDecorView().removeCallbacks(f.this.r);
            }
            f fVar2 = f.this;
            if (fVar2.p != null) {
                fVar2.J();
                f fVar3 = f.this;
                s sVarA = g.e.j.o.a(fVar3.p);
                sVarA.a(0.0f);
                fVar3.s = sVarA;
                f.this.s.f(new a());
            }
            f fVar4 = f.this;
            androidx.appcompat.app.d dVar = fVar4.f16h;
            if (dVar != null) {
                dVar.d(fVar4.o);
            }
            f.this.o = null;
        }

        @Override // g.a.m.b.a
        public boolean c(g.a.m.b bVar, MenuItem menuItem) {
            return this.a.c(bVar, menuItem);
        }

        @Override // g.a.m.b.a
        public boolean d(g.a.m.b bVar, Menu menu) {
            return this.a.d(bVar, menu);
        }
    }

    /* JADX INFO: compiled from: AppCompatDelegateImpl.java */
    final class k {
        private androidx.appcompat.app.j a;
        private boolean b;
        private BroadcastReceiver c;
        private IntentFilter d;

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

            @Override // android.content.BroadcastReceiver
            public void onReceive(Context context, Intent intent) {
                k.this.b();
            }
        }

        k(androidx.appcompat.app.j jVar) {
            this.a = jVar;
            this.b = jVar.d();
        }

        void a() {
            BroadcastReceiver broadcastReceiver = this.c;
            if (broadcastReceiver != null) {
                f.this.d.unregisterReceiver(broadcastReceiver);
                this.c = null;
            }
        }

        void b() {
            boolean zD = this.a.d();
            if (zD != this.b) {
                this.b = zD;
                f.this.d();
            }
        }

        int c() {
            boolean zD = this.a.d();
            this.b = zD;
            return zD ? 2 : 1;
        }

        void d() {
            a();
            if (this.c == null) {
                this.c = new a();
            }
            if (this.d == null) {
                IntentFilter intentFilter = new IntentFilter();
                this.d = intentFilter;
                intentFilter.addAction("android.intent.action.TIME_SET");
                this.d.addAction("android.intent.action.TIMEZONE_CHANGED");
                this.d.addAction("android.intent.action.TIME_TICK");
            }
            f.this.d.registerReceiver(this.c, this.d);
        }
    }

    /* JADX INFO: compiled from: AppCompatDelegateImpl.java */
    private class l extends ContentFrameLayout {
        public l(Context context) {
            super(context);
        }

        private boolean c(int i2, int i3) {
            return i2 < -5 || i3 < -5 || i2 > getWidth() + 5 || i3 > getHeight() + 5;
        }

        @Override // android.view.ViewGroup, android.view.View
        public boolean dispatchKeyEvent(KeyEvent keyEvent) {
            return f.this.H(keyEvent) || super.dispatchKeyEvent(keyEvent);
        }

        @Override // android.view.ViewGroup
        public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
            if (motionEvent.getAction() != 0 || !c((int) motionEvent.getX(), (int) motionEvent.getY())) {
                return super.onInterceptTouchEvent(motionEvent);
            }
            f.this.C(0);
            return true;
        }

        @Override // android.view.View
        public void setBackgroundResource(int i2) {
            setBackgroundDrawable(g.a.k.a.a.d(getContext(), i2));
        }
    }

    /* JADX INFO: compiled from: AppCompatDelegateImpl.java */
    protected static final class m {
        int a;
        int b;
        int c;
        int d;
        int e;
        int f;

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

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

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

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

        /* JADX INFO: renamed from: k, reason: collision with root package name */
        androidx.appcompat.view.menu.f f27k;

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

        /* JADX INFO: renamed from: m, reason: collision with root package name */
        boolean f29m;
        boolean n;
        boolean o;
        public boolean p;
        boolean q = false;
        boolean r;
        Bundle s;

        m(int i2) {
            this.a = i2;
        }

        p a(o.a aVar) {
            if (this.f26j == null) {
                return null;
            }
            if (this.f27k == null) {
                androidx.appcompat.view.menu.f fVar = new androidx.appcompat.view.menu.f(this.f28l, g.a.g.abc_list_menu_item_layout);
                this.f27k = fVar;
                fVar.k(aVar);
                this.f26j.b(this.f27k);
            }
            return this.f27k.d(this.f23g);
        }

        public boolean b() {
            if (this.f24h == null) {
                return false;
            }
            return this.f25i != null || this.f27k.b().getCount() > 0;
        }

        void c(androidx.appcompat.view.menu.h hVar) {
            androidx.appcompat.view.menu.f fVar;
            androidx.appcompat.view.menu.h hVar2 = this.f26j;
            if (hVar == hVar2) {
                return;
            }
            if (hVar2 != null) {
                hVar2.O(this.f27k);
            }
            this.f26j = hVar;
            if (hVar == null || (fVar = this.f27k) == null) {
                return;
            }
            hVar.b(fVar);
        }

        void d(Context context) {
            TypedValue typedValue = new TypedValue();
            Resources.Theme themeNewTheme = context.getResources().newTheme();
            themeNewTheme.setTo(context.getTheme());
            themeNewTheme.resolveAttribute(g.a.a.actionBarPopupTheme, typedValue, true);
            int i2 = typedValue.resourceId;
            if (i2 != 0) {
                themeNewTheme.applyStyle(i2, true);
            }
            themeNewTheme.resolveAttribute(g.a.a.panelMenuListTheme, typedValue, true);
            int i3 = typedValue.resourceId;
            if (i3 != 0) {
                themeNewTheme.applyStyle(i3, true);
            } else {
                themeNewTheme.applyStyle(g.a.i.Theme_AppCompat_CompactMenu, true);
            }
            g.a.m.d dVar = new g.a.m.d(context, 0);
            dVar.getTheme().setTo(themeNewTheme);
            this.f28l = dVar;
            TypedArray typedArrayObtainStyledAttributes = dVar.obtainStyledAttributes(g.a.j.AppCompatTheme);
            this.b = typedArrayObtainStyledAttributes.getResourceId(g.a.j.AppCompatTheme_panelBackground, 0);
            this.f = typedArrayObtainStyledAttributes.getResourceId(g.a.j.AppCompatTheme_android_windowAnimationStyle, 0);
            typedArrayObtainStyledAttributes.recycle();
        }
    }

    /* JADX INFO: compiled from: AppCompatDelegateImpl.java */
    private final class n implements o.a {
        n() {
        }

        @Override // androidx.appcompat.view.menu.o.a
        public void a(androidx.appcompat.view.menu.h hVar, boolean z) {
            androidx.appcompat.view.menu.h hVarD = hVar.D();
            boolean z2 = hVarD != hVar;
            f fVar = f.this;
            if (z2) {
                hVar = hVarD;
            }
            m mVarM = fVar.M(hVar);
            if (mVarM != null) {
                if (!z2) {
                    f.this.D(mVarM, z);
                } else {
                    f.this.A(mVarM.a, mVarM, hVarD);
                    f.this.D(mVarM, true);
                }
            }
        }

        @Override // androidx.appcompat.view.menu.o.a
        public boolean b(androidx.appcompat.view.menu.h hVar) {
            Window.Callback callbackR;
            if (hVar != null) {
                return true;
            }
            f fVar = f.this;
            if (!fVar.A || (callbackR = fVar.R()) == null || f.this.J) {
                return true;
            }
            callbackR.onMenuOpened(108, hVar);
            return true;
        }
    }

    static {
        boolean z = Build.VERSION.SDK_INT < 21;
        U = z;
        V = new int[]{R.attr.windowBackground};
        if (!z || W) {
            return;
        }
        Thread.setDefaultUncaughtExceptionHandler(new a(Thread.getDefaultUncaughtExceptionHandler()));
        W = true;
    }

    f(Context context, Window window, androidx.appcompat.app.d dVar) {
        this.d = context;
        this.e = window;
        this.f16h = dVar;
        Window.Callback callback = window.getCallback();
        this.f = callback;
        if (callback instanceof j) {
            throw new IllegalStateException("AppCompat has already installed itself into the Window");
        }
        j jVar = new j(callback);
        this.f15g = jVar;
        this.e.setCallback(jVar);
        t0 t0VarS = t0.s(context, null, V);
        Drawable drawableG = t0VarS.g(0);
        if (drawableG != null) {
            this.e.setBackgroundDrawable(drawableG);
        }
        t0VarS.u();
    }

    private ViewGroup E() {
        ViewGroup viewGroup;
        TypedArray typedArrayObtainStyledAttributes = this.d.obtainStyledAttributes(g.a.j.AppCompatTheme);
        if (!typedArrayObtainStyledAttributes.hasValue(g.a.j.AppCompatTheme_windowActionBar)) {
            typedArrayObtainStyledAttributes.recycle();
            throw new IllegalStateException("You need to use a Theme.AppCompat theme (or descendant) with this activity.");
        }
        if (typedArrayObtainStyledAttributes.getBoolean(g.a.j.AppCompatTheme_windowNoTitle, false)) {
            u(1);
        } else if (typedArrayObtainStyledAttributes.getBoolean(g.a.j.AppCompatTheme_windowActionBar, false)) {
            u(108);
        }
        if (typedArrayObtainStyledAttributes.getBoolean(g.a.j.AppCompatTheme_windowActionBarOverlay, false)) {
            u(109);
        }
        if (typedArrayObtainStyledAttributes.getBoolean(g.a.j.AppCompatTheme_windowActionModeOverlay, false)) {
            u(10);
        }
        this.D = typedArrayObtainStyledAttributes.getBoolean(g.a.j.AppCompatTheme_android_windowIsFloating, false);
        typedArrayObtainStyledAttributes.recycle();
        this.e.getDecorView();
        LayoutInflater layoutInflaterFrom = LayoutInflater.from(this.d);
        if (this.E) {
            viewGroup = this.C ? (ViewGroup) layoutInflaterFrom.inflate(g.a.g.abc_screen_simple_overlay_action_mode, (ViewGroup) null) : (ViewGroup) layoutInflaterFrom.inflate(g.a.g.abc_screen_simple, (ViewGroup) null);
            if (Build.VERSION.SDK_INT >= 21) {
                g.e.j.o.x(viewGroup, new c());
            } else {
                ((e0) viewGroup).setOnFitSystemWindowsListener(new d());
            }
        } else if (this.D) {
            viewGroup = (ViewGroup) layoutInflaterFrom.inflate(g.a.g.abc_dialog_title_material, (ViewGroup) null);
            this.B = false;
            this.A = false;
        } else if (this.A) {
            TypedValue typedValue = new TypedValue();
            this.d.getTheme().resolveAttribute(g.a.a.actionBarTheme, typedValue, true);
            viewGroup = (ViewGroup) LayoutInflater.from(typedValue.resourceId != 0 ? new g.a.m.d(this.d, typedValue.resourceId) : this.d).inflate(g.a.g.abc_screen_toolbar, (ViewGroup) null);
            a0 a0Var = (a0) viewGroup.findViewById(g.a.f.decor_content_parent);
            this.f20l = a0Var;
            a0Var.setWindowCallback(R());
            if (this.B) {
                this.f20l.k(109);
            }
            if (this.y) {
                this.f20l.k(2);
            }
            if (this.z) {
                this.f20l.k(5);
            }
        } else {
            viewGroup = null;
        }
        if (viewGroup == null) {
            throw new IllegalArgumentException("AppCompat does not support the current theme features: { windowActionBar: " + this.A + ", windowActionBarOverlay: " + this.B + ", android:windowIsFloating: " + this.D + ", windowActionModeOverlay: " + this.C + ", windowNoTitle: " + this.E + " }");
        }
        if (this.f20l == null) {
            this.w = (TextView) viewGroup.findViewById(g.a.f.title);
        }
        z0.c(viewGroup);
        ContentFrameLayout contentFrameLayout = (ContentFrameLayout) viewGroup.findViewById(g.a.f.action_bar_activity_content);
        ViewGroup viewGroup2 = (ViewGroup) this.e.findViewById(R.id.content);
        if (viewGroup2 != null) {
            while (viewGroup2.getChildCount() > 0) {
                View childAt = viewGroup2.getChildAt(0);
                viewGroup2.removeViewAt(0);
                contentFrameLayout.addView(childAt);
            }
            viewGroup2.setId(-1);
            contentFrameLayout.setId(R.id.content);
            if (viewGroup2 instanceof FrameLayout) {
                ((FrameLayout) viewGroup2).setForeground(null);
            }
        }
        this.e.setContentView(viewGroup);
        contentFrameLayout.setAttachListener(new e());
        return viewGroup;
    }

    private void K() {
        if (this.M == null) {
            this.M = new k(androidx.appcompat.app.j.a(this.d));
        }
    }

    private void L() {
        if (this.u) {
            return;
        }
        this.v = E();
        CharSequence charSequenceQ = Q();
        if (!TextUtils.isEmpty(charSequenceQ)) {
            a0 a0Var = this.f20l;
            if (a0Var != null) {
                a0Var.setWindowTitle(charSequenceQ);
            } else if (j0() != null) {
                j0().t(charSequenceQ);
            } else {
                TextView textView = this.w;
                if (textView != null) {
                    textView.setText(charSequenceQ);
                }
            }
        }
        z();
        h0(this.v);
        this.u = true;
        m mVarP = P(0, false);
        if (this.J) {
            return;
        }
        if (mVarP == null || mVarP.f26j == null) {
            W(108);
        }
    }

    private int O() {
        int i2 = this.K;
        return i2 != -100 ? i2 : androidx.appcompat.app.e.h();
    }

    private void S() {
        L();
        if (this.A && this.f17i == null) {
            Window.Callback callback = this.f;
            if (callback instanceof Activity) {
                this.f17i = new androidx.appcompat.app.k((Activity) this.f, this.B);
            } else if (callback instanceof Dialog) {
                this.f17i = new androidx.appcompat.app.k((Dialog) this.f);
            }
            androidx.appcompat.app.a aVar = this.f17i;
            if (aVar != null) {
                aVar.r(this.Q);
            }
        }
    }

    private boolean T(m mVar) {
        View view = mVar.f25i;
        if (view != null) {
            mVar.f24h = view;
            return true;
        }
        if (mVar.f26j == null) {
            return false;
        }
        if (this.n == null) {
            this.n = new n();
        }
        View view2 = (View) mVar.a(this.n);
        mVar.f24h = view2;
        return view2 != null;
    }

    private boolean U(m mVar) {
        mVar.d(N());
        mVar.f23g = new l(mVar.f28l);
        mVar.c = 81;
        return true;
    }

    private boolean V(m mVar) {
        Context context = this.d;
        int i2 = mVar.a;
        if ((i2 == 0 || i2 == 108) && this.f20l != null) {
            TypedValue typedValue = new TypedValue();
            Resources.Theme theme = context.getTheme();
            theme.resolveAttribute(g.a.a.actionBarTheme, typedValue, true);
            Resources.Theme themeNewTheme = null;
            if (typedValue.resourceId != 0) {
                themeNewTheme = context.getResources().newTheme();
                themeNewTheme.setTo(theme);
                themeNewTheme.applyStyle(typedValue.resourceId, true);
                themeNewTheme.resolveAttribute(g.a.a.actionBarWidgetTheme, typedValue, true);
            } else {
                theme.resolveAttribute(g.a.a.actionBarWidgetTheme, typedValue, true);
            }
            if (typedValue.resourceId != 0) {
                if (themeNewTheme == null) {
                    themeNewTheme = context.getResources().newTheme();
                    themeNewTheme.setTo(theme);
                }
                themeNewTheme.applyStyle(typedValue.resourceId, true);
            }
            if (themeNewTheme != null) {
                g.a.m.d dVar = new g.a.m.d(context, 0);
                dVar.getTheme().setTo(themeNewTheme);
                context = dVar;
            }
        }
        androidx.appcompat.view.menu.h hVar = new androidx.appcompat.view.menu.h(context);
        hVar.R(this);
        mVar.c(hVar);
        return true;
    }

    private void W(int i2) {
        this.O = (1 << i2) | this.O;
        if (this.N) {
            return;
        }
        g.e.j.o.p(this.e.getDecorView(), this.P);
        this.N = true;
    }

    private boolean b0(int i2, KeyEvent keyEvent) {
        if (keyEvent.getRepeatCount() != 0) {
            return false;
        }
        m mVarP = P(i2, true);
        if (mVarP.o) {
            return false;
        }
        return l0(mVarP, keyEvent);
    }

    /* JADX WARN: Removed duplicated region for block: B:34:0x0062  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private boolean e0(int r4, android.view.KeyEvent r5) {
        /*
            r3 = this;
            g.a.m.b r0 = r3.o
            r1 = 0
            if (r0 == 0) goto L6
            return r1
        L6:
            r0 = 1
            androidx.appcompat.app.f$m r2 = r3.P(r4, r0)
            if (r4 != 0) goto L43
            androidx.appcompat.widget.a0 r4 = r3.f20l
            if (r4 == 0) goto L43
            boolean r4 = r4.h()
            if (r4 == 0) goto L43
            android.content.Context r4 = r3.d
            android.view.ViewConfiguration r4 = android.view.ViewConfiguration.get(r4)
            boolean r4 = r4.hasPermanentMenuKey()
            if (r4 != 0) goto L43
            androidx.appcompat.widget.a0 r4 = r3.f20l
            boolean r4 = r4.b()
            if (r4 != 0) goto L3c
            boolean r4 = r3.J
            if (r4 != 0) goto L62
            boolean r4 = r3.l0(r2, r5)
            if (r4 == 0) goto L62
            androidx.appcompat.widget.a0 r4 = r3.f20l
            boolean r0 = r4.g()
            goto L6a
        L3c:
            androidx.appcompat.widget.a0 r4 = r3.f20l
            boolean r0 = r4.f()
            goto L6a
        L43:
            boolean r4 = r2.o
            if (r4 != 0) goto L64
            boolean r4 = r2.n
            if (r4 == 0) goto L4c
            goto L64
        L4c:
            boolean r4 = r2.f29m
            if (r4 == 0) goto L62
            boolean r4 = r2.r
            if (r4 == 0) goto L5b
            r2.f29m = r1
            boolean r4 = r3.l0(r2, r5)
            goto L5c
        L5b:
            r4 = r0
        L5c:
            if (r4 == 0) goto L62
            r3.i0(r2, r5)
            goto L6a
        L62:
            r0 = r1
            goto L6a
        L64:
            boolean r4 = r2.o
            r3.D(r2, r0)
            r0 = r4
        L6a:
            if (r0 == 0) goto L83
            android.content.Context r4 = r3.d
            java.lang.String r5 = "audio"
            java.lang.Object r4 = r4.getSystemService(r5)
            android.media.AudioManager r4 = (android.media.AudioManager) r4
            if (r4 == 0) goto L7c
            r4.playSoundEffect(r1)
            goto L83
        L7c:
            java.lang.String r4 = "AppCompatDelegate"
            java.lang.String r5 = "Couldn't get audio manager"
            android.util.Log.w(r4, r5)
        L83:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: androidx.appcompat.app.f.e0(int, android.view.KeyEvent):boolean");
    }

    private void i0(m mVar, KeyEvent keyEvent) {
        int i2;
        ViewGroup.LayoutParams layoutParams;
        if (mVar.o || this.J) {
            return;
        }
        if (mVar.a == 0) {
            if ((this.d.getResources().getConfiguration().screenLayout & 15) == 4) {
                return;
            }
        }
        Window.Callback callbackR = R();
        if (callbackR != null && !callbackR.onMenuOpened(mVar.a, mVar.f26j)) {
            D(mVar, true);
            return;
        }
        WindowManager windowManager = (WindowManager) this.d.getSystemService("window");
        if (windowManager != null && l0(mVar, keyEvent)) {
            if (mVar.f23g != null && !mVar.q) {
                View view = mVar.f25i;
                if (view != null && (layoutParams = view.getLayoutParams()) != null && layoutParams.width == -1) {
                    i2 = -1;
                }
                mVar.n = false;
                WindowManager.LayoutParams layoutParams2 = new WindowManager.LayoutParams(i2, -2, mVar.d, mVar.e, FwUpgradeManager.TYPE_FW_SXCAM_MC1_32_CAMERA, 8519680, -3);
                layoutParams2.gravity = mVar.c;
                layoutParams2.windowAnimations = mVar.f;
                windowManager.addView(mVar.f23g, layoutParams2);
                mVar.o = true;
            }
            ViewGroup viewGroup = mVar.f23g;
            if (viewGroup == null) {
                if (!U(mVar) || mVar.f23g == null) {
                    return;
                }
            } else if (mVar.q && viewGroup.getChildCount() > 0) {
                mVar.f23g.removeAllViews();
            }
            if (!T(mVar) || !mVar.b()) {
                return;
            }
            ViewGroup.LayoutParams layoutParams3 = mVar.f24h.getLayoutParams();
            if (layoutParams3 == null) {
                layoutParams3 = new ViewGroup.LayoutParams(-2, -2);
            }
            mVar.f23g.setBackgroundResource(mVar.b);
            ViewParent parent = mVar.f24h.getParent();
            if (parent != null && (parent instanceof ViewGroup)) {
                ((ViewGroup) parent).removeView(mVar.f24h);
            }
            mVar.f23g.addView(mVar.f24h, layoutParams3);
            if (!mVar.f24h.hasFocus()) {
                mVar.f24h.requestFocus();
            }
            i2 = -2;
            mVar.n = false;
            WindowManager.LayoutParams layoutParams22 = new WindowManager.LayoutParams(i2, -2, mVar.d, mVar.e, FwUpgradeManager.TYPE_FW_SXCAM_MC1_32_CAMERA, 8519680, -3);
            layoutParams22.gravity = mVar.c;
            layoutParams22.windowAnimations = mVar.f;
            windowManager.addView(mVar.f23g, layoutParams22);
            mVar.o = true;
        }
    }

    private boolean k0(m mVar, int i2, KeyEvent keyEvent, int i3) {
        androidx.appcompat.view.menu.h hVar;
        boolean zPerformShortcut = false;
        if (keyEvent.isSystem()) {
            return false;
        }
        if ((mVar.f29m || l0(mVar, keyEvent)) && (hVar = mVar.f26j) != null) {
            zPerformShortcut = hVar.performShortcut(i2, keyEvent, i3);
        }
        if (zPerformShortcut && (i3 & 1) == 0 && this.f20l == null) {
            D(mVar, true);
        }
        return zPerformShortcut;
    }

    private boolean l0(m mVar, KeyEvent keyEvent) {
        a0 a0Var;
        a0 a0Var2;
        a0 a0Var3;
        if (this.J) {
            return false;
        }
        if (mVar.f29m) {
            return true;
        }
        m mVar2 = this.H;
        if (mVar2 != null && mVar2 != mVar) {
            D(mVar2, false);
        }
        Window.Callback callbackR = R();
        if (callbackR != null) {
            mVar.f25i = callbackR.onCreatePanelView(mVar.a);
        }
        int i2 = mVar.a;
        boolean z = i2 == 0 || i2 == 108;
        if (z && (a0Var3 = this.f20l) != null) {
            a0Var3.d();
        }
        if (mVar.f25i == null) {
            if (z) {
                j0();
            }
            if (mVar.f26j == null || mVar.r) {
                if (mVar.f26j == null && (!V(mVar) || mVar.f26j == null)) {
                    return false;
                }
                if (z && this.f20l != null) {
                    if (this.f21m == null) {
                        this.f21m = new h();
                    }
                    this.f20l.a(mVar.f26j, this.f21m);
                }
                mVar.f26j.d0();
                if (!callbackR.onCreatePanelMenu(mVar.a, mVar.f26j)) {
                    mVar.c(null);
                    if (z && (a0Var = this.f20l) != null) {
                        a0Var.a(null, this.f21m);
                    }
                    return false;
                }
                mVar.r = false;
            }
            mVar.f26j.d0();
            Bundle bundle = mVar.s;
            if (bundle != null) {
                mVar.f26j.P(bundle);
                mVar.s = null;
            }
            if (!callbackR.onPreparePanel(0, mVar.f25i, mVar.f26j)) {
                if (z && (a0Var2 = this.f20l) != null) {
                    a0Var2.a(null, this.f21m);
                }
                mVar.f26j.c0();
                return false;
            }
            boolean z2 = KeyCharacterMap.load(keyEvent != null ? keyEvent.getDeviceId() : -1).getKeyboardType() != 1;
            mVar.p = z2;
            mVar.f26j.setQwertyMode(z2);
            mVar.f26j.c0();
        }
        mVar.f29m = true;
        mVar.n = false;
        this.H = mVar;
        return true;
    }

    private void m0(androidx.appcompat.view.menu.h hVar, boolean z) {
        a0 a0Var = this.f20l;
        if (a0Var == null || !a0Var.h() || (ViewConfiguration.get(this.d).hasPermanentMenuKey() && !this.f20l.e())) {
            m mVarP = P(0, true);
            mVarP.q = true;
            D(mVarP, false);
            i0(mVarP, null);
            return;
        }
        Window.Callback callbackR = R();
        if (this.f20l.b() && z) {
            this.f20l.f();
            if (this.J) {
                return;
            }
            callbackR.onPanelClosed(108, P(0, true).f26j);
            return;
        }
        if (callbackR == null || this.J) {
            return;
        }
        if (this.N && (this.O & 1) != 0) {
            this.e.getDecorView().removeCallbacks(this.P);
            this.P.run();
        }
        m mVarP2 = P(0, true);
        androidx.appcompat.view.menu.h hVar2 = mVarP2.f26j;
        if (hVar2 == null || mVarP2.r || !callbackR.onPreparePanel(0, mVarP2.f25i, hVar2)) {
            return;
        }
        callbackR.onMenuOpened(108, mVarP2.f26j);
        this.f20l.g();
    }

    private int n0(int i2) {
        if (i2 == 8) {
            Log.i("AppCompatDelegate", "You should now use the AppCompatDelegate.FEATURE_SUPPORT_ACTION_BAR id when requesting this feature.");
            return 108;
        }
        if (i2 != 9) {
            return i2;
        }
        Log.i("AppCompatDelegate", "You should now use the AppCompatDelegate.FEATURE_SUPPORT_ACTION_BAR_OVERLAY id when requesting this feature.");
        return 109;
    }

    private boolean p0(ViewParent viewParent) {
        if (viewParent == null) {
            return false;
        }
        View decorView = this.e.getDecorView();
        while (viewParent != null) {
            if (viewParent == decorView || !(viewParent instanceof View) || g.e.j.o.l((View) viewParent)) {
                return false;
            }
            viewParent = viewParent.getParent();
        }
        return true;
    }

    private boolean q0() {
        if (this.L) {
            Context context = this.d;
            if (context instanceof Activity) {
                try {
                    return (context.getPackageManager().getActivityInfo(new ComponentName(this.d, this.d.getClass()), 0).configChanges & 512) == 0;
                } catch (PackageManager.NameNotFoundException e2) {
                    Log.d("AppCompatDelegate", "Exception while getting ActivityInfo", e2);
                    return true;
                }
            }
        }
        return false;
    }

    private void t0() {
        if (this.u) {
            throw new AndroidRuntimeException("Window feature must be requested before adding content");
        }
    }

    private boolean u0(int i2) {
        Resources resources = this.d.getResources();
        Configuration configuration = resources.getConfiguration();
        int i3 = configuration.uiMode & 48;
        int i4 = i2 == 2 ? 32 : 16;
        if (i3 == i4) {
            return false;
        }
        if (q0()) {
            ((Activity) this.d).recreate();
            return true;
        }
        Configuration configuration2 = new Configuration(configuration);
        DisplayMetrics displayMetrics = resources.getDisplayMetrics();
        configuration2.uiMode = i4 | (configuration2.uiMode & (-49));
        resources.updateConfiguration(configuration2, displayMetrics);
        if (Build.VERSION.SDK_INT >= 26) {
            return true;
        }
        androidx.appcompat.app.h.a(resources);
        return true;
    }

    private void z() {
        ContentFrameLayout contentFrameLayout = (ContentFrameLayout) this.v.findViewById(R.id.content);
        View decorView = this.e.getDecorView();
        contentFrameLayout.b(decorView.getPaddingLeft(), decorView.getPaddingTop(), decorView.getPaddingRight(), decorView.getPaddingBottom());
        TypedArray typedArrayObtainStyledAttributes = this.d.obtainStyledAttributes(g.a.j.AppCompatTheme);
        typedArrayObtainStyledAttributes.getValue(g.a.j.AppCompatTheme_windowMinWidthMajor, contentFrameLayout.getMinWidthMajor());
        typedArrayObtainStyledAttributes.getValue(g.a.j.AppCompatTheme_windowMinWidthMinor, contentFrameLayout.getMinWidthMinor());
        if (typedArrayObtainStyledAttributes.hasValue(g.a.j.AppCompatTheme_windowFixedWidthMajor)) {
            typedArrayObtainStyledAttributes.getValue(g.a.j.AppCompatTheme_windowFixedWidthMajor, contentFrameLayout.getFixedWidthMajor());
        }
        if (typedArrayObtainStyledAttributes.hasValue(g.a.j.AppCompatTheme_windowFixedWidthMinor)) {
            typedArrayObtainStyledAttributes.getValue(g.a.j.AppCompatTheme_windowFixedWidthMinor, contentFrameLayout.getFixedWidthMinor());
        }
        if (typedArrayObtainStyledAttributes.hasValue(g.a.j.AppCompatTheme_windowFixedHeightMajor)) {
            typedArrayObtainStyledAttributes.getValue(g.a.j.AppCompatTheme_windowFixedHeightMajor, contentFrameLayout.getFixedHeightMajor());
        }
        if (typedArrayObtainStyledAttributes.hasValue(g.a.j.AppCompatTheme_windowFixedHeightMinor)) {
            typedArrayObtainStyledAttributes.getValue(g.a.j.AppCompatTheme_windowFixedHeightMinor, contentFrameLayout.getFixedHeightMinor());
        }
        typedArrayObtainStyledAttributes.recycle();
        contentFrameLayout.requestLayout();
    }

    void A(int i2, m mVar, Menu menu) {
        if (menu == null) {
            if (mVar == null && i2 >= 0) {
                m[] mVarArr = this.G;
                if (i2 < mVarArr.length) {
                    mVar = mVarArr[i2];
                }
            }
            if (mVar != null) {
                menu = mVar.f26j;
            }
        }
        if ((mVar == null || mVar.o) && !this.J) {
            this.f.onPanelClosed(i2, menu);
        }
    }

    void B(androidx.appcompat.view.menu.h hVar) {
        if (this.F) {
            return;
        }
        this.F = true;
        this.f20l.l();
        Window.Callback callbackR = R();
        if (callbackR != null && !this.J) {
            callbackR.onPanelClosed(108, hVar);
        }
        this.F = false;
    }

    void C(int i2) {
        D(P(i2, true), true);
    }

    void D(m mVar, boolean z) {
        ViewGroup viewGroup;
        a0 a0Var;
        if (z && mVar.a == 0 && (a0Var = this.f20l) != null && a0Var.b()) {
            B(mVar.f26j);
            return;
        }
        WindowManager windowManager = (WindowManager) this.d.getSystemService("window");
        if (windowManager != null && mVar.o && (viewGroup = mVar.f23g) != null) {
            windowManager.removeView(viewGroup);
            if (z) {
                A(mVar.a, mVar, null);
            }
        }
        mVar.f29m = false;
        mVar.n = false;
        mVar.o = false;
        mVar.f24h = null;
        mVar.q = true;
        if (this.H == mVar) {
            this.H = null;
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    public View F(View view, String str, Context context, AttributeSet attributeSet) {
        boolean zP0 = false;
        if (this.T == null) {
            String string = this.d.obtainStyledAttributes(g.a.j.AppCompatTheme).getString(g.a.j.AppCompatTheme_viewInflaterClass);
            if (string == null || AppCompatViewInflater.class.getName().equals(string)) {
                this.T = new AppCompatViewInflater();
            } else {
                try {
                    this.T = (AppCompatViewInflater) Class.forName(string).getDeclaredConstructor(new Class[0]).newInstance(new Object[0]);
                } catch (Throwable th) {
                    Log.i("AppCompatDelegate", "Failed to instantiate custom view inflater " + string + ". Falling back to default.", th);
                    this.T = new AppCompatViewInflater();
                }
            }
        }
        if (U) {
            if (!(attributeSet instanceof XmlPullParser)) {
                zP0 = p0((ViewParent) view);
            } else if (((XmlPullParser) attributeSet).getDepth() > 1) {
                zP0 = true;
            }
        }
        return this.T.p(view, str, context, attributeSet, zP0, U, true, y0.b());
    }

    void G() {
        androidx.appcompat.view.menu.h hVar;
        a0 a0Var = this.f20l;
        if (a0Var != null) {
            a0Var.l();
        }
        if (this.q != null) {
            this.e.getDecorView().removeCallbacks(this.r);
            if (this.q.isShowing()) {
                try {
                    this.q.dismiss();
                } catch (IllegalArgumentException unused) {
                }
            }
            this.q = null;
        }
        J();
        m mVarP = P(0, false);
        if (mVarP == null || (hVar = mVarP.f26j) == null) {
            return;
        }
        hVar.close();
    }

    boolean H(KeyEvent keyEvent) {
        View decorView;
        Window.Callback callback = this.f;
        if (((callback instanceof d.a) || (callback instanceof androidx.appcompat.app.g)) && (decorView = this.e.getDecorView()) != null && g.e.j.d.d(decorView, keyEvent)) {
            return true;
        }
        if (keyEvent.getKeyCode() == 82 && this.f.dispatchKeyEvent(keyEvent)) {
            return true;
        }
        int keyCode = keyEvent.getKeyCode();
        return keyEvent.getAction() == 0 ? a0(keyCode, keyEvent) : d0(keyCode, keyEvent);
    }

    void I(int i2) {
        m mVarP;
        m mVarP2 = P(i2, true);
        if (mVarP2.f26j != null) {
            Bundle bundle = new Bundle();
            mVarP2.f26j.Q(bundle);
            if (bundle.size() > 0) {
                mVarP2.s = bundle;
            }
            mVarP2.f26j.d0();
            mVarP2.f26j.clear();
        }
        mVarP2.r = true;
        mVarP2.q = true;
        if ((i2 != 108 && i2 != 0) || this.f20l == null || (mVarP = P(0, false)) == null) {
            return;
        }
        mVarP.f29m = false;
        l0(mVarP, null);
    }

    void J() {
        s sVar = this.s;
        if (sVar != null) {
            sVar.b();
        }
    }

    m M(Menu menu) {
        m[] mVarArr = this.G;
        int length = mVarArr != null ? mVarArr.length : 0;
        for (int i2 = 0; i2 < length; i2++) {
            m mVar = mVarArr[i2];
            if (mVar != null && mVar.f26j == menu) {
                return mVar;
            }
        }
        return null;
    }

    final Context N() {
        androidx.appcompat.app.a aVarJ = j();
        Context contextK = aVarJ != null ? aVarJ.k() : null;
        return contextK == null ? this.d : contextK;
    }

    protected m P(int i2, boolean z) {
        m[] mVarArr = this.G;
        if (mVarArr == null || mVarArr.length <= i2) {
            m[] mVarArr2 = new m[i2 + 1];
            if (mVarArr != null) {
                System.arraycopy(mVarArr, 0, mVarArr2, 0, mVarArr.length);
            }
            this.G = mVarArr2;
            mVarArr = mVarArr2;
        }
        m mVar = mVarArr[i2];
        if (mVar != null) {
            return mVar;
        }
        m mVar2 = new m(i2);
        mVarArr[i2] = mVar2;
        return mVar2;
    }

    final CharSequence Q() {
        Window.Callback callback = this.f;
        return callback instanceof Activity ? ((Activity) callback).getTitle() : this.f19k;
    }

    final Window.Callback R() {
        return this.e.getCallback();
    }

    public boolean X() {
        return this.t;
    }

    int Y(int i2) {
        if (i2 == -100) {
            return -1;
        }
        if (i2 != 0) {
            return i2;
        }
        if (Build.VERSION.SDK_INT >= 23 && ((UiModeManager) this.d.getSystemService(UiModeManager.class)).getNightMode() == 0) {
            return -1;
        }
        K();
        return this.M.c();
    }

    boolean Z() {
        g.a.m.b bVar = this.o;
        if (bVar != null) {
            bVar.c();
            return true;
        }
        androidx.appcompat.app.a aVarJ = j();
        return aVarJ != null && aVarJ.h();
    }

    @Override // androidx.appcompat.view.menu.h.a
    public boolean a(androidx.appcompat.view.menu.h hVar, MenuItem menuItem) {
        m mVarM;
        Window.Callback callbackR = R();
        if (callbackR == null || this.J || (mVarM = M(hVar.D())) == null) {
            return false;
        }
        return callbackR.onMenuItemSelected(mVarM.a, menuItem);
    }

    boolean a0(int i2, KeyEvent keyEvent) {
        if (i2 == 4) {
            this.I = (keyEvent.getFlags() & 128) != 0;
        } else if (i2 == 82) {
            b0(0, keyEvent);
            return true;
        }
        return false;
    }

    @Override // androidx.appcompat.view.menu.h.a
    public void b(androidx.appcompat.view.menu.h hVar) {
        m0(hVar, true);
    }

    @Override // androidx.appcompat.app.e
    public void c(View view, ViewGroup.LayoutParams layoutParams) {
        L();
        ((ViewGroup) this.v.findViewById(R.id.content)).addView(view, layoutParams);
        this.f.onContentChanged();
    }

    boolean c0(int i2, KeyEvent keyEvent) {
        androidx.appcompat.app.a aVarJ = j();
        if (aVarJ != null && aVarJ.o(i2, keyEvent)) {
            return true;
        }
        m mVar = this.H;
        if (mVar != null && k0(mVar, keyEvent.getKeyCode(), keyEvent, 1)) {
            m mVar2 = this.H;
            if (mVar2 != null) {
                mVar2.n = true;
            }
            return true;
        }
        if (this.H == null) {
            m mVarP = P(0, true);
            l0(mVarP, keyEvent);
            boolean zK0 = k0(mVarP, keyEvent.getKeyCode(), keyEvent, 1);
            mVarP.f29m = false;
            if (zK0) {
                return true;
            }
        }
        return false;
    }

    @Override // androidx.appcompat.app.e
    public boolean d() {
        int iO = O();
        int iY = Y(iO);
        boolean zU0 = iY != -1 ? u0(iY) : false;
        if (iO == 0) {
            K();
            this.M.d();
        }
        this.L = true;
        return zU0;
    }

    boolean d0(int i2, KeyEvent keyEvent) {
        if (i2 == 4) {
            boolean z = this.I;
            this.I = false;
            m mVarP = P(0, false);
            if (mVarP != null && mVarP.o) {
                if (!z) {
                    D(mVarP, true);
                }
                return true;
            }
            if (Z()) {
                return true;
            }
        } else if (i2 == 82) {
            e0(0, keyEvent);
            return true;
        }
        return false;
    }

    void f0(int i2) {
        androidx.appcompat.app.a aVarJ;
        if (i2 != 108 || (aVarJ = j()) == null) {
            return;
        }
        aVarJ.i(true);
    }

    @Override // androidx.appcompat.app.e
    public <T extends View> T g(int i2) {
        L();
        return (T) this.e.findViewById(i2);
    }

    void g0(int i2) {
        if (i2 == 108) {
            androidx.appcompat.app.a aVarJ = j();
            if (aVarJ != null) {
                aVarJ.i(false);
                return;
            }
            return;
        }
        if (i2 == 0) {
            m mVarP = P(i2, true);
            if (mVarP.o) {
                D(mVarP, false);
            }
        }
    }

    void h0(ViewGroup viewGroup) {
    }

    @Override // androidx.appcompat.app.e
    public MenuInflater i() {
        if (this.f18j == null) {
            S();
            androidx.appcompat.app.a aVar = this.f17i;
            this.f18j = new g.a.m.g(aVar != null ? aVar.k() : this.d);
        }
        return this.f18j;
    }

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

    final androidx.appcompat.app.a j0() {
        return this.f17i;
    }

    @Override // androidx.appcompat.app.e
    public void k() {
        LayoutInflater layoutInflaterFrom = LayoutInflater.from(this.d);
        if (layoutInflaterFrom.getFactory() == null) {
            g.e.j.e.b(layoutInflaterFrom, this);
        } else {
            if (layoutInflaterFrom.getFactory2() instanceof f) {
                return;
            }
            Log.i("AppCompatDelegate", "The Activity's LayoutInflater already has a Factory installed so we can not install AppCompat's");
        }
    }

    @Override // androidx.appcompat.app.e
    public void l() {
        androidx.appcompat.app.a aVarJ = j();
        if (aVarJ == null || !aVarJ.l()) {
            W(0);
        }
    }

    @Override // androidx.appcompat.app.e
    public void m(Configuration configuration) {
        androidx.appcompat.app.a aVarJ;
        if (this.A && this.u && (aVarJ = j()) != null) {
            aVarJ.m(configuration);
        }
        androidx.appcompat.widget.j.n().y(this.d);
        d();
    }

    @Override // androidx.appcompat.app.e
    public void n(Bundle bundle) {
        Window.Callback callback = this.f;
        if (callback instanceof Activity) {
            String strC = null;
            try {
                strC = androidx.core.app.e.c((Activity) callback);
            } catch (IllegalArgumentException unused) {
            }
            if (strC != null) {
                androidx.appcompat.app.a aVarJ0 = j0();
                if (aVarJ0 == null) {
                    this.Q = true;
                } else {
                    aVarJ0.r(true);
                }
            }
        }
        if (bundle == null || this.K != -100) {
            return;
        }
        this.K = bundle.getInt("appcompat:local_night_mode", -100);
    }

    @Override // androidx.appcompat.app.e
    public void o() {
        if (this.N) {
            this.e.getDecorView().removeCallbacks(this.P);
        }
        this.J = true;
        androidx.appcompat.app.a aVar = this.f17i;
        if (aVar != null) {
            aVar.n();
        }
        k kVar = this.M;
        if (kVar != null) {
            kVar.a();
        }
    }

    final boolean o0() {
        ViewGroup viewGroup;
        return this.u && (viewGroup = this.v) != null && g.e.j.o.m(viewGroup);
    }

    @Override // android.view.LayoutInflater.Factory2
    public final View onCreateView(View view, String str, Context context, AttributeSet attributeSet) {
        return F(view, str, context, attributeSet);
    }

    @Override // androidx.appcompat.app.e
    public void p(Bundle bundle) {
        L();
    }

    @Override // androidx.appcompat.app.e
    public void q() {
        androidx.appcompat.app.a aVarJ = j();
        if (aVarJ != null) {
            aVarJ.s(true);
        }
    }

    @Override // androidx.appcompat.app.e
    public void r(Bundle bundle) {
        int i2 = this.K;
        if (i2 != -100) {
            bundle.putInt("appcompat:local_night_mode", i2);
        }
    }

    public g.a.m.b r0(b.a aVar) {
        androidx.appcompat.app.d dVar;
        if (aVar == null) {
            throw new IllegalArgumentException("ActionMode callback can not be null.");
        }
        g.a.m.b bVar = this.o;
        if (bVar != null) {
            bVar.c();
        }
        i iVar = new i(aVar);
        androidx.appcompat.app.a aVarJ = j();
        if (aVarJ != null) {
            g.a.m.b bVarU = aVarJ.u(iVar);
            this.o = bVarU;
            if (bVarU != null && (dVar = this.f16h) != null) {
                dVar.c(bVarU);
            }
        }
        if (this.o == null) {
            this.o = s0(iVar);
        }
        return this.o;
    }

    @Override // androidx.appcompat.app.e
    public void s() {
        d();
    }

    g.a.m.b s0(b.a aVar) {
        g.a.m.b bVarF;
        Context dVar;
        androidx.appcompat.app.d dVar2;
        J();
        g.a.m.b bVar = this.o;
        if (bVar != null) {
            bVar.c();
        }
        if (!(aVar instanceof i)) {
            aVar = new i(aVar);
        }
        androidx.appcompat.app.d dVar3 = this.f16h;
        if (dVar3 == null || this.J) {
            bVarF = null;
        } else {
            try {
                bVarF = dVar3.f(aVar);
            } catch (AbstractMethodError unused) {
                bVarF = null;
            }
        }
        if (bVarF != null) {
            this.o = bVarF;
        } else {
            if (this.p == null) {
                if (this.D) {
                    TypedValue typedValue = new TypedValue();
                    Resources.Theme theme = this.d.getTheme();
                    theme.resolveAttribute(g.a.a.actionBarTheme, typedValue, true);
                    if (typedValue.resourceId != 0) {
                        Resources.Theme themeNewTheme = this.d.getResources().newTheme();
                        themeNewTheme.setTo(theme);
                        themeNewTheme.applyStyle(typedValue.resourceId, true);
                        dVar = new g.a.m.d(this.d, 0);
                        dVar.getTheme().setTo(themeNewTheme);
                    } else {
                        dVar = this.d;
                    }
                    this.p = new ActionBarContextView(dVar);
                    PopupWindow popupWindow = new PopupWindow(dVar, (AttributeSet) null, g.a.a.actionModePopupWindowStyle);
                    this.q = popupWindow;
                    androidx.core.widget.h.b(popupWindow, 2);
                    this.q.setContentView(this.p);
                    this.q.setWidth(-1);
                    dVar.getTheme().resolveAttribute(g.a.a.actionBarSize, typedValue, true);
                    this.p.setContentHeight(TypedValue.complexToDimensionPixelSize(typedValue.data, dVar.getResources().getDisplayMetrics()));
                    this.q.setHeight(-2);
                    this.r = new RunnableC0001f();
                } else {
                    ViewStubCompat viewStubCompat = (ViewStubCompat) this.v.findViewById(g.a.f.action_mode_bar_stub);
                    if (viewStubCompat != null) {
                        viewStubCompat.setLayoutInflater(LayoutInflater.from(N()));
                        this.p = (ActionBarContextView) viewStubCompat.a();
                    }
                }
            }
            if (this.p != null) {
                J();
                this.p.k();
                g.a.m.e eVar = new g.a.m.e(this.p.getContext(), this.p, aVar, this.q == null);
                if (aVar.d(eVar, eVar.e())) {
                    eVar.k();
                    this.p.h(eVar);
                    this.o = eVar;
                    if (o0()) {
                        this.p.setAlpha(0.0f);
                        s sVarA = g.e.j.o.a(this.p);
                        sVarA.a(1.0f);
                        this.s = sVarA;
                        sVarA.f(new g());
                    } else {
                        this.p.setAlpha(1.0f);
                        this.p.setVisibility(0);
                        this.p.sendAccessibilityEvent(32);
                        if (this.p.getParent() instanceof View) {
                            g.e.j.o.r((View) this.p.getParent());
                        }
                    }
                    if (this.q != null) {
                        this.e.getDecorView().post(this.r);
                    }
                } else {
                    this.o = null;
                }
            }
        }
        g.a.m.b bVar2 = this.o;
        if (bVar2 != null && (dVar2 = this.f16h) != null) {
            dVar2.c(bVar2);
        }
        return this.o;
    }

    @Override // androidx.appcompat.app.e
    public void t() {
        androidx.appcompat.app.a aVarJ = j();
        if (aVarJ != null) {
            aVarJ.s(false);
        }
        k kVar = this.M;
        if (kVar != null) {
            kVar.a();
        }
    }

    @Override // androidx.appcompat.app.e
    public boolean u(int i2) {
        int iN0 = n0(i2);
        if (this.E && iN0 == 108) {
            return false;
        }
        if (this.A && iN0 == 1) {
            this.A = false;
        }
        if (iN0 == 1) {
            t0();
            this.E = true;
            return true;
        }
        if (iN0 == 2) {
            t0();
            this.y = true;
            return true;
        }
        if (iN0 == 5) {
            t0();
            this.z = true;
            return true;
        }
        if (iN0 == 10) {
            t0();
            this.C = true;
            return true;
        }
        if (iN0 == 108) {
            t0();
            this.A = true;
            return true;
        }
        if (iN0 != 109) {
            return this.e.requestFeature(iN0);
        }
        t0();
        this.B = true;
        return true;
    }

    @Override // androidx.appcompat.app.e
    public void v(int i2) {
        L();
        ViewGroup viewGroup = (ViewGroup) this.v.findViewById(R.id.content);
        viewGroup.removeAllViews();
        LayoutInflater.from(this.d).inflate(i2, viewGroup);
        this.f.onContentChanged();
    }

    int v0(int i2) {
        boolean z;
        boolean z2;
        ActionBarContextView actionBarContextView = this.p;
        if (actionBarContextView == null || !(actionBarContextView.getLayoutParams() instanceof ViewGroup.MarginLayoutParams)) {
            z = false;
        } else {
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) this.p.getLayoutParams();
            if (this.p.isShown()) {
                if (this.R == null) {
                    this.R = new Rect();
                    this.S = new Rect();
                }
                Rect rect = this.R;
                Rect rect2 = this.S;
                rect.set(0, i2, 0, 0);
                z0.a(this.v, rect, rect2);
                if (marginLayoutParams.topMargin != (rect2.top == 0 ? i2 : 0)) {
                    marginLayoutParams.topMargin = i2;
                    View view = this.x;
                    if (view == null) {
                        View view2 = new View(this.d);
                        this.x = view2;
                        view2.setBackgroundColor(this.d.getResources().getColor(g.a.c.abc_input_method_navigation_guard));
                        this.v.addView(this.x, -1, new ViewGroup.LayoutParams(-1, i2));
                    } else {
                        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
                        if (layoutParams.height != i2) {
                            layoutParams.height = i2;
                            this.x.setLayoutParams(layoutParams);
                        }
                    }
                    z2 = true;
                } else {
                    z2 = false;
                }
                z = this.x != null;
                if (!this.C && z) {
                    i2 = 0;
                }
                boolean z3 = z;
                z = z2;
                z = z3;
            } else if (marginLayoutParams.topMargin != 0) {
                marginLayoutParams.topMargin = 0;
                z = false;
            } else {
                z = false;
                z = false;
            }
            if (z) {
                this.p.setLayoutParams(marginLayoutParams);
            }
        }
        View view3 = this.x;
        if (view3 != null) {
            view3.setVisibility(z ? 0 : 8);
        }
        return i2;
    }

    @Override // androidx.appcompat.app.e
    public void w(View view) {
        L();
        ViewGroup viewGroup = (ViewGroup) this.v.findViewById(R.id.content);
        viewGroup.removeAllViews();
        viewGroup.addView(view);
        this.f.onContentChanged();
    }

    @Override // androidx.appcompat.app.e
    public void x(View view, ViewGroup.LayoutParams layoutParams) {
        L();
        ViewGroup viewGroup = (ViewGroup) this.v.findViewById(R.id.content);
        viewGroup.removeAllViews();
        viewGroup.addView(view, layoutParams);
        this.f.onContentChanged();
    }

    @Override // androidx.appcompat.app.e
    public final void y(CharSequence charSequence) {
        this.f19k = charSequence;
        a0 a0Var = this.f20l;
        if (a0Var != null) {
            a0Var.setWindowTitle(charSequence);
            return;
        }
        if (j0() != null) {
            j0().t(charSequence);
            return;
        }
        TextView textView = this.w;
        if (textView != null) {
            textView.setText(charSequence);
        }
    }

    @Override // android.view.LayoutInflater.Factory
    public View onCreateView(String str, Context context, AttributeSet attributeSet) {
        return onCreateView(null, str, context, attributeSet);
    }

    /* JADX INFO: compiled from: AppCompatDelegateImpl.java */
    class j extends g.a.m.i {
        j(Window.Callback callback) {
            super(callback);
        }

        final ActionMode a(ActionMode.Callback callback) {
            f.a aVar = new f.a(f.this.d, callback);
            g.a.m.b bVarR0 = f.this.r0(aVar);
            if (bVarR0 != null) {
                return aVar.e(bVarR0);
            }
            return null;
        }

        @Override // g.a.m.i, android.view.Window.Callback
        public boolean dispatchKeyEvent(KeyEvent keyEvent) {
            return f.this.H(keyEvent) || super.dispatchKeyEvent(keyEvent);
        }

        @Override // g.a.m.i, android.view.Window.Callback
        public boolean dispatchKeyShortcutEvent(KeyEvent keyEvent) {
            return super.dispatchKeyShortcutEvent(keyEvent) || f.this.c0(keyEvent.getKeyCode(), keyEvent);
        }

        @Override // android.view.Window.Callback
        public void onContentChanged() {
        }

        @Override // g.a.m.i, android.view.Window.Callback
        public boolean onCreatePanelMenu(int i2, Menu menu) {
            if (i2 != 0 || (menu instanceof androidx.appcompat.view.menu.h)) {
                return super.onCreatePanelMenu(i2, menu);
            }
            return false;
        }

        @Override // g.a.m.i, android.view.Window.Callback
        public boolean onMenuOpened(int i2, Menu menu) {
            super.onMenuOpened(i2, menu);
            f.this.f0(i2);
            return true;
        }

        @Override // g.a.m.i, android.view.Window.Callback
        public void onPanelClosed(int i2, Menu menu) {
            super.onPanelClosed(i2, menu);
            f.this.g0(i2);
        }

        @Override // g.a.m.i, android.view.Window.Callback
        public boolean onPreparePanel(int i2, View view, Menu menu) {
            androidx.appcompat.view.menu.h hVar = menu instanceof androidx.appcompat.view.menu.h ? (androidx.appcompat.view.menu.h) menu : null;
            if (i2 == 0 && hVar == null) {
                return false;
            }
            if (hVar != null) {
                hVar.a0(true);
            }
            boolean zOnPreparePanel = super.onPreparePanel(i2, view, menu);
            if (hVar != null) {
                hVar.a0(false);
            }
            return zOnPreparePanel;
        }

        @Override // g.a.m.i, android.view.Window.Callback
        public void onProvideKeyboardShortcuts(List<KeyboardShortcutGroup> list, Menu menu, int i2) {
            androidx.appcompat.view.menu.h hVar;
            m mVarP = f.this.P(0, true);
            if (mVarP == null || (hVar = mVarP.f26j) == null) {
                super.onProvideKeyboardShortcuts(list, menu, i2);
            } else {
                super.onProvideKeyboardShortcuts(list, hVar, i2);
            }
        }

        @Override // g.a.m.i, android.view.Window.Callback
        public ActionMode onWindowStartingActionMode(ActionMode.Callback callback) {
            if (Build.VERSION.SDK_INT >= 23) {
                return null;
            }
            return f.this.X() ? a(callback) : super.onWindowStartingActionMode(callback);
        }

        @Override // g.a.m.i, android.view.Window.Callback
        public ActionMode onWindowStartingActionMode(ActionMode.Callback callback, int i2) {
            if (f.this.X() && i2 == 0) {
                return a(callback);
            }
            return super.onWindowStartingActionMode(callback, i2);
        }
    }
}
