4 * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <appcore-efl.h>
22 #include <Elementary.h>
34 #define KEY_BACK "XF86Back"
35 #define PRIVATE_DATA_KEY_LIST_TIMER "pri_list_tm"
37 static main_s main_info = {
48 //main_h main_info_h = &main_info;
52 extern main_h main_get_info(void)
59 static Eina_Bool _back_key_pressed(void *data, Evas_Object *obj, Evas_Object *src, Evas_Callback_Type type, void *event_info)
62 Evas_Event_Key_Down *ev = event_info;
64 if (type == EVAS_CALLBACK_KEY_DOWN && strncmp(KEY_BACK, ev->key, strlen(KEY_BACK)) == 0) {
65 _D("KEY PRESSED: %s", ev->key);
76 static task_mgr_error_e _create_layout(Evas_Object *parent)
79 Evas_Object *layout = NULL;
80 Eina_Bool ret = EINA_FALSE;
83 layout = elm_layout_add(parent);
84 goto_if (!layout, ERROR);
86 ret = elm_layout_file_set(layout, LAYOUT, "layout");
87 goto_if(EINA_FALSE == ret, ERROR);
89 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
90 evas_object_move(layout, 0, 0);
91 evas_object_resize(layout, main_info.root_w, main_info.root_h);
92 evas_object_show(layout);
94 main_info.layout = layout;
97 main_info.scroller = scroller_create(layout);
98 goto_if(!main_info.scroller, ERROR);
100 return TASK_MGR_ERROR_NONE;
103 if (layout) evas_object_del(layout);
104 evas_object_del(main_info.win);
105 return TASK_MGR_ERROR_FAIL;
110 static void _destroy_layout(void)
112 if (main_info.layout) {
113 evas_object_del(main_info.layout);
114 main_info.layout = NULL;
120 static Eina_Bool _list_timer_cb(void *data)
123 Evas_Object *clear_item = NULL;
124 task_mgr_error_e ret = TASK_MGR_ERROR_NONE;
126 if (main_info.pkg_list) {
127 _D("Already loaded");
131 clear_item = item_clear_all_create(main_info.scroller);
133 _E("Fail to create clear all button");
134 return ECORE_CALLBACK_CANCEL;
136 scroller_push_item(main_info.scroller, clear_item);
138 ret = list_create(&main_info.pkg_list);
139 elm_object_part_text_set(main_info.layout, "no,apps,txt", _("IDS_TASKMGR_NPBODY_NO_APPLICATIONS_ABB2"));
140 if (TASK_MGR_ERROR_NO_DATA == ret) {
141 _D("There is no application");
142 item_clear_set_disable(main_info.scroller);
143 } else if (TASK_MGR_ERROR_NONE != ret) {
144 _E("Fail to create pkglist");
148 goto_if(TASK_MGR_ERROR_NONE != scroller_push_all_item(main_info.scroller, main_info.pkg_list), END);
151 evas_object_data_del(main_info.win, PRIVATE_DATA_KEY_LIST_TIMER);
152 return ECORE_CALLBACK_CANCEL;
157 static bool _create_cb(void *data)
161 Ecore_Timer *timer = NULL;
163 main_info.win = elm_win_add(NULL, "Task-mgr", ELM_WIN_BASIC);
164 retv_if(!main_info.win, false);
166 elm_win_screen_size_get(main_info.win, NULL, NULL, &main_info.root_w, &main_info.root_h);
167 _D("screen size is (%d, %d)", main_info.root_w, main_info.root_h);
169 elm_object_event_callback_add(main_info.win, _back_key_pressed, NULL);
171 elm_win_indicator_mode_set(main_info.win, ELM_WIN_INDICATOR_SHOW);
172 elm_win_indicator_opacity_set(main_info.win, ELM_WIN_INDICATOR_TRANSPARENT);
174 elm_win_borderless_set(main_info.win, EINA_TRUE);
175 elm_win_alpha_set(main_info.win, EINA_TRUE);
176 evas_object_show(main_info.win);
178 main_info.e = evas_object_evas_get(main_info.win);
180 if (_create_layout(main_info.win) != TASK_MGR_ERROR_NONE) {
181 _E("Failed to create a layout");
186 timer = evas_object_data_get(main_info.win, PRIVATE_DATA_KEY_LIST_TIMER);
188 ecore_timer_del(timer);
191 timer = ecore_timer_add(0.001f, _list_timer_cb, NULL);
193 evas_object_data_set(main_info.win, PRIVATE_DATA_KEY_LIST_TIMER, timer);
195 _E("Cannot add a create list timer");
203 static void _terminate_cb(void *data)
208 list_destroy(main_info.pkg_list);
209 evas_object_data_del(main_info.win, PRIVATE_DATA_KEY_LIST_TIMER);
211 elm_cache_all_flush();
213 appcore_flush_memory();
215 scroller_destroy(main_info.layout);
219 * Even though the window is deleted automatically,
220 * It is good habit to delete window explicitly by your hands.
224 evas_object_del(main_info.win);
225 main_info.win = NULL;
231 static void _app_control(app_control_h service, void *data)
240 static void _pause_cb(void *data)
250 static void _language_changed(app_event_info_h event_info, void *data)
257 int main(int argc, char **argv)
260 ui_app_lifecycle_callback_s lifecycle_callback = {0, };
261 app_event_handler_h event_handlers[5] = {NULL, };
263 lifecycle_callback.create = _create_cb;
264 lifecycle_callback.terminate = _terminate_cb;
265 lifecycle_callback.pause = _pause_cb;
266 lifecycle_callback.resume = NULL;
267 lifecycle_callback.app_control = _app_control;
269 ui_app_add_event_handler(&event_handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, NULL, NULL);
270 ui_app_add_event_handler(&event_handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, NULL, NULL);
271 ui_app_add_event_handler(&event_handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, NULL, NULL);
272 ui_app_add_event_handler(&event_handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _language_changed, NULL);
273 ui_app_add_event_handler(&event_handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, NULL, NULL);
275 ret = ui_app_main(argc, argv, &lifecycle_callback, &main_info);