CustomLayoutDialogFragment.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package epson.print;
  2. import android.app.AlertDialog;
  3. import android.app.Dialog;
  4. import android.content.DialogInterface;
  5. import android.os.Bundle;
  6. import android.view.KeyEvent;
  7. import android.view.View;
  8. import android.view.ViewGroup;
  9. import android.widget.Button;
  10. import android.widget.TextView;
  11. public class CustomLayoutDialogFragment extends DialogFragment {
  12. private static final String TAG_CLOSE_BUTTON_STRING_ID = "close_button_string_id";
  13. private static final String TAG_DIALOG_ID = "dialog_id";
  14. private static final String TAG_MESSAGE = "message";
  15. private static final String TAG_POSITIVE_BUTTON_STRING_ID = "positive_button_string_id";
  16. private static final String TAG_TITLE_ID = "title_id";
  17. private static final String TAG_TITLE_STRING = "title_string";
  18. public static CustomLayoutDialogFragment newInstance(int i, String str, int i2, int i3, int i4) {
  19. CustomLayoutDialogFragment customLayoutDialogFragment = new CustomLayoutDialogFragment();
  20. Bundle bundle = new Bundle();
  21. bundle.putInt(TAG_DIALOG_ID, i);
  22. bundle.putString("message", str);
  23. bundle.putInt(TAG_TITLE_ID, i2);
  24. bundle.putInt(TAG_POSITIVE_BUTTON_STRING_ID, i3);
  25. bundle.putInt(TAG_CLOSE_BUTTON_STRING_ID, i4);
  26. customLayoutDialogFragment.setArguments(bundle);
  27. return customLayoutDialogFragment;
  28. }
  29. public static CustomLayoutDialogFragment newInstance(int i, String str, String str2, int i2, int i3) {
  30. CustomLayoutDialogFragment customLayoutDialogFragment = new CustomLayoutDialogFragment();
  31. Bundle bundle = new Bundle();
  32. bundle.putInt(TAG_DIALOG_ID, i);
  33. bundle.putString("message", str);
  34. bundle.putString(TAG_TITLE_STRING, str2);
  35. bundle.putInt(TAG_POSITIVE_BUTTON_STRING_ID, i2);
  36. bundle.putInt(TAG_CLOSE_BUTTON_STRING_ID, i3);
  37. customLayoutDialogFragment.setArguments(bundle);
  38. return customLayoutDialogFragment;
  39. }
  40. public Dialog onCreateDialog(Bundle bundle) {
  41. Bundle arguments = getArguments();
  42. final int i = arguments.getInt(TAG_DIALOG_ID);
  43. String string = arguments.getString("message");
  44. int i2 = arguments.getInt(TAG_TITLE_ID);
  45. String string2 = arguments.getString(TAG_TITLE_STRING);
  46. int i3 = arguments.getInt(TAG_POSITIVE_BUTTON_STRING_ID);
  47. int i4 = arguments.getInt(TAG_CLOSE_BUTTON_STRING_ID);
  48. final CustomTitleDialogFragment.Callback callback = (CustomTitleDialogFragment.Callback) getActivity();
  49. AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
  50. View inflate = getActivity().getLayoutInflater().inflate(R.layout.dialog_custom_layout01, (ViewGroup) null);
  51. TextView textView = (TextView) inflate.findViewById(R.id.title_text);
  52. if (string2 != null) {
  53. textView.setText(string2);
  54. } else {
  55. textView.setText(i2);
  56. }
  57. ((TextView) inflate.findViewById(R.id.message_text)).setText(string);
  58. Button button = (Button) inflate.findViewById(R.id.close_button);
  59. button.setOnClickListener(new View.OnClickListener() {
  60. public void onClick(View view) {
  61. dismiss();
  62. callback.onLocalNegativeCallback(i);
  63. }
  64. });
  65. button.setText(i4);
  66. Button button2 = (Button) inflate.findViewById(R.id.browse_button);
  67. button2.setOnClickListener(new View.OnClickListener() {
  68. public void onClick(View view) {
  69. dismiss();
  70. callback.onLocalPositiveCallback(i);
  71. }
  72. });
  73. if (i3 != 0) {
  74. button2.setText(i3);
  75. } else {
  76. button2.setVisibility(View.GONE);
  77. }
  78. builder.setView(inflate);
  79. AlertDialog create = builder.create();
  80. create.setCanceledOnTouchOutside(false);
  81. create.setOnKeyListener(new DialogInterface.OnKeyListener() {
  82. public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
  83. return keyEvent.getKeyCode() == 84;
  84. }
  85. });
  86. return create;
  87. }
  88. }