Fix turn screen on prefs
This commit is contained in:
parent
6d160244ac
commit
af13433571
5 changed files with 34 additions and 45 deletions
|
@ -11,6 +11,7 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="default_screen_timeout">Default screen timeout</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>
|
||||
|
|
|
@ -66,13 +66,11 @@ import net.osmand.map.MapTileDownloader.IMapDownloaderCallback;
|
|||
import net.osmand.plus.AppInitializer;
|
||||
import net.osmand.plus.AppInitializer.AppInitializeListener;
|
||||
import net.osmand.plus.AppInitializer.InitEvents;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
|
||||
import net.osmand.plus.HuaweiDrmHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener;
|
||||
import net.osmand.plus.OnDismissDialogFragmentListener;
|
||||
import net.osmand.plus.settings.backend.OsmAndAppCustomization.OsmAndAppCustomizationListener;
|
||||
import net.osmand.plus.OsmAndConstants;
|
||||
import net.osmand.plus.OsmAndLocationSimulation;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -89,6 +87,7 @@ import net.osmand.plus.chooseplan.OsmLiveCancelledDialog;
|
|||
import net.osmand.plus.dashboard.DashboardOnMap;
|
||||
import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
|
||||
import net.osmand.plus.dialogs.CrashBottomSheetDialogFragment;
|
||||
import net.osmand.plus.dialogs.ImportGpxBottomSheetDialogFragment;
|
||||
import net.osmand.plus.dialogs.RateUsBottomSheetDialogFragment;
|
||||
import net.osmand.plus.dialogs.SendAnalyticsBottomSheetDialogFragment;
|
||||
import net.osmand.plus.dialogs.WhatsNewDialogFragment;
|
||||
|
@ -101,7 +100,6 @@ import net.osmand.plus.firstusage.FirstUsageWizardFragment;
|
|||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.helpers.DiscountHelper;
|
||||
import net.osmand.plus.helpers.ImportHelper;
|
||||
import net.osmand.plus.dialogs.ImportGpxBottomSheetDialogFragment;
|
||||
import net.osmand.plus.helpers.IntentHelper;
|
||||
import net.osmand.plus.helpers.LockHelper;
|
||||
import net.osmand.plus.helpers.LockHelper.LockUIAdapter;
|
||||
|
@ -134,6 +132,8 @@ import net.osmand.plus.routing.TransportRoutingHelper.TransportRouteCalculationP
|
|||
import net.osmand.plus.search.QuickSearchDialogFragment;
|
||||
import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchTab;
|
||||
import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchType;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.settings.backend.OsmAndAppCustomization.OsmAndAppCustomizationListener;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
|
||||
import net.osmand.plus.settings.fragments.BaseSettingsFragment.SettingsScreenType;
|
||||
|
@ -192,7 +192,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
private static final int ZOOM_LABEL_DISPLAY = 16;
|
||||
private static final int MIN_ZOOM_LABEL_DISPLAY = 12;
|
||||
private static final int SECOND_SPLASH_TIME_OUT = 8000;
|
||||
|
||||
|
||||
private static final int SMALL_SCROLLING_UNIT = 1;
|
||||
private static final int BIG_SCROLLING_UNIT = 200;
|
||||
|
||||
|
@ -1968,9 +1968,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
}
|
||||
|
||||
public void changeKeyguardFlags() {
|
||||
boolean turnScreenOnEnabled = getRoutingHelper().isFollowingMode();
|
||||
int turnScreenOnTime = settings.TURN_SCREEN_ON_TIME_INT.get();
|
||||
boolean enabled = turnScreenOnEnabled && (turnScreenOnTime > 0 || turnScreenOnTime == -1);
|
||||
boolean enabled = settings.TURN_SCREEN_ON_TIME_INT.get() >= 0;
|
||||
boolean keepScreenOn = !settings.USE_SYSTEM_SCREEN_TIMEOUT.get();
|
||||
changeKeyguardFlags(enabled, keepScreenOn);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ public class LockHelper implements SensorEventListener {
|
|||
private OsmandApplication app;
|
||||
private CommonPreference<Integer> turnScreenOnTime;
|
||||
private CommonPreference<Boolean> turnScreenOnSensor;
|
||||
private CommonPreference<Boolean> useSystemScreenTimeout;
|
||||
private CommonPreference<Boolean> turnScreenOnPowerButton;
|
||||
private CommonPreference<Boolean> turnScreenOnNavigationInstructions;
|
||||
|
||||
@Nullable
|
||||
|
@ -53,6 +55,8 @@ public class LockHelper implements SensorEventListener {
|
|||
OsmandSettings settings = app.getSettings();
|
||||
turnScreenOnTime = settings.TURN_SCREEN_ON_TIME_INT;
|
||||
turnScreenOnSensor = settings.TURN_SCREEN_ON_SENSOR;
|
||||
useSystemScreenTimeout = settings.USE_SYSTEM_SCREEN_TIMEOUT;
|
||||
turnScreenOnPowerButton = settings.TURN_SCREEN_ON_POWER_BUTTON;
|
||||
turnScreenOnNavigationInstructions = settings.TURN_SCREEN_ON_NAVIGATION_INSTRUCTIONS;
|
||||
|
||||
lockRunnable = new Runnable() {
|
||||
|
@ -75,6 +79,8 @@ public class LockHelper implements SensorEventListener {
|
|||
OsmandSettings settings = app.getSettings();
|
||||
turnScreenOnTime = settings.TURN_SCREEN_ON_TIME_INT;
|
||||
turnScreenOnSensor = settings.TURN_SCREEN_ON_SENSOR;
|
||||
useSystemScreenTimeout = settings.USE_SYSTEM_SCREEN_TIMEOUT;
|
||||
turnScreenOnPowerButton = settings.TURN_SCREEN_ON_POWER_BUTTON;
|
||||
turnScreenOnNavigationInstructions = settings.TURN_SCREEN_ON_NAVIGATION_INSTRUCTIONS;
|
||||
}
|
||||
};
|
||||
|
@ -107,15 +113,13 @@ public class LockHelper implements SensorEventListener {
|
|||
private void lock() {
|
||||
releaseWakeLocks();
|
||||
int unlockTime = turnScreenOnTime.get();
|
||||
if (lockUIAdapter != null && isFollowingMode() && unlockTime != -1) {
|
||||
lockUIAdapter.lock();
|
||||
if (lockUIAdapter != null) {
|
||||
if (!(useSystemScreenTimeout.get() && turnScreenOnPowerButton.get()) && unlockTime != 0) {
|
||||
lockUIAdapter.lock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isFollowingMode() {
|
||||
return app.getRoutingHelper().isFollowingMode();
|
||||
}
|
||||
|
||||
private void timedUnlock(final long millis) {
|
||||
uiHandler.removeCallbacks(lockRunnable);
|
||||
if (wakeLock == null) {
|
||||
|
@ -135,10 +139,10 @@ public class LockHelper implements SensorEventListener {
|
|||
|
||||
private void unlockEvent() {
|
||||
int unlockTime = turnScreenOnTime.get();
|
||||
if (unlockTime > 0) {
|
||||
if (unlockTime > 0 && !useSystemScreenTimeout.get()) {
|
||||
timedUnlock(unlockTime * 1000L);
|
||||
} else if (unlockTime == -1) {
|
||||
timedUnlock(-1);
|
||||
} else {
|
||||
timedUnlock(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,14 +160,6 @@ public class LockHelper implements SensorEventListener {
|
|||
}
|
||||
}
|
||||
|
||||
private void switchSensorOn() {
|
||||
switchSensor(true);
|
||||
}
|
||||
|
||||
private void switchSensorOff() {
|
||||
switchSensor(false);
|
||||
}
|
||||
|
||||
private void switchSensor(boolean on) {
|
||||
SensorManager sensorManager = (SensorManager) app.getSystemService(Context.SENSOR_SERVICE);
|
||||
if (sensorManager != null) {
|
||||
|
@ -176,23 +172,18 @@ public class LockHelper implements SensorEventListener {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean isSensorEnabled() {
|
||||
return turnScreenOnSensor.get() && isFollowingMode();
|
||||
}
|
||||
|
||||
public void onStart(@NonNull Activity activity) {
|
||||
switchSensorOff();
|
||||
switchSensor(false);
|
||||
}
|
||||
|
||||
public void onStop(@NonNull Activity activity) {
|
||||
lock();
|
||||
if (!activity.isFinishing() && isSensorEnabled()) {
|
||||
switchSensorOn();
|
||||
if (!activity.isFinishing() && turnScreenOnSensor.get()) {
|
||||
switchSensor(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void setLockUIAdapter(@Nullable LockUIAdapter adapter) {
|
||||
lockUIAdapter = adapter;
|
||||
}
|
||||
|
||||
}
|
|
@ -53,8 +53,8 @@ public class WakeTimeBottomSheet extends BasePreferenceBottomSheet {
|
|||
keepScreenOnEnabled = savedInstanceState.getBoolean(KEEP_SCREEN_ON_ENABLED);
|
||||
} else {
|
||||
int savedValIndex = listPreference.getValueIndex();
|
||||
keepScreenOnEnabled = savedValIndex == 0;
|
||||
selectedEntryIndex = savedValIndex != 0 ? savedValIndex : 1;
|
||||
keepScreenOnEnabled = savedValIndex <= 0;
|
||||
selectedEntryIndex = savedValIndex > 0 ? savedValIndex : 1;
|
||||
}
|
||||
|
||||
items.add(new TitleItem(listPreference.getDialogTitle()));
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package net.osmand.plus.settings.fragments;
|
||||
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
@ -32,11 +31,9 @@ public class TurnScreenOnFragment extends BaseSettingsFragment implements OnPref
|
|||
super.onBindPreferenceViewHolder(preference, holder);
|
||||
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;
|
||||
imageView.setEnabled(enabled);
|
||||
TextView summaryView = (TextView) holder.findViewById(android.R.id.summary);
|
||||
if (summaryView != null && !preference.isEnabled()) {
|
||||
summaryView.setText(R.string.default_screen_timeout);
|
||||
}
|
||||
} else if ("turn_screen_on_info".equals(prefId) || "turn_screen_on_options_info".equals(prefId)) {
|
||||
TextView titleView = (TextView) holder.findViewById(android.R.id.title);
|
||||
|
@ -70,12 +67,11 @@ public class TurnScreenOnFragment extends BaseSettingsFragment implements OnPref
|
|||
}
|
||||
|
||||
private void setupTurnScreenOnTimePref() {
|
||||
Integer[] entryValues = new Integer[] {-1, 0, 5, 10, 15, 20, 30, 45, 60};
|
||||
Integer[] entryValues = new Integer[] {0, 5, 10, 15, 20, 30, 45, 60};
|
||||
String[] entries = new String[entryValues.length];
|
||||
|
||||
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[0] = getString(R.string.keep_screen_on);
|
||||
for (int i = 1; i < entryValues.length; i++) {
|
||||
entries[i] = entryValues[i] + " " + getString(R.string.int_seconds);
|
||||
}
|
||||
|
||||
|
@ -100,9 +96,12 @@ public class TurnScreenOnFragment extends BaseSettingsFragment implements OnPref
|
|||
}
|
||||
|
||||
private void setupTurnScreenOnPowerButtonPref() {
|
||||
ApplicationMode appMode = getSelectedAppMode();
|
||||
boolean enabled = settings.TURN_SCREEN_ON_TIME_INT.getModeValue(appMode) == 0 || settings.USE_SYSTEM_SCREEN_TIMEOUT.getModeValue(appMode);
|
||||
SwitchPreferenceEx turnScreenOnPowerButton = (SwitchPreferenceEx) findPreference(settings.TURN_SCREEN_ON_POWER_BUTTON.getId());
|
||||
turnScreenOnPowerButton.setIcon(getPersistentPrefIcon(R.drawable.ic_action_power_button));
|
||||
turnScreenOnPowerButton.setEnabled(enabled);
|
||||
turnScreenOnPowerButton.setDescription(R.string.turn_screen_on_power_button_descr);
|
||||
turnScreenOnPowerButton.setIcon(getPersistentPrefIcon(R.drawable.ic_action_power_button));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue