Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/UserInterface/CustomDevicesActivity.java
Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | 57 | protected void onCreate(Bundle savedInstanceState) { | |||
---|---|---|---|---|---|
59 | initializeDeviceList(this); | 59 | initializeDeviceList(this); | ||
60 | setContentView(R.layout.custom_ip_list); | 60 | setContentView(R.layout.custom_ip_list); | ||
61 | 61 | | |||
62 | list = (ListView) findViewById(android.R.id.list); | 62 | list = (ListView) findViewById(android.R.id.list); | ||
63 | list.setOnItemClickListener(onClickListener); | 63 | list.setOnItemClickListener(onClickListener); | ||
64 | 64 | | |||
65 | list.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, ipAddressList)); | 65 | list.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, ipAddressList)); | ||
66 | 66 | | |||
67 | findViewById(android.R.id.button1).setOnClickListener(new View.OnClickListener() { | 67 | findViewById(android.R.id.button1).setOnClickListener(v -> addNewDevice()); | ||
68 | @Override | | |||
69 | public void onClick(View v) { | | |||
70 | addNewDevice(); | | |||
71 | } | | |||
72 | }); | | |||
73 | 68 | | |||
74 | EditText ipEntryBox = (EditText) findViewById(R.id.ip_edittext); | 69 | EditText ipEntryBox = (EditText) findViewById(R.id.ip_edittext); | ||
75 | ipEntryBox.setOnEditorActionListener(new TextView.OnEditorActionListener() { | 70 | ipEntryBox.setOnEditorActionListener((v, actionId, event) -> { | ||
76 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { | | |||
77 | if (actionId == EditorInfo.IME_ACTION_SEND) { | 71 | if (actionId == EditorInfo.IME_ACTION_SEND) { | ||
78 | addNewDevice(); | 72 | addNewDevice(); | ||
79 | return true; | 73 | return true; | ||
80 | } | 74 | } | ||
81 | return false; | 75 | return false; | ||
82 | } | | |||
83 | }); | 76 | }); | ||
84 | } | 77 | } | ||
85 | 78 | | |||
86 | boolean dialogAlreadyShown = false; | 79 | boolean dialogAlreadyShown = false; | ||
87 | private AdapterView.OnItemClickListener onClickListener = new AdapterView.OnItemClickListener() { | 80 | private AdapterView.OnItemClickListener onClickListener = (parent, view, position, id) -> { | ||
88 | @Override | | |||
89 | public void onItemClick(AdapterView<?> parent, View view, final int position, final long id) { | | |||
90 | 81 | | |||
91 | if (dialogAlreadyShown) { | 82 | if (dialogAlreadyShown) { | ||
92 | return; | 83 | return; | ||
93 | } | 84 | } | ||
94 | 85 | | |||
95 | // remove touched item after confirmation | 86 | // remove touched item after confirmation | ||
96 | DialogInterface.OnClickListener confirmationListener = new DialogInterface.OnClickListener() { | 87 | DialogInterface.OnClickListener confirmationListener = (dialog, which) -> { | ||
97 | @Override | | |||
98 | public void onClick(DialogInterface dialog, int which) { | | |||
99 | switch (which) { | 88 | switch (which) { | ||
100 | case DialogInterface.BUTTON_POSITIVE: | 89 | case DialogInterface.BUTTON_POSITIVE: | ||
101 | ipAddressList.remove(position); | 90 | ipAddressList.remove(position); | ||
102 | saveList(); | 91 | saveList(); | ||
103 | break; | 92 | break; | ||
104 | case DialogInterface.BUTTON_NEGATIVE: | 93 | case DialogInterface.BUTTON_NEGATIVE: | ||
105 | break; | 94 | break; | ||
106 | } | 95 | } | ||
107 | } | | |||
108 | }; | 96 | }; | ||
109 | 97 | | |||
110 | AlertDialog.Builder builder = new AlertDialog.Builder(CustomDevicesActivity.this); | 98 | AlertDialog.Builder builder = new AlertDialog.Builder(CustomDevicesActivity.this); | ||
111 | builder.setMessage("Delete " + ipAddressList.get(position) + " ?"); | 99 | builder.setMessage("Delete " + ipAddressList.get(position) + " ?"); | ||
112 | builder.setPositiveButton("Yes", confirmationListener); | 100 | builder.setPositiveButton("Yes", confirmationListener); | ||
113 | builder.setNegativeButton("No", confirmationListener); | 101 | builder.setNegativeButton("No", confirmationListener); | ||
114 | 102 | | |||
115 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { //DismissListener | 103 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { //DismissListener | ||
116 | dialogAlreadyShown = true; | 104 | dialogAlreadyShown = true; | ||
117 | builder.setOnDismissListener(new DialogInterface.OnDismissListener() { | 105 | builder.setOnDismissListener(dialog -> dialogAlreadyShown = false); | ||
118 | @Override | | |||
119 | public void onDismiss(DialogInterface dialog) { | | |||
120 | dialogAlreadyShown = false; | | |||
121 | } | | |||
122 | }); | | |||
123 | } | 106 | } | ||
124 | 107 | | |||
125 | builder.show(); | 108 | builder.show(); | ||
126 | } | | |||
127 | }; | 109 | }; | ||
128 | 110 | | |||
129 | private void addNewDevice() { | 111 | private void addNewDevice() { | ||
130 | EditText ipEntryBox = (EditText) findViewById(R.id.ip_edittext); | 112 | EditText ipEntryBox = (EditText) findViewById(R.id.ip_edittext); | ||
131 | String enteredText = ipEntryBox.getText().toString().trim(); | 113 | String enteredText = ipEntryBox.getText().toString().trim(); | ||
132 | if (!enteredText.isEmpty()) { | 114 | if (!enteredText.isEmpty()) { | ||
133 | // don't add empty string (after trimming) | 115 | // don't add empty string (after trimming) | ||
134 | ipAddressList.add(enteredText); | 116 | ipAddressList.add(enteredText); | ||
▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines |