Modify animation in Iot profile for resolution 1280x720
[apps/native/boot-animation.git] / src / animation.c
old mode 100644 (file)
new mode 100755 (executable)
index 9c18bba..17ce775
  *
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <sys/time.h>
-#include <unistd.h>
-#include <dirent.h>
-
 #include <vconf.h>
-#include <Elementary.h>
 #include <efl_util.h>
 
 #include "boot.h"
 #include "animation.h"
-#include "log.h"
-
-#define OVER_COUNT 19
+#include "app_log.h"
 
 static struct animation {
        Evas_Object *win;
-       Evas_Coord w;
-       Evas_Coord h;
-       int t;
-       Evas *evas;
-       Ecore_Evas *ee;
        Evas_Object *layout;
-       int state;
-       Evas_Object *txt;
+       Evas_Object *display_block;
+       Evas_Coord win_w;
+       Evas_Coord win_h;
+       int animation_type;
 } s_animation = {
-       .txt = NULL,};
-
-static void win_del(void *data, Evas_Object * obj, void *event_info)
+       .win = NULL,
+       .layout = NULL,
+       .display_block = NULL,
+       .win_w = 0,
+       .win_h = 0,
+       .animation_type = 0,
+};
+
+static void __win_del_cb(void *data, Evas_Object * obj, void *event_info)
 {
-       _D("Window delete event received");
+       __D("Window delete event received");
        elm_exit();
 }
 
-static Eina_Bool __end_cb(void *data)
+static Evas_Object *__create_window(void)
 {
-       int type = (int) data;
+       __D("Create Window");
 
-       if (type == TYPE_ON) {
-               _D("EXIT on BOOTING");
-               if (vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 1) != 0) {
-                       _E("Failed to set finished set");
-               }
-               elm_exit();
-       } else {
-               /* Delete Previous Layout */
-               _D("EXIT on SHUTDOWN");
-               if (s_animation.layout) evas_object_del(s_animation.layout);
-
-               Evas_Object *disp_block = NULL;
-               disp_block = evas_object_rectangle_add(evas_object_evas_get(s_animation.win));
-               elm_win_resize_object_add(s_animation.win, disp_block);
-               evas_object_color_set(disp_block, 0, 0, 0, 255);
-               evas_object_show(disp_block);
+       Evas_Object *win;
+
+       win = elm_win_add(NULL, "BOOT_ANIMATION", ELM_WIN_NOTIFICATION);
+       if (!win) {
+               __E("Failed to create a new window");
+               return NULL;
        }
-       return ECORE_CALLBACK_CANCEL;
+       elm_win_aux_hint_add(win, "wm.comp.win.always.selective.mode", "1");
+       elm_win_role_set(win, "alert");
+       efl_util_set_notification_window_level(win, EFL_UTIL_NOTIFICATION_LEVEL_HIGH);
+       evas_object_smart_callback_add(win, "delete-request", __win_del_cb, NULL);
+
+       elm_win_screen_size_get(win, NULL, NULL, &s_animation.win_w, &s_animation.win_h);
+       elm_win_borderless_set(win, EINA_TRUE);
+       elm_win_indicator_mode_set(win, ELM_WIN_INDICATOR_HIDE);
+       evas_object_move(win, 0, 0);
+       evas_object_show(win);
+
+       return win;
 }
 
-static void __set_poweroff_message(void)
+static void __block_display(void)
 {
-       Evas_Coord w;
-       Evas_Coord h;
-
-       evas_object_size_hint_weight_set(s_animation.txt, EVAS_HINT_EXPAND,     EVAS_HINT_EXPAND);
-       evas_object_size_hint_fill_set(s_animation.txt, EVAS_HINT_FILL, EVAS_HINT_FILL);
-       evas_object_resize(s_animation.txt, s_animation.w, s_animation.h);
-       evas_object_color_set(s_animation.txt, 255, 255, 255, 255);
-       evas_object_text_font_set(s_animation.txt, "SLP:style=medium", 30);
-       evas_object_geometry_get(s_animation.txt, NULL, NULL, &w, &h);
-       evas_object_move(s_animation.txt, (s_animation.w - w) >> 1, (s_animation.h - h) >> 1);
-       evas_object_show(s_animation.txt);
+       Evas_Object *display_block = NULL;
+       display_block = evas_object_rectangle_add(evas_object_evas_get(s_animation.win));
+       elm_win_resize_object_add(s_animation.win, display_block);
+       evas_object_color_set(display_block, 0, 0, 0, 255);
+       evas_object_show(display_block);
+
+       s_animation.display_block = display_block;
 }
 
