From 73fd7b333cdfce3768b67e3e495b1bb048e7a37a Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 10 Feb 2020 18:53:33 +0200 Subject: [PATCH 01/13] Fix #8266 --- .../plus/routing/RouteCalculationResult.java | 84 +++++++++++++++---- 1 file changed, 68 insertions(+), 16 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index 2faaca1a3a..f93886ac3d 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -35,6 +35,7 @@ public class RouteCalculationResult { private static double distanceClosestToIntermediate = 3000; private static double distanceThresholdToIntermediate = 25; + private static double DISTANCE_THRESHOLD_TO_INTRODUCE_FIRST_AND_LAST_POINTS = 50; // could not be null and immodifiable! private final List locations; private final List directions; @@ -692,22 +693,9 @@ public class RouteCalculationResult { private static void introduceFirstPointAndLastPoint(List locations, List directions, List segs, Location start, LatLon end, OsmandApplication ctx) { - if (!locations.isEmpty() && locations.get(0).distanceTo(start) > 50) { - // add start point - locations.add(0, start); - if(segs != null) { - segs.add(0, segs.get(0)); - } - if (directions != null && !directions.isEmpty()) { - for (RouteDirectionInfo i : directions) { - i.routePointOffset++; - } - RouteDirectionInfo info = new RouteDirectionInfo(directions.get(0).getAverageSpeed(), - TurnType.straight()); - info.routePointOffset = 0; - // info.setDescriptionRoute(ctx.getString( R.string.route_head));//; //$NON-NLS-1$ - directions.add(0, info); - } + boolean firstPointIntroduced = introduceFirstPoint(locations, directions, segs, start); + boolean lastPointIntroduced = introduceLastPoint(locations, directions, segs, end); + if (firstPointIntroduced || lastPointIntroduced) { checkForDuplicatePoints(locations, directions); } RouteDirectionInfo lastDirInf = directions.size() > 0 ? directions.get(directions.size() - 1) : null; @@ -742,6 +730,70 @@ public class RouteCalculationResult { } } + private static boolean introduceFirstPoint(List locations, List directions, + List segs, Location start) { + if (!locations.isEmpty() && locations.get(0).distanceTo(start) > DISTANCE_THRESHOLD_TO_INTRODUCE_FIRST_AND_LAST_POINTS) { + // add start point + locations.add(0, start); + if (segs != null) { + segs.add(0, segs.get(0)); + } + if (directions != null && !directions.isEmpty()) { + for (RouteDirectionInfo i : directions) { + i.routePointOffset++; + } + RouteDirectionInfo info = new RouteDirectionInfo(directions.get(0).getAverageSpeed(), TurnType.straight()); + info.routePointOffset = 0; + // info.setDescriptionRoute(ctx.getString( R.string.route_head));//; //$NON-NLS-1$ + directions.add(0, info); + } + return true; + } + return false; + } + + private static boolean introduceLastPoint(List locations, List directions, + List segs, LatLon end) { + if (!locations.isEmpty()) { + Location lastFoundLocation = locations.get(locations.size() - 1); + + Location endLocation = new Location(lastFoundLocation.getProvider()); + endLocation.setLatitude(end.getLatitude()); + endLocation.setLongitude(end.getLongitude()); + + if (lastFoundLocation.distanceTo(endLocation) > DISTANCE_THRESHOLD_TO_INTRODUCE_FIRST_AND_LAST_POINTS) { + if (directions != null && !directions.isEmpty()) { + if (locations.size() > 2) { + int type = TurnType.C; + Location prevLast = locations.get(locations.size() - 2); + float lastBearing = prevLast.bearingTo(lastFoundLocation); + float bearingToEnd = lastFoundLocation.bearingTo(endLocation); + double diff = MapUtils.degreesDiff(lastBearing, bearingToEnd); + if (Math.abs(diff) > 10) { + if (Math.abs(diff) < 60) { + type = diff > 0 ? TurnType.TSLL : TurnType.TSLR; + } else { + type = diff > 0 ? TurnType.TL : TurnType.TR; + } + } + + RouteDirectionInfo lastDirInf = directions.get(directions.size() - 1); + RouteDirectionInfo info = new RouteDirectionInfo(lastDirInf != null ? lastDirInf.getAverageSpeed() : 1, TurnType.valueOf(type, false)); + info.routePointOffset = locations.size() - 1; + directions.add(info); + } + } + // add end point + locations.add(endLocation); + if (segs != null) { + segs.add(segs.get(segs.size() - 1)); + } + return true; + } + } + return false; + } + /** * PREPARATION * At the end always update listDistance local vars and time From c534802bc374187bd20115400d504c445b42268f Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 11 Feb 2020 10:28:06 +0200 Subject: [PATCH 02/13] Fix profile creation --- .../plus/settings/ProfileAppearanceFragment.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index a99bb97b16..7f35a744bd 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -96,6 +96,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { private View saveButton; private boolean isBaseProfileImported; + private boolean isNewProfile; @Override public void onCreate(Bundle savedInstanceState) { @@ -118,7 +119,6 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { profile.routeService = baseModeForNewProfile.getRouteService(); profile.locationIcon = baseModeForNewProfile.getLocationIcon(); profile.navigationIcon = baseModeForNewProfile.getNavigationIcon(); - onAppModeChanged(ApplicationMode.valueOfStringKey(baseModeForNewProfile.getStringKey(), null)); } else { profile.stringKey = getSelectedAppMode().getStringKey(); profile.parent = getSelectedAppMode().getParent(); @@ -148,6 +148,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { changedProfile.locationIcon = profile.locationIcon; changedProfile.navigationIcon = profile.navigationIcon; } + isNewProfile = ApplicationMode.valueOfStringKey(changedProfile.stringKey, null) == null; } private String createNonDuplicateName(String oldName) { @@ -189,7 +190,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { findPreference(SELECT_ICON).setIconSpaceReserved(false); findPreference(SELECT_LOCATION_ICON).setIconSpaceReserved(false); findPreference(SELECT_NAV_ICON).setIconSpaceReserved(false); - if (getSelectedAppMode().equals(ApplicationMode.DEFAULT)) { + if (getSelectedAppMode().equals(ApplicationMode.DEFAULT) && !isNewProfile) { findPreference(SELECT_ICON).setVisible(false); findPreference(ICON_ITEMS).setVisible(false); } @@ -228,10 +229,9 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { if (getActivity() != null) { hideKeyboard(); if (isChanged()) { - boolean isNew = ApplicationMode.valueOfStringKey(changedProfile.stringKey, null) == null; - if (saveProfile(isNew)) { + if (saveProfile()) { profile = changedProfile; - if (isNew) { + if (isNewProfile) { ProfileAppearanceFragment.this.dismiss(); BaseSettingsFragment.showInstance(getMapActivity(), SettingsScreenType.CONFIGURE_PROFILE, ApplicationMode.valueOfStringKey(changedProfile.stringKey, null)); @@ -645,7 +645,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { } } - private boolean saveProfile(boolean isNew) { + private boolean saveProfile() { if (changedProfile.name.replace(" ", "").length() < 1) { if (getActivity() != null) { createWarningDialog(getActivity(), @@ -653,7 +653,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { } return false; } - if (isNew) { + if (isNewProfile) { ApplicationMode.ApplicationModeBuilder builder = ApplicationMode .createCustomMode(changedProfile.parent, changedProfile.stringKey, app) .setIconResName(ProfileIcons.getResStringByResId(changedProfile.iconRes)) From c80f0ebf86274a1ec5df91988581ad4013a33f14 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 11 Feb 2020 11:47:10 +0200 Subject: [PATCH 03/13] Add edit online sources. --- .../src/net/osmand/plus/SQLiteTileSource.java | 58 ++++++++++++++----- .../download/ui/LocalIndexesFragment.java | 6 +- .../rastermaps/OsmandRasterMapsPlugin.java | 41 +++++++++---- 3 files changed, 80 insertions(+), 25 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java b/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java index b6ca8f5527..0fd47b6452 100644 --- a/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java +++ b/OsmAnd/src/net/osmand/plus/SQLiteTileSource.java @@ -25,10 +25,14 @@ import java.util.List; public class SQLiteTileSource implements ITileSource { - public static final String EXT = IndexConstants.SQLITE_EXT; private static final Log LOG = PlatformUtil.getLog(SQLiteTileSource.class); - + private static final String MAXZOOM_FIELD = "maxzoom"; + private static final String MINZOOM_FIELD = "minzoom"; + private static final String ELLIPSOID_FIELD = "ellipsoid"; + private static final String URL_FIELD = "url"; + private static final String EXPIREMINUTES_FIELD = "expireminutes"; + private ITileSource base; private String urlTemplate = null; private String name; @@ -163,7 +167,7 @@ public class SQLiteTileSource implements ITileSource { if(cursor.moveToFirst()) { String[] columnNames = cursor.getColumnNames(); List list = Arrays.asList(columnNames); - int url = list.indexOf("url"); + int url = list.indexOf(URL_FIELD); if(url != -1) { String template = cursor.getString(url); if(!Algorithms.isEmpty(template)){ @@ -192,7 +196,7 @@ public class SQLiteTileSource implements ITileSource { timeSupported = hasTimeColumn(); addInfoColumn("timecolumn", timeSupported? "yes" : "no"); } - int expireminutes = list.indexOf("expireminutes"); + int expireminutes = list.indexOf(EXPIREMINUTES_FIELD); this.expirationTimeMillis = -1; if(expireminutes != -1) { int minutes = (int) cursor.getInt(expireminutes); @@ -200,14 +204,14 @@ public class SQLiteTileSource implements ITileSource { this.expirationTimeMillis = minutes * 60 * 1000l; } } else { - addInfoColumn("expireminutes", "0"); + addInfoColumn(EXPIREMINUTES_FIELD, "0"); } int tsColumn = list.indexOf("tilesize"); this.tileSizeSpecified = tsColumn != -1; if(tileSizeSpecified) { this.tileSize = (int) cursor.getInt(tsColumn); } - int ellipsoid = list.indexOf("ellipsoid"); + int ellipsoid = list.indexOf(ELLIPSOID_FIELD); if(ellipsoid != -1) { int set = (int) cursor.getInt(ellipsoid); if(set == 1){ @@ -225,15 +229,14 @@ public class SQLiteTileSource implements ITileSource { if(randomsId != -1) { this.randoms = cursor.getString(randomsId); this.randomsArray = TileSourceTemplate.buildRandomsArray(this.randoms); - } //boolean inversiveInfoZoom = tnumbering != -1 && "BigPlanet".equals(cursor.getString(tnumbering)); boolean inversiveInfoZoom = inversiveZoom; - int mnz = list.indexOf("minzoom"); + int mnz = list.indexOf(MINZOOM_FIELD); if(mnz != -1) { minZoom = (int) cursor.getInt(mnz); } - int mxz = list.indexOf("maxzoom"); + int mxz = list.indexOf(MAXZOOM_FIELD); if(mxz != -1) { maxZoom = (int) cursor.getInt(mxz); } @@ -251,10 +254,37 @@ public class SQLiteTileSource implements ITileSource { return db; } + public void updateFromTileSourceTemplate(TileSourceTemplate r) { + if (!onlyReadonlyAvailable) { + int maxZoom = r.getMaximumZoomSupported(); + int minZoom = r.getMinimumZoomSupported(); + if (inversiveZoom) { + int mnz = minZoom; + minZoom = 17 - maxZoom; + maxZoom = 17 - mnz; + } + if (getUrlTemplate() != null && !getUrlTemplate().equals(r.getUrlTemplate())) { + db.execSQL("update info set " + URL_FIELD + " = '" + r.getUrlTemplate() + "'"); + } + if (r.getMinimumZoomSupported() != minZoom) { + db.execSQL("update info set " + MINZOOM_FIELD + " = '" + minZoom + "'"); + } + if (r.getMaximumZoomSupported() != maxZoom) { + db.execSQL("update info set " + MAXZOOM_FIELD + " = '" + maxZoom + "'"); + } + if (r.isEllipticYTile() != isEllipticYTile()) { + db.execSQL("update info set " + ELLIPSOID_FIELD + " = '" + (r.isEllipticYTile() ? 1 : 0) + "'"); + } + if (r.getExpirationTimeMinutes() != getExpirationTimeMinutes()) { + db.execSQL("update info set " + EXPIREMINUTES_FIELD + " = '" + r.getExpirationTimeMinutes() + "'"); + } + } + } + private void addInfoColumn(String columnName, String value) { - if(!onlyReadonlyAvailable) { - db.execSQL("alter table info add column "+columnName+" TEXT"); - db.execSQL("update info set "+columnName+" = '"+value+"'"); + if (!onlyReadonlyAvailable) { + db.execSQL("alter table info add column " + columnName + " TEXT"); + db.execSQL("update info set " + columnName + " = '" + value + "'"); } } @@ -517,7 +547,9 @@ public class SQLiteTileSource implements ITileSource { return referer; } - + public String getUrlTemplate() { + return urlTemplate; + } } diff --git a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java index 3d59779e6b..ec394ed36d 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java @@ -23,6 +23,7 @@ import net.osmand.map.TileSourceManager; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.ItemClickListener; import net.osmand.plus.ContextMenuItem; +import net.osmand.plus.SQLiteTileSource; import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; @@ -252,7 +253,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement getDownloadActivity().reloadLocalIndexes(); return true; } - }, info.getName()); + }, info.getFileName()); } else if (resId == R.string.local_index_mi_restore) { new LocalIndexOperationTask(getDownloadActivity(), listAdapter, LocalIndexOperationTask.RESTORE_OPERATION).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, info); } else if (resId == R.string.shared_string_delete) { @@ -1237,7 +1238,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement } }); if (info.getType() == LocalIndexType.TILES_DATA - && (info.getAttachedObject() instanceof TileSourceManager.TileSourceTemplate)) { + && ((info.getAttachedObject() instanceof TileSourceManager.TileSourceTemplate) + || (info.getAttachedObject() instanceof SQLiteTileSource))) { item = optionsMenu.getMenu().add(R.string.shared_string_edit) .setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark)); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java index 51928d38ef..3b109485fb 100644 --- a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java @@ -36,6 +36,7 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.OsmandSettings.LayerTransparencySeekbarMode; import net.osmand.plus.R; +import net.osmand.plus.SQLiteTileSource; import net.osmand.plus.UiUtilities; import net.osmand.plus.Version; import net.osmand.plus.activities.DownloadTilesDialog; @@ -478,10 +479,11 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { t.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } - public static void defineNewEditLayer(final Activity activity, final ResultMatcher resultMatcher, String editedLayerName) { + public static void defineNewEditLayer(final Activity activity, final ResultMatcher resultMatcher, final String editedLayerName) { final OsmandApplication app = (OsmandApplication) activity.getApplication(); final OsmandSettings settings = app.getSettings(); - final Map entriesMap = settings.getTileSourceEntries(false); + final Map entriesMap = settings.getTileSourceEntries(true); + final SQLiteTileSource[] sqLiteTileSource = new SQLiteTileSource[1]; boolean nightMode = isNightMode(activity, app); final int dp8 = AndroidUtils.dpToPx(app, 8f); int textColorPrimary = ContextCompat.getColor(app, nightMode ? R.color.text_color_primary_dark : R.color.text_color_primary_light); @@ -512,10 +514,25 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { ); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); existing.setAdapter(adapter); + TileSourceTemplate template; if (editedLayerName != null) { - File f = ((OsmandApplication) activity.getApplication()).getAppPath( - IndexConstants.TILES_INDEX_DIR + editedLayerName); - TileSourceTemplate template = TileSourceManager.createTileSourceTemplate(f); + if (!editedLayerName.endsWith(IndexConstants.SQLITE_EXT)) { + File f = ((OsmandApplication) activity.getApplication()).getAppPath( + IndexConstants.TILES_INDEX_DIR + editedLayerName); + template = TileSourceManager.createTileSourceTemplate(f); + } else { + List knownTemplates = TileSourceManager.getKnownSourceTemplates(); + File tPath = app.getAppPath(IndexConstants.TILES_INDEX_DIR); + File dir = new File(tPath, editedLayerName); + sqLiteTileSource[0] = new SQLiteTileSource(app, dir, knownTemplates); + sqLiteTileSource[0].couldBeDownloadedFromInternet(); + template = new TileSourceManager.TileSourceTemplate(sqLiteTileSource[0].getName(), + sqLiteTileSource[0].getUrlTemplate(), "png", sqLiteTileSource[0].getMaximumZoomSupported(), + sqLiteTileSource[0].getMinimumZoomSupported(), sqLiteTileSource[0].getTileSize(), + sqLiteTileSource[0].getBitDensity(), 32000); + template.setExpirationTimeMinutes(sqLiteTileSource[0].getExpirationTimeMinutes()); + template.setEllipticYTile(sqLiteTileSource[0].isEllipticYTile()); + } if (template != null) { result[0] = template.copy(); updateTileSourceEditView(result[0], name, urlToLoad, minZoom, maxZoom, expire, elliptic); @@ -558,11 +575,15 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { r.setEllipticYTile(elliptic.isChecked()); r.setUrlToLoad(urlToLoad.getText().toString().equals("") ? null : urlToLoad.getText().toString().replace("{$x}", "{1}") .replace("{$y}", "{2}").replace("{$z}", "{0}")); - if (r.getName().length() > 0) { - if (settings.installTileSource(r)) { - Toast.makeText(activity, activity.getString(R.string.edit_tilesource_successfully, r.getName()), - Toast.LENGTH_SHORT).show(); - resultMatcher.publish(r); + if (sqLiteTileSource[0] != null) { + sqLiteTileSource[0].updateFromTileSourceTemplate(r); + } else { + if (r.getName().length() > 0) { + if (settings.installTileSource(r)) { + Toast.makeText(activity, activity.getString(R.string.edit_tilesource_successfully, r.getName()), + Toast.LENGTH_SHORT).show(); + resultMatcher.publish(r); + } } } } catch (RuntimeException e) { From 0566232711609eb2f7bb22903859d220afbe7da0 Mon Sep 17 00:00:00 2001 From: veliymolfar Date: Tue, 11 Feb 2020 12:23:32 +0200 Subject: [PATCH 04/13] status widget remove animation / change appearance --- OsmAnd-telegram/res/values/strings.xml | 1 + .../telegram/helpers/ShowLocationHelper.kt | 30 +++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/OsmAnd-telegram/res/values/strings.xml b/OsmAnd-telegram/res/values/strings.xml index 4c4347e03d..a9105619fc 100644 --- a/OsmAnd-telegram/res/values/strings.xml +++ b/OsmAnd-telegram/res/values/strings.xml @@ -1,5 +1,6 @@ + ERR Last update from Telegram: %1$s Last response: %1$s Last update from Telegram: %1$s ago diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt index adf59d90c9..d618c0f626 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt @@ -49,10 +49,10 @@ class ShowLocationHelper(private val app: TelegramApplication) { private const val STATUS_WIDGET_MENU_ICON = "widget_location_sharing_night" private const val STATUS_WIDGET_MENU_ICON_OLD = "ic_action_relative_bearing" private const val STATUS_WIDGET_ICON_OLD = "widget_relative_bearing_day" - private const val STATUS_WIDGET_ANIM_ICON_DAY = "anim_widget_location_sharing_day" - private const val STATUS_WIDGET_ANIM_ICON_NIGHT = "anim_widget_location_sharing_night" - private const val STATUS_WIDGET_ON_ANIM_ICON_DAY = "anim_widget_location_sharing_on_day" - private const val STATUS_WIDGET_ON_ANIM_ICON_NIGHT = "anim_widget_location_sharing_on_night" + private const val STATUS_WIDGET_ICON_DAY = "widget_location_sharing_day" + private const val STATUS_WIDGET_ICON_NIGHT = "widget_location_sharing_night" + private const val STATUS_WIDGET_ON_ICON_DAY = "widget_location_sharing_on_day" + private const val STATUS_WIDGET_ON_ICON_NIGHT = "widget_location_sharing_on_night" private const val STATUS_WIDGET_OFF_ICON_DAY = "widget_location_sharing_off_day" private const val STATUS_WIDGET_OFF_ICON_NIGHT = "widget_location_sharing_off_night" @@ -232,21 +232,27 @@ class ShowLocationHelper(private val app: TelegramApplication) { STATUS_WIDGET_MENU_ICON_OLD } val text = when { - time > 0L -> { - iconDay = STATUS_WIDGET_ANIM_ICON_DAY - iconNight = STATUS_WIDGET_ANIM_ICON_NIGHT + time > 0L && isSending -> { + iconDay = STATUS_WIDGET_ON_ICON_DAY + iconNight = STATUS_WIDGET_ON_ICON_NIGHT + val diffTime = (System.currentTimeMillis() - time) / 1000 + OsmandFormatter.getFormattedDurationForWidget(diffTime) + } + time > 0L && !isSending -> { + iconDay = STATUS_WIDGET_ICON_DAY + iconNight = STATUS_WIDGET_ICON_NIGHT val diffTime = (System.currentTimeMillis() - time) / 1000 OsmandFormatter.getFormattedDurationForWidget(diffTime) } time == 0L && isSending -> { - iconDay = STATUS_WIDGET_ON_ANIM_ICON_DAY - iconNight = STATUS_WIDGET_ON_ANIM_ICON_NIGHT + iconDay = STATUS_WIDGET_ON_ICON_DAY + iconNight = STATUS_WIDGET_ON_ICON_NIGHT app.getString(R.string.shared_string_ok) } time == 0L && !isSending -> { - iconDay = STATUS_WIDGET_ANIM_ICON_DAY - iconNight = STATUS_WIDGET_ANIM_ICON_NIGHT - app.getString(R.string.shared_string_ok) + iconDay = STATUS_WIDGET_ICON_DAY + iconNight = STATUS_WIDGET_ICON_NIGHT + app.getString(R.string.shared_string_error_short) } else -> { iconDay = STATUS_WIDGET_OFF_ICON_DAY From 973fc013aadd4f92c21e8741c5eae440a7ff9f39 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 11 Feb 2020 12:48:20 +0200 Subject: [PATCH 05/13] Fix #8304 --- .../main/java/net/osmand/router/GeneralRouter.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java b/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java index d8e54ecaf5..c825aeb1d9 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java @@ -135,12 +135,9 @@ public class GeneralRouter implements VehicleRouter { for (int i = 0; i < objectAttributes.length; i++) { objectAttributes[i] = new RouteAttributeContext(parent.objectAttributes[i], params); } - allowPrivate = params.containsKey(ALLOW_PRIVATE) && parseSilentBoolean(params.get(ALLOW_PRIVATE), false) ; + allowPrivate = params.containsKey(ALLOW_PRIVATE) && parseSilentBoolean(params.get(ALLOW_PRIVATE), false); shortestRoute = params.containsKey(USE_SHORTEST_WAY) && parseSilentBoolean(params.get(USE_SHORTEST_WAY), false); - heightObstacles = params.containsKey(USE_HEIGHT_OBSTACLES) && parseSilentBoolean(params.get(USE_HEIGHT_OBSTACLES), false); - if(shortestRoute) { - maxSpeed = Math.min(CAR_SHORTEST_DEFAULT_SPEED, maxSpeed); - } + heightObstacles = params.containsKey(USE_HEIGHT_OBSTACLES) && parseSilentBoolean(params.get(USE_HEIGHT_OBSTACLES), false); if (params.containsKey(DEFAULT_SPEED)) { defaultSpeed = parseSilentFloat(params.get(DEFAULT_SPEED), defaultSpeed); } @@ -150,8 +147,10 @@ public class GeneralRouter implements VehicleRouter { if (params.containsKey(MAX_SPEED)) { maxSpeed = parseSilentFloat(params.get(MAX_SPEED), maxSpeed); } + if (shortestRoute) { + maxSpeed = Math.min(CAR_SHORTEST_DEFAULT_SPEED, maxSpeed); + } initCaches(); - } public GeneralRouter(GeneralRouterProfile profile, Map attributes) { From 49ef3b3500f971e25eae2518c12313e1a6233e60 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 11 Feb 2020 13:16:41 +0200 Subject: [PATCH 06/13] Add disable edit online sources without url. --- .../src/net/osmand/plus/download/ui/LocalIndexesFragment.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java index ec394ed36d..135291eb46 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java @@ -1239,7 +1239,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement }); if (info.getType() == LocalIndexType.TILES_DATA && ((info.getAttachedObject() instanceof TileSourceManager.TileSourceTemplate) - || (info.getAttachedObject() instanceof SQLiteTileSource))) { + || ((info.getAttachedObject() instanceof SQLiteTileSource) + && ((SQLiteTileSource) info.getAttachedObject()).couldBeDownloadedFromInternet()))) { item = optionsMenu.getMenu().add(R.string.shared_string_edit) .setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark)); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { From 791f8ad065d9f2fcf6e5d49c3bcef09f2b898576 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 11 Feb 2020 13:34:48 +0200 Subject: [PATCH 07/13] Add icons: Keep both, Map style, Replace --- OsmAnd/res/drawable/ic_action_keep_both.xml | 15 ++++++++ OsmAnd/res/drawable/ic_action_map_style.xml | 20 +++++++++++ OsmAnd/res/drawable/ic_action_replace.xml | 40 +++++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 OsmAnd/res/drawable/ic_action_keep_both.xml create mode 100644 OsmAnd/res/drawable/ic_action_map_style.xml create mode 100644 OsmAnd/res/drawable/ic_action_replace.xml diff --git a/OsmAnd/res/drawable/ic_action_keep_both.xml b/OsmAnd/res/drawable/ic_action_keep_both.xml new file mode 100644 index 0000000000..a3348d9bfc --- /dev/null +++ b/OsmAnd/res/drawable/ic_action_keep_both.xml @@ -0,0 +1,15 @@ + + + + diff --git a/OsmAnd/res/drawable/ic_action_map_style.xml b/OsmAnd/res/drawable/ic_action_map_style.xml new file mode 100644 index 0000000000..fa4726be62 --- /dev/null +++ b/OsmAnd/res/drawable/ic_action_map_style.xml @@ -0,0 +1,20 @@ + + + + + diff --git a/OsmAnd/res/drawable/ic_action_replace.xml b/OsmAnd/res/drawable/ic_action_replace.xml new file mode 100644 index 0000000000..6d426ef84b --- /dev/null +++ b/OsmAnd/res/drawable/ic_action_replace.xml @@ -0,0 +1,40 @@ + + + + + + + + + From ebc25edaed88e1203a375161e138ab0f6e97c890 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 11 Feb 2020 15:17:26 +0200 Subject: [PATCH 08/13] Fix #7694 dismiss the recorded track without saving. --- OsmAnd/res/values/strings.xml | 3 ++- .../osmand/plus/activities/SavingTrackHelper.java | 11 +++++------ .../plus/monitoring/OsmandMonitoringPlugin.java | 15 +++++++++------ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index eb85f2626e..05a85ae427 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,7 +11,8 @@ Thx - Hardy --> - + Clear recorded data + • Profiles: now you can change order, set icon for map, change all setting for base profiles and restore them back to defaults\n\n • Added exit number in the navigation\n\n • Reworked plugin settings\n\n diff --git a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java index c00fa94337..20416c72b0 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java @@ -247,18 +247,18 @@ public class SavingTrackHelper extends SQLiteOpenHelper { } } } + clearRecordedData(warnings.isEmpty()); + return new SaveGpxResult(warnings, filenames); + } - if (warnings.isEmpty()) { + public void clearRecordedData(boolean isWarningEmpty) { + if (isWarningEmpty) { SQLiteDatabase db = getWritableDatabase(); if (db != null) { try { if (db.isOpen()) { - // remove all from db db.execSQL("DELETE FROM " + TRACK_NAME + " WHERE " + TRACK_COL_DATE + " <= ?", new Object[]{System.currentTimeMillis()}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ db.execSQL("DELETE FROM " + POINT_NAME + " WHERE " + POINT_COL_DATE + " <= ?", new Object[]{System.currentTimeMillis()}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - // delete all - // db.execSQL("DELETE FROM " + TRACK_NAME + " WHERE 1 = 1", new Object[] { }); //$NON-NLS-1$ //$NON-NLS-2$ - // db.execSQL("DELETE FROM " + POINT_NAME + " WHERE 1 = 1", new Object[] { }); //$NON-NLS-1$ //$NON-NLS-2$ } } finally { db.close(); @@ -274,7 +274,6 @@ public class SavingTrackHelper extends SQLiteOpenHelper { currentTrack.getModifiablePointsToDisplay().clear(); currentTrack.getModifiableGpxFile().modifiedTime = System.currentTimeMillis(); prepareCurrentTrackForRecording(); - return new SaveGpxResult(warnings, filenames); } public Map collectRecordedData() { diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java index 0b8e57720a..1009ea771e 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java @@ -310,6 +310,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { } if (app.getSavingTrackHelper().hasDataToSave()) { items.add(R.string.save_current_track); + items.add(R.string.clear_recorded_data); } String[] strings = new String[items.size()]; for (int i = 0; i < strings.length; i++) { @@ -326,6 +327,8 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { if (app.getLocationProvider().checkGPSEnabled(activity)) { startGPXMonitoring(activity, showTrackSelection); } + } else if (item == R.string.clear_recorded_data) { + app.getSavingTrackHelper().clearRecordedData(true); } else if(item == R.string.gpx_monitoring_stop) { stopRecording(); } else if(item == R.string.gpx_start_new_segment) { @@ -338,12 +341,12 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { showIntervalChooseDialog(activity, app.getString(R.string.live_monitoring_interval) + " : %s", app.getString(R.string.save_track_to_gpx_globally), SECONDS, MINUTES, null, vs, showTrackSelection, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - settings.LIVE_MONITORING_INTERVAL.set(vs.value); - settings.LIVE_MONITORING.set(true); - } - }); + @Override + public void onClick(DialogInterface dialog, int which) { + settings.LIVE_MONITORING_INTERVAL.set(vs.value); + settings.LIVE_MONITORING.set(true); + } + }); } if (monitoringControl != null) { monitoringControl.updateInfo(null); From c066e737fe72258d1f19f79d16bab278c31c7cfa Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 11 Feb 2020 16:50:13 +0200 Subject: [PATCH 09/13] Fix #8269 --- OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java | 2 ++ OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index d869b22eff..fe6d1336f1 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -1557,6 +1557,8 @@ public class GPXUtilities { serializer.endTag(null, "wpt"); //$NON-NLS-1$ } + writeExtensions(serializer, file); + serializer.endTag(null, "gpx"); //$NON-NLS-1$ serializer.endDocument(); serializer.flush(); diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 2c98608e76..6eda756137 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -1119,7 +1119,7 @@ public class OsmandAidlApi { @SuppressLint("StaticFieldLeak") private void finishGpxImport(boolean destinationExists, File destination, String color, boolean show) { - int col = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColor( + final int col = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColor( app.getRendererRegistry().getCurrentSelectedRenderer(), color); if (!destinationExists) { GpxDataItem gpxDataItem = new GpxDataItem(destination, col); @@ -1145,6 +1145,9 @@ public class OsmandAidlApi { @Override protected void onPostExecute(GPXFile gpx) { if (gpx.error == null) { + if (col != -1) { + gpx.setColor(col); + } selectedGpx.setGpxFile(gpx, app); refreshMap(); } From c58ff85926c1cc42be5aea61d9aea2266fec8a5c Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 11 Feb 2020 17:17:27 +0200 Subject: [PATCH 10/13] Add new colors for live tracks --- OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt | 2 +- .../src/net/osmand/telegram/helpers/ShowLocationHelper.kt | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt index cb7f9ae6a8..bb1a6ee37d 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/TelegramSettings.kt @@ -207,7 +207,7 @@ class TelegramSettings(private val app: TelegramApplication) { fun updateLiveTrack(userId: Int, chatId: Long, deviceName: String, enable: Boolean) { val tracksInfo = liveTracksInfo.toMutableList() if (enable) { - val colorIndex = if (tracksInfo.size > 0) (tracksInfo.last().colorIndex + 1) % ShowLocationHelper.GPX_COLORS_COUNT else 0 + val colorIndex = if (tracksInfo.size > 0) (tracksInfo.last().colorIndex + 1) % ShowLocationHelper.GPX_COLORS.size else 0 tracksInfo.add(LiveTrackInfo(userId, chatId, deviceName, colorIndex)) } else { tracksInfo.removeAll { it.userId == userId && it.chatId == chatId && it.deviceName == deviceName } diff --git a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt index adf59d90c9..c2c665d6b2 100644 --- a/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt +++ b/OsmAnd-telegram/src/net/osmand/telegram/helpers/ShowLocationHelper.kt @@ -43,8 +43,6 @@ class ShowLocationHelper(private val app: TelegramApplication) { const val LIVE_TRACKS_DIR = "livetracks" - const val GPX_COLORS_COUNT = 10 - private const val STATUS_WIDGET_ID = "status_widget" private const val STATUS_WIDGET_MENU_ICON = "widget_location_sharing_night" private const val STATUS_WIDGET_MENU_ICON_OLD = "ic_action_relative_bearing" @@ -57,9 +55,9 @@ class ShowLocationHelper(private val app: TelegramApplication) { private const val STATUS_WIDGET_OFF_ICON_NIGHT = "widget_location_sharing_off_night" val GPX_COLORS = arrayOf( - "red", "orange", "lightblue", "blue", "purple", + "red", "orange", "lightblue", "blue", "purple", "pink", "translucent_red", "translucent_orange", "translucent_lightblue", - "translucent_blue", "translucent_purple" + "translucent_blue", "translucent_purple", "translucent_pink" ) } From a907d30b3b894f65d15b056be658bd53f4a3b053 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 11 Feb 2020 17:17:49 +0100 Subject: [PATCH 11/13] Move out dialog to activity --- .../net/osmand/plus/OsmandApplication.java | 3 +- .../osmand/plus/activities/MapActivity.java | 69 --------------- .../activities/actions/OsmAndDialogs.java | 87 ++++++++++++++++++- .../MapRouteInfoMenu.java | 3 +- .../RouteOptionsBottomSheet.java | 3 +- .../RoutingOptionsHelper.java | 6 +- 6 files changed, 95 insertions(+), 76 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 7f729ca523..1fa59571b7 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -46,6 +46,7 @@ import net.osmand.plus.activities.DayNightHelper; import net.osmand.plus.activities.ExitActivity; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SavingTrackHelper; +import net.osmand.plus.activities.actions.OsmAndDialogs; import net.osmand.plus.api.SQLiteAPI; import net.osmand.plus.api.SQLiteAPIImpl; import net.osmand.plus.base.MapViewTrackingUtilities; @@ -465,7 +466,7 @@ public class OsmandApplication extends MultiDexApplication { if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) { if (warningNoneProvider && voiceProvider == null) { if (uiContext instanceof MapActivity) { - ((MapActivity) uiContext).showVoiceProviderDialog(applicationMode, applyAllModes); + OsmAndDialogs.showVoiceProviderDialog((MapActivity) uiContext, applicationMode, applyAllModes); } } } else { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 8de45d0011..e775297667 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -1090,75 +1090,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven new XMasDialogFragment().show(getSupportFragmentManager(), XMasDialogFragment.TAG); } - public void showVoiceProviderDialog(final ApplicationMode applicationMode, final boolean applyAllModes) { - boolean nightMode = app.getDaynightHelper().isNightModeForMapControls(); - final RoutingOptionsHelper routingOptionsHelper = app.getRoutingOptionsHelper(); - final AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(this, nightMode)); - final String[] firstSelectedVoiceProvider = new String[1]; - - View view = UiUtilities.getInflater(this, nightMode).inflate(R.layout.select_voice_first, null); - - ((ImageView) view.findViewById(R.id.icon)) - .setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_volume_up, settings.isLightContent())); - - view.findViewById(R.id.spinner).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(final View v) { - routingOptionsHelper.selectVoiceGuidance(MapActivity.this, new CallbackWithObject() { - @Override - public boolean processResult(String result) { - boolean acceptableValue = !RoutePreferencesMenu.MORE_VALUE.equals(firstSelectedVoiceProvider[0]); - if (acceptableValue) { - ((TextView) v.findViewById(R.id.selectText)) - .setText(routingOptionsHelper.getVoiceProviderName(v.getContext(), result)); - firstSelectedVoiceProvider[0] = result; - } - return acceptableValue; - } - }, applicationMode); - } - }); - - ((ImageView) view.findViewById(R.id.dropDownIcon)) - .setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_arrow_drop_down, settings.isLightContent())); - - builder.setCancelable(true); - builder.setNegativeButton(R.string.shared_string_cancel, null); - builder.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (!Algorithms.isEmpty(firstSelectedVoiceProvider[0])) { - routingOptionsHelper.applyVoiceProvider(MapActivity.this, firstSelectedVoiceProvider[0], applyAllModes); - if (OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(firstSelectedVoiceProvider[0])) { - settings.VOICE_MUTE.setModeValue(applicationMode, true); - } else { - settings.VOICE_MUTE.setModeValue(applicationMode, false); - } - } - } - }); - builder.setNeutralButton(R.string.shared_string_do_not_use, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - if (applyAllModes) { - muteVoiceForAllProfiles(); - } else { - settings.VOICE_PROVIDER.setModeValue(applicationMode, OsmandSettings.VOICE_PROVIDER_NOT_USE); - settings.VOICE_MUTE.setModeValue(applicationMode, true); - } - } - }); - - builder.setView(view); - builder.show(); - } - - private void muteVoiceForAllProfiles() { - for (ApplicationMode mode : ApplicationMode.allPossibleValues()) { - settings.VOICE_PROVIDER.setModeValue(mode, OsmandSettings.VOICE_PROVIDER_NOT_USE); - settings.VOICE_MUTE.setModeValue(mode, true); - } - } private void dismissSecondSplashScreen() { if (SecondSplashScreenFragment.VISIBLE) { diff --git a/OsmAnd/src/net/osmand/plus/activities/actions/OsmAndDialogs.java b/OsmAnd/src/net/osmand/plus/activities/actions/OsmAndDialogs.java index 76c13a358d..8f299ced53 100644 --- a/OsmAnd/src/net/osmand/plus/activities/actions/OsmAndDialogs.java +++ b/OsmAnd/src/net/osmand/plus/activities/actions/OsmAndDialogs.java @@ -5,7 +5,23 @@ import java.util.Map; import android.app.Activity; import android.app.Dialog; +import android.content.DialogInterface; import android.os.Bundle; +import android.support.v7.app.AlertDialog; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +import net.osmand.CallbackWithObject; +import net.osmand.plus.ApplicationMode; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu; +import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper; +import net.osmand.util.Algorithms; public class OsmAndDialogs { @@ -24,7 +40,76 @@ public class OsmAndDialogs { action.prepareDialog(activity, args, dlg); } } - + + + public static void showVoiceProviderDialog(final MapActivity activity, final ApplicationMode applicationMode, final boolean applyAllModes) { + OsmandApplication app = activity.getMyApplication(); + final OsmandSettings settings = app.getSettings(); + boolean nightMode = app.getDaynightHelper().isNightModeForMapControls(); + final RoutingOptionsHelper routingOptionsHelper = app.getRoutingOptionsHelper(); + final AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(activity, nightMode)); + final String[] firstSelectedVoiceProvider = new String[1]; + + View view = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.select_voice_first, null); + + ((ImageView) view.findViewById(R.id.icon)) + .setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_volume_up, settings.isLightContent())); + + view.findViewById(R.id.spinner).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(final View v) { + routingOptionsHelper.selectVoiceGuidance(activity, new CallbackWithObject() { + @Override + public boolean processResult(String result) { + boolean acceptableValue = !RoutePreferencesMenu.MORE_VALUE.equals(firstSelectedVoiceProvider[0]); + if (acceptableValue) { + ((TextView) v.findViewById(R.id.selectText)) + .setText(routingOptionsHelper.getVoiceProviderName(v.getContext(), result)); + firstSelectedVoiceProvider[0] = result; + } + return acceptableValue; + } + }, applicationMode); + } + }); + + ((ImageView) view.findViewById(R.id.dropDownIcon)) + .setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_arrow_drop_down, settings.isLightContent())); + + builder.setCancelable(true); + builder.setNegativeButton(R.string.shared_string_cancel, null); + builder.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (!Algorithms.isEmpty(firstSelectedVoiceProvider[0])) { + routingOptionsHelper.applyVoiceProvider(activity, firstSelectedVoiceProvider[0], applyAllModes); + if (OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(firstSelectedVoiceProvider[0])) { + settings.VOICE_MUTE.setModeValue(applicationMode, true); + } else { + settings.VOICE_MUTE.setModeValue(applicationMode, false); + } + } + } + }); + builder.setNeutralButton(R.string.shared_string_do_not_use, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + if (applyAllModes) { + for (ApplicationMode mode : ApplicationMode.allPossibleValues()) { + //if (!settings.VOICE_PROVIDER.isSetForMode(mode)) { + settings.VOICE_PROVIDER.setModeValue(mode, OsmandSettings.VOICE_PROVIDER_NOT_USE); + settings.VOICE_MUTE.setModeValue(mode, true); + //} + } + } + settings.VOICE_PROVIDER.setModeValue(applicationMode, OsmandSettings.VOICE_PROVIDER_NOT_USE); + settings.VOICE_MUTE.setModeValue(applicationMode, true); + } + }); + + builder.setView(view); + builder.show(); + } public static void registerDialogAction(OsmAndAction action) { if(action.getDialogID() != 0) { diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 3455b10b40..be4ce89b3a 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -62,6 +62,7 @@ import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SettingsBaseActivity; import net.osmand.plus.activities.actions.AppModeDialog; +import net.osmand.plus.activities.actions.OsmAndDialogs; import net.osmand.plus.base.ContextMenuFragment.MenuState; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.GpxUiHelper; @@ -1098,7 +1099,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener if (app != null) { String voiceProvider = app.getSettings().VOICE_PROVIDER.getModeValue(appMode); if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) { - mapActivity.showVoiceProviderDialog(appMode, false); + OsmAndDialogs.showVoiceProviderDialog(mapActivity, appMode, false); } else { app.getRoutingOptionsHelper().switchSound(); } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java index 1e2d17777f..b7771fcf14 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java @@ -24,6 +24,7 @@ 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.activities.actions.OsmAndDialogs; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; @@ -182,7 +183,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { routingHelper.getVoiceRouter().setMuteForMode(applicationMode, active); String voiceProvider = app.getSettings().VOICE_PROVIDER.getModeValue(applicationMode); if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) { - mapActivity.showVoiceProviderDialog(applicationMode, false); + OsmAndDialogs.showVoiceProviderDialog(mapActivity, applicationMode, false); } else { muteSoundItem[0].setChecked(!active); muteSoundItem[0].setIcon(getContentIcon(!active ? optionsItem.getActiveIconId() : optionsItem.getDisabledIconId())); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java index 3ae9748fb1..eae018184e 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java @@ -187,13 +187,13 @@ public class RoutingOptionsHelper { public void applyVoiceProvider(MapActivity mapActivity, String provider, boolean applyAllModes) { OsmandApplication app = mapActivity.getMyApplication(); ApplicationMode selectedAppMode = app.getRoutingHelper().getAppMode(); + OsmandSettings.OsmandPreference VP = app.getSettings().VOICE_PROVIDER; if (applyAllModes) { for (ApplicationMode mode : ApplicationMode.allPossibleValues()) { - app.getSettings().VOICE_PROVIDER.setModeValue(mode, provider); + VP.setModeValue(mode, provider); } - } else { - app.getSettings().VOICE_PROVIDER.setModeValue(selectedAppMode, provider); } + VP.setModeValue(selectedAppMode, provider); app.initVoiceCommandPlayer(mapActivity, selectedAppMode, false, null, true, false, applyAllModes); } From eb7931621f3e9944bd4085a4e147b464b3374b70 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Tue, 11 Feb 2020 18:13:12 +0100 Subject: [PATCH 12/13] Update OsmandPlugin.java --- OsmAnd/src/net/osmand/plus/OsmandPlugin.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index 1d57820283..41e26a076d 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -251,7 +251,7 @@ public abstract class OsmandPlugin { boolean paid = plugin.isPaid(); if ((Version.isDeveloperVersion(app) || !Version.isProductionVersion(app)) && !paid) { // for test reasons - marketEnabled = false; + // marketEnabled = false; } if (pckg || (!marketEnabled && !paid)) { if (pckg && !app.getSettings().getPlugins().contains("-" + plugin.getId())) { @@ -681,4 +681,4 @@ public abstract class OsmandPlugin { pluginPreferences.add(preference); return preference; } -} \ No newline at end of file +} From f8720833c9354552a7f69b184544483861786770 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 11 Feb 2020 19:23:16 +0100 Subject: [PATCH 13/13] Simulate time-based only if there is time in GPX --- OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java index 7880b29d2e..1a7c69a1ae 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java @@ -112,23 +112,24 @@ public class OsmAndLocationSimulation { startStopRouteAnimation(ma, true, null); } - private void startAnimationThread(final OsmandApplication app, final List directions, final boolean useLocationTime, final float coeff) { + private void startAnimationThread(final OsmandApplication app, final List directions, final boolean locTime, final float coeff) { final float time = 1.5f; routeAnimation = new Thread() { @Override public void run() { Location current = directions.isEmpty() ? null : new Location(directions.remove(0)); - + boolean useLocationTime = locTime && current.getTime() != 0; Location prev = current; long prevTime = current == null ? 0 : current.getTime(); float meters = metersToGoInFiveSteps(directions, current); if(current != null) { current.setProvider(OsmAndLocationProvider.SIMULATED_PROVIDER); } + while (!directions.isEmpty() && routeAnimation != null) { int timeout = (int) (time * 1000); float intervalTime = time; - if(useLocationTime) { + if (useLocationTime) { current = directions.remove(0); meters = current.distanceTo(prev); if (!directions.isEmpty()) {