refactor fix build
This commit is contained in:
parent
c8ed464125
commit
9472f6306d
23 changed files with 216 additions and 200 deletions
|
@ -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" />
|
||||
|
||||
<Preference
|
||||
|
@ -25,7 +25,7 @@
|
|||
android:persistent="false"
|
||||
android:summary="@string/configure_navigation"
|
||||
android:title="@string/routing_settings_2"
|
||||
app:fragment="net.osmand.plus.settings.NavigationFragment"
|
||||
app:fragment="net.osmand.plus.settings.fragments.NavigationFragment"
|
||||
tools:icon="@drawable/ic_action_gdirections_dark" />
|
||||
|
||||
<Preference
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
android:key="coordinates_format"
|
||||
android:layout="@layout/preference_with_descr"
|
||||
android:title="@string/coords_format"
|
||||
app:fragment="net.osmand.plus.settings.CoordinatesFormatFragment" />
|
||||
app:fragment="net.osmand.plus.settings.fragments.CoordinatesFormatFragment" />
|
||||
|
||||
<net.osmand.plus.settings.preferences.ListPreferenceEx
|
||||
android:key="angular_measurement"
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
android:layout="@layout/preference_with_descr"
|
||||
android:persistent="false"
|
||||
android:title="@string/application_dir"
|
||||
app:fragment="net.osmand.plus.settings.DataStorageFragment"
|
||||
app:fragment="net.osmand.plus.settings.fragments.DataStorageFragment"
|
||||
tools:icon="@drawable/ic_action_folder" />
|
||||
|
||||
<Preference
|
||||
|
@ -48,7 +48,7 @@
|
|||
android:persistent="false"
|
||||
android:title="@string/dialogs_and_notifications_title"
|
||||
android:summary="@string/shared_string_all"
|
||||
app:fragment="net.osmand.plus.settings.DialogsAndNotificationsSettingsFragment"
|
||||
app:fragment="net.osmand.plus.settings.fragments.DialogsAndNotificationsSettingsFragment"
|
||||
tools:icon="@drawable/ic_action_notification" />
|
||||
|
||||
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
android:layout="@layout/preference_with_descr"
|
||||
android:summary="@string/route_parameters_descr"
|
||||
android:title="@string/route_parameters"
|
||||
app:fragment="net.osmand.plus.settings.RouteParametersFragment"
|
||||
app:fragment="net.osmand.plus.settings.fragments.RouteParametersFragment"
|
||||
tools:icon="@drawable/ic_action_route_distance" />
|
||||
|
||||
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
|
||||
|
@ -42,7 +42,7 @@
|
|||
android:layout="@layout/preference_with_descr"
|
||||
android:summary="@string/vehicle_parameters_descr"
|
||||
android:title="@string/vehicle_parameters"
|
||||
app:fragment="net.osmand.plus.settings.VehicleParametersFragment"
|
||||
app:fragment="net.osmand.plus.settings.fragments.VehicleParametersFragment"
|
||||
tools:icon="@drawable/ic_action_car_dark" />
|
||||
|
||||
<PreferenceCategory
|
||||
|
@ -54,7 +54,7 @@
|
|||
android:key="map_during_navigation"
|
||||
android:layout="@layout/preference_with_descr"
|
||||
android:title="@string/map_during_navigation"
|
||||
app:fragment="net.osmand.plus.settings.MapDuringNavigationFragment" />
|
||||
app:fragment="net.osmand.plus.settings.fragments.MapDuringNavigationFragment" />
|
||||
|
||||
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
|
||||
android:key="turn_screen_on_enabled"
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
android:persistent="false"
|
||||
android:summary="@string/osmand_settings_descr"
|
||||
android:title="@string/osmand_settings"
|
||||
app:fragment="net.osmand.plus.settings.GlobalSettingsFragment"
|
||||
app:fragment="net.osmand.plus.settings.fragments.GlobalSettingsFragment"
|
||||
tools:icon="@drawable/ic_action_settings" />
|
||||
|
||||
<Preference
|
||||
|
@ -27,7 +27,7 @@
|
|||
android:layout="@layout/preference_with_descr"
|
||||
android:persistent="false"
|
||||
android:title="@string/configure_profile"
|
||||
app:fragment="net.osmand.plus.settings.ConfigureProfileFragment"
|
||||
app:fragment="net.osmand.plus.settings.fragments.ConfigureProfileFragment"
|
||||
tools:icon="@drawable/ic_action_car_dark" />
|
||||
|
||||
<PreferenceCategory
|
||||
|
@ -58,7 +58,7 @@
|
|||
android:layout="@layout/preference_button"
|
||||
android:persistent="false"
|
||||
android:title="@string/reorder_profiles"
|
||||
app:fragment="net.osmand.plus.profiles.EditProfilesFragment"
|
||||
app:fragment="net.osmand.plus.profiles.fragments.EditProfilesFragment"
|
||||
tools:icon="@drawable/ic_action_edit_dark" />
|
||||
|
||||
<Preference
|
||||
|
|
|
@ -9,9 +9,11 @@ import com.google.gson.reflect.TypeToken;
|
|||
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.api.SettingsAPI;
|
||||
import net.osmand.plus.settings.backend.CommonPreference;
|
||||
import net.osmand.plus.settings.backend.EnumStringPreference;
|
||||
import net.osmand.plus.settings.backend.OsmandPreference;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
@ -51,9 +53,11 @@ class AppVersionUpgradeOnInit {
|
|||
private int prevAppVersion;
|
||||
private boolean appVersionChanged;
|
||||
private boolean firstTime;
|
||||
private OsmandSettings settings;
|
||||
|
||||
AppVersionUpgradeOnInit(OsmandApplication app) {
|
||||
this.app = app;
|
||||
settings = app.getSettings();
|
||||
}
|
||||
|
||||
@SuppressLint("ApplySharedPref")
|
||||
|
@ -74,27 +78,28 @@ class AppVersionUpgradeOnInit {
|
|||
} else {
|
||||
prevAppVersion = startPrefs.getInt(VERSION_INSTALLED_NUMBER, 0);
|
||||
if (needsUpgrade(startPrefs, lastVersion)) {
|
||||
|
||||
if (prevAppVersion < VERSION_2_2) {
|
||||
app.getSettings().SHOW_DASHBOARD_ON_START.set(true);
|
||||
app.getSettings().SHOW_DASHBOARD_ON_MAP_SCREEN.set(true);
|
||||
app.getSettings().SHOW_CARD_TO_CHOOSE_DRAWER.set(true);
|
||||
settings.SHOW_DASHBOARD_ON_START.set(true);
|
||||
settings.SHOW_DASHBOARD_ON_MAP_SCREEN.set(true);
|
||||
settings.SHOW_CARD_TO_CHOOSE_DRAWER.set(true);
|
||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_2).commit();
|
||||
}
|
||||
if (prevAppVersion < VERSION_2_3) {
|
||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_3).commit();
|
||||
}
|
||||
if (prevAppVersion < VERSION_3_2) {
|
||||
app.getSettings().BILLING_PURCHASE_TOKENS_SENT.set("");
|
||||
settings.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")
|
||||
|| Version.getAppVersion(app).equals("3.5.4")) {
|
||||
app.getSettings().migratePreferences();
|
||||
migratePreferences();
|
||||
app.getAppInitializer().addListener(new AppInitializer.AppInitializeListener() {
|
||||
@Override
|
||||
public void onProgress(AppInitializer init, AppInitializer.InitEvents event) {
|
||||
if (event.equals(AppInitializer.InitEvents.FAVORITES_INITIALIZED)) {
|
||||
app.getSettings().migrateHomeWorkParkingToFavorites();
|
||||
migrateHomeWorkParkingToFavorites();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,11 +110,11 @@ class AppVersionUpgradeOnInit {
|
|||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_5).commit();
|
||||
}
|
||||
if (prevAppVersion < VERSION_3_6) {
|
||||
app.getSettings().migratePreferences();
|
||||
migratePreferences();
|
||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_6).commit();
|
||||
}
|
||||
if (prevAppVersion < VERSION_3_7) {
|
||||
app.getSettings().migrateEnumPreferences();
|
||||
migrateEnumPreferences();
|
||||
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_7).commit();
|
||||
}
|
||||
if (prevAppVersion < VERSION_3_7_01) {
|
||||
|
@ -171,80 +176,49 @@ class AppVersionUpgradeOnInit {
|
|||
return firstTime;
|
||||
}
|
||||
|
||||
private OsmandPreference[] generalPrefs = 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 void migratePreferences() {
|
||||
migrateEnumPreferences();
|
||||
SharedPreferences globalSharedPreferences = (SharedPreferences) globalPreferences;
|
||||
SharedPreferences globalSharedPreferences = (SharedPreferences) settings.getGlobalPreferences();
|
||||
Map<String, ?> 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<String, ?> 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<ArrayList<ApplicationMode.ApplicationModeBean>>() {
|
||||
|
@ -252,22 +226,22 @@ class AppVersionUpgradeOnInit {
|
|||
List<ApplicationMode.ApplicationModeBean> 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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,13 +7,13 @@ public class BooleanPreference extends CommonPreference<Boolean> {
|
|||
}
|
||||
|
||||
@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
|
||||
|
|
|
@ -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<T> extends PreferenceWithListener<T> {
|
|||
}
|
||||
|
||||
// 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
|
||||
|
||||
|
|
|
@ -3,25 +3,23 @@ package net.osmand.plus.settings.backend;
|
|||
import androidx.annotation.NonNull;
|
||||
|
||||
public class ContextMenuItemsPreference extends CommonPreference<ContextMenuItemsSettings> {
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<String> 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 "";
|
||||
}
|
||||
|
|
|
@ -2,19 +2,17 @@ package net.osmand.plus.settings.backend;
|
|||
|
||||
public class EnumStringPreference<E extends Enum<E>> extends CommonPreference<E> {
|
||||
|
||||
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<E extends Enum<E>> extends CommonPreference<E>
|
|||
}
|
||||
|
||||
@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<E extends Enum<E>> extends CommonPreference<E>
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public E[] getValues() {
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,22 +2,18 @@ package net.osmand.plus.settings.backend;
|
|||
|
||||
public class FloatPreference extends CommonPreference<Float> {
|
||||
|
||||
|
||||
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
|
||||
|
|
|
@ -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<Long> getRoadIds(int size) {
|
||||
List<Long> 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<String> getAppModeKeys(int size) {
|
||||
List<String> 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();
|
||||
}
|
||||
|
|
|
@ -2,22 +2,18 @@ package net.osmand.plus.settings.backend;
|
|||
|
||||
class IntPreference extends CommonPreference<Integer> {
|
||||
|
||||
|
||||
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
|
||||
|
|
|
@ -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<LatLon> ps, List<String> ds) {
|
||||
boolean res = super.savePoints(ps, ds);
|
||||
osmandSettings.backupTargetPoints();
|
||||
getOsmandSettings().backupTargetPoints();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String> getStringsList() {
|
||||
return getStringsListForProfile(osmandSettings.getApplicationMode());
|
||||
return getStringsListForProfile(getApplicationMode());
|
||||
}
|
||||
|
||||
public List<String> getStringsListForProfile(ApplicationMode appMode) {
|
||||
|
@ -93,7 +91,7 @@ public class ListStringPreference extends StringPreference {
|
|||
}
|
||||
|
||||
public void setStringsList(List<String> values) {
|
||||
setStringsListForProfile(osmandSettings.getApplicationMode(), values);
|
||||
setStringsListForProfile(getApplicationMode(), values);
|
||||
}
|
||||
|
||||
public void setStringsListForProfile(ApplicationMode appMode, List<String> values) {
|
||||
|
|
|
@ -2,22 +2,18 @@ package net.osmand.plus.settings.backend;
|
|||
|
||||
class LongPreference extends CommonPreference<Long> {
|
||||
|
||||
|
||||
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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<ApplicationMode> DEFAULT_APPLICATION_MODE = new CommonPreference<ApplicationMode>(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<ApplicationMode> LAST_ROUTE_APPLICATION_MODE = new CommonPreference<ApplicationMode>(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<Boolean> DRIVING_REGION_AUTOMATIC = new BooleanPreference(this, "driving_region_automatic", true).makeProfile().cache();
|
||||
public final OsmandPreference<DrivingRegion> DRIVING_REGION = new EnumStringPreference<DrivingRegion>(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),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<String> getPointDescriptions(int sz) {
|
||||
List<String> 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<LatLon> getPoints() {
|
||||
List<LatLon> 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<String> 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();
|
||||
|
|
|
@ -2,21 +2,18 @@ package net.osmand.plus.settings.backend;
|
|||
|
||||
public class StringPreference extends CommonPreference<String> {
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue