diff --git a/OsmAnd/res/xml/configure_profile.xml b/OsmAnd/res/xml/configure_profile.xml index d86a80620f..9fb131486e 100644 --- a/OsmAnd/res/xml/configure_profile.xml +++ b/OsmAnd/res/xml/configure_profile.xml @@ -16,7 +16,7 @@ android:persistent="false" android:summary="@string/general_settings_profile_descr" android:title="@string/general_settings_2" - app:fragment="net.osmand.plus.settings.GeneralProfileSettingsFragment" + app:fragment="net.osmand.plus.settings.fragments.GeneralProfileSettingsFragment" tools:icon="@drawable/ic_action_settings" /> + app:fragment="net.osmand.plus.settings.fragments.CoordinatesFormatFragment" /> + app:fragment="net.osmand.plus.settings.fragments.MapDuringNavigationFragment" /> globalPrefsMap = globalSharedPreferences.getAll(); for (String key : globalPrefsMap.keySet()) { - OsmandPreference pref = getPreference(key); + OsmandPreference pref = settings.getPreference(key); if (pref instanceof CommonPreference) { - CommonPreference commonPreference = (CommonPreference) pref; - if (!commonPreference.global) { + CommonPreference commonPreference = (CommonPreference) pref; + if (!commonPreference.isGlobal()) { for (ApplicationMode mode : ApplicationMode.allPossibleValues()) { if (!commonPreference.isSetForMode(mode) && !commonPreference.hasDefaultValueForMode(mode)) { - setPreference(key, globalPrefsMap.get(key), mode); + settings.setPreference(key, globalPrefsMap.get(key), mode); } } } } } - SharedPreferences defaultProfilePreferences = (SharedPreferences) getProfilePreferences(ApplicationMode.DEFAULT); + SharedPreferences defaultProfilePreferences = (SharedPreferences) settings.getProfilePreferences(ApplicationMode.DEFAULT); Map defaultPrefsMap = defaultProfilePreferences.getAll(); for (String key : defaultPrefsMap.keySet()) { - OsmandPreference pref = getPreference(key); + OsmandPreference pref = settings.getPreference(key); if (pref instanceof CommonPreference) { - CommonPreference commonPreference = (CommonPreference) pref; - if (commonPreference.global && !commonPreference.isSet()) { - setPreference(key, defaultPrefsMap.get(key)); + CommonPreference commonPreference = (CommonPreference) pref; + if (commonPreference.isGlobal() && !commonPreference.isSet()) { + settings.setPreference(key, defaultPrefsMap.get(key)); } } } - for (OsmandPreference pref : generalPrefs) { + for (OsmandPreference pref : settings.getGeneralPrefs()) { if (pref instanceof CommonPreference) { - CommonPreference commonPref = (CommonPreference) pref; + CommonPreference commonPref = (CommonPreference) pref; Object defaultVal = commonPref.getModeValue(ApplicationMode.DEFAULT); for (ApplicationMode mode : ApplicationMode.allPossibleValues()) { if (!commonPref.isSetForMode(mode) && !commonPref.hasDefaultValueForMode(mode)) { - setPreference(commonPref.getId(), defaultVal, mode); + settings.setPreference(commonPref.getId(), defaultVal, mode); } } } } - String json = settingsAPI.getString(globalPreferences, "custom_app_profiles", ""); + String json = settings.getSettingsAPI().getString(settings.getGlobalPreferences(), "custom_app_profiles", ""); if (!Algorithms.isEmpty(json)) { Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); Type t = new TypeToken>() { @@ -252,22 +226,22 @@ class AppVersionUpgradeOnInit { List customProfiles = gson.fromJson(json, t); if (!Algorithms.isEmpty(customProfiles)) { for (ApplicationMode.ApplicationModeBean modeBean : customProfiles) { - ApplicationMode.ApplicationModeBuilder builder = ApplicationMode.fromModeBean(ctx, modeBean); - ApplicationMode.saveProfile(builder, ctx); + ApplicationMode.ApplicationModeBuilder builder = ApplicationMode.fromModeBean(app, modeBean); + ApplicationMode.saveProfile(builder, app); } } } } public void migrateEnumPreferences() { - for (OsmandPreference pref : registeredPreferences.values()) { + for (OsmandPreference pref : settings.getRegisteredPreferences().values()) { if (pref instanceof EnumStringPreference) { EnumStringPreference enumPref = (EnumStringPreference) pref; if (enumPref.isGlobal()) { - migrateEnumPref(enumPref, (SharedPreferences) globalPreferences); + migrateEnumPref(enumPref, (SharedPreferences) settings.getGlobalPreferences()); } else { for (ApplicationMode mode : ApplicationMode.allPossibleValues()) { - migrateEnumPref(enumPref, (SharedPreferences) getProfilePreferences(mode)); + migrateEnumPref(enumPref, (SharedPreferences) settings.getProfilePreferences(mode)); } } } @@ -278,15 +252,17 @@ class AppVersionUpgradeOnInit { Object value = sharedPreferences.getAll().get(enumPref.getId()); if (value instanceof Integer) { int enumIndex = (int) value; - if (enumIndex >= 0 && enumIndex < enumPref.values.length) { - Enum savedValue = enumPref.values[enumIndex]; + if (enumIndex >= 0 && enumIndex < enumPref.getValues().length) { + Enum savedValue = enumPref.getValues()[enumIndex]; enumPref.setValue(sharedPreferences, savedValue); } } } public void migrateHomeWorkParkingToFavorites() { - FavouritesDbHelper favorites = ctx.getFavorites(); + FavouritesDbHelper favorites = app.getFavorites(); + SettingsAPI settingsAPI = settings.getSettingsAPI(); + Object globalPreferences= settings.getGlobalPreferences(); LatLon homePoint = null; float lat = settingsAPI.getFloat(globalPreferences, "home_point_lat", 0); diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/BooleanAccessibilityPreference.java b/OsmAnd/src/net/osmand/plus/settings/backend/BooleanAccessibilityPreference.java index 7a796b6a6a..c376b6a99a 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/BooleanAccessibilityPreference.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/BooleanAccessibilityPreference.java @@ -4,30 +4,27 @@ import net.osmand.plus.ApplicationMode; class BooleanAccessibilityPreference extends BooleanPreference { - private OsmandSettings osmandSettings; - BooleanAccessibilityPreference(OsmandSettings osmandSettings, String id, boolean defaultValue) { - super(id, defaultValue); - this.osmandSettings = osmandSettings; + super(osmandSettings, id, defaultValue); } @Override public Boolean get() { - return osmandSettings.ctx.accessibilityEnabled() ? super.get() : getDefaultValue(); + return getContext().accessibilityEnabled() ? super.get() : getDefaultValue(); } @Override public Boolean getModeValue(ApplicationMode mode) { - return osmandSettings.ctx.accessibilityEnabledForMode(mode) ? super.getModeValue(mode) : getDefaultValue(); + return getContext().accessibilityEnabledForMode(mode) ? super.getModeValue(mode) : getDefaultValue(); } @Override public boolean set(Boolean obj) { - return osmandSettings.ctx.accessibilityEnabled() && super.set(obj); + return getContext().accessibilityEnabled() && super.set(obj); } @Override public boolean setModeValue(ApplicationMode mode, Boolean obj) { - return osmandSettings.ctx.accessibilityEnabledForMode(mode) && super.setModeValue(mode, obj); + return getContext().accessibilityEnabledForMode(mode) && super.setModeValue(mode, obj); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/BooleanPreference.java b/OsmAnd/src/net/osmand/plus/settings/backend/BooleanPreference.java index 3a1c0cd363..9a0c2a2391 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/BooleanPreference.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/BooleanPreference.java @@ -7,13 +7,13 @@ public class BooleanPreference extends CommonPreference { } @Override - protected Boolean getValue(Object prefs, Boolean defaultValue) { - return osmandSettings.settingsAPI.getBoolean(prefs, getId(), defaultValue); + public Boolean getValue(Object prefs, Boolean defaultValue) { + return getSettingsAPI().getBoolean(prefs, getId(), defaultValue); } @Override protected boolean setValue(Object prefs, Boolean val) { - return osmandSettings.settingsAPI.edit(prefs).putBoolean(getId(), val).commit(); + return getSettingsAPI().edit(prefs).putBoolean(getId(), val).commit(); } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/CommonPreference.java b/OsmAnd/src/net/osmand/plus/settings/backend/CommonPreference.java index 4e1e69f1b4..0a53139dc1 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/CommonPreference.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/CommonPreference.java @@ -1,6 +1,8 @@ package net.osmand.plus.settings.backend; import net.osmand.plus.ApplicationMode; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.api.SettingsAPI; import org.json.JSONException; import org.json.JSONObject; @@ -27,16 +29,27 @@ public abstract class CommonPreference extends PreferenceWithListener { } // Methods to possibly override - protected abstract T getValue(Object prefs, T defaultValue); + public abstract T getValue(Object prefs, T defaultValue); protected abstract boolean setValue(Object prefs, T val); public abstract T parseString(String s); protected String toString(T o) { - return o == null ? null : o.toString(); + return o == null ? null : o.toString(); } + protected SettingsAPI getSettingsAPI() { + return osmandSettings.getSettingsAPI(); + } + + protected ApplicationMode getApplicationMode() { + return osmandSettings.getApplicationMode(); + } + + protected OsmandApplication getContext() { + return osmandSettings.getContext(); + } // common methods diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/ContextMenuItemsPreference.java b/OsmAnd/src/net/osmand/plus/settings/backend/ContextMenuItemsPreference.java index a671d6141b..4e562f1aca 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/ContextMenuItemsPreference.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/ContextMenuItemsPreference.java @@ -3,25 +3,23 @@ package net.osmand.plus.settings.backend; import androidx.annotation.NonNull; public class ContextMenuItemsPreference extends CommonPreference { - private OsmandSettings osmandSettings; @NonNull private String idScheme; ContextMenuItemsPreference(OsmandSettings osmandSettings, String id, @NonNull String idScheme, @NonNull ContextMenuItemsSettings defValue) { - super(id, defValue); - this.osmandSettings = osmandSettings; + super(osmandSettings, id, defValue); this.idScheme = idScheme; } @Override - protected ContextMenuItemsSettings getValue(Object prefs, ContextMenuItemsSettings defaultValue) { - String s = osmandSettings.settingsAPI.getString(prefs, getId(), ""); + public ContextMenuItemsSettings getValue(Object prefs, ContextMenuItemsSettings defaultValue) { + String s = getSettingsAPI().getString(prefs, getId(), ""); return readValue(s); } @Override protected boolean setValue(Object prefs, ContextMenuItemsSettings val) { - return osmandSettings.settingsAPI.edit(prefs).putString(getId(), val.writeToJsonString(idScheme)).commit(); + return getSettingsAPI().edit(prefs).putString(getId(), val.writeToJsonString(idScheme)).commit(); } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/ContextMenuItemsSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/ContextMenuItemsSettings.java index 85046ba00a..822840a60e 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/ContextMenuItemsSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/ContextMenuItemsSettings.java @@ -1,7 +1,9 @@ package net.osmand.plus.settings.backend; +import net.osmand.PlatformUtil; import net.osmand.util.Algorithms; +import org.apache.commons.logging.Log; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -14,6 +16,9 @@ import java.util.List; import androidx.annotation.NonNull; public class ContextMenuItemsSettings implements Serializable { + + private static final Log LOG = PlatformUtil.getLog(ContextMenuItemsSettings.class.getName()); + private static final String HIDDEN = "hidden"; private static final String ORDER = "order"; private List hiddenIds = new ArrayList<>(); @@ -40,7 +45,7 @@ public class ContextMenuItemsSettings implements Serializable { JSONObject json = new JSONObject(jsonString); readFromJson(json, idScheme); } catch (JSONException e) { - OsmandSettings.LOG.error("Error converting to json string: " + e); + LOG.error("Error converting to json string: " + e); } } @@ -66,7 +71,7 @@ public class ContextMenuItemsSettings implements Serializable { writeToJson(json, idScheme); return json.toString(); } catch (JSONException e) { - OsmandSettings.LOG.error("Error converting to json string: " + e); + LOG.error("Error converting to json string: " + e); } return ""; } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/EnumStringPreference.java b/OsmAnd/src/net/osmand/plus/settings/backend/EnumStringPreference.java index d8d01e4091..5d03d3e556 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/EnumStringPreference.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/EnumStringPreference.java @@ -2,19 +2,17 @@ package net.osmand.plus.settings.backend; public class EnumStringPreference> extends CommonPreference { - private OsmandSettings osmandSettings; private final E[] values; EnumStringPreference(OsmandSettings osmandSettings, String id, E defaultValue, E[] values) { - super(id, defaultValue); - this.osmandSettings = osmandSettings; + super(osmandSettings, id, defaultValue); this.values = values; } @Override - protected E getValue(Object prefs, E defaultValue) { + public E getValue(Object prefs, E defaultValue) { try { - String name = osmandSettings.settingsAPI.getString(prefs, getId(), defaultValue.name()); + String name = getSettingsAPI().getString(prefs, getId(), defaultValue.name()); E value = parseString(name); return value != null ? value : defaultValue; } catch (ClassCastException ex) { @@ -24,8 +22,8 @@ public class EnumStringPreference> extends CommonPreference } @Override - protected boolean setValue(Object prefs, E val) { - return osmandSettings.settingsAPI.edit(prefs).putString(getId(), val.name()).commit(); + public boolean setValue(Object prefs, E val) { + return getSettingsAPI().edit(prefs).putString(getId(), val.name()).commit(); } @Override @@ -42,4 +40,8 @@ public class EnumStringPreference> extends CommonPreference } return null; } + + public E[] getValues() { + return values; + } } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/FloatPreference.java b/OsmAnd/src/net/osmand/plus/settings/backend/FloatPreference.java index 9c10a314f9..47ee4a24bd 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/FloatPreference.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/FloatPreference.java @@ -2,22 +2,18 @@ package net.osmand.plus.settings.backend; public class FloatPreference extends CommonPreference { - - private OsmandSettings osmandSettings; - FloatPreference(OsmandSettings osmandSettings, String id, float defaultValue) { - super(id, defaultValue); - this.osmandSettings = osmandSettings; + super(osmandSettings, id, defaultValue); } @Override - protected Float getValue(Object prefs, Float defaultValue) { - return osmandSettings.settingsAPI.getFloat(prefs, getId(), defaultValue); + public Float getValue(Object prefs, Float defaultValue) { + return getSettingsAPI().getFloat(prefs, getId(), defaultValue); } @Override protected boolean setValue(Object prefs, Float val) { - return osmandSettings.settingsAPI.edit(prefs).putFloat(getId(), val).commit(); + return getSettingsAPI().edit(prefs).putFloat(getId(), val).commit(); } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/ImpassableRoadsStorage.java b/OsmAnd/src/net/osmand/plus/settings/backend/ImpassableRoadsStorage.java index dacadbf149..1f890766c2 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/ImpassableRoadsStorage.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/ImpassableRoadsStorage.java @@ -11,12 +11,11 @@ import java.util.StringTokenizer; class ImpassableRoadsStorage extends SettingsMapPointsStorage { - private OsmandSettings osmandSettings; protected String roadsIdsKey; protected String appModeKey; public ImpassableRoadsStorage(OsmandSettings osmandSettings) { - this.osmandSettings = osmandSettings; + super(osmandSettings); pointsKey = OsmandSettings.IMPASSABLE_ROAD_POINTS; descriptionsKey = OsmandSettings.IMPASSABLE_ROADS_DESCRIPTIONS; roadsIdsKey = OsmandSettings.IMPASSABLE_ROADS_IDS; @@ -25,7 +24,7 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage { public List getRoadIds(int size) { List list = new ArrayList<>(); - String roadIds = osmandSettings.settingsAPI.getString(osmandSettings.globalPreferences, roadsIdsKey, ""); + String roadIds = getSettingsAPI().getString(getOsmandSettings().globalPreferences, roadsIdsKey, ""); if (roadIds.trim().length() > 0) { StringTokenizer tok = new StringTokenizer(roadIds, ","); while (tok.hasMoreTokens() && list.size() <= size) { @@ -40,7 +39,7 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage { public List getAppModeKeys(int size) { List list = new ArrayList<>(); - String roadIds = osmandSettings.settingsAPI.getString(osmandSettings.globalPreferences, appModeKey, ""); + String roadIds = getSettingsAPI().getString(getOsmandSettings().globalPreferences, appModeKey, ""); if (roadIds.trim().length() > 0) { StringTokenizer tok = new StringTokenizer(roadIds, ","); while (tok.hasMoreTokens() && list.size() <= size) { @@ -173,7 +172,7 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage { stringBuilder.append(","); } } - return osmandSettings.settingsAPI.edit(osmandSettings.globalPreferences) + return getSettingsAPI().edit(getOsmandSettings().globalPreferences) .putString(roadsIdsKey, stringBuilder.toString()) .commit(); } @@ -187,7 +186,7 @@ class ImpassableRoadsStorage extends SettingsMapPointsStorage { stringBuilder.append(","); } } - return osmandSettings.settingsAPI.edit(osmandSettings.globalPreferences) + return getSettingsAPI().edit(getOsmandSettings().globalPreferences) .putString(appModeKey, stringBuilder.toString()) .commit(); } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/IntPreference.java b/OsmAnd/src/net/osmand/plus/settings/backend/IntPreference.java index 3c040821b9..92e0b9071c 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/IntPreference.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/IntPreference.java @@ -2,22 +2,18 @@ package net.osmand.plus.settings.backend; class IntPreference extends CommonPreference { - - private OsmandSettings osmandSettings; - IntPreference(OsmandSettings osmandSettings, String id, int defaultValue) { - super(id, defaultValue); - this.osmandSettings = osmandSettings; + super(osmandSettings, id, defaultValue); } @Override - protected Integer getValue(Object prefs, Integer defaultValue) { - return osmandSettings.settingsAPI.getInt(prefs, getId(), defaultValue); + public Integer getValue(Object prefs, Integer defaultValue) { + return getSettingsAPI().getInt(prefs, getId(), defaultValue); } @Override protected boolean setValue(Object prefs, Integer val) { - return osmandSettings.settingsAPI.edit(prefs).putInt(getId(), val).commit(); + return getSettingsAPI().edit(prefs).putInt(getId(), val).commit(); } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/IntermediatePointsStorage.java b/OsmAnd/src/net/osmand/plus/settings/backend/IntermediatePointsStorage.java index aaf90f0efd..c420036da0 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/IntermediatePointsStorage.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/IntermediatePointsStorage.java @@ -6,10 +6,8 @@ import java.util.List; class IntermediatePointsStorage extends SettingsMapPointsStorage { - private OsmandSettings osmandSettings; - public IntermediatePointsStorage(OsmandSettings osmandSettings) { - this.osmandSettings = osmandSettings; + super(osmandSettings); pointsKey = OsmandSettings.INTERMEDIATE_POINTS; descriptionsKey = OsmandSettings.INTERMEDIATE_POINTS_DESCRIPTION; } @@ -17,7 +15,7 @@ class IntermediatePointsStorage extends SettingsMapPointsStorage { @Override public boolean savePoints(List ps, List ds) { boolean res = super.savePoints(ps, ds); - osmandSettings.backupTargetPoints(); + getOsmandSettings().backupTargetPoints(); return res; } } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/ListStringPreference.java b/OsmAnd/src/net/osmand/plus/settings/backend/ListStringPreference.java index 81b7a01f60..ff611593cc 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/ListStringPreference.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/ListStringPreference.java @@ -8,17 +8,15 @@ import java.util.List; public class ListStringPreference extends StringPreference { - private OsmandSettings osmandSettings; private String delimiter; ListStringPreference(OsmandSettings osmandSettings, String id, String defaultValue, String delimiter) { - super(id, defaultValue); - this.osmandSettings = osmandSettings; + super(osmandSettings, id, defaultValue); this.delimiter = delimiter; } public boolean addValue(String res) { - return addModeValue(osmandSettings.getApplicationMode(), res); + return addModeValue(getApplicationMode(), res); } public boolean addModeValue(ApplicationMode appMode, String res) { @@ -33,7 +31,7 @@ public class ListStringPreference extends StringPreference { } public void clearAll() { - clearAllForProfile(osmandSettings.getApplicationMode()); + clearAllForProfile(getApplicationMode()); } public void clearAllForProfile(ApplicationMode appMode) { @@ -41,7 +39,7 @@ public class ListStringPreference extends StringPreference { } public boolean containsValue(String res) { - return containsValue(osmandSettings.getApplicationMode(), res); + return containsValue(getApplicationMode(), res); } public boolean containsValue(ApplicationMode appMode, String res) { @@ -51,7 +49,7 @@ public class ListStringPreference extends StringPreference { } public boolean removeValue(String res) { - return removeValueForProfile(osmandSettings.getApplicationMode(), res); + return removeValueForProfile(getApplicationMode(), res); } public boolean removeValueForProfile(ApplicationMode appMode, String res) { @@ -75,7 +73,7 @@ public class ListStringPreference extends StringPreference { } public List getStringsList() { - return getStringsListForProfile(osmandSettings.getApplicationMode()); + return getStringsListForProfile(getApplicationMode()); } public List getStringsListForProfile(ApplicationMode appMode) { @@ -93,7 +91,7 @@ public class ListStringPreference extends StringPreference { } public void setStringsList(List values) { - setStringsListForProfile(osmandSettings.getApplicationMode(), values); + setStringsListForProfile(getApplicationMode(), values); } public void setStringsListForProfile(ApplicationMode appMode, List values) { diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/LongPreference.java b/OsmAnd/src/net/osmand/plus/settings/backend/LongPreference.java index 8993919e23..f36d8368a3 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/LongPreference.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/LongPreference.java @@ -2,22 +2,18 @@ package net.osmand.plus.settings.backend; class LongPreference extends CommonPreference { - - private OsmandSettings osmandSettings; - LongPreference(OsmandSettings osmandSettings, String id, long defaultValue) { - super(id, defaultValue); - this.osmandSettings = osmandSettings; + super(osmandSettings, id, defaultValue); } @Override - protected Long getValue(Object prefs, Long defaultValue) { - return osmandSettings.settingsAPI.getLong(prefs, getId(), defaultValue); + public Long getValue(Object prefs, Long defaultValue) { + return getSettingsAPI().getLong(prefs, getId(), defaultValue); } @Override protected boolean setValue(Object prefs, Long val) { - return osmandSettings.settingsAPI.edit(prefs).putLong(getId(), val).commit(); + return getSettingsAPI().edit(prefs).putLong(getId(), val).commit(); } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmAndPreferencesDataStore.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmAndPreferencesDataStore.java index 0a6f464b77..d4eaf070f2 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmAndPreferencesDataStore.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmAndPreferencesDataStore.java @@ -55,7 +55,7 @@ public class OsmAndPreferencesDataStore extends PreferenceDataStore { @Nullable @Override public String getString(String key, @Nullable String defValue) { - OsmandPreference preference = osmandSettings.getPreference(key); + OsmandPreference preference = osmandSettings.getPreference(key); if (preference instanceof StringPreference) { return ((StringPreference) preference).getModeValue(appMode); } else { @@ -75,25 +75,25 @@ public class OsmAndPreferencesDataStore extends PreferenceDataStore { @Override public int getInt(String key, int defValue) { - OsmandPreference preference = osmandSettings.getPreference(key); - if (preference instanceof OsmandSettings.IntPreference) { - return ((OsmandSettings.IntPreference) preference).getModeValue(appMode); + OsmandPreference preference = osmandSettings.getPreference(key); + if (preference instanceof IntPreference) { + return ((IntPreference) preference).getModeValue(appMode); } return defValue; } @Override public long getLong(String key, long defValue) { - OsmandPreference preference = osmandSettings.getPreference(key); - if (preference instanceof OsmandSettings.LongPreference) { - return ((OsmandSettings.LongPreference) preference).getModeValue(appMode); + OsmandPreference preference = osmandSettings.getPreference(key); + if (preference instanceof LongPreference) { + return ((LongPreference) preference).getModeValue(appMode); } return defValue; } @Override public float getFloat(String key, float defValue) { - OsmandPreference preference = osmandSettings.getPreference(key); + OsmandPreference preference = osmandSettings.getPreference(key); if (preference instanceof FloatPreference) { return ((FloatPreference) preference).getModeValue(appMode); } @@ -102,7 +102,7 @@ public class OsmAndPreferencesDataStore extends PreferenceDataStore { @Override public boolean getBoolean(String key, boolean defValue) { - OsmandPreference preference = osmandSettings.getPreference(key); + OsmandPreference preference = osmandSettings.getPreference(key); if (preference instanceof BooleanPreference) { return ((BooleanPreference) preference).getModeValue(appMode); } @@ -111,7 +111,7 @@ public class OsmAndPreferencesDataStore extends PreferenceDataStore { @Nullable public Object getValue(String key, Object defValue) { - OsmandPreference preference = osmandSettings.getPreference(key); + OsmandPreference preference = osmandSettings.getPreference(key); if (preference != null) { return preference.getModeValue(appMode); } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index 523caf7866..3a9cd36219 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -113,14 +113,13 @@ public class OsmandSettings { private boolean editObjectToShow; private String searchRequestToShow; - - protected OsmandSettings(OsmandApplication clientContext, SettingsAPI settinsAPI) { + public OsmandSettings(OsmandApplication clientContext, SettingsAPI settinsAPI) { ctx = clientContext; this.settingsAPI = settinsAPI; initPrefs(); } - protected OsmandSettings(OsmandApplication clientContext, SettingsAPI settinsAPI, String sharedPreferencesName) { + public OsmandSettings(OsmandApplication clientContext, SettingsAPI settinsAPI, String sharedPreferencesName) { ctx = clientContext; this.settingsAPI = settinsAPI; CUSTOM_SHARED_PREFERENCES_NAME = CUSTOM_SHARED_PREFERENCES_PREFIX + sharedPreferencesName; @@ -196,7 +195,7 @@ public class OsmandSettings { return settingsAPI.getPreferenceObject(getSharedPreferencesNameForKey(modeKey)); } - public OsmandPreference getPreference(String key) { + public OsmandPreference getPreference(String key) { return registeredPreferences.get(key); } @@ -301,7 +300,7 @@ public class OsmandSettings { } else if (preference instanceof EnumStringPreference) { EnumStringPreference enumPref = (EnumStringPreference) preference; if (value instanceof String) { - Enum enumValue = enumPref.parseString((String) value); + Enum enumValue = enumPref.parseString((String) value); if (enumValue != null) { return enumPref.setModeValue(mode, enumValue); } @@ -310,8 +309,8 @@ public class OsmandSettings { return enumPref.setModeValue(mode, value); } else if (value instanceof Integer) { int newVal = (Integer) value; - if (enumPref.values.length > newVal) { - Enum enumValue = enumPref.values[newVal]; + if (enumPref.getValues().length > newVal) { + Enum enumValue = enumPref.getValues()[newVal]; return enumPref.setModeValue(mode, enumValue); } return false; @@ -358,7 +357,7 @@ public class OsmandSettings { } private boolean prefCanBeCopiedOrReset(OsmandPreference pref) { - return pref instanceof CommonPreference && !((CommonPreference) pref).global + return pref instanceof CommonPreference && !((CommonPreference) pref).isGlobal() && !APP_MODE_ORDER.getId().equals(pref.getId()); } @@ -412,7 +411,7 @@ public class OsmandSettings { OsmandAidlApi aidlApi = ctx.getAidlApi(); if (aidlApi != null) { - ctx.poiFilters.loadSelectedPoiFilters(); + ctx.getPoiFilters().loadSelectedPoiFilters(); } fireEvent(oldMode); @@ -728,13 +727,13 @@ public class OsmandSettings { public final OsmandPreference DEFAULT_APPLICATION_MODE = new CommonPreference(this, "default_application_mode_string", ApplicationMode.DEFAULT) { @Override - protected ApplicationMode getValue(Object prefs, ApplicationMode defaultValue) { + public ApplicationMode getValue(Object prefs, ApplicationMode defaultValue) { String key = settingsAPI.getString(prefs, getId(), defaultValue.getStringKey()); return ApplicationMode.valueOfStringKey(key, defaultValue); } @Override - protected boolean setValue(Object prefs, ApplicationMode val) { + public boolean setValue(Object prefs, ApplicationMode val) { boolean valueSaved = settingsAPI.edit(prefs).putString(getId(), val.getStringKey()).commit(); if (valueSaved) { APPLICATION_MODE.set(val); @@ -774,13 +773,13 @@ public class OsmandSettings { public final OsmandPreference LAST_ROUTE_APPLICATION_MODE = new CommonPreference(this, "last_route_application_mode_backup_string", ApplicationMode.DEFAULT) { @Override - protected ApplicationMode getValue(Object prefs, ApplicationMode defaultValue) { + public ApplicationMode getValue(Object prefs, ApplicationMode defaultValue) { String key = settingsAPI.getString(prefs, getId(), defaultValue.getStringKey()); return ApplicationMode.valueOfStringKey(key, defaultValue); } @Override - protected boolean setValue(Object prefs, ApplicationMode val) { + public boolean setValue(Object prefs, ApplicationMode val) { return settingsAPI.edit(prefs).putString(getId(), val.getStringKey()).commit(); } @@ -818,7 +817,7 @@ public class OsmandSettings { public final CommonPreference DRIVING_REGION_AUTOMATIC = new BooleanPreference(this, "driving_region_automatic", true).makeProfile().cache(); public final OsmandPreference DRIVING_REGION = new EnumStringPreference(this, "default_driving_region", DrivingRegion.EUROPE_ASIA, DrivingRegion.values()) { - protected boolean setValue(Object prefs, DrivingRegion val) { + public boolean setValue(Object prefs, DrivingRegion val) { if (val != null) { METRIC_SYSTEM.set(val.defMetrics); } @@ -2067,10 +2066,10 @@ public class OsmandSettings { public final static String MY_LOC_POINT_LON = "my_loc_point_lon"; public final static String MY_LOC_POINT_DESCRIPTION = "my_loc_point_description"; - private static final String IMPASSABLE_ROAD_POINTS = "impassable_road_points"; - private static final String IMPASSABLE_ROADS_DESCRIPTIONS = "impassable_roads_descriptions"; - private static final String IMPASSABLE_ROADS_IDS = "impassable_roads_ids"; - private static final String IMPASSABLE_ROADS_APP_MODE_KEYS = "impassable_roads_app_mode_keys"; + public static final String IMPASSABLE_ROAD_POINTS = "impassable_road_points"; + public static final String IMPASSABLE_ROADS_DESCRIPTIONS = "impassable_roads_descriptions"; + public static final String IMPASSABLE_ROADS_IDS = "impassable_roads_ids"; + public static final String IMPASSABLE_ROADS_APP_MODE_KEYS = "impassable_roads_app_mode_keys"; public void backupPointToStart() { settingsAPI.edit(globalPreferences) @@ -2509,7 +2508,7 @@ public class OsmandSettings { @Nullable public ContextMenuItemsPreference getContextMenuItemsPreference(@NonNull String id) { for (ContextMenuItemsPreference preference : CONTEXT_MENU_ITEMS_PREFERENCES) { - if (id.startsWith(preference.idScheme)) { + if (id.startsWith(preference.getIdScheme())) { return preference; } } @@ -2745,6 +2744,55 @@ public class OsmandSettings { return res; } + public String[] getAppModeBeanPrefsIds() { + return new String[]{ + ICON_COLOR.getId(), + ICON_RES_NAME.getId(), + PARENT_APP_MODE.getId(), + ROUTING_PROFILE.getId(), + ROUTE_SERVICE.getId(), + USER_PROFILE_NAME.getId(), + LOCATION_ICON.getId(), + NAVIGATION_ICON.getId(), + APP_MODE_ORDER.getId() + }; + } + + public OsmandPreference[] getGeneralPrefs() { + return new OsmandPreference[]{ + EXTERNAL_INPUT_DEVICE, + CENTER_POSITION_ON_MAP, + ROTATE_MAP, + MAP_SCREEN_ORIENTATION, + LIVE_MONITORING_URL, + LIVE_MONITORING_MAX_INTERVAL_TO_SEND, + LIVE_MONITORING_INTERVAL, + LIVE_MONITORING, + SHOW_TRIP_REC_NOTIFICATION, + AUTO_SPLIT_RECORDING, + SAVE_TRACK_MIN_SPEED, + SAVE_TRACK_PRECISION, + SAVE_TRACK_MIN_DISTANCE, + SAVE_TRACK_INTERVAL, + TRACK_STORAGE_DIRECTORY, + SAVE_HEADING_TO_GPX, + DISABLE_RECORDING_ONCE_APP_KILLED, + SAVE_TRACK_TO_GPX, + SAVE_GLOBAL_TRACK_REMEMBER, + SAVE_GLOBAL_TRACK_INTERVAL, + MAP_EMPTY_STATE_ALLOWED, + DO_NOT_USE_ANIMATIONS, + USE_KALMAN_FILTER_FOR_COMPASS, + USE_MAGNETIC_FIELD_SENSOR_COMPASS, + USE_TRACKBALL_FOR_MOVEMENTS, + SPEED_SYSTEM, + ANGULAR_UNITS, + METRIC_SYSTEM, + DRIVING_REGION, + DRIVING_REGION_AUTOMATIC + }; + } + public enum DayNightMode { AUTO(R.string.daynight_mode_auto, R.drawable.ic_action_map_sunset), DAY(R.string.daynight_mode_day, R.drawable.ic_action_map_day), diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/SettingsHelper.java index 50ee1c028e..1c6c003021 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/SettingsHelper.java @@ -906,18 +906,6 @@ public class SettingsHelper { } } - String[] - appModeBeanPrefsIds = new String[] { - ICON_COLOR.getId(), - ICON_RES_NAME.getId(), - PARENT_APP_MODE.getId(), - ROUTING_PROFILE.getId(), - ROUTE_SERVICE.getId(), - USER_PROFILE_NAME.getId(), - LOCATION_ICON.getId(), - NAVIGATION_ICON.getId(), - APP_MODE_ORDER.getId() - }; public static class ProfileSettingsItem extends OsmandSettingsItem { @@ -947,7 +935,7 @@ public class SettingsHelper { @Override protected void init() { super.init(); - appModeBeanPrefsIds = new HashSet<>(Arrays.asList(app.getSettings().appModeBeanPrefsIds)); + appModeBeanPrefsIds = new HashSet<>(Arrays.asList(app.getSettings().getAppModeBeanPrefsIds())); } @NonNull diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/SettingsMapPointsStorage.java b/OsmAnd/src/net/osmand/plus/settings/backend/SettingsMapPointsStorage.java index cdb923ed23..46c5bc1f3d 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/SettingsMapPointsStorage.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/SettingsMapPointsStorage.java @@ -2,6 +2,7 @@ package net.osmand.plus.settings.backend; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; +import net.osmand.plus.api.SettingsAPI; import net.osmand.plus.helpers.SearchHistoryHelper; import java.util.ArrayList; @@ -19,9 +20,17 @@ abstract class SettingsMapPointsStorage { this.osmandSettings = osmandSettings; } + protected SettingsAPI getSettingsAPI() { + return osmandSettings.getSettingsAPI(); + } + + protected OsmandSettings getOsmandSettings() { + return osmandSettings; + } + public List getPointDescriptions(int sz) { List list = new ArrayList<>(); - String ip = osmandSettings.settingsAPI.getString(osmandSettings.globalPreferences, descriptionsKey, ""); + String ip = getSettingsAPI().getString(osmandSettings.globalPreferences, descriptionsKey, ""); if (ip.trim().length() > 0) { list.addAll(Arrays.asList(ip.split("--"))); } @@ -36,7 +45,7 @@ abstract class SettingsMapPointsStorage { public List getPoints() { List list = new ArrayList<>(); - String ip = osmandSettings.settingsAPI.getString(osmandSettings.globalPreferences, pointsKey, ""); + String ip = getSettingsAPI().getString(osmandSettings.globalPreferences, pointsKey, ""); if (ip.trim().length() > 0) { StringTokenizer tok = new StringTokenizer(ip, ","); while (tok.hasMoreTokens()) { @@ -56,8 +65,8 @@ abstract class SettingsMapPointsStorage { List ds = getPointDescriptions(ps.size()); ps.add(index, new LatLon(latitude, longitude)); ds.add(index, PointDescription.serializeToString(historyDescription)); - if (historyDescription != null && !historyDescription.isSearchingAddress(osmandSettings.ctx)) { - SearchHistoryHelper.getInstance(osmandSettings.ctx).addNewItemToHistory(latitude, longitude, historyDescription); + if (historyDescription != null && !historyDescription.isSearchingAddress(osmandSettings.getContext())) { + SearchHistoryHelper.getInstance(osmandSettings.getContext()).addNewItemToHistory(latitude, longitude, historyDescription); } return savePoints(ps, ds); } @@ -68,8 +77,8 @@ abstract class SettingsMapPointsStorage { int i = ps.indexOf(new LatLon(latitude, longitude)); if (i != -1) { ds.set(i, PointDescription.serializeToString(historyDescription)); - if (historyDescription != null && !historyDescription.isSearchingAddress(osmandSettings.ctx)) { - SearchHistoryHelper.getInstance(osmandSettings.ctx).addNewItemToHistory(latitude, longitude, historyDescription); + if (historyDescription != null && !historyDescription.isSearchingAddress(osmandSettings.getContext())) { + SearchHistoryHelper.getInstance(osmandSettings.getContext()).addNewItemToHistory(latitude, longitude, historyDescription); } return savePoints(ps, ds); } else { @@ -121,7 +130,7 @@ abstract class SettingsMapPointsStorage { tb.append(ds.get(i)); } } - return osmandSettings.settingsAPI.edit(osmandSettings.globalPreferences) + return getSettingsAPI().edit(osmandSettings.globalPreferences) .putString(pointsKey, sb.toString()) .putString(descriptionsKey, tb.toString()) .commit(); diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/StringPreference.java b/OsmAnd/src/net/osmand/plus/settings/backend/StringPreference.java index 3ee07b43bd..e0c98404be 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/StringPreference.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/StringPreference.java @@ -2,21 +2,18 @@ package net.osmand.plus.settings.backend; public class StringPreference extends CommonPreference { - private OsmandSettings osmandSettings; - StringPreference(OsmandSettings osmandSettings, String id, String defaultValue) { - super(id, defaultValue); - this.osmandSettings = osmandSettings; + super(osmandSettings, id, defaultValue); } @Override - protected String getValue(Object prefs, String defaultValue) { - return osmandSettings.settingsAPI.getString(prefs, getId(), defaultValue); + public String getValue(Object prefs, String defaultValue) { + return getSettingsAPI().getString(prefs, getId(), defaultValue); } @Override protected boolean setValue(Object prefs, String val) { - return osmandSettings.settingsAPI.edit(prefs).putString(getId(), (val != null) ? val.trim() : val).commit(); + return getSettingsAPI().edit(prefs).putString(getId(), (val != null) ? val.trim() : val).commit(); } @Override