DialogProgress.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. package epson.common;
  2. import android.app.Dialog;
  3. import android.content.DialogInterface;
  4. import android.os.Bundle;
  5. import android.support.annotation.NonNull;
  6. import android.support.annotation.Nullable;
  7. import android.support.p000v4.app.DialogFragment;
  8. import android.support.p000v4.app.FragmentManager;
  9. import android.support.p003v7.app.AlertDialog;
  10. import android.view.View;
  11. import android.view.ViewGroup;
  12. import android.widget.ProgressBar;
  13. import android.widget.RelativeLayout;
  14. import android.widget.TextView;
  15. import epson.print.C2135R;
  16. public class DialogProgress extends DialogFragment {
  17. public static final int MESSAGE_BOTTOM = 1;
  18. public static final int MESSAGE_ONLY = 2;
  19. public static final int MESSAGE_RIGHT = 0;
  20. private static final String TAG_DIALOG = "tag";
  21. private static final String TAG_MESSAGE = "message";
  22. private static final String TAG_NEGATIVE_MESSAGE = "negative_dialog_message";
  23. private static final String TAG_NEUTRAL_MESSAGE = "neutral_dialog_message";
  24. private static final String TAG_POSITION = "position";
  25. private static final String TAG_POSITIVE_MESSAGE = "positive_dialog_message";
  26. private static final String TAG_TITLE_MESSAGE = "title_message";
  27. private DialogButtonClick mActivity;
  28. private String mTag;
  29. public interface DialogButtonClick {
  30. void onCancelDialog(String str);
  31. void onNegativeClick(String str);
  32. void onNeutralClick(String str);
  33. void onPositiveClick(String str);
  34. }
  35. public static DialogProgress newInstance(String str, int i, @Nullable String str2) {
  36. return newInstance(str, i, str2, (String) null, (String) null, (String) null, (String) null);
  37. }
  38. public static DialogProgress newInstance(String str, int i, @Nullable String str2, @Nullable String str3, @Nullable String str4, @Nullable String str5, @Nullable String str6) {
  39. DialogProgress dialogProgress = new DialogProgress();
  40. Bundle bundle = new Bundle();
  41. bundle.putString(TAG_DIALOG, str);
  42. bundle.putInt("position", i);
  43. bundle.putString("message", str2);
  44. bundle.putString(TAG_TITLE_MESSAGE, str3);
  45. bundle.putString(TAG_POSITIVE_MESSAGE, str4);
  46. bundle.putString(TAG_NEUTRAL_MESSAGE, str5);
  47. bundle.putString(TAG_NEGATIVE_MESSAGE, str6);
  48. dialogProgress.setArguments(bundle);
  49. return dialogProgress;
  50. }
  51. private void deleteFragment(FragmentManager fragmentManager, String str) {
  52. Dialog dialog;
  53. DialogProgress dialogProgress = (DialogProgress) fragmentManager.findFragmentByTag(str);
  54. if (dialogProgress != null && (dialog = dialogProgress.getDialog()) != null && dialog.isShowing()) {
  55. dialogProgress.dismiss();
  56. }
  57. }
  58. @NonNull
  59. public Dialog onCreateDialog(@Nullable Bundle bundle) {
  60. this.mTag = getArguments().getString(TAG_DIALOG);
  61. int i = getArguments().getInt("position");
  62. String string = getArguments().getString("message");
  63. String string2 = getArguments().getString(TAG_TITLE_MESSAGE);
  64. String string3 = getArguments().getString(TAG_POSITIVE_MESSAGE);
  65. String string4 = getArguments().getString(TAG_NEUTRAL_MESSAGE);
  66. String string5 = getArguments().getString(TAG_NEGATIVE_MESSAGE);
  67. AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
  68. View inflate = getActivity().getLayoutInflater().inflate(R.layout.dialog_progress, (ViewGroup) null);
  69. try {
  70. this.mActivity = (DialogButtonClick) getActivity();
  71. } catch (ClassCastException unused) {
  72. this.mActivity = null;
  73. }
  74. if (string2 != null) {
  75. builder.setTitle((CharSequence) string2);
  76. }
  77. if (string3 != null) {
  78. builder.setPositiveButton((CharSequence) string3, (DialogInterface.OnClickListener) new DialogInterface.OnClickListener() {
  79. public final void onClick(DialogInterface dialogInterface, int i) {
  80. DialogProgress.lambda$onCreateDialog$0(DialogProgress.this, dialogInterface, i);
  81. }
  82. });
  83. }
  84. if (string4 != null) {
  85. builder.setNeutralButton((CharSequence) string4, (DialogInterface.OnClickListener) new DialogInterface.OnClickListener() {
  86. public final void onClick(DialogInterface dialogInterface, int i) {
  87. DialogProgress.lambda$onCreateDialog$1(DialogProgress.this, dialogInterface, i);
  88. }
  89. });
  90. }
  91. if (string5 != null) {
  92. builder.setNegativeButton((CharSequence) string5, (DialogInterface.OnClickListener) new DialogInterface.OnClickListener() {
  93. public final void onClick(DialogInterface dialogInterface, int i) {
  94. DialogProgress.lambda$onCreateDialog$2(DialogProgress.this, dialogInterface, i);
  95. }
  96. });
  97. }
  98. ProgressBar progressBar = (ProgressBar) inflate.findViewById(R.C2137id.dialog_progress_id);
  99. if (i == 1) {
  100. RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) progressBar.getLayoutParams();
  101. layoutParams.addRule(14);
  102. progressBar.setLayoutParams(layoutParams);
  103. TextView textView = (TextView) inflate.findViewById(R.C2137id.dialog_progress_text_bottom);
  104. textView.setText(string);
  105. progressBar.setVisibility(0);
  106. textView.setVisibility(0);
  107. } else if (i == 0) {
  108. TextView textView2 = (TextView) inflate.findViewById(R.C2137id.dialog_progress_text_right);
  109. textView2.setText(string);
  110. progressBar.setVisibility(0);
  111. textView2.setVisibility(0);
  112. } else {
  113. TextView textView3 = (TextView) inflate.findViewById(R.C2137id.dialog_progress_text_right);
  114. textView3.setText(string);
  115. textView3.setVisibility(0);
  116. }
  117. builder.setView(inflate);
  118. return builder.create();
  119. }
  120. public static /* synthetic */ void lambda$onCreateDialog$0(DialogProgress dialogProgress, DialogInterface dialogInterface, int i) {
  121. dialogProgress.dismiss();
  122. DialogButtonClick dialogButtonClick = dialogProgress.mActivity;
  123. if (dialogButtonClick != null) {
  124. dialogButtonClick.onPositiveClick(dialogProgress.mTag);
  125. }
  126. }
  127. public static /* synthetic */ void lambda$onCreateDialog$1(DialogProgress dialogProgress, DialogInterface dialogInterface, int i) {
  128. dialogProgress.dismiss();
  129. DialogButtonClick dialogButtonClick = dialogProgress.mActivity;
  130. if (dialogButtonClick != null) {
  131. dialogButtonClick.onNeutralClick(dialogProgress.mTag);
  132. }
  133. }
  134. public static /* synthetic */ void lambda$onCreateDialog$2(DialogProgress dialogProgress, DialogInterface dialogInterface, int i) {
  135. dialogProgress.dismiss();
  136. DialogButtonClick dialogButtonClick = dialogProgress.mActivity;
  137. if (dialogButtonClick != null) {
  138. dialogButtonClick.onNegativeClick(dialogProgress.mTag);
  139. }
  140. }
  141. public void onCancel(DialogInterface dialogInterface) {
  142. DialogButtonClick dialogButtonClick = this.mActivity;
  143. if (dialogButtonClick != null) {
  144. dialogButtonClick.onCancelDialog(this.mTag);
  145. }
  146. super.onCancel(dialogInterface);
  147. }
  148. public void show(FragmentManager fragmentManager, String str) {
  149. deleteFragment(fragmentManager, str);
  150. super.showNow(fragmentManager, str);
  151. }
  152. }