From: Jihoon Kim Date: Tue, 8 Nov 2016 23:43:47 +0000 (+0900) Subject: Refactoring code about option window X-Git-Tag: accepted/tizen/3.0/common/20161114.081731~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F65%2F96365%2F4;p=platform%2Fcore%2Fuifw%2Fise-default.git Refactoring code about option window Change-Id: I93608e038b48759645bb98a380f9b3ba51a18751 Signed-off-by: Jihoon Kim --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 35b6f89..25e3cf6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,7 @@ SET(ISE_SRCS src/ise-emoticon-mode.cpp src/cbhm.cpp src/modeindicator.cpp + src/eflutil.cpp ) SET(ISE_PACKAGE ${PROJECT_NAME}) diff --git a/src/eflutil.cpp b/src/eflutil.cpp new file mode 100644 index 0000000..69edf6f --- /dev/null +++ b/src/eflutil.cpp @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2012 - 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 + +Evas_Object * create_genlist(Evas_Object *parent) +{ + Evas_Object *genlist = elm_genlist_add(parent); + evas_object_paragraph_direction_set(genlist, EVAS_BIDI_DIRECTION_NEUTRAL); + elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS); + evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_genlist_tree_effect_enabled_set(genlist, EINA_FALSE); + + return genlist; +} + +Evas_Object * naviframe_item_push(Evas_Object *naviframe, const char *title, Evas_Object *content, Elm_Naviframe_Item_Pop_Cb pop_cb, void *pop_cb_data, Evas_Smart_Cb back_cb, void *back_cb_data) +{ + Evas_Object *back_button = elm_button_add(naviframe); + elm_object_style_set(back_button, "naviframe/back_btn/default"); + if (back_cb) + evas_object_smart_callback_add(back_button, "clicked", back_cb, back_cb_data); + + Elm_Object_Item *navi_it = elm_naviframe_item_push(naviframe, title, back_button, NULL, content, NULL); +#ifdef _WEARABLE + elm_naviframe_item_title_enabled_set(navi_it, EINA_FALSE, EINA_FALSE); +#endif + if (pop_cb) + elm_naviframe_item_pop_cb_set(navi_it, pop_cb, pop_cb_data); + + return back_button; +} + +static void +gl_realized_cb(void *data, Evas_Object *obj, void *event_info) +{ + Elm_Object_Item *it = (Elm_Object_Item *)event_info; + if (it == elm_genlist_first_item_get(obj)) { + elm_object_item_signal_emit(it, "elm,action,title,slide,start", "elm"); + } +} + +static char *_title_text_get(void *data, Evas_Object *obj, const char *part) +{ + const char *title = (const char *)data; + if (!title) return NULL; + + if (!strcmp(part, "elm.text")) { + return strdup(title); + } + + return NULL; +} + +void add_scrollable_title_area(Evas_Object *genlist, const char *title, Eina_Bool autoscroll) +{ + /* Add scrollable title area in wearable profile */ + Elm_Object_Item *it; + Elm_Genlist_Item_Class *ttc = elm_genlist_item_class_new(); + ttc->item_style = "title"; + ttc->func.text_get = title ? _title_text_get : NULL; + it = elm_genlist_item_append(genlist, ttc, title, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); + elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_NONE); + elm_genlist_item_class_free(ttc); + + if (autoscroll) + evas_object_smart_callback_add(genlist, "realized", gl_realized_cb, NULL); +} + diff --git a/src/include/eflutil.h b/src/include/eflutil.h new file mode 100644 index 0000000..7a585a0 --- /dev/null +++ b/src/include/eflutil.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2012 - 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 __EFL_UTIL_H__ +#define __EFL_UTIL_H__ + +#include + +Evas_Object * create_genlist(Evas_Object *parent); +Evas_Object * naviframe_item_push(Evas_Object *naviframe, const char *title, Evas_Object *content, Elm_Naviframe_Item_Pop_Cb pop_cb, void *pop_cb_data, Evas_Smart_Cb back_cb, void *back_cb_data); +void add_scrollable_title_area(Evas_Object *genlist, const char *title, Eina_Bool autoscroll); + +#endif //__EFL_UTIL_H__ diff --git a/src/ise-stt-option.cpp b/src/ise-stt-option.cpp index 1287ec9..d689e2a 100644 --- a/src/ise-stt-option.cpp +++ b/src/ise-stt-option.cpp @@ -28,6 +28,7 @@ #include "ise.h" #include "ise-stt-option.h" #include "ise-stt-mode.h" +#include "eflutil.h" #define item_append(obj, style, index, cb, udata) \ elm_genlist_item_append(obj, &(style), (void *)index, NULL, ELM_GENLIST_ITEM_NONE, cb, udata) @@ -36,23 +37,17 @@ sclboolean g_setting_window_open_status = FALSE; extern stt_h g_stt; static Evas_Object *radio_gp = NULL; -Evas_Object *g_setting_naviframe = NULL; -Evas_Object *g_setting_window = NULL; +static Evas_Object *g_setting_naviframe = NULL; +static Evas_Object *g_setting_window = NULL; -#ifdef _WEARABLE -static Elm_Genlist_Item_Class itc_title; -#endif static Elm_Genlist_Item_Class itc_1text; static Elm_Genlist_Item_Class itc_2text; -const char* get_lang_label(char lang[]); +static const char* get_lang_label(char lang[]); static int get_language_value(); static void set_language_value(int type); -#ifdef _WEARABLE -static char *__get_genlist_title_label(void *data, Evas_Object *obj, const char *part); -#endif -char *__get_genlist_item_label(void *data, Evas_Object *obj, const char *part); +static char *__get_genlist_item_label(void *data, Evas_Object *obj, const char *part); static Evas_Object *__get_genlist_item_content(void *data, Evas_Object *obj, const char *part); static void language_set_genlist_radio_cb(void *data, Evas_Object *obj, void *event_info); static Eina_Bool close_setting_window_idler_cb(void *data); @@ -88,7 +83,7 @@ typedef enum { STT_VOICE_N66_KO_KR } STT_VOICE_LANGUAGE_N66_I; -const char* get_lang_label(char lang[]) +static const char* get_lang_label(char lang[]) { const char *str = NULL; @@ -237,14 +232,7 @@ void get_stt_default_language(VoiceData *my_voicedata) LOGD("stt language (%s)", my_voicedata->kbd_lang); } -#ifdef _WEARABLE -static char *__get_genlist_title_label(void *data, Evas_Object *obj, const char *part) -{ - return strdup(_("IDS_VOICE_OPT_LANGUAGE_ABB")); -} -#endif - -char *__get_genlist_item_label(void *data, Evas_Object *obj, const char *part) +static char *__get_genlist_item_label(void *data, Evas_Object *obj, const char *part) { char text[128] = {0, }; @@ -331,7 +319,7 @@ static void language_set_genlist_radio_cb(void *data, Evas_Object *obj, void *ev int index = 0; - Elm_Object_Item * item = (Elm_Object_Item *) event_info; + Elm_Object_Item * item = (Elm_Object_Item *)event_info; if (item) { elm_genlist_item_selected_set(item, 0); index = (intptr_t)elm_object_item_data_get(item); @@ -382,12 +370,9 @@ static Evas_Object *create_language_list(Evas_Object *parent) { if (!parent) return NULL; - Evas_Object *genlist = elm_genlist_add(parent); + Evas_Object *genlist = create_genlist(parent); if (!genlist) return NULL; - elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS); - elm_genlist_homogeneous_set(genlist, EINA_TRUE); - evas_object_paragraph_direction_set(genlist, EVAS_BIDI_DIRECTION_NEUTRAL); #ifdef _CIRCLE Evas_Object *circle_language_genlist = eext_circle_object_genlist_add(genlist, NULL); eext_circle_object_genlist_scroller_policy_set(circle_language_genlist, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO); @@ -401,21 +386,13 @@ static Evas_Object *create_language_list(Evas_Object *parent) int lang_val = 0; Elm_Object_Item * item = NULL; - evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL); - radio_gp = elm_radio_add(genlist); elm_radio_state_value_set(radio_gp, -1); lang_val = get_language_value(); #ifdef _WEARABLE - //Title - itc_title.item_style = "title"; - itc_title.func.text_get = __get_genlist_title_label; - itc_title.func.content_get = NULL; - - elm_genlist_item_append(genlist, &itc_title, (void *)-1, NULL, ELM_GENLIST_ITEM_GROUP, NULL, genlist); + add_scrollable_title_area(genlist, _("IDS_VOICE_OPT_LANGUAGE_ABB"), EINA_FALSE); #endif // 2 line text @@ -427,7 +404,6 @@ static Evas_Object *create_language_list(Evas_Object *parent) itc_2text.func.text_get = __get_genlist_item_label; itc_2text.func.content_get = __get_genlist_item_content; - item = item_append(genlist, itc_2text, (void *)0, language_set_genlist_radio_cb, genlist); // AUTO if (lang_val == i) { @@ -435,7 +411,7 @@ static Evas_Object *create_language_list(Evas_Object *parent) elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE); } - if ( item == NULL ) { + if (item == NULL) { LOGD("elm_genlist_item_append was failed"); } @@ -468,15 +444,10 @@ static Evas_Object *create_language_list(Evas_Object *parent) break; } } - Elm_Object_Item *dummy; - Elm_Genlist_Item_Class *itc_dummy = elm_genlist_item_class_new(); - if (itc_dummy) { - itc_dummy->item_style = "title"; - itc_dummy->func.text_get = NULL; - itc_dummy->func.content_get = NULL; - } - dummy = elm_genlist_item_append(genlist, itc_dummy, NULL, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); - elm_genlist_item_select_mode_set(dummy, ELM_OBJECT_SELECT_MODE_NONE); + +#ifdef _CIRCLE + add_scrollable_title_area(genlist, NULL, EINA_FALSE); +#endif LOGD("before elm_radio_value_set > lang_val = %d", lang_val); radio_gp = elm_radio_add(genlist); @@ -538,20 +509,11 @@ void create_setting_window() genlist = create_language_list(naviframe); - /* Add a back button to naviframe */ - Evas_Object *back_button = NULL; char *title = NULL; - const char *item_style = NULL; - #ifdef _MOBILE - back_button = elm_button_add(naviframe); - elm_object_style_set(back_button, "naviframe/back_btn/default"); - evas_object_smart_callback_add(back_button, "clicked", _naviframe_back_cb, naviframe); title = _("IDS_VOICE_OPT_LANGUAGE_ABB"); -#else - item_style = "empty"; #endif - elm_naviframe_item_push(naviframe, title, back_button, NULL, genlist, item_style); + naviframe_item_push(naviframe, title, genlist, NULL, NULL, _naviframe_back_cb, naviframe); elm_object_content_set(conformant, naviframe); diff --git a/src/option.cpp b/src/option.cpp index 13ec31e..bd3406e 100644 --- a/src/option.cpp +++ b/src/option.cpp @@ -26,6 +26,7 @@ #include "utils.h" #include "option.h" #include "languages.h" +#include "eflutil.h" #undef LOG_TAG #define LOG_TAG "ISE_DEFAULT" @@ -298,42 +299,6 @@ static char *_main_gl_text_get(void *data, Evas_Object *obj, const char *part) return NULL; } -#ifdef _WEARABLE -static char *_title_text_get(void *data, Evas_Object *obj, const char *part) -{ - const char *title = (const char *)data; - if (!title) return NULL; - - if (!strcmp(part, "elm.text")) { - return strdup(title); - } - - return NULL; -} - -static void -gl_realized_cb(void *data, Evas_Object *obj, void *event_info) -{ - Elm_Object_Item *it = (Elm_Object_Item *)event_info; - if (it == elm_genlist_first_item_get(obj)) { - elm_object_item_signal_emit(it, "elm,action,title,slide,start", "elm"); - } -} - -static void add_scrollable_title_area(Evas_Object *genlist, const char *title, Eina_Bool autoscroll) -{ - /* Add scrollable title area in wearable profile */ - Elm_Genlist_Item_Class *ttc = elm_genlist_item_class_new(); - ttc->item_style = "title"; - ttc->func.text_get = _title_text_get; - elm_genlist_item_append(genlist, ttc, title, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL); - elm_genlist_item_class_free(ttc); - - if (autoscroll) - evas_object_smart_callback_add(genlist, "realized", gl_realized_cb, NULL); -} -#endif - static Eina_Bool _update_check_button_state(Elm_Object_Item *item, Evas_Object *obj) { Eina_Bool state = EINA_FALSE; @@ -836,8 +801,7 @@ Evas_Object* create_option_main_view(Evas_Object *parent, Evas_Object *naviframe if (CHECK_ARRAY_INDEX(type, OPTION_WINDOW_TYPE_MAX)) { create_genlist_item_classes(type); - genlist = elm_genlist_add(naviframe); - evas_object_paragraph_direction_set(genlist, EVAS_BIDI_DIRECTION_NEUTRAL); + genlist = create_genlist(naviframe); option_elements[type].genlist = genlist; #ifdef _CIRCLE @@ -849,11 +813,6 @@ Evas_Object* create_option_main_view(Evas_Object *parent, Evas_Object *naviframe option_elements[type].circle_genlist = circle_genlist; #endif - elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS); - evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_genlist_tree_effect_enabled_set(genlist, EINA_FALSE); - #ifdef _WEARABLE add_scrollable_title_area(genlist, OPTIONS, EINA_TRUE); #endif @@ -943,10 +902,7 @@ Evas_Object* create_option_main_view(Evas_Object *parent, Evas_Object *naviframe static Evas_Object* create_option_language_view(Evas_Object *naviframe) { - Evas_Object *genlist = elm_genlist_add(naviframe); - elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS); - elm_genlist_homogeneous_set(genlist, EINA_TRUE); - evas_object_paragraph_direction_set(genlist, EVAS_BIDI_DIRECTION_NEUTRAL); + Evas_Object *genlist = create_genlist(naviframe); SCLOptionWindowType type = find_option_window_type(naviframe); @@ -993,14 +949,7 @@ static Evas_Object* create_option_language_view(Evas_Object *naviframe) evas_object_show(genlist); - Evas_Object *back_button = elm_button_add(naviframe); - elm_object_style_set(back_button, "naviframe/back_btn/default"); - evas_object_smart_callback_add(back_button, "clicked", language_selection_finished_cb, naviframe); - Elm_Object_Item *navi_it = elm_naviframe_item_push(naviframe, LANGUAGE, back_button, NULL, genlist, NULL); -#ifdef _WEARABLE - elm_naviframe_item_title_enabled_set(navi_it, EINA_FALSE, EINA_FALSE); -#endif - elm_naviframe_item_pop_cb_set(navi_it, _pop_cb, naviframe); + naviframe_item_push(naviframe, LANGUAGE, genlist, _pop_cb, naviframe, language_selection_finished_cb, naviframe); return genlist; } @@ -1008,11 +957,7 @@ static Evas_Object* create_option_language_view(Evas_Object *naviframe) #ifdef _WEARABLE static Evas_Object* create_smart_typing_view(Evas_Object *naviframe) { - Evas_Object *genlist = elm_genlist_add(naviframe); - elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS); - elm_genlist_homogeneous_set(genlist, EINA_TRUE); - evas_object_paragraph_direction_set(genlist, EVAS_BIDI_DIRECTION_NEUTRAL); - + Evas_Object *genlist = create_genlist(naviframe); SCLOptionWindowType type = find_option_window_type(naviframe); if (CHECK_ARRAY_INDEX(type, OPTION_WINDOW_TYPE_MAX)) { @@ -1042,24 +987,14 @@ static Evas_Object* create_smart_typing_view(Evas_Object *naviframe) evas_object_show(genlist); - Evas_Object *back_button = elm_button_add(naviframe); - elm_object_style_set(back_button, "naviframe/back_btn/default"); - Elm_Object_Item *navi_it = elm_naviframe_item_push(naviframe, LANGUAGE, back_button, NULL, genlist, NULL); -#ifdef _WEARABLE - elm_naviframe_item_title_enabled_set(navi_it, EINA_FALSE, EINA_FALSE); -#endif - elm_naviframe_item_pop_cb_set(navi_it, _pop_cb, naviframe); + naviframe_item_push(naviframe, LANGUAGE, genlist, _pop_cb, naviframe, NULL, NULL); return genlist; } static Evas_Object* create_feedback_view(Evas_Object *naviframe) { - Evas_Object *genlist = elm_genlist_add(naviframe); - elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS); - elm_genlist_homogeneous_set(genlist, EINA_TRUE); - evas_object_paragraph_direction_set(genlist, EVAS_BIDI_DIRECTION_NEUTRAL); - + Evas_Object *genlist = create_genlist(naviframe); SCLOptionWindowType type = find_option_window_type(naviframe); if (CHECK_ARRAY_INDEX(type, OPTION_WINDOW_TYPE_MAX)) { @@ -1089,13 +1024,7 @@ static Evas_Object* create_feedback_view(Evas_Object *naviframe) evas_object_show(genlist); - Evas_Object *back_button = elm_button_add(naviframe); - elm_object_style_set(back_button, "naviframe/back_btn/default"); - Elm_Object_Item *navi_it = elm_naviframe_item_push(naviframe, LANGUAGE, back_button, NULL, genlist, NULL); -#ifdef _WEARABLE - elm_naviframe_item_title_enabled_set(navi_it, EINA_FALSE, EINA_FALSE); -#endif - elm_naviframe_item_pop_cb_set(navi_it, _pop_cb, naviframe); + naviframe_item_push(naviframe, LANGUAGE, genlist, _pop_cb, naviframe, NULL, NULL); return genlist; } @@ -1295,19 +1224,7 @@ option_window_created(Evas_Object *window, SCLOptionWindowType type) evas_object_size_hint_align_set(naviframe, EVAS_HINT_FILL, EVAS_HINT_FILL); Evas_Object *list = create_option_main_view(conformant, naviframe, type); - - /* Add a back button to naviframe */ - Evas_Object *back_button = elm_button_add(naviframe); - option_elements[type].back_button = back_button; - - elm_object_style_set(back_button, "naviframe/back_btn/default"); - evas_object_smart_callback_add(back_button, "clicked", navi_back_cb, NULL); -#ifdef _WEARABLE - Elm_Object_Item *navi_it = elm_naviframe_item_push(naviframe, OPTIONS, back_button, NULL, list, NULL); - elm_naviframe_item_title_enabled_set(navi_it, EINA_FALSE, EINA_FALSE); -#else - elm_naviframe_item_push(naviframe, OPTIONS, back_button, NULL, list, NULL); -#endif + option_elements[type].back_button = naviframe_item_push(naviframe, OPTIONS, list, NULL, NULL, navi_back_cb, NULL); elm_object_content_set(conformant, naviframe);