diff --git a/android/res/values/donottranslate.xml b/android/res/values/donottranslate.xml index 8c2df853bb..52c8adbf46 100644 --- a/android/res/values/donottranslate.xml +++ b/android/res/values/donottranslate.xml @@ -40,6 +40,7 @@ Information Transliteration PowerManagment + ScreenSleep %1$s: %2$s %2$s :%1$s diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml index 5bdec1ba44..1d25956869 100644 --- a/android/res/values/strings.xml +++ b/android/res/values/strings.xml @@ -1130,6 +1130,8 @@ Never Automatic Maximum power saving + Allow screen to sleep + When enabled the screen will be allowed to sleep after a period of inactivity. The option turns on logging for diagnostic purposes. It can be helpful for our support staff who are troubleshooting issues with the app. Enable this option only at the request of Organic Maps support. Please check your network settings and try again No internet connection diff --git a/android/res/xml/prefs_main.xml b/android/res/xml/prefs_main.xml index b9450d9c57..935de53239 100644 --- a/android/res/xml/prefs_main.xml +++ b/android/res/xml/prefs_main.xml @@ -92,6 +92,12 @@ android:entries="@array/power_management_scheme" android:entryValues="@array/power_management_scheme_values" android:order="15"/> + { @@ -548,7 +549,9 @@ public enum LocationHelper implements Initializable mUiCallback = callback; - Utils.keepScreenOn(true, mUiCallback.getActivity().getWindow()); + if (!Config.isScreenSleepEnabled()) { + Utils.keepScreenOn(true, mUiCallback.getActivity().getWindow()); + } mUiCallback.onMyPositionModeChanged(getMyPositionMode()); if (mCompassData != null) diff --git a/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java b/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java index 0e868a7ab9..26cc887d7c 100644 --- a/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java +++ b/android/src/com/mapswithme/maps/settings/SettingsPrefsFragment.java @@ -43,6 +43,7 @@ import com.mapswithme.util.ThemeSwitcher; import com.mapswithme.util.UiUtils; import com.mapswithme.util.concurrency.UiThread; import com.mapswithme.util.log.LoggerFactory; +import com.mapswithme.util.Utils; import java.util.HashMap; import java.util.List; @@ -305,6 +306,7 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment initUseMobileDataPrefsCallbacks(); initPowerManagementPrefsCallbacks(); initCrashReports(); + initScreenSleepEnabledPrefsCallbacks(); updateTts(); } @@ -832,6 +834,25 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment pref.setOnPreferenceChangeListener((preference, newValue) -> onToggleCrashReports(newValue)); } + private void initScreenSleepEnabledPrefsCallbacks() + { + Preference pref = findPreference(getString(R.string.pref_screen_sleep)); + if (pref == null) + return; + + final boolean isScreenSleepEnabled = Config.isScreenSleepEnabled(); + ((TwoStatePreference) pref).setChecked(isScreenSleepEnabled); + pref.setOnPreferenceChangeListener( + (preference, newValue) -> + { + boolean newVal = (Boolean) newValue; + if (isScreenSleepEnabled != newVal) + Config.setScreenSleepEnabled(newVal); + Utils.keepScreenOn(!newVal, getActivity().getWindow()); + return true; + }); + } + private void removePreference(@NonNull String categoryKey, @NonNull Preference preference) { PreferenceCategory category = findPreference(categoryKey); diff --git a/android/src/com/mapswithme/util/Config.java b/android/src/com/mapswithme/util/Config.java index 426228635c..71f67798b1 100644 --- a/android/src/com/mapswithme/util/Config.java +++ b/android/src/com/mapswithme/util/Config.java @@ -38,6 +38,7 @@ public final class Config private static final String KEY_MISC_USE_MOBILE_DATA_TIMESTAMP = "UseMobileDataTimestamp"; private static final String KEY_MISC_USE_MOBILE_DATA_ROAMING = "UseMobileDataRoaming"; private static final String KEY_MISC_AD_FORBIDDEN = "AdForbidden"; + private static final String KEY_MISC_ENABLE_SCREEN_SLEEP = "EnableScreenSleep"; private Config() {} @@ -120,6 +121,8 @@ public final class Config getBool(KEY_MISC_FIRST_START_DIALOG_SEEN)) .putInt(KEY_MISC_NEWS_LAST_VERSION, getInt(KEY_MISC_NEWS_LAST_VERSION)) .putInt(KEY_LIKES_LAST_RATED_SESSION, getInt(KEY_LIKES_LAST_RATED_SESSION)) + .putBoolean(KEY_MISC_ENABLE_SCREEN_SLEEP, + getBool(KEY_MISC_ENABLE_SCREEN_SLEEP)) .apply(); } @@ -178,6 +181,16 @@ public final class Config setBool(KEY_PREF_STATISTICS, enabled); } + public static boolean isScreenSleepEnabled() + { + return getBool(KEY_MISC_ENABLE_SCREEN_SLEEP, false); + } + + public static void setScreenSleepEnabled(boolean enabled) + { + setBool(KEY_MISC_ENABLE_SCREEN_SLEEP, enabled); + } + public static boolean useGoogleServices() { return getBool(KEY_PREF_USE_GS, true);