Merge pull request #8148 from osmandapp/preferences_improvements

Copy and reset profile preferences
This commit is contained in:
max-klaus 2020-01-02 18:33:43 +03:00 committed by GitHub
commit e8d5d85df2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 652 additions and 109 deletions

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<net.osmand.plus.widgets.TextViewEx xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingLeft="@dimen/content_padding"
android:paddingTop="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingBottom="@dimen/content_padding"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
app:typeface="@string/font_roboto_regular"
tools:text="@string/reset_all_profile_settings_descr" />

View file

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:minHeight="@dimen/bottom_sheet_large_list_item_height"
android:orientation="horizontal">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginTop="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/content_padding"
android:layout_marginBottom="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/ic_action_coordinates_latitude"
tools:tint="?attr/default_icon_color" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textAppearance="@style/TextAppearance.ListItemTitle"
android:textColor="?android:textColorPrimary"
tools:text="Item Title" />
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:textColorSecondary"
tools:text="Item additional desription" />
</LinearLayout>
<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/compound_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:background="@null"
android:clickable="false"
android:focusable="false"
android:saveEnabled="false" />
</LinearLayout>

View file

@ -11,6 +11,9 @@
Thx - Hardy
-->
<string name="reset_confirmation_descr">By clicking %1$s, you will lose all your changes.</string>
<string name="reset_all_profile_settings_descr">All profile settings will be reset to the state after installation.</string>
<string name="reset_all_profile_settings">Reset all profile settings to default?</string>
<string name="select_navigation_icon">Select navigation icon</string>
<string name="select_map_icon">Select map icon</string>
<string name="delete_profiles_descr">After you tap Apply, deleted profiles will be lost completely.</string>

View file

@ -53,7 +53,7 @@
tools:icon="@drawable/ic_action_offroad" />
<Preference
android:layout="@layout/list_item_divider"
android:layout="@layout/simple_divider_item"
android:selectable="false" />
<PreferenceCategory
@ -78,6 +78,24 @@
android:title="@string/export_profile"
tools:icon="@drawable/ic_action_app_configuration" />
<Preference
android:key="copy_profile_settings"
android:layout="@layout/preference_button"
android:persistent="false"
android:title="@string/copy_from_other_profile"
tools:icon="@drawable/ic_action_copy" />
<Preference
android:layout="@layout/simple_divider_item"
android:selectable="false" />
<Preference
android:key="reset_to_default"
android:layout="@layout/preference_button"
android:persistent="false"
android:title="@string/reset_to_default"
tools:icon="@drawable/ic_action_reset_to_default_dark" />
<Preference
android:key="delete_profile"
android:layout="@layout/preference_button"
@ -85,13 +103,6 @@
android:title="@string/profile_alert_delete_title"
tools:icon="@drawable/ic_action_delete_dark" />
<Preference
android:key="export_profile_descr"
android:layout="@layout/preference_info_descr_with_title"
android:title="@string/profile_import"
android:summary="@string/profile_import_descr"
android:selectable="false" />
<Preference
android:layout="@layout/card_bottom_divider"
android:selectable="false" />

View file

