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">
-
SQLiteDB file
One image file per tile
Pseudo-Mercator projection
+ 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.
+ 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
+ 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
OsmAnd GPX is not well formed, please contact support team to investigate further
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" />
+
+
+
+
+ android:summaryOff="@string/shared_string_disabled"
+ android:summaryOn="@string/shared_string_enabled"
+ android:title="@string/turn_screen_on_proximity_sensor" />
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java
index 75330977de..1abb37b1e4 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 = 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/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/helpers/LockHelper.java b/OsmAnd/src/net/osmand/plus/helpers/LockHelper.java
index 85fdc3535a..fb61f1f915 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,7 @@ public class LockHelper implements SensorEventListener {
private OsmandApplication app;
private CommonPreference turnScreenOnTime;
private CommonPreference turnScreenOnSensor;
- private CommonPreference turnScreenOnEnabled;
+ private CommonPreference turnScreenOnNavigationInstructions;
@Nullable
private LockUIAdapter lockUIAdapter;
@@ -51,9 +51,9 @@ 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;
+ turnScreenOnNavigationInstructions = settings.TURN_SCREEN_ON_NAVIGATION_INSTRUCTIONS;
lockRunnable = new Runnable() {
@Override
@@ -64,16 +64,18 @@ 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() {
@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;
+ turnScreenOnNavigationInstructions = settings.TURN_SCREEN_ON_NAVIGATION_INSTRUCTIONS;
}
};
app.getAppCustomization().addListener(customizationListener);
@@ -104,7 +106,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 +128,17 @@ 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()) {
+ if (unlockTime > 0) {
timedUnlock(unlockTime * 1000L);
+ } else if (unlockTime == -1) {
+ timedUnlock(-1);
}
}
@@ -179,7 +186,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..1a336e50eb 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();
@@ -2290,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/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/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/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/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java
index ca633e3885..d0ed8f7515 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.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_preference_toolbar),
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 a4ebc2215c..96e462c32e 100644
--- a/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/fragments/TurnScreenOnFragment.java
@@ -1,116 +1,117 @@
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.fragment.app.FragmentManager;
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.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;
-import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR;
-
-public class TurnScreenOnFragment extends BaseSettingsFragment {
+public class TurnScreenOnFragment extends BaseSettingsFragment implements OnPreferenceChanged {
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);
- }
- });
+ setupTurnScreenOnNavigationInstructionsPref();
+ setupTurnScreenOnPowerButtonPref();
}
@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
- protected void updateToolbar() {
- super.updateToolbar();
- updateToolbarSwitch();
+ public void onDisplayPreferenceDialog(Preference preference) {
+ 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, 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);
+ }
}
- 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 systemScreenTimeout = (SwitchPreferenceEx) findPreference(settings.USE_SYSTEM_SCREEN_TIMEOUT.getId());
+ systemScreenTimeout.setDescription(R.string.system_screen_timeout_descr);
}
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);
}
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.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));
}
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.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);
+ }
+
+ @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
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);
}
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) {