renew pui prototype again
[platform/core/uifw/libpui.git] / samples / PUI_sample.c
index cc4744d..359fd8e 100644 (file)
@@ -1,7 +1,10 @@
 #include <stdio.h>
-#include <PUI.h>
-
 #define NUM_ECORE_EVENT_HANDLERS 4
+#define EFL_BETA_API_SUPPORT
+
+#include <Ecore_Wl2.h>
+#include <Ecore_Input.h>
+#include <PUI.h>
 
 #define debug_error(msg, ...)                                                                                  \
        do {                                                                                                                            \
@@ -18,7 +21,7 @@ struct _animation
 {
        pui_id id;
        pui_ani_cmd cmd;
-       pui_ani_opt opt;
+       int repeat;
 };
 
 typedef struct app_data app_data_t;
@@ -33,56 +36,29 @@ struct app_data
 
 static Eina_Array *_ecore_event_hdls = NULL;
 static animation_t ani_collection[] = {
-       { "bixby_listening", PUI_ANI_CMD_START, PUI_ANI_OPT_ONCE },
-       { "bixby_processing", PUI_ANI_CMD_START, PUI_ANI_OPT_REPEAT },
-       { "bixby_speaking", PUI_ANI_CMD_START, PUI_ANI_OPT_REPEAT },
-       { "bixby_error", PUI_ANI_CMD_START, PUI_ANI_OPT_ONCE },
-       { "alarm", PUI_ANI_CMD_START, PUI_ANI_OPT_REPEAT },
-       { "notification", PUI_ANI_CMD_START, PUI_ANI_OPT_REPEAT },
+       { "bixby_listening", PUI_ANI_CMD_START, 1 },
+       { "bixby_processing", PUI_ANI_CMD_START, -1 },
+       { "bixby_speaking", PUI_ANI_CMD_START, -1 },
+       { "bixby_error", PUI_ANI_CMD_START, 1 },
+       { "alarm", PUI_ANI_CMD_START, -1 },
+       { "notification", PUI_ANI_CMD_START, -1 },
 };
 
 static void
-ani_play(app_data_t *app, pui_ani_opt opt)
-{
-       pui_error e;
-
-       if (!app || !app->ani_h)
-       {
-               debug_error("Invalid app data or pui animation handle !\n");
-               return;
-       }
-
-       e = pui_ani_control(app->ani_h, PUI_ANI_CMD_START, opt);
-
-       if (PUI_ERROR_NONE != e)
-       {
-               debug_error("Failed on playing an animation ! (cmd:%d, opt:%d)\n", PUI_ANI_CMD_START, opt);
-               return;
-       }
-
-       debug_info("Animation(%s) will be started !\n", pui_ani_get_id(ani_h));
-}
-
-static void
 ani_stop(app_data_t *app)
 {
-       pui_error e;
-
-       if (!app || !app->ani_h)
-       {
-               debug_error("Invalid app data or pui animation handle !\n");
-               return;
-       }
+       pui_error e = PUI_ERROR_NONE;
 
-       e = pui_ani_control(app->ani_h, PUI_ANI_CMD_STOP, PUI_ANI_OPT_ONCE);
+       /* stop animation running already */
+       e = pui_ani_control(app->ani_h, PUI_ANI_CMD_STOP, 0);
 
        if (PUI_ERROR_NONE != e)
        {
-               debug_error("Failed on stopping an animation !(cmd:%d, opt:%d)\n", PUI_ANI_CMD_STOP, PUI_ANI_OPT_ONCE);
+               debug_error("Failed on stopping an animation !(cmd:%d, repeat:%d)\n", PUI_ANI_CMD_STOP, 0);
                return;
        }
 
-       debug_info("Animation(%s) will be stopped !\n", pui_ani_get_id(ani_h));
+       debug_info("Animation(%s) will be stopped !\n", pui_ani_get_id(app->ani_h));
 }
 
 static void
@@ -93,7 +69,7 @@ ani_collection_play(app_data_t *app)
        pui_ani_h ani_h = NULL;
        pui_error e = PUI_ERROR_NONE;
 
-       n_animation = ani_collection / sizeof(animation_t);
+       n_animation = sizeof(ani_collection) / sizeof(animation_t);
 
        if (n_animation < 0)
        {
@@ -117,24 +93,37 @@ ani_collection_play(app_data_t *app)
 
        if (app->ani_h)
        {
-               ani_stop(app);
+               /* stop animation running already */
+               e = pui_ani_control(app->ani_h, PUI_ANI_CMD_STOP, 0);
+
+               if (PUI_ERROR_NONE != e)
+               {
+                       debug_error("Failed on stopping an animation !(cmd:%d, repeat:%d)\n", PUI_ANI_CMD_STOP, 0);
+                       return;
+               }
+
+               debug_info("Animation(%s) will be stopped !\n", pui_ani_get_id(ani_h));
+
                app->ani_h = NULL;
        }
 
        app->ani_h = ani_h;
-       ani_play(app, ani_collection[ani_idx].opt);
+
+       /* play animation */
+       e = pui_ani_control(app->ani_h, PUI_ANI_CMD_START, ani_collection[ani_idx].repeat);
+
+       if (PUI_ERROR_NONE != e)
+       {
+               debug_error("Failed on playing an animation ! (cmd:%d, repeat:%d)\n", PUI_ANI_CMD_START, ani_collection[ani_idx].repeat);
+               return;
+       }
+
+       debug_info("Animation(%s) will be started !\n", pui_ani_get_id(app->ani_h));
 
        if (++ani_idx >= n_animation)
                ani_idx = 0;
 
        return;
-
-err:
-       if (ani_h)
-       {
-               pui_ani_control(ani_h, PUI_ANI_CMD_STOP, PUI_ANI_OPT_NONE);
-               pui_ani_destroy(ani_h);
-       }
 }
 
 static Eina_Bool
@@ -287,7 +276,7 @@ int main()
        ecore_main_loop_begin();
 err:
        if (app->ani_h)
-               pui_ani_destroy(app->ani_h)
+               pui_ani_destroy(app->ani_h);
        if (app->ph)
                pui_destroy(app->ph);