Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Plugins/SharePlugin/ShareActivity.java
Show All 27 Lines | |||||
28 | import android.support.v7.app.AppCompatActivity; | 28 | import android.support.v7.app.AppCompatActivity; | ||
29 | import android.util.Log; | 29 | import android.util.Log; | ||
30 | import android.view.Menu; | 30 | import android.view.Menu; | ||
31 | import android.view.MenuInflater; | 31 | import android.view.MenuInflater; | ||
32 | import android.view.MenuItem; | 32 | import android.view.MenuItem; | ||
33 | import android.view.View; | 33 | import android.view.View; | ||
34 | import android.widget.AdapterView; | 34 | import android.widget.AdapterView; | ||
35 | import android.widget.ListView; | 35 | import android.widget.ListView; | ||
36 | import android.widget.Toast; | ||||
37 | | ||||
36 | import org.kde.kdeconnect.BackgroundService; | 38 | import org.kde.kdeconnect.BackgroundService; | ||
37 | import org.kde.kdeconnect.Device; | 39 | import org.kde.kdeconnect.Device; | ||
38 | import org.kde.kdeconnect.NetworkPackage; | 40 | import org.kde.kdeconnect.NetworkPackage; | ||
39 | import org.kde.kdeconnect.UserInterface.List.EntryItem; | 41 | import org.kde.kdeconnect.UserInterface.List.EntryItem; | ||
40 | import org.kde.kdeconnect.UserInterface.List.ListAdapter; | 42 | import org.kde.kdeconnect.UserInterface.List.ListAdapter; | ||
41 | import org.kde.kdeconnect.UserInterface.List.SectionItem; | 43 | import org.kde.kdeconnect.UserInterface.List.SectionItem; | ||
42 | import org.kde.kdeconnect_tp.R; | 44 | import org.kde.kdeconnect_tp.R; | ||
43 | 45 | | |||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Line(s) | 125 | runOnUiThread(new Runnable() { | |||
125 | public void run() { | 127 | public void run() { | ||
126 | ListView list = (ListView) findViewById(R.id.listView1); | 128 | ListView list = (ListView) findViewById(R.id.listView1); | ||
127 | list.setAdapter(new ListAdapter(ShareActivity.this, items)); | 129 | list.setAdapter(new ListAdapter(ShareActivity.this, items)); | ||
128 | list.setOnItemClickListener(new AdapterView.OnItemClickListener() { | 130 | list.setOnItemClickListener(new AdapterView.OnItemClickListener() { | ||
129 | @Override | 131 | @Override | ||
130 | public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { | 132 | public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { | ||
131 | 133 | | |||
132 | Device device = devicesList.get(i - 1); //NOTE: -1 because of the title! | 134 | Device device = devicesList.get(i - 1); //NOTE: -1 because of the title! | ||
133 | 135 | SharePlugin.share(intent, device); | |||
134 | Bundle extras = intent.getExtras(); | | |||
135 | if (extras != null) { | | |||
136 | if (extras.containsKey(Intent.EXTRA_STREAM)) { | | |||
137 | | ||||
138 | try { | | |||
139 | | ||||
140 | ArrayList<Uri> uriList; | | |||
141 | if (!Intent.ACTION_SEND.equals(intent.getAction())) { | | |||
142 | uriList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM); | | |||
143 | } else { | | |||
144 | Uri uri = extras.getParcelable(Intent.EXTRA_STREAM); | | |||
145 | uriList = new ArrayList<>(); | | |||
146 | uriList.add(uri); | | |||
147 | } | | |||
148 | | ||||
149 | SharePlugin.queuedSendUriList(getApplicationContext(), device, uriList); | | |||
150 | | ||||
151 | } catch (Exception e) { | | |||
152 | Log.e("ShareActivity", "Exception"); | | |||
153 | e.printStackTrace(); | | |||
154 | } | | |||
155 | | ||||
156 | } else if (extras.containsKey(Intent.EXTRA_TEXT)) { | | |||
157 | String text = extras.getString(Intent.EXTRA_TEXT); | | |||
158 | String subject = extras.getString(Intent.EXTRA_SUBJECT); | | |||
159 | | ||||
160 | //Hack: Detect shared youtube videos, so we can open them in the browser instead of as text | | |||
161 | if (subject != null && subject.endsWith("YouTube")) { | | |||
162 | int index = text.indexOf(": http://youtu.be/"); | | |||
163 | if (index > 0) { | | |||
164 | text = text.substring(index + 2); //Skip ": " | | |||
165 | } | | |||
166 | } | | |||
167 | | ||||
168 | boolean isUrl; | | |||
169 | try { | | |||
170 | new URL(text); | | |||
171 | isUrl = true; | | |||
172 | } catch (Exception e) { | | |||
173 | isUrl = false; | | |||
174 | } | | |||
175 | NetworkPackage np = new NetworkPackage(SharePlugin.PACKAGE_TYPE_SHARE_REQUEST); | | |||
176 | if (isUrl) { | | |||
177 | np.set("url", text); | | |||
178 | } else { | | |||
179 | np.set("text", text); | | |||
180 | } | | |||
181 | device.sendPackage(np); | | |||
182 | } | | |||
183 | } | | |||
184 | finish(); | 136 | finish(); | ||
185 | } | 137 | } | ||
186 | }); | 138 | }); | ||
187 | } | 139 | } | ||
188 | }); | 140 | }); | ||
189 | 141 | | |||
190 | } | 142 | } | ||
191 | }); | 143 | }); | ||
Show All 18 Lines | 161 | if (actionBar != null) { | |||
210 | actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM); | 162 | actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM); | ||
211 | } | 163 | } | ||
212 | } | 164 | } | ||
213 | 165 | | |||
214 | 166 | | |||
215 | @Override | 167 | @Override | ||
216 | protected void onStart() { | 168 | protected void onStart() { | ||
217 | super.onStart(); | 169 | super.onStart(); | ||
170 | | ||||
171 | final Intent intent = getIntent(); | ||||
172 | final String deviceId = intent.getStringExtra("deviceId"); | ||||
173 | | ||||
174 | if (deviceId!=null) { | ||||
175 | | ||||
176 | BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback(){ | ||||
albertvaka: I think here we can use the BackgroundService.RunCommand construct, instead of using the… | |||||
177 | | ||||
178 | @Override | ||||
179 | public void onServiceStart(BackgroundService service) { | ||||
180 | Log.d("DirectShare", "sharing to "+service.getDevice(deviceId).getName()); | ||||
181 | Device device = service.getDevice(deviceId); | ||||
182 | if (device.isReachable() && device.isPaired()) { | ||||
183 | SharePlugin.share(intent, device); | ||||
184 | } | ||||
185 | finish(); | ||||
186 | } | ||||
187 | }); | ||||
188 | } else { | ||||
189 | | ||||
218 | BackgroundService.addGuiInUseCounter(this); | 190 | BackgroundService.addGuiInUseCounter(this); | ||
219 | BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() { | 191 | BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() { | ||
220 | @Override | 192 | @Override | ||
221 | public void onServiceStart(BackgroundService service) { | 193 | public void onServiceStart(BackgroundService service) { | ||
222 | service.onNetworkChange(); | 194 | service.onNetworkChange(); | ||
223 | service.addDeviceListChangedCallback("ShareActivity", new BackgroundService.DeviceListChangedCallback() { | 195 | service.addDeviceListChangedCallback("ShareActivity", new BackgroundService.DeviceListChangedCallback() { | ||
224 | @Override | 196 | @Override | ||
225 | public void onDeviceListChanged() { | 197 | public void onDeviceListChanged() { | ||
226 | updateComputerList(); | 198 | updateComputerList(); | ||
227 | } | 199 | } | ||
228 | }); | 200 | }); | ||
229 | } | 201 | } | ||
230 | }); | 202 | }); | ||
231 | updateComputerList(); | 203 | updateComputerList(); | ||
232 | } | 204 | } | ||
205 | } | ||||
206 | | ||||
233 | 207 | | |||
234 | @Override | 208 | @Override | ||
235 | protected void onStop() { | 209 | protected void onStop() { | ||
236 | BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() { | 210 | BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() { | ||
237 | @Override | 211 | @Override | ||
238 | public void onServiceStart(BackgroundService service) { | 212 | public void onServiceStart(BackgroundService service) { | ||
239 | service.removeDeviceListChangedCallback("ShareActivity"); | 213 | service.removeDeviceListChangedCallback("ShareActivity"); | ||
240 | } | 214 | } | ||
241 | }); | 215 | }); | ||
242 | BackgroundService.removeGuiInUseCounter(this); | 216 | BackgroundService.removeGuiInUseCounter(this); | ||
243 | super.onStop(); | 217 | super.onStop(); | ||
244 | } | 218 | } | ||
245 | 219 | | |||
246 | } | 220 | } |
I think here we can use the BackgroundService.RunCommand construct, instead of using the singleton... I would prefer if we only use the singleton when it's 100% necessary (ie: only from the ChooserTargetService).