-static void __edje_cb(void *d, Evas_Object * obj, const char *e, const char *s)
+static Eina_Bool __end_cb(void *data)
 {
-       if (s_animation.state == TYPE_OFF || s_animation.state == TYPE_OFF_WITH_MSG) {
-               _D("TYPE OFF");
-               if (vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 1) != 0) {
-                       _E("Failed to set finished set");
-               }
-               if (s_animation.txt) {
-                       __set_poweroff_message();
+       int type = (int) data;
+
+       if (type == TYPE_OFF) {
+               __D("EXIT on SHUTDOWN");
+               /* Delete Previous Layout */
+               if (s_animation.layout) {
+                       evas_object_del(s_animation.layout);
+                       s_animation.layout = NULL;
                }
-               ecore_timer_add(1, __end_cb, (void *)TYPE_OFF);
+
+               /* boot-animation do not terminate on shutdown, so flush log now */
+               fflush(stdout);
+               close(1);
+
+               __block_display();
        } else {
-               _D("TYPE_ON");
-               __end_cb((void *)TYPE_ON);
+               __D("EXIT on BOOTING");
+               if (vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 1) != 0)
+                       __E("Failed to set finished set");
+
+               boot_exit();
        }
+       return ECORE_CALLBACK_CANCEL;
 }
 
-static Eina_Bool __layout_file_set(Evas_Object *layout, int state)
+static void __animation_finished_cb(void *d, Evas_Object * obj, const char *e, const char *s)
 {
-       char file_name[1024];
-       char *on_off;
-       int ret;
-
-       if (state == TYPE_ON) {
-               snprintf(file_name, sizeof(file_name), FILE_PATH"%dx%d_PowerOn.edj", s_animation.w, s_animation.h);
-               on_off = GRP_ON;
-       } else {
-               snprintf(file_name, sizeof(file_name), FILE_PATH"%dx%d_PowerOff.edj", s_animation.w, s_animation.h);
-               on_off = GRP_OFF;
-       }
-       _D("File name for Animation is: %s", file_name);
+       if (s_animation.animation_type == TYPE_OFF) {
+               __D("TYPE OFF");
+               if (vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 1) != 0)
+                       __E("Failed to set finished set");
 
-       ret = access(file_name, 0);
-       if (ret == 0) {
-               _D("This Resolution[%d]x[%d] is supported !!", s_animation.w, s_animation.h);
-               if (!elm_layout_file_set(layout, file_name, on_off)) return EINA_FALSE;
+               ecore_timer_add(1, __end_cb, (void *)TYPE_OFF);
        } else {
-               _E("This Resolution[%d]x[%d] is STRANGE !!, Set default image '720x1280'", s_animation.w, s_animation.h);
-               if (state == TYPE_ON) {
-                       if (!elm_layout_file_set(layout, DEFAULT_ON, on_off)) return EINA_FALSE;
-               } else {
-                       if (!elm_layout_file_set(layout, DEFAULT_OFF, on_off)) return EINA_FALSE;
-               }
+               __D("TYPE_ON");
+               __end_cb((void *)TYPE_ON);
        }
-
-       return EINA_TRUE;
 }
 
