Merge pull request #9111 from osmandapp/screen_timeout_fixes

Fix screen timeout
This commit is contained in:
max-klaus 2020-05-30 13:51:17 +03:00 committed by GitHub
commit 873fb38c0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 5 deletions

View file

@ -58,6 +58,7 @@
<net.osmand.plus.settings.preferences.SwitchPreferenceEx <net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="turn_screen_on_power_button" android:key="turn_screen_on_power_button"
android:layout="@layout/preference_with_descr_dialog_and_switch" android:layout="@layout/preference_with_descr_dialog_and_switch"
android:persistent="false"
android:summaryOff="@string/shared_string_disabled" android:summaryOff="@string/shared_string_disabled"
android:summaryOn="@string/shared_string_enabled" android:summaryOn="@string/shared_string_enabled"
android:title="@string/turn_screen_on_power_button" /> android:title="@string/turn_screen_on_power_button" />

View file

@ -1977,11 +1977,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
if (enable) { if (enable) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED, getWindow().setFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED,
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
setKeepScreenOn(true);
} else { } else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
setKeepScreenOn(forceKeepScreenOn);
} }
setKeepScreenOn(forceKeepScreenOn);
} }
@Override @Override

View file

@ -10,20 +10,26 @@ import android.hardware.SensorManager;
import android.os.Handler; import android.os.Handler;
import android.os.PowerManager; import android.os.PowerManager;
import android.os.PowerManager.WakeLock; import android.os.PowerManager.WakeLock;
import android.provider.Settings;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.routing.VoiceRouter.VoiceMessageListener; import net.osmand.plus.routing.VoiceRouter.VoiceMessageListener;
import net.osmand.plus.settings.backend.OsmAndAppCustomization.OsmAndAppCustomizationListener; import net.osmand.plus.settings.backend.OsmAndAppCustomization.OsmAndAppCustomizationListener;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference; import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import org.apache.commons.logging.Log;
import java.util.List; import java.util.List;
public class LockHelper implements SensorEventListener { public class LockHelper implements SensorEventListener {
private static final Log LOG = PlatformUtil.getLog(LockHelper.class);
private static final int SENSOR_SENSITIVITY = 4; private static final int SENSOR_SENSITIVITY = 4;
@Nullable @Nullable
@ -138,14 +144,29 @@ public class LockHelper implements SensorEventListener {
} }
private void unlockEvent() { private void unlockEvent() {
int unlockTime = turnScreenOnTime.get(); int unlockTime = getUnlockTime();
if (unlockTime > 0 && !useSystemScreenTimeout.get()) { if (unlockTime > 0) {
timedUnlock(unlockTime * 1000L); timedUnlock(unlockTime * 1000L);
} else { } else {
timedUnlock(0); timedUnlock(0);
} }
} }
private int getUnlockTime() {
int unlockTime = turnScreenOnTime.get();
if (useSystemScreenTimeout.get()) {
try {
int screenOffTimeout = Settings.System.getInt(app.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 0);
if (screenOffTimeout > 0) {
unlockTime = screenOffTimeout / 1000;
}
} catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}
return unlockTime;
}
@Override @Override
public void onAccuracyChanged(Sensor sensor, int accuracy) { public void onAccuracyChanged(Sensor sensor, int accuracy) {

View file

@ -97,11 +97,12 @@ public class TurnScreenOnFragment extends BaseSettingsFragment implements OnPref
private void setupTurnScreenOnPowerButtonPref() { private void setupTurnScreenOnPowerButtonPref() {
ApplicationMode appMode = getSelectedAppMode(); ApplicationMode appMode = getSelectedAppMode();
boolean enabled = settings.TURN_SCREEN_ON_TIME_INT.getModeValue(appMode) == 0 || settings.USE_SYSTEM_SCREEN_TIMEOUT.getModeValue(appMode); boolean enabled = settings.TURN_SCREEN_ON_TIME_INT.get() == 0 || settings.USE_SYSTEM_SCREEN_TIMEOUT.get();
SwitchPreferenceEx turnScreenOnPowerButton = (SwitchPreferenceEx) findPreference(settings.TURN_SCREEN_ON_POWER_BUTTON.getId()); SwitchPreferenceEx turnScreenOnPowerButton = (SwitchPreferenceEx) findPreference(settings.TURN_SCREEN_ON_POWER_BUTTON.getId());
turnScreenOnPowerButton.setEnabled(enabled); turnScreenOnPowerButton.setEnabled(enabled);
turnScreenOnPowerButton.setDescription(R.string.turn_screen_on_power_button_descr); turnScreenOnPowerButton.setDescription(R.string.turn_screen_on_power_button_descr);
turnScreenOnPowerButton.setIcon(getPersistentPrefIcon(R.drawable.ic_action_power_button)); turnScreenOnPowerButton.setIcon(getPersistentPrefIcon(R.drawable.ic_action_power_button));
turnScreenOnPowerButton.setChecked(enabled && settings.TURN_SCREEN_ON_POWER_BUTTON.getModeValue(appMode));
} }
@Override @Override