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];
34 Evas_Object *focused_btn;
43 const char *layout_id;
46 static struct _menu_item g_menu_item[MENU_BTN_SIZE] = {
61 static void _mouse_move_cb(int id, void *data, Evas *e,
62 Evas_Object *obj, Evas_Event_Mouse_Move *ev)
64 if (!elm_object_focus_get(obj))
65 elm_object_focus_set(obj, EINA_TRUE);
68 static void _focused_cb(int id, void *data, Evas_Object *obj,
75 _ERR("failed to get data");
81 if (priv->focused_btn == obj)
84 for (i = 0; i < MENU_BTN_SIZE; i++) {
85 if (priv->btn[i] == obj)
89 if (i == MENU_BTN_SIZE)
92 layoutmgr_hide_layout(priv->lmgr,
93 g_menu_item[priv->current_layout].layout_id);
94 layoutmgr_show_layout(priv->lmgr, g_menu_item[i].layout_id);
95 layoutmgr_update_layout(priv->lmgr, g_menu_item[i].layout_id, 0, NULL);
97 priv->focused_btn = obj;
98 priv->current_layout = i;
101 static input_handler handler = {
102 .mouse_move = _mouse_move_cb,
103 .focused = _focused_cb
106 static bool _draw_title(struct _priv *priv)
111 elm_object_part_text_set(priv->base, PART_TITLE, TITLE_TEXT);
116 static bool _draw_menu_btn(struct _priv *priv)
118 Evas_Object *box, *btn;
124 box = elm_box_add(priv->base);
126 _ERR("failed to create box object");
130 elm_box_horizontal_set(box, EINA_TRUE);
132 evas_object_size_hint_weight_set(box,
133 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
134 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
136 for (i = 0; i < MENU_BTN_SIZE; i++) {
137 btn = elm_button_add(box);
139 _ERR("failed to create button object");
143 elm_object_style_set(btn, STYLE_MENU_BTN);
144 elm_object_text_set(btn, g_menu_item[i].name);
146 elm_box_pack_end(box, btn);
148 evas_object_show(btn);
150 inputmgr_add_callback(btn, 0, &handler, priv);
155 evas_object_show(box);
157 elm_object_part_content_set(priv->base, PART_MENU_AREA, box);
159 elm_object_focus_set(priv->btn[0], EINA_TRUE);
161 elm_object_focus_next_object_set(priv->btn[MENU_BTN_SIZE - 1],
162 priv->btn[0], ELM_FOCUS_RIGHT);
163 elm_object_focus_next_object_set(priv->btn[0],
164 priv->btn[MENU_BTN_SIZE - 1], ELM_FOCUS_LEFT);
169 static bool _draw_items(struct _priv *priv)
174 if (!_draw_title(priv))
177 if (!_draw_menu_btn(priv))
183 static Evas_Object *_create(Evas_Object *win, void *data)
190 _ERR("failed to get win object");
194 priv = calloc(1, sizeof(*priv));
196 _ERR("failed to allocate priv");
200 base = elm_layout_add(win);
202 _ERR("failed to create base object");
207 elm_layout_file_set(base, EDJEFILE, GRP_BASE_VIEW);
209 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
210 elm_win_resize_object_add(win, base);
212 lmgr = layoutmgr_create(base);
213 layoutmgr_add_layout(lmgr, layout_movie_get_lclass(), NULL);
214 layoutmgr_add_layout(lmgr, layout_gallery_get_lclass(), NULL);
215 layoutmgr_add_layout(lmgr, layout_music_get_lclass(), NULL);
221 if (!_draw_items(priv)) {
222 _ERR("failed to draw items");
227 viewmgr_set_view_data(VIEW_BASE, priv);
232 static void _show(void *view_data)
237 _ERR("failed to get view data");
243 evas_object_show(priv->base);
246 static void _hide(void *view_data)
251 _ERR("failed to get view data");
257 evas_object_hide(priv->base);
260 static void _destroy(void *view_data)
266 _ERR("failed to get view data");
272 for (i = 0; i < MENU_BTN_SIZE; i++)
273 inputmgr_remove_callback(priv->btn[i], &handler);
275 layoutmgr_remove_layout(priv->lmgr, LAYOUT_MOVIE);
276 layoutmgr_remove_layout(priv->lmgr, LAYOUT_GALLERY);
277 layoutmgr_remove_layout(priv->lmgr, LAYOUT_MUSIC);
279 layoutmgr_destroy(priv->lmgr);
281 evas_object_del(priv->base);
286 static view_class _vclass = {
287 .view_id = VIEW_BASE,
294 view_class *view_base_get_vclass(void)