-static Evas_Object *__create_layout(const char *msg)
+static Evas_Object * __create_layout(Evas_Object *win, const char *file_name)
 {
-       Eina_Bool ret;
-       Evas_Object *layout = elm_layout_add(s_animation.win);
+       Evas_Object *layout = elm_layout_add(win);
        if (!layout) {
-               _E("Failed to create layout");
+               __E("Failed to create layout");
                return NULL;
        }
+       evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       elm_win_resize_object_add(s_animation.win, layout);
+       elm_layout_signal_callback_add(layout, "end", "animation", __animation_finished_cb, NULL);
 
-       ret = __layout_file_set(layout, s_animation.state);
-       if (ret != EINA_TRUE) {
-               _E("Failed to set layout file");
-               evas_object_del(layout);
+       if (!elm_layout_file_set(layout, file_name, GRP_ANIM)) {
+               __E("Failed to layout file set");
                return NULL;
        }
 
-       evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-       elm_win_resize_object_add(s_animation.win, layout);
-       edje_object_signal_callback_add(elm_layout_edje_get(layout), "end", "animation", __edje_cb, NULL);
        evas_object_show(layout);
 
-       if (msg) {
-               if (!s_animation.txt) {
-                       s_animation.txt = evas_object_text_add(evas_object_evas_get(s_animation.win));
-                       if (!s_animation.txt) {
-                               _E("Failed to add text");
-                               evas_object_del(layout);
-                               return NULL;
-                       }
-               }
-
-               evas_object_text_text_set(s_animation.txt, msg);
-               evas_object_hide(s_animation.txt);
-       }
-
        return layout;
 }
 
-static void __fini_layout(void)
+static void __destroy_layout(void)
 {
-       if (s_animation.layout) {
-               evas_object_del(s_animation.layout);
+       if (s_animation.display_block) {
+               evas_object_del(s_animation.display_block);
+               s_animation.display_block = NULL;
        }
 
-       if (s_animation.txt) {
-               evas_object_del(s_animation.txt);
-               s_animation.txt = NULL;
+       if (s_animation.layout) {
+               evas_object_del(s_animation.layout);
+               s_animation.layout = NULL;
        }
 }
 
-static Evas_Object *__create_window(void)
+static char * __get_layout_file_name(int animation_type, int w, int h)
 {
-       _D("Create Window");
-       printf("Create Window\n");
+       char file_name[1024];
+       int ret = 0;
 
-       int x, y = 0;
-       Evas_Object *win;
+       if (animation_type == TYPE_OFF)
+               snprintf(file_name, sizeof(file_name), FILE_PATH"%dx%d_PowerOff.edj", w, h);
+       else
+               snprintf(file_name, sizeof(file_name), FILE_PATH"%dx%d_PowerOn.edj", w, h);
 
-       win = elm_win_add(NULL, "BOOT_ANIMATION", ELM_WIN_NOTIFICATION);
-       elm_win_aux_hint_add(win, "wm.comp.win.always.selective.mode", "1");
+       __D("File name for Animation is: %s", file_name);
 
-       elm_win_role_set(win, "alert");
-       if (!win) {
-               _E("Failed to create a new window");
-               printf("Failed to create a new window\n");
-               return NULL;
-       }
-       if (s_animation.state == TYPE_OFF || s_animation.state == TYPE_OFF_WITH_MSG) {
-               _D("We are turning off the Tizen");
+       ret = access(file_name, 0);
+       if (ret != 0) {
+               __E("There's no Image same with [%s], So set Default[720x1280] image", file_name);
+               __D("There's no Image same with [%s], So set Default[720x1280] image", file_name);
+               if (animation_type == TYPE_OFF)
+                       snprintf(file_name, sizeof(file_name), "%s", DEFAULT_OFF);
+               else
+                       snprintf(file_name, sizeof(file_name), "%s", DEFAULT_ON);
+
+               ret = access(file_name, 0);
+               if (ret) {
+                       __E("There's no Image file[%s] on target", file_name);
+                       __D("There's no Image file[%s] on target", file_name);
+                       return NULL;
+               }
        }
-       efl_util_set_notification_window_level(win, EFL_UTIL_NOTIFICATION_LEVEL_HIGH);
-       evas_object_smart_callback_add(win, "delete-request", win_del, NULL);
 
-       elm_win_screen_size_get(win, &x, &y, &s_animation.w, &s_animation.h);
-       _D("Window size is x: %d, y: %d, w: %d, h: %d", x, y, s_animation.w, s_animation.h);
-       elm_win_borderless_set(win, 1);
-       elm_win_indicator_mode_set(win, ELM_WIN_INDICATOR_HIDE);
-       evas_object_move(win, 0, 0);
-       evas_object_show(win);
+       return strdup(file_name);
+}
 
-       return win;
+static Eina_Bool __is_layout_file_exist(const char *file_name)
+{
+       int ret = 0;
+
+       ret = access(file_name, 0);
+       if (ret == 0)
+               return EINA_TRUE;
+       else
+               return EINA_FALSE;
 }
 
-int init_animation(int state, const char *msg)
+int animation_init(int animation_type)
 {
-       _D("Init animation");
-       printf("Init animation\n");
+       __D("Init animation");
 
-       s_animation.state = state;
+       s_animation.animation_type = animation_type;
 
        s_animation.win = __create_window();
        if (!s_animation.win) {
-               _E("Failed to create a new window");
-               printf("Failed to create a new window\n");
+               __E("Failed to create a new window");
+               return EXIT_FAILURE;
+       }
+
+       char *layout_file_name = NULL;
+       layout_file_name = __get_layout_file_name(animation_type, s_animation.win_w, s_animation.win_h);
+       if (!layout_file_name) {
+               __E("Failed to get layout file name");
                return EXIT_FAILURE;
        }
 
-       s_animation.layout = __create_layout(msg);
+       if (!__is_layout_file_exist(layout_file_name)) {
+               __E("This file is not exist");
+               free(layout_file_name);
+               return EXIT_FAILURE;
+       }
+
+       s_animation.layout = __create_layout(s_animation.win, layout_file_name);
        if (!s_animation.layout) {
-               _E("Failed to create layout");
-               if (s_animation.txt) {
-                       evas_object_del(s_animation.txt);
-               }
+               __E("Failed to create layout");
+               free(layout_file_name);
                evas_object_del(s_animation.win);
                return EXIT_FAILURE;
        }
 
+       free(layout_file_name);
+
        return EXIT_SUCCESS;
 }
 
-int fini_animation(void)
+int animation_fini(void)
 {
-       __fini_layout();
+       __destroy_layout();
+
        evas_object_del(s_animation.win);
        fflush(stdout);
        close(1);
        return EXIT_SUCCESS;
 }
 
+#include "test.h"
 #if TEST_MODE
-Evas_Object *__t_create_window(void)
+Evas_Object *__t__get_window(void)
+{
+       return s_animation.win;
+}
+
+Evas_Object *__t__get_layout(void)
+{
+       return s_animation.layout;
+}
+
+Evas_Object *__t__get_display_block(void)
+{
+       return s_animation.display_block;
+}
+
+Evas_Object * __t__animation_create_layout(Evas_Object *win, const char *file_name)
+{
+       return __create_layout(win, file_name);
+}
+
+Evas_Object *__t__animation_create_window(void)
 {
        return __create_window();
 }
+
+char * __t__get_layout_file_name(int animation_type, int w, int h)
+{
+       return __get_layout_file_name(animation_type, w, h);
+}
+
+Eina_Bool __t__is_layout_file_exist(const char *file_name)
+{
+       return __is_layout_file_exist(file_name);
+}
 #endif