3 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an AS IS BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <Elementary.h>
19 #include <app_debug.h>
24 #include "view_user_edit.h"
25 #include "view_photo.h"
29 #define MESSAGE_BTN_DONE "Done"
30 #define MESSAGE_BTN_CANCEL "Cancel"
31 #define MESSAGE_ADD_USER "Add user"
32 #define MESSAGE_EDIT_USER "Edit user"
33 #define MESSAGE_ENTRY_NAME "User Name"
34 #define MESSAGE_ENTRY_ACCOUNT "sample@tizen.com"
35 #define MESSAGE_ENTRY_PIN "Pin code"
37 #define CTXPOPUP_X 294
38 #define CTXPOPUP_Y 310
40 static const char *icon_info[][2] = {
41 { IMAGE_USER_DEFAULT, IMAGE_USER_DEFAULT_FOCUS },
42 { IMAGE_USER_DEFAULT_02, IMAGE_USER_DEFAULT_02_FOCUS },
43 { IMAGE_USER_DEFAULT_03, IMAGE_USER_DEFAULT_03_FOCUS },
44 { IMAGE_USER_DEFAULT_04, IMAGE_USER_DEFAULT_04_FOCUS },
45 { IMAGE_USER_DEFAULT_05, IMAGE_USER_DEFAULT_05_FOCUS },
46 { IMAGE_USER_DEFAULT_06, IMAGE_USER_DEFAULT_06_FOCUS },
47 { IMAGE_USER_DEFAULT_07, IMAGE_USER_DEFAULT_07_FOCUS },
48 { IMAGE_USER_ADD, IMAGE_USER_ADD_FOCUS }
61 Evas_Object *focus_icon;
64 Evas_Object *ctxpopup;
69 static void _done_key_down(int id, void *data, Evas *e, Evas_Object *obj,
70 Evas_Event_Key_Down *ev)
72 if (!strcmp(ev->keyname, KEY_ENTER)) {
73 /* check state of user edit */
78 static input_handler done_handler = {
79 .key_down = _done_key_down
82 static void _cancel_key_down(int id, void *data, Evas *e, Evas_Object *obj,
83 Evas_Event_Key_Down *ev)
85 if (!strcmp(ev->keyname, KEY_ENTER)) {
90 static input_handler cancel_handler = {
91 .key_down = _cancel_key_down
94 static bool _add_btns(struct _priv *priv)
96 Evas_Object *done, *cancel;
98 done = utils_add_button(priv->base, MESSAGE_BTN_DONE,
99 PART_USER_EDIT_BTN_DONE);
101 _ERR("failed to add done btn");
104 inputmgr_add_callback(done, 0, &done_handler, NULL);
106 cancel = utils_add_button(priv->base, MESSAGE_BTN_CANCEL,
107 PART_USER_EDIT_BTN_CANCEL);
109 _ERR("failed to add cancel btn");
110 evas_object_del(done);
113 inputmgr_add_callback(cancel, 0, &cancel_handler, NULL);
115 priv->cancel = cancel;
121 static void _focused(int id, void *data, Evas_Object *obj,
122 Elm_Object_Item *item)
124 elm_object_signal_emit(obj, SIG_FOCUS, SRC_PROG);
127 static void _unfocused(int id, void *data, Evas_Object *obj,
128 Elm_Object_Item *item)
130 elm_object_signal_emit(obj, SIG_UNFOCUS, SRC_PROG);
133 static void _eo_key_down(int id, void *data, Evas *e, Evas_Object *obj,
134 Evas_Event_Key_Down *ev)
136 if (!strcmp(ev->keyname, KEY_BACK) ||
137 !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
138 evas_object_del(data);
139 } else if (!strcmp(ev->keyname, KEY_ENTER) ||
140 !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
141 /* It should be implemented later */
142 evas_object_del(data);
143 viewmgr_push_view(VIEW_PHOTO);
147 static input_handler icon_handler = {
149 .unfocused = _unfocused,
150 .key_down = _eo_key_down
153 static Evas_Object *_pack_icon(Evas_Object *table, const char *icon_file,
154 const char *focus_icon_file, int i)
156 Evas_Object *eo, *ic, *focus_ic;
158 eo = utils_add_layout(table, GRP_USER_EDIT_ICON_LIST_ITEM, true, NULL);
160 _ERR("failed to add layout");
163 evas_object_show(eo);
164 elm_table_pack(table, eo, i % 4, i / 4, 1, 1);
166 ic = utils_add_icon(eo, icon_file, PART_USER_EDIT_ICON_LIST_ITEM);
168 _ERR("failed to add icon");
173 focus_ic = utils_add_icon(eo, focus_icon_file,
174 PART_USER_EDIT_ICON_LIST_ITEM_FOCUS);
176 _ERR("failed to add focus icon");
184 static void _add_icon_list(struct _priv *priv)
186 Evas_Coord x, y, w, h;
187 Evas_Object *ctxpopup, *ly, *table, *eo;
190 ctxpopup = elm_ctxpopup_add(priv->base);
192 _ERR("failed to add ctxpopup");
195 elm_ctxpopup_horizontal_set(ctxpopup, EINA_TRUE);
196 elm_ctxpopup_auto_hide_disabled_set(ctxpopup, EINA_TRUE);
198 ly = utils_add_layout(ctxpopup, GRP_USER_EDIT_ICON_LIST, false, NULL);
200 _ERR("failed to layout");
201 evas_object_del(ctxpopup);
204 elm_object_content_set(ctxpopup, ly);
205 evas_object_show(ly);
206 evas_object_show(ctxpopup);
208 evas_object_geometry_get(priv->photo, &x, &y, &w, &h);
209 evas_object_move(ctxpopup,
210 (x + w + CTXPOPUP_X) * elm_config_scale_get(),
211 (y + CTXPOPUP_Y) * elm_config_scale_get());
213 table = utils_add_table(ly, true, PART_USER_EDIT_ICON_LIST);
215 _ERR("failed to add table");
216 evas_object_del(ctxpopup);
219 elm_table_padding_set(table, elm_config_scale_get() * 1,
220 elm_config_scale_get() * 1);
221 evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND,
224 for (i = 0; i < sizeof(icon_info) / sizeof(*icon_info); i++) {
225 eo = _pack_icon(table, icon_info[i][0], icon_info[i][1], i);
229 inputmgr_add_callback(eo, 0, &icon_handler, ctxpopup);
231 elm_object_focus_set(eo, EINA_TRUE);
234 priv->ctxpopup = ctxpopup;
237 static void _photo_key_down(int id, void *data, Evas *e, Evas_Object *obj,
238 Evas_Event_Key_Down *ev)
240 if (!strcmp(ev->keyname, KEY_ENTER)) {
241 _add_icon_list(data);
245 static input_handler photo_handler = {
247 .unfocused = _unfocused,
248 .key_down = _photo_key_down
251 static Evas_Object *_add_layout(struct _priv *priv)
253 Evas_Object *ly, *photo, *name, *pin, *account, *lock;
255 ly = utils_add_layout(priv->base, GRP_USER_EDIT_CONTENTS, false,
256 PART_USER_EDIT_CONTENTS);
258 _ERR("failed to add layout");
262 photo = utils_add_layout(ly, GRP_USER_EDIT_PHOTO, true,
263 PART_USER_EDIT_CONTENTS_PHOTO);
267 name = utils_add_entry(ly, MESSAGE_ENTRY_NAME, false,
268 PART_USER_EDIT_CONTENTS_NAME);
272 pin = utils_add_entry(ly, MESSAGE_ENTRY_PIN, false,
273 PART_USER_EDIT_CONTENTS_PIN);
277 account = utils_add_entry(ly, MESSAGE_ENTRY_ACCOUNT, false,
278 PART_USER_EDIT_CONTENTS_ACCOUNT);
282 lock = utils_add_layout(ly, GRP_USER_EDIT_SWITCH, true,
283 PART_USER_EDIT_CONTENTS_LOCK);
287 inputmgr_add_callback(photo, 0, &photo_handler, priv);
291 priv->account = account;
297 _ERR("failed to add layout");
302 static bool _add_user_edit(struct _priv *priv)
306 ly = _add_layout(priv);
308 _ERR("failed to add edit layout");
312 if (!_add_btns(priv)) {
313 _ERR("failed to add buttons");
318 /* It should be implemented later about function btn */
325 static Evas_Object *_create(Evas_Object *win, void *data)
331 _ERR("Invalid argument");
335 priv = calloc(1, sizeof(*priv));
337 _ERR("failed to calloc priv");
341 base = utils_add_layout(win, GRP_USER_EDIT, false, NULL);
343 _ERR("failed to create base");
347 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
349 elm_win_resize_object_add(win, base);
355 if (!_add_user_edit(priv)) {
356 _ERR("failed to add user edit layout");
357 evas_object_del(base);
362 viewmgr_set_view_data(VIEW_USER_EDIT, priv);
363 viewmgr_add_view(view_photo_get_vclass(), NULL);
368 static void _load_user_edit(struct _priv *priv)
370 Evas_Object *icon, *focus_icon;
372 /* check state of user edit */
374 elm_object_part_text_set(priv->base, PART_USER_EDIT_TITLE,
376 icon = utils_add_icon(priv->photo, IMAGE_USER_CURRENT_DEFAULT,
377 PART_USER_EDIT_PHOTO);
379 _ERR("failed to add icon");
381 focus_icon = utils_add_icon(priv->photo,
382 IMAGE_USER_CURRENT_DEFAULT_FOCUS,
383 PART_USER_EDIT_PHOTO_FOCUS);
385 _ERR("failed to add focus icon");
388 priv->focus_icon = focus_icon;
391 static void _show(void *data)
396 _ERR("Invalid argument");
402 evas_object_show(priv->base);
404 _load_user_edit(priv);
407 static void _hide(void *data)
412 _ERR("Invalid argument");
418 evas_object_hide(priv->base);
421 static void _destroy(void *data)
426 _ERR("Invalid argument");
432 inputmgr_remove_callback(priv->photo, &photo_handler);
433 inputmgr_remove_callback(priv->done, &done_handler);
434 inputmgr_remove_callback(priv->cancel, &cancel_handler);
435 viewmgr_remove_view(VIEW_PHOTO);
436 evas_object_del(priv->base);
440 static view_class vclass = {
441 .view_id = VIEW_USER_EDIT,
448 view_class *view_user_edit_get_vclass(void)