DialogProgressWiFiDirect.java 6.8 KB

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