Simplified lifecycle example

When window minimization works, we can remove the simulation code or create
another example.
This commit is contained in:
Xavi Artigas 2017-12-12 11:45:30 +01:00
parent afb4aa07ca
commit 37a5123360
1 changed files with 27 additions and 33 deletions

View File

@ -5,45 +5,36 @@
#include <Efl_Core.h> #include <Efl_Core.h>
/* /*
* These are some helper methods for triggering lifecycle events for the purpose of this demo. * This helper method triggers lifecycle events for the purpose of this demo.
* efl_pause and efl_resume may never be called for your application, depending on your environment. * efl_pause and efl_resume may never be called for your application, depending
* This demo triggers them directly to show how you can respond. * on your environment, therefore this demo triggers them directly to show how
* you can respond.
*/ */
static void
_method_delay_call(Efl_Event_Cb method, double delay, Efl_Loop *loop)
{
efl_add(EFL_LOOP_TIMER_CLASS, loop,
efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TICK, method, loop),
efl_loop_timer_interval_set(efl_added, delay));
}
static void static void
_simulate_app_exit(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED) _lifecycle_simulation(void *data, const Efl_Event *ev EINA_UNUSED)
{
efl_exit(0);
}
static void
_simulate_app_foreground(void *data, const Efl_Event *ev)
{ {
Efl_Loop *loop = data; Efl_Loop *loop = data;
efl_event_callback_call(loop, EFL_LOOP_EVENT_RESUME, NULL); static int called = 0;
efl_del(ev->object);
_method_delay_call(_simulate_app_exit, 0.5, loop); switch (called)
{
case 0:
// First call, pause the application
efl_event_callback_call(loop, EFL_LOOP_EVENT_PAUSE, NULL);
break;
case 1:
// Second call, resume the application
efl_event_callback_call(loop, EFL_LOOP_EVENT_RESUME, NULL);
break;
default:
// Last call, exit the application
efl_exit(0);
}
called++;
} }
static void
_simulate_app_background(void *data, const Efl_Event *ev)
{
Efl_Loop *loop = data;
efl_event_callback_call(loop, EFL_LOOP_EVENT_PAUSE, NULL);
efl_del(ev->object);
_method_delay_call(_simulate_app_foreground, 1.0, loop);
}
/* end helper methods - what follows below is efl event handling that you can use in your apps. */
EAPI_MAIN void EAPI_MAIN void
efl_pause(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED) efl_pause(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
{ {
@ -67,8 +58,11 @@ efl_main(void *data EINA_UNUSED, const Efl_Event *ev)
{ {
printf("Lifecycle: launched\n"); printf("Lifecycle: launched\n");
// here we trigger the chain of simulated events to show how an app could respond to system lifecycle. // The timer function will trigger the chain of simulated events to show
_method_delay_call(_simulate_app_background, 0.5, ev->object); // how an app could respond to system lifecycle events.
efl_add(EFL_LOOP_TIMER_CLASS, ev->object,
efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TICK, _lifecycle_simulation, ev->object),
efl_loop_timer_interval_set(efl_added, 1.0));
} }
EFL_MAIN_EX() EFL_MAIN_EX()