Modify animation in Iot profile for resolution 1280x720
[apps/native/boot-animation.git] / src / animation.c
index af0f229..17ce775 100755 (executable)
 /*
-  * Copyright 2012  Samsung Electronics Co., Ltd
-  * 
-  * Licensed under the Flora License, Version 1.0 (the License);
-  * you may not use this file except in compliance with the License.
-  * You may obtain a copy of the License at
-  * 
-  *     http://floralicense.org/license/
-  * 
-  * Unless required by applicable law or agreed to in writing, software
-  * distributed under the License is distributed on an AS IS BASIS,
-  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-  * See the License for the specific language governing permissions and
-  * limitations under the License.
-  */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include <utilX.h>
-#include <vconf.h>
+ * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
-#include <Elementary.h>
-#include <Ecore_X.h>
-#include <Ecore_X_Atoms.h>
+#include <vconf.h>
+#include <efl_util.h>
 
-#include <boot-animation.h>
-#include <animation.h>
+#include "boot.h"
+#include "animation.h"
+#include "app_log.h"
 
 static struct animation {
-       Ecore_X_Window focus_win;
-       Ecore_X_Window root_win;
        Evas_Object *win;
-       Ecore_Window xwin;
-       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)
 {
-       fprintf(stderr, "Window delete event received\n");
+       __D("Window delete event received");
        elm_exit();
 }
 
