OneButtonDialogFragment.java 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package com.epson.iprint.storage;
  2. import android.app.AlertDialog;
  3. import android.app.Dialog;
  4. import android.content.DialogInterface;
  5. import android.os.Bundle;
  6. import epson.print.R;
  7. public class OneButtonDialogFragment extends DialogFragment {
  8. private static final String PARAM_DIALOG_ID = "dialog_id";
  9. private static final String PARAM_MESSAGE_RESOURCE_ID = "message_id";
  10. private String mDialogId;
  11. private int mMessageId;
  12. public interface DialogCallback {
  13. void buttonPressed(@Nullable String str);
  14. }
  15. public static OneButtonDialogFragment newInstance(int i, String str) {
  16. OneButtonDialogFragment oneButtonDialogFragment = new OneButtonDialogFragment();
  17. Bundle bundle = new Bundle();
  18. bundle.putInt(PARAM_MESSAGE_RESOURCE_ID, i);
  19. bundle.putSerializable(PARAM_DIALOG_ID, str);
  20. oneButtonDialogFragment.setArguments(bundle);
  21. return oneButtonDialogFragment;
  22. }
  23. public void onCreate(Bundle bundle) {
  24. super.onCreate(bundle);
  25. Bundle arguments = getArguments();
  26. mMessageId = arguments.getInt(PARAM_MESSAGE_RESOURCE_ID);
  27. mDialogId = arguments.getString(PARAM_DIALOG_ID);
  28. setCancelable(false);
  29. }
  30. @NonNull
  31. public Dialog onCreateDialog(Bundle bundle) {
  32. super.onCreateDialog(bundle);
  33. return new AlertDialog.Builder(getActivity()).setMessage(mMessageId).setPositiveButton(R.string.str_ok, new DialogInterface.OnClickListener() {
  34. public void onClick(DialogInterface dialogInterface, int i) {
  35. FragmentActivity activity = getActivity();
  36. if (activity != null) {
  37. ((DialogCallback) activity).buttonPressed (mDialogId);
  38. }
  39. }
  40. }).setCancelable(false).create();
  41. }
  42. }