Add systemScreenTimeout dialog and two turn screen on prefs

This commit is contained in:
Vitaliy 2020-05-26 19:06:31 +03:00
parent 80f9bbdc5f
commit f46e57f30b
4 changed files with 122 additions and 5 deletions

View file

@ -11,6 +11,11 @@
Thx - Hardy
-->
<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>

View file

@ -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" />
<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

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

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