Add wikipedia new type download, add language switcher, add button to read whole article

This commit is contained in:
Victor Shcherb 2015-06-08 01:50:53 +02:00
parent a72f9c32cd
commit e49ca072f0
11 changed files with 168 additions and 18 deletions

View file

@ -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$

View file

@ -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<String> getNames(String defName) {
List<String> l = new ArrayList<String>();
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);

View file

@ -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
-->
<string name="read_full_article">Read full article</string>
<string name="download_wikipedia_item">Wikipedia</string>
<string name="local_indexes_cat_wiki">Wikipedia</string>
<string name="shared_string_show_details">Show details</string>
<string name="osm_edit_context_menu_delete">Delete OSM Edit</string>
<string name="rendering_value_disabled_name">Disabled</string>
@ -875,6 +878,7 @@
<string name="max_speed_none">none</string>
<string name="index_name_openmaps">OpenMaps EU</string>
<string name="download_hillshade_item">Hillshade</string>
<string name="download_wikipedia_maps">Wikipedia</string>
<string name="download_hillshade_maps">Hillshade overlays</string>
<string name="tip_recent_changes_1_1_2_t">Changes in 1.1.2:
\n\t* Audio/video plugin enhancement (photos with EXIF information)

View file

@ -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<LocalIndexInfo> 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<LocalIndexInfo> result, boolean backup, LoadLocalIndexTask loadTask, Map<String, String> 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);;

View file

@ -363,12 +363,16 @@ public class DownloadActivity extends BaseDownloadActivity {
public List<DownloadActivityType> createDownloadTypes() {
List<DownloadActivityType> items = new ArrayList<DownloadActivityType>();
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;
}

View file

@ -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";
}

View file

@ -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);

View file

@ -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 {

View file

@ -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){

View file

@ -595,6 +595,7 @@ public class ResourceManager {
ArrayList<File> files = new ArrayList<File>();
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);
}

View file

@ -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<String> 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) {