diff --git a/OsmAnd-java/src/net/osmand/IndexConstants.java b/OsmAnd-java/src/net/osmand/IndexConstants.java index b33fea6aea..498bc44ac4 100644 --- a/OsmAnd-java/src/net/osmand/IndexConstants.java +++ b/OsmAnd-java/src/net/osmand/IndexConstants.java @@ -13,6 +13,8 @@ public class IndexConstants { public static final String POI_INDEX_EXT = ".poi.odb"; //$NON-NLS-1$ public static final String BINARY_MAP_INDEX_EXT = ".obf"; //$NON-NLS-1$ public static final String BINARY_SRTM_MAP_INDEX_EXT = ".srtm.obf"; //$NON-NLS-1$ + public static final String BINARY_WIKI_MAP_INDEX_EXT_ZIP = ".wiki.obf.zip"; //$NON-NLS-1$ + public static final String BINARY_WIKI_MAP_INDEX_EXT = ".wiki.obf"; //$NON-NLS-1$ public static final String BINARY_SRTM_MAP_INDEX_EXT_ZIP = ".srtm.obf.zip"; //$NON-NLS-1$ public static final String TOUR_INDEX_EXT = ".tour"; //$NON-NLS-1$ @@ -42,6 +44,7 @@ public class IndexConstants { public static final String TILES_INDEX_DIR= "tiles/"; public static final String TOURS_INDEX_DIR= "tours/"; public static final String SRTM_INDEX_DIR = "srtm/"; //$NON-NLS-1$ + public static final String WIKI_INDEX_DIR = "wiki/"; //$NON-NLS-1$ public static final String AV_INDEX_DIR = "avnotes/"; //$NON-NLS-1$ public static final String VOICE_INDEX_DIR = "voice/"; //$NON-NLS-1$ public static final String RENDERERS_DIR = "rendering/"; //$NON-NLS-1$ diff --git a/OsmAnd-java/src/net/osmand/data/Amenity.java b/OsmAnd-java/src/net/osmand/data/Amenity.java index 1491028673..351d0c59b8 100644 --- a/OsmAnd-java/src/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/net/osmand/data/Amenity.java @@ -5,8 +5,10 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; +import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.zip.GZIPInputStream; @@ -150,6 +152,29 @@ public class Amenity extends MapObject { setAdditionalInfo(PHONE, phone); } + public String getNameSelected(String lang) { + if (lang != null) { + String translateName; + if (lang.equals("en")) { + translateName = getEnName(); + } else { + translateName = getAdditionalInfo("name:" + lang); + } + if (!Algorithms.isEmpty(translateName)) { + return lang; + } + } + if (!Algorithms.isEmpty(getName())) { + return ""; + } + for (String nm : getAdditionalInfo().keySet()) { + if (nm.startsWith("name:")) { + return nm.substring("name:".length()); + } + } + return ""; + } + public String getName(String lang) { if (lang != null) { String translateName; @@ -173,6 +198,20 @@ public class Amenity extends MapObject { return ""; } + public List getNames(String defName) { + List l = new ArrayList(); + if (!Algorithms.isEmpty(getName())) { + l.add(defName); + } + for (String nm : getAdditionalInfo().keySet()) { + if (nm.startsWith("name:")) { + l.add(nm.substring("name:".length())); + } + } + + return l; + } + public String getContentLang(String tag, String lang) { if (lang != null) { String translateName = getAdditionalInfo(tag + ":" + lang); diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 2ac246462c..0dd2dba61f 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,9 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Read full article + Wikipedia + Wikipedia Show details Delete OSM Edit Disabled @@ -875,6 +878,7 @@ none OpenMaps EU Hillshade + Wikipedia Hillshade overlays Changes in 1.1.2: \n\t* Audio/video plugin enhancement (photos with EXIF information) diff --git a/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java b/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java index d2bc25ef60..1e6daa8ced 100644 --- a/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/LocalIndexHelper.java @@ -94,6 +94,7 @@ public class LocalIndexHelper { loadObfData(app.getAppPath(IndexConstants.BACKUP_INDEX_DIR), result, true, loadTask, loadedMaps); loadTilesData(app.getAppPath(IndexConstants.TILES_INDEX_DIR), result, false, loadTask); loadSrtmData(app.getAppPath(IndexConstants.SRTM_INDEX_DIR), result, loadTask); + loadWikiData(app.getAppPath(IndexConstants.WIKI_INDEX_DIR), result, loadTask); loadVoiceData(app.getAppPath(IndexConstants.VOICE_INDEX_DIR), result, false, loadTask); loadVoiceData(app.getAppPath(IndexConstants.TTSVOICE_INDEX_EXT_ZIP), result, true, loadTask); @@ -168,12 +169,30 @@ public class LocalIndexHelper { } } + private void loadWikiData(File mapPath, List result, LoadLocalIndexTask loadTask) { + if (mapPath.canRead()) { + for (File mapFile : listFilesSorted(mapPath)) { + if (mapFile.isFile() && mapFile.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) { + LocalIndexInfo info = new LocalIndexInfo(LocalIndexType.WIKI_DATA, mapFile, false); + updateDescription(info); + result.add(info); + loadTask.loadFile(info); + } + } + } + } + private void loadObfData(File mapPath, List result, boolean backup, LoadLocalIndexTask loadTask, Map loadedMaps) { if (mapPath.canRead()) { for (File mapFile : listFilesSorted(mapPath)) { if (mapFile.isFile() && mapFile.getName().endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) { - boolean srtm = mapFile.getName().endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT); - LocalIndexInfo info = new LocalIndexInfo(srtm ? LocalIndexType.SRTM_DATA :LocalIndexType.MAP_DATA, mapFile, backup); + LocalIndexType lt = LocalIndexType.MAP_DATA; + if(mapFile.getName().endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT)) { + lt = LocalIndexType.SRTM_DATA; + } else if(mapFile.getName().endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)) { + lt = LocalIndexType.WIKI_DATA; + } + LocalIndexInfo info = new LocalIndexInfo(lt, mapFile, backup); if(loadedMaps.containsKey(mapFile.getName()) && !backup){ info.setLoaded(true); } @@ -194,6 +213,7 @@ public class LocalIndexHelper { MAP_DATA(R.string.local_indexes_cat_map), TILES_DATA(R.string.local_indexes_cat_tile), SRTM_DATA(R.string.local_indexes_cat_srtm), + WIKI_DATA(R.string.local_indexes_cat_wiki), VOICE_DATA(R.string.local_indexes_cat_voice), TTS_VOICE_DATA(R.string.local_indexes_cat_tts); // AV_DATA(R.string.local_indexes_cat_av);; diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index b02cb4c33a..11c3c81f18 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -363,12 +363,16 @@ public class DownloadActivity extends BaseDownloadActivity { public List createDownloadTypes() { List items = new ArrayList(); items.add(DownloadActivityType.NORMAL_FILE); + if(!Version.isFreeVersion(getMyApplication())) { + items.add(DownloadActivityType.WIKIPEDIA_FILE); + } items.add(DownloadActivityType.VOICE_FILE); items.add(DownloadActivityType.ROADS_FILE); if(OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null){ items.add(DownloadActivityType.HILLSHADE_FILE); items.add(DownloadActivityType.SRTM_COUNTRY_FILE); } + getMyApplication().getAppCustomization().getDownloadTypes(items); return items; } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java index d557bb0b46..5e45c5d972 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java @@ -34,6 +34,7 @@ public class DownloadActivityType { public static final DownloadActivityType ROADS_FILE = new DownloadActivityType(R.string.download_roads_only_maps, "road_map"); public static final DownloadActivityType SRTM_COUNTRY_FILE = new DownloadActivityType(R.string.download_srtm_maps, "srtm_map"); public static final DownloadActivityType HILLSHADE_FILE = new DownloadActivityType(R.string.download_hillshade_maps, "hillshade"); + public static final DownloadActivityType WIKIPEDIA_FILE = new DownloadActivityType(R.string.download_wikipedia_maps, "wikimap"); private int resource; private String[] tags; @@ -84,6 +85,9 @@ public class DownloadActivityType { || fileName.endsWith(IndexConstants.SQLITE_EXT); } else if (VOICE_FILE == this) { return fileName.endsWith(addVersionToExt(IndexConstants.VOICE_INDEX_EXT_ZIP, IndexConstants.VOICE_VERSION)); + } else if (WIKIPEDIA_FILE == this) { + return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT_ZIP, + IndexConstants.BINARY_MAP_VERSION)); } else if (SRTM_COUNTRY_FILE == this) { return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT_ZIP, IndexConstants.BINARY_MAP_VERSION)); @@ -103,6 +107,8 @@ public class DownloadActivityType { return ctx.getAppPath(IndexConstants.VOICE_INDEX_DIR); } else if (SRTM_COUNTRY_FILE == this) { return ctx.getAppPath(IndexConstants.SRTM_INDEX_DIR); + } else if (WIKIPEDIA_FILE == this) { + return ctx.getAppPath(IndexConstants.WIKI_INDEX_DIR); } else if (HILLSHADE_FILE == this) { return ctx.getAppPath(IndexConstants.TILES_INDEX_DIR); } @@ -139,7 +145,9 @@ public class DownloadActivityType { } else if (VOICE_FILE == this) { return ""; } else if (SRTM_COUNTRY_FILE == this) { - return BINARY_SRTM_MAP_INDEX_EXT; + return IndexConstants.BINARY_SRTM_MAP_INDEX_EXT; + } else if (WIKIPEDIA_FILE == this) { + return IndexConstants.BINARY_WIKI_MAP_INDEX_EXT; } else if (HILLSHADE_FILE == this) { return IndexConstants.SQLITE_EXT; } @@ -151,6 +159,8 @@ public class DownloadActivityType { return "&road=yes"; } else if (this == DownloadActivityType.SRTM_COUNTRY_FILE) { return "&srtmcountry=yes"; + } else if (this == DownloadActivityType.WIKIPEDIA_FILE) { + return "&wiki=yes"; }else if (this== DownloadActivityType.HILLSHADE_FILE) { return "&hillshade=yes"; } @@ -202,6 +212,8 @@ public class DownloadActivityType { public String getVisibleDescription(IndexItem indexItem, Context ctx) { if (this == DownloadActivityType.SRTM_COUNTRY_FILE) { return ctx.getString(R.string.download_srtm_maps); + } else if (this == DownloadActivityType.WIKIPEDIA_FILE) { + return ctx.getString(R.string.download_wikipedia_item); } else if (this == DownloadActivityType.ROADS_FILE) { return ctx.getString(R.string.download_roads_only_item); } @@ -264,6 +276,9 @@ public class DownloadActivityType { if (this == DownloadActivityType.SRTM_COUNTRY_FILE) { return baseNameWithoutVersion + IndexConstants.BINARY_SRTM_MAP_INDEX_EXT; } + if (this == DownloadActivityType.WIKIPEDIA_FILE) { + return baseNameWithoutVersion + IndexConstants.BINARY_WIKI_MAP_INDEX_EXT; + } if (this == DownloadActivityType.ROADS_FILE) { baseNameWithoutVersion += "-roads"; } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java index 686f60eeaa..80713aed97 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexAdapter.java @@ -252,8 +252,7 @@ public class DownloadIndexAdapter extends OsmandBaseExpandableListAdapter implem }); if (indexFileNames != null && e.isAlreadyDownloaded(indexFileNames)) { - if (e.getType() == DownloadActivityType.HILLSHADE_FILE - || e.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) { + if (e.getType() == DownloadActivityType.HILLSHADE_FILE) { String sfName = e.getTargetFileName(); if (indexActivatedFileNames.containsKey(sfName)) { name.setTypeface(Typeface.DEFAULT, Typeface.NORMAL); diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index 7d9d957b99..64613ecd41 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -583,6 +583,7 @@ public class DownloadIndexesThread { !date.equals(indexfilesdate)) { if ((item.getType() == DownloadActivityType.NORMAL_FILE && !item.extra) || item.getType() == DownloadActivityType.ROADS_FILE || + item.getType() == DownloadActivityType.WIKIPEDIA_FILE || item.getType() == DownloadActivityType.SRTM_COUNTRY_FILE){ outdated = true; } else { diff --git a/OsmAnd/src/net/osmand/plus/download/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/LocalIndexesFragment.java index 4a00ea9b8b..e480f60225 100644 --- a/OsmAnd/src/net/osmand/plus/download/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/LocalIndexesFragment.java @@ -195,7 +195,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment { return performBasicOperation(resId, info); } }; - if(info.getType() == LocalIndexType.MAP_DATA || info.getType() == LocalIndexType.SRTM_DATA){ + if(info.getType() == LocalIndexType.MAP_DATA || info.getType() == LocalIndexType.SRTM_DATA || + info.getType() == LocalIndexType.WIKI_DATA){ if(!info.isBackupedData()){ adapter.item(R.string.local_index_mi_backup).listen(listener).position( 1).reg(); } @@ -338,6 +339,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment { File parent = new File(i.getPathToData()).getParentFile(); if(i.getType() == LocalIndexType.SRTM_DATA){ parent = getMyApplication().getAppPath(IndexConstants.SRTM_INDEX_DIR); + } else if(i.getType() == LocalIndexType.WIKI_DATA){ + parent = getMyApplication().getAppPath(IndexConstants.WIKI_INDEX_DIR); } else if(i.getType() == LocalIndexType.MAP_DATA){ parent = getMyApplication().getAppPath(IndexConstants.MAPS_PATH); } else if(i.getType() == LocalIndexType.TILES_DATA){ diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index 953de8c1de..28d82fcccc 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -595,6 +595,7 @@ public class ResourceManager { ArrayList files = new ArrayList(); File appPath = context.getAppPath(null); collectFiles(appPath, IndexConstants.BINARY_MAP_INDEX_EXT, files); + collectFiles(context.getAppPath(IndexConstants.WIKI_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files); if(OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null) { collectFiles(context.getAppPath(IndexConstants.SRTM_INDEX_DIR), IndexConstants.BINARY_MAP_INDEX_EXT, files); } diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index eac9933d17..75515ec942 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -21,6 +21,8 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.download.DownloadActivity; +import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.osmo.OsMoService; import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiLegacyFilter; @@ -46,18 +48,25 @@ import android.graphics.Paint.Style; import android.graphics.drawable.Drawable; import android.graphics.PointF; import android.net.Uri; +import android.support.v4.view.MenuItemCompat; +import android.support.v7.widget.PopupMenu; import android.support.v7.widget.Toolbar; import android.text.SpannableString; import android.text.method.LinkMovementMethod; import android.text.util.Linkify; import android.util.TypedValue; +import android.view.Gravity; +import android.view.MenuItem; +import android.view.MenuItem.OnMenuItemClickListener; import android.view.MotionEvent; import android.view.View; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.ArrayAdapter; +import android.widget.Button; import android.widget.LinearLayout; +import android.widget.LinearLayout.LayoutParams; import android.widget.ScrollView; import android.widget.TextView; import android.widget.Toast; @@ -331,8 +340,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon public static void showDescriptionDialog(Context ctx, OsmandApplication app, Amenity a) { String lang = app.getSettings().MAP_PREFERRED_LOCALE.get(); if (a.getType().isWiki()) { - showWiki(ctx, app, a.getName(lang), - a.getDescription(lang)); + showWiki(ctx, app, a, lang); } else { String d = OsmAndFormatter.getAmenityDescriptionContent(app, a, false); SpannableString spannable = new SpannableString(d); @@ -358,21 +366,50 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon return typedvalueattr.resourceId; } - private static void showWiki(Context ctx, OsmandApplication app, String name, String content ) { + private static void showWiki(final Context ctx,final OsmandApplication app, final Amenity a, final String lang ) { final Dialog dialog = new Dialog(ctx, app.getSettings().isLightContent() ? R.style.OsmandLightTheme: R.style.OsmandDarkTheme); + String content = a.getDescription(lang); + final String title = a.getName(lang); LinearLayout ll = new LinearLayout(ctx); ll.setOrientation(LinearLayout.VERTICAL); - Toolbar tb = new Toolbar(ctx); - tb.setClickable(true); + + final Toolbar topBar = new Toolbar(ctx); + topBar.setClickable(true); Drawable back = app.getIconsCache().getIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha); - tb.setNavigationIcon(back); - tb.setTitle(name); - tb.setBackgroundColor(ctx.getResources().getColor(getResIdFromAttribute(ctx, R.attr.pstsTabBackground))); - tb.setTitleTextColor(ctx.getResources().getColor(getResIdFromAttribute(ctx, R.attr.pstsTextColor))); - tb.setNavigationOnClickListener(new View.OnClickListener() { + topBar.setNavigationIcon(back); + topBar.setTitle(title); + topBar.setBackgroundColor(ctx.getResources().getColor(getResIdFromAttribute(ctx, R.attr.pstsTabBackground))); + topBar.setTitleTextColor(ctx.getResources().getColor(getResIdFromAttribute(ctx, R.attr.pstsTextColor))); + String lng = a.getNameSelected(lang); + if(Algorithms.isEmpty(lng)) { + lng = "EN"; + } + final String langSelected = lng; + final Button bottomBar = new Button(ctx); + bottomBar.setText(R.string.read_full_article); + bottomBar.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + String article = "http://"+langSelected.toLowerCase()+".wikipedia.org/wiki/" + title.replace(' ', '_'); + Intent i = new Intent(Intent.ACTION_VIEW); + i.setData(Uri.parse(article)); + ctx.startActivity(i); + } + }); + MenuItem mi = topBar.getMenu().add(langSelected.toUpperCase()).setOnMenuItemClickListener(new OnMenuItemClickListener() { + + @Override + public boolean onMenuItemClick(final MenuItem item) { + showPopupLangMenu(ctx, topBar, app, a, dialog); + return true; + } + }); + MenuItemCompat.setShowAsAction(mi, MenuItem.SHOW_AS_ACTION_ALWAYS); + topBar.setNavigationOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { dialog.dismiss(); @@ -384,8 +421,11 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon wv.loadDataWithBaseURL(null, content, "text/html", "UTF-8", null); // wv.loadUrl(OsMoService.SIGN_IN_URL + app.getSettings().OSMO_DEVICE_KEY.get()); ScrollView scrollView = new ScrollView(ctx); - ll.addView(tb); - ll.addView(scrollView); + ll.addView(topBar); + LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 0); + lp.weight = 1; + ll.addView(scrollView, lp); + ll.addView(bottomBar, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); scrollView.addView(wv); dialog.setContentView(ll); wv.setFocusable(true); @@ -412,6 +452,27 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon } + protected static void showPopupLangMenu(final Context ctx, Toolbar tb, + final OsmandApplication app, final Amenity a, final Dialog dialog) { + final PopupMenu optionsMenu = new PopupMenu(ctx, tb, Gravity.RIGHT); + List names = a.getNames("en"); + for (final String n : names) { + String vn = FileNameTranslationHelper.getVoiceName(ctx, n); + MenuItem item = optionsMenu.getMenu().add(vn); + item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + dialog.dismiss(); + showWiki(ctx, app, a, n); + return true; + } + }); + } + optionsMenu.show(); + + } + + @Override public String getObjectDescription(Object o) { if (o instanceof Amenity) {