package com.epson.memcardacc; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; public class LocalAlertDialogFragment extends DialogFragment { private static final String KEY_DIALOG_CODE = "dialog_code"; private static final String KEY_MESSAGE = "message"; private static final String KEY_NO_TITLE = "no_title"; private static final String KEY_TITLE = "title"; private int mDialogCode; public interface DialogCallback { void onDialogCallback(int i); } public static LocalAlertDialogFragment newInstance(int i, int i2, int i3) { LocalAlertDialogFragment localAlertDialogFragment = new LocalAlertDialogFragment(); Bundle bundle = new Bundle(); bundle.putInt("message", i); bundle.putInt(KEY_TITLE, i2); bundle.putInt(KEY_DIALOG_CODE, i3); localAlertDialogFragment.setArguments(bundle); return localAlertDialogFragment; } public static LocalAlertDialogFragment newInstanceNoTitle(int i, int i2) { LocalAlertDialogFragment localAlertDialogFragment = new LocalAlertDialogFragment(); Bundle bundle = new Bundle(); bundle.putInt("message", i); bundle.putInt(KEY_DIALOG_CODE, i2); bundle.putBoolean(KEY_NO_TITLE, true); localAlertDialogFragment.setArguments(bundle); return localAlertDialogFragment; } public Dialog onCreateDialog(Bundle bundle) { Bundle arguments = getArguments(); int i = arguments.getInt("message", 0); int i2 = arguments.getInt(KEY_TITLE, 0); boolean z = arguments.getBoolean(KEY_NO_TITLE, false); mDialogCode = arguments.getInt(KEY_DIALOG_CODE); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setMessage(i).setPositiveButton(getActivity().getString(R.string.str_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { execCallback(); } }); if (!z) { builder.setTitle(i2); } AlertDialog create = builder.create(); create.setCanceledOnTouchOutside(false); return create; } private void execCallback() { try { DialogCallback dialogCallback = (DialogCallback) getActivity(); if (dialogCallback != null) { dialogCallback.onDialogCallback(mDialogCode); } } catch (ClassCastException unused) { } } }