Merge pull request #7986 from osmandapp/preference_fixes
Preference fixes
This commit is contained in:
commit
b656083b3e
12 changed files with 89 additions and 58 deletions
|
@ -22,8 +22,9 @@
|
|||
tools:icon="@drawable/ic_action_alert" />
|
||||
|
||||
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
|
||||
android:key="speak_routing_alarms"
|
||||
android:key="voice_mute"
|
||||
android:layout="@layout/preference_with_descr_dialog_and_switch"
|
||||
android:persistent="false"
|
||||
android:summary="@string/voice_announces_descr"
|
||||
android:title="@string/voice_announces"
|
||||
app:fragment="net.osmand.plus.settings.VoiceAnnouncesFragment"
|
||||
|
|
|
@ -769,7 +769,6 @@ public class OsmandAidlApi {
|
|||
public void onReceive(Context context, Intent intent) {
|
||||
MapActivity mapActivity = mapActivityRef.get();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.getMyApplication().getSettings().VOICE_MUTE.set(true);
|
||||
mapActivity.getRoutingHelper().getVoiceRouter().setMute(true);
|
||||
}
|
||||
}
|
||||
|
@ -784,7 +783,6 @@ public class OsmandAidlApi {
|
|||
public void onReceive(Context context, Intent intent) {
|
||||
MapActivity mapActivity = mapActivityRef.get();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.getMyApplication().getSettings().VOICE_MUTE.set(false);
|
||||
mapActivity.getRoutingHelper().getVoiceRouter().setMute(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -190,8 +190,9 @@ public class AppInitializer implements IProgress {
|
|||
app.getSettings().BILLING_PURCHASE_TOKENS_SENT.set("");
|
||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_2).commit();
|
||||
}
|
||||
if (prevAppVersion < VERSION_3_5 || Version.getAppVersion(app).equals("3.5.3")) {
|
||||
app.getSettings().migrateGlobalPrefsToProfile();
|
||||
if (prevAppVersion < VERSION_3_5 || Version.getAppVersion(app).equals("3.5.3")
|
||||
|| Version.getAppVersion(app).equals("3.5.4")) {
|
||||
app.getSettings().migratePreferences();
|
||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_5).commit();
|
||||
}
|
||||
startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
|
||||
|
|
|
@ -229,24 +229,31 @@ public class OsmandSettings {
|
|||
return globalPreferences != null && globalPreferences.getBoolean(SETTING_CUSTOMIZED_ID, false);
|
||||
}
|
||||
|
||||
public void migrateGlobalPrefsToProfile() {
|
||||
SharedPreferences sharedPreferences = (SharedPreferences) globalPreferences;
|
||||
Map<String, ?> map = sharedPreferences.getAll();
|
||||
for (String key : map.keySet()) {
|
||||
public void migratePreferences() {
|
||||
SharedPreferences globalSharedPreferences = (SharedPreferences) globalPreferences;
|
||||
Map<String, ?> globalPrefsMap = globalSharedPreferences.getAll();
|
||||
for (String key : globalPrefsMap.keySet()) {
|
||||
OsmandPreference pref = getPreference(key);
|
||||
if (pref instanceof CommonPreference) {
|
||||
CommonPreference commonPreference = (CommonPreference) pref;
|
||||
if (!commonPreference.global) {
|
||||
List<ApplicationMode> 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<String, ?> 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<Boolean> SHOW_NEARBY_FAVORITES = new BooleanPreference("show_nearby_favorites", false).makeProfile().cache();
|
||||
public final OsmandPreference<Boolean> SHOW_NEARBY_POI = new BooleanPreference("show_nearby_poi", false).makeProfile().cache();
|
||||
|
||||
public final OsmandPreference<Boolean> SPEAK_ROUTING_ALARMS = new BooleanPreference("speak_routing_alarms", true).makeProfile().cache();
|
||||
public final OsmandPreference<Boolean> SPEAK_STREET_NAMES = new BooleanPreference("speak_street_names", true).makeProfile().cache();
|
||||
public final CommonPreference<Boolean> SPEAK_TRAFFIC_WARNINGS = new BooleanPreference("speak_traffic_warnings", true).makeProfile().cache();
|
||||
{
|
||||
|
@ -3130,7 +3136,7 @@ public class OsmandSettings {
|
|||
|
||||
public final OsmandPreference<Boolean> USE_OSM_LIVE_FOR_PUBLIC_TRANSPORT = new BooleanPreference("enable_osmc_public_transport", false).makeGlobal();
|
||||
|
||||
public final OsmandPreference<Boolean> VOICE_MUTE = new BooleanPreference("voice_mute", false).makeGlobal();
|
||||
public final OsmandPreference<Boolean> VOICE_MUTE = new BooleanPreference("voice_mute", false).makeProfile().cache();
|
||||
|
||||
// for background service
|
||||
public final OsmandPreference<Boolean> MAP_ACTIVITY_ENABLED = new BooleanPreference("map_activity_enabled", false).makeGlobal();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
})
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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<String> played = p.play();
|
||||
notifyOnVoiceMessage(p.getListCommands(), played);
|
||||
} else {
|
||||
notifyOnVoiceMessage(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
|
||||
}
|
||||
if (p != null) {
|
||||
List<String> played = p.play();
|
||||
notifyOnVoiceMessage(p.getListCommands(), played);
|
||||
} else {
|
||||
notifyOnVoiceMessage(Collections.EMPTY_LIST, Collections.EMPTY_LIST);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue