StringListSelectDialog.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package epson.print.screen;
  2. import android.app.AlertDialog;
  3. import android.app.Dialog;
  4. import android.content.Context;
  5. import android.content.DialogInterface;
  6. import android.os.Bundle;
  7. import android.support.annotation.NonNull;
  8. import android.support.annotation.Nullable;
  9. public class StringListSelectDialog extends DialogFragment {
  10. private static final String ARGS_KEY_STRING_LIST = "key-stringList";
  11. private OnItemSelectedListener mListener;
  12. private String[] mStringList;
  13. public interface OnItemSelectedListener {
  14. void onItemSelected(@NonNull String str);
  15. }
  16. @NonNull
  17. public static StringListSelectDialog newInstance(@NonNull String[] strArr) {
  18. StringListSelectDialog stringListSelectDialog = new StringListSelectDialog();
  19. Bundle bundle = new Bundle();
  20. bundle.putStringArray(ARGS_KEY_STRING_LIST, strArr);
  21. stringListSelectDialog.setArguments(bundle);
  22. return stringListSelectDialog;
  23. }
  24. @NonNull
  25. public Dialog onCreateDialog(@Nullable Bundle bundle) {
  26. Bundle arguments = getArguments();
  27. if (arguments != null) {
  28. this.mStringList = arguments.getStringArray(ARGS_KEY_STRING_LIST);
  29. if (this.mStringList != null) {
  30. AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
  31. builder.setItems(this.mStringList, new DialogInterface.OnClickListener() {
  32. public void onClick(DialogInterface dialogInterface, int i) {
  33. StringListSelectDialog.this.itemSelected(i);
  34. }
  35. });
  36. setCancelable(false);
  37. return builder.create();
  38. }
  39. throw new IllegalArgumentException();
  40. }
  41. throw new IllegalArgumentException();
  42. }
  43. /* access modifiers changed from: private */
  44. public void itemSelected(int i) {
  45. OnItemSelectedListener onItemSelectedListener = this.mListener;
  46. if (onItemSelectedListener != null) {
  47. onItemSelectedListener.onItemSelected(this.mStringList[i]);
  48. }
  49. }
  50. public void onAttach(Context context) {
  51. super.onAttach(context);
  52. try {
  53. this.mListener = (OnItemSelectedListener) context;
  54. } catch (ClassCastException unused) {
  55. throw new ClassCastException(context.toString() + " must implement StringListSelectDialog.OnItemSelectedListener");
  56. }
  57. }
  58. public void onDetach() {
  59. super.onDetach();
  60. this.mListener = null;
  61. }
  62. }