2 * Copyright (c) 2016 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.
24 #include <vconf-keys.h>
26 #include <system_info.h>
28 #include "w-input-selector.h"
29 #include "w-input-template.h"
30 #include "w-input-keyboard.h"
31 #include "w-input-stt-ise.h"
32 #include "w-input-emoticon.h"
33 #include "w-input-smartreply.h"
40 App_Data* app_data = NULL;
42 InputKeyboardData g_input_keyboard_data;
43 InputTypeData g_input_type_data;
45 static Elm_Object_Item *it_empty;
46 static Elm_Object_Item *it_title;
48 static unsigned int g_smartreply_item_size = 0; /* Current Smartreply item size */
49 static unsigned int g_template_item_size = 0; /* Current Template item size */
51 Evas_Coord last_step; // 0 ~ 9 for gesture, 10~11 for rotary
53 tizen_profile_t _get_tizen_profile()
55 static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
56 if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
60 system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
65 profile = TIZEN_PROFILE_MOBILE;
69 profile = TIZEN_PROFILE_WEARABLE;
73 profile = TIZEN_PROFILE_TV;
77 profile = TIZEN_PROFILE_IVI;
79 default: // common or unknown ==> ALL ARE COMMON.
80 profile = TIZEN_PROFILE_COMMON;
87 void _init_app_data(App_Data* app_data);
88 static void _app_language_changed(app_event_info_h event_info, void *user_data);
90 Evas_Object* _create_genlist(Evas_Object* parent);
91 void _create_genlist_items(void* user_data);
92 void _create_header_items(void *user_data);
93 void _update_genlist_items(void *user_data);
94 unsigned int _update_smartreply_items(void *user_data);
95 unsigned int _update_template_items(void *user_data);
96 static void _popup_close_cb(void *data, Evas_Object *obj, void *event_info);
97 static void _popup_back_cb(void *data, Evas_Object *obj, void *event_info);
98 static void input_type_deinit(void);
100 bool __compare_string(const char * src, const char * dst);
102 void _init_app_data(App_Data* app_data)
104 app_data->win_main = NULL;
105 app_data->layout_main = NULL;
106 app_data->conform = NULL;
107 app_data->naviframe = NULL;
108 app_data->genlist = NULL;
110 app_data->res_path = NULL;
113 Evas_Object* load_edj(Evas_Object* parent, const char* file, const char* group)
116 Evas_Object* content;
119 window = elm_layout_add(parent);
121 ret = elm_layout_file_set(window, file, group);
123 evas_object_del(window);
127 content = elm_layout_add(parent);
128 elm_layout_theme_set(content, "layout", "application", "default");
129 elm_object_part_content_set(window, "elm.swallow.content", content);
131 evas_object_size_hint_weight_set(window, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
136 void init_customizing_theme(void)
138 string stt_edj_path = get_resource_path();
139 string app_edj_path = get_resource_path();
142 stt_edj_path = stt_edj_path + STT_EDJ_FILE_WEARABLE;
143 app_edj_path = app_edj_path + APP_EDJ_FILE_WEARABLE;
145 stt_edj_path = stt_edj_path + STT_EDJ_FILE_TV;
146 app_edj_path = app_edj_path + APP_EDJ_FILE_TV;
148 stt_edj_path = stt_edj_path + STT_EDJ_FILE_MOBILE;
149 app_edj_path = app_edj_path + APP_EDJ_FILE_MOBILE;
152 elm_theme_extension_add(NULL, stt_edj_path.c_str());
153 elm_theme_extension_add(NULL, app_edj_path.c_str());
157 static Eina_Bool back_cb(void *data, Elm_Object_Item *it)
159 reply_to_sender_by_callback_for_back();
164 static void _stt_clicked_cb(void *data, Evas_Object * obj, void *event_info)
166 App_Data* ad = (App_Data*)data;
168 PRINTFUNC(DLOG_DEBUG, "");
173 ise_show_stt_popup(ad);
176 static void _input_smartreply_notify_cb(void *user_data)
178 ecore_main_loop_iterate();
179 _update_genlist_items((void *)app_data);
182 static void _input_template_notify_cb(void *user_data)
184 _update_genlist_items((void *)app_data);
187 static void _emoticon_clicked_cb(void *data, Evas_Object * obj, void *event_info)
189 App_Data* ad = (App_Data*)data;
191 PRINTFUNC(DLOG_DEBUG, "");
196 ise_show_emoticon_list(ad);
199 static void _keyboard_clicked_cb(void *data, Evas_Object * obj, void *event_info)
201 App_Data* ad = (App_Data *)data;
203 PRINTFUNC(DLOG_DEBUG, "");
208 input_keyboard_launch(ad->win_main, data);
211 static void __ise_smartreply_gl_sel(void *data, Evas_Object *obj, void *event_info)
213 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
216 elm_genlist_item_selected_set(item, EINA_FALSE);
218 int index = (intptr_t) elm_object_item_data_get(item);
221 char *reply = input_smartreply_get_nth_item(index, &type);
223 input_smartreply_send_feedback(reply);
224 reply_to_sender_by_callback(reply, "smartreply", NULL, NULL);
231 static void __ise_template_gl_sel(void *data, Evas_Object *obj, void *event_info)
233 Elm_Object_Item *item = (Elm_Object_Item *) event_info;
237 elm_genlist_item_selected_set(item, EINA_FALSE);
239 index = (uintptr_t) elm_object_item_data_get(item);
240 const std::vector<TemplateData> template_list = input_template_get_list();
242 if (index < (int)template_list.size()) {
243 reply_to_sender_by_callback(gettext(template_list[index].text.c_str()), "template", NULL, NULL);
249 static char * __ise_template_gl_text_get(void *data, Evas_Object *obj, const char *part)
251 if (!strcmp(part, "elm.text")) {
252 unsigned int index = (uintptr_t)data;
253 const std::vector<TemplateData> template_list = input_template_get_list();
255 if (index < template_list.size()) {
256 if (template_list[index].use_gettext) {
257 return strdup(gettext(template_list[index].text.c_str()));
259 Eina_Strbuf *buf = NULL;
260 const char *str = NULL;
263 buf = eina_strbuf_new();
265 eina_strbuf_append(buf, template_list[index].text.c_str());
266 eina_strbuf_replace_all(buf, "\n", "");
267 eina_strbuf_replace_all(buf, "\r", "");
269 str = eina_strbuf_string_get(buf);
272 markup = elm_entry_utf8_to_markup(str);
274 eina_strbuf_free(buf);
283 static Evas_Object * __ise_gl_2button_content_get(void *data, Evas_Object *obj, const char *part)
285 char *first_input_type = *(g_input_type_data.input_type_array + 0);
286 char *second_input_type = *(g_input_type_data.input_type_array + 1);
288 if (!strcmp(part, "elm.icon.1") || (!strcmp(part, "elm.icon.2"))) {
289 Evas_Object* btn = elm_button_add(obj);
290 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
291 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
293 Evas_Object* ic = elm_image_add(btn);
294 elm_image_resizable_set(ic, EINA_TRUE, EINA_TRUE);
295 string path = get_resource_path();
297 path = path + "wearable/";
301 path = path + "mobile/";
303 if (!strcmp(part, "elm.icon.1")) {
305 if (!strcmp(first_input_type, "input_voice")) {
306 elm_object_style_set(btn, "ime_button_stt");
307 path_ic = path + "images/w_mode_stt_ic.png";
308 } else if (!strcmp(first_input_type, "input_emoticon")) {
309 elm_object_style_set(btn, "ime_button_emoticon");
310 path_ic = path + "images/Delta_w_mode_emoticon_ic.png";
311 } else if (!strcmp(first_input_type, "input_keyboard")) {
312 elm_object_style_set(btn, "ime_button_keyboard");
313 path_ic = path + "images/w_mode_keyboard_ic.png";
314 evas_object_propagate_events_set(btn, EINA_FALSE);
316 elm_image_file_set(ic, path_ic.c_str(), NULL);
317 elm_object_content_set(btn, ic);
318 evas_object_layer_set(btn, 32000);
319 } else if (!strcmp(part, "elm.icon.2")){
321 if (!strcmp(second_input_type, "input_voice")) {
322 elm_object_style_set(btn, "ime_button_stt");
323 path_ic = path + "images/w_mode_stt_ic.png";
324 } else if (!strcmp(second_input_type, "input_emoticon")) {
325 elm_object_style_set(btn, "ime_button_emoticon");
326 path_ic = path + "images/Delta_w_mode_emoticon_ic.png";
327 } else if (!strcmp(second_input_type, "input_keyboard")) {
328 elm_object_style_set(btn, "ime_button_keyboard");
329 path_ic = path + "images/w_mode_keyboard_ic.png";
330 evas_object_propagate_events_set(btn, EINA_FALSE);
332 elm_image_file_set(ic, path_ic.c_str(), NULL);
333 elm_object_content_set(btn, ic);
334 evas_object_layer_set(btn, 32000);
337 } else if (!strcmp(part, "elm.icon.1.touch_area") || (!strcmp(part, "elm.icon.2.touch_area"))) {
338 Evas_Object* btn = elm_button_add(obj);
339 elm_object_style_set(btn, "touch_area");
340 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
341 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
342 string path = get_resource_path();
343 if (!strcmp(part, "elm.icon.1.touch_area")) {
344 evas_object_layer_set(btn, 32000);
345 if (!strcmp(first_input_type, "input_voice")) {
346 evas_object_smart_callback_add(btn, "clicked", _stt_clicked_cb, app_data);
347 } else if (!strcmp(first_input_type, "input_emoticon")) {
348 evas_object_smart_callback_add(btn, "clicked", _emoticon_clicked_cb, app_data);
349 } else if (!strcmp(first_input_type, "input_keyboard")) {
350 evas_object_propagate_events_set(btn, EINA_FALSE);
351 evas_object_smart_callback_add(btn, "clicked", _keyboard_clicked_cb, app_data);
353 } else if (!strcmp(part, "elm.icon.2.touch_area")){
354 evas_object_layer_set(btn, 32000);
355 if (!strcmp(second_input_type, "input_voice")) {
356 evas_object_smart_callback_add(btn, "clicked", _stt_clicked_cb, app_data);
357 } else if (!strcmp(second_input_type, "input_emoticon")) {
358 evas_object_smart_callback_add(btn, "clicked", _emoticon_clicked_cb, app_data);
359 } else if (!strcmp(second_input_type, "input_keyboard")) {
360 evas_object_propagate_events_set(btn, EINA_FALSE);
361 evas_object_smart_callback_add(btn, "clicked", _keyboard_clicked_cb, app_data);
365 } else if (!strcmp(part, "base")) {
366 Evas_Object* btn = elm_button_add(obj);
367 elm_object_style_set(btn, "ime_transparent");
373 static Evas_Object * __ise_gl_3button_content_get(void *data, Evas_Object *obj, const char *part)
375 if (!strcmp(part, "elm.icon.1") || (!strcmp(part, "elm.icon.2")) || (!strcmp(part, "elm.icon.3"))) {
376 Evas_Object* btn = elm_button_add(obj);
377 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
378 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
379 Evas_Object* ic = elm_image_add(btn);
380 elm_image_resizable_set(ic, EINA_TRUE, EINA_TRUE);
381 string path = get_resource_path();
383 path = path + "wearable/";
387 path = path + "mobile/";
389 if (!strcmp(part, "elm.icon.1")) {
390 elm_object_style_set(btn, "ime_button_stt");
391 string path_ic = path + "images/w_mode_stt_ic.png";
392 elm_image_file_set(ic, path_ic.c_str(), NULL);
393 elm_object_content_set(btn, ic);
394 evas_object_layer_set(btn, 32000);
396 } else if (!strcmp(part, "elm.icon.2")){
397 elm_object_style_set(btn, "ime_button_emoticon");
398 string path_ic = path + "images/Delta_w_mode_emoticon_ic.png";
399 elm_image_file_set(ic, path_ic.c_str(), NULL);
400 elm_object_content_set(btn, ic);
401 evas_object_layer_set(btn, 32000);
403 } else if (!strcmp(part, "elm.icon.3")){
404 elm_object_style_set(btn, "ime_button_keyboard");
405 string path_ic = path + "images/w_mode_keyboard_ic.png";
406 elm_image_file_set(ic, path_ic.c_str(), NULL);
407 elm_object_content_set(btn, ic);
408 evas_object_layer_set(btn, 32000);
409 evas_object_propagate_events_set(btn, EINA_FALSE);
413 } else if (!strcmp(part, "elm.icon.1.touch_area") || (!strcmp(part, "elm.icon.2.touch_area")) || (!strcmp(part, "elm.icon.3.touch_area"))) {
414 Evas_Object* btn = elm_button_add(obj);
415 elm_object_style_set(btn, "touch_area");
416 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
417 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
418 string path = get_resource_path();
419 if (!strcmp(part, "elm.icon.1.touch_area")) {
420 evas_object_layer_set(btn, 32000);
421 evas_object_smart_callback_add(btn, "clicked", _stt_clicked_cb, app_data);
423 } else if (!strcmp(part, "elm.icon.2.touch_area")){
424 evas_object_layer_set(btn, 32000);
425 evas_object_smart_callback_add(btn, "clicked", _emoticon_clicked_cb, app_data);
426 } else if (!strcmp(part, "elm.icon.3.touch_area")) {
427 evas_object_layer_set(btn, 32000);
428 evas_object_propagate_events_set(btn, EINA_FALSE);
429 evas_object_smart_callback_add(btn, "clicked", _keyboard_clicked_cb, app_data);
433 } else if (!strcmp(part, "base")) {
434 Evas_Object* btn = elm_button_add(obj);
435 elm_object_style_set(btn, "ime_transparent");
441 static char * __ise_smartreply_gl_text_get(void *data, Evas_Object *obj, const char *part)
443 if(!strcmp(part, "elm.text")) {
446 index = (intptr_t)data;
450 reply = input_smartreply_get_nth_item(index, NULL);
459 static void __ise_gl_lang_changed(void *data, Evas_Object *obj, void *event_info)
461 //Update genlist items. The Item texts will be translated in the _gl_text_get().
462 elm_genlist_realized_items_update(obj);
465 void set_source_caller_app_id(app_control_h app_control)
468 PRINTFUNC(DLOG_ERROR, "can't get app_control");
473 app_control_get_caller(app_data->source_app_control, &caller);
476 PRINTFUNC(DLOG_DEBUG, "caller = %s", caller);
477 app_control_add_extra_data(app_control, "caller_appid", caller);
482 void reply_to_sender_by_callback(const char *value, const char *type, const char *path[], const char *cursor_position)
484 PRINTFUNC(DLOG_DEBUG, "");
486 app_control_h app_control;
488 if (app_control_create(&app_control) == 0) {
492 app_control_add_extra_data(app_control, APP_CONTROL_DATA_TEXT, value);
495 app_control_add_extra_data(app_control, "reply_type", type);
498 app_control_add_extra_data_array(app_control, APP_CONTROL_DATA_PATH, path, 1);
501 if (cursor_position != NULL)
502 app_control_add_extra_data(app_control, "cursor_position_get", cursor_position);
504 set_source_caller_app_id(app_control);
506 ret = app_control_reply_to_launch_request(app_control, app_data->source_app_control, APP_CONTROL_RESULT_SUCCEEDED);
507 if (ret != APP_CONTROL_ERROR_NONE)
508 PRINTFUNC(DLOG_ERROR, "reply failed : %d", ret);
510 app_control_destroy(app_control);
511 app_control_destroy(app_data->source_app_control);
512 app_data->source_app_control = NULL;
516 void reply_to_sender_by_callback_for_back()
518 PRINTFUNC(DLOG_DEBUG, "");
520 app_control_h app_control;
522 if (app_control_create(&app_control) == 0) {
525 app_control_add_extra_data(app_control, "back_to_composer", "yes");
527 ret = app_control_reply_to_launch_request(app_control, app_data->source_app_control, APP_CONTROL_RESULT_SUCCEEDED);
528 if (ret != APP_CONTROL_ERROR_NONE)
529 PRINTFUNC(DLOG_ERROR, "reply failed : %d", ret);
531 app_control_destroy(app_control);
532 app_control_destroy(app_data->source_app_control);
533 app_data->source_app_control = NULL;
537 char* get_resource_path()
539 if (NULL == app_data->res_path) {
540 app_data->res_path = app_get_resource_path();
541 PRINTFUNC(DLOG_INFO, "set resource path = %s", app_data->res_path);
543 return (app_data->res_path);
546 char* get_shared_resource_path()
548 if (NULL == app_data->shared_res_path) {
549 app_data->shared_res_path = app_get_shared_resource_path();
550 PRINTFUNC(DLOG_INFO, "set shared resource path = %s", app_data->shared_res_path);
552 return (app_data->shared_res_path);
555 void show_gl_focus(Eina_Bool bVisible){
556 if (app_data->genlist == NULL)
559 if (bVisible == EINA_TRUE){
560 elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,enable", "elm");
561 //elm_layout_theme_set(app_data->genlist, "genlist", "base", "focus_bg");
562 //elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,show", "elm");
564 elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,disable", "elm");
565 //elm_layout_theme_set(app_data->genlist, "genlist", "base", "default");
566 //elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,hide", "elm");
570 void show_popup_toast(const char *text, bool check_img)
572 PRINTFUNC(DLOG_ERROR, "show_popup_toast");
576 popup = elm_popup_add(app_data->win_main);
577 elm_object_style_set(popup, "toast/circle");
578 elm_popup_orient_set(popup, ELM_POPUP_ORIENT_BOTTOM);
579 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
582 string path = get_resource_path();
584 path = path + "wearable/";
588 path = path + "mobile/";
589 string path_ic = path + "/images/toast_check_icon.png";
590 Evas_Object * img = elm_image_add(popup);
591 elm_image_file_set(img, path_ic.c_str(), NULL);
592 elm_object_part_content_set(popup, "toast,icon", img);
595 elm_object_part_text_set(popup, "elm.text", text);
598 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, _popup_back_cb, NULL);
599 evas_object_smart_callback_add(popup, "dismissed", _popup_close_cb, NULL);
600 evas_object_smart_callback_add(popup, "block,clicked", _popup_back_cb, NULL);
602 elm_popup_timeout_set(popup, 2.0);
603 evas_object_show(popup);
606 static void _popup_close_cb(void *data, Evas_Object *obj, void *event_info)
609 evas_object_hide(obj);
610 evas_object_del(obj);
614 static void _popup_back_cb(void *data, Evas_Object *obj, void *event_info)
617 elm_popup_dismiss(obj);
621 void _back_to_genlist_for_selector()
623 PRINTFUNC(DLOG_DEBUG, "");
625 if (!app_data) return;
628 Evas_Object *circle_genlist = (Evas_Object *) evas_object_data_get(app_data->genlist, "circle");
629 eext_rotary_object_event_activated_set(circle_genlist, EINA_TRUE);
631 if (app_data->app_type == APP_TYPE_STT || app_data->app_type == APP_TYPE_EMOTICON || app_data->app_type == APP_TYPE_KEYBOARD){
632 PRINTFUNC(DLOG_DEBUG, "launched as STT/EMOTICON/KEYBOARD mode, So exit here.");
633 reply_to_sender_by_callback(NULL, NULL, NULL, NULL);
638 static void _item_realized(void *data, Evas_Object *obj, void *event_info) //called when list scrolled
640 PRINTFUNC(DLOG_DEBUG, "%s", __func__);
643 Evas_Object* _create_genlist(Evas_Object* navi)
645 Evas_Object* genlist = elm_genlist_add(navi);
649 elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
651 Evas_Object* circle_object_genlist = eext_circle_object_genlist_add(genlist, app_data->circle_surface);
652 eext_circle_object_genlist_scroller_policy_set(circle_object_genlist, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
653 evas_object_data_set(genlist, "circle", (void *) circle_object_genlist);
654 eext_rotary_object_event_activated_set(circle_object_genlist, EINA_TRUE);
656 evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
657 evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
659 evas_object_smart_callback_add(genlist, "language,changed", __ise_gl_lang_changed, genlist);
660 evas_object_show(genlist);
662 // uxt_genlist_set_bottom_margin_enabled(genlist, EINA_TRUE);
664 show_gl_focus(EINA_FALSE);
666 const char *item_style = NULL;
668 item_style = "empty";
669 Elm_Object_Item *nf_main_item = elm_naviframe_item_push(navi,
676 elm_naviframe_item_pop_cb_set(nf_main_item, back_cb, app_data);
677 evas_object_smart_callback_add(genlist, "realized", _item_realized, NULL);
682 static void _item_position_changed_cb(void *data, Evas_Object *obj, void *event_info)
687 Evas_Object *genlist = (Evas_Object *)obj;
688 Elm_Object_Item *gen_item = (Elm_Object_Item *)data;
691 elm_scroller_region_get(genlist, NULL, &y, NULL, NULL);
693 // PRINTFUNC(DLOG_DEBUG,"y=%d",y);
695 if (250 > y && y >= 100){
696 if (last_step == 0) return;
698 elm_object_item_signal_emit(gen_item, "elm,action,ime,0.0", "elm");
699 show_gl_focus(EINA_TRUE);
700 } else if (100 > y && y >= 50){
701 if (last_step == 1) return;
703 elm_object_item_signal_emit(gen_item, "elm,action,ime,0.1", "elm");
704 show_gl_focus(EINA_TRUE);
705 } else if (y < 50 && y >=0){
706 if (last_step == 2) return;
708 elm_object_item_signal_emit(gen_item, "elm,action,ime,0.9", "elm");
709 show_gl_focus(EINA_FALSE);
714 _main_menu_title_text_get(void *data, Evas_Object *obj, const char *part)
718 snprintf(buf, 1023, "%s", "Select method");
722 void _create_genlist_items(void* user_data)
724 App_Data* app_data = (App_Data*) user_data;
726 if (NULL == app_data->genlist) {
727 app_data->genlist = _create_genlist(app_data->naviframe);
728 if (NULL == app_data->genlist)
732 elm_genlist_clear(app_data->genlist);
734 Elm_Genlist_Item_Class * itc0 = elm_genlist_item_class_new();
735 itc0->item_style = "title";
736 itc0->func.text_get = _main_menu_title_text_get;
737 itc0->func.content_get = NULL;
738 itc0->func.state_get = NULL;
739 itc0->func.del = NULL;
741 Elm_Genlist_Item_Class * itc1 = elm_genlist_item_class_new();
742 if (g_input_type_data.input_type_array_len == 2){
743 itc1->item_style = "2button_flat";
744 itc1->func.text_get = NULL;
745 itc1->func.content_get = __ise_gl_2button_content_get;
746 itc1->func.state_get = NULL;
747 itc1->func.del = NULL;
749 itc1->item_style = "3button_flat";
750 itc1->func.text_get = NULL;
751 itc1->func.content_get = __ise_gl_3button_content_get;
752 itc1->func.state_get = NULL;
753 itc1->func.del = NULL;
756 // dummy title for empty space
757 it_empty = elm_genlist_item_append(app_data->genlist, itc0,
759 ELM_GENLIST_ITEM_NONE,
763 it_title = elm_genlist_item_append(app_data->genlist, itc1,
765 ELM_GENLIST_ITEM_NONE,
768 elm_genlist_item_select_mode_set(it_title, ELM_OBJECT_SELECT_MODE_NONE);
770 g_template_item_size = _update_template_items(app_data);
772 Elm_Object_Item *item = elm_genlist_item_next_get(it_title);
773 elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
775 evas_object_smart_callback_add(app_data->genlist, "elm,item,position,changed", _item_position_changed_cb, it_title);
777 elm_genlist_item_class_free(itc0);
778 elm_genlist_item_class_free(itc1);
781 void _create_header_items(void *user_data)
783 Elm_Genlist_Item_Class * itc0 = elm_genlist_item_class_new();
784 itc0->item_style = "title";
785 itc0->func.text_get = NULL;
786 itc0->func.content_get = NULL;
787 itc0->func.state_get = NULL;
788 itc0->func.del = NULL;
790 Elm_Genlist_Item_Class * itc1 = elm_genlist_item_class_new();
791 if (g_input_type_data.input_type_array_len == 2) {
792 itc1->item_style = "2button_flat";
793 itc1->func.text_get = NULL;
794 itc1->func.content_get = __ise_gl_2button_content_get;
795 itc1->func.state_get = NULL;
796 itc1->func.del = NULL;
798 itc1->item_style = "3button_flat";
799 itc1->func.text_get = NULL;
800 itc1->func.content_get = __ise_gl_3button_content_get;
801 itc1->func.state_get = NULL;
802 itc1->func.del = NULL;
805 // dummy title for empty space
806 it_empty = elm_genlist_item_append(app_data->genlist, itc0,
808 ELM_GENLIST_ITEM_NONE,
812 it_title = elm_genlist_item_append(app_data->genlist, itc1,
814 ELM_GENLIST_ITEM_NONE,
817 elm_genlist_item_select_mode_set(it_title, ELM_OBJECT_SELECT_MODE_NONE);
819 elm_genlist_item_class_free(itc0);
820 elm_genlist_item_class_free(itc1);
823 void _update_genlist_items(void *user_data)
825 elm_genlist_clear(app_data->genlist);
827 _create_header_items(user_data);
829 if (input_smartreply_is_enabled())
830 g_smartreply_item_size = _update_smartreply_items(user_data);
832 g_smartreply_item_size = 0;
834 g_template_item_size = _update_template_items(user_data);
836 /* Update genlist item position */
837 Elm_Object_Item *item = elm_genlist_item_next_get(it_title);
838 elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
841 unsigned int _update_smartreply_items(void *user_data)
845 Elm_Object_Item *first;
846 Elm_Object_Item *menu;
849 unsigned int len = 0;
850 unsigned int item_size = 0;
852 app_data = (App_Data *)user_data;
854 if (app_data == NULL) {
855 PRINTFUNC(DLOG_ERROR, "Can not get app_data");
859 if (app_data->genlist == NULL) {
860 /* smartreply will update when genlist is exist only */
861 PRINTFUNC(DLOG_ERROR, "Can not get getlist");
865 /* Move to smartreply */
866 first = elm_genlist_first_item_get(app_data->genlist);
867 menu = elm_genlist_item_next_get(first);
869 if (input_smartreply_is_enabled() == false)
872 /* Append newly added smartreply list */
873 len = input_smartreply_get_reply_num();
876 const std::vector<TemplateData> template_list = input_template_get_list();
878 Elm_Genlist_Item_Class *itc;
880 itc = elm_genlist_item_class_new();
881 itc->item_style = "1text";
882 itc->func.text_get = __ise_smartreply_gl_text_get;
883 itc->func.content_get = NULL;
884 itc->func.state_get = NULL;
885 itc->func.del = NULL;
887 for (i = 0; i < len; i++) {
888 char *reply = "hello";
895 reply = input_smartreply_get_nth_item(i, &type);
898 PRINTFUNC(DLOG_DEBUG, "SmartReply = [%d]%s", i, reply);
900 for (j = 0; j < template_list.size(); j++) {
901 const char *template_str;
903 if (template_list[j].use_gettext)
904 template_str = gettext(template_list[j].text.c_str());
906 template_str = template_list[j].text.c_str();
908 if (!__compare_string(reply, template_str)) {
917 elm_genlist_item_append(app_data->genlist,
919 (void *)(uintptr_t)i,
921 ELM_GENLIST_ITEM_NONE,
922 __ise_smartreply_gl_sel,
929 elm_genlist_item_class_free(itc);
935 unsigned int _update_template_items(void *user_data)
939 Elm_Object_Item *first;
940 Elm_Object_Item *menu;
941 Elm_Object_Item *pos;
944 unsigned int item_size = 0;
946 app_data = (App_Data *)user_data;
948 if (app_data == NULL) {
949 PRINTFUNC(DLOG_ERROR, "Can not get app_data");
953 if (app_data->genlist == NULL) {
954 /* smartreply will update when genlist is exist only */
955 PRINTFUNC(DLOG_ERROR, "Can not get getlist");
959 first = elm_genlist_first_item_get(app_data->genlist);
962 menu = elm_genlist_item_next_get(first);
965 /* move to smartreply next if it need */
966 if (input_smartreply_is_enabled()) {
969 for (j = 0; j < g_smartreply_item_size; j++) {
973 pos = elm_genlist_item_next_get(pos);
977 /* Append New Template list */
978 const std::vector<TemplateData> template_list = input_template_get_list();
980 if (template_list.size() > 0) {
981 Elm_Genlist_Item_Class *itc;
983 itc = elm_genlist_item_class_new();
985 itc->item_style = "1text";
986 itc->func.text_get = __ise_template_gl_text_get;
987 itc->func.content_get = NULL;
988 itc->func.state_get = NULL;
989 itc->func.del = NULL;
991 for (i = 0; i < template_list.size(); i++) {
992 pos = elm_genlist_item_append(app_data->genlist,
994 (void *)(uintptr_t)i,
996 ELM_GENLIST_ITEM_NONE,
997 __ise_template_gl_sel,
1001 elm_genlist_item_class_free(itc);
1007 bool __compare_string(const char * smart_str, const char * template_str)
1013 if(!smart_str||!template_str)
1016 src_len = strlen(smart_str);
1017 dst_len = strlen(template_str);
1019 if(smart_str[src_len-1] == '.')
1022 while(template_str[dst_len-1] == ' ')
1024 if(template_str[dst_len-1] == '.')
1027 dst_len = (dst_len > src_len)? dst_len : src_len;
1029 if(!strncmp(smart_str, template_str, (size_t)dst_len))
1035 bool _app_create(void* user_data)
1037 int width = 1000, height = 1000;
1038 // App_Data* app_data = NULL;
1039 Evas_Object* layout = NULL;
1040 Evas_Object* conform = NULL;
1041 Evas_Object* bg = NULL;
1042 Evas_Object* window = NULL;
1043 Eext_Circle_Surface *surface = NULL;
1049 _app_language_changed(NULL, NULL);
1051 app_data = (App_Data*)user_data;
1053 elm_app_base_scale_set(1.3);
1055 window = elm_win_add(NULL, PACKAGE, ELM_WIN_BASIC);
1057 init_customizing_theme();
1059 elm_win_title_set(window, PACKAGE);
1060 elm_win_borderless_set(window, EINA_TRUE);
1061 // ecore_x_window_size_get(ecore_x_window_root_first_get(), &width, &height);
1062 evas_object_resize(window, width, height);
1063 elm_win_indicator_mode_set(window, ELM_WIN_INDICATOR_SHOW);
1065 LOGE("elm_win_add() is failed.");
1069 bg = elm_bg_add(window);
1070 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1071 elm_win_resize_object_add(window, bg);
1072 evas_object_show(bg);
1074 layout = elm_layout_add(window);
1075 elm_layout_theme_set(layout, "layout", "application", "default");
1076 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1078 conform = elm_conformant_add(window);
1080 surface = eext_circle_surface_conformant_add(conform);
1082 evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1084 elm_win_resize_object_add(window, conform);
1085 elm_object_content_set(conform, layout);
1087 evas_object_show(layout);
1088 evas_object_show(conform);
1089 evas_object_show(window);
1090 app_data->win_main = window;
1091 app_data->conform = conform;
1092 app_data->layout_main = layout;
1093 app_data->circle_surface = surface;
1094 app_data->app_type = APP_TYPE_SELECT_MODE;
1096 Evas_Object *naviframe = elm_naviframe_add(layout);
1097 elm_naviframe_prev_btn_auto_pushed_set(naviframe, EINA_FALSE);
1098 eext_object_event_callback_add(naviframe, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, NULL);
1099 elm_object_part_content_set(layout, "elm.swallow.content", naviframe);
1100 evas_object_show(naviframe);
1102 app_data->naviframe = naviframe;
1107 void _app_service(app_control_h service, void* user_data)
1110 char *context = NULL;
1111 char **input_type_array = NULL;
1112 int input_type_array_len = -1;
1113 bool is_extra_data_array = false;
1114 char *mime_type = NULL;
1116 app_control_clone(&(app_data->source_app_control), service);
1117 app_data->reply_type = REPLY_APP_NORMAL;
1118 app_data->mime_type = MIME_TYPE_ALL;
1120 ret = app_control_get_mime(service, &mime_type);
1121 if (ret != APP_CONTROL_ERROR_NONE) {
1122 LOGD("Fail to get mime type : %d", ret);
1125 LOGD("mime type = %s", mime_type);
1126 if (!strncmp(mime_type, "image/", strlen("image/"))) {
1127 app_data->mime_type = MIME_TYPE_IMAGE;
1128 app_data->app_type = APP_TYPE_DRAWING;
1129 launch_drawing_app((void *)app_data);
1133 } else if(!strncmp(mime_type, "audio/", strlen("audio/"))) {
1134 app_data->mime_type = MIME_TYPE_AUDIO;
1135 app_data->app_type = APP_TYPE_STT;
1136 _stt_clicked_cb((void *)app_data, NULL, NULL);
1140 } else if(!strncmp(mime_type, "text/", strlen("text/"))) {
1141 app_data->mime_type = MIME_TYPE_TEXT;
1148 if (_TV || _MOBILE) {
1149 app_data->app_type = APP_TYPE_KEYBOARD;
1150 input_keyboard_init(service);
1151 _keyboard_clicked_cb((void *)app_data, NULL, NULL);
1155 ret = app_control_is_extra_data_array(service, APP_CONTROL_DATA_INPUT_TYPE, &is_extra_data_array);
1156 if ( is_extra_data_array == true) {
1157 ret = app_control_get_extra_data_array(service, APP_CONTROL_DATA_INPUT_TYPE, &input_type_array, &input_type_array_len);
1158 g_input_type_data.input_type_array = input_type_array;
1159 g_input_type_data.input_type_array_len = input_type_array_len;
1161 ret = app_control_get_extra_data(service, APP_CONTROL_DATA_INPUT_TYPE, &context);
1162 if (ret == APP_CONTROL_ERROR_NONE) {
1163 if (!strcmp(context, "input_voice")) {
1164 app_data->app_type = APP_TYPE_STT;
1165 _stt_clicked_cb((void *)app_data, NULL, NULL);
1167 } else if (!strcmp(context, "input_emoticon")) {
1168 app_data->app_type = APP_TYPE_EMOTICON;
1169 _emoticon_clicked_cb((void *)app_data, NULL, NULL);
1171 } else if (!strcmp(context, "input_keyboard")) {
1172 app_data->app_type = APP_TYPE_KEYBOARD;
1173 input_keyboard_init(service);
1174 _keyboard_clicked_cb((void *)app_data, NULL, NULL);
1176 } else if (!strcmp(context, "input_reply")) {
1177 app_data->app_type = APP_TYPE_REPLY;
1182 if (app_data->genlist == NULL)
1183 app_data->genlist = _create_genlist(app_data->naviframe);
1185 input_keyboard_init(service);
1187 input_smartreply_init(service);
1188 input_smartreply_set_notify(_input_smartreply_notify_cb, NULL);
1190 if (input_smartreply_is_enabled())
1191 input_smartreply_get_reply_async();
1193 input_template_init(service);
1194 input_template_set_notify(_input_template_notify_cb, NULL);
1196 _create_genlist_items(app_data);
1199 elm_win_activate(app_data->win_main);
1206 void _app_pause(void* user_data)
1208 PRINTFUNC(DLOG_DEBUG, "");
1212 void _app_resume(void* user_data)
1214 PRINTFUNC(DLOG_DEBUG, "");
1217 void _app_terminate(void* user_data)
1219 App_Data* app_data = NULL;
1220 app_data = (App_Data*)user_data;
1222 if (app_data->genlist){
1223 evas_object_smart_callback_del(app_data->genlist, "elm,item,position,changed", _item_position_changed_cb);
1226 if (app_data->res_path)
1227 free(app_data->res_path);
1229 if (app_data->shared_res_path)
1230 free(app_data->shared_res_path);
1232 input_keyboard_deinit();
1233 input_smartreply_deinit();
1235 input_template_unset_notify();
1236 input_template_deinit();
1238 input_type_deinit();
1241 static int init_i18n(const char *domain, const char *dir, char *lang_str)
1243 if (setlocale(LC_ALL, "") == NULL) {
1244 PRINTFUNC(DLOG_INFO, "Some environment variable is invalid, setlocale(LC_ALL, \"\") has returns\ed a null pointer");
1245 if (setlocale(LC_ALL, lang_str) == NULL)
1248 if (bindtextdomain(domain, dir) == NULL)
1250 if (textdomain(domain) == NULL)
1257 * @brief Set language and locale.
1261 static void _app_language_changed(app_event_info_h event_info, void *user_data)
1263 char* lang_str = vconf_get_str(VCONFKEY_LANGSET);
1265 setenv("LANG", lang_str, 1);
1266 setenv("LC_MESSAGES", lang_str, 1);
1268 setenv("LANG", "en_GB.utf8", 1);
1269 setenv("LC_MESSAGES", "en_GB.utf8", 1);
1270 lang_str = strdup("en_GB.UTF-8");
1273 init_i18n(PACKAGE, LOCALEDIR, lang_str);
1276 elm_language_set(lang_str);
1281 void input_type_deinit(void)
1284 char **data_array = NULL;
1286 data_array = g_input_type_data.input_type_array;
1288 for (i = 0; i < g_input_type_data.input_type_array_len; i++) {
1289 if (*(data_array + i))
1290 free(*(data_array + i));
1294 g_input_type_data.input_type_array = NULL;
1295 g_input_type_data.input_type_array_len = 0;
1298 EXPORTED int main(int argc, char* argv[])
1300 App_Data app_data = {0, };
1301 ui_app_lifecycle_callback_s event_callback = {0, };
1302 app_event_handler_h handlers[5] = {NULL, };
1304 event_callback.create = _app_create;
1305 event_callback.terminate = _app_terminate;
1306 event_callback.pause = _app_pause;
1307 event_callback.resume = _app_resume;
1308 event_callback.app_control = _app_service;
1310 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, NULL, &app_data);
1311 ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, NULL, &app_data);
1312 ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, NULL, &app_data);
1313 ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _app_language_changed, &app_data);
1314 ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, NULL, &app_data);
1316 _init_app_data(&app_data);
1318 int ret = ui_app_main(argc, argv, &event_callback, &app_data);
1319 if (ret != APP_ERROR_NONE) {
1320 LOGD("ui_app_main() is failed. err = %d", ret);