LocalProgressDialog.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package com.epson.iprint.storage;
  2. import android.app.Dialog;
  3. import android.os.Bundle;
  4. import android.support.p000v4.app.FragmentManager;
  5. import android.view.KeyEvent;
  6. import android.view.LayoutInflater;
  7. import android.view.View;
  8. import android.view.ViewGroup;
  9. import android.widget.Button;
  10. import android.widget.LinearLayout;
  11. import android.widget.TextView;
  12. import epson.print.R;
  13. public class LocalProgressDialog extends DialogFragment {
  14. private static final String LOG_TAG = "MyProgress";
  15. private static final String PARAM_CANCELABLE = "cancelable";
  16. private static final String PARAM_CANCEL_CONFIRM_DIALOG_TAG = "tag_confirm-cancel";
  17. private static final String PARAM_MESSAGE_ID = "message-id";
  18. private String mCancelConfirmDialogTag;
  19. public static LocalProgressDialog newInstance(boolean z, int i, @NonNull String str) {
  20. if (!z || str != null) {
  21. LocalProgressDialog localProgressDialog = new LocalProgressDialog();
  22. Bundle bundle = new Bundle();
  23. bundle.putBoolean(PARAM_CANCELABLE, z);
  24. bundle.putInt(PARAM_MESSAGE_ID, i);
  25. bundle.putString(PARAM_CANCEL_CONFIRM_DIALOG_TAG, str);
  26. localProgressDialog.setArguments(bundle);
  27. return localProgressDialog;
  28. }
  29. throw new IllegalArgumentException();
  30. }
  31. @Nullable
  32. public View onCreateView(@NonNull LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
  33. Bundle arguments = getArguments();
  34. boolean z = arguments.getBoolean(PARAM_CANCELABLE, false);
  35. int i = arguments.getInt(PARAM_MESSAGE_ID, 0);
  36. mCancelConfirmDialogTag = arguments.getString(PARAM_CANCEL_CONFIRM_DIALOG_TAG);
  37. View inflate = layoutInflater.inflate(R.layout.my_progress, viewGroup, false);
  38. Button button = (Button) inflate.findViewById(R.id.cancelButton);
  39. button.setOnClickListener(new View.OnClickListener() {
  40. public void onClick(View view) {
  41. showCancelConfirmDialog();
  42. }
  43. });
  44. button.setText(R.string.str_cancel);
  45. int i2 = 8;
  46. button.setVisibility(z ? 0 : 8);
  47. TextView textView = (TextView) inflate.findViewById(R.id.messageText);
  48. if (i != 0) {
  49. textView.setText(i);
  50. }
  51. if (i != 0) {
  52. i2 = 0;
  53. }
  54. textView.setVisibility(i2);
  55. ((LinearLayout) inflate.findViewById(R.id.dialog_back)).setOnClickListener(new View.OnClickListener() {
  56. public void onClick(View view) {
  57. }
  58. });
  59. inflate.setFocusableInTouchMode(true);
  60. inflate.requestFocus();
  61. inflate.setOnKeyListener(new View.OnKeyListener() {
  62. public boolean onKey(View view, int i, KeyEvent keyEvent) {
  63. return i == 4;
  64. }
  65. });
  66. setCancelable(false);
  67. return inflate;
  68. }
  69. @NonNull
  70. public Dialog onCreateDialog(Bundle bundle) {
  71. Dialog onCreateDialog = super.onCreateDialog(bundle);
  72. onCreateDialog.requestWindowFeature(1);
  73. return onCreateDialog;
  74. }
  75. private void showCancelConfirmDialog() {
  76. if (mCancelConfirmDialogTag != null) {
  77. FragmentManager fragmentManager = getFragmentManager();
  78. if (fragmentManager != null) {
  79. ConfirmCancelDialog.newInstance(R.string.str_msg_scan_cancel).show(fragmentManager, mCancelConfirmDialogTag);
  80. return;
  81. }
  82. return;
  83. }
  84. throw new IllegalStateException();
  85. }
  86. }