@ -95,6 +95,8 @@ public class AppInitializer implements IProgress {
public static final int VERSION_3_2 = 32;
// 35 - 3.5
public static final int VERSION_3_5 = 35;
// 36 - 3.6
public static final int VERSION_3_6 = 36;
public static final boolean TIPS_AND_TRICKS = false;
@ -160,6 +162,7 @@ public class AppInitializer implements IProgress {
if(initSettings) {
return;
}
ApplicationMode.onApplicationStart(app);
startPrefs = app.getSharedPreferences(
getLocalClassName(app.getAppCustomization().getMapActivity().getName()),
Context.MODE_PRIVATE);
@ -200,14 +203,16 @@ public class AppInitializer implements IProgress {
app.getSettings().migrateHomeWorkParkingToFavorites();
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_5).commit();
}
if (prevAppVersion < VERSION_3_6) {
app.getSettings().migratePreferences();
startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_6).commit();
}
startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit();
appVersionChanged = true;
}
app.getSettings().SHOW_TRAVEL_UPDATE_CARD.set(true);
app.getSettings().SHOW_TRAVEL_NEEDED_MAPS_CARD.set(true);
ApplicationMode.onApplicationStart(app);
initSettings = true;
}
public int getNumberOfStarts() {

View file

@ -151,7 +151,6 @@ public class OsmandSettings {
/// Settings variables
private final OsmandApplication ctx;
private SettingsAPI settingsAPI;
private Object defaultProfilePreferences;
private Object globalPreferences;
private Object profilePreferences;
private ApplicationMode currentMode;
@ -179,7 +178,6 @@ public class OsmandSettings {
private void initPrefs() {
globalPreferences = settingsAPI.getPreferenceObject(getSharedPreferencesName(null));
defaultProfilePreferences = getProfilePreferences(ApplicationMode.DEFAULT);
currentMode = readApplicationMode();
profilePreferences = getProfilePreferences(currentMode);
registeredPreferences.put(APPLICATION_MODE.getId(), APPLICATION_MODE);
@ -237,8 +235,7 @@ public class OsmandSettings {
if (pref instanceof CommonPreference) {
CommonPreference commonPreference = (CommonPreference) pref;
if (!commonPreference.global) {
List<ApplicationMode> modes = commonPreference.general ? Collections.singletonList(ApplicationMode.DEFAULT) : ApplicationMode.allPossibleValues();
for (ApplicationMode mode : modes) {
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
if (!commonPreference.isSetForMode(mode)) {
setPreference(key, globalPrefsMap.get(key), mode);
}
@ -246,7 +243,7 @@ public class OsmandSettings {
}
}
}
SharedPreferences defaultProfilePreferences = (SharedPreferences) this.defaultProfilePreferences;
SharedPreferences defaultProfilePreferences = (SharedPreferences) getProfilePreferences(ApplicationMode.DEFAULT);
Map<String, ?> defaultPrefsMap = defaultProfilePreferences.getAll();
for (String key : defaultPrefsMap.keySet()) {
OsmandPreference pref = getPreference(key);
@ -257,6 +254,14 @@ public class OsmandSettings {
}
}
}
for (OsmandPreference pref : generalPrefs) {
Object defaultVal = pref.getModeValue(ApplicationMode.DEFAULT);
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
if (!pref.isSetForMode(mode)) {
pref.setModeValue(mode, defaultVal);
}
}
}
}
void migrateHomeWorkParkingToFavorites() {
@ -290,25 +295,10 @@ public class OsmandSettings {
return registeredPreferences.get(key);
}
public boolean setSharedGeneralPreference(String key, Object value) {
OsmandPreference<?> preference = registeredPreferences.get(key);
if (preference instanceof CommonPreference) {
CommonPreference commonPref = (CommonPreference) preference;
if (commonPref.general) {
for (ApplicationMode mode : ApplicationMode.values(ctx)) {
if (commonPref.isSetForMode(mode)) {
settingsAPI.edit(getProfilePreferences(mode)).remove(key).commit();
}
}
boolean valueSaved = setPreference(key, value, ApplicationMode.DEFAULT);
if (valueSaved) {
commonPref.cachedValue = null;
}
return valueSaved;
}
public void setPreferenceForAllModes(String key, Object value) {
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
setPreference(key, value, mode);
}
return false;
}
public boolean setPreference(String key, Object value) {
@ -415,6 +405,36 @@ public class OsmandSettings {
return false;
}
public boolean copyPreferencesFromProfile(ApplicationMode modeFrom, ApplicationMode modeTo) {
SettingsEditor settingsEditor = settingsAPI.edit(getProfilePreferences(modeTo));
for (OsmandPreference pref : registeredPreferences.values()) {
if (pref instanceof CommonPreference && !((CommonPreference) pref).global) {
CommonPreference profilePref = (CommonPreference) pref;
if (profilePref.isSetForMode(modeFrom)) {
Object copiedValue = profilePref.getModeValue(modeFrom);
if (copiedValue instanceof String) {
settingsEditor.putString(pref.getId(), (String) copiedValue);
} else if (copiedValue instanceof Boolean) {
settingsEditor.putBoolean(pref.getId(), (Boolean) copiedValue);
} else if (copiedValue instanceof Float) {
settingsEditor.putFloat(pref.getId(), (Float) copiedValue);
} else if (copiedValue instanceof Integer) {
settingsEditor.putInt(pref.getId(), (Integer) copiedValue);
} else if (copiedValue instanceof Long) {
settingsEditor.putLong(pref.getId(), (Long) copiedValue);
}
} else {
settingsEditor.remove(pref.getId());
}
}
}
return settingsEditor.commit();
}
public boolean resetPreferencesForProfile(ApplicationMode mode) {
return settingsAPI.edit(getProfilePreferences(mode)).clear().commit();
}
public ApplicationMode LAST_ROUTING_APPLICATION_MODE = null;
// this value string is synchronized with settings_pref.xml preference name
@ -592,7 +612,6 @@ public class OsmandSettings {
public abstract class CommonPreference<T> extends PreferenceWithListener<T> {
private final String id;
private boolean global;
private boolean general;
private T cachedValue;
private Object cachedPreference;
private boolean cache;
@ -621,11 +640,6 @@ public class OsmandSettings {
return this;
}
public CommonPreference<T> makeGeneral() {
general = true;
return this;
}
protected Object getPreferences() {
return global ? globalPreferences : profilePreferences;
}
@ -664,11 +678,7 @@ public class OsmandSettings {
if (pt != null) {
return getProfileDefaultValue(pt);
}
if (general && settingsAPI.contains(defaultProfilePreferences, getId())) {
return getValue(defaultProfilePreferences, defaultValue);
} else {
return defaultValue;
}
return defaultValue;
}
public boolean hasDefaultValues() {
@ -1277,7 +1287,7 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> FIRST_MAP_IS_DOWNLOADED = new BooleanPreference(
"first_map_is_downloaded", false);
public final CommonPreference<Boolean> DRIVING_REGION_AUTOMATIC = new BooleanPreference("driving_region_automatic", true).makeProfile().makeGeneral().cache();
public final CommonPreference<Boolean> DRIVING_REGION_AUTOMATIC = new BooleanPreference("driving_region_automatic", true).makeProfile().cache();
public final OsmandPreference<DrivingRegion> DRIVING_REGION = new EnumIntPreference<DrivingRegion>(
"default_driving_region", DrivingRegion.EUROPE_ASIA, DrivingRegion.values()) {
protected boolean setValue(Object prefs, DrivingRegion val) {
@ -1309,7 +1319,7 @@ public class OsmandSettings {
return DrivingRegion.EUROPE_ASIA;
}
}.makeProfile().makeGeneral().cache();
}.makeProfile().cache();
// this value string is synchronized with settings_pref.xml preference name
// cache of metrics constants as they are used very often
@ -1319,12 +1329,12 @@ public class OsmandSettings {
return DRIVING_REGION.get().defMetrics;
}
}.makeProfile().makeGeneral();
}.makeProfile();
//public final OsmandPreference<Integer> COORDINATES_FORMAT = new IntPreference("coordinates_format", PointDescription.FORMAT_DEGREES).makeGlobal();
public final OsmandPreference<AngularConstants> ANGULAR_UNITS = new EnumIntPreference<AngularConstants>(
"angular_measurement", AngularConstants.DEGREES, AngularConstants.values()).makeProfile().makeGeneral();
"angular_measurement", AngularConstants.DEGREES, AngularConstants.values()).makeProfile();
public final OsmandPreference<SpeedConstants> SPEED_SYSTEM = new EnumIntPreference<SpeedConstants>(
@ -1354,7 +1364,7 @@ public class OsmandSettings {
;
}.makeProfile().makeGeneral();
}.makeProfile();
// this value string is synchronized with settings_pref.xml preference name
@ -1391,7 +1401,7 @@ public class OsmandSettings {
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> USE_TRACKBALL_FOR_MOVEMENTS =
new BooleanPreference("use_trackball_for_movements", true).makeProfile().makeGeneral();
new BooleanPreference("use_trackball_for_movements", true).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> ACCESSIBILITY_SMART_AUTOANNOUNCE =
@ -1418,12 +1428,12 @@ public class OsmandSettings {
new BooleanAccessibilityPreference("direction_haptic_feedback", false).makeGlobal();
// magnetic field doesn'torkmost of the time on some phones
public final OsmandPreference<Boolean> USE_MAGNETIC_FIELD_SENSOR_COMPASS = new BooleanPreference("use_magnetic_field_sensor_compass", false).makeProfile().makeGeneral().cache();
public final OsmandPreference<Boolean> USE_KALMAN_FILTER_FOR_COMPASS = new BooleanPreference("use_kalman_filter_compass", true).makeProfile().makeGeneral().cache();
public final OsmandPreference<Boolean> USE_MAGNETIC_FIELD_SENSOR_COMPASS = new BooleanPreference("use_magnetic_field_sensor_compass", false).makeProfile().cache();
public final OsmandPreference<Boolean> USE_KALMAN_FILTER_FOR_COMPASS = new BooleanPreference("use_kalman_filter_compass", true).makeProfile().cache();
public final OsmandPreference<Boolean> DO_NOT_SHOW_STARTUP_MESSAGES = new BooleanPreference("do_not_show_startup_messages", false).makeGlobal().cache();
public final OsmandPreference<Boolean> SHOW_DOWNLOAD_MAP_DIALOG = new BooleanPreference("show_download_map_dialog", true).makeGlobal().cache();
public final OsmandPreference<Boolean> DO_NOT_USE_ANIMATIONS = new BooleanPreference("do_not_use_animations", false).makeProfile().makeGeneral().cache();
public final OsmandPreference<Boolean> DO_NOT_USE_ANIMATIONS = new BooleanPreference("do_not_use_animations", false).makeProfile().cache();
public final OsmandPreference<Boolean> SEND_ANONYMOUS_MAP_DOWNLOADS_DATA = new BooleanPreference("send_anonymous_map_downloads_data", false).makeGlobal().cache();
public final OsmandPreference<Boolean> SEND_ANONYMOUS_APP_USAGE_DATA = new BooleanPreference("send_anonymous_app_usage_data", false).makeGlobal().cache();
@ -1431,7 +1441,7 @@ public class OsmandSettings {
public final OsmandPreference<Integer> SEND_ANONYMOUS_DATA_REQUESTS_COUNT = new IntPreference("send_anonymous_data_requests_count", 0).makeGlobal().cache();
public final OsmandPreference<Integer> SEND_ANONYMOUS_DATA_LAST_REQUEST_NS = new IntPreference("send_anonymous_data_last_request_ns", -1).makeGlobal().cache();
public final OsmandPreference<Boolean> MAP_EMPTY_STATE_ALLOWED = new BooleanPreference("map_empty_state_allowed", false).makeProfile().makeGeneral().cache();
public final OsmandPreference<Boolean> MAP_EMPTY_STATE_ALLOWED = new BooleanPreference("map_empty_state_allowed", false).makeProfile().cache();
public final CommonPreference<Float> TEXT_SCALE = new FloatPreference("text_scale", 1f).makeProfile().cache();
@ -1575,10 +1585,10 @@ public class OsmandSettings {
public static final String SAVE_CURRENT_TRACK = "save_current_track"; //$NON-NLS-1$
public final CommonPreference<Boolean> SAVE_GLOBAL_TRACK_TO_GPX = new BooleanPreference("save_global_track_to_gpx", false).makeGlobal().cache();
public final CommonPreference<Integer> SAVE_GLOBAL_TRACK_INTERVAL = new IntPreference("save_global_track_interval", 5000).makeProfile().makeGeneral().cache();
public final CommonPreference<Boolean> SAVE_GLOBAL_TRACK_REMEMBER = new BooleanPreference("save_global_track_remember", false).makeProfile().makeGeneral().cache();
public final CommonPreference<Integer> SAVE_GLOBAL_TRACK_INTERVAL = new IntPreference("save_global_track_interval", 5000).makeProfile().cache();
public final CommonPreference<Boolean> SAVE_GLOBAL_TRACK_REMEMBER = new BooleanPreference("save_global_track_remember", false).makeProfile().cache();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Boolean> SAVE_TRACK_TO_GPX = new BooleanPreference("save_track_to_gpx", false).makeProfile().makeGeneral().cache();
public final CommonPreference<Boolean> SAVE_TRACK_TO_GPX = new BooleanPreference("save_track_to_gpx", false).makeProfile().cache();
{
SAVE_TRACK_TO_GPX.setModeDefaultValue(ApplicationMode.CAR, false);
@ -1590,11 +1600,11 @@ public class OsmandSettings {
public static final Integer MONTHLY_DIRECTORY = 1;
public static final Integer DAILY_DIRECTORY = 2;
public final CommonPreference<Boolean> DISABLE_RECORDING_ONCE_APP_KILLED = new BooleanPreference("disable_recording_once_app_killed", false).makeProfile().makeGeneral();
public final CommonPreference<Boolean> DISABLE_RECORDING_ONCE_APP_KILLED = new BooleanPreference("disable_recording_once_app_killed", false).makeProfile();
public final CommonPreference<Boolean> SAVE_HEADING_TO_GPX = new BooleanPreference("save_heading_to_gpx", false).makeProfile().makeGeneral();
public final CommonPreference<Boolean> SAVE_HEADING_TO_GPX = new BooleanPreference("save_heading_to_gpx", false).makeProfile();
public final CommonPreference<Integer> TRACK_STORAGE_DIRECTORY = new IntPreference("track_storage_directory", 0).makeProfile().makeGeneral();
public final CommonPreference<Integer> TRACK_STORAGE_DIRECTORY = new IntPreference("track_storage_directory", 0).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> FAST_ROUTE_MODE = new BooleanPreference("fast_route_mode", true).makeProfile();
@ -1701,7 +1711,7 @@ public class OsmandSettings {
public final CommonPreference<Integer> CURRENT_TRACK_COLOR = new IntPreference("current_track_color", 0).makeGlobal().cache();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Integer> SAVE_TRACK_INTERVAL = new IntPreference("save_track_interval", 5000).makeProfile().makeGeneral();
public final CommonPreference<Integer> SAVE_TRACK_INTERVAL = new IntPreference("save_track_interval", 5000).makeProfile();
{
SAVE_TRACK_INTERVAL.setModeDefaultValue(ApplicationMode.CAR, 3000);
@ -1710,40 +1720,40 @@ public class OsmandSettings {
}
// Please note that SAVE_TRACK_MIN_DISTANCE, SAVE_TRACK_PRECISION, SAVE_TRACK_MIN_SPEED should all be "0" for the default profile, as we have no interface to change them
public final CommonPreference<Float> SAVE_TRACK_MIN_DISTANCE = new FloatPreference("save_track_min_distance", 0).makeProfile().makeGeneral();
public final CommonPreference<Float> SAVE_TRACK_MIN_DISTANCE = new FloatPreference("save_track_min_distance", 0).makeProfile();
//{
// SAVE_TRACK_MIN_DISTANCE.setModeDefaultValue(ApplicationMode.CAR, 5.f);
// SAVE_TRACK_MIN_DISTANCE.setModeDefaultValue(ApplicationMode.BICYCLE, 5.f);
// SAVE_TRACK_MIN_DISTANCE.setModeDefaultValue(ApplicationMode.PEDESTRIAN, 5.f);
//}
public final CommonPreference<Float> SAVE_TRACK_PRECISION = new FloatPreference("save_track_precision", 50.0f).makeProfile().makeGeneral();
public final CommonPreference<Float> SAVE_TRACK_PRECISION = new FloatPreference("save_track_precision", 50.0f).makeProfile();
//{
// SAVE_TRACK_PRECISION.setModeDefaultValue(ApplicationMode.CAR, 50.f);
// SAVE_TRACK_PRECISION.setModeDefaultValue(ApplicationMode.BICYCLE, 50.f);
// SAVE_TRACK_PRECISION.setModeDefaultValue(ApplicationMode.PEDESTRIAN, 50.f);
//}
public final CommonPreference<Float> SAVE_TRACK_MIN_SPEED = new FloatPreference("save_track_min_speed", 0.f).makeProfile().makeGeneral();
public final CommonPreference<Float> SAVE_TRACK_MIN_SPEED = new FloatPreference("save_track_min_speed", 0.f).makeProfile();
//{
// SAVE_TRACK_MIN_SPEED.setModeDefaultValue(ApplicationMode.CAR, 2.f);
// SAVE_TRACK_MIN_SPEED.setModeDefaultValue(ApplicationMode.BICYCLE, 1.f);
// SAVE_TRACK_MIN_SPEED.setModeDefaultValue(ApplicationMode.PEDESTRIAN, 0.f);
//}
public final CommonPreference<Boolean> AUTO_SPLIT_RECORDING = new BooleanPreference("auto_split_recording", true).makeProfile().makeGeneral();
public final CommonPreference<Boolean> AUTO_SPLIT_RECORDING = new BooleanPreference("auto_split_recording", true).makeProfile();
public final CommonPreference<Boolean> SHOW_TRIP_REC_NOTIFICATION = new BooleanPreference("show_trip_recording_notification", true).makeProfile().makeGeneral();
public final CommonPreference<Boolean> SHOW_TRIP_REC_NOTIFICATION = new BooleanPreference("show_trip_recording_notification", true).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Boolean> LIVE_MONITORING = new BooleanPreference("live_monitoring", false).makeProfile().makeGeneral();
public final CommonPreference<Boolean> LIVE_MONITORING = new BooleanPreference("live_monitoring", false).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Integer> LIVE_MONITORING_INTERVAL = new IntPreference("live_monitoring_interval", 5000).makeProfile().makeGeneral();
public final CommonPreference<Integer> LIVE_MONITORING_INTERVAL = new IntPreference("live_monitoring_interval", 5000).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Integer> LIVE_MONITORING_MAX_INTERVAL_TO_SEND = new IntPreference("live_monitoring_maximum_interval_to_send", 900000).makeProfile().makeGeneral();
public final CommonPreference<Integer> LIVE_MONITORING_MAX_INTERVAL_TO_SEND = new IntPreference("live_monitoring_maximum_interval_to_send", 900000).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<String> LIVE_MONITORING_URL = new StringPreference("live_monitoring_url",
"https://example.com?lat={0}&lon={1}&timestamp={2}&hdop={3}&altitude={4}&speed={5}").makeProfile().makeGeneral();
"https://example.com?lat={0}&lon={1}&timestamp={2}&hdop={3}&altitude={4}&speed={5}").makeProfile();
public final CommonPreference<String> GPS_STATUS_APP = new StringPreference("gps_status_app", "").makeGlobal();
@ -1780,7 +1790,7 @@ public class OsmandSettings {
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Integer> MAP_SCREEN_ORIENTATION =
new IntPreference("map_screen_orientation", -1/*ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED*/).makeProfile().makeGeneral();
new IntPreference("map_screen_orientation", -1/*ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED*/).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
// public final CommonPreference<Boolean> SHOW_VIEW_ANGLE = new BooleanPreference("show_view_angle", false).makeProfile().cache();
@ -1837,7 +1847,7 @@ public class OsmandSettings {
public static final int ROTATE_MAP_BEARING = 1;
public static final int ROTATE_MAP_COMPASS = 2;
public final CommonPreference<Integer> ROTATE_MAP =
new IntPreference("rotate_map", ROTATE_MAP_NONE).makeProfile().makeGeneral().cache();
new IntPreference("rotate_map", ROTATE_MAP_NONE).makeProfile().cache();
{
ROTATE_MAP.setModeDefaultValue(ApplicationMode.CAR, ROTATE_MAP_BEARING);
@ -1851,7 +1861,7 @@ public class OsmandSettings {
public static final int MIDDLE_BOTTOM_CONSTANT = 2;
public static final int MIDDLE_TOP_CONSTANT = 3;
public static final int LANDSCAPE_MIDDLE_RIGHT_CONSTANT = 4;
public final CommonPreference<Boolean> CENTER_POSITION_ON_MAP = new BooleanPreference("center_position_on_map", false).makeProfile().makeGeneral();
public final CommonPreference<Boolean> CENTER_POSITION_ON_MAP = new BooleanPreference("center_position_on_map", false).makeProfile();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Integer> MAX_LEVEL_TO_DOWNLOAD_TILE = new IntPreference("max_level_download_tile", 20).makeProfile().cache();
@ -1949,7 +1959,7 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> ANIMATE_MY_LOCATION = new BooleanPreference("animate_my_location", true).makeProfile().cache();
public final OsmandPreference<Integer> EXTERNAL_INPUT_DEVICE = new IntPreference("external_input_device", 0).makeProfile().makeGeneral();
public final OsmandPreference<Integer> EXTERNAL_INPUT_DEVICE = new IntPreference("external_input_device", 0).makeProfile();
public final OsmandPreference<Boolean> ROUTE_MAP_MARKERS_START_MY_LOC = new BooleanPreference("route_map_markers_start_my_loc", false).makeGlobal().cache();
public final OsmandPreference<Boolean> ROUTE_MAP_MARKERS_ROUND_TRIP = new BooleanPreference("route_map_markers_round_trip", false).makeGlobal().cache();
@ -3097,7 +3107,7 @@ public class OsmandSettings {
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<String> CONTRIBUTION_INSTALL_APP_DATE = new StringPreference("CONTRIBUTION_INSTALL_APP_DATE", null).makeGlobal();
public final OsmandPreference<Integer> COORDINATES_FORMAT = new IntPreference("coordinates_format", PointDescription.FORMAT_DEGREES).makeProfile().makeGeneral();
public final OsmandPreference<Integer> COORDINATES_FORMAT = new IntPreference("coordinates_format", PointDescription.FORMAT_DEGREES).makeProfile();
public final OsmandPreference<Boolean> FOLLOW_THE_ROUTE = new BooleanPreference("follow_to_route", false).makeGlobal();
public final OsmandPreference<String> FOLLOW_THE_GPX_ROUTE = new StringPreference("follow_gpx", null).makeGlobal();
@ -3163,7 +3173,7 @@ public class OsmandSettings {
new IntPreference("FAVORITES_TAB", 0).makeGlobal().cache();
public final CommonPreference<Integer> OSMAND_THEME =
new IntPreference("osmand_theme", OSMAND_LIGHT_THEME).makeProfile().makeGeneral().cache();
new IntPreference("osmand_theme", OSMAND_LIGHT_THEME).makeProfile().cache();
public boolean isLightActionBar() {
return isLightContent();
@ -3468,6 +3478,39 @@ public class OsmandSettings {
}
}
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 class PreferencesDataStore extends PreferenceDataStore {
private ApplicationMode appMode;

View file

@ -50,7 +50,13 @@ public class FileSettingsAPIImpl implements SettingsAPI {
modified.put(wrap(pref,key), null);
return this;
}
@Override
public SettingsEditor clear() {
modified.clear();
return this;
}
@Override
public SettingsEditor putString(String key, String value) {
modified.put(wrap(pref,key), value);

View file

@ -13,6 +13,7 @@ public interface SettingsAPI {
public SettingsEditor putInt(String key, int value);
public SettingsEditor putLong(String key, long value);
public SettingsEditor remove(String key);
public SettingsEditor clear();
public boolean commit();
}

View file

@ -28,7 +28,13 @@ public class SettingsAPIImpl implements SettingsAPI {
edit.remove(key);
return this;
}
@Override
public SettingsEditor clear() {
edit.clear();
return this;
}
@Override
public SettingsEditor putString(String key, String value) {
edit.putString(key, value);

View file

@ -83,7 +83,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
inflateMenuItems();
dismissButton = mainView.findViewById(R.id.dismiss_button);
UiUtilities.setupDialogButton(nightMode, dismissButton, getDismissByttonType(), getDismissButtonTextId());
UiUtilities.setupDialogButton(nightMode, dismissButton, getDismissButtonType(), getDismissButtonTextId());
dismissButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -98,7 +98,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
if (rightBottomButtonTextId != DEFAULT_VALUE) {
mainView.findViewById(R.id.buttons_divider).setVisibility(View.VISIBLE);
rightButton = mainView.findViewById(R.id.right_bottom_button);
UiUtilities.setupDialogButton(nightMode, rightButton, getRightBottomByttonType(), rightBottomButtonTextId);
UiUtilities.setupDialogButton(nightMode, rightButton, getRightBottomButtonType(), rightBottomButtonTextId);
rightButton.setVisibility(View.VISIBLE);
rightButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -249,7 +249,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
dismissButtonStringRes = stringRes;
}
protected DialogButtonType getDismissByttonType() {
protected DialogButtonType getDismissButtonType() {
return DialogButtonType.SECONDARY;
}
@ -262,7 +262,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
return DEFAULT_VALUE;
}
protected DialogButtonType getRightBottomByttonType() {
protected DialogButtonType getRightBottomButtonType() {
return DialogButtonType.PRIMARY;
}

View file

@ -31,6 +31,7 @@ public class BottomSheetItemTitleWithDescrAndButton extends BottomSheetItemWithD
View.OnClickListener onClickListener,
int position,
Drawable icon,
Drawable background,
String title,
@ColorRes int titleColorId,
CharSequence description,
@ -49,6 +50,7 @@ public class BottomSheetItemTitleWithDescrAndButton extends BottomSheetItemWithD
onClickListener,
position,
icon,
background,
title,
titleColorId,
description,
@ -123,6 +125,7 @@ public class BottomSheetItemTitleWithDescrAndButton extends BottomSheetItemWithD
onClickListener,
position,
icon,
background,
title,
titleColorId,
description,

View file

@ -36,6 +36,7 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
View.OnClickListener onClickListener,
int position,
Drawable icon,
Drawable background,
String title,
@ColorRes int titleColorId,
CharSequence description,
@ -53,6 +54,7 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
onClickListener,
position,
icon,
background,
title,
titleColorId,
description,
@ -126,6 +128,7 @@ public class BottomSheetItemWithCompoundButton extends BottomSheetItemWithDescri
onClickListener,
position,
icon,
background,
title,
titleColorId,
description,

View file

@ -10,7 +10,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
@ -30,13 +29,14 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
View.OnClickListener onClickListener,
int position,
Drawable icon,
Drawable background,
String title,
@ColorRes int titleColorId,
CharSequence description,
@ColorRes int descriptionColorId,
int descriptionMaxLines,
boolean descriptionLinksClickable) {
super(customView, layoutId, tag, disabled, onClickListener, position, icon, title, titleColorId);
super(customView, layoutId, tag, disabled, onClickListener, position, icon, background, title, titleColorId);
this.description = description;
this.descriptionColorId = descriptionColorId;
this.descriptionMaxLines = descriptionMaxLines;
@ -121,6 +121,7 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
onClickListener,
position,
icon,
background,
title,
titleColorId,
description,

View file

@ -10,11 +10,12 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.plus.OsmandApplication;
import net.osmand.AndroidUtils;
import net.osmand.plus.R;
public class SimpleBottomSheetItem extends BaseBottomSheetItem {
private Drawable background;
private Drawable icon;
protected String title;
@ColorRes
@ -30,10 +31,12 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
View.OnClickListener onClickListener,
int position,
Drawable icon,
Drawable background,
String title,
@ColorRes int titleColorId) {
super(customView, layoutId, tag, disabled, onClickListener, position);
this.icon = icon;
this.background = background;
this.title = title;
this.titleColorId = titleColorId;
}
@ -66,11 +69,15 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
titleTv.setTextColor(ContextCompat.getColor(context, titleColorId));
}
}
if (background != null) {
AndroidUtils.setBackground(view, background);
}
}
public static class Builder extends BaseBottomSheetItem.Builder {
protected Drawable icon;
protected Drawable background;
protected String title;
@ColorRes
protected int titleColorId = INVALID_ID;
@ -80,6 +87,11 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
return this;
}
public Builder setBackground(Drawable icon) {
this.background = icon;
return this;
}
public Builder setTitle(String title) {
this.title = title;
return this;
@ -98,6 +110,7 @@ public class SimpleBottomSheetItem extends BaseBottomSheetItem {
onClickListener,
position,
icon,
background,
title,
titleColorId);
}

View file

@ -293,7 +293,7 @@ public class SettingsMonitoringActivity extends SettingsBaseActivity {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
settings.setSharedGeneralPreference(prefId, newValue);
settings.setPreferenceForAllModes(prefId, newValue);
} else {
settings.setPreference(prefId, newValue);
}

View file

@ -100,14 +100,14 @@ public class ConfigureProfileMenuAdapter extends AbstractProfileMenuAdapter<Conf
holder.dividerBottom.setVisibility(View.VISIBLE);
holder.icon.setVisibility(View.VISIBLE);
holder.descr.setVisibility(View.VISIBLE);
holder.switcher.setVisibility(View.VISIBLE);
holder.compoundButton.setVisibility(View.VISIBLE);
holder.menuIcon.setVisibility(View.VISIBLE);
final ApplicationMode item = (ApplicationMode) obj;
holder.title.setText(item.toHumanString(app));
holder.descr.setText(BaseSettingsFragment.getAppModeDescription(app, item));
holder.initSwitcher = true;
holder.switcher.setChecked(selectedItems.contains(item));
holder.compoundButton.setChecked(selectedItems.contains(item));
holder.initSwitcher = false;
updateViewHolder(holder, item);
} else {
@ -117,7 +117,7 @@ public class ConfigureProfileMenuAdapter extends AbstractProfileMenuAdapter<Conf
}
holder.icon.setVisibility(View.INVISIBLE);
holder.descr.setVisibility(View.GONE);
holder.switcher.setVisibility(View.GONE);
holder.compoundButton.setVisibility(View.GONE);
holder.menuIcon.setVisibility(View.GONE);
holder.title.setTextColor(app.getResources().getColor(
nightMode
@ -166,7 +166,7 @@ public class ConfigureProfileMenuAdapter extends AbstractProfileMenuAdapter<Conf
}
}
});
switcher.setOnCheckedChangeListener(new OnCheckedChangeListener() {
compoundButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
int pos = getAdapterPosition();

View file

@ -65,7 +65,7 @@ public class EditProfilesFragment extends BaseOsmAndFragment {
}
nightMode = !app.getSettings().isLightContent();
View mainView =UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.edit_profiles_list_fragment, container, false);
View mainView = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.edit_profiles_list_fragment, container, false);
ImageButton closeButton = mainView.findViewById(R.id.close_button);
closeButton.setImageResource(R.drawable.ic_action_remove_dark);
closeButton.setOnClickListener(new View.OnClickListener() {
@ -355,7 +355,7 @@ public class EditProfilesFragment extends BaseOsmAndFragment {
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int pos) {
if (holder instanceof ProfileViewHolder) {
ProfileViewHolder profileViewHolder = (ProfileViewHolder) holder;
EditProfileDataObject mode = (EditProfileDataObject) items.get(pos);
final EditProfileDataObject mode = (EditProfileDataObject) items.get(pos);
profileViewHolder.title.setText(mode.getName());
profileViewHolder.description.setText(mode.getDescription());
@ -373,17 +373,15 @@ public class EditProfilesFragment extends BaseOsmAndFragment {
Drawable drawable = UiUtilities.getColoredSelectableDrawable(app, colorNoAlpha, 0.3f);
AndroidUtils.setBackground(profileViewHolder.itemsContainer, drawable);
if (mode.isCustomProfile()) {
profileViewHolder.actionIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos = holder.getAdapterPosition();
if (pos != RecyclerView.NO_POSITION) {
listener.onButtonClicked(pos);
}
profileViewHolder.actionIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos = holder.getAdapterPosition();
if (mode.isCustomProfile() && pos != RecyclerView.NO_POSITION) {
listener.onButtonClicked(pos);
}
});
}
}
});
profileViewHolder.moveIcon.setVisibility(mode.isDeleted() ? View.GONE : View.VISIBLE);
if (!mode.isDeleted()) {
int removeIconColor = mode.isCustomProfile() ? R.color.color_osm_edit_delete : R.color.icon_color_default_light;

View file

@ -1,8 +1,8 @@
package net.osmand.plus.profiles;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SwitchCompat;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@ -11,7 +11,7 @@ import net.osmand.plus.R;
public abstract class ProfileAbstractViewHolder extends RecyclerView.ViewHolder {
TextView title, descr;
SwitchCompat switcher;
CompoundButton compoundButton;
ImageView icon, menuIcon;
LinearLayout profileOptions;
View dividerBottom;
@ -21,7 +21,7 @@ public abstract class ProfileAbstractViewHolder extends RecyclerView.ViewHolder
super(itemView);
title = itemView.findViewById(R.id.title);
descr = itemView.findViewById(R.id.description);
switcher = itemView.findViewById(R.id.compound_button);
compoundButton = itemView.findViewById(R.id.compound_button);
icon = itemView.findViewById(R.id.icon);
profileOptions = itemView.findViewById(R.id.profile_settings);
dividerBottom = itemView.findViewById(R.id.divider_bottom);

View file

@ -0,0 +1,130 @@
package net.osmand.plus.profiles;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import org.apache.commons.logging.Log;
import java.util.ArrayList;
import java.util.List;
public class SelectCopyAppModeBottomSheet extends AppModesBottomSheetDialogFragment<SelectCopyProfilesMenuAdapter> {
public static final String TAG = "SelectCopyAppModeBottomSheet";
private static final String SELECTED_APP_MODE_KEY = "selected_app_mode_key";
private static final String CURRENT_APP_MODE_KEY = "current_app_mode_key";
private static final Log LOG = PlatformUtil.getLog(SelectCopyAppModeBottomSheet.class);
private List<ApplicationMode> appModes = new ArrayList<>();
private ApplicationMode selectedAppMode;
private ApplicationMode currentAppMode;
@Override
public void onCreate(Bundle savedInstanceState) {
Bundle args = getArguments();
if (args != null && args.containsKey(CURRENT_APP_MODE_KEY)) {
currentAppMode = ApplicationMode.valueOfStringKey(args.getString(CURRENT_APP_MODE_KEY), null);
}
if (currentAppMode == null) {
currentAppMode = requiredMyApplication().getSettings().getApplicationMode();
}
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
selectedAppMode = ApplicationMode.valueOfStringKey(savedInstanceState.getString(SELECTED_APP_MODE_KEY), null);
}
}
public ApplicationMode getSelectedAppMode() {
return selectedAppMode;
}
@Override
protected void getData() {
appModes = new ArrayList<>();
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
if (mode != currentAppMode) {
appModes.add(mode);
}
}
}
@Override
protected SelectCopyProfilesMenuAdapter getMenuAdapter() {
return new SelectCopyProfilesMenuAdapter(appModes, requiredMyApplication(), nightMode, selectedAppMode);
}
@Override
protected String getTitle() {
return getString(R.string.copy_from_other_profile);
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(CURRENT_APP_MODE_KEY, currentAppMode.getStringKey());
if (selectedAppMode != null) {
outState.putString(SELECTED_APP_MODE_KEY, selectedAppMode.getStringKey());
}
}
@Override
protected boolean isNightMode(@NonNull OsmandApplication app) {
if (usedOnMap) {
return app.getDaynightHelper().isNightModeForMapControlsForProfile(currentAppMode);
} else {
return !app.getSettings().isLightContentForMode(currentAppMode);
}
}
@Override
public void onProfilePressed(ApplicationMode item) {
selectedAppMode = item;
}
@Override
protected int getDismissButtonTextId() {
return R.string.shared_string_cancel;
}
@Override
protected int getRightBottomButtonTextId() {
return R.string.shared_string_copy;
}
@Override
protected void onRightBottomButtonClick() {
OsmandApplication app = getMyApplication();
if (app != null && selectedAppMode != null) {
app.getSettings().copyPreferencesFromProfile(selectedAppMode, currentAppMode);
}
dismiss();
}
public static void showInstance(@NonNull FragmentManager fm, Fragment target, boolean usedOnMap,
@NonNull ApplicationMode currentMode) {
try {
if (fm.findFragmentByTag(SelectCopyAppModeBottomSheet.TAG) == null) {
Bundle args = new Bundle();
args.putString(CURRENT_APP_MODE_KEY, currentMode.getStringKey());
SelectCopyAppModeBottomSheet fragment = new SelectCopyAppModeBottomSheet();
fragment.setTargetFragment(target, 0);
fragment.setUsedOnMap(usedOnMap);
fragment.setArguments(args);
fragment.show(fm, SelectCopyAppModeBottomSheet.TAG);
}
} catch (RuntimeException e) {
LOG.error("showInstance", e);
}
}
}

View file

@ -0,0 +1,101 @@
package net.osmand.plus.profiles;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.AndroidUtils;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import java.util.ArrayList;
import java.util.List;
public class SelectCopyProfilesMenuAdapter extends AbstractProfileMenuAdapter<SelectCopyProfilesMenuAdapter.SelectProfileViewHolder> {
private OsmandApplication app;
private ApplicationMode selectedAppMode;
private List<ApplicationMode> items = new ArrayList<>();
private boolean nightMode;
public SelectCopyProfilesMenuAdapter(List<ApplicationMode> items, @NonNull OsmandApplication app,
boolean nightMode, @Nullable ApplicationMode selectedAppMode) {
this.items.addAll(items);
this.app = app;
this.selectedAppMode = selectedAppMode;
this.nightMode = nightMode;
}
@NonNull
@Override
public SelectProfileViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = UiUtilities.getInflater(parent.getContext(), nightMode);
View itemView = inflater.inflate(R.layout.bottom_sheet_item_with_radio_btn, parent, false);
return new SelectProfileViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull final SelectProfileViewHolder holder, int position) {
ApplicationMode appMode = items.get(position);
boolean selected = appMode == selectedAppMode;
holder.title.setText(appMode.toHumanString(app));
holder.compoundButton.setChecked(selected);
updateViewHolder(holder, appMode, selected);
}
@Override
public int getItemCount() {
return items.size();
}
private void updateViewHolder(SelectProfileViewHolder holder, ApplicationMode appMode, boolean selected) {
int iconRes = appMode.getIconRes();
if (iconRes == 0 || iconRes == -1) {
iconRes = R.drawable.ic_action_world_globe;
}
int iconColor = appMode.getIconColorInfo().getColor(nightMode);
holder.icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes, iconColor));
int colorNoAlpha = ContextCompat.getColor(app, iconColor);
Drawable drawable = UiUtilities.getColoredSelectableDrawable(app, colorNoAlpha, 0.3f);
if (selected) {
Drawable[] layers = {new ColorDrawable(UiUtilities.getColorWithAlpha(colorNoAlpha, 0.15f)), drawable};
drawable = new LayerDrawable(layers);
}
AndroidUtils.setBackground(holder.itemView, drawable);
}
class SelectProfileViewHolder extends ProfileAbstractViewHolder {
SelectProfileViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos = getAdapterPosition();
if (pos != RecyclerView.NO_POSITION) {
selectedAppMode = items.get(pos);
if (profilePressedListener != null) {
profilePressedListener.onProfilePressed(selectedAppMode);
notifyDataSetChanged();
}
}
}
});
}
}
}

View file

@ -94,7 +94,7 @@ public class SelectProfileMenuAdapter extends AbstractProfileMenuAdapter<SelectP
holder.dividerUp.setVisibility(View.INVISIBLE);
holder.icon.setVisibility(View.VISIBLE);
holder.descr.setVisibility(View.VISIBLE);
holder.switcher.setVisibility(View.GONE);
holder.compoundButton.setVisibility(View.GONE);
holder.menuIcon.setVisibility(View.GONE);
final ApplicationMode item = (ApplicationMode) obj;
holder.title.setText(item.toHumanString(app));
@ -123,7 +123,7 @@ public class SelectProfileMenuAdapter extends AbstractProfileMenuAdapter<SelectP
}
holder.icon.setVisibility(View.INVISIBLE);
holder.descr.setVisibility(View.GONE);
holder.switcher.setVisibility(View.GONE);
holder.compoundButton.setVisibility(View.GONE);
holder.menuIcon.setVisibility(View.GONE);
int color = ContextCompat.getColor(app, nightMode
? R.color.active_color_primary_dark

View file

@ -32,8 +32,8 @@ import android.widget.Toast;
import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.aidl.OsmandAidlApi;
import net.osmand.aidl.ConnectedApp;
import net.osmand.aidl.OsmandAidlApi;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
@ -45,6 +45,8 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.PluginActivity;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.profiles.SelectCopyAppModeBottomSheet;
import net.osmand.plus.settings.bottomsheets.ResetProfilePrefsBottomSheet;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import net.osmand.plus.skimapsplugin.SkiMapsPlugin;
@ -69,6 +71,8 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
private static final String SETTINGS_ACTIONS = "settings_actions";
private static final String CONFIGURE_MAP = "configure_map";
private static final String CONFIGURE_SCREEN = "configure_screen";
private static final String COPY_PROFILE_SETTINGS = "copy_profile_settings";
private static final String RESET_TO_DEFAULT = "reset_to_default";
private static final String EXPORT_PROFILE = "export_profile";
private static final String DELETE_PROFILE = "delete_profile";
private static final String PROFILE_APPEARANCE = "profile_appearance";
@ -215,6 +219,8 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
PreferenceCategory settingsActions = (PreferenceCategory) findPreference(SETTINGS_ACTIONS);
settingsActions.setIconSpaceReserved(false);
setupCopyProfileSettingsPref();
setupResetToDefaultPref();
setupExportProfilePref();
setupDeleteProfilePref();
}
@ -268,6 +274,22 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
}
}
private void setupCopyProfileSettingsPref() {
Preference copyProfilePrefs = findPreference(COPY_PROFILE_SETTINGS);
copyProfilePrefs.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_copy,
isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
}
private void setupResetToDefaultPref() {
Preference resetToDefault = findPreference(RESET_TO_DEFAULT);
if (getSelectedAppMode().isCustomProfile()) {
resetToDefault.setVisible(false);
} else {
resetToDefault.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_reset_to_default_dark,
isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
}
}
private void setupExportProfilePref() {
Preference exportProfile = findPreference(EXPORT_PROFILE);
exportProfile.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_app_configuration,
@ -380,6 +402,16 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
LOG.error(e);
}
}
} else if (COPY_PROFILE_SETTINGS.equals(prefId)) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
SelectCopyAppModeBottomSheet.showInstance(fragmentManager, this, false, getSelectedAppMode());
}
} else if (RESET_TO_DEFAULT.equals(prefId)) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
ResetProfilePrefsBottomSheet.showInstance(fragmentManager, prefId, this, false, getSelectedAppMode());
}
} else if (EXPORT_PROFILE.equals(prefId)) {
Context ctx = requireContext();
final ApplicationMode profile = getSelectedAppMode();

View file

@ -521,10 +521,16 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
.setRouteService(changedProfile.routeService)
.setRoutingProfile(changedProfile.routingProfile)
.setColor(changedProfile.color);
boolean newProfile = ApplicationMode.valueOfStringKey(changedProfile.stringKey, null) == null;
ApplicationMode mode = ApplicationMode.saveProfile(builder, getMyApplication());
if (!ApplicationMode.values(app).contains(mode)) {
ApplicationMode.changeProfileAvailability(mode, true, getMyApplication());
}
if (newProfile) {
app.getSettings().copyPreferencesFromProfile(changedProfile.parent, mode);
}
return true;
}

View file

@ -54,7 +54,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
app.getSettings().setSharedGeneralPreference(prefId, newValue);
app.getSettings().setPreferenceForAllModes(prefId, newValue);
updateTargetSettings(false);
dismiss();
}

