cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to implement Screen timeout?

SKILA
Associate II

Hello,

I am trying to implement a basic screen timeout where the current screen is changed to the startup screen after a set time.

The timeout itself is straightfoward to implement using a tickcounter. However, the problem I am facing is resetting this counter whenever the screen is touched. I could possibly add a reset function to every button I have in the current screen but I also need the counter to be reset when the user touches any part of the screen and not just the interactive ones.

At first instance, I have utilized the handleClickEvent of the screen to basically detect any touch, which works in detecting all touches but unfortunately it also masks the button press events, so none of the buttons are interactive anymore.

It is possible that I use the clicklistener on all the buttons and basically handle the presses through that but this makes the code a bit complicated and this what I am trying to avoid.

I would like to know if there is a simpler way. So any input would be greatly appreacited.

Many thanks,

Samer

1 ACCEPTED SOLUTION

Accepted Solutions
Martin KJELDSEN
Chief III

Do it like this:

  • Keep track of your timers (timeout, etc) in your model.
  • Once the timers run out, carry out whatever action. Maybe they're recurring.
  • In FrontEndApplication.hpp/cpp override the handleClickEvent() method and make a call to your Model to reset the timers that need to be, like a timeout timer.

/Martin

View solution in original post

5 REPLIES 5
Martin KJELDSEN
Chief III

Do it like this:

  • Keep track of your timers (timeout, etc) in your model.
  • Once the timers run out, carry out whatever action. Maybe they're recurring.
  • In FrontEndApplication.hpp/cpp override the handleClickEvent() method and make a call to your Model to reset the timers that need to be, like a timeout timer.

/Martin

SKILA
Associate II

Works like a charm!!! Thank you very much.

Martin KJELDSEN
Chief III

Great! I forgot to mention that when you override handleClickEvent() in FrontEndApplication, you probably need to forward-propagate the event manually to make sure everything still works as normal. Like this:

void FrontEndApplication::handleClickEvent(Event &evt)
{
    model.resetTimers();
    Application::handleClickEvent(evt);
}

/Martin

SKILA
Associate II

Yes, that is exactly how I have done it.

But it is good to have it here so other people would have a reference.

Thanks again!

Martin KJELDSEN
Chief III

Oh, that's very insightful of you. Great! 🙂