-static void _edje_cb(void *d, Evas_Object * obj, const char *e, const char *s)
+static Evas_Object *__create_window(void)
 {
-       fprintf(stderr, "edje calback is invoked\n");
+       __D("Create Window");
+
+       Evas_Object *win;
 
-       if (vconf_set_int("memory/boot-animation/finished", 1) != 0) {
-               fprintf(stderr, "Failed to set finished set\n");
+       win = elm_win_add(NULL, "BOOT_ANIMATION", ELM_WIN_NOTIFICATION);
+       if (!win) {
+               __E("Failed to create a new window");
+               return NULL;
        }
+       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 __block_display(void)
+{
+       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);
 
-       if (s_animation.state == TYPE_OFF || s_animation.state == TYPE_ON) {
-               elm_exit();
-       } else if (s_animation.state == TYPE_OFF_WITH_MSG) {
-               if (s_animation.txt) {
-                       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);
+       s_animation.display_block = display_block;
+}
+
+static Eina_Bool __end_cb(void *data)
+{
+       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;
                }
+
+               /* boot-animation do not terminate on shutdown, so flush log now */
+               fflush(stdout);
+               close(1);
+
+               __block_display();
+       } else {
+               __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
-int init_layout(const char *msg)
+static void __animation_finished_cb(void *d, Evas_Object * obj, const char *e, const char *s)
 {
-       s_animation.layout = elm_layout_add(s_animation.win);
-       if (!s_animation.layout) {
-               fprintf(stderr, "Failed to create layout\n");
-               return EXIT_FAILURE;
-       }
+       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");
 
-       if (s_animation.state == TYPE_ON) {
-               elm_layout_file_set(s_animation.layout, EDJ_ON, GRP_ON);
+               ecore_timer_add(1, __end_cb, (void *)TYPE_OFF);
        } else {
-               elm_layout_file_set(s_animation.layout, EDJ_OFF, GRP_OFF);
+               __D("TYPE_ON");
+               __end_cb((void *)TYPE_ON);
        }
+}
 
-       evas_object_size_hint_weight_set(s_animation.layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-       printf("[Boot-ani] Start animation: %d mode\n", s_animation.state);
-       elm_win_resize_object_add(s_animation.win, s_animation.layout);
-       edje_object_signal_callback_add(elm_layout_edje_get(s_animation.layout),
-                                       "end", "animation", _edje_cb, NULL);
-       evas_object_show(s_animation.layout);
-
-       Ecore_X_Window xwin;
-       xwin = elm_win_xwindow_get(s_animation.win);
-       ecore_x_icccm_hints_set(xwin, 0, 0, 0, 0, 0, 0, 0);
-
-
-       if (msg) {
-               if (!s_animation.txt) {
-                       s_animation.txt =
-                           evas_object_text_add(s_animation.evas);
-                       if (!s_animation.txt) {
-                               fprintf(stderr, "Failed to add text\n");
-                               evas_object_del(s_animation.layout);
-                               return EXIT_FAILURE;
-                       }
-               }
-
-               evas_object_text_text_set(s_animation.txt, msg);
-               evas_object_hide(s_animation.txt);
+static Evas_Object * __create_layout(Evas_Object *win, const char *file_name)
+{
+       Evas_Object *layout = elm_layout_add(win);
+       if (!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);
 
-       if (vconf_set_int("memory/boot-animation/finished", 0) != 0) {
-               fprintf(stderr, "Failed to set finished value to 0\n");
+       if (!elm_layout_file_set(layout, file_name, GRP_ANIM)) {
+               __E("Failed to layout file set");
+               return NULL;
        }
 
-       return EXIT_SUCCESS;
+       evas_object_show(layout);
+
+       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;
        }
 }
 
-void restart_animation(int state, const char *msg)
+static char * __get_layout_file_name(int animation_type, int w, int h)
 {
-       fini_layout();
+       char file_name[1024];
+       int ret = 0;
+
+       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);
+
+       __D("File name for Animation is: %s", file_name);
+
+       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;
+               }
+       }
 
-       s_animation.state = state;
+       return strdup(file_name);
+}
 
-       init_layout(msg);
+static Eina_Bool __is_layout_file_exist(const char *file_name)
+{
+       int ret = 0;
 
-       evas_object_show(s_animation.win);
+       ret = access(file_name, 0);
+       if (ret == 0)
+               return EINA_TRUE;
+       else
+               return EINA_FALSE;
 }
 
-static
-int create_window(void)
+int animation_init(int animation_type)
 {
-       s_animation.win = elm_win_add(NULL, "", ELM_WIN_BASIC);
+       __D("Init animation");
+
+       s_animation.animation_type = animation_type;
+
+       s_animation.win = __create_window();
        if (!s_animation.win) {
-               fprintf(stderr, "Failed to create a new window\n");
+               __E("Failed to create a new window");
                return EXIT_FAILURE;
        }
-       evas_object_smart_callback_add(s_animation.win, "delete-request",
-                                      win_del, NULL);
-       evas_object_resize(s_animation.win, s_animation.w, s_animation.h);
 
-       s_animation.evas = evas_object_evas_get(s_animation.win);
-       if (!s_animation.evas) {
-               evas_object_del(s_animation.win);
-               fprintf(stderr, "Failed to get the evas object\n");
+       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;
        }
-       elm_win_borderless_set(s_animation.win, 1);
-       evas_object_move(s_animation.win, 0, 0);
-
-       if (s_animation.w > s_animation.h) {
-               int t;
-               elm_win_rotation_with_resize_set(s_animation.win, 90);
-               t = s_animation.w;
-               s_animation.w = s_animation.h;
-               s_animation.h = t;
+
+       if (!__is_layout_file_exist(layout_file_name)) {
+               __E("This file is not exist");
+               free(layout_file_name);
+               return EXIT_FAILURE;
        }
-       evas_object_show(s_animation.win);
 
-       s_animation.ee = ecore_evas_ecore_evas_get(s_animation.evas);
-       if (!s_animation.ee) {
+       s_animation.layout = __create_layout(s_animation.win, layout_file_name);
+       if (!s_animation.layout) {
+               __E("Failed to create layout");
+               free(layout_file_name);
                evas_object_del(s_animation.win);
-               fprintf(stderr, "Failed to get the ecore evas object\n");
                return EXIT_FAILURE;
        }
 
-       s_animation.xwin = ecore_evas_window_get(s_animation.ee);
-       ecore_x_netwm_window_type_set(s_animation.xwin,
-                                     ECORE_X_WINDOW_TYPE_NOTIFICATION);
-       utilx_set_system_notification_level(ecore_x_display_get(),
-                                           s_animation.xwin,
-                                           UTILX_NOTIFICATION_LEVEL_HIGH);
+       free(layout_file_name);
 
        return EXIT_SUCCESS;
 }
 
-int init_animation(int state, const char *msg)
+int animation_fini(void)
 {
-       s_animation.focus_win = ecore_x_window_focus_get();
-       s_animation.root_win = ecore_x_window_root_get(s_animation.focus_win);
-       s_animation.state = state;
-       ecore_x_window_size_get(s_animation.root_win, &s_animation.w,
-                               &s_animation.h);
+       __destroy_layout();
 
-       if (create_window() == EXIT_FAILURE) {
-               fprintf(stderr, "Failed to create a new window\n");
-               return EXIT_FAILURE;
-       }
+       evas_object_del(s_animation.win);
+       fflush(stdout);
+       close(1);
+       return EXIT_SUCCESS;
+}
 
-       if (init_layout(msg) == EXIT_FAILURE) {
-               fprintf(stderr, "Failed to init the layout object\n");
-               if (msg)
-                       evas_object_del(s_animation.txt);
-               evas_object_del(s_animation.win);
-               return EXIT_FAILURE;
-       }
+#include "test.h"
+#if TEST_MODE
+Evas_Object *__t__get_window(void)
+{
+       return s_animation.win;
+}
 
-       return EXIT_SUCCESS;
+Evas_Object *__t__get_layout(void)
+{
+       return s_animation.layout;
 }
 
-int fini_animation(void)
+Evas_Object *__t__get_display_block(void)
 {
-       fini_layout();
-       evas_object_del(s_animation.win);
-       return EXIT_SUCCESS;
+       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