View file

@ -0,0 +1,103 @@
package net.osmand.plus.settings.bottomsheets;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.settings.BaseSettingsFragment;
public class ResetProfilePrefsBottomSheet extends BasePreferenceBottomSheet {
public static final String TAG = ResetProfilePrefsBottomSheet.class.getSimpleName();
@Override
public void createMenuItems(Bundle savedInstanceState) {
Context ctx = getContext();
if (ctx == null) {
return;
}
items.add(new TitleItem(getString(R.string.reset_all_profile_settings)));
ApplicationMode mode = getAppMode();
int profileColor = mode.getIconColorInfo().getColor(nightMode);
int colorNoAlpha = ContextCompat.getColor(ctx, profileColor);
Drawable backgroundIcon = UiUtilities.getColoredSelectableDrawable(ctx, colorNoAlpha, 0.3f);
Drawable[] layers = {new ColorDrawable(UiUtilities.getColorWithAlpha(colorNoAlpha, 0.10f)), backgroundIcon};
BaseBottomSheetItem profileItem = new BottomSheetItemWithCompoundButton.Builder()
.setChecked(true)
.setCompoundButtonColorId(profileColor)
.setButtonTintList(ColorStateList.valueOf(getResolvedColor(profileColor)))
.setDescription(BaseSettingsFragment.getAppModeDescription(ctx, mode))
.setIcon(getIcon(mode.getIconRes(), profileColor))
.setTitle(mode.toHumanString(ctx))
.setBackground(new LayerDrawable(layers))
.setLayoutId(R.layout.preference_profile_item_with_radio_btn)
.create();
items.add(profileItem);
StringBuilder description = new StringBuilder(getString(R.string.reset_confirmation_descr, getString(R.string.shared_string_reset)));
description.append("\n\n");
description.append(getString(R.string.reset_all_profile_settings_descr));
BaseBottomSheetItem resetAllSettings = new BottomSheetItemWithDescription.Builder()
.setDescription(description)
.setLayoutId(R.layout.bottom_sheet_item_pref_info)
.create();
items.add(resetAllSettings);
}
@Override
protected int getRightBottomButtonTextId() {
return R.string.shared_string_reset;
}
@Override
protected void onRightBottomButtonClick() {
OsmandApplication app = getMyApplication();
if (app != null) {
app.getSettings().resetPreferencesForProfile(getAppMode());
}
dismiss();
}
@Override
protected UiUtilities.DialogButtonType getRightBottomButtonType() {
return UiUtilities.DialogButtonType.SECONDARY;
}
public static boolean showInstance(@NonNull FragmentManager fragmentManager, String key, Fragment target,
boolean usedOnMap, @NonNull ApplicationMode appMode) {
try {
Bundle args = new Bundle();
args.putString(PREFERENCE_ID, key);
ResetProfilePrefsBottomSheet fragment = new ResetProfilePrefsBottomSheet();
fragment.setArguments(args);
fragment.setUsedOnMap(usedOnMap);
fragment.setAppMode(appMode);
fragment.setTargetFragment(target, 0);
fragment.show(fragmentManager, TAG);
return true;
} catch (RuntimeException e) {
return false;
}
}
}