package android.support.v7.app;

import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.app.AlertController;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ListAdapter;

/* JADX INFO: compiled from: AlertDialog.java */
/* JADX INFO: loaded from: classes.dex */
public class b extends g implements DialogInterface {

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

    /* JADX INFO: compiled from: AlertDialog.java */
    public static class a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        private final AlertController.f f764a;

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

        public a(Context context) {
            this(context, b.h(context, 0));
        }

        public b a() {
            b bVar = new b(this.f764a.f734a, this.f765b);
            this.f764a.a(bVar.f763d);
            bVar.setCancelable(this.f764a.r);
            if (this.f764a.r) {
                bVar.setCanceledOnTouchOutside(true);
            }
            bVar.setOnCancelListener(this.f764a.s);
            bVar.setOnDismissListener(this.f764a.t);
            DialogInterface.OnKeyListener onKeyListener = this.f764a.u;
            if (onKeyListener != null) {
                bVar.setOnKeyListener(onKeyListener);
            }
            return bVar;
        }

        public Context b() {
            return this.f764a.f734a;
        }

        public a c(ListAdapter listAdapter, DialogInterface.OnClickListener onClickListener) {
            AlertController.f fVar = this.f764a;
            fVar.w = listAdapter;
            fVar.x = onClickListener;
            return this;
        }

        public a d(View view) {
            this.f764a.g = view;
            return this;
        }

        public a e(Drawable drawable) {
            this.f764a.f737d = drawable;
            return this;
        }

        public a f(DialogInterface.OnKeyListener onKeyListener) {
            this.f764a.u = onKeyListener;
            return this;
        }

        public a g(CharSequence charSequence) {
            this.f764a.f739f = charSequence;
            return this;
        }

        public a(Context context, int i) {
            this.f764a = new AlertController.f(new ContextThemeWrapper(context, b.h(context, i)));
            this.f765b = i;
        }
    }

    protected b(Context context, int i) {
        super(context, h(context, i));
        this.f763d = new AlertController(getContext(), this, getWindow());
    }

    static int h(Context context, int i) {
        if (((i >>> 24) & 255) >= 1) {
            return i;
        }
        TypedValue typedValue = new TypedValue();
        context.getTheme().resolveAttribute(a.b.d.a.a.alertDialogTheme, typedValue, true);
        return typedValue.resourceId;
    }

    @Override // android.support.v7.app.g, android.app.Dialog
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.f763d.d();
    }

    @Override // android.app.Dialog, android.view.KeyEvent.Callback
    public boolean onKeyDown(int i, KeyEvent keyEvent) {
        if (this.f763d.f(i, keyEvent)) {
            return true;
        }
        return super.onKeyDown(i, keyEvent);
    }

    @Override // android.app.Dialog, android.view.KeyEvent.Callback
    public boolean onKeyUp(int i, KeyEvent keyEvent) {
        if (this.f763d.g(i, keyEvent)) {
            return true;
        }
        return super.onKeyUp(i, keyEvent);
    }

    @Override // android.support.v7.app.g, android.app.Dialog
    public void setTitle(CharSequence charSequence) {
        super.setTitle(charSequence);
        this.f763d.p(charSequence);
    }
}
