diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index 9fe9abe44ff..e75b808b505 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -10,6 +10,8 @@
- For wording and consistency, please note https://docs.osmand.net/docs/technical/contributions/translating-osmand
Thx - Hardy
-->
+
+ Selected profile \"%s\"
Interpolation
Location interpolation percentage
Set the percentage of location interpolation during route navigation. This parameter reduces the lag of your location position on the map during animation.
diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/BaseSwitchAppModeAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/BaseSwitchAppModeAction.java
index 9a88dbe0440..21dd877eb3e 100644
--- a/OsmAnd/src/net/osmand/plus/quickaction/actions/BaseSwitchAppModeAction.java
+++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/BaseSwitchAppModeAction.java
@@ -1,9 +1,12 @@
package net.osmand.plus.quickaction.actions;
+import static net.osmand.plus.OsmAndConstants.UI_HANDLER_MAP_CONTROLS;
+
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
+import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
@@ -12,9 +15,11 @@
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
+import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
public abstract class BaseSwitchAppModeAction extends QuickAction {
+ private static final long CHANGE_PROFILE_DELAY = 3500;
public BaseSwitchAppModeAction(QuickActionType type) {
super(type);
@@ -29,16 +34,48 @@ public BaseSwitchAppModeAction(QuickAction quickAction) {
@StringRes
public abstract int getQuickActionDescription();
- @Override
- public void execute(@NonNull MapActivity mapActivity) {
+ private static ApplicationMode delayedSwitchProfile;
+ private static Toast delayedSwitchProfileToast;
+
+ public void delayedSwitchAppMode(@NonNull MapActivity mapActivity) {
OsmandSettings settings = mapActivity.getMyApplication().getSettings();
- if (shouldChangeForward()) {
- settings.switchAppModeToNext();
- } else {
- settings.switchAppModeToPrevious();
+ ApplicationMode appMode = settings.getApplicationMode();
+ boolean next = shouldChangeForward();
+
+ if (delayedSwitchProfile == null) {
+ delayedSwitchProfile = appMode;
+ }
+ delayedSwitchProfile = settings.getSwitchedAppMode(delayedSwitchProfile, next);
+ cancelDelayedToast();
+
+ String patternDelayedSwitch = mapActivity.getString(R.string.selected_delayed_profile);
+ String messageDelayedSwitch = String.format(patternDelayedSwitch, delayedSwitchProfile.toHumanString());
+ delayedSwitchProfileToast = Toast.makeText(mapActivity, messageDelayedSwitch, Toast.LENGTH_SHORT);
+ delayedSwitchProfileToast.show();
+
+ mapActivity.getMyApplication().runMessageInUIThreadAndCancelPrevious(UI_HANDLER_MAP_CONTROLS + 1, () -> {
+ if (delayedSwitchProfile != null && appMode != delayedSwitchProfile && settings.setApplicationMode(delayedSwitchProfile)) {
+ cancelDelayedToast();
+ String pattern = mapActivity.getString(R.string.application_profile_changed);
+ String message = String.format(pattern, delayedSwitchProfile.toHumanString());
+ mapActivity.getMyApplication().showShortToastMessage(message);
+ }
+ delayedSwitchProfileToast = null;
+ delayedSwitchProfile = null;
+ }, CHANGE_PROFILE_DELAY);
+ }
+
+ private void cancelDelayedToast(){
+ if (delayedSwitchProfileToast != null) {
+ delayedSwitchProfileToast.cancel();
}
}
+ @Override
+ public void execute(@NonNull MapActivity mapActivity) {
+ delayedSwitchAppMode(mapActivity);
+ }
+
@Override
public void drawUI(@NonNull ViewGroup parent, @NonNull MapActivity mapActivity) {
View view = LayoutInflater.from(parent.getContext())
diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java
index 9922b5ebf71..4ee64f2a873 100644
--- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java
+++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java
@@ -446,15 +446,7 @@ public boolean switchAppModeToPrevious() {
public boolean switchAppMode(boolean next) {
ApplicationMode appMode = getApplicationMode();
- List enabledModes = ApplicationMode.values(ctx);
- int indexOfCurrent = enabledModes.indexOf(appMode);
- int indexOfNext;
- if (next) {
- indexOfNext = indexOfCurrent < enabledModes.size() - 1 ? indexOfCurrent + 1 : 0;
- } else {
- indexOfNext = indexOfCurrent > 0 ? indexOfCurrent - 1 : enabledModes.size() - 1;
- }
- ApplicationMode nextAppMode = enabledModes.get(indexOfNext);
+ ApplicationMode nextAppMode = getSwitchedAppMode(appMode, next);
if (appMode != nextAppMode && setApplicationMode(nextAppMode)) {
String pattern = ctx.getString(R.string.application_profile_changed);
String message = String.format(pattern, nextAppMode.toHumanString());
@@ -464,6 +456,18 @@ public boolean switchAppMode(boolean next) {
return false;
}
+ public ApplicationMode getSwitchedAppMode(ApplicationMode selectedMode, boolean next) {
+ List enabledModes = ApplicationMode.values(ctx);
+ int indexOfCurrent = enabledModes.indexOf(selectedMode);
+ int indexOfNext;
+ if (next) {
+ indexOfNext = indexOfCurrent < enabledModes.size() - 1 ? indexOfCurrent + 1 : 0;
+ } else {
+ indexOfNext = indexOfCurrent > 0 ? indexOfCurrent - 1 : enabledModes.size() - 1;
+ }
+ return enabledModes.get(indexOfNext);
+ }
+
public boolean setApplicationMode(ApplicationMode appMode) {
return setApplicationMode(appMode, true);
}