diff --git a/OsmAnd/res/xml/navigation_settings_new.xml b/OsmAnd/res/xml/navigation_settings_new.xml index 49125d8f49..dd1c6b0294 100644 --- a/OsmAnd/res/xml/navigation_settings_new.xml +++ b/OsmAnd/res/xml/navigation_settings_new.xml @@ -22,8 +22,9 @@ tools:icon="@drawable/ic_action_alert" /> map = sharedPreferences.getAll(); - for (String key : map.keySet()) { + public void migratePreferences() { + SharedPreferences globalSharedPreferences = (SharedPreferences) globalPreferences; + Map globalPrefsMap = globalSharedPreferences.getAll(); + for (String key : globalPrefsMap.keySet()) { OsmandPreference pref = getPreference(key); if (pref instanceof CommonPreference) { CommonPreference commonPreference = (CommonPreference) pref; if (!commonPreference.global) { List modes = commonPreference.general ? Collections.singletonList(ApplicationMode.DEFAULT) : ApplicationMode.allPossibleValues(); - boolean valueSaved = false; for (ApplicationMode mode : modes) { if (!commonPreference.isSetForMode(mode)) { - valueSaved = setPreference(key, map.get(key), mode) || valueSaved; + setPreference(key, globalPrefsMap.get(key), mode); } } - if (valueSaved) { - settingsAPI.edit(globalPreferences).remove(key).commit(); - } + } + } + } + SharedPreferences defaultProfilePreferences = (SharedPreferences) this.defaultProfilePreferences; + Map defaultPrefsMap = defaultProfilePreferences.getAll(); + for (String key : defaultPrefsMap.keySet()) { + OsmandPreference pref = getPreference(key); + if (pref instanceof CommonPreference) { + CommonPreference commonPreference = (CommonPreference) pref; + if (commonPreference.global && !commonPreference.isSet()) { + setPreference(key, defaultPrefsMap.get(key)); } } } @@ -1643,7 +1650,6 @@ public class OsmandSettings { public final OsmandPreference SHOW_NEARBY_FAVORITES = new BooleanPreference("show_nearby_favorites", false).makeProfile().cache(); public final OsmandPreference SHOW_NEARBY_POI = new BooleanPreference("show_nearby_poi", false).makeProfile().cache(); - public final OsmandPreference SPEAK_ROUTING_ALARMS = new BooleanPreference("speak_routing_alarms", true).makeProfile().cache(); public final OsmandPreference SPEAK_STREET_NAMES = new BooleanPreference("speak_street_names", true).makeProfile().cache(); public final CommonPreference SPEAK_TRAFFIC_WARNINGS = new BooleanPreference("speak_traffic_warnings", true).makeProfile().cache(); { @@ -3130,7 +3136,7 @@ public class OsmandSettings { public final OsmandPreference USE_OSM_LIVE_FOR_PUBLIC_TRANSPORT = new BooleanPreference("enable_osmc_public_transport", false).makeGlobal(); - public final OsmandPreference VOICE_MUTE = new BooleanPreference("voice_mute", false).makeGlobal(); + public final OsmandPreference VOICE_MUTE = new BooleanPreference("voice_mute", false).makeProfile().cache(); // for background service public final OsmandPreference MAP_ACTIVITY_ENABLED = new BooleanPreference("map_activity_enabled", false).makeGlobal(); diff --git a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java index e61dc78cd9..64ed3acfcb 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java @@ -403,11 +403,9 @@ public class ExternalApiHelper { resultCode = Activity.RESULT_OK; } } else if (API_CMD_MUTE_NAVIGATION.equals(cmd)) { - mapActivity.getMyApplication().getSettings().VOICE_MUTE.set(true); mapActivity.getRoutingHelper().getVoiceRouter().setMute(true); resultCode = Activity.RESULT_OK; } else if (API_CMD_UNMUTE_NAVIGATION.equals(cmd)) { - mapActivity.getMyApplication().getSettings().VOICE_MUTE.set(false); mapActivity.getRoutingHelper().getVoiceRouter().setMute(false); resultCode = Activity.RESULT_OK; } else if (API_CMD_RECORD_AUDIO.equals(cmd) diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavVoiceAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavVoiceAction.java index 7da8366bff..1e4eb81502 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavVoiceAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavVoiceAction.java @@ -23,16 +23,12 @@ public class NavVoiceAction extends QuickAction { @Override public void execute(MapActivity activity) { - - boolean voice = activity.getMyApplication().getSettings().VOICE_MUTE.get(); - - activity.getMyApplication().getSettings().VOICE_MUTE.set(!voice); - activity.getRoutingHelper().getVoiceRouter().setMute(!voice); + boolean mute = activity.getMyApplication().getSettings().VOICE_MUTE.get(); + activity.getMyApplication().getSettings().VOICE_MUTE.set(!mute); } @Override public void drawUI(ViewGroup parent, MapActivity activity) { - View view = LayoutInflater.from(parent.getContext()) .inflate(R.layout.quick_action_with_text, parent, false); @@ -44,7 +40,6 @@ public class NavVoiceAction extends QuickAction { @Override public String getActionText(OsmandApplication application) { - return application.getSettings().VOICE_MUTE.get() ? application.getString(R.string.quick_action_navigation_voice_off) : application.getString(R.string.quick_action_navigation_voice_on); @@ -52,7 +47,6 @@ public class NavVoiceAction extends QuickAction { @Override public boolean isActionWithSlash(OsmandApplication application) { - return !application.getSettings().VOICE_MUTE.get(); } } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 9e2113d18a..ee2994d7d4 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -1054,10 +1054,11 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener } private void createMuteSoundRoutingParameterButton(MapActivity mapActivity, final MuteSoundRoutingParameter parameter, final RouteMenuAppModes mode, LinearLayout optionsContainer) { + final ApplicationMode appMode = mapActivity.getRoutingHelper().getAppMode(); final int colorActive = ContextCompat.getColor(mapActivity, nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light); final int colorDisabled = ContextCompat.getColor(mapActivity, R.color.description_font_and_bottom_sheet_icons); String text = null; - final boolean active = !mapActivity.getRoutingHelper().getVoiceRouter().isMute(); + boolean active = !mapActivity.getRoutingHelper().getVoiceRouter().isMuteForMode(appMode); if (mode.parameters.size() <= 2) { text = mapActivity.getString(active ? R.string.shared_string_on : R.string.shared_string_off); } @@ -1067,7 +1068,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener OsmandApplication app = getApp(); if (app != null) { app.getRoutingOptionsHelper().switchSound(); - boolean active = !app.getRoutingHelper().getVoiceRouter().isMute(); + boolean active = !app.getRoutingHelper().getVoiceRouter().isMuteForMode(appMode); String text = app.getString(active ? R.string.shared_string_on : R.string.shared_string_off); Drawable itemDrawable = app.getUIUtilities().getIcon(active ? parameter.getActiveIconId() : parameter.getDisabledIconId(), nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java index 4232ec40e3..3242b89383 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java @@ -133,22 +133,22 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { } private BaseBottomSheetItem createMuteSoundItem(final LocalRoutingParameter optionsItem) { + boolean active = !routingHelper.getVoiceRouter().isMuteForMode(applicationMode); final BottomSheetItemWithCompoundButton[] muteSoundItem = new BottomSheetItemWithCompoundButton[1]; muteSoundItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() - .setChecked(!routingHelper.getVoiceRouter().isMute()) + .setChecked(active) .setDescription(getString(R.string.voice_announcements)) - .setIcon(getContentIcon((routingHelper.getVoiceRouter().isMute() ? optionsItem.getDisabledIconId() : optionsItem.getActiveIconId()))) + .setIcon(getContentIcon(active ? optionsItem.getActiveIconId() : optionsItem.getDisabledIconId())) .setTitle(getString(R.string.shared_string_sound)) .setLayoutId(R.layout.bottom_sheet_item_with_descr_and_switch_56dp) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { routingOptionsHelper.addNewRouteMenuParameter(applicationMode, optionsItem); - boolean mt = !routingHelper.getVoiceRouter().isMute(); - settings.VOICE_MUTE.set(mt); - routingHelper.getVoiceRouter().setMute(mt); - muteSoundItem[0].setChecked(!routingHelper.getVoiceRouter().isMute()); - muteSoundItem[0].setIcon(getContentIcon((routingHelper.getVoiceRouter().isMute() ? optionsItem.getDisabledIconId() : optionsItem.getActiveIconId()))); + boolean active = !routingHelper.getVoiceRouter().isMuteForMode(applicationMode); + routingHelper.getVoiceRouter().setMuteForMode(applicationMode, active); + muteSoundItem[0].setChecked(!active); + muteSoundItem[0].setIcon(getContentIcon(!active ? optionsItem.getActiveIconId() : optionsItem.getDisabledIconId())); updateMenu(); } }) diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java index bc1cda9b6f..5c90b98de2 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java @@ -95,9 +95,9 @@ public class RoutingOptionsHelper { public void switchSound() { RoutingHelper routingHelper = app.getRoutingHelper(); - boolean mt = !routingHelper.getVoiceRouter().isMute(); - settings.VOICE_MUTE.set(mt); - routingHelper.getVoiceRouter().setMute(mt); + ApplicationMode mode = routingHelper.getAppMode(); + boolean mute = !routingHelper.getVoiceRouter().isMuteForMode(mode); + routingHelper.getVoiceRouter().setMuteForMode(mode, mute); } public void switchMusic() { diff --git a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java index ef092063b1..a05ebe5a40 100644 --- a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java +++ b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java @@ -49,7 +49,6 @@ public class VoiceRouter { protected static CommandPlayer player; protected final OsmandSettings settings; - private static boolean mute = false; private static int currentStatus = STATUS_UNKNOWN; private static boolean playedAndArriveAtTarget = false; private static float playGoAheadDist = 0; @@ -87,7 +86,6 @@ public class VoiceRouter { VoiceRouter(RoutingHelper router, final OsmandSettings settings) { this.router = router; this.settings = settings; - mute = settings.VOICE_MUTE.get(); } public void setPlayer(CommandPlayer player) { @@ -104,13 +102,21 @@ public class VoiceRouter { public CommandPlayer getPlayer() { return player; } - + public void setMute(boolean mute) { - this.mute = mute; + settings.VOICE_MUTE.set(mute); } - + + public void setMuteForMode(ApplicationMode mode, boolean mute) { + settings.VOICE_MUTE.setModeValue(mode, mute); + } + public boolean isMute() { - return mute; + return settings.VOICE_MUTE.get(); + } + + public boolean isMuteForMode(ApplicationMode mode) { + return settings.VOICE_MUTE.getModeValue(mode); } private CommandBuilder getNewCommandPlayerToPlay() { @@ -907,13 +913,11 @@ public class VoiceRouter { } private void play(CommandBuilder p) { - if (settings.SPEAK_ROUTING_ALARMS.get()) { - if (p != null) { - List played = p.play(); - notifyOnVoiceMessage(p.getListCommands(), played); - } else { - notifyOnVoiceMessage(Collections.EMPTY_LIST, Collections.EMPTY_LIST); - } + if (p != null) { + List played = p.play(); + notifyOnVoiceMessage(p.getListCommands(), played); + } else { + notifyOnVoiceMessage(Collections.EMPTY_LIST, Collections.EMPTY_LIST); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java b/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java index 2a27514ba0..697cb5c423 100644 --- a/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java @@ -4,6 +4,7 @@ import android.support.v7.preference.Preference; import android.support.v7.preference.SwitchPreferenceCompat; import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.settings.preferences.SwitchPreferenceEx; public class NavigationFragment extends BaseSettingsFragment { @@ -14,7 +15,7 @@ public class NavigationFragment extends BaseSettingsFragment { protected void setupPreferences() { Preference routeParameters = findPreference("route_parameters"); SwitchPreferenceCompat showRoutingAlarms = (SwitchPreferenceCompat) findPreference(settings.SHOW_ROUTING_ALARMS.getId()); - SwitchPreferenceCompat speakRoutingAlarms = (SwitchPreferenceCompat) findPreference(settings.SPEAK_ROUTING_ALARMS.getId()); + SwitchPreferenceCompat speakRoutingAlarms = (SwitchPreferenceCompat) findPreference(settings.VOICE_MUTE.getId()); SwitchPreferenceCompat turnScreenOn = (SwitchPreferenceCompat) findPreference(settings.TURN_SCREEN_ON_ENABLED.getId()); SwitchPreferenceEx animateMyLocation = (SwitchPreferenceEx) findPreference(settings.ANIMATE_MY_LOCATION.getId()); @@ -24,13 +25,31 @@ public class NavigationFragment extends BaseSettingsFragment { turnScreenOn.setIcon(getContentIcon(R.drawable.ic_action_turn_screen_on)); setupVehicleParametersPref(); - + speakRoutingAlarms.setChecked(!settings.VOICE_MUTE.getModeValue(getSelectedAppMode())); animateMyLocation.setDescription(getString(R.string.animate_my_location_desc)); } + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + String key = preference.getKey(); + if (settings.VOICE_MUTE.getId().equals(key) && newValue instanceof Boolean) { + settings.VOICE_MUTE.setModeValue(getSelectedAppMode(), !(Boolean) newValue); + updateMenu(); + return true; + } + return super.onPreferenceChange(preference, newValue); + } + private void setupVehicleParametersPref() { Preference vehicleParameters = findPreference("vehicle_parameters"); int iconRes = getSelectedAppMode().getIconRes(); vehicleParameters.setIcon(getContentIcon(iconRes)); } + + private void updateMenu() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getMapRouteInfoMenu().updateMenu(); + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java b/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java index 0d6204e4fb..ec9d28988c 100644 --- a/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/VoiceAnnouncesFragment.java @@ -20,6 +20,7 @@ import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.Version; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.helpers.FileNameTranslationHelper; @@ -41,10 +42,11 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { @Override public void onClick(View view) { ApplicationMode selectedMode = getSelectedAppMode(); - boolean checked = !settings.SPEAK_ROUTING_ALARMS.getModeValue(selectedMode); - settings.SPEAK_ROUTING_ALARMS.setModeValue(selectedMode, checked); + boolean checked = !settings.VOICE_MUTE.getModeValue(selectedMode); + settings.VOICE_MUTE.setModeValue(selectedMode, checked); updateToolbarSwitch(); - enableDisablePreferences(checked); + enableDisablePreferences(!checked); + updateMenu(); } }); } @@ -60,7 +62,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { if (view == null) { return; } - boolean checked = settings.SPEAK_ROUTING_ALARMS.getModeValue(getSelectedAppMode()); + boolean checked = !settings.VOICE_MUTE.getModeValue(getSelectedAppMode()); int color = checked ? getActiveProfileColor() : ContextCompat.getColor(app, R.color.preference_top_switch_off); View switchContainer = view.findViewById(R.id.toolbar_switch_container); @@ -88,7 +90,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { setupAudioStreamGuidancePref(); setupInterruptMusicPref(); } - enableDisablePreferences(settings.SPEAK_ROUTING_ALARMS.getModeValue(getSelectedAppMode())); + enableDisablePreferences(!settings.VOICE_MUTE.getModeValue(getSelectedAppMode())); } private void setupSpeedLimitExceedPref() { @@ -218,6 +220,13 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment { bld.show(); } + private void updateMenu() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getMapRouteInfoMenu().updateMenu(); + } + } + @Override public boolean onPreferenceChange(Preference preference, Object newValue) { String prefId = preference.getKey();