Initial refactoring

This commit is contained in:
Victor Shcherb 2020-05-19 14:33:53 +02:00
parent f5f971874f
commit 8acebd22f9
91 changed files with 2089 additions and 1907 deletions

View file

@ -15,7 +15,7 @@ import net.osmand.AndroidUtils;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.AidlMapLayer;
@ -54,7 +54,7 @@ public class ConnectedApp implements Comparable<ConnectedApp> {
private Map<String, AidlMapLayerWrapper> layers = new ConcurrentHashMap<>();
private Map<String, OsmandMapLayer> mapLayers = new ConcurrentHashMap<>();
private OsmandSettings.CommonPreference<Boolean> layersPref;
private CommonPreference<Boolean> layersPref;
private String pack;
private String name;

View file

@ -25,7 +25,7 @@ import net.osmand.core.jni.ResolvedMapStyle;
import net.osmand.core.jni.SwigUtilities;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.render.RendererRegistry;
import net.osmand.render.RenderingRuleProperty;
import net.osmand.render.RenderingRuleStorageProperties;

View file

@ -9,8 +9,8 @@ import androidx.annotation.StringRes;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings.BooleanPreference;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.settings.backend.BooleanPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.util.Algorithms;

View file

@ -3,6 +3,22 @@ package net.osmand.plus;
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.EnumStringPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.util.Algorithms;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
class AppVersionUpgradeOnInit {
public static final String FIRST_TIME_APP_RUN = "FIRST_TIME_APP_RUN"; //$NON-NLS-1$
public static final String VERSION_INSTALLED_NUMBER = "VERSION_INSTALLED_NUMBER"; //$NON-NLS-1$
@ -154,4 +170,141 @@ class AppVersionUpgradeOnInit {
public boolean isFirstTime() {
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;
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) {
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
if (!commonPreference.isSetForMode(mode) && !commonPreference.hasDefaultValueForMode(mode)) {
setPreference(key, globalPrefsMap.get(key), mode);
}
}
}
}
}
SharedPreferences defaultProfilePreferences = (SharedPreferences) getProfilePreferences(ApplicationMode.DEFAULT);
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));
}
}
}
for (OsmandPreference pref : generalPrefs) {
if (pref instanceof CommonPreference) {
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);
}
}
}
}
String json = settingsAPI.getString(globalPreferences, "custom_app_profiles", "");
if (!Algorithms.isEmpty(json)) {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
Type t = new TypeToken<ArrayList<ApplicationMode.ApplicationModeBean>>() {
}.getType();
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);
}
}
}
}
public void migrateEnumPreferences() {
for (OsmandPreference pref : registeredPreferences.values()) {
if (pref instanceof EnumStringPreference) {
EnumStringPreference enumPref = (EnumStringPreference) pref;
if (enumPref.isGlobal()) {
migrateEnumPref(enumPref, (SharedPreferences) globalPreferences);
} else {
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
migrateEnumPref(enumPref, (SharedPreferences) getProfilePreferences(mode));
}
}
}
}
}
private void migrateEnumPref(EnumStringPreference enumPref, SharedPreferences sharedPreferences) {
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];
enumPref.setValue(sharedPreferences, savedValue);
}
}
}
public void migrateHomeWorkParkingToFavorites() {
FavouritesDbHelper favorites = ctx.getFavorites();
LatLon homePoint = null;
float lat = settingsAPI.getFloat(globalPreferences, "home_point_lat", 0);
float lon = settingsAPI.getFloat(globalPreferences, "home_point_lon", 0);
if (lat != 0 || lon != 0) {
homePoint = new LatLon(lat, lon);
}
LatLon workPoint = null;
lat = settingsAPI.getFloat(globalPreferences, "work_point_lat", 0);
lon = settingsAPI.getFloat(globalPreferences, "work_point_lon", 0);
if (lat != 0 || lon != 0) {
workPoint = new LatLon(lat, lon);
}
if (homePoint != null) {
favorites.setSpecialPoint(homePoint, FavouritePoint.SpecialPointType.HOME, null);
}
if (workPoint != null) {
favorites.setSpecialPoint(workPoint, FavouritePoint.SpecialPointType.WORK, null);
}
}
}

View file

