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