Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to keep screen on #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
android:entries="@array/KeyguardPreferenceEntries"
android:entryValues="@array/KeyguardPreferenceValues"
android:defaultValue="0" />
<CheckBoxPreference
android:key="setting_keep_screen_on"
android:title="Keep Screen On"
android:summary="Prevent the screen from turning off while app is running"
android:defaultValue="false"/>
</PreferenceCategory>
<PreferenceCategory android:title="Miscellaneous options">
<CheckBoxPreference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
class ConfigurationManager implements OnSharedPreferenceChangeListener {

public final static String PREF_KEYGUARD_DISABLED = "setting_disable_keyguard";
public final static String PREF_KEEP_SCREEN_ON = "setting_keep_screen_on";

public final static String KEYGUARD_STATUS_ENABLED = "0";
public final static String KEYGUARD_STATUS_REMOTE_ONLY = "1";
Expand All @@ -49,13 +50,16 @@ class ConfigurationManager implements OnSharedPreferenceChangeListener {

private int mKeyguardState = 0;

private boolean mKeepScreenOn = false;

private KeyguardManager.KeyguardLock mKeyguardLock = null;

private ConfigurationManager(Activity activity) {
mActivity = activity;
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mActivity);
prefs.registerOnSharedPreferenceChangeListener(this);
mKeyguardState = Integer.parseInt(prefs.getString(PREF_KEYGUARD_DISABLED, KEYGUARD_STATUS_ENABLED));
mKeepScreenOn = prefs.getBoolean(PREF_KEEP_SCREEN_ON, false);
}

public static ConfigurationManager getInstance(Activity activity) {
Expand Down Expand Up @@ -103,6 +107,9 @@ public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
else
enableKeyguard();
}
else if (key.equals(PREF_KEEP_SCREEN_ON)) {
mKeepScreenOn = prefs.getBoolean(PREF_KEEP_SCREEN_ON, false);
}
}

public void onActivityResume(Activity activity) {
Expand All @@ -121,6 +128,10 @@ public void onActivityResume(Activity activity) {
break;
}

if (mKeepScreenOn) {
activity.getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
mActivity = activity;
}
Expand Down