@ -36,9 +36,8 @@ import net.osmand.plus.activities.actions.AppModeDialog;
import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.dialogs.HelpArticleDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.ContextMenuItemsPreference;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.settings.backend.ContextMenuItemsPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
@ -629,7 +628,7 @@ public class ContextMenuAdapter {
return makeDeleteAction(prefs.toArray(new OsmandPreference[prefs.size()]));
}
private static void resetSetting(ApplicationMode appMode, OsmandSettings.OsmandPreference preference, boolean profileOnly) {
private static void resetSetting(ApplicationMode appMode, OsmandPreference preference, boolean profileOnly) {
if (profileOnly) {
preference.resetModeToDefault(appMode);
} else {

View file

@ -41,7 +41,8 @@ import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.plus.skimapsplugin.SkiMapsPlugin;
import net.osmand.plus.srtmplugin.SRTMPlugin;
@ -73,7 +74,7 @@ public abstract class OsmandPlugin {
protected OsmandApplication app;
protected List<OsmandSettings.OsmandPreference> pluginPreferences = new ArrayList<>();
protected List<OsmandPreference> pluginPreferences = new ArrayList<>();
private boolean active;
private String installURL = null;
@ -111,7 +112,7 @@ public abstract class OsmandPlugin {
return null;
}
public List<OsmandSettings.OsmandPreference> getPreferences() {
public List<OsmandPreference> getPreferences() {
return pluginPreferences;
}
@ -841,44 +842,44 @@ public abstract class OsmandPlugin {
}
}
protected OsmandSettings.CommonPreference<Boolean> registerBooleanPreference(OsmandApplication app, String prefId, boolean defValue) {
OsmandSettings.CommonPreference<Boolean> preference = app.getSettings().registerBooleanPreference(prefId, defValue);
protected CommonPreference<Boolean> registerBooleanPreference(OsmandApplication app, String prefId, boolean defValue) {
CommonPreference<Boolean> preference = app.getSettings().registerBooleanPreference(prefId, defValue);
pluginPreferences.add(preference);
return preference;
}
private OsmandSettings.CommonPreference<Boolean> registerBooleanAccessibilityPreference(OsmandApplication app, String prefId, boolean defValue) {
OsmandSettings.CommonPreference<Boolean> preference = app.getSettings().registerBooleanAccessibilityPreference(prefId, defValue);
private CommonPreference<Boolean> registerBooleanAccessibilityPreference(OsmandApplication app, String prefId, boolean defValue) {
CommonPreference<Boolean> preference = app.getSettings().registerBooleanAccessibilityPreference(prefId, defValue);
pluginPreferences.add(preference);
return preference;
}
protected OsmandSettings.CommonPreference<String> registerStringPreference(OsmandApplication app, String prefId, String defValue) {
OsmandSettings.CommonPreference<String> preference = app.getSettings().registerStringPreference(prefId, defValue);
protected CommonPreference<String> registerStringPreference(OsmandApplication app, String prefId, String defValue) {
CommonPreference<String> preference = app.getSettings().registerStringPreference(prefId, defValue);
pluginPreferences.add(preference);
return preference;
}
protected OsmandSettings.CommonPreference<Integer> registerIntPreference(OsmandApplication app, String prefId, int defValue) {
OsmandSettings.CommonPreference<Integer> preference = app.getSettings().registerIntPreference(prefId, defValue);
protected CommonPreference<Integer> registerIntPreference(OsmandApplication app, String prefId, int defValue) {
CommonPreference<Integer> preference = app.getSettings().registerIntPreference(prefId, defValue);
pluginPreferences.add(preference);
return preference;
}
protected OsmandSettings.CommonPreference<Long> registerLongPreference(OsmandApplication app, String prefId, long defValue) {
OsmandSettings.CommonPreference<Long> preference = app.getSettings().registerLongPreference(prefId, defValue);
protected CommonPreference<Long> registerLongPreference(OsmandApplication app, String prefId, long defValue) {
CommonPreference<Long> preference = app.getSettings().registerLongPreference(prefId, defValue);
pluginPreferences.add(preference);
return preference;
}
protected OsmandSettings.CommonPreference<Float> registerFloatPreference(OsmandApplication app, String prefId, float defValue) {
OsmandSettings.CommonPreference<Float> preference = app.getSettings().registerFloatPreference(prefId, defValue);
protected CommonPreference<Float> registerFloatPreference(OsmandApplication app, String prefId, float defValue) {
CommonPreference<Float> preference = app.getSettings().registerFloatPreference(prefId, defValue);
pluginPreferences.add(preference);
return preference;
}
protected <T extends Enum> OsmandSettings.CommonPreference<T> registerEnumIntPreference(OsmandApplication app, String prefId, Enum defaultValue, Enum[] values, Class<T> clz) {
OsmandSettings.CommonPreference<T> preference = app.getSettings().registerEnumIntPreference(prefId, defaultValue, values, clz);
protected <T extends Enum> CommonPreference<T> registerEnumIntPreference(OsmandApplication app, String prefId, Enum defaultValue, Enum[] values, Class<T> clz) {
CommonPreference<T> preference = app.getSettings().registerEnumIntPreference(prefId, defaultValue, values, clz);
pluginPreferences.add(preference);
return preference;
}

View file

@ -44,6 +44,7 @@ import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.FavouritesDbHelper.FavoritesListener;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
@ -97,7 +98,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
private Set<FavoriteGroup> groupsToDelete = new LinkedHashSet<>();
private ActionMode actionMode;
private Drawable arrowImageDisabled;
private HashMap<String, OsmandSettings.OsmandPreference<Boolean>> preferenceCache = new HashMap<>();
private HashMap<String, OsmandPreference<Boolean>> preferenceCache = new HashMap<>();
private View footerView;
private Location lastLocation;
private float lastHeading;
@ -763,8 +764,8 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
}
}
private OsmandSettings.OsmandPreference<Boolean> getGroupExpandedPreference(String groupName) {
OsmandSettings.OsmandPreference<Boolean> preference = preferenceCache.get(groupName);
private OsmandPreference<Boolean> getGroupExpandedPreference(String groupName) {
OsmandPreference<Boolean> preference = preferenceCache.get(groupName);
if (preference == null) {
String groupKey = groupName + GROUP_EXPANDED_POSTFIX;
preference = getSettings().registerBooleanPreference(groupKey, false);

View file

@ -77,6 +77,7 @@ import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmAndLocationSimulation;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
@ -548,7 +549,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
@Override
public void requestPrivateAccessRouting() {
if (!settings.FORCE_PRIVATE_ACCESS_ROUTING_ASKED.getModeValue(getRoutingHelper().getAppMode())) {
final OsmandSettings.CommonPreference<Boolean> allowPrivate
final CommonPreference<Boolean> allowPrivate
= settings.getCustomRoutingBooleanProperty(GeneralRouter.ALLOW_PRIVATE, false);
final List<ApplicationMode> modes = ApplicationMode.values(app);
for (ApplicationMode mode : modes) {

View file

@ -28,7 +28,7 @@ import net.osmand.plus.DialogListItemAdapter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.SQLiteTileSource;
import net.osmand.plus.activities.MapActivity.ShowQuickSearchMode;

View file

@ -26,8 +26,8 @@ import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.profiles.AppProfileArrayAdapter;
import net.osmand.plus.profiles.ProfileDataObject;

View file

@ -35,9 +35,10 @@ import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.AutoZoomMap;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandSettings.SpeedConstants;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
@ -406,7 +407,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
}
public static boolean isRoutingParameterSelected(OsmandSettings settings, ApplicationMode am, RoutingParameter routingParameter) {
final OsmandSettings.CommonPreference<Boolean> property =
final CommonPreference<Boolean> property =
settings.getCustomRoutingBooleanProperty(routingParameter.getId(), routingParameter.getDefaultBoolean());
if(am != null) {
return property.getModeValue(am);
@ -416,7 +417,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
}
public static void setRoutingParameterSelected(OsmandSettings settings, ApplicationMode am, String routingParameterId, boolean defaultBoolean, boolean isChecked) {
final OsmandSettings.CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(routingParameterId, defaultBoolean);
final CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(routingParameterId, defaultBoolean);
if (am != null) {
property.setModeValue(am, isChecked);
} else {

View file

@ -53,8 +53,8 @@ import net.osmand.plus.ContextMenuAdapter.ItemClickListener;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;

View file

@ -3,7 +3,7 @@ package net.osmand.plus.audionotes;
import android.os.Bundle;
import android.view.View;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings.NotesSortByMode;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
@ -53,7 +53,7 @@ public class SortByMenuBottomSheetDialogFragment extends MenuBottomSheetDialogFr
}
private void selectSortByMode(NotesSortByMode mode) {
final OsmandSettings.CommonPreference<NotesSortByMode> sortByMode = getMyApplication().getSettings().NOTES_SORT_BY_MODE;
final CommonPreference<NotesSortByMode> sortByMode = getMyApplication().getSettings().NOTES_SORT_BY_MODE;
if (sortByMode.get() != mode) {
sortByMode.set(mode);
if (listener != null) {

View file

@ -24,7 +24,7 @@ import androidx.fragment.app.FragmentManager;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndDialogFragment;

View file

@ -25,7 +25,7 @@ import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;

View file

@ -19,7 +19,7 @@ import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.routing.data.StreetName;
@ -149,7 +149,7 @@ public class TestVoiceActivity extends OsmandActionBarActivity {
v += "\n \u25CF BT SCO: The current app profile is not set to use 'Phone call audio'.";
}
OsmandSettings.OsmandPreference<Integer> pref = ((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[stream];
OsmandPreference<Integer> pref = ((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[stream];
if(pref != null) {
v += "\n \u25CF Voice prompt delay for selected output: " + pref.get() + "\u00A0ms";
}
@ -288,7 +288,7 @@ public class TestVoiceActivity extends OsmandActionBarActivity {
}
if (description.startsWith("\u25BA (11.2)")) {
int ams = ((OsmandApplication) getApplication()).getSettings().AUDIO_MANAGER_STREAM.get();
OsmandSettings.OsmandPreference<Integer> pref = ((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[ams];
OsmandPreference<Integer> pref = ((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[ams];
if (pref != null) {
if (pref.get() >= 3000) {
pref.set(0);

View file

@ -37,9 +37,10 @@ import net.osmand.plus.DialogListItemAdapter;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings.ListStringPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.ListStringPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
@ -571,7 +572,7 @@ public class ConfigureMapMenu {
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId,
final int pos, boolean isChecked, int[] viewCoordinates) {
final OsmandMapTileView view = activity.getMapView();
final OsmandSettings.OsmandPreference<Float> mapDensity = view.getSettings().MAP_DENSITY;
final OsmandPreference<Float> mapDensity = view.getSettings().MAP_DENSITY;
AlertDialog.Builder bld = new AlertDialog.Builder(new ContextThemeWrapper(view.getContext(), themeRes));
int p = (int) (mapDensity.get() * 100);
final TIntArrayList tlist = new TIntArrayList(new int[]{25, 33, 50, 75, 100, 125, 150, 200, 300, 400});
@ -858,25 +859,25 @@ public class ConfigureMapMenu {
@ColorInt final int selectedProfileColor) {
final List<RenderingRuleProperty> ps = new ArrayList<>();
final List<OsmandSettings.CommonPreference<Boolean>> prefs = new ArrayList<>();
final List<CommonPreference<Boolean>> prefs = new ArrayList<>();
Iterator<RenderingRuleProperty> it = customRules.iterator();
while (it.hasNext()) {
RenderingRuleProperty p = it.next();
if (category.equals(p.getCategory()) && p.isBoolean()) {
ps.add(p);
final OsmandSettings.CommonPreference<Boolean> pref = activity.getMyApplication().getSettings()
final CommonPreference<Boolean> pref = activity.getMyApplication().getSettings()
.getCustomRenderBooleanProperty(p.getAttrName());
prefs.add(pref);
it.remove();
}
}
if (prefs.size() > 0) {
final List<OsmandSettings.CommonPreference<String>> includedPrefs = new ArrayList<>();
final List<CommonPreference<String>> includedPrefs = new ArrayList<>();
if (customRulesIncluded != null) {
for (RenderingRuleProperty p : customRulesIncluded) {
if (!p.isBoolean()) {
final OsmandSettings.CommonPreference<String> pref = activity.getMyApplication().getSettings()
final CommonPreference<String> pref = activity.getMyApplication().getSettings()
.getCustomRenderProperty(p.getAttrName());
includedPrefs.add(pref);
}
@ -914,14 +915,14 @@ public class ConfigureMapMenu {
.setId(id)
.setIcon(icon).setListener(clickListener);
boolean selected = false;
for (OsmandSettings.CommonPreference<Boolean> p : prefs) {
for (CommonPreference<Boolean> p : prefs) {
if (p.get()) {
selected = true;
break;
}
}
if (!selected && includedPrefs.size() > 0) {
for (OsmandSettings.CommonPreference<String> p : includedPrefs) {
for (CommonPreference<String> p : includedPrefs) {
if (!Algorithms.isEmpty(p.get())) {
selected = true;
break;
@ -958,17 +959,17 @@ public class ConfigureMapMenu {
return null;
}
protected String getDescription(final List<OsmandSettings.CommonPreference<Boolean>> prefs,
final List<OsmandSettings.CommonPreference<String>> includedPrefs) {
protected String getDescription(final List<CommonPreference<Boolean>> prefs,
final List<CommonPreference<String>> includedPrefs) {
int count = 0;
int enabled = 0;
for (OsmandSettings.CommonPreference<Boolean> p : prefs) {
for (CommonPreference<Boolean> p : prefs) {
count++;
if (p.get()) {
enabled++;
}
}
for (OsmandSettings.CommonPreference<String> p : includedPrefs) {
for (CommonPreference<String> p : includedPrefs) {
count++;
if (!Algorithms.isEmpty(p.get())) {
enabled++;
@ -1039,11 +1040,11 @@ public class ConfigureMapMenu {
prefs.get(i).set(tempPrefs[i]);
selected |= tempPrefs[i];
}
final List<OsmandSettings.CommonPreference<String>> includedPrefs = new ArrayList<>();
final List<CommonPreference<String>> includedPrefs = new ArrayList<>();
if (customRulesIncluded != null) {
for (RenderingRuleProperty p : customRulesIncluded) {
if (p.getAttrName().equals(HIKING_ROUTES_OSMC_ATTR)) {
final OsmandSettings.CommonPreference<String> pref = activity.getMyApplication().getSettings()
final CommonPreference<String> pref = activity.getMyApplication().getSettings()
.getCustomRenderProperty(p.getAttrName());
includedPrefs.add(pref);
if (hikingRouteOSMCValue == 0) {
@ -1077,7 +1078,7 @@ public class ConfigureMapMenu {
if (customRulesIncluded != null) {
for (RenderingRuleProperty p : customRulesIncluded) {
if (!p.isBoolean()) {
final OsmandSettings.CommonPreference<String> pref = activity.getMyApplication().getSettings()
final CommonPreference<String> pref = activity.getMyApplication().getSettings()
.getCustomRenderProperty(p.getAttrName());
View spinnerView = View.inflate(new ContextThemeWrapper(activity, themeRes), R.layout.spinner_rule_layout, null);
@ -1214,7 +1215,7 @@ public class ConfigureMapMenu {
final String propertyDescr = SettingsActivity.getStringPropertyDescription(view.getContext(),
p.getAttrName(), p.getName());
if (p.isBoolean()) {
final OsmandSettings.CommonPreference<Boolean> pref = view.getApplication().getSettings()
final CommonPreference<Boolean> pref = view.getApplication().getSettings()
.getCustomRenderBooleanProperty(p.getAttrName());
return ContextMenuItem.createBuilder(propertyName)
.setId(id)
@ -1230,7 +1231,7 @@ public class ConfigureMapMenu {
.setSelected(pref.get())
.createItem();
} else {
final OsmandSettings.CommonPreference<String> pref = view.getApplication().getSettings()
final CommonPreference<String> pref = view.getApplication().getSettings()
.getCustomRenderProperty(p.getAttrName());
final String descr;
if (!Algorithms.isEmpty(pref.get())) {

View file

@ -10,6 +10,7 @@ import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.LayerTransparencySeekbarMode;
import net.osmand.plus.R;
@ -39,9 +40,9 @@ public class RasterMapMenu {
final OsmandSettings settings = app.getSettings();
final OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class);
assert plugin != null;
final OsmandSettings.CommonPreference<Integer> mapTransparencyPreference;
final OsmandSettings.CommonPreference<String> mapTypePreference;
final OsmandSettings.CommonPreference<String> exMapTypePreference;
final CommonPreference<Integer> mapTransparencyPreference;
final CommonPreference<String> mapTypePreference;
final CommonPreference<String> exMapTypePreference;
final LayerTransparencySeekbarMode currentMapTypeSeekbarMode =
type == RasterMapType.OVERLAY ? LayerTransparencySeekbarMode.OVERLAY : LayerTransparencySeekbarMode.UNDERLAY;
@StringRes final int mapTypeString;
@ -62,7 +63,7 @@ public class RasterMapMenu {
throw new RuntimeException("Unexpected raster map type");
}
final OsmandSettings.CommonPreference<Boolean> hidePolygonsPref =
final CommonPreference<Boolean> hidePolygonsPref =
mapActivity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
String mapTypeDescr = mapTypePreference.get();

View file

@ -19,7 +19,7 @@ import androidx.fragment.app.FragmentManager;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;

View file

@ -22,7 +22,7 @@ import net.osmand.map.WorldRegion;
import net.osmand.map.WorldRegion.RegionParams;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.base.BasicProgressAsyncTask;

View file

@ -80,6 +80,7 @@ import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
@ -513,9 +514,9 @@ public class GpxUiHelper {
} else {
final View apprTitleView = View.inflate(new ContextThemeWrapper(activity, themeRes), R.layout.select_gpx_appearance_title, null);
final OsmandSettings.CommonPreference<String> prefWidth
final CommonPreference<String> prefWidth
= app.getSettings().getCustomRenderProperty(CURRENT_TRACK_WIDTH_ATTR);
final OsmandSettings.CommonPreference<String> prefColor
final CommonPreference<String> prefColor
= app.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR);
updateAppearanceTitle(activity, app, trackWidthProp, renderer, apprTitleView, prefWidth.get(), prefColor.get());
@ -567,7 +568,7 @@ public class GpxUiHelper {
public void onClick(DialogInterface dialog, int which) {
if (gpxAppearanceParams.size() > 0) {
for (Map.Entry<String, String> entry : gpxAppearanceParams.entrySet()) {
final OsmandSettings.CommonPreference<String> pref
final CommonPreference<String> pref
= app.getSettings().getCustomRenderProperty(entry.getKey());
pref.set(entry.getValue());
}

View file

@ -17,7 +17,7 @@ import androidx.annotation.Nullable;
import net.osmand.plus.OsmAndAppCustomization.OsmAndAppCustomizationListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.routing.VoiceRouter.VoiceMessageListener;
import java.util.List;

View file

@ -23,7 +23,7 @@ import net.osmand.AndroidNetworkUtils.RequestResponse;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.inapp.InAppPurchases.InAppPurchase;

View file

@ -35,6 +35,7 @@ import androidx.fragment.app.FragmentManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.Version;
@ -312,7 +313,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
}
public void add(LocalIndexInfo info) {
OsmandSettings.CommonPreference<Boolean> preference = preferenceLiveUpdatesOn(
CommonPreference<Boolean> preference = preferenceLiveUpdatesOn(
info.getFileName(), getSettings());
if (preference.get()) {
dataShouldUpdate.add(info);
@ -324,7 +325,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
public void notifyLiveUpdatesChanged() {
Set<LocalIndexInfo> changedSet = new HashSet<>();
for (LocalIndexInfo localIndexInfo : dataShouldUpdate) {
OsmandSettings.CommonPreference<Boolean> preference =
CommonPreference<Boolean> preference =
preferenceLiveUpdatesOn(localIndexInfo.getFileName(), getSettings());
if (!preference.get()) {
changedSet.add(localIndexInfo);
@ -334,7 +335,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
dataShouldNotUpdate.addAll(changedSet);
changedSet.clear();
for (LocalIndexInfo localIndexInfo : dataShouldNotUpdate) {
OsmandSettings.CommonPreference<Boolean> preference =
CommonPreference<Boolean> preference =
preferenceLiveUpdatesOn(localIndexInfo.getFileName(), getSettings());
if (preference.get()) {
changedSet.add(localIndexInfo);
@ -475,9 +476,9 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
PendingIntent alarmIntent = getPendingIntent(getActivity(),
fileName);
if (enable) {
final OsmandSettings.CommonPreference<Integer> updateFrequencyPreference =
final CommonPreference<Integer> updateFrequencyPreference =
preferenceUpdateFrequency(fileName, getSettings());
final OsmandSettings.CommonPreference<Integer> timeOfDayPreference =
final CommonPreference<Integer> timeOfDayPreference =
preferenceTimeOfDayToUpdate(fileName, getSettings());
UpdateFrequency updateFrequency = UpdateFrequency.values()[updateFrequencyPreference.get()];
TimeOfDay timeOfDayToUpdate = TimeOfDay.values()[timeOfDayPreference.get()];
@ -572,7 +573,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
public void bindLocalIndexInfo(@NonNull final String item, boolean isLastChild) {
OsmandApplication context = fragment.getMyActivity().getMyApplication();
final OsmandSettings.CommonPreference<Boolean> shouldUpdatePreference =
final CommonPreference<Boolean> shouldUpdatePreference =
preferenceLiveUpdatesOn(item, fragment.getSettings());
IncrementalChangesManager changesManager = context.getResourceManager().getChangesManager();
@ -602,7 +603,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
Algorithms.getFileNameWithoutExtension(new File(item));
final long timestamp = changesManager.getTimestamp(fileNameWithoutExtension);
final long lastCheck = preferenceLastCheck(item, fragment.getSettings()).get();
OsmandSettings.CommonPreference<Boolean> liveUpdateOn = preferenceLiveUpdatesOn(item, fragment.getSettings());
CommonPreference<Boolean> liveUpdateOn = preferenceLiveUpdatesOn(item, fragment.getSettings());
if(liveUpdateOn.get() && lastCheck != DEFAULT_LAST_CHECK) {
String lastCheckString = formatDateTime(fragment.getActivity(), lastCheck );
descriptionTextView.setText(context.getString(R.string.last_update, lastCheckString));

View file

@ -8,6 +8,7 @@ import android.os.AsyncTask;
import androidx.annotation.NonNull;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandActionBarActivity;
@ -32,7 +33,7 @@ public class LiveUpdatesHelper {
public static final int DEFAULT_LAST_CHECK = -1;
private static <T> OsmandSettings.CommonPreference<T> checkPref(OsmandSettings.CommonPreference<T> p) {
private static <T> CommonPreference<T> checkPref(CommonPreference<T> p) {
if (p.isSet()) {
T vl = p.get();
p = p.makeGlobal();
@ -44,37 +45,37 @@ public class LiveUpdatesHelper {
}
return p;
}
public static OsmandSettings.CommonPreference<Boolean> preferenceForLocalIndex(
public static CommonPreference<Boolean> preferenceForLocalIndex(
String fileName, OsmandSettings settings) {
final String settingId = fileName + LIVE_UPDATES_ON_POSTFIX;
return checkPref(settings.registerBooleanPreference(settingId, false));
}
public static OsmandSettings.CommonPreference<Boolean> preferenceLiveUpdatesOn(
public static CommonPreference<Boolean> preferenceLiveUpdatesOn(
String fileName, OsmandSettings settings) {
final String settingId = fileName + LIVE_UPDATES_ON_POSTFIX;
return checkPref(settings.registerBooleanPreference(settingId, false));
}
public static OsmandSettings.CommonPreference<Boolean> preferenceDownloadViaWiFi(
public static CommonPreference<Boolean> preferenceDownloadViaWiFi(
String fileName, OsmandSettings settings) {
final String settingId = fileName + DOWNLOAD_VIA_WIFI_POSTFIX;
return checkPref(settings.registerBooleanPreference(settingId, false));
}
public static OsmandSettings.CommonPreference<Integer> preferenceUpdateFrequency(
public static CommonPreference<Integer> preferenceUpdateFrequency(
String fileName, OsmandSettings settings) {
final String settingId = fileName + UPDATE_TIMES_POSTFIX;
return checkPref(settings.registerIntPreference(settingId, UpdateFrequency.HOURLY.ordinal()));
}
public static OsmandSettings.CommonPreference<Integer> preferenceTimeOfDayToUpdate(
public static CommonPreference<Integer> preferenceTimeOfDayToUpdate(
String fileName, OsmandSettings settings) {
final String settingId = fileName + TIME_OF_DAY_TO_UPDATE_POSTFIX;
return checkPref(settings.registerIntPreference(settingId, TimeOfDay.NIGHT.ordinal()));
}
public static OsmandSettings.CommonPreference<Long> preferenceLastCheck(
public static CommonPreference<Long> preferenceLastCheck(
String fileName, OsmandSettings settings) {
final String settingId = fileName + LAST_UPDATE_ATTEMPT_ON_POSTFIX;
return checkPref(settings.registerLongPreference(settingId, DEFAULT_LAST_CHECK));

View file

@ -23,6 +23,7 @@ import androidx.fragment.app.DialogFragment;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.download.AbstractDownloadActivity;
@ -85,7 +86,7 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
final long lastCheck = preferenceLastCheck(fileName, getSettings()).get();
OsmandSettings.CommonPreference<Boolean> preference = preferenceLiveUpdatesOn(fileName,
CommonPreference<Boolean> preference = preferenceLiveUpdatesOn(fileName,
getSettings());
if (preference.get() && lastCheck != DEFAULT_LAST_CHECK) {
String lastCheckString = formatDateTime(getActivity(), lastCheck);
@ -94,13 +95,13 @@ public class LiveUpdatesSettingsDialogFragment extends DialogFragment {
lastUpdateTextView.setVisibility(View.GONE);
}
final OsmandSettings.CommonPreference<Boolean> liveUpdatePreference =
final CommonPreference<Boolean> liveUpdatePreference =
preferenceForLocalIndex(fileName, getSettings());
final OsmandSettings.CommonPreference<Boolean> downloadViaWiFiPreference =
final CommonPreference<Boolean> downloadViaWiFiPreference =
preferenceDownloadViaWiFi(fileName, getSettings());
final OsmandSettings.CommonPreference<Integer> updateFrequencyPreference =
final CommonPreference<Integer> updateFrequencyPreference =
preferenceUpdateFrequency(fileName, getSettings());
final OsmandSettings.CommonPreference<Integer> timeOfDayPreference =
final CommonPreference<Integer> timeOfDayPreference =
preferenceTimeOfDayToUpdate(fileName, getSettings());
downloadOverWiFiCheckBox.setChecked(!liveUpdatePreference.get() || downloadViaWiFiPreference.get());

View file

@ -9,6 +9,7 @@ import androidx.annotation.NonNull;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.download.AbstractDownloadActivity;
@ -50,7 +51,7 @@ public class PerformLiveUpdateAsyncTask
activity.setSupportProgressBarIndeterminateVisibility(true);
}
final OsmandApplication myApplication = getMyApplication();
OsmandSettings.CommonPreference<Long> lastCheckPreference =
CommonPreference<Long> lastCheckPreference =
LiveUpdatesHelper.preferenceLastCheck(localIndexFileName, myApplication.getSettings());
lastCheckPreference.set(System.currentTimeMillis());
}
@ -148,7 +149,7 @@ public class PerformLiveUpdateAsyncTask
public static void tryRescheduleDownload(@NonNull Context context,
@NonNull OsmandSettings settings,
@NonNull String localIndexFileName) {
final OsmandSettings.CommonPreference<Integer> updateFrequencyPreference =
final CommonPreference<Integer> updateFrequencyPreference =
preferenceUpdateFrequency(localIndexFileName, settings);
final Integer frequencyOrdinal = updateFrequencyPreference.get();
if (LiveUpdatesHelper.UpdateFrequency.values()[frequencyOrdinal]

View file

@ -4,7 +4,7 @@ import android.view.View;
import androidx.annotation.NonNull;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.mapcontextmenu.MenuBuilder.CollapseExpandListener;
public class CollapsableView {

View file

@ -57,6 +57,7 @@ import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.LockableScrollView;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.MainContextMenuItemsSettings;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
@ -569,7 +570,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
// Action buttons
ContextMenuAdapter adapter = menu.getActionsContextMenuAdapter(false);
List<ContextMenuItem> items = adapter.getVisibleItems();
List<String> mainIds = ((OsmandSettings.MainContextMenuItemsSettings) app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS.get()).getMainIds();
List<String> mainIds = ((MainContextMenuItemsSettings) app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS.get()).getMainIds();
ContextMenuAdapter mainAdapter = new ContextMenuAdapter(requireMyApplication());
ContextMenuAdapter additionalAdapter = new ContextMenuAdapter(requireMyApplication());

View file

@ -13,7 +13,7 @@ import androidx.core.content.ContextCompat;
import net.osmand.data.PointDescription;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.MapMarkerDialogHelper;
@ -56,7 +56,7 @@ public class MapMarkerMenuController extends MenuController {
public void buttonPressed() {
MapActivity activity = getMapActivity();
if (activity != null) {
OsmandSettings.OsmandPreference<Boolean> indication
OsmandPreference<Boolean> indication
= activity.getMyApplication().getSettings().MARKERS_DISTANCE_INDICATION_ENABLED;
if (!indication.get()) {
indication.set(true);

View file

@ -6,6 +6,7 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
@ -83,7 +84,7 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia
@Override
public void onClick(View v) {
if (listener != null) {
OsmandSettings.CommonPreference<Boolean> pref = settings.COORDS_INPUT_TWO_DIGITS_LONGTITUDE;
CommonPreference<Boolean> pref = settings.COORDS_INPUT_TWO_DIGITS_LONGTITUDE;
pref.set(!pref.get());
listener.onInputSettingsChanged();
}
@ -108,7 +109,7 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia
@Override
public void onClick(View v) {
if (listener != null) {
OsmandSettings.CommonPreference<Boolean> pref = settings.COORDS_INPUT_USE_RIGHT_SIDE;
CommonPreference<Boolean> pref = settings.COORDS_INPUT_USE_RIGHT_SIDE;
pref.set(!pref.get());
listener.onHandChanged();
}

View file

@ -66,7 +66,7 @@ import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.Version;
@ -1020,7 +1020,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
}
private void changeOsmandKeyboardSetting() {
OsmandSettings.OsmandPreference<Boolean> pref = getMyApplication().getSettings().COORDS_INPUT_USE_OSMAND_KEYBOARD;
OsmandPreference<Boolean> pref = getMyApplication().getSettings().COORDS_INPUT_USE_OSMAND_KEYBOARD;
pref.set(!pref.get());
}

View file

@ -33,7 +33,7 @@ import net.osmand.AndroidUtils;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.MapMarkersMode;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;

View file

@ -13,7 +13,8 @@ import androidx.preference.Preference;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.FontCache;
@ -288,11 +289,11 @@ public class MonitoringSettingsFragment extends BaseSettingsFragment
@Override
public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
if (SAVE_GLOBAL_TRACK_INTERVAL.equals(prefId)) {
OsmandSettings.OsmandPreference pref = settings.getPreference(prefId);
OsmandPreference pref = settings.getPreference(prefId);
if (newValue instanceof Boolean) {
applyPreference(settings.SAVE_GLOBAL_TRACK_REMEMBER.getId(), applyToAllProfiles, false);
} else if (pref instanceof OsmandSettings.CommonPreference
&& !((OsmandSettings.CommonPreference) pref).hasDefaultValueForMode(getSelectedAppMode())) {
} else if (pref instanceof CommonPreference
&& !((CommonPreference) pref).hasDefaultValueForMode(getSelectedAppMode())) {
applyPreference(SAVE_GLOBAL_TRACK_INTERVAL, applyToAllProfiles, newValue);
applyPreference(settings.SAVE_GLOBAL_TRACK_REMEMBER.getId(), applyToAllProfiles, true);
}

View file

@ -49,6 +49,7 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
@ -760,7 +761,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
}
if (color == 0) {
final RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer();
final OsmandSettings.CommonPreference<String> prefColor
final CommonPreference<String> prefColor
= app.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR);
color = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColor(renderer, prefColor.get());
}

View file

@ -30,6 +30,7 @@ import net.osmand.plus.ContextMenuAdapter.ItemClickListener;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.EnumAdapter;
@ -355,7 +356,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
if (itemId == R.string.layer_osm_bugs) {
OsmandSettings.OsmandPreference<Boolean> showOsmBugs = settings.SHOW_OSM_BUGS;
OsmandPreference<Boolean> showOsmBugs = settings.SHOW_OSM_BUGS;
showOsmBugs.set(isChecked);
adapter.getItem(pos).setColorRes(showOsmBugs.get() ?
R.color.osmand_orange : ContextMenuItem.INVALID_ID);
@ -378,7 +379,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
if (itemId == R.string.layer_osm_edits) {
OsmandSettings.OsmandPreference<Boolean> showOsmEdits = settings.SHOW_OSM_EDITS;
OsmandPreference<Boolean> showOsmEdits = settings.SHOW_OSM_EDITS;
showOsmEdits.set(isChecked);
adapter.getItem(pos).setColorRes(showOsmEdits.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();

View file

@ -14,8 +14,8 @@ import net.osmand.plus.DialogListItemAdapter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;

View file

@ -29,7 +29,7 @@ import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;

View file

@ -15,6 +15,7 @@ import com.google.gson.reflect.TypeToken;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.LayerTransparencySeekbarMode;
import net.osmand.plus.R;
@ -144,7 +145,7 @@ public class MapUnderlayAction extends SwitchableAction<Pair<String, String>> {
}
final OsmandSettings.CommonPreference<Boolean> hidePolygonsPref =
final CommonPreference<Boolean> hidePolygonsPref =
activity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
hidePolygonsPref.set(hasUnderlay);

View file

@ -35,7 +35,7 @@ import net.osmand.plus.DialogListItemAdapter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings.LayerTransparencySeekbarMode;
import net.osmand.plus.R;
import net.osmand.plus.SQLiteTileSource;
@ -626,7 +626,7 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
OsmandMapTileView mapView = mapActivity.getMapView();
CommonPreference<String> mapTypePreference;
CommonPreference<String> exMapTypePreference;
OsmandSettings.CommonPreference<Integer> mapTransparencyPreference;
CommonPreference<Integer> mapTransparencyPreference;
//boolean isMapSelected;
MapTileLayer layer;

View file

@ -43,7 +43,7 @@ import net.osmand.plus.OsmAndAppCustomization.OsmAndAppCustomizationListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.development.OsmandDevelopmentPlugin;
import net.osmand.plus.render.OsmandRenderer.RenderingContext;

View file

@ -18,7 +18,7 @@ import net.osmand.data.MapObject;
import net.osmand.data.QuadRect;
import net.osmand.data.QuadTree;
import net.osmand.data.Street;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.resources.ResourceManager.BinaryMapReaderResource;
import net.osmand.plus.resources.ResourceManager.BinaryMapReaderResourceType;
import net.osmand.util.MapUtils;

View file

@ -20,7 +20,7 @@ import androidx.fragment.app.Fragment;
import net.osmand.AndroidUtils;
import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
@ -292,7 +292,7 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr
GeneralRouter.RoutingParameter parameter = routingOptionsHelper.getRoutingPrefsForAppModeById(app.getRoutingHelper().getAppMode(), parameterId);
if (parameter != null) {
boolean checked = entry.getValue();
OsmandSettings.CommonPreference<Boolean> preference = app.getSettings().getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean());
CommonPreference<Boolean> preference = app.getSettings().getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean());
preference.setModeValue(app.getRoutingHelper().getAppMode(), checked);
}
}
@ -318,7 +318,7 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr
List<GeneralRouter.RoutingParameter> avoidParameters = routingOptionsHelper.getAvoidRoutingPrefsForAppMode(app.getRoutingHelper().getAppMode());
for (GeneralRouter.RoutingParameter parameter : avoidParameters) {
OsmandSettings.CommonPreference<Boolean> preference = app.getSettings().getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean());
CommonPreference<Boolean> preference = app.getSettings().getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean());
res.put(parameter.getId(), preference.getModeValue(app.getRoutingHelper().getAppMode()));
}

View file

@ -54,8 +54,8 @@ import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint;

View file

@ -26,6 +26,8 @@ import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.DialogListItemAdapter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
@ -186,7 +188,7 @@ public class RoutingOptionsHelper {
public void applyVoiceProvider(MapActivity mapActivity, String provider, boolean applyAllModes) {
OsmandApplication app = mapActivity.getMyApplication();
ApplicationMode selectedAppMode = app.getRoutingHelper().getAppMode();
OsmandSettings.OsmandPreference<String> VP = app.getSettings().VOICE_PROVIDER;
OsmandPreference<String> VP = app.getSettings().VOICE_PROVIDER;
if (applyAllModes) {
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
VP.setModeValue(mode, provider);
@ -662,7 +664,7 @@ public class RoutingOptionsHelper {
}
public boolean isSelected(OsmandSettings settings) {
final OsmandSettings.CommonPreference<Boolean> property =
final CommonPreference<Boolean> property =
settings.getCustomRoutingBooleanProperty(routingParameter.getId(), routingParameter.getDefaultBoolean());
if (am != null) {
return property.getModeValue(am);
@ -672,7 +674,7 @@ public class RoutingOptionsHelper {
}
public void setSelected(OsmandSettings settings, boolean isChecked) {
final OsmandSettings.CommonPreference<Boolean> property =
final CommonPreference<Boolean> property =
settings.getCustomRoutingBooleanProperty(routingParameter.getId(), routingParameter.getDefaultBoolean());
if (am != null) {
property.setModeValue(am, isChecked);

View file

@ -22,7 +22,7 @@ import net.osmand.osm.io.NetworkUtils;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint;

View file

@ -16,6 +16,7 @@ import net.osmand.osm.edit.Node;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.render.NativeOsmandLibrary;
@ -478,7 +479,7 @@ public class TransportRoutingHelper {
GeneralRouter.RoutingParameter pr = e.getValue();
String vl;
if(pr.getType() == GeneralRouter.RoutingParameterType.BOOLEAN) {
OsmandSettings.CommonPreference<Boolean> pref = settings.getCustomRoutingBooleanProperty(key, pr.getDefaultBoolean());
CommonPreference<Boolean> pref = settings.getCustomRoutingBooleanProperty(key, pr.getDefaultBoolean());
Boolean bool = pref.getModeValue(params.mode);
vl = bool ? "true" : null;
} else {

View file

@ -0,0 +1,33 @@
package net.osmand.plus.settings.backend;
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;
}
@Override
public Boolean get() {
return osmandSettings.ctx.accessibilityEnabled() ? super.get() : getDefaultValue();
}
@Override
public Boolean getModeValue(ApplicationMode mode) {
return osmandSettings.ctx.accessibilityEnabledForMode(mode) ? super.getModeValue(mode) : getDefaultValue();
}
@Override
public boolean set(Boolean obj) {
return osmandSettings.ctx.accessibilityEnabled() && super.set(obj);
}
@Override
public boolean setModeValue(ApplicationMode mode, Boolean obj) {
return osmandSettings.ctx.accessibilityEnabledForMode(mode) && super.setModeValue(mode, obj);
}
}

View file

@ -0,0 +1,23 @@
package net.osmand.plus.settings.backend;
public class BooleanPreference extends CommonPreference<Boolean> {
BooleanPreference(OsmandSettings osmandSettings, String id, boolean defaultValue) {
super(osmandSettings, id, defaultValue);
}
@Override
protected Boolean getValue(Object prefs, Boolean defaultValue) {
return osmandSettings.settingsAPI.getBoolean(prefs, getId(), defaultValue);
}
@Override
protected boolean setValue(Object prefs, Boolean val) {
return osmandSettings.settingsAPI.edit(prefs).putBoolean(getId(), val).commit();
}
@Override
public Boolean parseString(String s) {
return Boolean.parseBoolean(s);
}
}

View file

@ -0,0 +1,234 @@
package net.osmand.plus.settings.backend;
import net.osmand.plus.ApplicationMode;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.LinkedHashMap;
import java.util.Map;
public abstract class CommonPreference<T> extends PreferenceWithListener<T> {
private OsmandSettings osmandSettings;
private final String id;
private boolean global;
private T cachedValue;
private Object cachedPreference;
private boolean cache;
private Map<ApplicationMode, T> defaultValues;
private T defaultValue;
public CommonPreference(OsmandSettings osmandSettings, String id, T defaultValue) {
this.osmandSettings = osmandSettings;
this.id = id;
this.defaultValue = defaultValue;
osmandSettings.registerInternalPreference(id, this);
}
// Methods to possibly override
protected 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();
}
// common methods
public final CommonPreference<T> makeGlobal() {
global = true;
return this;
}
public final CommonPreference<T> cache() {
cache = true;
return this;
}
public final CommonPreference<T> makeProfile() {
global = false;
return this;
}
protected final Object getPreferences() {
return osmandSettings.getPreferences(global);
}
public final void setModeDefaultValue(ApplicationMode mode, T defValue) {
if (defaultValues == null) {
defaultValues = new LinkedHashMap<ApplicationMode, T>();
}
defaultValues.put(mode, defValue);
}
// TODO final
@Override
public boolean setModeValue(ApplicationMode mode, T obj) {
if (global) {
return set(obj);
}
Object profilePrefs = osmandSettings.getProfilePreferences(mode);
boolean valueSaved = setValue(profilePrefs, obj);
if (valueSaved && cache && cachedPreference == profilePrefs) {
cachedValue = obj;
}
fireEvent(obj);
return valueSaved;
}
// TODO final
public T getProfileDefaultValue(ApplicationMode mode) {
if (global) {
return defaultValue;
}
if (defaultValues != null && defaultValues.containsKey(mode)) {
return defaultValues.get(mode);
}
ApplicationMode pt = mode.getParent();
if (pt != null) {
return getProfileDefaultValue(pt);
}
return defaultValue;
}
public final boolean hasDefaultValues() {
return defaultValues != null && !defaultValues.isEmpty();
}
public final boolean hasDefaultValueForMode(ApplicationMode mode) {
return defaultValues != null && defaultValues.containsKey(mode);
}
// TODO final
protected T getDefaultValue() {
return getProfileDefaultValue(osmandSettings.currentMode);
}
@Override
public final void overrideDefaultValue(T newDefaultValue) {
this.defaultValue = newDefaultValue;
}
// TODO final
@Override
public T getModeValue(ApplicationMode mode) {
if (global) {
return get();
}
T defaultV = getProfileDefaultValue(mode);
return getValue(osmandSettings.getProfilePreferences(mode), defaultV);
}
// TODO final
@Override
public T get() {
if (cache && cachedValue != null && cachedPreference == getPreferences()) {
return cachedValue;
}
cachedPreference = getPreferences();
cachedValue = getValue(cachedPreference, getProfileDefaultValue(osmandSettings.currentMode));
return cachedValue;
}
@Override
public final String getId() {
return id;
}
@Override
public final void resetToDefault() {
T o = getProfileDefaultValue(osmandSettings.currentMode);
set(o);
}
@Override
public final void resetModeToDefault(ApplicationMode mode) {
if (global) {
resetToDefault();
} else {
T o = getProfileDefaultValue(mode);
setModeValue(mode, o);
}
}
// TODO final
@Override
public boolean set(T obj) {
Object prefs = getPreferences();
if (setValue(prefs, obj)) {
cachedValue = obj;
cachedPreference = prefs;
fireEvent(obj);
return true;
}
return false;
}
public final boolean isSet() {
return osmandSettings.isSet(global, getId());
}
public boolean isSetForMode(ApplicationMode mode) {
return osmandSettings.isSet(mode, getId());
}
public final boolean isGlobal() {
return global;
}
// TODO final
@Override
public boolean writeToJson(JSONObject json, ApplicationMode appMode) throws JSONException {
if (appMode != null) {
if (!global) {
String value = asStringModeValue(appMode);
if (value != null) {
json.put(getId(), value);
}
return true;
}
} else if (global) {
String value = asString();
if (value != null) {
json.put(getId(), value);
}
return true;
}
return false;
}
// TODO final
@Override
public void readFromJson(JSONObject json, ApplicationMode appMode) throws JSONException {
if (appMode != null) {
if (!global) {
String modeValue = json.getString(getId());
setModeValue(appMode, parseString(modeValue));
}
} else if (global) {
String globalValue = json.getString(getId());
set(parseString(globalValue));
}
}
@Override
public final String asString() {
T o = get();
return toString(o);
}
@Override
public final String asStringModeValue(ApplicationMode m) {
T v = getModeValue(m);
return toString(v);
}
}

View file

@ -0,0 +1,48 @@
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;
this.idScheme = idScheme;
}
@Override
protected ContextMenuItemsSettings getValue(Object prefs, ContextMenuItemsSettings defaultValue) {
String s = osmandSettings.settingsAPI.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();
}
@Override
protected String toString(ContextMenuItemsSettings o) {
return o.writeToJsonString(idScheme);
}
@Override
public ContextMenuItemsSettings parseString(String s) {
return readValue(s);
}
private ContextMenuItemsSettings readValue(String s) {
ContextMenuItemsSettings value = getDefaultValue().newInstance();
value.readFromJsonString(s, idScheme);
return value;
}
@NonNull
public String getIdScheme() {
return idScheme;
}
}

View file

@ -0,0 +1,96 @@
package net.osmand.plus.settings.backend;
import net.osmand.util.Algorithms;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import androidx.annotation.NonNull;
public class ContextMenuItemsSettings implements Serializable {
private static final String HIDDEN = "hidden";
private static final String ORDER = "order";
private List<String> hiddenIds = new ArrayList<>();
private List<String> orderIds = new ArrayList<>();
public ContextMenuItemsSettings() {
}
public ContextMenuItemsSettings(@NonNull List<String> hiddenIds, @NonNull List<String> orderIds) {
this.hiddenIds = hiddenIds;
this.orderIds = orderIds;
}
public ContextMenuItemsSettings newInstance() {
return new ContextMenuItemsSettings();
}
public void readFromJsonString(String jsonString, @NonNull String idScheme) {
if (Algorithms.isEmpty(jsonString)) {
return;
}
try {
JSONObject json = new JSONObject(jsonString);
readFromJson(json, idScheme);
} catch (JSONException e) {
OsmandSettings.LOG.error("Error converting to json string: " + e);
}
}
public void readFromJson(JSONObject json, String idScheme) {
hiddenIds = readIdsList(json.optJSONArray(HIDDEN), idScheme);
orderIds = readIdsList(json.optJSONArray(ORDER), idScheme);
}
protected List<String> readIdsList(JSONArray jsonArray, @NonNull String idScheme) {
List<String> list = new ArrayList<>();
if (jsonArray != null) {
for (int i = 0; i < jsonArray.length(); i++) {
String id = jsonArray.optString(i);
list.add(idScheme + id);
}
}
return list;
}
public String writeToJsonString(@NonNull String idScheme) {
try {
JSONObject json = new JSONObject();
writeToJson(json, idScheme);
return json.toString();
} catch (JSONException e) {
OsmandSettings.LOG.error("Error converting to json string: " + e);
}
return "";
}
public void writeToJson(JSONObject json, String idScheme) throws JSONException {
json.put(HIDDEN, getJsonArray(hiddenIds, idScheme));
json.put(ORDER, getJsonArray(orderIds, idScheme));
}
protected JSONArray getJsonArray(List<String> ids, @NonNull String idScheme) {
JSONArray jsonArray = new JSONArray();
if (ids != null && !ids.isEmpty()) {
for (String id : ids) {
jsonArray.put(id.replace(idScheme, ""));
}
}
return jsonArray;
}
public List<String> getHiddenIds() {
return Collections.unmodifiableList(hiddenIds);
}
public List<String> getOrderIds() {
return Collections.unmodifiableList(orderIds);
}
}

View file

@ -0,0 +1,45 @@
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;
this.values = values;
}
@Override
protected E getValue(Object prefs, E defaultValue) {
try {
String name = osmandSettings.settingsAPI.getString(prefs, getId(), defaultValue.name());
E value = parseString(name);
return value != null ? value : defaultValue;
} catch (ClassCastException ex) {
setValue(prefs, defaultValue);
}
return defaultValue;
}
@Override
protected boolean setValue(Object prefs, E val) {
return osmandSettings.settingsAPI.edit(prefs).putString(getId(), val.name()).commit();
}
@Override
protected String toString(E o) {
return o.name();
}
@Override
public E parseString(String s) {
for (E value : values) {
if (value.name().equals(s)) {
return value;
}
}
return null;
}
}

View file

@ -0,0 +1,27 @@
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;
}
@Override
protected Float getValue(Object prefs, Float defaultValue) {
return osmandSettings.settingsAPI.getFloat(prefs, getId(), defaultValue);
}
@Override
protected boolean setValue(Object prefs, Float val) {
return osmandSettings.settingsAPI.edit(prefs).putFloat(getId(), val).commit();
}
@Override
public Float parseString(String s) {
return Float.parseFloat(s);
}
}

View file

@ -0,0 +1,194 @@
package net.osmand.plus.settings.backend;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.helpers.AvoidSpecificRoads;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
class ImpassableRoadsStorage extends SettingsMapPointsStorage {
private OsmandSettings osmandSettings;
protected String roadsIdsKey;
protected String appModeKey;
public ImpassableRoadsStorage(OsmandSettings osmandSettings) {
this.osmandSettings = osmandSettings;
pointsKey = OsmandSettings.IMPASSABLE_ROAD_POINTS;
descriptionsKey = OsmandSettings.IMPASSABLE_ROADS_DESCRIPTIONS;
roadsIdsKey = OsmandSettings.IMPASSABLE_ROADS_IDS;
appModeKey = OsmandSettings.IMPASSABLE_ROADS_APP_MODE_KEYS;
}
public List<Long> getRoadIds(int size) {
List<Long> list = new ArrayList<>();
String roadIds = osmandSettings.settingsAPI.getString(osmandSettings.globalPreferences, roadsIdsKey, "");
if (roadIds.trim().length() > 0) {
StringTokenizer tok = new StringTokenizer(roadIds, ",");
while (tok.hasMoreTokens() && list.size() <= size) {
list.add(Long.parseLong(tok.nextToken()));
}
}
while (list.size() < size) {
list.add(0L);
}
return list;
}
public List<String> getAppModeKeys(int size) {
List<String> list = new ArrayList<>();
String roadIds = osmandSettings.settingsAPI.getString(osmandSettings.globalPreferences, appModeKey, "");
if (roadIds.trim().length() > 0) {
StringTokenizer tok = new StringTokenizer(roadIds, ",");
while (tok.hasMoreTokens() && list.size() <= size) {
list.add(tok.nextToken());
}
}
while (list.size() < size) {
list.add("");
}
return list;
}
public List<AvoidSpecificRoads.AvoidRoadInfo> getImpassableRoadsInfo() {
List<LatLon> points = getPoints();
List<Long> roadIds = getRoadIds(points.size());
List<String> appModeKeys = getAppModeKeys(points.size());
List<String> descriptions = getPointDescriptions(points.size());
List<AvoidSpecificRoads.AvoidRoadInfo> avoidRoadsInfo = new ArrayList<>();
for (int i = 0; i < points.size(); i++) {
LatLon latLon = points.get(i);
PointDescription description = PointDescription.deserializeFromString(descriptions.get(i), null);
AvoidSpecificRoads.AvoidRoadInfo avoidRoadInfo = new AvoidSpecificRoads.AvoidRoadInfo();
avoidRoadInfo.id = roadIds.get(i);
avoidRoadInfo.latitude = latLon.getLatitude();
avoidRoadInfo.longitude = latLon.getLongitude();
avoidRoadInfo.name = description.getName();
avoidRoadInfo.appModeKey = appModeKeys.get(i);
avoidRoadsInfo.add(avoidRoadInfo);
}
return avoidRoadsInfo;
}
public boolean addImpassableRoadInfo(AvoidSpecificRoads.AvoidRoadInfo avoidRoadInfo) {
List<LatLon> points = getPoints();
List<Long> roadIds = getRoadIds(points.size());
List<String> appModeKeys = getAppModeKeys(points.size());
List<String> descriptions = getPointDescriptions(points.size());
roadIds.add(0, avoidRoadInfo.id);
points.add(0, new LatLon(avoidRoadInfo.latitude, avoidRoadInfo.longitude));
appModeKeys.add(0, avoidRoadInfo.appModeKey);
descriptions.add(0, PointDescription.serializeToString(new PointDescription("", avoidRoadInfo.name)));
return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys);
}
public boolean updateImpassableRoadInfo(AvoidSpecificRoads.AvoidRoadInfo avoidRoadInfo) {
List<LatLon> points = getPoints();
int index = points.indexOf(new LatLon(avoidRoadInfo.latitude, avoidRoadInfo.longitude));
if (index != -1) {
List<Long> roadIds = getRoadIds(points.size());
List<String> appModeKeys = getAppModeKeys(points.size());
List<String> descriptions = getPointDescriptions(points.size());
roadIds.set(index, avoidRoadInfo.id);
appModeKeys.set(index, avoidRoadInfo.appModeKey);
descriptions.set(index, PointDescription.serializeToString(new PointDescription("", avoidRoadInfo.name)));
return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys);
}
return false;
}
@Override
public boolean deletePoint(int index) {
List<LatLon> points = getPoints();
List<Long> roadIds = getRoadIds(points.size());
List<String> appModeKeys = getAppModeKeys(points.size());
List<String> descriptions = getPointDescriptions(points.size());
if (index < points.size()) {
points.remove(index);
roadIds.remove(index);
appModeKeys.remove(index);
descriptions.remove(index);
return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys);
}
return false;
}
@Override
public boolean deletePoint(LatLon latLon) {
List<LatLon> points = getPoints();
List<Long> roadIds = getRoadIds(points.size());
List<String> appModeKeys = getAppModeKeys(points.size());
List<String> descriptions = getPointDescriptions(points.size());
int index = points.indexOf(latLon);
if (index != -1) {
points.remove(index);
roadIds.remove(index);
appModeKeys.remove(index);
descriptions.remove(index);
return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys);
}
return false;
}
@Override
public boolean movePoint(LatLon latLonEx, LatLon latLonNew) {
List<LatLon> points = getPoints();
List<Long> roadIds = getRoadIds(points.size());
List<String> appModeKeys = getAppModeKeys(points.size());
List<String> descriptions = getPointDescriptions(points.size());
int i = points.indexOf(latLonEx);
if (i != -1) {
points.set(i, latLonNew);
return saveAvoidRoadData(points, descriptions, roadIds, appModeKeys);
} else {
return false;
}
}
public boolean saveAvoidRoadData(List<LatLon> points, List<String> descriptions,
List<Long> roadIds, List<String> appModeKeys) {
return savePoints(points, descriptions) && saveRoadIds(roadIds) && saveAppModeKeys(appModeKeys);
}
public boolean saveRoadIds(List<Long> roadIds) {
StringBuilder stringBuilder = new StringBuilder();
Iterator<Long> iterator = roadIds.iterator();
while (iterator.hasNext()) {
stringBuilder.append(iterator.next());
if (iterator.hasNext()) {
stringBuilder.append(",");
}
}
return osmandSettings.settingsAPI.edit(osmandSettings.globalPreferences)
.putString(roadsIdsKey, stringBuilder.toString())
.commit();
}
public boolean saveAppModeKeys(List<String> appModeKeys) {
StringBuilder stringBuilder = new StringBuilder();
Iterator<String> iterator = appModeKeys.iterator();
while (iterator.hasNext()) {
stringBuilder.append(iterator.next());
if (iterator.hasNext()) {
stringBuilder.append(",");
}
}
return osmandSettings.settingsAPI.edit(osmandSettings.globalPreferences)
.putString(appModeKey, stringBuilder.toString())
.commit();
}
}

View file

@ -0,0 +1,27 @@
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;
}
@Override
protected Integer getValue(Object prefs, Integer defaultValue) {
return osmandSettings.settingsAPI.getInt(prefs, getId(), defaultValue);
}
@Override
protected boolean setValue(Object prefs, Integer val) {
return osmandSettings.settingsAPI.edit(prefs).putInt(getId(), val).commit();
}
@Override
public Integer parseString(String s) {
return Integer.parseInt(s);
}
}

View file

@ -0,0 +1,23 @@
package net.osmand.plus.settings.backend;
import net.osmand.data.LatLon;
import java.util.List;
class IntermediatePointsStorage extends SettingsMapPointsStorage {
private OsmandSettings osmandSettings;
public IntermediatePointsStorage(OsmandSettings osmandSettings) {
this.osmandSettings = osmandSettings;
pointsKey = OsmandSettings.INTERMEDIATE_POINTS;
descriptionsKey = OsmandSettings.INTERMEDIATE_POINTS_DESCRIPTION;
}
@Override
public boolean savePoints(List<LatLon> ps, List<String> ds) {
boolean res = super.savePoints(ps, ds);
osmandSettings.backupTargetPoints();
return res;
}
}

View file

@ -0,0 +1,127 @@
package net.osmand.plus.settings.backend;
import net.osmand.plus.ApplicationMode;
import java.util.ArrayList;
import java.util.Arrays;
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;
this.delimiter = delimiter;
}
public boolean addValue(String res) {
return addModeValue(osmandSettings.getApplicationMode(), res);
}
public boolean addModeValue(ApplicationMode appMode, String res) {
String vl = getModeValue(appMode);
if (vl == null || vl.isEmpty()) {
vl = res + delimiter;
} else {
vl = vl + res + delimiter;
}
setModeValue(appMode, vl);
return true;
}
public void clearAll() {
clearAllForProfile(osmandSettings.getApplicationMode());
}
public void clearAllForProfile(ApplicationMode appMode) {
setModeValue(appMode, "");
}
public boolean containsValue(String res) {
return containsValue(osmandSettings.getApplicationMode(), res);
}
public boolean containsValue(ApplicationMode appMode, String res) {
String vl = getModeValue(appMode);
String r = res + delimiter;
return vl.startsWith(r) || vl.contains(delimiter + r);
}
public boolean removeValue(String res) {
return removeValueForProfile(osmandSettings.getApplicationMode(), res);
}
public boolean removeValueForProfile(ApplicationMode appMode, String res) {
String vl = getModeValue(appMode);
String r = res + delimiter;
if(vl != null) {
if(vl.startsWith(r)) {
vl = vl.substring(r.length());
setModeValue(appMode, vl);
return true;
} else {
int it = vl.indexOf(delimiter + r);
if(it >= 0) {
vl = vl.substring(0, it + delimiter.length()) + vl.substring(it + delimiter.length() + r.length());
}
setModeValue(appMode, vl);
return true;
}
}
return false;
}
public List<String> getStringsList() {
return getStringsListForProfile(osmandSettings.getApplicationMode());
}
public List<String> getStringsListForProfile(ApplicationMode appMode) {
final String listAsString = getModeValue(appMode);
if (listAsString != null) {
if (listAsString.contains(delimiter)) {
return Arrays.asList(listAsString.split(delimiter));
} else {
return new ArrayList<String>() {
{add(listAsString);}
};
}
}
return null;
}
public void setStringsList(List<String> values) {
setStringsListForProfile(osmandSettings.getApplicationMode(), values);
}
public void setStringsListForProfile(ApplicationMode appMode, List<String> values) {
if (values == null || values.size() == 0) {
setModeValue(appMode, null);
return;
}
clearAllForProfile(appMode);
for (String value : values) {
addModeValue(appMode, value);
}
}
public boolean setModeValues(ApplicationMode mode, List<String> values) {
if (values == null || values.size() == 0) {
setModeValue(mode,null);
return false;
}
clearAll();
String vl = get();
for (String value : values) {
addValue(value);
if (vl == null || vl.isEmpty()) {
vl = value + delimiter;
} else {
vl = vl + value + delimiter;
}
}
return setModeValue(mode, vl);
}
}

View file

@ -0,0 +1,27 @@
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;
}
@Override
protected Long getValue(Object prefs, Long defaultValue) {
return osmandSettings.settingsAPI.getLong(prefs, getId(), defaultValue);
}
@Override
protected boolean setValue(Object prefs, Long val) {
return osmandSettings.settingsAPI.edit(prefs).putLong(getId(), val).commit();
}
@Override
public Long parseString(String s) {
return Long.parseLong(s);
}
}

View file

@ -0,0 +1,45 @@
package net.osmand.plus.settings.backend;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import androidx.annotation.NonNull;
public class MainContextMenuItemsSettings extends ContextMenuItemsSettings {
private static final String MAIN = "main";
private List<String> mainIds = new ArrayList<>();
public MainContextMenuItemsSettings() {
}
public MainContextMenuItemsSettings(@NonNull List<String> mainIds, @NonNull List<String> hiddenIds, @NonNull List<String> orderIds) {
super(hiddenIds, orderIds);
this.mainIds = mainIds;
}
@Override
public ContextMenuItemsSettings newInstance() {
return new MainContextMenuItemsSettings();
}
@Override
public void readFromJson(JSONObject json, String idScheme) {
super.readFromJson(json, idScheme);
mainIds = readIdsList(json.optJSONArray(MAIN), idScheme);
}
@Override
public void writeToJson(JSONObject json, String idScheme) throws JSONException {
super.writeToJson(json, idScheme);
json.put(MAIN, getJsonArray(mainIds, idScheme));
}
public List<String> getMainIds() {
return Collections.unmodifiableList(mainIds);
}
}

View file

@ -0,0 +1,120 @@
package net.osmand.plus.settings.backend;
import net.osmand.plus.ApplicationMode;
import java.util.Set;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.PreferenceDataStore;
public class OsmAndPreferencesDataStore extends PreferenceDataStore {
private OsmandSettings osmandSettings;
private ApplicationMode appMode;
public OsmAndPreferencesDataStore(OsmandSettings osmandSettings, @NonNull ApplicationMode appMode) {
this.osmandSettings = osmandSettings;
this.appMode = appMode;
}
@Override
public void putString(String key, @Nullable String value) {
osmandSettings.setPreference(key, value, appMode);
}
@Override
public void putStringSet(String key, @Nullable Set<String> values) {
osmandSettings.setPreference(key, values, appMode);
}
@Override
public void putInt(String key, int value) {
osmandSettings.setPreference(key, value, appMode);
}
@Override
public void putLong(String key, long value) {
osmandSettings.setPreference(key, value, appMode);
}
@Override
public void putFloat(String key, float value) {
osmandSettings.setPreference(key, value, appMode);
}
@Override
public void putBoolean(String key, boolean value) {
osmandSettings.setPreference(key, value, appMode);
}
public void putValue(String key, Object value) {
osmandSettings.setPreference(key, value, appMode);
}
@Nullable
@Override
public String getString(String key, @Nullable String defValue) {
OsmandPreference preference = osmandSettings.getPreference(key);
if (preference instanceof StringPreference) {
return ((StringPreference) preference).getModeValue(appMode);
} else {
Object value = preference.getModeValue(appMode);
if (value != null) {
return value.toString();
}
}
return defValue;
}
@Nullable
@Override
public Set<String> getStringSet(String key, @Nullable Set<String> defValues) {
return super.getStringSet(key, defValues);
}
@Override
public int getInt(String key, int defValue) {
OsmandPreference preference = osmandSettings.getPreference(key);
if (preference instanceof OsmandSettings.IntPreference) {
return ((OsmandSettings.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);
}
return defValue;
}
@Override
public float getFloat(String key, float defValue) {
OsmandPreference preference = osmandSettings.getPreference(key);
if (preference instanceof FloatPreference) {
return ((FloatPreference) preference).getModeValue(appMode);
}
return defValue;
}
@Override
public boolean getBoolean(String key, boolean defValue) {
OsmandPreference preference = osmandSettings.getPreference(key);
if (preference instanceof BooleanPreference) {
return ((BooleanPreference) preference).getModeValue(appMode);
}
return defValue;
}
@Nullable
public Object getValue(String key, Object defValue) {
OsmandPreference preference = osmandSettings.getPreference(key);
if (preference != null) {
return preference.getModeValue(appMode);
}
return defValue;
}
}

View file

@ -0,0 +1,43 @@
package net.osmand.plus.settings.backend;
import net.osmand.StateChangedListener;
import net.osmand.plus.ApplicationMode;
import org.json.JSONException;
import org.json.JSONObject;
public interface OsmandPreference<T> {
T get();
boolean set(T obj);
boolean setModeValue(ApplicationMode m, T obj);
T getModeValue(ApplicationMode m);
String getId();
void resetToDefault();
void resetModeToDefault(ApplicationMode m);
void overrideDefaultValue(T newDefaultValue);
void addListener(StateChangedListener<T> listener);
void removeListener(StateChangedListener<T> listener);
boolean isSet();
boolean isSetForMode(ApplicationMode m);
boolean writeToJson(JSONObject json, ApplicationMode appMode) throws JSONException;
void readFromJson(JSONObject json, ApplicationMode appMode) throws JSONException;
String asString();
String asStringModeValue(ApplicationMode m);
T parseString(String s);
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,49 @@
package net.osmand.plus.settings.backend;
import net.osmand.StateChangedListener;
import java.lang.ref.WeakReference;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
abstract class PreferenceWithListener<T> implements OsmandPreference<T> {
private List<WeakReference<StateChangedListener<T>>> l = null;
@Override
public synchronized void addListener(StateChangedListener<T> listener) {
if (l == null) {
l = new LinkedList<WeakReference<StateChangedListener<T>>>();
}
if (!l.contains(new WeakReference<StateChangedListener<T>>(listener))) {
l.add(new WeakReference<StateChangedListener<T>>(listener));
}
}
public synchronized void fireEvent(T value) {
if (l != null) {
Iterator<WeakReference<StateChangedListener<T>>> it = l.iterator();
while (it.hasNext()) {
StateChangedListener<T> t = it.next().get();
if (t == null) {
it.remove();
} else {
t.stateChanged(value);
}
}
}
}
@Override
public synchronized void removeListener(StateChangedListener<T> listener) {
if (l != null) {
Iterator<WeakReference<StateChangedListener<T>>> it = l.iterator();
while (it.hasNext()) {
StateChangedListener<T> t = it.next().get();
if (t == listener) {
it.remove();
}
}
}
}
}

View file

@ -30,7 +30,6 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.SQLiteTileSource;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.helpers.AvoidSpecificRoads;
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
import net.osmand.plus.poi.PoiUIFilter;
@ -907,6 +906,19 @@ 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 {
private ApplicationMode appMode;

View file

@ -0,0 +1,141 @@
package net.osmand.plus.settings.backend;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.helpers.SearchHistoryHelper;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
abstract class SettingsMapPointsStorage {
private OsmandSettings osmandSettings;
protected String pointsKey;
protected String descriptionsKey;
public SettingsMapPointsStorage(OsmandSettings osmandSettings) {
this.osmandSettings = osmandSettings;
}
public List<String> getPointDescriptions(int sz) {
List<String> list = new ArrayList<>();
String ip = osmandSettings.settingsAPI.getString(osmandSettings.globalPreferences, descriptionsKey, "");
if (ip.trim().length() > 0) {
list.addAll(Arrays.asList(ip.split("--")));
}
while (list.size() > sz) {
list.remove(list.size() - 1);
}
while (list.size() < sz) {
list.add("");
}
return list;
}
public List<LatLon> getPoints() {
List<LatLon> list = new ArrayList<>();
String ip = osmandSettings.settingsAPI.getString(osmandSettings.globalPreferences, pointsKey, "");
if (ip.trim().length() > 0) {
StringTokenizer tok = new StringTokenizer(ip, ",");
while (tok.hasMoreTokens()) {
String lat = tok.nextToken();
if (!tok.hasMoreTokens()) {
break;
}
String lon = tok.nextToken();
list.add(new LatLon(Float.parseFloat(lat), Float.parseFloat(lon)));
}
}
return list;
}
public boolean insertPoint(double latitude, double longitude, PointDescription historyDescription, int index) {
List<LatLon> ps = getPoints();
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);
}
return savePoints(ps, ds);
}
public boolean updatePoint(double latitude, double longitude, PointDescription historyDescription) {
List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size());
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);
}
return savePoints(ps, ds);
} else {
return false;
}
}
public boolean deletePoint(int index) {
List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size());
if (index < ps.size()) {
ps.remove(index);
ds.remove(index);
return savePoints(ps, ds);
} else {
return false;
}
}
public boolean deletePoint(LatLon latLon) {
List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size());
int index = ps.indexOf(latLon);
if (index != -1) {
ps.remove(index);
ds.remove(index);
return savePoints(ps, ds);
} else {
return false;
}
}
public boolean savePoints(List<LatLon> ps, List<String> ds) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < ps.size(); i++) {
if (i > 0) {
sb.append(",");
}
sb.append(((float) ps.get(i).getLatitude() + "")).append(",").append(((float) ps.get(i).getLongitude() + ""));
}
StringBuilder tb = new StringBuilder();
for (int i = 0; i < ds.size(); i++) {
if (i > 0) {
tb.append("--");
}
if (ds.get(i) == null) {
tb.append("");
} else {
tb.append(ds.get(i));
}
}
return osmandSettings.settingsAPI.edit(osmandSettings.globalPreferences)
.putString(pointsKey, sb.toString())
.putString(descriptionsKey, tb.toString())
.commit();
}
public boolean movePoint(LatLon latLonEx, LatLon latLonNew) {
List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size());
int i = ps.indexOf(latLonEx);
if (i != -1) {
ps.set(i, latLonNew);
return savePoints(ps, ds);
} else {
return false;
}
}
}

View file

@ -0,0 +1,26 @@
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;
}
@Override
protected String getValue(Object prefs, String defaultValue) {
return osmandSettings.settingsAPI.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();
}
@Override
public String parseString(String s) {
return s;
}
}

View file

@ -16,9 +16,8 @@ import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.BooleanPreference;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.settings.backend.BooleanPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
@ -57,7 +56,7 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
String title = switchPreference.getTitle().toString();
items.add(new TitleItem(title));
final OsmandSettings.BooleanPreference pref = (BooleanPreference) preference;
final BooleanPreference pref = (BooleanPreference) preference;
CharSequence summaryOn = switchPreference.getSummaryOn();
CharSequence summaryOff = switchPreference.getSummaryOff();
final String on = summaryOn == null || summaryOn.toString().equals("")

View file

@ -17,6 +17,7 @@ import net.osmand.AndroidUtils;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
@ -43,7 +44,7 @@ public class RecalculateRouteInDeviationBottomSheet extends BooleanPreferenceBot
private OsmandApplication app;
private OsmandSettings settings;
private ApplicationMode appMode;
private OsmandSettings.CommonPreference<Float> preference;
private CommonPreference<Float> preference;
private Slider slider;
private TextView tvSliderTitle;

View file

@ -54,8 +54,9 @@ import net.osmand.PlatformUtil;
import net.osmand.access.AccessibilitySettingsFragment;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
@ -833,11 +834,11 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
return icon;
}
public SwitchPreferenceCompat createSwitchPreference(OsmandSettings.OsmandPreference<Boolean> b, int title, int summary, int layoutId) {
public SwitchPreferenceCompat createSwitchPreference(OsmandPreference<Boolean> b, int title, int summary, int layoutId) {
return createSwitchPreference(b, getString(title), getString(summary), layoutId);
}
public SwitchPreferenceCompat createSwitchPreference(OsmandSettings.OsmandPreference<Boolean> b, String title, String summary, int layoutId) {
public SwitchPreferenceCompat createSwitchPreference(OsmandPreference<Boolean> b, String title, String summary, int layoutId) {
SwitchPreferenceCompat p = new SwitchPreferenceCompat(getContext());
p.setTitle(title);
p.setKey(b.getId());

View file

@ -28,7 +28,9 @@ import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.ContextMenuItemsPreference;
import net.osmand.plus.settings.backend.ContextMenuItemsSettings;
import net.osmand.plus.settings.backend.MainContextMenuItemsSettings;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
@ -163,9 +165,9 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
private void initMainActionsIds(ApplicationMode appMode) {
List<ContextMenuItem> defItems = getCustomizableDefaultItems(contextMenuAdapter.getDefaultItems());
OsmandSettings.ContextMenuItemsSettings pref = getSettingForScreen(app, screenType).getModeValue(appMode);
if (pref instanceof OsmandSettings.MainContextMenuItemsSettings) {
mainActionItems = new ArrayList<>(((OsmandSettings.MainContextMenuItemsSettings) pref).getMainIds());
ContextMenuItemsSettings pref = getSettingForScreen(app, screenType).getModeValue(appMode);
if (pref instanceof MainContextMenuItemsSettings) {
mainActionItems = new ArrayList<>(((MainContextMenuItemsSettings) pref).getMainIds());
if (mainActionItems.isEmpty()) {
for (int i = 0; i < MAIN_BUTTONS_QUANTITY; i++) {
mainActionItems.add(defItems.get(i).getId());
@ -255,11 +257,11 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
}
}
FragmentManager fm = getFragmentManager();
final OsmandSettings.ContextMenuItemsSettings prefToSave;
final ContextMenuItemsSettings prefToSave;
if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) {
prefToSave = new OsmandSettings.MainContextMenuItemsSettings(mainActionItems, hiddenMenuItems, ids);
prefToSave = new MainContextMenuItemsSettings(mainActionItems, hiddenMenuItems, ids);
} else {
prefToSave = new OsmandSettings.ContextMenuItemsSettings(hiddenMenuItems, ids);
prefToSave = new ContextMenuItemsSettings(hiddenMenuItems, ids);
}
if (fm != null) {
ChangeGeneralProfilesPrefBottomSheet.showInstance(fm,
@ -523,7 +525,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
}
}
public static OsmandSettings.ContextMenuItemsPreference getSettingForScreen(OsmandApplication app, ScreenType screenType) throws IllegalArgumentException {
public static ContextMenuItemsPreference getSettingForScreen(OsmandApplication app, ScreenType screenType) throws IllegalArgumentException {
switch (screenType) {
case DRAWER:
return app.getSettings().DRAWER_ITEMS;

View file

@ -25,8 +25,9 @@ import net.osmand.StateChangedListener;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.BooleanPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.settings.backend.BooleanPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.SettingsBaseActivity;
@ -218,7 +219,7 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
String description = SettingsBaseActivity.getRoutingStringPropertyDescription(app, p.getId(), p.getDescription());
if (p.getType() == RoutingParameterType.BOOLEAN) {
OsmandSettings.OsmandPreference pref = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean());
OsmandPreference pref = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean());
SwitchPreferenceEx switchPreferenceEx = (SwitchPreferenceEx) createSwitchPreferenceEx(pref.getId(), title, description, R.layout.preference_with_descr_dialog_and_switch);
switchPreferenceEx.setDescription(description);
@ -234,7 +235,7 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
for (Object o : vls) {
svlss[i++] = o.toString();
}
OsmandSettings.OsmandPreference pref = settings.getCustomRoutingProperty(p.getId(), p.getType() == RoutingParameterType.NUMERIC ? "0.0" : "-");
OsmandPreference pref = settings.getCustomRoutingProperty(p.getId(), p.getType() == RoutingParameterType.NUMERIC ? "0.0" : "-");
ListPreferenceEx listPreferenceEx = (ListPreferenceEx) createListPreferenceEx(pref.getId(), p.getPossibleValueDescriptions(), svlss, title, R.layout.preference_with_descr);
listPreferenceEx.setDescription(description);
@ -381,10 +382,10 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
for (RoutingParameter parameter : otherRoutingParameters) {
if (parameter.getType() == RoutingParameterType.BOOLEAN) {
OsmandSettings.CommonPreference<Boolean> pref = settings.getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean());
CommonPreference<Boolean> pref = settings.getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean());
pref.addListener(booleanRoutingPrefListener);
} else {
OsmandSettings.CommonPreference<String> pref = settings.getCustomRoutingProperty(parameter.getId(), parameter.getType() == RoutingParameterType.NUMERIC ? "0.0" : "-");
CommonPreference<String> pref = settings.getCustomRoutingProperty(parameter.getId(), parameter.getType() == RoutingParameterType.NUMERIC ? "0.0" : "-");
pref.addListener(customRoutingPrefListener);
}
}
@ -396,10 +397,10 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
for (RoutingParameter parameter : otherRoutingParameters) {
if (parameter.getType() == RoutingParameterType.BOOLEAN) {
OsmandSettings.CommonPreference<Boolean> pref = settings.getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean());
CommonPreference<Boolean> pref = settings.getCustomRoutingBooleanProperty(parameter.getId(), parameter.getDefaultBoolean());
pref.removeListener(booleanRoutingPrefListener);
} else {
OsmandSettings.CommonPreference<String> pref = settings.getCustomRoutingProperty(parameter.getId(), parameter.getType() == RoutingParameterType.NUMERIC ? "0.0" : "-");
CommonPreference<String> pref = settings.getCustomRoutingProperty(parameter.getId(), parameter.getType() == RoutingParameterType.NUMERIC ? "0.0" : "-");
pref.removeListener(customRoutingPrefListener);
}
}

View file

@ -9,11 +9,11 @@ import androidx.preference.PreferenceViewHolder;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.StringPreference;
import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.router.GeneralRouter;
@ -77,7 +77,7 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O
String description = SettingsBaseActivity.getRoutingStringPropertyDescription(app, parameterId, parameter.getDescription());
String defValue = parameter.getType() == GeneralRouter.RoutingParameterType.NUMERIC ? ROUTING_PARAMETER_NUMERIC_DEFAULT : ROUTING_PARAMETER_SYMBOLIC_DEFAULT;
OsmandSettings.StringPreference pref = (OsmandSettings.StringPreference) app.getSettings().getCustomRoutingProperty(parameterId, defValue);
StringPreference pref = (StringPreference) app.getSettings().getCustomRoutingProperty(parameterId, defValue);
Object[] values = parameter.getPossibleValues();
String[] valuesStr = new String[values.length];

View file

@ -8,7 +8,7 @@ import androidx.preference.DialogPreference;
import androidx.preference.PreferenceDataStore;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings.PreferencesDataStore;
import net.osmand.plus.settings.backend.OsmAndPreferencesDataStore;
public class ListPreferenceEx extends DialogPreference {
@ -126,8 +126,8 @@ public class ListPreferenceEx extends DialogPreference {
private Object getPersistedValue(Object defaultValue) {
PreferenceDataStore dataStore = getPreferenceDataStore();
if (dataStore instanceof PreferencesDataStore) {
Object value = ((PreferencesDataStore) dataStore).getValue(getKey(), defaultValue);
if (dataStore instanceof OsmAndPreferencesDataStore) {
Object value = ((OsmAndPreferencesDataStore) dataStore).getValue(getKey(), defaultValue);
if (value instanceof Enum) {
return ((Enum) value).ordinal();
} else if (value instanceof ApplicationMode) {
@ -144,8 +144,8 @@ public class ListPreferenceEx extends DialogPreference {
return;
}
PreferenceDataStore dataStore = getPreferenceDataStore();
if (dataStore instanceof PreferencesDataStore) {
((PreferencesDataStore) dataStore).putValue(getKey(), value);
if (dataStore instanceof OsmAndPreferencesDataStore) {
((OsmAndPreferencesDataStore) dataStore).putValue(getKey(), value);
}
}
}

View file

@ -6,7 +6,7 @@ import android.util.AttributeSet;
import androidx.preference.MultiSelectListPreference;
import androidx.preference.PreferenceDataStore;
import net.osmand.plus.settings.backend.OsmandSettings.PreferencesDataStore;
import net.osmand.plus.settings.backend.OsmAndPreferencesDataStore;
import java.util.HashSet;
import java.util.Set;
@ -79,8 +79,8 @@ public class MultiSelectBooleanPreference extends MultiSelectListPreference {
return;
}
PreferenceDataStore dataStore = getPreferenceDataStore();
if (dataStore instanceof PreferencesDataStore) {
PreferencesDataStore preferencesDataStore = (PreferencesDataStore) dataStore;
if (dataStore instanceof OsmAndPreferencesDataStore) {
OsmAndPreferencesDataStore preferencesDataStore = (OsmAndPreferencesDataStore) dataStore;
for (String prefId : getPrefsIds()) {
preferencesDataStore.putBoolean(prefId, getValues().contains(prefId));
@ -96,8 +96,8 @@ public class MultiSelectBooleanPreference extends MultiSelectListPreference {
Set<String> enabledPrefs = new HashSet<>();
PreferenceDataStore dataStore = getPreferenceDataStore();
if (dataStore instanceof PreferencesDataStore && getEntryValues() != null) {
PreferencesDataStore preferencesDataStore = (PreferencesDataStore) dataStore;
if (dataStore instanceof OsmAndPreferencesDataStore && getEntryValues() != null) {
OsmAndPreferencesDataStore preferencesDataStore = (OsmAndPreferencesDataStore) dataStore;
for (String prefId : getPrefsIds()) {
boolean enabled = preferencesDataStore.getBoolean(prefId, false);

View file

@ -8,7 +8,7 @@ import android.widget.TextView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction;
@ -46,7 +46,7 @@ public class ContourLinesAction extends QuickAction {
OsmandApplication app = activity.getMyApplication();
RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
if (contourLinesProp != null) {
final OsmandSettings.CommonPreference<String> pref = app.getSettings().getCustomRenderProperty(contourLinesProp.getAttrName());
final CommonPreference<String> pref = app.getSettings().getCustomRenderProperty(contourLinesProp.getAttrName());
boolean selected = !pref.get().equals(CONTOUR_LINES_DISABLED_VALUE);
if (selected && !plugin.isActive() && !plugin.needsInstallation()) {

View file

@ -7,6 +7,7 @@ import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
@ -61,8 +62,8 @@ public class ContourLinesMenu {
final String contourWidthName;
final String contourDensityName;
final OsmandSettings.CommonPreference<String> widthPref;
final OsmandSettings.CommonPreference<String> densityPref;
final CommonPreference<String> widthPref;
final CommonPreference<String> densityPref;
final RenderingRuleProperty contourWidthProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_WIDTH_ATTR);
if (contourWidthProp != null) {
contourWidthName = SettingsActivity.getStringPropertyName(app, contourWidthProp.getAttrName(),
@ -82,8 +83,8 @@ public class ContourLinesMenu {
densityPref = null;
}
final OsmandSettings.CommonPreference<String> pref = settings.getCustomRenderProperty(contourLinesProp.getAttrName());
final OsmandSettings.CommonPreference<String> colorPref = settings.getCustomRenderProperty(colorSchemeProp.getAttrName());
final CommonPreference<String> pref = settings.getCustomRenderProperty(contourLinesProp.getAttrName());
final CommonPreference<String> colorPref = settings.getCustomRenderProperty(colorSchemeProp.getAttrName());
final boolean selected = !pref.get().equals(CONTOUR_LINES_DISABLED_VALUE);
final int toggleActionStringId = selected ? R.string.shared_string_on : R.string.shared_string_off;

View file

@ -22,7 +22,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.TerrainMode;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SettingsActivity;
@ -234,7 +234,7 @@ public class SRTMPlugin extends OsmandPlugin {
RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
if (contourLinesProp != null) {
final OsmandSettings.CommonPreference<String> pref = app.getSettings().getCustomRenderProperty(contourLinesProp.getAttrName());
final CommonPreference<String> pref = app.getSettings().getCustomRenderProperty(contourLinesProp.getAttrName());
if (!Algorithms.isEmpty(pref.get())) {
contourLinesEnabled = !pref.get().equals(CONTOUR_LINES_DISABLED_VALUE);
} else {
@ -291,7 +291,7 @@ public class SRTMPlugin extends OsmandPlugin {
public void run() {
RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
if (contourLinesProp != null) {
final OsmandSettings.CommonPreference<String> pref = settings.getCustomRenderProperty(contourLinesProp.getAttrName());
final CommonPreference<String> pref = settings.getCustomRenderProperty(contourLinesProp.getAttrName());
boolean selected = !pref.get().equals(CONTOUR_LINES_DISABLED_VALUE);
SRTMPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
@ -338,7 +338,7 @@ public class SRTMPlugin extends OsmandPlugin {
RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
if (contourLinesProp != null) {
final OsmandSettings.CommonPreference<String> pref = settings.getCustomRenderProperty(contourLinesProp.getAttrName());
final CommonPreference<String> pref = settings.getCustomRenderProperty(contourLinesProp.getAttrName());
boolean contourLinesSelected = isContourLinesLayerEnabled(app);
String descr = getPrefDescription(app, contourLinesProp, pref);
adapter.addItem(new ContextMenuItem.ItemBuilder()
@ -407,7 +407,7 @@ public class SRTMPlugin extends OsmandPlugin {
final Runnable callback) {
RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
if (contourLinesProp != null) {
final OsmandSettings.CommonPreference<String> pref = settings.getCustomRenderProperty(contourLinesProp.getAttrName());
final CommonPreference<String> pref = settings.getCustomRenderProperty(contourLinesProp.getAttrName());
CommonPreference<String> zoomSetting = settings.CONTOUR_LINES_ZOOM;
if (!isChecked) {
zoomSetting.set(pref.get());
@ -435,7 +435,7 @@ public class SRTMPlugin extends OsmandPlugin {
}
}
public String getPrefDescription(final Context ctx, final RenderingRuleProperty p, final OsmandSettings.CommonPreference<String> pref) {
public String getPrefDescription(final Context ctx, final RenderingRuleProperty p, final CommonPreference<String> pref) {
if (!Algorithms.isEmpty(pref.get())) {
return SettingsActivity.getStringPropertyValue(ctx, pref.get());
} else {
@ -445,7 +445,7 @@ public class SRTMPlugin extends OsmandPlugin {
public void selectPropertyValue(final MapActivity activity,
final RenderingRuleProperty p,
final OsmandSettings.CommonPreference<String> pref,
final CommonPreference<String> pref,
final Runnable callback) {
final String propertyDescr = SettingsActivity.getStringPropertyDescription(activity,
p.getAttrName(), p.getName());

View file

@ -20,7 +20,7 @@ import net.osmand.CallbackWithObject;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;

View file

@ -24,7 +24,7 @@ import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MapContextMenu;

View file

@ -41,7 +41,7 @@ import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu.TrackChartPoints;

View file

@ -43,8 +43,9 @@ import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmAndLocationSimulation;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings.LayerTransparencySeekbarMode;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
@ -1225,7 +1226,7 @@ public class MapControlsLayer extends OsmandMapLayer {
@Override
public boolean onLongClick(View notUseCouldBeNull) {
final OsmandSettings.OsmandPreference<Float> mapDensity = view.getSettings().MAP_DENSITY;
final OsmandPreference<Float> mapDensity = view.getSettings().MAP_DENSITY;
final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
int p = (int) (mapDensity.get() * 100);
final TIntArrayList tlist = new TIntArrayList(new int[]{25, 33, 50, 75, 100, 125, 150, 200, 300, 400});

View file

@ -29,6 +29,7 @@ import net.osmand.data.QuadPoint;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.AngularConstants;
import net.osmand.plus.settings.backend.OsmandSettings.RulerMode;
@ -67,7 +68,7 @@ public class RulerControlLayer extends OsmandMapLayer {
private QuadPoint cacheCenter;
private float cacheMapDensity;
private OsmandSettings.OsmandPreference<Float> mapDensity;
private OsmandPreference<Float> mapDensity;
private OsmandSettings.MetricsConstants cacheMetricSystem;
private int cacheIntZoom;
private LatLon cacheCenterLatLon;

View file

@ -25,6 +25,7 @@ import net.osmand.data.RotatedTileBox;
import net.osmand.data.TransportStop;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Way;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
@ -60,7 +61,7 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
private MapLayerData<List<TransportStop>> data;
private TransportStopRoute stopRoute = null;
private OsmandSettings.CommonPreference<Boolean> showTransportStops;
private CommonPreference<Boolean> showTransportStops;
private Path path;
private float backgroundIconHalfWidth;

View file

@ -48,6 +48,7 @@ import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmAndLocationProvider.GPSInfo;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.RulerMode;
import net.osmand.plus.R;
@ -167,7 +168,7 @@ public class MapInfoWidgetsFactory {
public static final int COMPASS_CONTROL_WIDGET_STATE_SHOW = R.id.compass_ruler_control_widget_state_show;
public static final int COMPASS_CONTROL_WIDGET_STATE_HIDE = R.id.compass_ruler_control_widget_state_hide;
private final OsmandSettings.OsmandPreference<Boolean> showCompass;
private final OsmandPreference<Boolean> showCompass;
public CompassRulerControlWidgetState(OsmandApplication ctx) {
super(ctx);

View file

@ -17,7 +17,7 @@ import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;

View file

@ -35,7 +35,7 @@ import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
@ -1178,7 +1178,7 @@ public class RouteInfoWidgetsFactory {
private String cacheRulerText;
private int maxWidth;
private float cacheMapDensity;
private OsmandSettings.OsmandPreference<Float> mapDensity;
private OsmandPreference<Float> mapDensity;
private int cacheRulerZoom;
private double cacheRulerTileX;
private double cacheRulerTileY;

View file

@ -8,7 +8,7 @@ import android.os.Build;
import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.routing.VoiceRouter;
import org.apache.commons.logging.Log;
@ -91,7 +91,7 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen
// Delay first prompt of each batch to allow BT SCO link being established, or when VOICE_PROMPT_DELAY is set >0 for the other stream types
if (ctx != null) {
Integer stream = ctx.getSettings().AUDIO_MANAGER_STREAM.getModeValue(getApplicationMode());
OsmandSettings.OsmandPreference<Integer> pref = ctx.getSettings().VOICE_PROMPT_DELAY[stream];
OsmandPreference<Integer> pref = ctx.getSettings().VOICE_PROMPT_DELAY[stream];
if (pref.getModeValue(getApplicationMode()) > 0) {
try {
Thread.sleep(pref.getModeValue(getApplicationMode()));

View file

@ -17,7 +17,7 @@ import androidx.appcompat.app.AlertDialog;
import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.routing.VoiceRouter;
@ -127,7 +127,7 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
// Delay first prompt of each batch to allow BT SCO link being established, or when VOICE_PROMPT_DELAY is set >0 for the other stream types
if (ctx != null) {
Integer streamModeValue = ctx.getSettings().AUDIO_MANAGER_STREAM.getModeValue(getApplicationMode());
OsmandSettings.OsmandPreference<Integer> pref = ctx.getSettings().VOICE_PROMPT_DELAY[streamModeValue];
OsmandPreference<Integer> pref = ctx.getSettings().VOICE_PROMPT_DELAY[streamModeValue];
int vpd = pref == null ? 0 : pref.getModeValue(getApplicationMode());
if (vpd > 0) {
ttsRequests++;

View file

@ -9,7 +9,7 @@ import androidx.appcompat.widget.PopupMenu;
import androidx.fragment.app.Fragment;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings.WikiArticleShowImages;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
@ -28,7 +28,7 @@ public class WikipediaOptionsBottomSheetDialogFragment extends MenuBottomSheetDi
@Override
public void createMenuItems(Bundle savedInstanceState) {
final OsmandApplication app = getMyApplication();
final OsmandSettings.CommonPreference<WikiArticleShowImages> showImagesPref = app.getSettings().WIKI_ARTICLE_SHOW_IMAGES;
final CommonPreference<WikiArticleShowImages> showImagesPref = app.getSettings().WIKI_ARTICLE_SHOW_IMAGES;
items.add(new TitleItem(getString(R.string.shared_string_options)));

View file

@ -15,7 +15,7 @@ import androidx.appcompat.widget.PopupMenu;
import net.osmand.PicassoUtils;
import net.osmand.plus.OnDialogFragmentResultListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings.WikiArticleShowImages;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
@ -44,7 +44,7 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
if (app == null) {
return;
}
final OsmandSettings.CommonPreference<WikiArticleShowImages> showImagesPref = app.getSettings().WIKI_ARTICLE_SHOW_IMAGES;
final CommonPreference<WikiArticleShowImages> showImagesPref = app.getSettings().WIKI_ARTICLE_SHOW_IMAGES;
final TravelDbHelper dbHelper = app.getTravelDbHelper();
items.add(new TitleItem(getString(R.string.shared_string_options)));