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"
36 #define ICON_ADD "add"
37 #define KEY_ICON "icon"
38 #define KEY_FOCUS_ICON "focusicon"
40 #define CTXPOPUP_X 294
41 #define CTXPOPUP_Y 310
45 const char *focus_file;
47 const char *focus_message;
60 Evas_Object *focus_icon;
63 Evas_Object *ctxpopup;
68 static void _done_key_down(int id, void *data, Evas *e, Evas_Object *obj,
69 Evas_Event_Key_Down *ev)
71 if (!strcmp(ev->keyname, KEY_ENTER)) {
72 /* check state of user edit */
77 static input_handler done_handler = {
78 .key_down = _done_key_down
81 static void _cancel_key_down(int id, void *data, Evas *e, Evas_Object *obj,
82 Evas_Event_Key_Down *ev)
84 if (!strcmp(ev->keyname, KEY_ENTER)) {
89 static input_handler cancel_handler = {
90 .key_down = _cancel_key_down
93 static bool _add_btns(struct _priv *priv)
95 Evas_Object *done, *cancel;
97 done = utils_add_button(priv->base, MESSAGE_BTN_DONE,
98 PART_USER_EDIT_BTN_DONE);
100 _ERR("failed to add done btn");
103 inputmgr_add_callback(done, 0, &done_handler, NULL);
105 cancel = utils_add_button(priv->base, MESSAGE_BTN_CANCEL,
106 PART_USER_EDIT_BTN_CANCEL);
108 _ERR("failed to add cancel btn");
109 evas_object_del(done);
112 inputmgr_add_callback(cancel, 0, &cancel_handler, NULL);
114 priv->cancel = cancel;
120 static void _focused(int id, void *data, Evas_Object *obj,
121 Elm_Object_Item *item)
123 elm_object_signal_emit(obj, SIG_FOCUS, SRC_PROG);
126 static void _unfocused(int id, void *data, Evas_Object *obj,
127 Elm_Object_Item *item)
129 elm_object_signal_emit(obj, SIG_UNFOCUS, SRC_PROG);
132 static void _load_user_icon(struct _priv *priv, const char *file,
133 const char *focus_file)
135 Evas_Object *icon, *focus_icon;
137 icon = utils_add_icon(priv->photo, file, PART_USER_EDIT_PHOTO);
139 _ERR("failed to add icon");
141 focus_icon = utils_add_icon(priv->photo, focus_file,
142 PART_USER_EDIT_PHOTO_FOCUS);
144 _ERR("failed to add focus icon");
147 priv->focus_icon = focus_icon;
150 static void _eo_key_down(int id, void *data, Evas *e, Evas_Object *obj,
151 Evas_Event_Key_Down *ev)
154 const char *file, *focus_file;
161 if (!strcmp(ev->keyname, KEY_BACK) ||
162 !strcmp(ev->keyname, KEY_BACK_REMOTE)) {
163 evas_object_del(priv->ctxpopup);
164 priv->ctxpopup = NULL;
165 } else if (!strcmp(ev->keyname, KEY_ENTER) ||
166 !strcmp(ev->keyname, KEY_ENTER_REMOTE)) {
167 evas_object_del(priv->ctxpopup);
168 priv->ctxpopup = NULL;
170 file = evas_object_data_get(obj, KEY_ICON);
171 focus_file = evas_object_data_get(obj, KEY_FOCUS_ICON);
173 if (!strcmp(file, ICON_ADD) || !strcmp(focus_file, ICON_ADD))
174 viewmgr_push_view(VIEW_PHOTO);
176 _load_user_icon(priv, file, focus_file);
180 static input_handler icon_handler = {
182 .unfocused = _unfocused,
183 .key_down = _eo_key_down
186 static Evas_Object *_pack_icon(Evas_Object *table, struct _icon_info *icon_info, int i)
188 Evas_Object *eo, *ic, *focus_ic;
190 eo = utils_add_layout(table, GRP_USER_EDIT_ICON_LIST_ITEM, true, NULL);
192 _ERR("failed to add layout");
195 evas_object_show(eo);
196 elm_table_pack(table, eo, i % 4, i / 4, 1, 1);
198 ic = utils_add_icon(eo, icon_info->file, PART_USER_EDIT_ICON_LIST_ITEM);
200 _ERR("failed to add icon");
205 focus_ic = utils_add_icon(eo, icon_info->focus_file,
206 PART_USER_EDIT_ICON_LIST_ITEM_FOCUS);
208 _ERR("failed to add focus icon");
212 evas_object_data_set(eo, KEY_ICON, icon_info->message);
213 evas_object_data_set(eo, KEY_FOCUS_ICON, icon_info->focus_message);
218 static void _add_icon_list(struct _priv *priv)
220 Evas_Coord x, y, w, h;
221 Evas_Object *ctxpopup, *ly, *table, *eo;
223 struct _icon_info icon_info[] = {
226 IMAGE_USER_DEFAULT_FOCUS,
227 IMAGE_USER_CURRENT_DEFAULT,
228 IMAGE_USER_CURRENT_DEFAULT_FOCUS
231 IMAGE_USER_DEFAULT_02,
232 IMAGE_USER_DEFAULT_02_FOCUS,
233 IMAGE_USER_CURRENT_DEFAULT_02,
234 IMAGE_USER_CURRENT_DEFAULT_02_FOCUS
237 IMAGE_USER_DEFAULT_03,
238 IMAGE_USER_DEFAULT_03_FOCUS,
239 IMAGE_USER_CURRENT_DEFAULT_03,
240 IMAGE_USER_CURRENT_DEFAULT_03_FOCUS
243 IMAGE_USER_DEFAULT_04,
244 IMAGE_USER_DEFAULT_04_FOCUS,
245 IMAGE_USER_CURRENT_DEFAULT_04,
246 IMAGE_USER_CURRENT_DEFAULT_04_FOCUS
249 IMAGE_USER_DEFAULT_05,
250 IMAGE_USER_DEFAULT_05_FOCUS,
251 IMAGE_USER_CURRENT_DEFAULT_05,
252 IMAGE_USER_CURRENT_DEFAULT_05_FOCUS
255 IMAGE_USER_DEFAULT_06,
256 IMAGE_USER_DEFAULT_06_FOCUS,
257 IMAGE_USER_CURRENT_DEFAULT_06,
258 IMAGE_USER_CURRENT_DEFAULT_06_FOCUS
261 IMAGE_USER_DEFAULT_07,
262 IMAGE_USER_DEFAULT_07_FOCUS,
263 IMAGE_USER_CURRENT_DEFAULT_07,
264 IMAGE_USER_CURRENT_DEFAULT_07_FOCUS
268 IMAGE_USER_ADD_FOCUS,
274 ctxpopup = elm_ctxpopup_add(priv->base);
276 _ERR("failed to add ctxpopup");
279 elm_ctxpopup_horizontal_set(ctxpopup, EINA_TRUE);
280 elm_ctxpopup_auto_hide_disabled_set(ctxpopup, EINA_TRUE);
282 ly = utils_add_layout(ctxpopup, GRP_USER_EDIT_ICON_LIST, false, NULL);
284 _ERR("failed to layout");
285 evas_object_del(ctxpopup);
288 elm_object_content_set(ctxpopup, ly);
289 evas_object_show(ly);
290 evas_object_show(ctxpopup);
292 evas_object_geometry_get(priv->photo, &x, &y, &w, &h);
293 evas_object_move(ctxpopup,
294 (x + w + CTXPOPUP_X) * elm_config_scale_get(),
295 (y + CTXPOPUP_Y) * elm_config_scale_get());
297 table = utils_add_table(ly, true, PART_USER_EDIT_ICON_LIST);
299 _ERR("failed to add table");
300 evas_object_del(ctxpopup);
303 elm_table_padding_set(table, elm_config_scale_get() * 1,
304 elm_config_scale_get() * 1);
305 evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND,
308 for (i = 0; i < sizeof(icon_info) / sizeof(*icon_info); i++) {
309 eo = _pack_icon(table, &icon_info[i], i);
313 inputmgr_add_callback(eo, 0, &icon_handler, priv);
315 elm_object_focus_set(eo, EINA_TRUE);
318 priv->ctxpopup = ctxpopup;
321 static void _photo_key_down(int id, void *data, Evas *e, Evas_Object *obj,
322 Evas_Event_Key_Down *ev)
324 if (!strcmp(ev->keyname, KEY_ENTER)) {
325 _add_icon_list(data);
329 static input_handler photo_handler = {
331 .unfocused = _unfocused,
332 .key_down = _photo_key_down
335 static Evas_Object *_add_layout(struct _priv *priv)
337 Evas_Object *ly, *photo, *name, *pin, *account, *lock;
339 ly = utils_add_layout(priv->base, GRP_USER_EDIT_CONTENTS, false,
340 PART_USER_EDIT_CONTENTS);
342 _ERR("failed to add layout");
346 photo = utils_add_layout(ly, GRP_USER_EDIT_PHOTO, true,
347 PART_USER_EDIT_CONTENTS_PHOTO);
351 name = utils_add_entry(ly, MESSAGE_ENTRY_NAME, false,
352 PART_USER_EDIT_CONTENTS_NAME);
356 pin = utils_add_entry(ly, MESSAGE_ENTRY_PIN, false,
357 PART_USER_EDIT_CONTENTS_PIN);
361 account = utils_add_entry(ly, MESSAGE_ENTRY_ACCOUNT, false,
362 PART_USER_EDIT_CONTENTS_ACCOUNT);
366 lock = utils_add_layout(ly, GRP_USER_EDIT_SWITCH, true,
367 PART_USER_EDIT_CONTENTS_LOCK);
371 inputmgr_add_callback(photo, 0, &photo_handler, priv);
375 priv->account = account;
381 _ERR("failed to add layout");
386 static bool _add_user_edit(struct _priv *priv)
390 ly = _add_layout(priv);
392 _ERR("failed to add edit layout");
396 if (!_add_btns(priv)) {
397 _ERR("failed to add buttons");
402 /* It should be implemented later about function btn */
409 static Evas_Object *_create(Evas_Object *win, void *data)
415 _ERR("Invalid argument");
419 priv = calloc(1, sizeof(*priv));
421 _ERR("failed to calloc priv");
425 base = utils_add_layout(win, GRP_USER_EDIT, false, NULL);
427 _ERR("failed to create base");
431 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
433 elm_win_resize_object_add(win, base);
439 if (!_add_user_edit(priv)) {
440 _ERR("failed to add user edit layout");
441 evas_object_del(base);
446 viewmgr_set_view_data(VIEW_USER_EDIT, priv);
447 viewmgr_add_view(view_photo_get_vclass(), NULL);
452 static void _show(void *data)
457 _ERR("Invalid argument");
463 evas_object_show(priv->base);
464 elm_object_part_text_set(priv->base, PART_USER_EDIT_TITLE,
466 _load_user_icon(priv, IMAGE_USER_CURRENT_DEFAULT,
467 IMAGE_USER_CURRENT_DEFAULT_FOCUS);
470 static void _hide(void *data)
475 _ERR("Invalid argument");
481 evas_object_hide(priv->base);
484 static void _destroy(void *data)
489 _ERR("Invalid argument");
495 inputmgr_remove_callback(priv->photo, &photo_handler);
496 inputmgr_remove_callback(priv->done, &done_handler);
497 inputmgr_remove_callback(priv->cancel, &cancel_handler);
498 viewmgr_remove_view(VIEW_PHOTO);
499 evas_object_del(priv->base);
503 static view_class vclass = {
504 .view_id = VIEW_USER_EDIT,
511 view_class *view_user_edit_get_vclass(void)