How to set screen time out for an activity then turn back on when screen pressed

Sunday, May 11, 2014

I have an activity that works like a night time clock, the user can change certain preferences to edit screen brightness, background colour, text colour, etc.


At the moment the activity disables screen timeout and lockscreen, because the thread that updates the time on the screen runs every second (I may remove seconds and update less frequently to save further), it ends up using more battery than I'd like. The whole point of it is to act like a bedside clock, the user can easily tap a button for the time to light up, in this case that button is the screen.


What I want to do is turn off the screen after a certain amount of time (a preference in the application's settings) then listen for screen presses. When the user taps the screen it will turn the screen back on until it times out again or the user destroys the activity, at which point screen time out will default to their phones settings.


Any help would be much appreciated.







http://ift.tt/1jNLypt