373 views
in GUI Development by
Dear all,

is there a way to get an event every time that the screen is touched regardless of the menu level where the user has gone?

I need to exit from every menu after 30 seconds and to go back to the main screen if not touch events occur.

Could you help me, please?

Thanks

Best regards

Gianni Perugini

1 Answer

+1 vote
by

Hello Gianni,

there are various approaches, how you can implement such application case and this is not so simple to explain. First at all, every touch event is handled by the corresponding handler. This means, it is not intended to create several handlers, which handle the same touch event simultanously unless one handler deflects its actual interaction to another handler. So far, there is no automatism to solve your problem. What can you do?

The right approach depends on your individual menu system. For example, if you have several menus stacked one above other and the user can interact with the latest (top most) menu only, then it would be reasonable to make every menu modal. In such case the user navigates in the menu structure entering and leaving the menu levels. When entering a menu you make this menu component modal. When the user leaves the menu you ends its modal state again.

The timer to close the menu I would maintain running only in the actually active menu. This means, when the user enters a new menu level, you deactivate the timer in the previous menu. When the timer expires and you want all menus to be closed, you can evaluate which components are actually modal and close them. See at the code example with the while-loop end of the section Modal GUI components.

Other approach is to interconnect all actually active menus. You can use variables for this purpose. You have to ensure, that when the user enters a menu, the new menu and the superior menu establish a connection by using the variables. In this manner one menu can access other menu and start/stop its timer, or close the menu remotely.

Anther possibility is to move the entire time-out functionality to a global autoobject and use the observer mechanisms to to notify the menus when the timer expires. For this purpose:

1. Create a new class in one of your project units.

2. Inside the class add the Timer object.

3. Inside the class add a Slot method.

4. Connect the Slot method (3) to the Timer object (2) and configure the elapse time of the timer to 30 seconds.

5. Implement the Slot method (3) with following code:

notifyobservers this;

6. From the prepared (1) class add a new autoobject to one your project units.

7. In your menus remove the old Timers. Instead you will use the global autoobject (6).

8. Add to every menu a new variable. Change the data type of the variable to correspond to the class (1) of the autoobject (6). Set the initialization value of the variable to be the complete name of the autoobject (6).

In this manner, every menu refers to the autoobject. Through the variable you can access the autoobject easily.

9. In every menu add a new Slot method.

10. During the initialization time of the menu (e.g. within its Init method) connect the slot method (9) to be observer for the autoobject stored in the variable (8). For this purpose you have to perform following code at some initialization time of the menu:

attachobserver your_slot_method, the_variable_refering_to_the_autobject;

11. Within the slot method (9) you put the code to close the menu.

12. Now when one of the touch handlers in a menu reacts to touch events, restart the timer in the global autoobject by executing the code:

the_variable_refering_to_the_autobject.Timer.Enabled = false;
the_variable_refering_to_the_autobject.Timer.Enabled = true;

With this all menu do share a unique timer within a global autoobject. Touching within one menu restarts this timer. When the timer expires, the autoobject containing the timer is notified causing all slot methods attached to this autoobject to receive signals. Thereupon the slot methods can dismiss the menus.

I hope, one of the approaches helps you further.

Best regards

Paul Banach

by
Dear Paul,

thank you so much for your answer.

Best regards

Gianni Perugini

Embedded Wizard Website | Privacy Policy | Imprint

...