From: Pawel Aksiutowicz Date: Mon, 15 May 2017 15:19:17 +0000 (+0200) Subject: [GUI] Clock mode selection popup view and its style is like in Language/Voice selecti... X-Git-Tag: submit/tizen/20170614.011152~21 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e361838f7f734b922ce2c9a88bf375d0435f93e6;p=profile%2Ftv%2Fapps%2Fnative%2Fair_settings.git [GUI] Clock mode selection popup view and its style is like in Language/Voice selection popup (and old popup style was removed). Change-Id: I4930ead5d6fcbef1f90d7d4984c86fdc9cf6e4ea Signed-off-by: Pawel Aksiutowicz --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f9aaf0..eb8456e 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,7 +85,6 @@ SET(SRCS src/layout/layout_network.c src/layout/layout_picture.c src/layout/layout_system.c - src/view/common/view_generic_popup.c src/view/common/view_datetime.c src/view/picture/view_picture_slider_generic.c src/view/picture/view_picture_contrast.c diff --git a/include/view/common/view_generic_popup.h b/include/view/common/view_generic_popup.h deleted file mode 100644 index f08c9ec..0000000 --- a/include/view/common/view_generic_popup.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VIEW_GENERIC_POPUP_H_ -#define VIEW_GENERIC_POPUP_H_ - -#include "common/viewmgr.h" -#include "common/inputmgr.h" - -/*TODO: make use of it and add more types if necessary:*/ - -/** -* @brief Available types of generic popups. -*/ -typedef enum { - POPUP_TYPE_BUTTONS_LIST = 0 -} popup_type_t; - -/** -* @brief Attributes of a generic popup view. -*/ -typedef struct { - const char *popup_title; /**< popup's title */ - const char *popup_description; /**< popup's description */ - const char *popup_layout_group; /**< popup's layout view */ - input_handler *handler; /**< popup's input handler */ - int buttns_count; /**< popup's buttons count - valid for popups with buttons only */ - const char **btn_texts; /**< labels to be set on popup's buttons - valid for popup with buttons only */ - int items_count; - const char **item_texts; - int (*ui_id_on_show_focus)(void); /**< callback function to be invoked when popup is shown; - * returns ID of the widget that should receive focus first. - */ - void *generic_popup_data; /**< [out] popup view's data - to be used by inheriting class */ -} generic_popup_attr; - -/** -* @brief Get the pointer to the view_class object of generic popup view. -* -* @return The pointer to generic popup view_class object. -*/ -view_class *view_generic_popup_get_vclass(void); - -/** - * Sets the item selected when the given popup is displayed. - * @param data The popup's private data. - * @param item The item to select. - */ -void view_generic_popup_set_selected_on_show(void *data, int item); - -#endif /* VIEW_GENERIC_POPUP_H_ */ diff --git a/src/view/common/view_generic_popup.c b/src/view/common/view_generic_popup.c deleted file mode 100644 index 8950668..0000000 --- a/src/view/common/view_generic_popup.c +++ /dev/null @@ -1,280 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "view/common/view_generic_popup.h" - -#include -#include - -#include "app_debug.h" -#include "define.h" -#include "common/viewmgr.h" -#include "common/inputmgr.h" -#include "common/utils.h" -#include "view/common/view_generic_popup.h" - -#define GENERIC_POPUP_BTN_NAME_MAX 128 -#define BUTTON_BOX_PADDING 8 -#define FOCUS_DIR_TYPES 2 - -struct _priv { - Evas_Object *popup; - Evas_Object *box; - Eina_List *popup_buttons; - int (*ui_id_on_show_focus)(void); - int item_selected_on_show; -}; - -/* View class functions: */ -static Evas_Object *_create(Evas_Object *win, void *data); -static void _show(void *view_data); -static void _hide(void *view_data); -static void _destroy(void *view_data); - -static void _key_down_cb(int id, void *data, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev); - -static input_handler _input_handler = { - .key_down = _key_down_cb, -}; - -/* Helper: */ -static bool _fill_items(struct _priv *priv, Evas_Object *popup, int item_count, const char **item_text, input_handler *handler); - -static view_class _vclass = { - .view_id = NULL, - .create = _create, - .show = _show, - .hide = _hide, - .destroy = _destroy -}; - -view_class *view_generic_popup_get_vclass(void) -{ - return &_vclass; -} - -static Evas_Object *_create(Evas_Object *win, void *data) -{ - SETTING_TRACE_BEGIN; - struct _priv *priv = NULL; - generic_popup_attr *g_data = (generic_popup_attr *)data; - - if (!win || !g_data) { - _ERR("Invalid arguments"); - return NULL; - } - - priv = calloc(1, sizeof(struct _priv)); - if (!priv) { - _ERR("Calloc failed."); - return NULL; - } - - priv->popup = utils_add_layout(win, g_data->popup_layout_group, EINA_TRUE); - if (!priv->popup) { - _ERR("Add layout failed."); - evas_object_del(priv->popup); - free(priv); - return NULL; - } - - elm_object_part_text_set(priv->popup, PART_POPUP_TITLE, g_data->popup_title); - - if (g_data->items_count != 0) - _fill_items(priv, priv->popup, g_data->items_count, g_data->item_texts, g_data->handler); - - inputmgr_add_callback(priv->popup, 0, &_input_handler, NULL); - g_data->generic_popup_data = priv; - - SETTING_TRACE_END; - return priv->popup; -} - -static void _show(void *data) -{ - SETTING_TRACE_BEGIN; - struct _priv *priv = (struct _priv *)data; - Eina_List *children = elm_box_children_get(priv->box); - Evas_Object *first = eina_list_data_get(children); - Evas_Object *selected = eina_list_nth(children, priv->item_selected_on_show); - - if (!priv) { - _ERR("Invalid parameter."); - return; - } - - elm_object_focus_set(selected, EINA_TRUE); - elm_radio_value_set(first, priv->item_selected_on_show); - - evas_object_show(priv->popup); - SETTING_TRACE_END; -} - -static void _hide(void *data) -{ - SETTING_TRACE_BEGIN; - struct _priv *priv = (struct _priv *)data; - - if (!priv) { - _ERR("Invalid parameter."); - return; - } - - evas_object_hide(priv->popup); - SETTING_TRACE_END; -} - -static void _destroy(void *data) -{ - SETTING_TRACE_BEGIN; - struct _priv *priv = (struct _priv *)data; - - if (!priv) { - _ERR("Invalid parameter."); - return; - } - - evas_object_del(priv->popup); - free(priv); - SETTING_TRACE_END; -} - -static inline void _focus_link_set(Evas_Object *prev, Evas_Object *next, - Elm_Focus_Direction *next_dirs, Elm_Focus_Direction *prev_dirs, - int count) -{ - int i; - for (i = 0; i < count; ++i) { - elm_object_focus_next_object_set(prev, next, next_dirs[i]); - - if (prev_dirs) - elm_object_focus_next_object_set(next, prev, prev_dirs[i]); - } -} - -static void _focus_chain_set(Evas_Object *box, bool is_last) -{ - Elm_Focus_Direction next_types[FOCUS_DIR_TYPES] = {ELM_FOCUS_DOWN, ELM_FOCUS_NEXT}; - Elm_Focus_Direction prev_types[FOCUS_DIR_TYPES] = {ELM_FOCUS_UP, ELM_FOCUS_PREVIOUS}; - Elm_Focus_Direction left_right[FOCUS_DIR_TYPES] = {ELM_FOCUS_LEFT, ELM_FOCUS_RIGHT}; - Eina_List *children = elm_box_children_get(box); - Eina_List *last = eina_list_last(children); - Eina_List *prev = eina_list_prev(last); - Evas_Object *obj_last = eina_list_data_get(last); - Evas_Object *obj_prev = eina_list_data_get(prev); - - _focus_link_set(obj_last, obj_last, left_right, NULL, FOCUS_DIR_TYPES); - - if (!obj_prev) { - _focus_link_set(obj_last, obj_last, prev_types, NULL, FOCUS_DIR_TYPES); - return; - } - - _focus_link_set(obj_last, obj_prev, prev_types, next_types, FOCUS_DIR_TYPES); - - if (is_last) - _focus_link_set(obj_last, obj_last, next_types, NULL, FOCUS_DIR_TYPES); -} - -static void _focus_chain_debug(Evas_Object *box) -{ - int i = 0; - Elm_Focus_Direction dir = 0; - Eina_List *children = elm_box_children_get(box); - int count = eina_list_count(children); - Evas_Object *item; - Evas_Object *focus_to; - const char *text; - - char *dir_names[] = { - "ELM_FOCUS_PREVIOUS", - "ELM_FOCUS_NEXT", - "ELM_FOCUS_UP", - "ELM_FOCUS_DOWN", - "ELM_FOCUS_RIGHT", - "ELM_FOCUS_LEFT", - }; - - for (i = 0; i < count; ++i) { - item = eina_list_nth(children, i); - - text = elm_object_text_get(item); - dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] ITEM: %s", __FILE__, __LINE__, text); - - for (dir = 0; dir < sizeof(dir_names) / sizeof(dir_names[0]); ++dir) { - - focus_to = elm_object_focus_next_object_get(item, dir); - text = elm_object_text_get(focus_to); - dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] >>>>>>>>>>> %s: %s", __FILE__, __LINE__, dir_names[dir], text); - } - } -} - -static bool _fill_items(struct _priv *priv, Evas_Object *popup, int item_count, const char **item_text, input_handler *handler) -{ - Evas_Object *radio = NULL; - Evas_Object *group = NULL; - priv->box = elm_box_add(priv->popup); - elm_box_horizontal_set(priv->box, EINA_FALSE); - - evas_object_size_hint_weight_set(priv->box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(priv->box, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_size_hint_min_set(priv->box, 300, 300); - - int i; - for (i = 0; i < item_count; i++) { - radio = utils_add_radio(priv->box, NULL, "style.popup.list", item_text[i % item_count]); - elm_radio_state_value_set(radio, i); - - if (i == 0) - group = radio; - else - elm_radio_group_add(radio, group); - - evas_object_size_hint_min_set(radio, 300, 50); - evas_object_size_hint_weight_set(radio, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(radio, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_show(radio); - elm_box_pack_end(priv->box, radio); - _focus_chain_set(priv->box, i == item_count - 1); - - inputmgr_add_callback(radio, i, handler, NULL); - } - - elm_object_part_content_set(priv->popup, PART_POPUP_LIST, priv->box); - - _focus_chain_debug(priv->box); - return true; -} - -static void _key_down_cb(int id, void *data, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) -{ - if (!obj || !ev) { - _ERR("Invalid argument."); - return; - } - - if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_WAY) || - !strcmp(ev->keyname, KEY_ESC) || !strcmp(ev->keyname, KEY_ESC_WAY)) { - viewmgr_pop_view(); - } -} - -void view_generic_popup_set_selected_on_show(void *data, int item) -{ - struct _priv *priv = (struct _priv *)data; - priv->item_selected_on_show = item; -} diff --git a/src/view/system/view_clock.c b/src/view/system/view_clock.c index e074271..344cb65 100755 --- a/src/view/system/view_clock.c +++ b/src/view/system/view_clock.c @@ -33,8 +33,8 @@ #define PADDING_VKEYBOARD 30 enum setup_type { - TYPE_MANUAL = 0, - TYPE_AUTO, + TYPE_AUTO = 0, + TYPE_MANUAL, TYPE_MAX }; diff --git a/src/view/system/view_clock_mode.c b/src/view/system/view_clock_mode.c index 259d8a1..70f296d 100755 --- a/src/view/system/view_clock_mode.c +++ b/src/view/system/view_clock_mode.c @@ -24,94 +24,104 @@ #include "define.h" #include "common/utils.h" #include "view/system/view_clock.h" -#include "view/common/view_generic_popup.h" #include "data/system/settings_clock.h" #include "app_string.h" -#define BUTTON_RETURN 36 - enum setup_type { - TYPE_MANUAL = 0, - TYPE_AUTO, + TYPE_AUTO = 0, + TYPE_MANUAL, TYPE_MAX }; -static const char *str_setup_type_opt[] = { - STR_MANUAL, - STR_AUTO +static char *str_setup_type_opt[] = { + STR_AUTO, + STR_MANUAL }; -typedef struct { - Evas_Object *win; - Evas_Object *ly; - Evas_Object *conformant; - - enum setup_type cur_type; - bool input_panel_show; - Evas_Object *focused_entry; - -} clock_mode_view_priv_data; +struct _priv { + Evas_Object *popup; + Evas_Object *base; + Evas_Object *popup_btn[TYPE_MAX]; +}; -static void _popup_item_selected_cb(int id, void *data, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev); +static void _key_down_cb(int id, void *data, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev); static void _mouse_down_cb(int id, void *data, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Down *ev); -static input_handler _input_handler = { - .key_down = _popup_item_selected_cb, +static input_handler handler = { + .key_down = _key_down_cb, .mouse_down = _mouse_down_cb }; static Evas_Object *_create(Evas_Object *win, void *data) { SETTING_TRACE_BEGIN; - view_class *vc = view_generic_popup_get_vclass(); - generic_popup_attr *g_data = NULL; + struct _priv *priv = NULL; + Evas_Object *ly = NULL; if (!win) { _ERR("Get window object failed."); return NULL; } - g_data = calloc(1, sizeof(generic_popup_attr)); - if (!g_data) { + priv = calloc(1, sizeof(struct _priv)); + if (!priv) { _ERR("Calloc failed."); return NULL; } - g_data->popup_title = "Clock"; - g_data->popup_description = NULL; - g_data->popup_layout_group = GRP_VIEW_POPUP_LIST; - g_data->handler = &_input_handler; - g_data->buttns_count = 0; - g_data->btn_texts = NULL; - g_data->items_count = sizeof(str_setup_type_opt) / sizeof(str_setup_type_opt[0]); - g_data->item_texts = calloc(g_data->items_count, sizeof(char *)); - g_data->ui_id_on_show_focus = NULL; - g_data->generic_popup_data = NULL; - - int i; - for (i = 0; i < sizeof(str_setup_type_opt) / sizeof(str_setup_type_opt[0]); ++i) - g_data->item_texts[i] = str_setup_type_opt[i]; - - if (!viewmgr_set_view_data(VIEW_CLOCK_MODE, g_data)) { - free(g_data->item_texts); - free(g_data); + priv->base = utils_add_popup(win, STYLE_POPUP, STR_CLOCK, NULL); + if (!priv->base) { + _ERR("Add popup failed"); + free(priv); + return NULL; + } + + ly = utils_add_layout(priv->base, GRP_VIEW_POPUP_2BTNS, EINA_FALSE); + if (!ly) { + _ERR("Add layout failed."); + evas_object_del(priv->base); + free(priv); + return NULL; + } + + priv->popup_btn[TYPE_AUTO] = utils_add_button(ly, PART_POPUP_BUTTON0, NULL, str_setup_type_opt[TYPE_AUTO]); + priv->popup_btn[TYPE_MANUAL] = utils_add_button(ly, PART_POPUP_BUTTON1, NULL, str_setup_type_opt[TYPE_MANUAL]); + if(!priv->popup_btn[TYPE_AUTO] || !priv->popup_btn[TYPE_MANUAL]) { + _ERR("Add button failed."); + evas_object_del(priv->base); + free(priv); + return NULL; + } + + inputmgr_add_callback(priv->popup_btn[TYPE_AUTO], TYPE_AUTO, &handler, priv); + inputmgr_add_callback(priv->popup_btn[TYPE_MANUAL], TYPE_MANUAL, &handler, priv); + + elm_object_part_content_set(priv->base, "elm.swallow.content", ly); + + if (!viewmgr_set_view_data(VIEW_CLOCK_MODE, priv)) { _ERR("Set view data failed."); + evas_object_del(priv->base); + free(priv); return NULL; } - SETTING_TRACE_END; - return vc->create(win, g_data); + return priv->base; } -static void _popup_item_selected_cb(int id, void *data, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) +static void _key_down_cb(int id, void *data, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) { dlog_print(DLOG_INFO, LOG_TAG, "[%s:%d] BUTTON = %d", __FILE__, __LINE__, ev->keycode); - if (ev->keycode != BUTTON_RETURN) + if(!data) return; - viewmgr_pop_view(); - viewmgr_update_view(VIEW_CLOCK, CLOCK_DISPLAY_MODE_UPDATE, (void *)(long)id); - viewmgr_show_view(VIEW_CLOCK); + if(!strcmp(ev->keyname, KEY_ENTER)) { + viewmgr_pop_view(); + viewmgr_update_view(VIEW_CLOCK, CLOCK_DISPLAY_MODE_UPDATE, (void *)(long)id); + viewmgr_show_view(VIEW_CLOCK); + } + else if(!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_WAY)) { + viewmgr_pop_view(); + } } static void _mouse_down_cb(int id, void *data, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Down *ev) @@ -126,39 +136,50 @@ static void _mouse_down_cb(int id, void *data, Evas *e, Evas_Object *obj, Evas_E static void _show(void *data) { SETTING_TRACE_BEGIN - bool automatic; - generic_popup_attr *g_data = (generic_popup_attr *)data; - view_class *vc = view_generic_popup_get_vclass(); + bool automatic = false; + struct _priv *priv = (struct _priv *)data; + if (!priv) { + _ERR("Invalid parameter."); + return; + } + + evas_object_show(priv->base); settings_clock_is_time_automatic(&automatic); + if (automatic) - view_generic_popup_set_selected_on_show(g_data->generic_popup_data, TYPE_AUTO); + elm_object_focus_set(priv->popup_btn[TYPE_AUTO], EINA_TRUE); else - view_generic_popup_set_selected_on_show(g_data->generic_popup_data, TYPE_MANUAL); + elm_object_focus_set(priv->popup_btn[TYPE_MANUAL], EINA_TRUE); - vc->show(g_data->generic_popup_data); SETTING_TRACE_END } static void _hide(void *data) { SETTING_TRACE_BEGIN; - view_class *vc = view_generic_popup_get_vclass(); - generic_popup_attr *g_data = (generic_popup_attr *)data; - vc->hide(g_data->generic_popup_data); + struct _priv *priv = (struct _priv *)data; + if (!priv) { + _ERR("Invalid parameter."); + return; + } + + evas_object_hide(priv->base); SETTING_TRACE_END; } static void _destroy(void *data) { SETTING_TRACE_BEGIN; - view_class *vc = view_generic_popup_get_vclass(); - generic_popup_attr *g_data = (generic_popup_attr *)data; + struct _priv *priv = (struct _priv *)data; + if (!priv) { + _ERR("Invalid parameter."); + return; + } - vc->destroy(g_data->generic_popup_data); - free(g_data->item_texts); - free(g_data); + evas_object_del(priv->base); + free(priv); SETTING_TRACE_END; }