Merge branch 'r3.7'

This commit is contained in:
max-klaus 2020-05-28 20:37:54 +03:00
commit c85f72a106
21 changed files with 476 additions and 120 deletions

View file

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

View file

@ -1,17 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_list_item_height"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingStart="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding"
android:paddingStart="@dimen/content_padding">
android:paddingRight="@dimen/content_padding">
<TextView
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -21,6 +22,7 @@
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.ListItemTitle"
app:typeface="@string/font_roboto_regular"
tools:text="Some Title" />
<androidx.appcompat.widget.SwitchCompat

View file

@ -28,6 +28,21 @@
<string name="sqlite_db_file">SQLiteDB file</string>
<string name="one_image_per_tile">One image file per tile</string>
<string name="pseudo_mercator_projection">Pseudo-Mercator projection</string>
<string name="screen_timeout_descr">If the \"%1$s\" option is enabled, the activity time will depend on it.</string>
<string name="keep_screen_off">Keep screen off</string>
<string name="keep_screen_on">Keep screen on</string>
<string name="turn_screen_on_wake_time_descr">Select the screen activity time after waking up, the screen will not turn off if \"%1$s\" is enabled.</string>
<string name="turn_screen_on_proximity_sensor">Proximity sensor</string>
<string name="turn_screen_on_power_button">Power button</string>
<string name="turn_screen_on_power_button_descr">Press on the device power button to turn on screen with OsmAnd on the foreground.</string>
<string name="turn_screen_on_navigation_instructions">Navigation instructions</string>
<string name="turn_screen_on_navigation_instructions_descr">Screen will turn on automatically a few seconds before navigation instructions for a specified time in “Wake time” option.\n\nWork only while navigation.</string>
<string name="turn_screen_on_descr">Those options will work, only if OsmAnd will be on the foreground when the device will be locked.</string>
<string name="turn_screen_on_options_descr">Use these options to wake up screen with OsmAnd on the foreground.</string>
<string name="system_screen_timeout">Screen timeout</string>
<string name="system_screen_timeout_descr">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.</string>
<string name="screen_control">Screen control</string>
<string name="shared_string_always">Always</string>
<string name="gpx_parse_error">OsmAnd GPX is not well formed, please contact support team to investigate further</string>
<string name="unsupported_type_error">Unsupported type</string>
<string name="index_item_world_basemap_detailed">World overview map (detailed)</string>

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:title="@string/general_settings_2">
<PreferenceCategory
@ -30,6 +31,13 @@
android:layout="@layout/preference_with_descr"
android:title="@string/map_screen_orientation" />
<Preference
android:key="screen_control"
android:layout="@layout/preference_with_descr"
android:title="@string/screen_control"
app:fragment="net.osmand.plus.settings.fragments.TurnScreenOnFragment"
tools:icon="@drawable/ic_action_turn_screen_on" />
<Preference
android:layout="@layout/simple_divider_item"
android:selectable="false" />

View file

@ -60,15 +60,4 @@
app:fragment="net.osmand.plus.settings.fragments.ProxySettingsFragment"
tools:icon="@drawable/ic_action_proxy" />
<Preference
android:layout="@layout/simple_divider_item"
android:selectable="false" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="use_system_screen_timeout"
android:layout="@layout/preference_with_descr_dialog_and_switch"
android:summaryOff="@string/shared_string_disabled"
android:summaryOn="@string/shared_string_enabled"
android:title="@string/use_system_screen_timeout" />
</PreferenceScreen>

View file

@ -56,15 +56,6 @@
android:title="@string/map_during_navigation"
app:fragment="net.osmand.plus.settings.fragments.MapDuringNavigationFragment" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="turn_screen_on_enabled"
android:layout="@layout/preference_with_descr_dialog_and_switch"
android:summaryOff="@string/shared_string_off"
android:summaryOn="@string/shared_string_on"
android:title="@string/turn_screen_on"
app:fragment="net.osmand.plus.settings.fragments.TurnScreenOnFragment"
tools:icon="@drawable/ic_action_turn_screen_on" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="animate_my_location"
android:layout="@layout/preference_with_descr_dialog_and_switch"

