package androidx.appcompat.app; import android.content.Context; import android.content.DialogInterface; import android.database.Cursor; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Message; import android.util.TypedValue; import android.view.ContextThemeWrapper; import android.view.KeyEvent; import android.view.View; import android.widget.AdapterView; import android.widget.Button; import android.widget.ListAdapter; import android.widget.ListView; import androidx.annotation.ArrayRes; import androidx.annotation.AttrRes; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RestrictTo; import androidx.annotation.StringRes; import androidx.annotation.StyleRes; import androidx.appcompat.R; import androidx.appcompat.app.AlertController; public class AlertDialog extends AppCompatDialog implements DialogInterface { public static final int LAYOUT_HINT_NONE = 0; public static final int LAYOUT_HINT_SIDE = 1; public final AlertController mAlert; public static class Builder { private final AlertController.AlertParams P; private final int mTheme; public Builder(@NonNull Context context) { this(context, AlertDialog.resolveDialogTheme(context, 0)); } public Builder(@NonNull Context context, @StyleRes int i) { this.P = new AlertController.AlertParams(new ContextThemeWrapper(context, AlertDialog.resolveDialogTheme(context, i))); this.mTheme = i; } @NonNull public AlertDialog create() { AlertDialog alertDialog = new AlertDialog(this.P.mContext, this.mTheme); this.P.apply(alertDialog.mAlert); alertDialog.setCancelable(this.P.mCancelable); if (this.P.mCancelable) { alertDialog.setCanceledOnTouchOutside(true); } alertDialog.setOnCancelListener(this.P.mOnCancelListener); alertDialog.setOnDismissListener(this.P.mOnDismissListener); DialogInterface.OnKeyListener onKeyListener = this.P.mOnKeyListener; if (onKeyListener != null) { alertDialog.setOnKeyListener(onKeyListener); } return alertDialog; } @NonNull public Context getContext() { return this.P.mContext; } public Builder setAdapter(ListAdapter listAdapter, DialogInterface.OnClickListener onClickListener) { AlertController.AlertParams alertParams = this.P; alertParams.mAdapter = listAdapter; alertParams.mOnClickListener = onClickListener; return this; } public Builder setCancelable(boolean z2) { this.P.mCancelable = z2; return this; } public Builder setCursor(Cursor cursor, DialogInterface.OnClickListener onClickListener, String str) { AlertController.AlertParams alertParams = this.P; alertParams.mCursor = cursor; alertParams.mLabelColumn = str; alertParams.mOnClickListener = onClickListener; return this; } public Builder setCustomTitle(@Nullable View view) { this.P.mCustomTitleView = view; return this; } public Builder setIcon(@DrawableRes int i) { this.P.mIconId = i; return this; } public Builder setIcon(@Nullable Drawable drawable) { this.P.mIcon = drawable; return this; } public Builder setIconAttribute(@AttrRes int i) { TypedValue typedValue = new TypedValue(); this.P.mContext.getTheme().resolveAttribute(i, typedValue, true); this.P.mIconId = typedValue.resourceId; return this; } @Deprecated public Builder setInverseBackgroundForced(boolean z2) { this.P.mForceInverseBackground = z2; return this; } public Builder setItems(@ArrayRes int i, DialogInterface.OnClickListener onClickListener) { AlertController.AlertParams alertParams = this.P; alertParams.mItems = alertParams.mContext.getResources().getTextArray(i); this.P.mOnClickListener = onClickListener; return this; } public Builder setItems(CharSequence[] charSequenceArr, DialogInterface.OnClickListener onClickListener) { AlertController.AlertParams alertParams = this.P; alertParams.mItems = charSequenceArr; alertParams.mOnClickListener = onClickListener; return this; } public Builder setMessage(@StringRes int i) { AlertController.AlertParams alertParams = this.P; alertParams.mMessage = alertParams.mContext.getText(i); return this; } public Builder setMessage(@Nullable CharSequence charSequence) { this.P.mMessage = charSequence; return this; } public Builder setMultiChoiceItems(@ArrayRes int i, boolean[] zArr, DialogInterface.OnMultiChoiceClickListener onMultiChoiceClickListener) { AlertController.AlertParams alertParams = this.P; alertParams.mItems = alertParams.mContext.getResources().getTextArray(i); AlertController.AlertParams alertParams2 = this.P; alertParams2.mOnCheckboxClickListener = onMultiChoiceClickListener; alertParams2.mCheckedItems = zArr; alertParams2.mIsMultiChoice = true; return this; } public Builder setMultiChoiceItems(Cursor cursor, String str, String str2, DialogInterface.OnMultiChoiceClickListener onMultiChoiceClickListener) { AlertController.AlertParams alertParams = this.P; alertParams.mCursor = cursor; alertParams.mOnCheckboxClickListener = onMultiChoiceClickListener; alertParams.mIsCheckedColumn = str; alertParams.mLabelColumn = str2; alertParams.mIsMultiChoice = true; return this; } public Builder setMultiChoiceItems(CharSequence[] charSequenceArr, boolean[] zArr, DialogInterface.OnMultiChoiceClickListener onMultiChoiceClickListener) { AlertController.AlertParams alertParams = this.P; alertParams.mItems = charSequenceArr; alertParams.mOnCheckboxClickListener = onMultiChoiceClickListener; alertParams.mCheckedItems = zArr; alertParams.mIsMultiChoice = true; return this; } public Builder setNegativeButton(@StringRes int i, DialogInterface.OnClickListener onClickListener) { AlertController.AlertParams alertParams = this.P; alertParams.mNegativeButtonText = alertParams.mContext.getText(i); this.P.mNegativeButtonListener = onClickListener; return this; } public Builder setNegativeButton(CharSequence charSequence, DialogInterface.OnClickListener onClickListener) { AlertController.AlertParams alertParams = this.P; alertParams.mNegativeButtonText = charSequence; alertParams.mNegativeButtonListener = onClickListener; return this; } public Builder setNegativeButtonIcon(Drawable drawable) { this.P.mNegativeButtonIcon = drawable; return this; } public Builder setNeutralButton(@StringRes int i, DialogInterface.OnClickListener onClickListener) { AlertController.AlertParams alertParams = this.P; alertParams.mNeutralButtonText = alertParams.mContext.getText(i); this.P.mNeutralButtonListener = onClickListener; return this; } public Builder setNeutralButton(CharSequence charSequence, DialogInterface.OnClickListener onClickListener) { AlertController.AlertParams alertParams = this.P; alertParams.mNeutralButtonText = charSequence; alertParams.mNeutralButtonListener = onClickListener; return this; } public Builder setNeutralButtonIcon(Drawable drawable) { this.P.mNeutralButtonIcon = drawable; return this; } public Builder setOnCancelListener(DialogInterface.OnCancelListener onCancelListener) { this.P.mOnCancelListener = onCancelListener; return this; } public Builder setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) { this.P.mOnDismissListener = onDismissListener; return this; } public Builder setOnItemSelectedListener(AdapterView.OnItemSelectedListener onItemSelectedListener) { this.P.mOnItemSelectedListener = onItemSelectedListener; return this; } public Builder setOnKeyListener(DialogInterface.OnKeyListener onKeyListener) { this.P.mOnKeyListener = onKeyListener; return this; } public Builder setPositiveButton(@StringRes int i, DialogInterface.OnClickListener onClickListener) { AlertController.AlertParams alertParams = this.P; alertParams.mPositiveButtonText = alertParams.mContext.getText(i); this.P.mPositiveButtonListener = onClickListener; return this; } public Builder setPositiveButton(CharSequence charSequence, DialogInterface.OnClickListener onClickListener) { AlertController.AlertParams alertParams = this.P; alertParams.mPositiveButtonText = charSequence; alertParams.mPositiveButtonListener = onClickListener; return this; } public Builder setPositiveButtonIcon(Drawable drawable) { this.P.mPositiveButtonIcon = drawable; return this; } @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public Builder setRecycleOnMeasureEnabled(boolean z2) { this.P.mRecycleOnMeasure = z2; return this; } public Builder setSingleChoiceItems(@ArrayRes int i, int i2, DialogInterface.OnClickListener onClickListener) { AlertController.AlertParams alertParams = this.P; alertParams.mItems = alertParams.mContext.getResources().getTextArray(i); AlertController.AlertParams alertParams2 = this.P; alertParams2.mOnClickListener = onClickListener; alertParams2.mCheckedItem = i2; alertParams2.mIsSingleChoice = true; return this; } public Builder setSingleChoiceItems(Cursor cursor, int i, String str, DialogInterface.OnClickListener onClickListener) { AlertController.AlertParams alertParams = this.P; alertParams.mCursor = cursor; alertParams.mOnClickListener = onClickListener; alertParams.mCheckedItem = i; alertParams.mLabelColumn = str; alertParams.mIsSingleChoice = true; return this; } public Builder setSingleChoiceItems(ListAdapter listAdapter, int i, DialogInterface.OnClickListener onClickListener) { AlertController.AlertParams alertParams = this.P; alertParams.mAdapter = listAdapter; alertParams.mOnClickListener = onClickListener; alertParams.mCheckedItem = i; alertParams.mIsSingleChoice = true; return this; } public Builder setSingleChoiceItems(CharSequence[] charSequenceArr, int i, DialogInterface.OnClickListener onClickListener) { AlertController.AlertParams alertParams = this.P; alertParams.mItems = charSequenceArr; alertParams.mOnClickListener = onClickListener; alertParams.mCheckedItem = i; alertParams.mIsSingleChoice = true; return this; } public Builder setTitle(@StringRes int i) { AlertController.AlertParams alertParams = this.P; alertParams.mTitle = alertParams.mContext.getText(i); return this; } public Builder setTitle(@Nullable CharSequence charSequence) { this.P.mTitle = charSequence; return this; } public Builder setView(int i) { AlertController.AlertParams alertParams = this.P; alertParams.mView = null; alertParams.mViewLayoutResId = i; alertParams.mViewSpacingSpecified = false; return this; } public Builder setView(View view) { AlertController.AlertParams alertParams = this.P; alertParams.mView = view; alertParams.mViewLayoutResId = 0; alertParams.mViewSpacingSpecified = false; return this; } @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) @Deprecated public Builder setView(View view, int i, int i2, int i3, int i4) { AlertController.AlertParams alertParams = this.P; alertParams.mView = view; alertParams.mViewLayoutResId = 0; alertParams.mViewSpacingSpecified = true; alertParams.mViewSpacingLeft = i; alertParams.mViewSpacingTop = i2; alertParams.mViewSpacingRight = i3; alertParams.mViewSpacingBottom = i4; return this; } public AlertDialog show() { AlertDialog create = create(); create.show(); return create; } } public AlertDialog(@NonNull Context context) { this(context, 0); } public AlertDialog(@NonNull Context context, @StyleRes int i) { super(context, resolveDialogTheme(context, i)); this.mAlert = new AlertController(getContext(), this, getWindow()); } public AlertDialog(@NonNull Context context, boolean z2, @Nullable DialogInterface.OnCancelListener onCancelListener) { this(context, 0); setCancelable(z2); setOnCancelListener(onCancelListener); } public static int resolveDialogTheme(@NonNull Context context, @StyleRes int i) { if (((i >>> 24) & 255) >= 1) { return i; } TypedValue typedValue = new TypedValue(); context.getTheme().resolveAttribute(R.attr.alertDialogTheme, typedValue, true); return typedValue.resourceId; } public Button getButton(int i) { return this.mAlert.getButton(i); } public ListView getListView() { return this.mAlert.getListView(); } @Override // androidx.appcompat.app.AppCompatDialog, android.app.Dialog public void onCreate(Bundle bundle) { super.onCreate(bundle); this.mAlert.installContent(); } @Override // android.app.Dialog, android.view.KeyEvent.Callback public boolean onKeyDown(int i, KeyEvent keyEvent) { if (this.mAlert.onKeyDown(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.mAlert.onKeyUp(i, keyEvent)) { return true; } return super.onKeyUp(i, keyEvent); } public void setButton(int i, CharSequence charSequence, DialogInterface.OnClickListener onClickListener) { this.mAlert.setButton(i, charSequence, onClickListener, null, null); } public void setButton(int i, CharSequence charSequence, Drawable drawable, DialogInterface.OnClickListener onClickListener) { this.mAlert.setButton(i, charSequence, onClickListener, null, drawable); } public void setButton(int i, CharSequence charSequence, Message message) { this.mAlert.setButton(i, charSequence, null, message, null); } @RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX}) public void setButtonPanelLayoutHint(int i) { this.mAlert.setButtonPanelLayoutHint(i); } public void setCustomTitle(View view) { this.mAlert.setCustomTitle(view); } public void setIcon(int i) { this.mAlert.setIcon(i); } public void setIcon(Drawable drawable) { this.mAlert.setIcon(drawable); } public void setIconAttribute(int i) { TypedValue typedValue = new TypedValue(); getContext().getTheme().resolveAttribute(i, typedValue, true); this.mAlert.setIcon(typedValue.resourceId); } public void setMessage(CharSequence charSequence) { this.mAlert.setMessage(charSequence); } @Override // androidx.appcompat.app.AppCompatDialog, android.app.Dialog public void setTitle(CharSequence charSequence) { super.setTitle(charSequence); this.mAlert.setTitle(charSequence); } public void setView(View view) { this.mAlert.setView(view); } public void setView(View view, int i, int i2, int i3, int i4) { this.mAlert.setView(view, i, i2, i3, i4); } }