package android.support.v7.app;

import a.b.c.g.e;
import a.b.c.g.p;
import a.b.c.g.t;
import a.b.c.g.v;
import a.b.c.g.x;
import a.b.d.d.b;
import a.b.d.d.f;
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.support.v7.view.menu.h;
import android.support.v7.view.menu.o;
import android.support.v7.widget.ActionBarContextView;
import android.support.v7.widget.ContentFrameLayout;
import android.support.v7.widget.ViewStubCompat;
import android.support.v7.widget.a0;
import android.support.v7.widget.e0;
import android.support.v7.widget.t0;
import android.support.v7.widget.y0;
import android.support.v7.widget.z0;
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 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 android.support.v7.app.e implements h.a, LayoutInflater.Factory2 {
    private static final boolean T;
    private static final int[] U;
    private static boolean V;
    boolean A;
    boolean B;
    boolean C;
    boolean D;
    private boolean E;
    private m[] F;
    private m G;
    private boolean H;
    boolean I;
    private boolean K;
    private k L;
    boolean M;
    int N;
    private boolean P;
    private Rect Q;
    private Rect R;
    private AppCompatViewInflater S;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    final Context f767c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    final Window f768d;

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    final Window.Callback f770f;
    final android.support.v7.app.d g;
    android.support.v7.app.a h;
    MenuInflater i;
    private CharSequence j;
    private a0 k;
    private h l;
    private n m;
    a.b.d.d.b n;
    ActionBarContextView o;
    PopupWindow p;
    Runnable q;
    private boolean t;
    private ViewGroup u;
    private TextView v;
    private View w;
    private boolean x;
    private boolean y;
    boolean z;
    t r = null;
    private boolean s = true;
    private int J = -100;
    private final Runnable O = new b();

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

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        final /* synthetic */ Thread.UncaughtExceptionHandler f771a;

        a(Thread.UncaughtExceptionHandler uncaughtExceptionHandler) {
            this.f771a = 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.f771a.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.f771a.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.N & 1) != 0) {
                fVar.I(0);
            }
            f fVar2 = f.this;
            if ((fVar2.N & 4096) != 0) {
                fVar2.I(a.b.d.a.j.AppCompatTheme_tooltipForegroundColor);
            }
            f fVar3 = f.this;
            fVar3.M = false;
            fVar3.N = 0;
        }
    }

    /* JADX INFO: compiled from: AppCompatDelegateImpl.java */
    class c implements a.b.c.g.n {
        c() {
        }

        @Override // a.b.c.g.n
        public x a(View view, x xVar) {
            int iD = xVar.d();
            int iV0 = f.this.v0(iD);
            if (iD != iV0) {
                xVar = xVar.e(xVar.b(), iV0, xVar.c(), xVar.a());
            }
            return p.n(view, xVar);
        }
    }

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

        @Override // android.support.v7.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 // android.support.v7.widget.ContentFrameLayout.a
        public void a() {
        }

        @Override // android.support.v7.widget.ContentFrameLayout.a
        public void onDetachedFromWindow() {
            f.this.G();
        }
    }

    /* JADX INFO: renamed from: android.support.v7.app.f$f, reason: collision with other inner class name */
    /* JADX INFO: compiled from: AppCompatDelegateImpl.java */
    class RunnableC0023f implements Runnable {

        /* JADX INFO: renamed from: android.support.v7.app.f$f$a */
        /* JADX INFO: compiled from: AppCompatDelegateImpl.java */
        class a extends v {
            a() {
            }

            @Override // a.b.c.g.u
            public void a(View view) {
                f.this.o.setAlpha(1.0f);
                f.this.r.f(null);
                f.this.r = null;
            }

            @Override // a.b.c.g.v, a.b.c.g.u
            public void b(View view) {
                f.this.o.setVisibility(0);
            }
        }

        RunnableC0023f() {
        }

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

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

        @Override // a.b.c.g.u
        public void a(View view) {
            f.this.o.setAlpha(1.0f);
            f.this.r.f(null);
            f.this.r = null;
        }

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

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

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

        @Override // android.support.v7.view.menu.o.a
        public boolean b(android.support.v7.view.menu.h hVar) {
            Window.Callback callbackR = f.this.R();
            if (callbackR == null) {
                return true;
            }
            callbackR.onMenuOpened(a.b.d.a.j.AppCompatTheme_tooltipForegroundColor, hVar);
            return true;
        }
    }

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

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

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

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

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

        @Override // a.b.d.d.b.a
        public void a(a.b.d.d.b bVar) {
            this.f780a.a(bVar);
            f fVar = f.this;
            if (fVar.p != null) {
                fVar.f768d.getDecorView().removeCallbacks(f.this.q);
            }
            f fVar2 = f.this;
            if (fVar2.o != null) {
                fVar2.J();
                f fVar3 = f.this;
                t tVarA = p.a(fVar3.o);
                tVarA.a(0.0f);
                fVar3.r = tVarA;
                f.this.r.f(new a());
            }
            f fVar4 = f.this;
            android.support.v7.app.d dVar = fVar4.g;
            if (dVar != null) {
                dVar.d(fVar4.n);
            }
            f.this.n = null;
        }

        @Override // a.b.d.d.b.a
        public boolean b(a.b.d.d.b bVar, MenuItem menuItem) {
            return this.f780a.b(bVar, menuItem);
        }

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

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

    /* JADX INFO: compiled from: AppCompatDelegateImpl.java */
    final class k {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private android.support.v7.app.j f784a;

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

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        private BroadcastReceiver f786c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        private IntentFilter f787d;

        /* 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(android.support.v7.app.j jVar) {
            this.f784a = jVar;
            this.f785b = jVar.d();
        }

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

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

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

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

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

        private boolean c(int i, int i2) {
            return i < -5 || i2 < -5 || i > getWidth() + 5 || i2 > 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 i) {
            setBackgroundDrawable(a.b.d.b.a.a.d(getContext(), i));
        }
    }

    /* JADX INFO: compiled from: AppCompatDelegateImpl.java */
    protected static final class m {

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

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        int f791b;

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

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

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

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        int f795f;
        ViewGroup g;
        View h;
        View i;
        android.support.v7.view.menu.h j;
        android.support.v7.view.menu.f k;
        Context l;
        boolean m;
        boolean n;
        boolean o;
        public boolean p;
        boolean q = false;
        boolean r;
        Bundle s;

        m(int i) {
            this.f790a = i;
        }

        android.support.v7.view.menu.p a(o.a aVar) {
            if (this.j == null) {
                return null;
            }
            if (this.k == null) {
                android.support.v7.view.menu.f fVar = new android.support.v7.view.menu.f(this.l, a.b.d.a.g.abc_list_menu_item_layout);
                this.k = fVar;
                fVar.f(aVar);
                this.j.b(this.k);
            }
            return this.k.h(this.g);
        }

        public boolean b() {
            if (this.h == null) {
                return false;
            }
            return this.i != null || this.k.c().getCount() > 0;
        }

        void c(android.support.v7.view.menu.h hVar) {
            android.support.v7.view.menu.f fVar;
            android.support.v7.view.menu.h hVar2 = this.j;
            if (hVar == hVar2) {
                return;
            }
            if (hVar2 != null) {
                hVar2.O(this.k);
            }
            this.j = hVar;
            if (hVar == null || (fVar = this.k) == 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(a.b.d.a.a.actionBarPopupTheme, typedValue, true);
            int i = typedValue.resourceId;
            if (i != 0) {
                themeNewTheme.applyStyle(i, true);
            }
            themeNewTheme.resolveAttribute(a.b.d.a.a.panelMenuListTheme, typedValue, true);
            int i2 = typedValue.resourceId;
            if (i2 != 0) {
                themeNewTheme.applyStyle(i2, true);
            } else {
                themeNewTheme.applyStyle(a.b.d.a.i.Theme_AppCompat_CompactMenu, true);
            }
            a.b.d.d.d dVar = new a.b.d.d.d(context, 0);
            dVar.getTheme().setTo(themeNewTheme);
            this.l = dVar;
            TypedArray typedArrayObtainStyledAttributes = dVar.obtainStyledAttributes(a.b.d.a.j.AppCompatTheme);
            this.f791b = typedArrayObtainStyledAttributes.getResourceId(a.b.d.a.j.AppCompatTheme_panelBackground, 0);
            this.f795f = typedArrayObtainStyledAttributes.getResourceId(a.b.d.a.j.AppCompatTheme_android_windowAnimationStyle, 0);
            typedArrayObtainStyledAttributes.recycle();
        }
    }

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

        @Override // android.support.v7.view.menu.o.a
        public void a(android.support.v7.view.menu.h hVar, boolean z) {
            android.support.v7.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.f790a, mVarM, hVarD);
                    f.this.D(mVarM, true);
                }
            }
        }

        @Override // android.support.v7.view.menu.o.a
        public boolean b(android.support.v7.view.menu.h hVar) {
            Window.Callback callbackR;
            if (hVar != null) {
                return true;
            }
            f fVar = f.this;
            if (!fVar.z || (callbackR = fVar.R()) == null || f.this.I) {
                return true;
            }
            callbackR.onMenuOpened(a.b.d.a.j.AppCompatTheme_tooltipForegroundColor, hVar);
            return true;
        }
    }

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

    f(Context context, Window window, android.support.v7.app.d dVar) {
        this.f767c = context;
        this.f768d = window;
        this.g = dVar;
        Window.Callback callback = window.getCallback();
        this.f769e = callback;
        if (callback instanceof j) {
            throw new IllegalStateException("AppCompat has already installed itself into the Window");
        }
        j jVar = new j(callback);
        this.f770f = jVar;
        this.f768d.setCallback(jVar);
        t0 t0VarS = t0.s(context, null, U);
        Drawable drawableG = t0VarS.g(0);
        if (drawableG != null) {
            this.f768d.setBackgroundDrawable(drawableG);
        }
        t0VarS.u();
    }

    private ViewGroup E() {
        ViewGroup viewGroup;
        TypedArray typedArrayObtainStyledAttributes = this.f767c.obtainStyledAttributes(a.b.d.a.j.AppCompatTheme);
        if (!typedArrayObtainStyledAttributes.hasValue(a.b.d.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(a.b.d.a.j.AppCompatTheme_windowNoTitle, false)) {
            u(1);
        } else if (typedArrayObtainStyledAttributes.getBoolean(a.b.d.a.j.AppCompatTheme_windowActionBar, false)) {
            u(a.b.d.a.j.AppCompatTheme_tooltipForegroundColor);
        }
        if (typedArrayObtainStyledAttributes.getBoolean(a.b.d.a.j.AppCompatTheme_windowActionBarOverlay, false)) {
            u(a.b.d.a.j.AppCompatTheme_tooltipFrameBackground);
        }
        if (typedArrayObtainStyledAttributes.getBoolean(a.b.d.a.j.AppCompatTheme_windowActionModeOverlay, false)) {
            u(10);
        }
        this.C = typedArrayObtainStyledAttributes.getBoolean(a.b.d.a.j.AppCompatTheme_android_windowIsFloating, false);
        typedArrayObtainStyledAttributes.recycle();
        this.f768d.getDecorView();
        LayoutInflater layoutInflaterFrom = LayoutInflater.from(this.f767c);
        if (this.D) {
            viewGroup = this.B ? (ViewGroup) layoutInflaterFrom.inflate(a.b.d.a.g.abc_screen_simple_overlay_action_mode, (ViewGroup) null) : (ViewGroup) layoutInflaterFrom.inflate(a.b.d.a.g.abc_screen_simple, (ViewGroup) null);
            if (Build.VERSION.SDK_INT >= 21) {
                p.x(viewGroup, new c());
            } else {
                ((e0) viewGroup).setOnFitSystemWindowsListener(new d());
            }
        } else if (this.C) {
            viewGroup = (ViewGroup) layoutInflaterFrom.inflate(a.b.d.a.g.abc_dialog_title_material, (ViewGroup) null);
            this.A = false;
            this.z = false;
        } else if (this.z) {
            TypedValue typedValue = new TypedValue();
            this.f767c.getTheme().resolveAttribute(a.b.d.a.a.actionBarTheme, typedValue, true);
            viewGroup = (ViewGroup) LayoutInflater.from(typedValue.resourceId != 0 ? new a.b.d.d.d(this.f767c, typedValue.resourceId) : this.f767c).inflate(a.b.d.a.g.abc_screen_toolbar, (ViewGroup) null);
            a0 a0Var = (a0) viewGroup.findViewById(a.b.d.a.f.decor_content_parent);
            this.k = a0Var;
            a0Var.setWindowCallback(R());
            if (this.A) {
                this.k.k(a.b.d.a.j.AppCompatTheme_tooltipFrameBackground);
            }
            if (this.x) {
                this.k.k(2);
            }
            if (this.y) {
                this.k.k(5);
            }
        } else {
            viewGroup = null;
        }
        if (viewGroup == null) {
            throw new IllegalArgumentException("AppCompat does not support the current theme features: { windowActionBar: " + this.z + ", windowActionBarOverlay: " + this.A + ", android:windowIsFloating: " + this.C + ", windowActionModeOverlay: " + this.B + ", windowNoTitle: " + this.D + " }");
        }
        if (this.k == null) {
            this.v = (TextView) viewGroup.findViewById(a.b.d.a.f.title);
        }
        z0.c(viewGroup);
        ContentFrameLayout contentFrameLayout = (ContentFrameLayout) viewGroup.findViewById(a.b.d.a.f.action_bar_activity_content);
        ViewGroup viewGroup2 = (ViewGroup) this.f768d.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.f768d.setContentView(viewGroup);
        contentFrameLayout.setAttachListener(new e());
        return viewGroup;
    }

    private void K() {
        if (this.L == null) {
            this.L = new k(android.support.v7.app.j.a(this.f767c));
        }
    }

    private void L() {
        if (this.t) {
            return;
        }
        this.u = E();
        CharSequence charSequenceQ = Q();
        if (!TextUtils.isEmpty(charSequenceQ)) {
            a0 a0Var = this.k;
            if (a0Var != null) {
                a0Var.setWindowTitle(charSequenceQ);
            } else if (j0() != null) {
                j0().t(charSequenceQ);
            } else {
                TextView textView = this.v;
                if (textView != null) {
                    textView.setText(charSequenceQ);
                }
            }
        }
        z();
        h0(this.u);
        this.t = true;
        m mVarP = P(0, false);
        if (this.I) {
            return;
        }
        if (mVarP == null || mVarP.j == null) {
            W(a.b.d.a.j.AppCompatTheme_tooltipForegroundColor);
        }
    }

    private int O() {
        int i2 = this.J;
        return i2 != -100 ? i2 : android.support.v7.app.e.h();
    }

    private void S() {
        L();
        if (this.z && this.h == null) {
            Window.Callback callback = this.f769e;
            if (callback instanceof Activity) {
                this.h = new android.support.v7.app.k((Activity) this.f769e, this.A);
            } else if (callback instanceof Dialog) {
                this.h = new android.support.v7.app.k((Dialog) this.f769e);
            }
            android.support.v7.app.a aVar = this.h;
            if (aVar != null) {
                aVar.r(this.P);
            }
        }
    }

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

    private boolean U(m mVar) {
        mVar.d(N());
        mVar.g = new l(mVar.l);
        mVar.f792c = 81;
        return true;
    }

    private boolean V(m mVar) {
        Context context = this.f767c;
        int i2 = mVar.f790a;
        if ((i2 == 0 || i2 == 108) && this.k != null) {
            TypedValue typedValue = new TypedValue();
            Resources.Theme theme = context.getTheme();
            theme.resolveAttribute(a.b.d.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(a.b.d.a.a.actionBarWidgetTheme, typedValue, true);
            } else {
                theme.resolveAttribute(a.b.d.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) {
                a.b.d.d.d dVar = new a.b.d.d.d(context, 0);
                dVar.getTheme().setTo(themeNewTheme);
                context = dVar;
            }
        }
        android.support.v7.view.menu.h hVar = new android.support.v7.view.menu.h(context);
        hVar.R(this);
        mVar.c(hVar);
        return true;
    }

    private void W(int i2) {
        this.N = (1 << i2) | this.N;
        if (this.M) {
            return;
        }
        p.p(this.f768d.getDecorView(), this.O);
        this.M = 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;
            a.b.d.d.b r0 = r3.n
            r1 = 0
            if (r0 == 0) goto L6
            return r1
        L6:
            r0 = 1
            android.support.v7.app.f$m r2 = r3.P(r4, r0)
            if (r4 != 0) goto L43
            android.support.v7.widget.a0 r4 = r3.k
            if (r4 == 0) goto L43
            boolean r4 = r4.h()
            if (r4 == 0) goto L43
            android.content.Context r4 = r3.f767c
            android.view.ViewConfiguration r4 = android.view.ViewConfiguration.get(r4)
            boolean r4 = r4.hasPermanentMenuKey()
            if (r4 != 0) goto L43
            android.support.v7.widget.a0 r4 = r3.k
            boolean r4 = r4.b()
            if (r4 != 0) goto L3c
            boolean r4 = r3.I
            if (r4 != 0) goto L62
            boolean r4 = r3.l0(r2, r5)
            if (r4 == 0) goto L62
            android.support.v7.widget.a0 r4 = r3.k
            boolean r0 = r4.f()
            goto L6a
        L3c:
            android.support.v7.widget.a0 r4 = r3.k
            boolean r0 = r4.e()
            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.m
            if (r4 == 0) goto L62
            boolean r4 = r2.r
            if (r4 == 0) goto L5b
            r2.m = 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.f767c
            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: android.support.v7.app.f.e0(int, android.view.KeyEvent):boolean");
    }

    private void i0(m mVar, KeyEvent keyEvent) {
        int i2;
        ViewGroup.LayoutParams layoutParams;
        if (mVar.o || this.I) {
            return;
        }
        if (mVar.f790a == 0) {
            if ((this.f767c.getResources().getConfiguration().screenLayout & 15) == 4) {
                return;
            }
        }
        Window.Callback callbackR = R();
        if (callbackR != null && !callbackR.onMenuOpened(mVar.f790a, mVar.j)) {
            D(mVar, true);
            return;
        }
        WindowManager windowManager = (WindowManager) this.f767c.getSystemService("window");
        if (windowManager != null && l0(mVar, keyEvent)) {
            if (mVar.g != null && !mVar.q) {
                View view = mVar.i;
                if (view != null && (layoutParams = view.getLayoutParams()) != null && layoutParams.width == -1) {
                    i2 = -1;
                }
                mVar.n = false;
                WindowManager.LayoutParams layoutParams2 = new WindowManager.LayoutParams(i2, -2, mVar.f793d, mVar.f794e, 1002, 8519680, -3);
                layoutParams2.gravity = mVar.f792c;
                layoutParams2.windowAnimations = mVar.f795f;
                windowManager.addView(mVar.g, layoutParams2);
                mVar.o = true;
            }
            ViewGroup viewGroup = mVar.g;
            if (viewGroup == null) {
                if (!U(mVar) || mVar.g == null) {
                    return;
                }
            } else if (mVar.q && viewGroup.getChildCount() > 0) {
                mVar.g.removeAllViews();
            }
            if (!T(mVar) || !mVar.b()) {
                return;
            }
            ViewGroup.LayoutParams layoutParams3 = mVar.h.getLayoutParams();
            if (layoutParams3 == null) {
                layoutParams3 = new ViewGroup.LayoutParams(-2, -2);
            }
            mVar.g.setBackgroundResource(mVar.f791b);
            ViewParent parent = mVar.h.getParent();
            if (parent != null && (parent instanceof ViewGroup)) {
                ((ViewGroup) parent).removeView(mVar.h);
            }
            mVar.g.addView(mVar.h, layoutParams3);
            if (!mVar.h.hasFocus()) {
                mVar.h.requestFocus();
            }
            i2 = -2;
            mVar.n = false;
            WindowManager.LayoutParams layoutParams22 = new WindowManager.LayoutParams(i2, -2, mVar.f793d, mVar.f794e, 1002, 8519680, -3);
            layoutParams22.gravity = mVar.f792c;
            layoutParams22.windowAnimations = mVar.f795f;
            windowManager.addView(mVar.g, layoutParams22);
            mVar.o = true;
        }
    }

    private boolean k0(m mVar, int i2, KeyEvent keyEvent, int i3) {
        android.support.v7.view.menu.h hVar;
        boolean zPerformShortcut = false;
        if (keyEvent.isSystem()) {
            return false;
        }
        if ((mVar.m || l0(mVar, keyEvent)) && (hVar = mVar.j) != null) {
            zPerformShortcut = hVar.performShortcut(i2, keyEvent, i3);
        }
        if (zPerformShortcut && (i3 & 1) == 0 && this.k == null) {
            D(mVar, true);
        }
        return zPerformShortcut;
    }

    private boolean l0(m mVar, KeyEvent keyEvent) {
        a0 a0Var;
        a0 a0Var2;
        a0 a0Var3;
        if (this.I) {
            return false;
        }
        if (mVar.m) {
            return true;
        }
        m mVar2 = this.G;
        if (mVar2 != null && mVar2 != mVar) {
            D(mVar2, false);
        }
        Window.Callback callbackR = R();
        if (callbackR != null) {
            mVar.i = callbackR.onCreatePanelView(mVar.f790a);
        }
        int i2 = mVar.f790a;
        boolean z = i2 == 0 || i2 == 108;
        if (z && (a0Var3 = this.k) != null) {
            a0Var3.g();
        }
        if (mVar.i == null) {
            if (z) {
                j0();
            }
            if (mVar.j == null || mVar.r) {
                if (mVar.j == null && (!V(mVar) || mVar.j == null)) {
                    return false;
                }
                if (z && this.k != null) {
                    if (this.l == null) {
                        this.l = new h();
                    }
                    this.k.c(mVar.j, this.l);
                }
                mVar.j.d0();
                if (!callbackR.onCreatePanelMenu(mVar.f790a, mVar.j)) {
                    mVar.c(null);
                    if (z && (a0Var = this.k) != null) {
                        a0Var.c(null, this.l);
                    }
                    return false;
                }
                mVar.r = false;
            }
            mVar.j.d0();
            Bundle bundle = mVar.s;
            if (bundle != null) {
                mVar.j.P(bundle);
                mVar.s = null;
            }
            if (!callbackR.onPreparePanel(0, mVar.i, mVar.j)) {
                if (z && (a0Var2 = this.k) != null) {
                    a0Var2.c(null, this.l);
                }
                mVar.j.c0();
                return false;
            }
            boolean z2 = KeyCharacterMap.load(keyEvent != null ? keyEvent.getDeviceId() : -1).getKeyboardType() != 1;
            mVar.p = z2;
            mVar.j.setQwertyMode(z2);
            mVar.j.c0();
        }
        mVar.m = true;
        mVar.n = false;
        this.G = mVar;
        return true;
    }

    private void m0(android.support.v7.view.menu.h hVar, boolean z) {
        a0 a0Var = this.k;
        if (a0Var == null || !a0Var.h() || (ViewConfiguration.get(this.f767c).hasPermanentMenuKey() && !this.k.a())) {
            m mVarP = P(0, true);
            mVarP.q = true;
            D(mVarP, false);
            i0(mVarP, null);
            return;
        }
        Window.Callback callbackR = R();
        if (this.k.b() && z) {
            this.k.e();
            if (this.I) {
                return;
            }
            callbackR.onPanelClosed(a.b.d.a.j.AppCompatTheme_tooltipForegroundColor, P(0, true).j);
            return;
        }
        if (callbackR == null || this.I) {
            return;
        }
        if (this.M && (this.N & 1) != 0) {
            this.f768d.getDecorView().removeCallbacks(this.O);
            this.O.run();
        }
        m mVarP2 = P(0, true);
        android.support.v7.view.menu.h hVar2 = mVarP2.j;
        if (hVar2 == null || mVarP2.r || !callbackR.onPreparePanel(0, mVarP2.i, hVar2)) {
            return;
        }
        callbackR.onMenuOpened(a.b.d.a.j.AppCompatTheme_tooltipForegroundColor, mVarP2.j);
        this.k.f();
    }

    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 a.b.d.a.j.AppCompatTheme_tooltipForegroundColor;
        }
        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 a.b.d.a.j.AppCompatTheme_tooltipFrameBackground;
    }

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

    private boolean q0() {
        if (this.K) {
            Context context = this.f767c;
            if (context instanceof Activity) {
                try {
                    return (context.getPackageManager().getActivityInfo(new ComponentName(this.f767c, this.f767c.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.t) {
            throw new AndroidRuntimeException("Window feature must be requested before adding content");
        }
    }

    private boolean u0(int i2) {
        Resources resources = this.f767c.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.f767c).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;
        }
        android.support.v7.app.h.a(resources);
        return true;
    }

    private void z() {
        ContentFrameLayout contentFrameLayout = (ContentFrameLayout) this.u.findViewById(R.id.content);
        View decorView = this.f768d.getDecorView();
        contentFrameLayout.b(decorView.getPaddingLeft(), decorView.getPaddingTop(), decorView.getPaddingRight(), decorView.getPaddingBottom());
        TypedArray typedArrayObtainStyledAttributes = this.f767c.obtainStyledAttributes(a.b.d.a.j.AppCompatTheme);
        typedArrayObtainStyledAttributes.getValue(a.b.d.a.j.AppCompatTheme_windowMinWidthMajor, contentFrameLayout.getMinWidthMajor());
        typedArrayObtainStyledAttributes.getValue(a.b.d.a.j.AppCompatTheme_windowMinWidthMinor, contentFrameLayout.getMinWidthMinor());
        if (typedArrayObtainStyledAttributes.hasValue(a.b.d.a.j.AppCompatTheme_windowFixedWidthMajor)) {
            typedArrayObtainStyledAttributes.getValue(a.b.d.a.j.AppCompatTheme_windowFixedWidthMajor, contentFrameLayout.getFixedWidthMajor());
        }
        if (typedArrayObtainStyledAttributes.hasValue(a.b.d.a.j.AppCompatTheme_windowFixedWidthMinor)) {
            typedArrayObtainStyledAttributes.getValue(a.b.d.a.j.AppCompatTheme_windowFixedWidthMinor, contentFrameLayout.getFixedWidthMinor());
        }
        if (typedArrayObtainStyledAttributes.hasValue(a.b.d.a.j.AppCompatTheme_windowFixedHeightMajor)) {
            typedArrayObtainStyledAttributes.getValue(a.b.d.a.j.AppCompatTheme_windowFixedHeightMajor, contentFrameLayout.getFixedHeightMajor());
        }
        if (typedArrayObtainStyledAttributes.hasValue(a.b.d.a.j.AppCompatTheme_windowFixedHeightMinor)) {
            typedArrayObtainStyledAttributes.getValue(a.b.d.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.F;
                if (i2 < mVarArr.length) {
                    mVar = mVarArr[i2];
                }
            }
            if (mVar != null) {
                menu = mVar.j;
            }
        }
        if ((mVar == null || mVar.o) && !this.I) {
            this.f769e.onPanelClosed(i2, menu);
        }
    }

    void B(android.support.v7.view.menu.h hVar) {
        if (this.E) {
            return;
        }
        this.E = true;
        this.k.l();
        Window.Callback callbackR = R();
        if (callbackR != null && !this.I) {
            callbackR.onPanelClosed(a.b.d.a.j.AppCompatTheme_tooltipForegroundColor, hVar);
        }
        this.E = false;
    }

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

    void D(m mVar, boolean z) {
        ViewGroup viewGroup;
        a0 a0Var;
        if (z && mVar.f790a == 0 && (a0Var = this.k) != null && a0Var.b()) {
            B(mVar.j);
            return;
        }
        WindowManager windowManager = (WindowManager) this.f767c.getSystemService("window");
        if (windowManager != null && mVar.o && (viewGroup = mVar.g) != null) {
            windowManager.removeView(viewGroup);
            if (z) {
                A(mVar.f790a, mVar, null);
            }
        }
        mVar.m = false;
        mVar.n = false;
        mVar.o = false;
        mVar.h = null;
        mVar.q = true;
        if (this.G == mVar) {
            this.G = null;
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    public View F(View view, String str, Context context, AttributeSet attributeSet) {
        boolean zP0 = false;
        if (this.S == null) {
            String string = this.f767c.obtainStyledAttributes(a.b.d.a.j.AppCompatTheme).getString(a.b.d.a.j.AppCompatTheme_viewInflaterClass);
            if (string == null || AppCompatViewInflater.class.getName().equals(string)) {
                this.S = new AppCompatViewInflater();
            } else {
                try {
                    this.S = (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.S = new AppCompatViewInflater();
                }
            }
        }
        if (T) {
            if (!(attributeSet instanceof XmlPullParser)) {
                zP0 = p0((ViewParent) view);
            } else if (((XmlPullParser) attributeSet).getDepth() > 1) {
                zP0 = true;
            }
        }
        return this.S.p(view, str, context, attributeSet, zP0, T, true, y0.b());
    }

    void G() {
        android.support.v7.view.menu.h hVar;
        a0 a0Var = this.k;
        if (a0Var != null) {
            a0Var.l();
        }
        if (this.p != null) {
            this.f768d.getDecorView().removeCallbacks(this.q);
            if (this.p.isShowing()) {
                try {
                    this.p.dismiss();
                } catch (IllegalArgumentException unused) {
                }
            }
            this.p = null;
        }
        J();
        m mVarP = P(0, false);
        if (mVarP == null || (hVar = mVarP.j) == null) {
            return;
        }
        hVar.close();
    }

    boolean H(KeyEvent keyEvent) {
        View decorView;
        Window.Callback callback = this.f769e;
        if (((callback instanceof e.a) || (callback instanceof android.support.v7.app.g)) && (decorView = this.f768d.getDecorView()) != null && a.b.c.g.e.d(decorView, keyEvent)) {
            return true;
        }
        if (keyEvent.getKeyCode() == 82 && this.f769e.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.j != null) {
            Bundle bundle = new Bundle();
            mVarP2.j.Q(bundle);
            if (bundle.size() > 0) {
                mVarP2.s = bundle;
            }
            mVarP2.j.d0();
            mVarP2.j.clear();
        }
        mVarP2.r = true;
        mVarP2.q = true;
        if ((i2 != 108 && i2 != 0) || this.k == null || (mVarP = P(0, false)) == null) {
            return;
        }
        mVarP.m = false;
        l0(mVarP, null);
    }

    void J() {
        t tVar = this.r;
        if (tVar != null) {
            tVar.b();
        }
    }

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

    final Context N() {
        android.support.v7.app.a aVarJ = j();
        Context contextK = aVarJ != null ? aVarJ.k() : null;
        return contextK == null ? this.f767c : contextK;
    }

    protected m P(int i2, boolean z) {
        m[] mVarArr = this.F;
        if (mVarArr == null || mVarArr.length <= i2) {
            m[] mVarArr2 = new m[i2 + 1];
            if (mVarArr != null) {
                System.arraycopy(mVarArr, 0, mVarArr2, 0, mVarArr.length);
            }
            this.F = 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.f769e;
        return callback instanceof Activity ? ((Activity) callback).getTitle() : this.j;
    }

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

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

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

    boolean Z() {
        a.b.d.d.b bVar = this.n;
        if (bVar != null) {
            bVar.c();
            return true;
        }
        android.support.v7.app.a aVarJ = j();
        return aVarJ != null && aVarJ.h();
    }

    @Override // android.support.v7.view.menu.h.a
    public void a(android.support.v7.view.menu.h hVar) {
        m0(hVar, true);
    }

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

    @Override // android.support.v7.view.menu.h.a
    public boolean b(android.support.v7.view.menu.h hVar, MenuItem menuItem) {
        m mVarM;
        Window.Callback callbackR = R();
        if (callbackR == null || this.I || (mVarM = M(hVar.D())) == null) {
            return false;
        }
        return callbackR.onMenuItemSelected(mVarM.f790a, menuItem);
    }

    @Override // android.support.v7.app.e
    public void c(View view, ViewGroup.LayoutParams layoutParams) {
        L();
        ((ViewGroup) this.u.findViewById(R.id.content)).addView(view, layoutParams);
        this.f769e.onContentChanged();
    }

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

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

    boolean d0(int i2, KeyEvent keyEvent) {
        if (i2 == 4) {
            boolean z = this.H;
            this.H = 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) {
        android.support.v7.app.a aVarJ;
        if (i2 != 108 || (aVarJ = j()) == null) {
            return;
        }
        aVarJ.i(true);
    }

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

    void g0(int i2) {
        if (i2 == 108) {
            android.support.v7.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 // android.support.v7.app.e
    public MenuInflater i() {
        if (this.i == null) {
            S();
            android.support.v7.app.a aVar = this.h;
            this.i = new a.b.d.d.g(aVar != null ? aVar.k() : this.f767c);
        }
        return this.i;
    }

    @Override // android.support.v7.app.e
    public android.support.v7.app.a j() {
        S();
        return this.h;
    }

    final android.support.v7.app.a j0() {
        return this.h;
    }

    @Override // android.support.v7.app.e
    public void k() {
        LayoutInflater layoutInflaterFrom = LayoutInflater.from(this.f767c);
        if (layoutInflaterFrom.getFactory() == null) {
            a.b.c.g.f.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 // android.support.v7.app.e
    public void l() {
        android.support.v7.app.a aVarJ = j();
        if (aVarJ == null || !aVarJ.l()) {
            W(0);
        }
    }

    @Override // android.support.v7.app.e
    public void m(Configuration configuration) {
        android.support.v7.app.a aVarJ;
        if (this.z && this.t && (aVarJ = j()) != null) {
            aVarJ.m(configuration);
        }
        android.support.v7.widget.j.n().y(this.f767c);
        d();
    }

    @Override // android.support.v7.app.e
    public void n(Bundle bundle) {
        Window.Callback callback = this.f769e;
        if (callback instanceof Activity) {
            String strC = null;
            try {
                strC = android.support.v4.app.t.c((Activity) callback);
            } catch (IllegalArgumentException unused) {
            }
            if (strC != null) {
                android.support.v7.app.a aVarJ0 = j0();
                if (aVarJ0 == null) {
                    this.P = true;
                } else {
                    aVarJ0.r(true);
                }
            }
        }
        if (bundle == null || this.J != -100) {
            return;
        }
        this.J = bundle.getInt("appcompat:local_night_mode", -100);
    }

    @Override // android.support.v7.app.e
    public void o() {
        if (this.M) {
            this.f768d.getDecorView().removeCallbacks(this.O);
        }
        this.I = true;
        android.support.v7.app.a aVar = this.h;
        if (aVar != null) {
            aVar.n();
        }
        k kVar = this.L;
        if (kVar != null) {
            kVar.a();
        }
    }

    final boolean o0() {
        ViewGroup viewGroup;
        return this.t && (viewGroup = this.u) != null && p.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 // android.support.v7.app.e
    public void p(Bundle bundle) {
        L();
    }

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

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

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

    @Override // android.support.v7.app.e
    public void s() {
        d();
    }

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

    @Override // android.support.v7.app.e
    public void t() {
        android.support.v7.app.a aVarJ = j();
        if (aVarJ != null) {
            aVarJ.s(false);
        }
        k kVar = this.L;
        if (kVar != null) {
            kVar.a();
        }
    }

    @Override // android.support.v7.app.e
    public boolean u(int i2) {
        int iN0 = n0(i2);
        if (this.D && iN0 == 108) {
            return false;
        }
        if (this.z && iN0 == 1) {
            this.z = false;
        }
        if (iN0 == 1) {
            t0();
            this.D = true;
            return true;
        }
        if (iN0 == 2) {
            t0();
            this.x = true;
            return true;
        }
        if (iN0 == 5) {
            t0();
            this.y = true;
            return true;
        }
        if (iN0 == 10) {
            t0();
            this.B = true;
            return true;
        }
        if (iN0 == 108) {
            t0();
            this.z = true;
            return true;
        }
        if (iN0 != 109) {
            return this.f768d.requestFeature(iN0);
        }
        t0();
        this.A = true;
        return true;
    }

    @Override // android.support.v7.app.e
    public void v(int i2) {
        L();
        ViewGroup viewGroup = (ViewGroup) this.u.findViewById(R.id.content);
        viewGroup.removeAllViews();
        LayoutInflater.from(this.f767c).inflate(i2, viewGroup);
        this.f769e.onContentChanged();
    }

    int v0(int i2) {
        boolean z;
        boolean z2;
        ActionBarContextView actionBarContextView = this.o;
        if (actionBarContextView == null || !(actionBarContextView.getLayoutParams() instanceof ViewGroup.MarginLayoutParams)) {
            z = false;
        } else {
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) this.o.getLayoutParams();
            if (this.o.isShown()) {
                if (this.Q == null) {
                    this.Q = new Rect();
                    this.R = new Rect();
                }
                Rect rect = this.Q;
                Rect rect2 = this.R;
                rect.set(0, i2, 0, 0);
                z0.a(this.u, rect, rect2);
                if (marginLayoutParams.topMargin != (rect2.top == 0 ? i2 : 0)) {
                    marginLayoutParams.topMargin = i2;
                    View view = this.w;
                    if (view == null) {
                        View view2 = new View(this.f767c);
                        this.w = view2;
                        view2.setBackgroundColor(this.f767c.getResources().getColor(a.b.d.a.c.abc_input_method_navigation_guard));
                        this.u.addView(this.w, -1, new ViewGroup.LayoutParams(-1, i2));
                    } else {
                        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
                        if (layoutParams.height != i2) {
                            layoutParams.height = i2;
                            this.w.setLayoutParams(layoutParams);
                        }
                    }
                    z2 = true;
                } else {
                    z2 = false;
                }
                z = this.w != null;
                if (!this.B && 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.o.setLayoutParams(marginLayoutParams);
            }
        }
        View view3 = this.w;
        if (view3 != null) {
            view3.setVisibility(z ? 0 : 8);
        }
        return i2;
    }

    @Override // android.support.v7.app.e
    public void w(View view) {
        L();
        ViewGroup viewGroup = (ViewGroup) this.u.findViewById(R.id.content);
        viewGroup.removeAllViews();
        viewGroup.addView(view);
        this.f769e.onContentChanged();
    }

    @Override // android.support.v7.app.e
    public void x(View view, ViewGroup.LayoutParams layoutParams) {
        L();
        ViewGroup viewGroup = (ViewGroup) this.u.findViewById(R.id.content);
        viewGroup.removeAllViews();
        viewGroup.addView(view, layoutParams);
        this.f769e.onContentChanged();
    }

    @Override // android.support.v7.app.e
    public final void y(CharSequence charSequence) {
        this.j = charSequence;
        a0 a0Var = this.k;
        if (a0Var != null) {
            a0Var.setWindowTitle(charSequence);
            return;
        }
        if (j0() != null) {
            j0().t(charSequence);
            return;
        }
        TextView textView = this.v;
        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 a.b.d.d.i {
        j(Window.Callback callback) {
            super(callback);
        }

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

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

        @Override // a.b.d.d.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 // a.b.d.d.i, android.view.Window.Callback
        public boolean onCreatePanelMenu(int i, Menu menu) {
            if (i != 0 || (menu instanceof android.support.v7.view.menu.h)) {
                return super.onCreatePanelMenu(i, menu);
            }
            return false;
        }

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

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

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

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

        @Override // a.b.d.d.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 // a.b.d.d.i, android.view.Window.Callback
        public ActionMode onWindowStartingActionMode(ActionMode.Callback callback, int i) {
            if (f.this.X() && i == 0) {
                return a(callback);
            }
            return super.onWindowStartingActionMode(callback, i);
        }
    }
}
