From 3887ad0636a45ac8d121a41b0c9717cbaea6b5b8 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 7 Jul 2014 12:04:24 +0300 Subject: [PATCH 1/3] fixed bug with navigation not continue after reaching point --- .../RoutePointsPlugin.java | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsPlugin.java b/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsPlugin.java index 36667e9a4e..d6bdf4bd0d 100644 --- a/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsPlugin.java @@ -51,6 +51,9 @@ public class RoutePointsPlugin extends OsmandPlugin { private RoutePointsLayer routePointsLayer; + private RoutePoint lastReachedPoint; + + public RoutePointsPlugin(OsmandApplication app) { ApplicationMode.regWidget("route_steps", ApplicationMode.CAR, ApplicationMode.DEFAULT); this.app = app; @@ -78,7 +81,10 @@ public class RoutePointsPlugin extends OsmandPlugin { btnY.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - currentRoute.navigateToNextPoint(true); + if (lastReachedPoint != null){ + lastReachedPoint.setDelivered(true); + lastReachedPoint = null; + } FrameLayout layout = (FrameLayout) mapActivity.getLayout(); layout.removeView(deliveredView); } @@ -89,7 +95,10 @@ public class RoutePointsPlugin extends OsmandPlugin { btnN.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - currentRoute.navigateToNextPoint(false); + if (lastReachedPoint != null){ + lastReachedPoint.setDelivered(false); + lastReachedPoint = null; + } FrameLayout layout = (FrameLayout) mapActivity.getLayout(); layout.removeView(deliveredView); } @@ -100,10 +109,16 @@ public class RoutePointsPlugin extends OsmandPlugin { @Override public boolean destinationReached() { if (currentRoute != null) { + if (currentRoute.currentPoints != null && !currentRoute.currentPoints.isEmpty()){ + lastReachedPoint = currentRoute.currentPoints.get(0); + } FrameLayout layout = (FrameLayout) mapActivity.getLayout(); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); params.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL; layout.addView(deliveredView, params); + //if it's possible to navigate to next point - navigation continues + return !currentRoute.navigateToNextPoint(); + } return true; @@ -463,20 +478,6 @@ public class RoutePointsPlugin extends OsmandPlugin { return null; } - public boolean navigateToNextPoint(boolean delivered) { - if (currentPoints.isEmpty()) { - return false; - } - - RoutePoint rp = currentPoints.get(0); - if (rp.isNextNavigate) { - rp.setDelivered(delivered); - return navigateToNextPoint(); - } - - return false; - } - public void saveGPXAsync() { new AsyncTask() { From 5b04bf969d73ae97593492729bdfdf8ebe3b79bd Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 7 Jul 2014 19:58:22 +0300 Subject: [PATCH 2/3] updated translation functionality for downloaded maps, tts etc. --- .../src/net/osmand/plus/OsmandSettings.java | 17 -- .../plus/activities/LocalIndexesActivity.java | 54 +---- .../activities/SettingsGeneralActivity.java | 5 +- .../plus/download/DownloadActivityType.java | 7 +- .../helpers/FileNameTranslationHelper.java | 195 ++++++++++++++++++ 5 files changed, 207 insertions(+), 71 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 1b50ed47d8..b9ef7cbfaf 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1746,23 +1746,6 @@ public class OsmandSettings { return false; } - public static String getVoiceName(Context ctx, String basename) { - try { - String nm = basename.replace('-', '_').replace(' ', '_'); - if (nm.endsWith("_tts") || nm.endsWith("-tts")) { - nm = nm.substring(0, nm.length() - 4); - } - Field f = R.string.class.getField("lang_"+nm); - if (f != null) { - Integer in = (Integer) f.get(null); - return ctx.getString(in); - } - } catch (Exception e) { - System.err.println(e.getMessage()); - } - return basename; - } - public enum DayNightMode { AUTO(R.string.daynight_mode_auto), DAY(R.string.daynight_mode_day), diff --git a/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java b/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java index 9571850ac4..99bd5cc0fd 100644 --- a/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java @@ -18,6 +18,7 @@ import net.osmand.plus.*; import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick; import net.osmand.plus.activities.LocalIndexHelper.LocalIndexType; import net.osmand.plus.download.IndexItem; +import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.util.Algorithms; import android.app.Activity; import android.app.AlertDialog; @@ -72,7 +73,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity { MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US); private ContextMenuAdapter optionsMenuAdapter; private ActionMode actionMode; - private OsmandRegions osmandRegions; + @SuppressWarnings("unchecked") @Override @@ -87,7 +88,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity { descriptionLoader = new LoadLocalIndexDescriptionTask(); listAdapter = new LocalIndexesAdapter(this); - osmandRegions = ((OsmandApplication) getApplication()).getResourceManager().getOsmandRegions(); + getExpandableListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { @@ -881,7 +882,8 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity { } TextView viewName = ((TextView) v.findViewById(R.id.local_index_name)); String mapDescr = getMapDescription(child.getFileName()); - String mapName = getMapName(child.getFileName()); + String mapName = FileNameTranslationHelper.getFileName(ctx, ((OsmandApplication) getApplication()).getResourceManager().getOsmandRegions(), child.getFileName()); + if (mapDescr.length() > 0){ viewName.setText(mapDescr + " - " + mapName); } else { @@ -1017,37 +1019,7 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity { return true; } - private String getMapName(String fileName){ - String mapname = getBasename(fileName); - String lc = mapname.toLowerCase(); - String std = getStandardMapName(ctx,lc); - if (std != null){ - return std; - } - - return osmandRegions.getLocaleName(mapname); - } - - private String getBasename(String fileName) { - if (fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)) { - return fileName.substring(0, fileName.length() - IndexConstants.EXTRA_ZIP_EXT.length()); - } - if (fileName.endsWith(IndexConstants.SQLITE_EXT)) { - return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length()).replace('_', ' '); - } - - int ls = fileName.lastIndexOf('-'); - if (ls >= 0) { - return fileName.substring(0, ls); - } else { - ls = fileName.lastIndexOf("."); - if (ls >= 0){ - return fileName.substring(0,ls); - } - } - return fileName; - } private String getMapDescription(String fileName){ int ls = fileName.lastIndexOf("."); @@ -1062,21 +1034,5 @@ public class LocalIndexesActivity extends OsmandExpandableListActivity { return ""; } - - private String getStandardMapName(Context ctx, String basename) { - if(basename.equals("world-ski")) { - return ctx.getString(R.string.index_item_world_ski); - } else if(basename.equals("world_altitude_correction_ww15mgh")) { - return ctx.getString(R.string.index_item_world_altitude_correction); - } else if(basename.equals("world_basemap")) { - return ctx.getString(R.string.index_item_world_basemap); - } else if(basename.equals("world_bitcoin_payments")) { - return ctx.getString(R.string.index_item_world_bitcoin_payments); - } else if(basename.equals("world_seamarks")) { - return ctx.getString(R.string.index_item_world_seamarks); - } - return null; - } - } } diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java index 89bcd35e86..bfd39290f9 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java @@ -23,6 +23,7 @@ import net.osmand.plus.R; import net.osmand.plus.Version; import net.osmand.plus.base.SuggestExternalDirectoryDialog; import net.osmand.plus.download.DownloadActivityType; +import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.render.NativeOsmandLibrary; import net.osmand.plus.voice.CommandPlayer; import net.osmand.render.RenderingRulesStorage; @@ -563,8 +564,8 @@ public class SettingsGeneralActivity extends SettingsBaseActivity { entrieValues[k] = OsmandSettings.VOICE_PROVIDER_NOT_USE; entries[k++] = getString(R.string.voice_not_use); for (String s : voiceFiles) { - entries[k] = (s.contains("tts") ? getString(R.string.ttsvoice) +" ":"") + - OsmandSettings.getVoiceName(this, s); + entries[k] = (s.contains("tts") ? getString(R.string.ttsvoice) +" ":"") + + FileNameTranslationHelper.getVoiceName(this, s); entrieValues[k] = s; k++; } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java index 6bccec5502..d0e6bea0dd 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java @@ -18,6 +18,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.Version; +import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.util.Algorithms; import org.xmlpull.v1.XmlPullParser; @@ -194,10 +195,10 @@ public class DownloadActivityType { if (this == VOICE_FILE) { if (fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)) { return ctx.getString(R.string.voice) + "\n" + - OsmandSettings.getVoiceName(ctx, getBasename(indexItem)); + FileNameTranslationHelper.getVoiceName(ctx, getBasename(indexItem)); } else if (fileName.endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) { - return ctx.getString(R.string.ttsvoice) + "\n" + - OsmandSettings.getVoiceName(ctx, getBasename(indexItem)); + return ctx.getString(R.string.ttsvoice) + "\n" + + FileNameTranslationHelper.getVoiceName(ctx, getBasename(indexItem)); } return getBasename(indexItem); } diff --git a/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java b/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java new file mode 100644 index 0000000000..1a4ce0e3f3 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java @@ -0,0 +1,195 @@ +package net.osmand.plus.helpers; + +import android.content.Context; +import net.osmand.IndexConstants; +import net.osmand.map.OsmandRegions; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; + +import java.lang.reflect.Field; + +/** + * Created by Barsik on 07.07.2014. + */ +public class FileNameTranslationHelper { + + public static String getFileName(Context ctx, OsmandRegions regions, String fileName) { + String basename = getBasename(fileName); + if (basename.endsWith("_wiki")) { //wiki files + String wikiName = getStandardLangName(ctx, basename.substring(0, basename.indexOf("_wiki"))); + String wikiWord = ctx.getString(R.string.amenity_type_osmwiki); + int index = wikiWord.indexOf("("); + if (index >= 0) { + //removing word in "()" from recourse file + return wikiWord.substring(0, index) + wikiName; + } + return ctx.getString(R.string.amenity_type_osmwiki) + " " + wikiName; + } else if (fileName.endsWith("tts")) { //tts files + return getVoiceName(ctx, fileName); + } else if (fileName.length() == 2) { //voice recorded files + try { + Field f = R.string.class.getField("lang_"+fileName); + if (f != null) { + Integer in = (Integer) f.get(null); + return ctx.getString(in); + } + } catch (Exception e) { + System.err.println(e.getMessage()); + } + } + + //if nothing else + String lc = basename.toLowerCase(); + String std = getStandardMapName(ctx, lc); + if (std != null) { + return std; + } + + if (regions != null) { + return regions.getLocaleName(basename); + } + + return null; + } + + public static String getVoiceName(Context ctx, String basename) { + try { + String nm = basename.replace('-', '_').replace(' ', '_'); + if (nm.endsWith("_tts") || nm.endsWith("-tts")) { + nm = nm.substring(0, nm.length() - 4); + } + Field f = R.string.class.getField("lang_"+nm); + if (f != null) { + Integer in = (Integer) f.get(null); + return ctx.getString(in); + } + } catch (Exception e) { + System.err.println(e.getMessage()); + } + return basename; + } + + private static String getBasename(String fileName) { + if (fileName.endsWith(IndexConstants.EXTRA_ZIP_EXT)) { + return fileName.substring(0, fileName.length() - IndexConstants.EXTRA_ZIP_EXT.length()); + } + if (fileName.endsWith(IndexConstants.SQLITE_EXT)) { + return fileName.substring(0, fileName.length() - IndexConstants.SQLITE_EXT.length()).replace('_', ' '); + } + + int ls = fileName.lastIndexOf('-'); + if (ls >= 0) { + return fileName.substring(0, ls); + } else { + ls = fileName.lastIndexOf("."); + if (ls >= 0) { + return fileName.substring(0, ls); + } + } + return fileName; + } + + private static String getStandardLangName(Context ctx, String filename) { + if (filename.equals("Croatian")) { + return ctx.getString(R.string.lang_hr); + } else if (filename.equals("Chinese")) { + return ctx.getString(R.string.lang_zh); + } else if (filename.equals("Portuguese")) { + return ctx.getString(R.string.lang_pt_br); + } else if (filename.equals("English")) { + return ctx.getString(R.string.lang_en); + } else if (filename.equals("Afrikaans") || filename.equals("Africaans")) { + return ctx.getString(R.string.lang_af); + } else if (filename.equals("Armenian")) { + return ctx.getString(R.string.lang_hy); + } else if (filename.equals("Basque")) { + return ctx.getString(R.string.lang_eu); + } else if (filename.equals("Belarusian")) { + return ctx.getString(R.string.lang_be); + } else if (filename.equals("Bosnian")) { + return ctx.getString(R.string.lang_bs); + } else if (filename.equals("Bulgarian")) { + return ctx.getString(R.string.lang_bg); + } else if (filename.equals("Catalan")) { + return ctx.getString(R.string.lang_ca); + } else if (filename.equals("Czech")) { + return ctx.getString(R.string.lang_cs); + } else if (filename.equals("Danish")) { + return ctx.getString(R.string.lang_da); + } else if (filename.equals("Dutch")) { + return ctx.getString(R.string.lang_nl); + } else if (filename.equals("Finnish")) { + return ctx.getString(R.string.lang_fi); + } else if (filename.equals("French")) { + return ctx.getString(R.string.lang_fr); + } else if (filename.equals("Georgian")) { + return ctx.getString(R.string.lang_ka); + } else if (filename.equals("German")) { + return ctx.getString(R.string.lang_de); + } else if (filename.equals("Greek")) { + return ctx.getString(R.string.lang_el); + } else if (filename.equals("Hebrew")) { + return ctx.getString(R.string.lang_iw); + } else if (filename.equals("Hindi")) { + return ctx.getString(R.string.lang_hi); + } else if (filename.equals("Hungarian")) { + return ctx.getString(R.string.lang_hu); + } else if (filename.equals("Indonesian")) { + return ctx.getString(R.string.lang_id); + } else if (filename.equals("Italian")) { + return ctx.getString(R.string.lang_it); + } else if (filename.equals("Japanese")) { + return ctx.getString(R.string.lang_ja); + } else if (filename.equals("Korean")) { + return ctx.getString(R.string.lang_ko); + } else if (filename.equals("Latvian")) { + return ctx.getString(R.string.lang_lv); + } else if (filename.equals("Lithuanian")) { + return ctx.getString(R.string.lang_lt); + } else if (filename.equals("Marathi")) { + return ctx.getString(R.string.lang_mr); + } else if (filename.equals("Norwegian")) { + return ctx.getString(R.string.lang_no); + } else if (filename.equals("Polish")) { + return ctx.getString(R.string.lang_pl); + } else if (filename.equals("Portuguese")) { + return ctx.getString(R.string.lang_pt); + } else if (filename.equals("Romanian")) { + return ctx.getString(R.string.lang_ro); + } else if (filename.equals("Russian")) { + return ctx.getString(R.string.lang_ru); + } else if (filename.equals("Slovak")) { + return ctx.getString(R.string.lang_sk); + } else if (filename.equals("Slovenian")) { + return ctx.getString(R.string.lang_sl); + } else if (filename.equals("Spanish")) { + return ctx.getString(R.string.lang_es); + } else if (filename.equals("Swedish")) { + return ctx.getString(R.string.lang_sv); + } else if (filename.equals("Turkish")) { + return ctx.getString(R.string.lang_tr); + } else if (filename.equals("Ukrainian")) { + return ctx.getString(R.string.lang_uk); + } else if (filename.equals("Vietnamese")) { + return ctx.getString(R.string.lang_vi); + } else if (filename.equals("Welsh")) { + return ctx.getString(R.string.lang_cy); + } + return null; + } + + private static String getStandardMapName(Context ctx, String basename) { + if (basename.equals("world-ski")) { + return ctx.getString(R.string.index_item_world_ski); + } else if (basename.equals("world_altitude_correction_ww15mgh")) { + return ctx.getString(R.string.index_item_world_altitude_correction); + } else if (basename.equals("world_basemap")) { + return ctx.getString(R.string.index_item_world_basemap); + } else if (basename.equals("world_bitcoin_payments")) { + return ctx.getString(R.string.index_item_world_bitcoin_payments); + } else if (basename.equals("world_seamarks")) { + return ctx.getString(R.string.index_item_world_seamarks); + } + return null; + } +} From 2c70301b844a14b3bc705eb6346ed4470b022212 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 7 Jul 2014 20:03:52 +0300 Subject: [PATCH 3/3] Refactored translation functionality. --- .../plus/download/DownloadActivityType.java | 17 +---------------- .../plus/helpers/FileNameTranslationHelper.java | 2 +- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java index d0e6bea0dd..d58f50971f 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java @@ -204,7 +204,7 @@ public class DownloadActivityType { } final String bn = getBasename(indexItem); final String lc = bn.toLowerCase(); - String std = getStandardMapName(ctx, lc); + String std = FileNameTranslationHelper.getStandardMapName(ctx, lc); if (std != null) { return std; } @@ -218,21 +218,6 @@ public class DownloadActivityType { return osmandRegions.getLocaleName(bn); } - private String getStandardMapName(Context ctx, String basename) { - if(basename.equals("world-ski")) { - return ctx.getString(R.string.index_item_world_ski); - } else if(basename.equals("world_altitude_correction_ww15mgh")) { - return ctx.getString(R.string.index_item_world_altitude_correction); - } else if(basename.equals("world_basemap")) { - return ctx.getString(R.string.index_item_world_basemap); - } else if(basename.equals("world_bitcoin_payments")) { - return ctx.getString(R.string.index_item_world_bitcoin_payments); - } else if(basename.equals("world_seamarks")) { - return ctx.getString(R.string.index_item_world_seamarks); - } - return null; - } - public String getTargetFileName(IndexItem item) { String fileName = item.fileName; // if(fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP) || diff --git a/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java b/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java index 1a4ce0e3f3..7f9f1eba0c 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/FileNameTranslationHelper.java @@ -178,7 +178,7 @@ public class FileNameTranslationHelper { return null; } - private static String getStandardMapName(Context ctx, String basename) { + public static String getStandardMapName(Context ctx, String basename) { if (basename.equals("world-ski")) { return ctx.getString(R.string.index_item_world_ski); } else if (basename.equals("world_altitude_correction_ww15mgh")) {