Fix #8034 (Option: for keep screen on or not)

This commit is contained in:
Nazar-Kutz 2020-02-06 10:24:35 +02:00
parent 6dc116fd1f
commit 0c14de0e23
7 changed files with 40 additions and 4 deletions

View file

@ -16,7 +16,6 @@
android:id="@+id/MapViewWithLayers"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:keepScreenOn="true"
android:orientation="vertical">
<ViewStub

View file

@ -11,6 +11,8 @@
Thx - Hardy
-->
<string name="use_system_screen_timeout">Use system screen timeout</string>
<string name="use_system_screen_timeout_promo">Disabled by default, if OsmAnd running on foreground, the screen doesnt time out.\n\nIf enabled OsmAnd will use system timeout settings.</string>
<string name="accessibility_mode_disabled">Accessibility mode disabled in your system.</string>
<string name="rearrange_categories">Rearrange categories</string>
<string name="create_custom_categories_list_promo">You can add custom categories hide categories that you dont find necessary and change the sort order of the list. The list can be imported and exported with profiles.</string>

View file

@ -60,4 +60,15 @@
app:fragment="net.osmand.plus.settings.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

@ -1767,6 +1767,8 @@ 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", true).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$

View file

@ -248,6 +248,13 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
}
};
private StateChangedListener<Boolean> useSystemScreenTimeoutListener = new StateChangedListener<Boolean>() {
@Override
public void stateChanged(Boolean change) {
changeKeyguardFlags();
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(AndroidUiHelper.getScreenOrientation(this));
@ -973,6 +980,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
}
settings.MAP_SCREEN_ORIENTATION.addListener(mapScreenOrientationSettingListener);
settings.USE_SYSTEM_SCREEN_TIMEOUT.addListener(useSystemScreenTimeoutListener);
}
public void applyScreenOrientation() {
@ -1460,6 +1468,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
private void onPauseActivity() {
settings.MAP_SCREEN_ORIENTATION.removeListener(mapScreenOrientationSettingListener);
settings.USE_SYSTEM_SCREEN_TIMEOUT.removeListener(useSystemScreenTimeoutListener);
if (!app.getRoutingHelper().isRouteWasFinished()) {
DestinationReachedMenu.resetShownState();
}
@ -2099,7 +2108,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
}
public void changeKeyguardFlags() {
changeKeyguardFlags(settings.TURN_SCREEN_ON_TIME_INT.get() > 0, true);
boolean enabled = settings.TURN_SCREEN_ON_ENABLED.get() && settings.TURN_SCREEN_ON_TIME_INT.get() > 0;
boolean keepScreenOn = !settings.USE_SYSTEM_SCREEN_TIMEOUT.get();
changeKeyguardFlags(enabled, keepScreenOn);
}
private void changeKeyguardFlags(boolean enable, boolean forceKeepScreenOn) {

View file

@ -33,6 +33,7 @@ public class GlobalSettingsFragment extends BaseSettingsFragment implements Send
setupSendAnonymousDataPref();
setupDialogsAndNotificationsPref();
setupEnableProxyPref();
setupUseSystemScreenTimeout();
}
@Override
@ -174,4 +175,10 @@ public class GlobalSettingsFragment extends BaseSettingsFragment implements Send
SwitchPreferenceEx enableProxy = (SwitchPreferenceEx) findPreference(settings.ENABLE_PROXY.getId());
enableProxy.setIcon(getContentIcon(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

@ -53,8 +53,12 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
items.add(new TitleItem(title));
final OsmandSettings.BooleanPreference pref = (BooleanPreference) preference;
final String on = getString(R.string.shared_string_on);
final String off = getString(R.string.shared_string_off);
CharSequence summaryOn = switchPreference.getSummaryOn();
CharSequence summaryOff = switchPreference.getSummaryOff();
final String on = summaryOn == null || summaryOn.toString().equals("")
? getString(R.string.shared_string_enabled) : summaryOn.toString();
final String off = summaryOff == null || summaryOff.toString().equals("")
? getString(R.string.shared_string_disabled) : summaryOff.toString();
final int activeColor = AndroidUtils.resolveAttribute(app, R.attr.active_color_basic);
final int disabledColor = AndroidUtils.resolveAttribute(app, android.R.attr.textColorSecondary);
boolean checked = pref.getModeValue(getAppMode());