View file

@ -1,24 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/turn_screen_on">
android:title="@string/screen_control">
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="use_system_screen_timeout"
android:layout="@layout/preference_with_descr_dialog_and_switch"
android:summaryOff="@string/shared_string_disabled"
android:summaryOn="@string/shared_string_enabled"
android:title="@string/system_screen_timeout" />
<Preference
android:layout="@layout/simple_divider_item"
android:selectable="false" />
<PreferenceCategory
android:key="turn_screen_on"
android:layout="@layout/preference_category_with_descr"
android:title="@string/turn_screen_on" />
<Preference
android:key="turn_screen_on_info"
android:layout="@layout/preference_info"
android:persistent="false"
android:selectable="false"
android:title="@string/turn_screen_on_info" />
android:title="@string/turn_screen_on_descr" />
<net.osmand.plus.settings.preferences.ListPreferenceEx
android:key="turn_screen_on_time_int"
android:layout="@layout/preference_with_descr"
android:title="@string/wake_time" />
<Preference
android:layout="@layout/divider_half_item"
android:selectable="false" />
<Preference
android:key="turn_screen_on_options_info"
android:layout="@layout/preference_info"
android:persistent="false"
android:selectable="false"
android:title="@string/turn_screen_on_options_descr" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="turn_screen_on_sensor"
android:layout="@layout/preference_with_descr_dialog_and_switch"
android:summaryOff="@string/shared_string_off"
android:summaryOn="@string/shared_string_on"
android:title="@string/turn_screen_on_sensor" />
android:summaryOff="@string/shared_string_disabled"
android:summaryOn="@string/shared_string_enabled"
android:title="@string/turn_screen_on_proximity_sensor" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="turn_screen_on_navigation_instructions"
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_navigation_instructions" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="turn_screen_on_power_button"
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_power_button" />
</PreferenceScreen>

View file

@ -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);
}

View file

@ -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;

View file

@ -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<Integer> turnScreenOnTime;
private CommonPreference<Boolean> turnScreenOnSensor;
private CommonPreference<Boolean> turnScreenOnEnabled;
private CommonPreference<Boolean> 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<String> listCommands, List<String> 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();
}
}

View file

@ -2030,8 +2030,6 @@ public class OsmandSettings {
public final CommonPreference<Integer> PROXY_PORT = new IntPreference("proxy_port", 8118).makeGlobal();
public final CommonPreference<String> USER_ANDROID_ID = new StringPreference("user_android_id", "").makeGlobal();
public final CommonPreference<Boolean> 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<Boolean> TURN_SCREEN_ON_ENABLED = new BooleanPreference("turn_screen_on_enabled", false).makeProfile();
public final CommonPreference<Boolean> USE_SYSTEM_SCREEN_TIMEOUT = new BooleanPreference("use_system_screen_timeout", false).makeProfile();
public final CommonPreference<Integer> 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<Boolean> TURN_SCREEN_ON_NAVIGATION_INSTRUCTIONS = new BooleanPreference("turn_screen_on_navigation_instructions", false).makeProfile();
public final CommonPreference<Boolean> 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<Boolean> AUTO_FOLLOW_ROUTE_NAV = new BooleanPreference("auto_follow_route_navigation", true, false);

View file

@ -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);
}

View file

@ -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);
}
}
}

View file

@ -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;
}
}
}

View file

@ -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),

View file

@ -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:

View file

@ -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));
}
}

View file

@ -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();

View file

@ -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()));
}
}
}
}

View file

@ -87,7 +87,7 @@ public class ListPreferenceEx extends DialogPreference {
return -1;
}
private int getValueIndex() {
public int getValueIndex() {
return findIndexOfValue(selectedValue);
}

View file

@ -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) {