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 an option to dim the screen to avoid killing the battery #49

Open
nolanlawson opened this issue Jan 7, 2013 · 7 comments
Open

Add an option to dim the screen to avoid killing the battery #49

nolanlawson opened this issue Jan 7, 2013 · 7 comments

Comments

@nolanlawson
Copy link
Owner

Currently KeepScore can destroy a phone's battery, because having the screen on eats a ton of power. During a two-hour game of Rummy, the battery on my Galaxy Nexus running Android 4.2 dropped almost 20%.

Turning the screen off entirely is not an option, because we don't want to make users unlock their lockscreen over and over again. (Especially because your friends probably don't know your password.) But dimming the screen after a certain timeout might offer some battery savings.

@nolanlawson
Copy link
Owner Author

After investigating, I'm not sure this is actually possible. I can't find in the API where I can manually dim the screen without shutting off the Activity entirely.

@daguej
Copy link
Contributor

daguej commented Feb 19, 2014

Don't you just need to set the activity's LayoutParams.screenBrightness?

There's a PhoneGap plugin I've used that does just that.

@nolanlawson
Copy link
Owner Author

Yeah, but it's complicated because apparently the API has been deprecated/changed since 4.0. Anyone interested is free to take a crack at the code, though!

@daguej
Copy link
Contributor

daguej commented Feb 20, 2014

The docs don't seem to indicate that it was deprecated. (Compare to the memoryType property a few items above screenBrightness – it has a big orange deprecation warning.)

@kparal
Copy link

kparal commented Jan 2, 2015

I don't have any insight into Android development, but I think you don't need to dim the screen programatically, just let Android do it itself. Both Unsleep [1] and Keep screen on! [2] are able to do that on Android 4.4. The latter has an option of SCREEN_DIM_WAKE_LOCK which does exactly the right thing - prevents the screen from turning off, but after a default timeout (configured in your settings), the brightness is reduced to a very low value.

[1] https://play.google.com/store/apps/details?id=com.nealc.unsleep
[2] https://play.google.com/store/apps/details?id=si.formias.keepscreenon

@nolanlawson
Copy link
Owner Author

OK, so maybe the fix is to use the new 4.4 option in post-4.4?

I'm happy with deprecating pre-4.4 and shipping only a minSdk=19 APK from now on.

@kparal
Copy link

kparal commented Jan 8, 2015

I have no idea whether the stuff I mentioned is new in 4.4. I just know it works on 4.4, that's the only version I can test :-)

Keep Screen On! supports 2.0 and higher and references http://developer.android.com/reference/android/os/PowerManager.html in its description.

Unsleep supports 2.3.3 and higher and there's no information how it does it.

http://developer.android.com/reference/android/os/PowerManager.html#SCREEN_DIM_WAKE_LOCK says it's deprecated and suggests http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_KEEP_SCREEN_ON , but that flag doesn't seem to support dimming (the documentation says keep the device's screen turned on and bright).

Maybe the deprecated option would be good enough for the time being?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants