From 47330b886a1568e6a7cbd60ffd1e581486da3690 Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 28 Oct 2019 15:58:54 +0200 Subject: [PATCH 1/3] Fix preferences bottom sheets state after screen rotation --- .../GeneralProfileSettingsFragment.java | 5 +- .../ChangeGeneralProfilesPrefBottomSheet.java | 22 +++++++-- .../MultiSelectPreferencesBottomSheet.java | 48 +++++++++---------- .../SingleSelectPreferenceBottomSheet.java | 17 +++---- 4 files changed, 50 insertions(+), 42 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java index fe4495fdc5..63781d62d7 100644 --- a/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/GeneralProfileSettingsFragment.java @@ -33,6 +33,7 @@ import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.settings.preferences.SwitchPreferenceEx; import net.osmand.plus.widgets.style.CustomTypefaceSpan; +import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -358,8 +359,8 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme OsmandSettings.OsmandPreference pref = settings.getPreference(prefId); if (pref instanceof CommonPreference && !((CommonPreference) pref).hasDefaultValueForMode(getSelectedAppMode())) { FragmentManager fragmentManager = getFragmentManager(); - if (fragmentManager != null) { - ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, prefId, newValue, this, false); + if (fragmentManager != null && newValue instanceof Serializable) { + ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, prefId, (Serializable) newValue, this, false); } return false; } diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java index 580fd02e5c..ba9e39aa50 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ChangeGeneralProfilesPrefBottomSheet.java @@ -18,22 +18,30 @@ import net.osmand.plus.settings.BaseSettingsFragment; import org.apache.commons.logging.Log; +import java.io.Serializable; + public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSheet { public static final String TAG = ChangeGeneralProfilesPrefBottomSheet.class.getSimpleName(); private static final Log LOG = PlatformUtil.getLog(ChangeGeneralProfilesPrefBottomSheet.class); - private Object newValue; + private static final String NEW_VALUE_KEY = "new_value_key"; + + private Serializable newValue; @Override public void createMenuItems(Bundle savedInstanceState) { final OsmandApplication app = getMyApplication(); Bundle args = getArguments(); - if (app == null || args == null || newValue == null || !args.containsKey(PREFERENCE_ID)) { + if (app == null || args == null) { return; } final String prefId = args.getString(PREFERENCE_ID); + newValue = args.getSerializable(NEW_VALUE_KEY); + if (newValue == null || prefId == null) { + return; + } items.add(new TitleItem(getString(R.string.change_default_settings))); items.add(new LongDescriptionItem(getString(R.string.apply_preference_to_all_profiles))); @@ -90,6 +98,12 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh return true; } + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putSerializable(NEW_VALUE_KEY, newValue); + } + private void updateTargetSettings() { BaseSettingsFragment target = (BaseSettingsFragment) getTargetFragment(); if (target != null) { @@ -97,16 +111,16 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh } } - public static void showInstance(@NonNull FragmentManager fm, String prefId, Object newValue, Fragment target, boolean usedOnMap) { + public static void showInstance(@NonNull FragmentManager fm, String prefId, Serializable newValue, Fragment target, boolean usedOnMap) { try { if (fm.findFragmentByTag(ChangeGeneralProfilesPrefBottomSheet.TAG) == null) { Bundle args = new Bundle(); args.putString(PREFERENCE_ID, prefId); + args.putSerializable(NEW_VALUE_KEY, newValue); ChangeGeneralProfilesPrefBottomSheet fragment = new ChangeGeneralProfilesPrefBottomSheet(); fragment.setArguments(args); fragment.setUsedOnMap(usedOnMap); - fragment.newValue = newValue; fragment.setTargetFragment(target, 0); fragment.show(fm, ChangeGeneralProfilesPrefBottomSheet.TAG); } diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/MultiSelectPreferencesBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/MultiSelectPreferencesBottomSheet.java index 6f94f6f105..b6a92b2fff 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/MultiSelectPreferencesBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/MultiSelectPreferencesBottomSheet.java @@ -41,36 +41,14 @@ public class MultiSelectPreferencesBottomSheet extends BasePreferenceBottomSheet private boolean prefChanged; - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - multiSelectBooleanPreference = getListPreference(); - if (savedInstanceState == null) { - if (multiSelectBooleanPreference.getEntries() == null || multiSelectBooleanPreference.getPrefsIds() == null) { - LOG.error("MultiSelectListPreference requires an entries array and an entryValues array."); - return; - } - enabledPrefs.clear(); - enabledPrefs.addAll(multiSelectBooleanPreference.getValues()); - prefChanged = false; - entries = multiSelectBooleanPreference.getEntries(); - prefsIds = multiSelectBooleanPreference.getPrefsIds(); - } else { - enabledPrefs.clear(); - enabledPrefs.addAll(savedInstanceState.getStringArrayList(ENABLED_PREFERENCES_IDS)); - prefChanged = savedInstanceState.getBoolean(PREFERENCE_CHANGED, false); - entries = savedInstanceState.getCharSequenceArray(PREFERENCES_ENTRIES); - prefsIds = savedInstanceState.getStringArray(PREFERENCES_IDS); - } - } - @Override public void createMenuItems(Bundle savedInstanceState) { final OsmandApplication app = getMyApplication(); - if (app == null || multiSelectBooleanPreference == null || prefsIds == null || entries == null) { + multiSelectBooleanPreference = getListPreference(); + if (app == null || multiSelectBooleanPreference == null) { return; } + readSavedState(savedInstanceState); String title = multiSelectBooleanPreference.getDialogTitle().toString(); items.add(new TitleItem(title)); @@ -151,6 +129,26 @@ public class MultiSelectPreferencesBottomSheet extends BasePreferenceBottomSheet return (MultiSelectBooleanPreference) getPreference(); } + private void readSavedState(Bundle savedInstanceState) { + if (savedInstanceState == null) { + if (multiSelectBooleanPreference.getEntries() == null || multiSelectBooleanPreference.getPrefsIds() == null) { + LOG.error("MultiSelectListPreference requires an entries array and an entryValues array."); + return; + } + enabledPrefs.clear(); + enabledPrefs.addAll(multiSelectBooleanPreference.getValues()); + prefChanged = false; + entries = multiSelectBooleanPreference.getEntries(); + prefsIds = multiSelectBooleanPreference.getPrefsIds(); + } else { + enabledPrefs.clear(); + enabledPrefs.addAll(savedInstanceState.getStringArrayList(ENABLED_PREFERENCES_IDS)); + prefChanged = savedInstanceState.getBoolean(PREFERENCE_CHANGED, false); + entries = savedInstanceState.getCharSequenceArray(PREFERENCES_ENTRIES); + prefsIds = savedInstanceState.getStringArray(PREFERENCES_IDS); + } + } + public static boolean showInstance(@NonNull FragmentManager fragmentManager, String prefId, Fragment target, boolean usedOnMap) { try { Bundle args = new Bundle(); diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/SingleSelectPreferenceBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/SingleSelectPreferenceBottomSheet.java index 24f040edd1..f994a2ab33 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/SingleSelectPreferenceBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/SingleSelectPreferenceBottomSheet.java @@ -27,23 +27,18 @@ public class SingleSelectPreferenceBottomSheet extends BasePreferenceBottomSheet private int selectedEntryIndex = -1; - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - listPreference = getListPreference(); - if (savedInstanceState != null) { - selectedEntryIndex = savedInstanceState.getInt(SELECTED_ENTRY_INDEX_KEY); - } else if (listPreference != null) { - selectedEntryIndex = listPreference.findIndexOfValue(listPreference.getValue()); - } - } - @Override public void createMenuItems(Bundle savedInstanceState) { Context ctx = getContext(); + listPreference = getListPreference(); if (ctx == null || listPreference == null || listPreference.getEntries() == null || listPreference.getEntryValues() == null) { return; } + if (savedInstanceState != null) { + selectedEntryIndex = savedInstanceState.getInt(SELECTED_ENTRY_INDEX_KEY); + } else { + selectedEntryIndex = listPreference.findIndexOfValue(listPreference.getValue()); + } String title = listPreference.getDialogTitle().toString(); items.add(new TitleItem(title)); From 11e10634c1ac8022031923568e1ab78f95f2de45 Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 28 Oct 2019 16:00:47 +0200 Subject: [PATCH 2/3] Fix dependent preferences screens --- OsmAnd/src/net/osmand/plus/settings/ProxySettingsFragment.java | 1 + OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java | 1 + OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java | 1 + 3 files changed, 3 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/settings/ProxySettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProxySettingsFragment.java index 95a146f8f3..a7479f63cc 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProxySettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProxySettingsFragment.java @@ -28,6 +28,7 @@ public class ProxySettingsFragment extends BaseSettingsFragment { setupProxyHostPref(); setupProxyPortPref(); + enableDisablePreferences(settings.ENABLE_PROXY.get()); } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java b/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java index 804102646c..1f123f5580 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ScreenAlertsFragment.java @@ -38,6 +38,7 @@ public class ScreenAlertsFragment extends BaseSettingsFragment { showTunnels.setIcon(getIcon(R.drawable.list_warnings_tunnel)); setupScreenAlertsImage(); + enableDisablePreferences(settings.SHOW_ROUTING_ALARMS.get()); } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java b/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java index 0d1b26574d..fe4015e4cf 100644 --- a/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/TurnScreenOnFragment.java @@ -24,6 +24,7 @@ public class TurnScreenOnFragment extends BaseSettingsFragment { setupTurnScreenOnTimePref(); setupTurnScreenOnSensorPref(); + enableDisablePreferences(settings.TURN_SCREEN_ON_ENABLED.get()); } @Override From db4dec3c56332a013bc9b67d459088ac1ce7bad0 Mon Sep 17 00:00:00 2001 From: Chumva Date: Mon, 28 Oct 2019 16:02:14 +0200 Subject: [PATCH 3/3] Fix preferences toolbar size and icons color --- .../res/layout/global_preference_toolbar.xml | 9 +++++---- .../global_preferences_toolbar_with_switch.xml | 3 +-- .../res/layout/profile_preference_toolbar.xml | 3 +-- .../layout/profile_preference_toolbar_big.xml | 3 +-- .../profile_preference_toolbar_with_switch.xml | 3 +-- .../GeneralProfileSettingsFragment.java | 18 +++++++++--------- .../plus/settings/MainSettingsFragment.java | 2 +- .../plus/settings/RouteParametersFragment.java | 4 ++-- .../settings/VehicleParametersFragment.java | 6 +++--- 9 files changed, 24 insertions(+), 27 deletions(-) diff --git a/OsmAnd/res/layout/global_preference_toolbar.xml b/OsmAnd/res/layout/global_preference_toolbar.xml index 9f14b4c110..961d6c2a7e 100644 --- a/OsmAnd/res/layout/global_preference_toolbar.xml +++ b/OsmAnd/res/layout/global_preference_toolbar.xml @@ -4,14 +4,16 @@ xmlns:tools="http://schemas.android.com/tools" android:id="@+id/toolbar" android:layout_width="match_parent" - android:layout_height="@dimen/toolbar_height" + android:layout_height="wrap_content" android:background="?attr/actionModeBackground" + android:minHeight="@dimen/toolbar_height" app:contentInsetLeft="0dp" app:contentInsetStart="0dp"> + android:layout_height="wrap_content" + android:gravity="center_vertical">