LocalProgressDialog.java 3.6 KB

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