From b202b7ac6d9f3d621ca01b99dbc3300228212bea Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 26 May 2020 11:25:34 +0300 Subject: [PATCH 1/8] Added Always setting (from 28a958535a69e1f2a8131582b54db807cd63ab95) --- OsmAnd/res/values/strings.xml | 1 + .../net/osmand/plus/activities/MapActivity.java | 4 +++- .../src/net/osmand/plus/helpers/LockHelper.java | 15 +++++++++++---- .../settings/fragments/TurnScreenOnFragment.java | 7 ++++--- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 65a1231387..c37fefafb4 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + Always Unsupported type World overview map (detailed) Could not find any such profiles. diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 75330977de..6c839ad8ab 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -1968,7 +1968,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } public void changeKeyguardFlags() { - boolean enabled = settings.TURN_SCREEN_ON_ENABLED.get() && settings.TURN_SCREEN_ON_TIME_INT.get() > 0; + boolean turnScreenOnEnabled = settings.TURN_SCREEN_ON_ENABLED.get() && getRoutingHelper().isFollowingMode(); + int turnScreenOnTime = settings.TURN_SCREEN_ON_TIME_INT.get(); + boolean enabled = turnScreenOnEnabled && (turnScreenOnTime > 0 || turnScreenOnTime == -1); boolean keepScreenOn = !settings.USE_SYSTEM_SCREEN_TIMEOUT.get(); changeKeyguardFlags(enabled, keepScreenOn); } diff --git a/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java b/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java index 85fdc3535a..9d50aa8f63 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java @@ -104,7 +104,8 @@ public class LockHelper implements SensorEventListener { private void lock() { releaseWakeLocks(); - if (lockUIAdapter != null && isFollowingMode()) { + int unlockTime = turnScreenOnTime.get(); + if (lockUIAdapter != null && isFollowingMode() && unlockTime != -1) { lockUIAdapter.lock(); } } @@ -125,13 +126,19 @@ public class LockHelper implements SensorEventListener { } }); } - uiHandler.postDelayed(lockRunnable, millis); + if (millis > 0) { + uiHandler.postDelayed(lockRunnable, millis); + } } private void unlockEvent() { int unlockTime = turnScreenOnTime.get(); - if (unlockTime > 0 && turnScreenOnEnabled.get()) { - timedUnlock(unlockTime * 1000L); + if (turnScreenOnEnabled.get()) { + if (unlockTime > 0) { + timedUnlock(unlockTime * 1000L); + } else if (unlockTime == -1) { + timedUnlock(-1); + } } } diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java index a4ebc2215c..4c55d3d637 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java @@ -90,11 +90,12 @@ public class TurnScreenOnFragment extends BaseSettingsFragment { } private void setupTurnScreenOnTimePref() { - Integer[] entryValues = new Integer[] {0, 5, 10, 15, 20, 30, 45, 60}; + Integer[] entryValues = new Integer[] {-1, 0, 5, 10, 15, 20, 30, 45, 60}; String[] entries = new String[entryValues.length]; - entries[0] = getString(R.string.shared_string_never); - for (int i = 1; i < entryValues.length; i++) { + entries[0] = getString(R.string.shared_string_always); + entries[1] = getString(R.string.shared_string_never); + for (int i = 2; i < entryValues.length; i++) { entries[i] = entryValues[i] + " " + getString(R.string.int_seconds); } From ad8aea4e7a89c30e975df78aba52424ccbc2b00d Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 26 May 2020 17:11:59 +0300 Subject: [PATCH 2/8] Add icons for Screen settings (cherry picked from commit db102c41b6163d55f9ebe3531fb8c215459e4323) --- .../res/drawable/ic_action_external_link.xml | 14 +++++++++++++ .../ic_action_notification_navigation.xml | 20 +++++++++++++++++++ .../res/drawable/ic_action_power_button.xml | 19 ++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 OsmAnd/res/drawable/ic_action_external_link.xml create mode 100644 OsmAnd/res/drawable/ic_action_notification_navigation.xml create mode 100644 OsmAnd/res/drawable/ic_action_power_button.xml diff --git a/OsmAnd/res/drawable/ic_action_external_link.xml b/OsmAnd/res/drawable/ic_action_external_link.xml new file mode 100644 index 0000000000..b445171abc --- /dev/null +++ b/OsmAnd/res/drawable/ic_action_external_link.xml @@ -0,0 +1,14 @@ + + + + diff --git a/OsmAnd/res/drawable/ic_action_notification_navigation.xml b/OsmAnd/res/drawable/ic_action_notification_navigation.xml new file mode 100644 index 0000000000..1901192493 --- /dev/null +++ b/OsmAnd/res/drawable/ic_action_notification_navigation.xml @@ -0,0 +1,20 @@ + + + + + diff --git a/OsmAnd/res/drawable/ic_action_power_button.xml b/OsmAnd/res/drawable/ic_action_power_button.xml new file mode 100644 index 0000000000..6e88c236a6 --- /dev/null +++ b/OsmAnd/res/drawable/ic_action_power_button.xml @@ -0,0 +1,19 @@ + + + + + From 7c8e44c95d6b2359e634645d95458e864861a4ed Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 26 May 2020 17:27:31 +0300 Subject: [PATCH 3/8] Remove unnecessary preference --- .../osmand/plus/activities/MapActivity.java | 2 +- .../net/osmand/plus/helpers/LockHelper.java | 19 +++++++------------ .../plus/settings/backend/OsmandSettings.java | 4 +--- .../preferences/SwitchPreferenceEx.java | 4 ++++ 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 6c839ad8ab..1abb37b1e4 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -1968,7 +1968,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } public void changeKeyguardFlags() { - boolean turnScreenOnEnabled = settings.TURN_SCREEN_ON_ENABLED.get() && getRoutingHelper().isFollowingMode(); + boolean turnScreenOnEnabled = getRoutingHelper().isFollowingMode(); int turnScreenOnTime = settings.TURN_SCREEN_ON_TIME_INT.get(); boolean enabled = turnScreenOnEnabled && (turnScreenOnTime > 0 || turnScreenOnTime == -1); boolean keepScreenOn = !settings.USE_SYSTEM_SCREEN_TIMEOUT.get(); diff --git a/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java b/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java index 9d50aa8f63..03ad3289de 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java @@ -14,11 +14,11 @@ import android.os.PowerManager.WakeLock; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import net.osmand.plus.settings.backend.OsmAndAppCustomization.OsmAndAppCustomizationListener; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.routing.VoiceRouter.VoiceMessageListener; +import net.osmand.plus.settings.backend.OsmAndAppCustomization.OsmAndAppCustomizationListener; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference; -import net.osmand.plus.routing.VoiceRouter.VoiceMessageListener; import java.util.List; @@ -33,7 +33,6 @@ public class LockHelper implements SensorEventListener { private OsmandApplication app; private CommonPreference turnScreenOnTime; private CommonPreference turnScreenOnSensor; - private CommonPreference turnScreenOnEnabled; @Nullable private LockUIAdapter lockUIAdapter; @@ -51,7 +50,6 @@ public class LockHelper implements SensorEventListener { this.app = app; uiHandler = new Handler(); OsmandSettings settings = app.getSettings(); - turnScreenOnEnabled = settings.TURN_SCREEN_ON_ENABLED; turnScreenOnTime = settings.TURN_SCREEN_ON_TIME_INT; turnScreenOnSensor = settings.TURN_SCREEN_ON_SENSOR; @@ -71,7 +69,6 @@ public class LockHelper implements SensorEventListener { @Override public void onOsmAndSettingsCustomized() { OsmandSettings settings = app.getSettings(); - turnScreenOnEnabled = settings.TURN_SCREEN_ON_ENABLED; turnScreenOnTime = settings.TURN_SCREEN_ON_TIME_INT; turnScreenOnSensor = settings.TURN_SCREEN_ON_SENSOR; } @@ -133,12 +130,10 @@ public class LockHelper implements SensorEventListener { private void unlockEvent() { int unlockTime = turnScreenOnTime.get(); - if (turnScreenOnEnabled.get()) { - if (unlockTime > 0) { - timedUnlock(unlockTime * 1000L); - } else if (unlockTime == -1) { - timedUnlock(-1); - } + if (unlockTime > 0) { + timedUnlock(unlockTime * 1000L); + } else if (unlockTime == -1) { + timedUnlock(-1); } } @@ -186,7 +181,7 @@ public class LockHelper implements SensorEventListener { public void onStop(@NonNull Activity activity) { lock(); - if (!activity.isFinishing() && turnScreenOnEnabled.get() && isSensorEnabled()) { + if (!activity.isFinishing() && isSensorEnabled()) { switchSensorOn(); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index b3d5dce45a..5e36f05769 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -2030,8 +2030,6 @@ public class OsmandSettings { public final CommonPreference PROXY_PORT = new IntPreference("proxy_port", 8118).makeGlobal(); public final CommonPreference USER_ANDROID_ID = new StringPreference("user_android_id", "").makeGlobal(); - public final CommonPreference USE_SYSTEM_SCREEN_TIMEOUT = new BooleanPreference("use_system_screen_timeout", false).makeGlobal(); - // this value string is synchronized with settings_pref.xml preference name public static final String SAVE_CURRENT_TRACK = "save_current_track"; //$NON-NLS-1$ @@ -2272,7 +2270,7 @@ public class OsmandSettings { KEEP_INFORMING.setModeDefaultValue(ApplicationMode.PEDESTRIAN, 0); } - public final CommonPreference TURN_SCREEN_ON_ENABLED = new BooleanPreference("turn_screen_on_enabled", false).makeProfile(); + public final CommonPreference USE_SYSTEM_SCREEN_TIMEOUT = new BooleanPreference("use_system_screen_timeout", false).makeProfile(); public final CommonPreference TURN_SCREEN_ON_TIME_INT = new IntPreference("turn_screen_on_time_int", 0).makeProfile(); diff --git a/OsmAnd/src/net/osmand/plus/settings/preferences/SwitchPreferenceEx.java b/OsmAnd/src/net/osmand/plus/settings/preferences/SwitchPreferenceEx.java index 18b46138c4..75902f4778 100644 --- a/OsmAnd/src/net/osmand/plus/settings/preferences/SwitchPreferenceEx.java +++ b/OsmAnd/src/net/osmand/plus/settings/preferences/SwitchPreferenceEx.java @@ -33,6 +33,10 @@ public class SwitchPreferenceEx extends SwitchPreferenceCompat { this.description = description; } + public void setDescription(int titleResId) { + setDescription(getContext().getString(titleResId)); + } + @Override protected void onClick() { if (getFragment() == null && getIntent() == null) { From 80f9bbdc5fdf82532b7bb2826ca1b58da6421f2d Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 26 May 2020 17:40:08 +0300 Subject: [PATCH 4/8] Move turn screen on prefs to new screen --- OsmAnd/res/values/strings.xml | 5 ++ OsmAnd/res/xml/general_profile_settings.xml | 8 +++ OsmAnd/res/xml/global_settings.xml | 11 --- OsmAnd/res/xml/navigation_settings_new.xml | 9 --- OsmAnd/res/xml/turn_screen_on.xml | 35 ++++++++-- .../plus/settings/backend/OsmandSettings.java | 4 ++ .../fragments/BaseSettingsFragment.java | 2 +- .../GeneralProfileSettingsFragment.java | 6 ++ .../fragments/GlobalSettingsFragment.java | 11 +-- .../fragments/NavigationFragment.java | 2 - .../fragments/TurnScreenOnFragment.java | 67 ++----------------- 11 files changed, 64 insertions(+), 96 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index c37fefafb4..94c1a55675 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,11 @@ Thx - Hardy --> + Those options will work, only if OsmAnd will be on the foreground when the device will be locked. + Use these options to wake up screen with OsmAnd on the foreground. + Screen timeout + Enable so the screen turns off after a certain period of inactivity, the time specified in the system settings of your device will be used. + Screen control Always Unsupported type World overview map (detailed) diff --git a/OsmAnd/res/xml/general_profile_settings.xml b/OsmAnd/res/xml/general_profile_settings.xml index 9196b5d7fa..e0c7ec3fa7 100644 --- a/OsmAnd/res/xml/general_profile_settings.xml +++ b/OsmAnd/res/xml/general_profile_settings.xml @@ -1,6 +1,7 @@ + + diff --git a/OsmAnd/res/xml/global_settings.xml b/OsmAnd/res/xml/global_settings.xml index 32f31fb859..de67e9fb54 100644 --- a/OsmAnd/res/xml/global_settings.xml +++ b/OsmAnd/res/xml/global_settings.xml @@ -60,15 +60,4 @@ app:fragment="net.osmand.plus.settings.fragments.ProxySettingsFragment" tools:icon="@drawable/ic_action_proxy" /> - - - - \ No newline at end of file diff --git a/OsmAnd/res/xml/navigation_settings_new.xml b/OsmAnd/res/xml/navigation_settings_new.xml index 25df608227..28886abad6 100644 --- a/OsmAnd/res/xml/navigation_settings_new.xml +++ b/OsmAnd/res/xml/navigation_settings_new.xml @@ -56,15 +56,6 @@ android:title="@string/map_during_navigation" app:fragment="net.osmand.plus.settings.fragments.MapDuringNavigationFragment" /> - - + android:title="@string/screen_control"> + + + + + + + android:title="@string/turn_screen_on_descr" /> + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index 5e36f05769..1a336e50eb 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -2288,6 +2288,10 @@ public class OsmandSettings { TURN_SCREEN_ON_SENSOR.setModeDefaultValue(ApplicationMode.PEDESTRIAN, false); } + public final CommonPreference TURN_SCREEN_ON_NAVIGATION_INSTRUCTIONS = new BooleanPreference("turn_screen_on_navigation_instructions", false).makeProfile(); + + public final CommonPreference TURN_SCREEN_ON_POWER_BUTTON = new BooleanPreference("turn_screen_on_power_button", false).makeProfile(); + // this value string is synchronized with settings_pref.xml preference name // try without AUTO_FOLLOW_ROUTE_NAV (see forum discussion 'Simplify our navigation preference menu') //public final CommonPreference AUTO_FOLLOW_ROUTE_NAV = new BooleanPreference("auto_follow_route_navigation", true, false); diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java index aef82939d1..692b81057d 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java @@ -122,7 +122,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl VOICE_ANNOUNCES(VoiceAnnouncesFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.voice_announces, R.layout.profile_preference_toolbar_with_switch), VEHICLE_PARAMETERS(VehicleParametersFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.vehicle_parameters, R.layout.profile_preference_toolbar), MAP_DURING_NAVIGATION(MapDuringNavigationFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.map_during_navigation, R.layout.profile_preference_toolbar), - TURN_SCREEN_ON(TurnScreenOnFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.turn_screen_on, R.layout.profile_preference_toolbar_with_switch), + TURN_SCREEN_ON(TurnScreenOnFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.turn_screen_on, R.layout.profile_preference_toolbar), DATA_STORAGE(DataStorageFragment.class.getName(), false, null, R.xml.data_storage, R.layout.global_preference_toolbar), DIALOGS_AND_NOTIFICATIONS_SETTINGS(DialogsAndNotificationsSettingsFragment.class.getName(), false, null, R.xml.dialogs_and_notifications_preferences, R.layout.global_preferences_toolbar_with_switch), PROFILE_APPEARANCE(ProfileAppearanceFragment.TAG, true, null, R.xml.profile_appearance, R.layout.profile_preference_toolbar), diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java index 9e07badc98..4ac4d78d32 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/GeneralProfileSettingsFragment.java @@ -46,6 +46,7 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme setupRotateMapPref(); setupCenterPositionOnMapPref(); setupMapScreenOrientationPref(); + setupTurnScreenOnPref(); setupDrivingRegionPref(); setupUnitsOfLengthPref(); @@ -137,6 +138,11 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme mapScreenOrientation.setIcon(getMapScreenOrientationIcon()); } + private void setupTurnScreenOnPref() { + Preference screenControl = findPreference("screen_control"); + screenControl.setIcon(getContentIcon(R.drawable.ic_action_turn_screen_on)); + } + private Drawable getMapScreenOrientationIcon() { switch (settings.MAP_SCREEN_ORIENTATION.getModeValue(getSelectedAppMode())) { case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java index 95ac579399..d99537215f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/GlobalSettingsFragment.java @@ -10,12 +10,12 @@ import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; import androidx.preference.SwitchPreferenceCompat; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.SettingsGeneralActivity; import net.osmand.plus.dialogs.SendAnalyticsBottomSheetDialogFragment; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.settings.preferences.SwitchPreferenceEx; @@ -36,7 +36,6 @@ public class GlobalSettingsFragment extends BaseSettingsFragment implements Send setupSendAnonymousDataPref(); setupDialogsAndNotificationsPref(); setupEnableProxyPref(); - setupUseSystemScreenTimeout(); } @Override @@ -192,10 +191,4 @@ public class GlobalSettingsFragment extends BaseSettingsFragment implements Send SwitchPreferenceEx enableProxy = (SwitchPreferenceEx) findPreference(settings.ENABLE_PROXY.getId()); enableProxy.setIcon(getPersistentPrefIcon(R.drawable.ic_action_proxy)); } - - private void setupUseSystemScreenTimeout() { - SwitchPreferenceEx useSystemScreenTimeout = (SwitchPreferenceEx) findPreference(settings.USE_SYSTEM_SCREEN_TIMEOUT.getId()); - useSystemScreenTimeout.setTitle(app.getString(R.string.use_system_screen_timeout)); - useSystemScreenTimeout.setDescription(app.getString(R.string.use_system_screen_timeout_promo)); - } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/NavigationFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/NavigationFragment.java index 6f666952f5..cb9aba42dd 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/NavigationFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/NavigationFragment.java @@ -57,12 +57,10 @@ public class NavigationFragment extends BaseSettingsFragment { Preference routeParameters = findPreference("route_parameters"); SwitchPreferenceCompat showRoutingAlarms = (SwitchPreferenceCompat) findPreference(settings.SHOW_ROUTING_ALARMS.getId()); - SwitchPreferenceCompat turnScreenOn = (SwitchPreferenceCompat) findPreference(settings.TURN_SCREEN_ON_ENABLED.getId()); SwitchPreferenceEx animateMyLocation = (SwitchPreferenceEx) findPreference(settings.ANIMATE_MY_LOCATION.getId()); routeParameters.setIcon(getContentIcon(R.drawable.ic_action_route_distance)); showRoutingAlarms.setIcon(getPersistentPrefIcon(R.drawable.ic_action_alert)); - turnScreenOn.setIcon(getPersistentPrefIcon(R.drawable.ic_action_turn_screen_on)); setupSpeakRoutingAlarmsPref(); setupVehicleParametersPref(); diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java index 4c55d3d637..56f331e91d 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java @@ -1,54 +1,23 @@ package net.osmand.plus.settings.fragments; -import android.graphics.drawable.ColorDrawable; -import android.view.LayoutInflater; -import android.view.View; import android.widget.ImageView; -import android.widget.TextView; -import androidx.appcompat.widget.SwitchCompat; -import androidx.core.content.ContextCompat; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; -import net.osmand.AndroidUtils; -import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.R; -import net.osmand.plus.UiUtilities; import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.settings.preferences.SwitchPreferenceEx; -import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR; - public class TurnScreenOnFragment extends BaseSettingsFragment { public static final String TAG = TurnScreenOnFragment.class.getSimpleName(); @Override protected void setupPreferences() { - Preference turnScreenOnInfo = findPreference("turn_screen_on_info"); - turnScreenOnInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark)); - + setupUseSystemScreenTimeout(); setupTurnScreenOnTimePref(); setupTurnScreenOnSensorPref(); - enableDisablePreferences(settings.TURN_SCREEN_ON_ENABLED.getModeValue(getSelectedAppMode())); - } - - @Override - protected void createToolbar(LayoutInflater inflater, View view) { - super.createToolbar(inflater, view); - - view.findViewById(R.id.toolbar_switch_container).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - ApplicationMode selectedMode = getSelectedAppMode(); - boolean checked = !settings.TURN_SCREEN_ON_ENABLED.getModeValue(selectedMode); - onConfirmPreferenceChange( - settings.TURN_SCREEN_ON_ENABLED.getId(), checked, ApplyQueryType.SNACK_BAR); - updateToolbarSwitch(); - enableDisablePreferences(checked); - } - }); } @Override @@ -64,29 +33,10 @@ public class TurnScreenOnFragment extends BaseSettingsFragment { } } - @Override - protected void updateToolbar() { - super.updateToolbar(); - updateToolbarSwitch(); - } - - private void updateToolbarSwitch() { - View view = getView(); - if (view == null) { - return; - } - boolean checked = settings.TURN_SCREEN_ON_ENABLED.getModeValue(getSelectedAppMode()); - - int color = checked ? getActiveProfileColor() : ContextCompat.getColor(app, R.color.preference_top_switch_off); - View switchContainer = view.findViewById(R.id.toolbar_switch_container); - AndroidUtils.setBackground(switchContainer, new ColorDrawable(color)); - - SwitchCompat switchView = (SwitchCompat) switchContainer.findViewById(R.id.switchWidget); - switchView.setChecked(checked); - UiUtilities.setupCompoundButton(switchView, isNightMode(), TOOLBAR); - - TextView title = switchContainer.findViewById(R.id.switchButtonText); - title.setText(checked ? R.string.shared_string_on : R.string.shared_string_off); + private void setupUseSystemScreenTimeout() { + SwitchPreferenceEx useSystemScreenTimeout = (SwitchPreferenceEx) findPreference(settings.USE_SYSTEM_SCREEN_TIMEOUT.getId()); + useSystemScreenTimeout.setTitle(app.getString(R.string.system_screen_timeout)); + useSystemScreenTimeout.setDescription(app.getString(R.string.system_screen_timeout_descr)); } private void setupTurnScreenOnTimePref() { @@ -106,12 +56,9 @@ public class TurnScreenOnFragment extends BaseSettingsFragment { } private void setupTurnScreenOnSensorPref() { - String title = getString(R.string.turn_screen_on_sensor); - String description = getString(R.string.turn_screen_on_sensor_descr); - SwitchPreferenceEx turnScreenOnSensor = (SwitchPreferenceEx) findPreference(settings.TURN_SCREEN_ON_SENSOR.getId()); turnScreenOnSensor.setIcon(getPersistentPrefIcon(R.drawable.ic_action_sensor_interaction)); - turnScreenOnSensor.setTitle(title); - turnScreenOnSensor.setDescription(description); + turnScreenOnSensor.setTitle(R.string.turn_screen_on_sensor); + turnScreenOnSensor.setDescription(R.string.turn_screen_on_sensor_descr); } } \ No newline at end of file From f46e57f30b3a71fe6b4473f3bba5dc74f2822a61 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 26 May 2020 19:06:31 +0300 Subject: [PATCH 5/8] Add systemScreenTimeout dialog and two turn screen on prefs --- OsmAnd/res/values/strings.xml | 5 ++ OsmAnd/res/xml/turn_screen_on.xml | 16 ++++- .../ScreenTimeoutBottomSheet.java | 72 +++++++++++++++++++ .../fragments/TurnScreenOnFragment.java | 34 +++++++-- 4 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/settings/bottomsheets/ScreenTimeoutBottomSheet.java diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 94c1a55675..72bd3e327f 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,11 @@ Thx - Hardy --> + Proximity sensor + Power button + Press on the device power button to turn on screen with OsmAnd on the foreground. + Navigation instructions + Screen will turn on automatically a few seconds before navigation instructions for a specified time in “Wake time” option.\n\nWork only while navigation. Those options will work, only if OsmAnd will be on the foreground when the device will be locked. Use these options to wake up screen with OsmAnd on the foreground. Screen timeout diff --git a/OsmAnd/res/xml/turn_screen_on.xml b/OsmAnd/res/xml/turn_screen_on.xml index 2a3830fb42..94b0242ba8 100644 --- a/OsmAnd/res/xml/turn_screen_on.xml +++ b/OsmAnd/res/xml/turn_screen_on.xml @@ -46,6 +46,20 @@ android:layout="@layout/preference_with_descr_dialog_and_switch" android:summaryOff="@string/shared_string_disabled" android:summaryOn="@string/shared_string_enabled" - android:title="@string/turn_screen_on_sensor" /> + android:title="@string/turn_screen_on_proximity_sensor" /> + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ScreenTimeoutBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ScreenTimeoutBottomSheet.java new file mode 100644 index 0000000000..ea40f40704 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/ScreenTimeoutBottomSheet.java @@ -0,0 +1,72 @@ +package net.osmand.plus.settings.bottomsheets; + +import android.content.Intent; +import android.os.Bundle; +import android.provider.Settings; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; + +import net.osmand.AndroidUtils; +import net.osmand.PlatformUtil; +import net.osmand.plus.R; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.fragments.ApplyQueryType; + +import org.apache.commons.logging.Log; + +public class ScreenTimeoutBottomSheet extends BooleanPreferenceBottomSheet { + + public static final String TAG = ScreenTimeoutBottomSheet.class.getSimpleName(); + + private static final Log LOG = PlatformUtil.getLog(ScreenTimeoutBottomSheet.class); + + @Override + public void createMenuItems(Bundle savedInstanceState) { + super.createMenuItems(savedInstanceState); + + BaseBottomSheetItem preferenceDescription = new BottomSheetItemWithDescription.Builder() + .setTitle(getString(R.string.change_default_settings)) + .setIcon(getContentIcon(R.drawable.ic_action_external_link)) + .setTitleColorId(nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light) + .setLayoutId(R.layout.bottom_sheet_item_simple_right_icon) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(Settings.ACTION_DISPLAY_SETTINGS); + if (AndroidUtils.isIntentSafe(v.getContext(), intent)) { + startActivity(intent); + } + } + }) + .create(); + items.add(preferenceDescription); + } + + public static void showInstance(@NonNull FragmentManager fm, String prefId, Fragment target, boolean usedOnMap, + @Nullable ApplicationMode appMode, ApplyQueryType applyQueryType, + boolean profileDependent) { + try { + if (fm.findFragmentByTag(ScreenTimeoutBottomSheet.TAG) == null) { + Bundle args = new Bundle(); + args.putString(PREFERENCE_ID, prefId); + + ScreenTimeoutBottomSheet fragment = new ScreenTimeoutBottomSheet(); + fragment.setArguments(args); + fragment.setUsedOnMap(usedOnMap); + fragment.setAppMode(appMode); + fragment.setApplyQueryType(applyQueryType); + fragment.setTargetFragment(target, 0); + fragment.setProfileDependent(profileDependent); + fragment.show(fm, ScreenTimeoutBottomSheet.TAG); + } + } catch (RuntimeException e) { + LOG.error("showInstance", e); + } + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java index 56f331e91d..d6bd9477c0 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java @@ -2,10 +2,12 @@ package net.osmand.plus.settings.fragments; import android.widget.ImageView; +import androidx.fragment.app.FragmentManager; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; import net.osmand.plus.R; +import net.osmand.plus.settings.bottomsheets.ScreenTimeoutBottomSheet; import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.settings.preferences.SwitchPreferenceEx; @@ -18,6 +20,8 @@ public class TurnScreenOnFragment extends BaseSettingsFragment { setupUseSystemScreenTimeout(); setupTurnScreenOnTimePref(); setupTurnScreenOnSensorPref(); + setupTurnScreenOnNavigationInstructionsPref(); + setupTurnScreenOnPowerButtonPref(); } @Override @@ -33,10 +37,21 @@ public class TurnScreenOnFragment extends BaseSettingsFragment { } } + @Override + public void onDisplayPreferenceDialog(Preference preference) { + if (settings.USE_SYSTEM_SCREEN_TIMEOUT.getId().equals(preference.getKey())) { + FragmentManager fragmentManager = getFragmentManager(); + if (fragmentManager != null) { + ScreenTimeoutBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, getSelectedAppMode(), getApplyQueryType(), isProfileDependent()); + } + } else { + super.onDisplayPreferenceDialog(preference); + } + } + private void setupUseSystemScreenTimeout() { - SwitchPreferenceEx useSystemScreenTimeout = (SwitchPreferenceEx) findPreference(settings.USE_SYSTEM_SCREEN_TIMEOUT.getId()); - useSystemScreenTimeout.setTitle(app.getString(R.string.system_screen_timeout)); - useSystemScreenTimeout.setDescription(app.getString(R.string.system_screen_timeout_descr)); + SwitchPreferenceEx systemScreenTimeout = (SwitchPreferenceEx) findPreference(settings.USE_SYSTEM_SCREEN_TIMEOUT.getId()); + systemScreenTimeout.setDescription(R.string.system_screen_timeout_descr); } private void setupTurnScreenOnTimePref() { @@ -58,7 +73,18 @@ public class TurnScreenOnFragment extends BaseSettingsFragment { private void setupTurnScreenOnSensorPref() { SwitchPreferenceEx turnScreenOnSensor = (SwitchPreferenceEx) findPreference(settings.TURN_SCREEN_ON_SENSOR.getId()); turnScreenOnSensor.setIcon(getPersistentPrefIcon(R.drawable.ic_action_sensor_interaction)); - turnScreenOnSensor.setTitle(R.string.turn_screen_on_sensor); turnScreenOnSensor.setDescription(R.string.turn_screen_on_sensor_descr); } + + private void setupTurnScreenOnNavigationInstructionsPref() { + SwitchPreferenceEx turnScreenOnNavigationInstructions = (SwitchPreferenceEx) findPreference(settings.TURN_SCREEN_ON_NAVIGATION_INSTRUCTIONS.getId()); + turnScreenOnNavigationInstructions.setIcon(getPersistentPrefIcon(R.drawable.ic_action_notification_navigation)); + turnScreenOnNavigationInstructions.setDescription(R.string.turn_screen_on_navigation_instructions_descr); + } + + private void setupTurnScreenOnPowerButtonPref() { + SwitchPreferenceEx turnScreenOnPowerButton = (SwitchPreferenceEx) findPreference(settings.TURN_SCREEN_ON_POWER_BUTTON.getId()); + turnScreenOnPowerButton.setIcon(getPersistentPrefIcon(R.drawable.ic_action_power_button)); + turnScreenOnPowerButton.setDescription(R.string.turn_screen_on_power_button_descr); + } } \ No newline at end of file From 152e3f1ebb92f2574a95b069b6a4d9034d337f28 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 28 May 2020 12:25:25 +0300 Subject: [PATCH 6/8] Add turn screen on nav instructions pref --- OsmAnd/src/net/osmand/plus/helpers/LockHelper.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java b/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java index 03ad3289de..fb61f1f915 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java @@ -33,6 +33,7 @@ public class LockHelper implements SensorEventListener { private OsmandApplication app; private CommonPreference turnScreenOnTime; private CommonPreference turnScreenOnSensor; + private CommonPreference turnScreenOnNavigationInstructions; @Nullable private LockUIAdapter lockUIAdapter; @@ -52,6 +53,7 @@ public class LockHelper implements SensorEventListener { OsmandSettings settings = app.getSettings(); turnScreenOnTime = settings.TURN_SCREEN_ON_TIME_INT; turnScreenOnSensor = settings.TURN_SCREEN_ON_SENSOR; + turnScreenOnNavigationInstructions = settings.TURN_SCREEN_ON_NAVIGATION_INSTRUCTIONS; lockRunnable = new Runnable() { @Override @@ -62,7 +64,9 @@ public class LockHelper implements SensorEventListener { voiceMessageListener = new VoiceMessageListener() { @Override public void onVoiceMessage(List listCommands, List played) { - unlockEvent(); + if (turnScreenOnNavigationInstructions.get()) { + unlockEvent(); + } } }; OsmAndAppCustomizationListener customizationListener = new OsmAndAppCustomizationListener() { @@ -71,6 +75,7 @@ public class LockHelper implements SensorEventListener { OsmandSettings settings = app.getSettings(); turnScreenOnTime = settings.TURN_SCREEN_ON_TIME_INT; turnScreenOnSensor = settings.TURN_SCREEN_ON_SENSOR; + turnScreenOnNavigationInstructions = settings.TURN_SCREEN_ON_NAVIGATION_INSTRUCTIONS; } }; app.getAppCustomization().addListener(customizationListener); From e5701769638b67fa19a0e0867c7238c2433581b4 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 28 May 2020 12:41:02 +0300 Subject: [PATCH 7/8] Disable wake time pref if screen timeout enabled --- .../settings/fragments/BaseSettingsFragment.java | 2 +- .../settings/fragments/TurnScreenOnFragment.java | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java index 692b81057d..e222ba09d6 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java @@ -122,7 +122,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl VOICE_ANNOUNCES(VoiceAnnouncesFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.voice_announces, R.layout.profile_preference_toolbar_with_switch), VEHICLE_PARAMETERS(VehicleParametersFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.vehicle_parameters, R.layout.profile_preference_toolbar), MAP_DURING_NAVIGATION(MapDuringNavigationFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.map_during_navigation, R.layout.profile_preference_toolbar), - TURN_SCREEN_ON(TurnScreenOnFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.turn_screen_on, R.layout.profile_preference_toolbar), + TURN_SCREEN_ON(TurnScreenOnFragment.class.getName(), true, ApplyQueryType.BOTTOM_SHEET, R.xml.turn_screen_on, R.layout.profile_preference_toolbar), DATA_STORAGE(DataStorageFragment.class.getName(), false, null, R.xml.data_storage, R.layout.global_preference_toolbar), DIALOGS_AND_NOTIFICATIONS_SETTINGS(DialogsAndNotificationsSettingsFragment.class.getName(), false, null, R.xml.dialogs_and_notifications_preferences, R.layout.global_preferences_toolbar_with_switch), PROFILE_APPEARANCE(ProfileAppearanceFragment.TAG, true, null, R.xml.profile_appearance, R.layout.profile_preference_toolbar), diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java index d6bd9477c0..ed7fb98719 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java @@ -11,7 +11,7 @@ import net.osmand.plus.settings.bottomsheets.ScreenTimeoutBottomSheet; import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.settings.preferences.SwitchPreferenceEx; -public class TurnScreenOnFragment extends BaseSettingsFragment { +public class TurnScreenOnFragment extends BaseSettingsFragment implements OnPreferenceChanged { public static final String TAG = TurnScreenOnFragment.class.getSimpleName(); @@ -65,6 +65,7 @@ public class TurnScreenOnFragment extends BaseSettingsFragment { } ListPreferenceEx turnScreenOnTime = (ListPreferenceEx) findPreference(settings.TURN_SCREEN_ON_TIME_INT.getId()); + turnScreenOnTime.setEnabled(!settings.USE_SYSTEM_SCREEN_TIMEOUT.getModeValue(getSelectedAppMode())); turnScreenOnTime.setEntries(entries); turnScreenOnTime.setEntryValues(entryValues); turnScreenOnTime.setIcon(getPersistentPrefIcon(R.drawable.ic_action_time_span)); @@ -87,4 +88,14 @@ public class TurnScreenOnFragment extends BaseSettingsFragment { turnScreenOnPowerButton.setIcon(getPersistentPrefIcon(R.drawable.ic_action_power_button)); turnScreenOnPowerButton.setDescription(R.string.turn_screen_on_power_button_descr); } + + @Override + public void onPreferenceChanged(String prefId) { + if (settings.USE_SYSTEM_SCREEN_TIMEOUT.getId().equals(prefId)) { + Preference turnScreenOnTime = findPreference(settings.TURN_SCREEN_ON_TIME_INT.getId()); + if (turnScreenOnTime != null) { + turnScreenOnTime.setEnabled(!settings.USE_SYSTEM_SCREEN_TIMEOUT.getModeValue(getSelectedAppMode())); + } + } + } } \ No newline at end of file From b37d96836853f06c17455705a2c2d0be8b31e95e Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 28 May 2020 15:55:51 +0300 Subject: [PATCH 8/8] Add wake time dialog --- OsmAnd/res/layout/bottom_sheet_item_descr.xml | 19 ++ .../bottom_sheet_item_with_switch_no_icon.xml | 8 +- OsmAnd/res/values/strings.xml | 4 + .../simpleitems/TitleItem.java | 4 +- .../BooleanPreferenceBottomSheet.java | 2 +- .../bottomsheets/WakeTimeBottomSheet.java | 206 ++++++++++++++++++ .../fragments/TurnScreenOnFragment.java | 26 ++- .../preferences/ListPreferenceEx.java | 2 +- 8 files changed, 259 insertions(+), 12 deletions(-) create mode 100644 OsmAnd/res/layout/bottom_sheet_item_descr.xml create mode 100644 OsmAnd/src/net/osmand/plus/settings/bottomsheets/WakeTimeBottomSheet.java diff --git a/OsmAnd/res/layout/bottom_sheet_item_descr.xml b/OsmAnd/res/layout/bottom_sheet_item_descr.xml new file mode 100644 index 0000000000..33ab71b1ec --- /dev/null +++ b/OsmAnd/res/layout/bottom_sheet_item_descr.xml @@ -0,0 +1,19 @@ + + \ No newline at end of file diff --git a/OsmAnd/res/layout/bottom_sheet_item_with_switch_no_icon.xml b/OsmAnd/res/layout/bottom_sheet_item_with_switch_no_icon.xml index d90d4fd44d..148e20cb46 100644 --- a/OsmAnd/res/layout/bottom_sheet_item_with_switch_no_icon.xml +++ b/OsmAnd/res/layout/bottom_sheet_item_with_switch_no_icon.xml @@ -1,17 +1,18 @@ + android:paddingRight="@dimen/content_padding"> - + If the \"%1$s\" option is enabled, the activity time will depend on it. + Keep screen off + Keep screen on + Select the screen activity time after waking up, the screen will not turn off if \"%1$s\" is enabled. Proximity sensor Power button Press on the device power button to turn on screen with OsmAnd on the foreground. diff --git a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleItem.java b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleItem.java index 966f02ef03..fb94762851 100644 --- a/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleItem.java +++ b/OsmAnd/src/net/osmand/plus/base/bottomsheetmenu/simpleitems/TitleItem.java @@ -10,12 +10,12 @@ import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; public class TitleItem extends SimpleBottomSheetItem { - public TitleItem(String title) { + public TitleItem(CharSequence title) { this.title = title; this.layoutId = R.layout.bottom_sheet_item_title; } - public TitleItem(String title, @ColorRes int titleColorId) { + public TitleItem(CharSequence title, @ColorRes int titleColorId) { this.title = title; this.layoutId = R.layout.bottom_sheet_item_title; this.titleColorId = titleColorId; diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanPreferenceBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanPreferenceBottomSheet.java index 88df995e44..c988dbdf68 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanPreferenceBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanPreferenceBottomSheet.java @@ -111,7 +111,7 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet { if (description != null) { BaseBottomSheetItem preferenceDescription = new BottomSheetItemWithDescription.Builder() .setDescription(description) - .setLayoutId(R.layout.bottom_sheet_item_preference_descr) + .setLayoutId(R.layout.bottom_sheet_item_descr) .create(); items.add(preferenceDescription); } diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/WakeTimeBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/WakeTimeBottomSheet.java new file mode 100644 index 0000000000..5cf26a5060 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/WakeTimeBottomSheet.java @@ -0,0 +1,206 @@ +package net.osmand.plus.settings.bottomsheets; + +import android.content.Context; +import android.os.Bundle; +import android.view.View; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; + +import com.google.android.material.slider.Slider; + +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.DividerItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; +import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.fragments.ApplyQueryType; +import net.osmand.plus.settings.fragments.OnPreferenceChanged; +import net.osmand.plus.settings.preferences.ListPreferenceEx; + +public class WakeTimeBottomSheet extends BasePreferenceBottomSheet { + + public static final String TAG = WakeTimeBottomSheet.class.getSimpleName(); + + private static final String SELECTED_ENTRY_INDEX_KEY = "selected_entry_index_key"; + private static final String KEEP_SCREEN_ON_ENABLED = "keep_screen_on_enabled"; + + private ListPreferenceEx listPreference; + + private View sliderView; + + private int selectedEntryIndex = 1; + private boolean keepScreenOnEnabled; + + @Override + public void createMenuItems(Bundle savedInstanceState) { + Context ctx = getContext(); + listPreference = getListPreference(); + if (ctx == null || listPreference == null) { + return; + } + if (savedInstanceState != null) { + selectedEntryIndex = savedInstanceState.getInt(SELECTED_ENTRY_INDEX_KEY); + keepScreenOnEnabled = savedInstanceState.getBoolean(KEEP_SCREEN_ON_ENABLED); + } else { + int savedValIndex = listPreference.getValueIndex(); + keepScreenOnEnabled = savedValIndex == 0; + selectedEntryIndex = savedValIndex != 0 ? savedValIndex : 1; + } + + items.add(new TitleItem(listPreference.getDialogTitle())); + + BaseBottomSheetItem preferenceDescription = new BottomSheetItemWithDescription.Builder() + .setDescription(listPreference.getDescription()) + .setLayoutId(R.layout.bottom_sheet_item_descr) + .create(); + items.add(preferenceDescription); + + final String on = getString(R.string.keep_screen_on); + final String off = getString(R.string.keep_screen_off); + final BottomSheetItemWithCompoundButton[] preferenceBtn = new BottomSheetItemWithCompoundButton[1]; + preferenceBtn[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() + .setChecked(keepScreenOnEnabled) + .setTitle(keepScreenOnEnabled ? on : off) + .setLayoutId(R.layout.bottom_sheet_item_with_switch_no_icon) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + keepScreenOnEnabled = !keepScreenOnEnabled; + preferenceBtn[0].setTitle(keepScreenOnEnabled ? on : off); + preferenceBtn[0].setChecked(keepScreenOnEnabled); + AndroidUiHelper.updateVisibility(sliderView, !keepScreenOnEnabled); + setupHeightAndBackground(getView()); + } + }) + .create(); + items.add(preferenceBtn[0]); + + DividerItem dividerItem = new DividerItem(ctx); + int topMargin = ctx.getResources().getDimensionPixelSize(R.dimen.context_menu_subtitle_margin); + int startMargin = ctx.getResources().getDimensionPixelSize(R.dimen.content_padding); + dividerItem.setMargins(startMargin, topMargin, 0, 0); + items.add(dividerItem); + items.add(new DividerSpaceItem(ctx, ctx.getResources().getDimensionPixelSize(R.dimen.content_padding_small))); + + sliderView = UiUtilities.getInflater(ctx, nightMode).inflate(R.layout.bottom_sheet_item_slider_with_two_text, null); + AndroidUiHelper.updateVisibility(sliderView, !keepScreenOnEnabled); + + Context themedCtx = UiUtilities.getThemedContext(ctx, nightMode); + + TextView tvSliderTitle = sliderView.findViewById(android.R.id.title); + tvSliderTitle.setText(getString(R.string.shared_string_time)); + + final TextView tvSliderSummary = sliderView.findViewById(android.R.id.summary); + tvSliderSummary.setText(listPreference.getEntries()[selectedEntryIndex]); + + Slider slider = sliderView.findViewById(R.id.slider); + slider.setValue(selectedEntryIndex); + slider.setStepSize(1); + slider.setValueFrom(1); + slider.setValueTo(listPreference.getEntryValues().length - 1); + slider.addOnChangeListener(new Slider.OnChangeListener() { + @Override + public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) { + if (fromUser) { + selectedEntryIndex = (int) value; + tvSliderSummary.setText(listPreference.getEntries()[selectedEntryIndex]); + } + } + }); + + int appModeColorId = getAppMode().getIconColorInfo().getColor(nightMode); + int appModeColor = ContextCompat.getColor(themedCtx, appModeColorId); + UiUtilities.setupSlider(slider, nightMode, appModeColor, true); + + items.add(new BaseBottomSheetItem.Builder() + .setCustomView(sliderView) + .create()); + + BaseBottomSheetItem timeoutDescription = new BottomSheetItemWithDescription.Builder() + .setDescription(getString(R.string.screen_timeout_descr, getString(R.string.system_screen_timeout))) + .setLayoutId(R.layout.bottom_sheet_item_descr) + .create(); + items.add(timeoutDescription); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + for (BaseBottomSheetItem item : items) { + if (item instanceof BottomSheetItemWithCompoundButton) { + BottomSheetItemWithCompoundButton itemWithCompoundButton = (BottomSheetItemWithCompoundButton) item; + itemWithCompoundButton.getCompoundButton().setSaveEnabled(false); + } + } + } + + @Override + protected void onRightBottomButtonClick() { + if (keepScreenOnEnabled) { + selectedEntryIndex = 0; + } + Object[] entryValues = listPreference.getEntryValues(); + if (entryValues != null && selectedEntryIndex >= 0) { + Object value = entryValues[selectedEntryIndex]; + if (listPreference.callChangeListener(value)) { + listPreference.setValue(value); + } + Fragment target = getTargetFragment(); + if (target instanceof OnPreferenceChanged) { + ((OnPreferenceChanged) target).onPreferenceChanged(listPreference.getKey()); + } + } + dismiss(); + } + + @Override + protected int getDismissButtonTextId() { + return R.string.shared_string_cancel; + } + + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_apply; + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putInt(SELECTED_ENTRY_INDEX_KEY, selectedEntryIndex); + outState.putBoolean(KEEP_SCREEN_ON_ENABLED, keepScreenOnEnabled); + } + + private ListPreferenceEx getListPreference() { + return (ListPreferenceEx) getPreference(); + } + + public static boolean showInstance(@NonNull FragmentManager fragmentManager, String prefId, Fragment target, boolean usedOnMap, + @Nullable ApplicationMode appMode, ApplyQueryType applyQueryType, + boolean profileDependent) { + try { + Bundle args = new Bundle(); + args.putString(PREFERENCE_ID, prefId); + + WakeTimeBottomSheet fragment = new WakeTimeBottomSheet(); + fragment.setArguments(args); + fragment.setUsedOnMap(usedOnMap); + fragment.setAppMode(appMode); + fragment.setApplyQueryType(applyQueryType); + fragment.setTargetFragment(target, 0); + fragment.setProfileDependent(profileDependent); + fragment.show(fragmentManager, TAG); + return true; + } catch (RuntimeException e) { + return false; + } + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java index ed7fb98719..96e462c32e 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java @@ -1,13 +1,16 @@ package net.osmand.plus.settings.fragments; import android.widget.ImageView; +import android.widget.TextView; import androidx.fragment.app.FragmentManager; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; import net.osmand.plus.R; +import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.bottomsheets.ScreenTimeoutBottomSheet; +import net.osmand.plus.settings.bottomsheets.WakeTimeBottomSheet; import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.settings.preferences.SwitchPreferenceEx; @@ -27,22 +30,34 @@ public class TurnScreenOnFragment extends BaseSettingsFragment implements OnPref @Override protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) { super.onBindPreferenceViewHolder(preference, holder); - if (settings.TURN_SCREEN_ON_TIME_INT.getId().equals(preference.getKey()) && preference instanceof ListPreferenceEx) { + String prefId = preference.getKey(); + if (settings.TURN_SCREEN_ON_TIME_INT.getId().equals(prefId) && preference instanceof ListPreferenceEx) { Object currentValue = ((ListPreferenceEx) preference).getValue(); ImageView imageView = (ImageView) holder.findViewById(android.R.id.icon); if (imageView != null && currentValue instanceof Integer) { - boolean enabled = preference.isEnabled() && (Integer) currentValue > 0; + boolean enabled = preference.isEnabled() && (Integer) currentValue != 0; imageView.setEnabled(enabled); } + } else if ("turn_screen_on_info".equals(prefId) || "turn_screen_on_options_info".equals(prefId)) { + TextView titleView = (TextView) holder.findViewById(android.R.id.title); + if (titleView != null) { + titleView.setTextColor(getDisabledTextColor()); + } } } @Override public void onDisplayPreferenceDialog(Preference preference) { - if (settings.USE_SYSTEM_SCREEN_TIMEOUT.getId().equals(preference.getKey())) { - FragmentManager fragmentManager = getFragmentManager(); + FragmentManager fragmentManager = getFragmentManager(); + ApplicationMode appMode = getSelectedAppMode(); + String prefId = preference.getKey(); + if (settings.USE_SYSTEM_SCREEN_TIMEOUT.getId().equals(prefId)) { if (fragmentManager != null) { - ScreenTimeoutBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, getSelectedAppMode(), getApplyQueryType(), isProfileDependent()); + ScreenTimeoutBottomSheet.showInstance(fragmentManager, prefId, this, false, appMode, getApplyQueryType(), isProfileDependent()); + } + } else if (settings.TURN_SCREEN_ON_TIME_INT.getId().equals(prefId)) { + if (fragmentManager != null) { + WakeTimeBottomSheet.showInstance(fragmentManager, prefId, this, false, appMode, getApplyQueryType(), isProfileDependent()); } } else { super.onDisplayPreferenceDialog(preference); @@ -68,6 +83,7 @@ public class TurnScreenOnFragment extends BaseSettingsFragment implements OnPref turnScreenOnTime.setEnabled(!settings.USE_SYSTEM_SCREEN_TIMEOUT.getModeValue(getSelectedAppMode())); turnScreenOnTime.setEntries(entries); turnScreenOnTime.setEntryValues(entryValues); + turnScreenOnTime.setDescription(getString(R.string.turn_screen_on_wake_time_descr, getString(R.string.keep_screen_on))); turnScreenOnTime.setIcon(getPersistentPrefIcon(R.drawable.ic_action_time_span)); } diff --git a/OsmAnd/src/net/osmand/plus/settings/preferences/ListPreferenceEx.java b/OsmAnd/src/net/osmand/plus/settings/preferences/ListPreferenceEx.java index 27e0c5a9c0..0743cd9c8b 100644 --- a/OsmAnd/src/net/osmand/plus/settings/preferences/ListPreferenceEx.java +++ b/OsmAnd/src/net/osmand/plus/settings/preferences/ListPreferenceEx.java @@ -87,7 +87,7 @@ public class ListPreferenceEx extends DialogPreference { return -1; } - private int getValueIndex() { + public int getValueIndex() { return findIndexOfValue(selectedValue); }