Skip to content

Commit 68b35f8

Browse files
committed
#7 add support for commons.wikimedia.org (view Fotos)
#8 add support for www.wikidata.org (view Knowledgebase) #9 add button "share" (i.e. save as local file)
1 parent 7405678 commit 68b35f8

File tree

12 files changed

+112
-54
lines changed

12 files changed

+112
-54
lines changed

README.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# AndroidGeo2ArticlesMap
22

33
Plugin for [Location Map Viewer](https://f-droid.org/en/packages/de.k3b.android.locationMapViewer):
4-
Show articles from Wikipedia™ or Wikivoyage™ near a given geographic location in an interactive map.
4+
Show articles near a given geographic location in an interactive map from
5+
6+
* Wikipedia™ (The Free Encyclopedia that anyone can edit) or
7+
* Wikivoyage™ (Free travel guide that anyone can edit) or
8+
* Wikimedia™ (Free Fotos, Vidio, Audo collections) or
9+
* Wikidata™ (knowledge base that anyone can edit).
510

611
Uscase: Suppose you are going on holiday. Your navigation app shows you a geo-map with your hotel
7-
and you want to know: what is near this place that has an article in [wikipedia](https://en.wikipedia.org)
8-
( or [wikivoyage](https://en.wikivoyage.org) ).
12+
and you want to know: what is near this place that has an article in [wikipedia](https://en.wikipedia.org).
913

1014
In your navigation app select "view in external app" (or "send location to" or "share location with" or ...)
1115
choose "Show Articles in Map" and you will get a map with marks for articles. If you click on a mark you get
@@ -55,7 +59,7 @@ If you select view + "Show Articles in Map" from a geo app you will see the sett
5559

5660
![](https://raw.githubusercontent.com/k3b/AndroidGeo2ArticlesMap/main/fastlane/metadata/android/en-US/images/phoneScreenshots/2-ageo2ArticleMap-pick-service.png)
5761

58-
(3) pick one of the 93 bigger **known services**
62+
(3) pick one of the 95 bigger **known services**
5963

6064
---
6165

@@ -81,7 +85,7 @@ Technically speaking the AndroidGeo2ArticlesMap app
8185
[Location Map Viewer](https://github.com/k3b/LocationMapViewer)
8286
Copyright (c) by k3b, Licensed under GPL, Version 3.0 or later.
8387

84-
Wikipedia and Wikivoyage are [trademarks of the Wikimedia Foundation](https://foundation.wikimedia.org/wiki/Wikimedia_trademarks)
88+
Wikipedia, Wikimedia, Wikidata and Wikivoyage are [trademarks of the Wikimedia Foundation](https://foundation.wikimedia.org/wiki/Wikimedia_trademarks)
8589

8690
-----
8791

app/build.gradle

+5-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ android {
1414
// v1.3 (3) fixed fastlane description
1515
// v1.4 (4) 2021-08-01: removed obsolete write permissions not neccessary since android-4.4 (api 19)
1616
// v1.5 (5) 2021-08-??: Setting: option to (not) Load symbols/images; Bug Fixes
17-
versionCode 5
18-
versionName 'v1.5'
17+
// v1.6 (6) 2023-03-21: Add support for Wikimedia (Fotos) and Wikidata (Knowledgebase) and Send
18+
versionCode 6
19+
versionName 'v1.6'
1920

2021
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
2122
}
@@ -54,8 +55,8 @@ dependencies {
5455
implementation 'org.slf4j:slf4j-api:1.7.7@jar'
5556
implementation 'org.slf4j:slf4j-simple:1.7.7'
5657
// implementation project(path: ':k3b-geoHelper')
57-
implementation 'com.github.k3b:k3b-geoHelper:v1.1.9'
58-
// implementation 'com.github.k3b:k3b-geoHelperAndroid:v1.1.9'
58+
implementation 'com.github.k3b:k3b-geoHelper:v1.1.12'
59+
// implementation 'com.github.k3b:k3b-geoHelperAndroid:v1.1.12'
5960

6061
implementation 'commons-io:commons-io:2.6'
6162
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

app/src/debug/res/values/fdroid.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ Note: You must also install [Location Map Viewer](https://f-droid.org/packages/d
3939
4040
This app adds the option *Show Articles in Map* to any app that can shown/send/share a geo location or **geo-uri** .
4141
42-
This app hooks into the android system to intercept "view geo-uri". When getting a geo-uri it asks wikipedia and shows the results in
42+
This app hooks into the android system to intercept "view geo-uri". When getting a geo-uri it asks
43+
encyclopedia *wikipedia* (or travelguide *wikivoyage* or knowledgebase *wikidata* or photogallery *wikimedia*)
44+
and shows the results in
4345
[Location Map Viewer](https://f-droid.org/packages/de.k3b.android.locationMapViewer)
4446
(or in any other installed app that understands the format 'kmz').
4547

app/src/main/assets/languages.properties

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#
88
# harvested on 2021-07-04: all html <option.. from https://www.wikipedia.org and https://www.wikivoyage.org/
99
# sorted by language-key
10+
# en_m => commons.wikimedia.org
11+
# en_d => www.wikidata.org
1012
# xx_p => xx.wikipedia.org
1113
# xx_v => xx.wikivoyage.org
1214
ar_p=العربية 🇸🇦
@@ -28,6 +30,8 @@ de_p=Deutsch 🇩🇪
2830
de_v=Deutsch 🇩🇪
2931
el_p=Ελληνικά
3032
el_v=Ελληνικά
33+
en_d=Knowledgebase 🔬
34+
en_m=Fotos 📷
3135
en_p=English 🇺🇸 🇬🇧
3236
en_v=English 🇺🇸 🇬🇧
3337
eo_p=Esperanto 🗺

app/src/main/java/de/k3b/android/articlemap/ArticlesDownloadService.java

+29-16
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private InputStream getInputStream(URL url) throws IOException {
106106
}
107107

108108
private Result getGeoPointInfos(Object lat, Object lon, boolean withSymbols) {
109-
String urlString = this.getQueryGeoUrlString(lat, lon, withSymbols);
109+
String urlString = this.getQueryGeoUrlString(lat, lon, withSymbols, serviceName.contains(".wikidata."));
110110
String message = "downloading articles from " + serviceName;
111111
Log.i(TAG, message + " using " + urlString);
112112
if (progressMessage != null) {
@@ -116,7 +116,7 @@ private Result getGeoPointInfos(Object lat, Object lon, boolean withSymbols) {
116116
try (InputStream inputStream = this.getInputStream(urlString) ){
117117
GpxReader<IGeoPointInfo> parser = new GpxReader<>();
118118
message = "analysing articles ...";
119-
Log.d(TAG,message);
119+
Log.d(TAG,message);
120120
if (progressMessage != null) {
121121
progressMessage.message(message);
122122
}
@@ -125,7 +125,7 @@ private Result getGeoPointInfos(Object lat, Object lon, boolean withSymbols) {
125125
return new Result(null, points, 0, null);
126126
} catch (Exception ex) {
127127
message = "cannot read from '" + this.serviceName + "' using '" + urlString + "'" ;
128-
Log.e(TAG, message,ex);
128+
Log.e(TAG, message,ex);
129129
if (progressMessage != null) {
130130
progressMessage.message(message);
131131
}
@@ -156,8 +156,13 @@ public Result saveAsEx(Object lat, Object lon, boolean withSymbols, File out) {
156156
return result;
157157
}
158158

159-
/** api creates url that encodes what we want to get from wikipedia */
160-
private String getQueryGeoUrlString(Object lat, Object lon, boolean withSymbols) {
159+
/** api creates url that encodes what we want to get from wikipedia
160+
*
161+
* examples
162+
* * https://de.wikivoyage.org/w/api.php?action=query&format=xml&prop=coordinates|info|pageimages|extracts&inprop=url&piprop=thumbnail&generator=geosearch&ggscoord=28.12722|-15.43139&ggsradius=10000&ggslimit=5&pilimit=5&exsentences=2&explaintext&exintro
163+
* * https://www.wikidata.org/w/api.php?action=query&format=xml&prop=entityterms|coordinates|info&inprop=url&generator=geosearch&ggscoord=36.45284|28.22016&ggsradius=10000&ggslimit=25
164+
* */
165+
private String getQueryGeoUrlString(Object lat, Object lon, boolean withSymbols, boolean fromWikiData) {
161166
// see https://www.mediawiki.org/wiki/Special:MyLanguage/API:Main_page
162167
StringBuilder urlString = new StringBuilder().append("https://")
163168
.append(serviceName)
@@ -166,27 +171,35 @@ private String getQueryGeoUrlString(Object lat, Object lon, boolean withSymbols)
166171
"&format=xml" +
167172
"&prop=coordinates|info");
168173

169-
if (withSymbols) {
170-
urlString.append("|pageimages");
174+
if (fromWikiData) {
175+
urlString.append("|entityterms");
176+
} else {
177+
if (withSymbols) {
178+
urlString.append("|pageimages");
179+
}
180+
181+
urlString.append("|extracts");
171182
}
172183

173-
urlString.append("|extracts" +
184+
urlString.append(
174185
"&inprop=url" +
175186
"&generator=geosearch" +
176187
"&ggscoord=")
177188
.append(lat).append("|").append(lon)
178189
.append("&ggsradius=").append(radius)
179190
.append("&ggslimit=").append(maxcount);
180191

181-
if (withSymbols) {
182-
urlString.append("&piprop=thumbnail")
183-
.append("&pithumbsize=").append(GeoConfig.THUMBSIZE)
184-
.append("&pilimit=").append(maxcount);
185-
}
192+
if (!fromWikiData) {
193+
if (withSymbols) {
194+
urlString.append("&piprop=thumbnail")
195+
.append("&pithumbsize=").append(GeoConfig.THUMBSIZE)
196+
.append("&pilimit=").append(maxcount);
197+
}
186198

187-
urlString
188-
// prop extracts: 2Sentenses in non-html before TOC
189-
.append("&exsentences=2&explaintext&exintro");
199+
urlString
200+
// prop extracts: 2Sentenses in non-html before TOC
201+
.append("&exsentences=2&explaintext&exintro");
202+
}
190203
return urlString.toString();
191204
}
192205

app/src/main/java/de/k3b/android/articlemap/GeoConfig.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
public class GeoConfig {
2929
public String serviceName = null; // i.e. "en.wikipedia.org";
30-
public final String USER_AGENT = "AndroidGeo2ArticlesMap/1.0 (https://github.com/k3b/AndroidGeo2ArticlesMap)";
30+
public final String USER_AGENT = "AndroidGeo2ArticlesMap/1.1 (https://github.com/k3b/AndroidGeo2ArticlesMap)";
3131
public final String outFileExtension = ".kmz";
3232
public final String outMimeType = "application/vnd.google-earth.kmz";
3333

app/src/main/java/de/k3b/android/articlemap/LanguageDefinition.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.Collections;
3131
import java.util.HashMap;
3232
import java.util.List;
33-
import java.util.Locale;
3433
import java.util.Map;
3534
import java.util.Properties;
3635

@@ -40,16 +39,18 @@ public class LanguageDefinition implements Comparable<LanguageDefinition> {
4039
private final String key;
4140
private final String name;
4241

42+
// ie new LanguageDefinition("en_d","Scientific Data 🔬")
4343
public LanguageDefinition(String key, String value) {
44-
String languageID = getLanguage(key);
45-
46-
this.url = languageID + (isWikipedia(key) ? ".wikipedia.org" : ".wikivoyage.org");
44+
this.url = getUrl(key);
4745
this.key = key;
48-
this.name = languageID + " " + value + " " + this.getUrl();
46+
this.name = getLanguage(key) + " " + value + " " + this.url;
4947
}
5048

51-
private boolean isWikipedia(String key) {
52-
return !key.endsWith("_v");
49+
@NonNull
50+
private String getUrl(String key) {
51+
if (key.endsWith("_d")) return "www.wikidata.org";
52+
if (key.endsWith("_m")) return "commons.wikimedia.org";
53+
return getLanguage(key) + (key.endsWith("_v") ? ".wikivoyage.org" : ".wikipedia.org");
5354
}
5455

5556
private String getLanguage(String key) {
@@ -73,7 +74,6 @@ public static Map<String, LanguageDefinition> getLanguages(Context context) thro
7374
}
7475

7576
public static Map<String, LanguageDefinition> getLanguages(InputStream in) throws IOException {
76-
String language = Locale.getDefault().getLanguage();
7777
Properties properties = new Properties();
7878
// note: Properties standard use iso-8859-1. However this app uses utf8
7979
properties.load(new InputStreamReader(in, StandardCharsets.UTF_8));

app/src/main/java/de/k3b/android/articlemap/ShowArticlesInMapActivity.java

+40-16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.annotation.SuppressLint;
2323
import android.app.AlertDialog;
2424
import android.content.ActivityNotFoundException;
25+
import android.content.ClipData;
2526
import android.content.Intent;
2627
import android.net.Uri;
2728
import android.os.AsyncTask;
@@ -89,10 +90,10 @@ private Gui() {
8990
editService );
9091

9192
Button cmdView = findViewById(R.id.cmd_view);
92-
cmdView.setOnClickListener(v -> onStartQuery());
93+
cmdView.setOnClickListener(v -> onStartQuery(false));
9394
/*
9495
Button cmdShare = findViewById(R.id.cmd_share);
95-
cmdShare.setOnClickListener(v -> onStartQuery());
96+
cmdShare.setOnClickListener(v -> onStartQuery(true));
9697
*/
9798
Button cmdCancel = findViewById(R.id.cmd_cancel);
9899
cmdCancel.setOnClickListener(v -> cancel());
@@ -131,6 +132,8 @@ private void initServiceHistory() {
131132
includeService(
132133
languages.get("simple_v"), // last in list
133134
languages.get("simple_p"),
135+
languages.get("en_m"),
136+
languages.get("en_d"),
134137
languages.get("en_v"),
135138
languages.get("en_p"),
136139
languages.get(language + "_v"),
@@ -196,6 +199,10 @@ public void setGuiMessage(int stringId, Object... parameters) {
196199
}
197200

198201
class GeoLoadTask extends AsyncTask<GeoPointDto, Void, ArticlesDownloadService.Result> {
202+
private final boolean useActionSend;
203+
public GeoLoadTask(boolean useActionSend) {
204+
this.useActionSend = useActionSend;
205+
}
199206

200207
@Override
201208
protected ArticlesDownloadService.Result doInBackground(GeoPointDto... arg0) {
@@ -222,7 +229,7 @@ private ArticlesDownloadService.Result translateGeoToFile(GeoPointDto geoPointFr
222229

223230
@Override
224231
protected void onPostExecute(ArticlesDownloadService.Result result) {
225-
showResult(result);
232+
showResult(result, useActionSend);
226233
}
227234
}
228235

@@ -234,7 +241,7 @@ protected void onCreateEx(Bundle savedInstanceState) {
234241
GeoPointDto geoPointFromIntent = getGeoPointDtoFromIntent(getIntent());
235242

236243
if (!geoConfig.showSettings && geoPointFromIntent != null && !GeoPointDto.isEmpty(geoPointFromIntent)) {
237-
queryDataFromArticleServer(geoPointFromIntent, false);
244+
queryDataFromArticleServer(geoPointFromIntent, false, false);
238245
} else {
239246
setContentView(R.layout.activity_choose_url);
240247
gui = new Gui().load(geoConfig);
@@ -248,20 +255,20 @@ protected void onCreateEx(Bundle savedInstanceState) {
248255
}
249256
}
250257

251-
private void queryDataFromArticleServer(GeoPointDto geoPointFromIntent, boolean inDemoMode) {
258+
private void queryDataFromArticleServer(GeoPointDto geoPointFromIntent, boolean inDemoMode, boolean useActionSend) {
252259
geoConfig.inDemoMode = inDemoMode;
253260
String name = createFileName(geoConfig.serviceName, geoPointFromIntent.getLatitude(), geoPointFromIntent.getLongitude());
254261
File outFile = new File(
255262
createSharedOutDir(name),
256263
name + geoConfig.outFileExtension);
257264
createSharedUri(outFile);
258265

259-
new GeoLoadTask().execute(geoPointFromIntent);
266+
new GeoLoadTask(useActionSend).execute(geoPointFromIntent);
260267
}
261268

262269
/** called in gui thread, after receiving answer from wikipedia */
263270
@SuppressLint("StringFormatMatches")
264-
private void showResult(ArticlesDownloadService.Result result) {
271+
private void showResult(ArticlesDownloadService.Result result, boolean useActionSend) {
265272

266273
if (result.errorMessageId != 0) {
267274
showErrorMessage(getString(result.errorMessageId, geoConfig.serviceName, result.outFile, toString(geoConfig.demoUri),""));
@@ -277,11 +284,24 @@ private void showResult(ArticlesDownloadService.Result result) {
277284

278285
Uri outUri = createSharedUri(result.outFile);
279286

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+
}
285305

286306
try {
287307
// start the image capture Intent
@@ -367,14 +387,18 @@ public boolean onPrepareOptionsMenu(Menu menu) {
367387
public boolean onOptionsItemSelected(MenuItem menuItem) {
368388
save();
369389
int itemId = menuItem.getItemId();
390+
boolean isCmdShare = itemId == R.id.cmd_share;
370391
if (itemId == R.id.cmd_cancel_pick) {
371392
finish();
372393
return true;
373-
} else if (itemId == R.id.cmd_ok) {
394+
} else if (itemId == R.id.cmd_ok || isCmdShare) {
374395
GeoPointDto geoPointFromIntent = getGeoPointDtoFromIntent(getIntent());
375396

397+
if (geoPointFromIntent == null) {
398+
geoPointFromIntent = new GeoConfig(this).demoUri;
399+
}
376400
if (geoPointFromIntent != null) {
377-
queryDataFromArticleServer(geoPointFromIntent, false);
401+
queryDataFromArticleServer(geoPointFromIntent, false, isCmdShare);
378402
} else {
379403
finish();
380404
}
@@ -385,9 +409,9 @@ public boolean onOptionsItemSelected(MenuItem menuItem) {
385409

386410
}
387411

388-
private void onStartQuery() {
412+
private void onStartQuery(boolean useActionSend) {
389413
save();
390-
queryDataFromArticleServer(geoConfig.demoUri, true);
414+
queryDataFromArticleServer(geoConfig.demoUri, true, useActionSend);
391415
}
392416

393417
private void save() {

app/src/main/res/menu/menu_choose_url.xml

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
-->
2222
<!-- menue of gallery for modus pick/getContent -->
2323
<menu xmlns:android="http://schemas.android.com/apk/res/android">
24+
<item android:id="@+id/cmd_share" android:title="@string/share"
25+
android:icon="@android:drawable/ic_menu_share"
26+
android:orderInCategory="2" android:showAsAction="always" android:visible="true" />
2427
<item android:id="@+id/cmd_ok" android:title="@android:string/ok"
2528
android:icon="@drawable/ic_action_accept"
2629
android:orderInCategory="2" android:showAsAction="always" android:visible="true" />
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
--- todo ---
1+
v1.6 (6)
2+
3+
* #7 Added support for 📷 commons.wikimedia.org (i.e. gallery of photos)
4+
* #8 Added support for 🔬 www.wikidata.org (Knowledgebase)
5+
* #9 Added button "share" (i.e. share generated kmz to "save as local file")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--- todo ---

0 commit comments

Comments
 (0)