22
22
import android .annotation .SuppressLint ;
23
23
import android .app .AlertDialog ;
24
24
import android .content .ActivityNotFoundException ;
25
+ import android .content .ClipData ;
25
26
import android .content .Intent ;
26
27
import android .net .Uri ;
27
28
import android .os .AsyncTask ;
@@ -89,10 +90,10 @@ private Gui() {
89
90
editService );
90
91
91
92
Button cmdView = findViewById (R .id .cmd_view );
92
- cmdView .setOnClickListener (v -> onStartQuery ());
93
+ cmdView .setOnClickListener (v -> onStartQuery (false ));
93
94
/*
94
95
Button cmdShare = findViewById(R.id.cmd_share);
95
- cmdShare.setOnClickListener(v -> onStartQuery());
96
+ cmdShare.setOnClickListener(v -> onStartQuery(true ));
96
97
*/
97
98
Button cmdCancel = findViewById (R .id .cmd_cancel );
98
99
cmdCancel .setOnClickListener (v -> cancel ());
@@ -131,6 +132,8 @@ private void initServiceHistory() {
131
132
includeService (
132
133
languages .get ("simple_v" ), // last in list
133
134
languages .get ("simple_p" ),
135
+ languages .get ("en_m" ),
136
+ languages .get ("en_d" ),
134
137
languages .get ("en_v" ),
135
138
languages .get ("en_p" ),
136
139
languages .get (language + "_v" ),
@@ -196,6 +199,10 @@ public void setGuiMessage(int stringId, Object... parameters) {
196
199
}
197
200
198
201
class GeoLoadTask extends AsyncTask <GeoPointDto , Void , ArticlesDownloadService .Result > {
202
+ private final boolean useActionSend ;
203
+ public GeoLoadTask (boolean useActionSend ) {
204
+ this .useActionSend = useActionSend ;
205
+ }
199
206
200
207
@ Override
201
208
protected ArticlesDownloadService .Result doInBackground (GeoPointDto ... arg0 ) {
@@ -222,7 +229,7 @@ private ArticlesDownloadService.Result translateGeoToFile(GeoPointDto geoPointFr
222
229
223
230
@ Override
224
231
protected void onPostExecute (ArticlesDownloadService .Result result ) {
225
- showResult (result );
232
+ showResult (result , useActionSend );
226
233
}
227
234
}
228
235
@@ -234,7 +241,7 @@ protected void onCreateEx(Bundle savedInstanceState) {
234
241
GeoPointDto geoPointFromIntent = getGeoPointDtoFromIntent (getIntent ());
235
242
236
243
if (!geoConfig .showSettings && geoPointFromIntent != null && !GeoPointDto .isEmpty (geoPointFromIntent )) {
237
- queryDataFromArticleServer (geoPointFromIntent , false );
244
+ queryDataFromArticleServer (geoPointFromIntent , false , false );
238
245
} else {
239
246
setContentView (R .layout .activity_choose_url );
240
247
gui = new Gui ().load (geoConfig );
@@ -248,20 +255,20 @@ protected void onCreateEx(Bundle savedInstanceState) {
248
255
}
249
256
}
250
257
251
- private void queryDataFromArticleServer (GeoPointDto geoPointFromIntent , boolean inDemoMode ) {
258
+ private void queryDataFromArticleServer (GeoPointDto geoPointFromIntent , boolean inDemoMode , boolean useActionSend ) {
252
259
geoConfig .inDemoMode = inDemoMode ;
253
260
String name = createFileName (geoConfig .serviceName , geoPointFromIntent .getLatitude (), geoPointFromIntent .getLongitude ());
254
261
File outFile = new File (
255
262
createSharedOutDir (name ),
256
263
name + geoConfig .outFileExtension );
257
264
createSharedUri (outFile );
258
265
259
- new GeoLoadTask ().execute (geoPointFromIntent );
266
+ new GeoLoadTask (useActionSend ).execute (geoPointFromIntent );
260
267
}
261
268
262
269
/** called in gui thread, after receiving answer from wikipedia */
263
270
@ SuppressLint ("StringFormatMatches" )
264
- private void showResult (ArticlesDownloadService .Result result ) {
271
+ private void showResult (ArticlesDownloadService .Result result , boolean useActionSend ) {
265
272
266
273
if (result .errorMessageId != 0 ) {
267
274
showErrorMessage (getString (result .errorMessageId , geoConfig .serviceName , result .outFile , toString (geoConfig .demoUri ),"" ));
@@ -277,11 +284,24 @@ private void showResult(ArticlesDownloadService.Result result) {
277
284
278
285
Uri outUri = createSharedUri (result .outFile );
279
286
280
- Intent newIntent = new Intent (Intent .ACTION_VIEW )
281
- .setFlags (Intent .FLAG_GRANT_READ_URI_PERMISSION );
282
- newIntent .putExtra (Intent .EXTRA_TITLE , geoConfig .serviceName );
283
-
284
- newIntent .setDataAndTypeAndNormalize (outUri , geoConfig .outMimeType );
287
+ Intent newIntent ;
288
+ if (useActionSend ) {
289
+ // https://developer.android.com/reference/android/content/Intent#ACTION_SEND
290
+ newIntent = new Intent (Intent .ACTION_SEND )
291
+ .setFlags (Intent .FLAG_GRANT_READ_URI_PERMISSION )
292
+ .setType ("*/*" )
293
+ .putExtra (Intent .EXTRA_TITLE , geoConfig .serviceName )
294
+ .putExtra (Intent .EXTRA_STREAM , outUri );
295
+ newIntent .setClipData (ClipData .newRawUri ("" , outUri ));
296
+
297
+ newIntent = Intent .createChooser (newIntent , geoConfig .serviceName );
298
+ } else {
299
+ // https://developer.android.com/reference/android/content/Intent#ACTION_VIEW
300
+ newIntent = new Intent (Intent .ACTION_VIEW )
301
+ .setFlags (Intent .FLAG_GRANT_READ_URI_PERMISSION )
302
+ .putExtra (Intent .EXTRA_TITLE , geoConfig .serviceName )
303
+ .setDataAndTypeAndNormalize (outUri , geoConfig .outMimeType );
304
+ }
285
305
286
306
try {
287
307
// start the image capture Intent
@@ -367,14 +387,18 @@ public boolean onPrepareOptionsMenu(Menu menu) {
367
387
public boolean onOptionsItemSelected (MenuItem menuItem ) {
368
388
save ();
369
389
int itemId = menuItem .getItemId ();
390
+ boolean isCmdShare = itemId == R .id .cmd_share ;
370
391
if (itemId == R .id .cmd_cancel_pick ) {
371
392
finish ();
372
393
return true ;
373
- } else if (itemId == R .id .cmd_ok ) {
394
+ } else if (itemId == R .id .cmd_ok || isCmdShare ) {
374
395
GeoPointDto geoPointFromIntent = getGeoPointDtoFromIntent (getIntent ());
375
396
397
+ if (geoPointFromIntent == null ) {
398
+ geoPointFromIntent = new GeoConfig (this ).demoUri ;
399
+ }
376
400
if (geoPointFromIntent != null ) {
377
- queryDataFromArticleServer (geoPointFromIntent , false );
401
+ queryDataFromArticleServer (geoPointFromIntent , false , isCmdShare );
378
402
} else {
379
403
finish ();
380
404
}
@@ -385,9 +409,9 @@ public boolean onOptionsItemSelected(MenuItem menuItem) {
385
409
386
410
}
387
411
388
- private void onStartQuery () {
412
+ private void onStartQuery (boolean useActionSend ) {
389
413
save ();
390
- queryDataFromArticleServer (geoConfig .demoUri , true );
414
+ queryDataFromArticleServer (geoConfig .demoUri , true , useActionSend );
391
415
}
392
416
393
417
private void save () {
0 commit comments