2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <Elementary.h>
18 #include <app_debug.h>
21 #include <layoutmgr.h>
26 #define TITLE_TEXT "Media Hub"
28 #define MENU_BTN_SIZE 3
33 Evas_Object *btn[MENU_BTN_SIZE];
42 const char *layout_id;
45 static struct _menu_item g_menu_item[MENU_BTN_SIZE] = {
60 static void _mouse_move_cb(int id, void *data, Evas *e,
61 Evas_Object *obj, Evas_Event_Mouse_Move *ev)
63 if (!elm_object_focus_get(obj))
64 elm_object_focus_set(obj, EINA_TRUE);
67 static void _focused_cb(int id, void *data, Evas_Object *obj,
74 _ERR("failed to get data");
80 for (i = 0; i < MENU_BTN_SIZE; i++) {
81 if (priv->btn[i] == obj)
85 if (i == priv->current_layout || i == MENU_BTN_SIZE)
88 layoutmgr_hide_layout(priv->lmgr,
89 g_menu_item[priv->current_layout].layout_id);
90 layoutmgr_show_layout(priv->lmgr, g_menu_item[i].layout_id);
91 layoutmgr_update_layout(priv->lmgr, g_menu_item[i].layout_id, 0, NULL);
93 priv->current_layout = i;
96 static input_handler handler = {
97 .mouse_move = _mouse_move_cb,
98 .focused = _focused_cb
101 static bool _draw_title(struct _priv *priv)
106 elm_object_part_text_set(priv->base, PART_TITLE, TITLE_TEXT);
111 static bool _draw_menu_btn(struct _priv *priv)
113 Evas_Object *box, *btn;
119 box = elm_box_add(priv->base);
121 _ERR("failed to create box object");
125 elm_box_horizontal_set(box, EINA_TRUE);
127 evas_object_size_hint_weight_set(box,
128 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
129 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
131 for (i = 0; i < MENU_BTN_SIZE; i++) {
132 btn = elm_button_add(box);
134 _ERR("failed to create button object");
138 elm_object_style_set(btn, STYLE_MENU_BTN);
139 elm_object_text_set(btn, g_menu_item[i].name);
141 elm_box_pack_end(box, btn);
143 evas_object_show(btn);
145 inputmgr_add_callback(btn, 0, &handler, priv);
150 evas_object_show(box);
152 elm_object_part_content_set(priv->base, PART_MENU_AREA, box);
154 elm_object_focus_set(priv->btn[0], EINA_TRUE);
156 elm_object_focus_next_object_set(priv->btn[MENU_BTN_SIZE - 1],
157 priv->btn[0], ELM_FOCUS_RIGHT);
158 elm_object_focus_next_object_set(priv->btn[0],
159 priv->btn[MENU_BTN_SIZE - 1], ELM_FOCUS_LEFT);
164 static bool _draw_items(struct _priv *priv)
169 if (!_draw_title(priv))
172 if (!_draw_menu_btn(priv))
178 static Evas_Object *_create(Evas_Object *win, void *data)
185 _ERR("failed to get win object");
189 priv = calloc(1, sizeof(*priv));
191 _ERR("failed to allocate priv");
195 base = elm_layout_add(win);
197 _ERR("failed to create base object");
202 elm_layout_file_set(base, EDJEFILE, GRP_BASE_VIEW);
204 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
205 elm_win_resize_object_add(win, base);
207 lmgr = layoutmgr_create(base);
208 layoutmgr_add_layout(lmgr, layout_movie_get_lclass(), NULL);
209 layoutmgr_add_layout(lmgr, layout_gallery_get_lclass(), NULL);
210 layoutmgr_add_layout(lmgr, layout_music_get_lclass(), NULL);
216 if (!_draw_items(priv)) {
217 _ERR("failed to draw items");
222 viewmgr_set_view_data(VIEW_BASE, priv);
227 static void _show(void *view_data)
232 _ERR("failed to get view data");
238 evas_object_show(priv->base);
241 static void _hide(void *view_data)
246 _ERR("failed to get view data");
252 evas_object_hide(priv->base);
255 static void _destroy(void *view_data)
261 _ERR("failed to get view data");
267 for (i = 0; i < MENU_BTN_SIZE; i++)
268 inputmgr_remove_callback(priv->btn[i], &handler);
270 layoutmgr_remove_layout(priv->lmgr, LAYOUT_MOVIE);
271 layoutmgr_remove_layout(priv->lmgr, LAYOUT_GALLERY);
272 layoutmgr_remove_layout(priv->lmgr, LAYOUT_MUSIC);
274 layoutmgr_destroy(priv->lmgr);
276 evas_object_del(priv->base);
281 static view_class _vclass = {
282 .view_id = VIEW_BASE,
289 view_class *view_base_get_vclass(void)