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

Added option to keep the screen on #316

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
16 changes: 14 additions & 2 deletions app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,22 @@ public void onResume()
// '1' is the brightest. We attempt to maximize the brightness
// to help barcode readers scan the barcode.
Window window = getWindow();
if(window != null && settings.useMaxBrightnessDisplayingBarcode())
if(window != null)
{
WindowManager.LayoutParams attributes = window.getAttributes();
attributes.screenBrightness = 1F;

if (settings.useMaxBrightnessDisplayingBarcode())
{
attributes.screenBrightness = 1F;
}

if (settings.getKeepScreenOn())
{
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON|
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From experimenting with the change on an emulator, it seems that the FLAG_KEEP_SCREEN_ON alone does the trick, even when I configured a lock screen. What do the other two flags add, and why are they necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first flag just makes the screen not turn off automatically.

The other two flags make the lock screen not appear over the app's window, even if the user turned off the screen manually. @sphh described it quite well in #287.

Double-checking this in the docs just now, I found that DISMISS_KEYGUARD is not strictly required (I really should stop writing code from memory!). It only affects insecure keyguards (i.e. swipe to unlock) and causes the phone to remain unlocked when closing the window. This is, if nothing else, inconsistent with the behavior on secured devices, so I'll remove it.

WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD|
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
}

window.setAttributes(attributes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,9 @@ public boolean getLockBarcodeScreenOrientation()
{
return getBoolean(R.string.settings_key_lock_barcode_orientation, false);
}

public boolean getKeepScreenOn()
{
return getBoolean(R.string.settings_key_keep_screen_on, false);
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,6 @@
<string name="settings_key_display_barcode_max_brightness" translatable="false">pref_display_card_max_brightness</string>
<string name="settings_lock_barcode_orientation">Lock barcode orientation</string>
<string name="settings_key_lock_barcode_orientation" translatable="false">pref_lock_barcode_orientation</string>
<string name="settings_keep_screen_on">Keep screen on</string>
<string name="settings_key_keep_screen_on" translatable="false">pref_keep_screen_on</string>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
android:defaultValue="false"
android:key="@string/settings_key_lock_barcode_orientation"
android:title="@string/settings_lock_barcode_orientation"/>

<CheckBoxPreference
android:defaultValue="false"
android:key="@string/settings_key_keep_screen_on"
android:title="@string/settings_keep_screen_on"/>
</PreferenceCategory>

</PreferenceScreen>