LocalAlertDialogFragment.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package com.epson.memcardacc;
  2. import android.app.AlertDialog;
  3. import android.app.Dialog;
  4. import android.content.DialogInterface;
  5. import android.os.Bundle;
  6. public class LocalAlertDialogFragment extends DialogFragment {
  7. private static final String KEY_DIALOG_CODE = "dialog_code";
  8. private static final String KEY_MESSAGE = "message";
  9. private static final String KEY_NO_TITLE = "no_title";
  10. private static final String KEY_TITLE = "title";
  11. private int mDialogCode;
  12. public interface DialogCallback {
  13. void onDialogCallback(int i);
  14. }
  15. public static LocalAlertDialogFragment newInstance(int i, int i2, int i3) {
  16. LocalAlertDialogFragment localAlertDialogFragment = new LocalAlertDialogFragment();
  17. Bundle bundle = new Bundle();
  18. bundle.putInt("message", i);
  19. bundle.putInt(KEY_TITLE, i2);
  20. bundle.putInt(KEY_DIALOG_CODE, i3);
  21. localAlertDialogFragment.setArguments(bundle);
  22. return localAlertDialogFragment;
  23. }
  24. public static LocalAlertDialogFragment newInstanceNoTitle(int i, int i2) {
  25. LocalAlertDialogFragment localAlertDialogFragment = new LocalAlertDialogFragment();
  26. Bundle bundle = new Bundle();
  27. bundle.putInt("message", i);
  28. bundle.putInt(KEY_DIALOG_CODE, i2);
  29. bundle.putBoolean(KEY_NO_TITLE, true);
  30. localAlertDialogFragment.setArguments(bundle);
  31. return localAlertDialogFragment;
  32. }
  33. public Dialog onCreateDialog(Bundle bundle) {
  34. Bundle arguments = getArguments();
  35. int i = arguments.getInt("message", 0);
  36. int i2 = arguments.getInt(KEY_TITLE, 0);
  37. boolean z = arguments.getBoolean(KEY_NO_TITLE, false);
  38. mDialogCode = arguments.getInt(KEY_DIALOG_CODE);
  39. AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
  40. builder.setMessage(i).setPositiveButton(getActivity().getString(R.string.str_ok), new DialogInterface.OnClickListener() {
  41. public void onClick(DialogInterface dialogInterface, int i) {
  42. execCallback();
  43. }
  44. });
  45. if (!z) {
  46. builder.setTitle(i2);
  47. }
  48. AlertDialog create = builder.create();
  49. create.setCanceledOnTouchOutside(false);
  50. return create;
  51. }
  52. private void execCallback() {
  53. try {
  54. DialogCallback dialogCallback = (DialogCallback) getActivity();
  55. if (dialogCallback != null) {
  56. dialogCallback.onDialogCallback(mDialogCode);
  57. }
  58. } catch (ClassCastException unused) {
  59. }
  60. }
  61. }