Add smartreply feature
[platform/core/uifw/inputdelegator.git] / src / w-input-selector.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "Debug.h"
18
19 #include <app.h>
20 #include <dlog.h>
21 #include <Eina.h>
22 #include <string>
23 #include <vconf.h>
24 #include <vconf-keys.h>
25 #include <stdint.h>
26 #include <system_info.h>
27
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"
34
35 #include <stt.h>
36
37
38 using namespace std;
39
40 App_Data* app_data = NULL;
41
42 InputKeyboardData g_input_keyboard_data;
43 InputTypeData g_input_type_data;
44
45 static Elm_Object_Item *it_empty;
46 static Elm_Object_Item *it_title;
47
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 */
50
51 Evas_Coord last_step; // 0 ~ 9 for gesture, 10~11 for rotary
52
53 tizen_profile_t _get_tizen_profile()
54 {
55         static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
56         if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
57                 return profile;
58
59         char *profileName;
60         system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
61         switch (*profileName)
62         {
63                 case 'm':
64                 case 'M':
65                         profile = TIZEN_PROFILE_MOBILE;
66                         break;
67                 case 'w':
68                 case 'W':
69                         profile = TIZEN_PROFILE_WEARABLE;
70                         break;
71                 case 't':
72                 case 'T':
73                         profile = TIZEN_PROFILE_TV;
74                         break;
75                 case 'i':
76                 case 'I':
77                         profile = TIZEN_PROFILE_IVI;
78                         break;
79                 default: // common or unknown ==> ALL ARE COMMON.
80                         profile = TIZEN_PROFILE_COMMON;
81         }
82         free(profileName);
83
84         return profile;
85 }
86
87 void _init_app_data(App_Data* app_data);
88 static void _app_language_changed(app_event_info_h event_info, void *user_data);
89
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);
99
100 bool __compare_string(const char * src, const char * dst);
101
102 void _init_app_data(App_Data* app_data)
103 {
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;
109
110         app_data->res_path = NULL;
111 }
112
113 Evas_Object* load_edj(Evas_Object* parent, const char* file, const char* group)
114 {
115         Evas_Object* window;
116         Evas_Object* content;
117         int ret;
118
119         window = elm_layout_add(parent);
120         if (window) {
121                 ret = elm_layout_file_set(window, file, group);
122                 if (!ret) {
123                         evas_object_del(window);
124                         return NULL;
125                 }
126
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);
130
131                 evas_object_size_hint_weight_set(window, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
132         }
133         return window;
134 }
135
136 void init_customizing_theme(void)
137 {
138         string stt_edj_path = get_resource_path();
139         string app_edj_path = get_resource_path();
140
141         if (_WEARABLE) {
142                 stt_edj_path = stt_edj_path + STT_EDJ_FILE_WEARABLE;
143                 app_edj_path = app_edj_path + APP_EDJ_FILE_WEARABLE;
144         } else if (_TV) {
145                 stt_edj_path = stt_edj_path + STT_EDJ_FILE_TV;
146                 app_edj_path = app_edj_path + APP_EDJ_FILE_TV;
147         } else {
148                 stt_edj_path = stt_edj_path + STT_EDJ_FILE_MOBILE;
149                 app_edj_path = app_edj_path + APP_EDJ_FILE_MOBILE;
150         }
151
152         elm_theme_extension_add(NULL, stt_edj_path.c_str());
153         elm_theme_extension_add(NULL, app_edj_path.c_str());
154 }
155
156
157 static Eina_Bool back_cb(void *data, Elm_Object_Item *it)
158 {
159         reply_to_sender_by_callback_for_back();
160         ui_app_exit();
161         return EINA_FALSE;
162 }
163
164 static void _stt_clicked_cb(void *data, Evas_Object * obj, void *event_info)
165 {
166         App_Data* ad = (App_Data*)data;
167
168         PRINTFUNC(DLOG_DEBUG, "");
169
170         if (!ad)
171                 return;
172
173         ise_show_stt_popup(ad);
174 }
175
176 static void _input_smartreply_notify_cb(void *user_data)
177 {
178         ecore_main_loop_iterate();
179         _update_genlist_items((void *)app_data);
180 }
181
182 static void _input_template_notify_cb(void *user_data)
183 {
184         _update_genlist_items((void *)app_data);
185 }
186
187 static void _emoticon_clicked_cb(void *data, Evas_Object * obj, void *event_info)
188 {
189         App_Data* ad = (App_Data*)data;
190
191         PRINTFUNC(DLOG_DEBUG, "");
192
193         if (!ad)
194                 return;
195
196         ise_show_emoticon_list(ad);
197 }
198
199 static void _keyboard_clicked_cb(void *data, Evas_Object * obj, void *event_info)
200 {
201         App_Data* ad = (App_Data *)data;
202
203         PRINTFUNC(DLOG_DEBUG, "");
204
205         if (!ad)
206                 return;
207
208         input_keyboard_launch(ad->win_main, data);
209 }
210
211 static void __ise_smartreply_gl_sel(void *data, Evas_Object *obj, void *event_info)
212 {
213         App_Data* app_data = (App_Data*) data;
214         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
215
216         if (item) {
217                 elm_genlist_item_selected_set(item, EINA_FALSE);
218
219                 int index = (intptr_t) elm_object_item_data_get(item);
220
221                 int type;
222                 char *reply = input_smartreply_get_nth_item(index, &type);
223                 if (reply) {
224                         input_smartreply_send_feedback(reply);
225                         reply_to_sender_by_callback(reply, "smartreply");
226                         free(reply);
227                         elm_exit();
228                 }
229         }
230 }
231
232 static void __ise_template_gl_sel(void *data, Evas_Object *obj, void *event_info)
233 {
234         Elm_Object_Item *item = (Elm_Object_Item *) event_info;
235         int index = 0;
236
237         if (item) {
238                 elm_genlist_item_selected_set(item, EINA_FALSE);
239
240                 index = (uintptr_t) elm_object_item_data_get(item);
241                 const std::vector<TemplateData>  template_list = input_template_get_list();
242
243                 if (index < (int)template_list.size()) {
244                         reply_to_sender_by_callback(gettext(template_list[index].text.c_str()), "template");
245                         ui_app_exit();
246                 }
247         }
248 }
249
250 static char * __ise_template_gl_text_get(void *data, Evas_Object *obj, const char *part)
251 {
252         if (!strcmp(part, "elm.text")) {
253                 unsigned int index = (uintptr_t)data;
254                 const std::vector<TemplateData>  template_list = input_template_get_list();
255
256                 if (index < template_list.size()) {
257                         if (template_list[index].use_gettext) {
258                                 return strdup(gettext(template_list[index].text.c_str()));
259                         } else {
260                                 Eina_Strbuf *buf = NULL;
261                                 const char *str = NULL;
262                                 char *markup = NULL;
263
264                                 buf = eina_strbuf_new();
265                                 if (buf) {
266                                         eina_strbuf_append(buf, template_list[index].text.c_str());
267                                         eina_strbuf_replace_all(buf, "\n", "");
268                                         eina_strbuf_replace_all(buf, "\r", "");
269
270                                         str = eina_strbuf_string_get(buf);
271
272                                         if (str) {
273                                                 markup = elm_entry_utf8_to_markup(str);
274                                         }
275                                         eina_strbuf_free(buf);
276                                 }
277                                 return markup;
278                         }
279                 }
280         }
281         return NULL;
282 }
283
284 static Evas_Object * __ise_gl_2button_content_get(void *data, Evas_Object *obj, const char *part)
285 {
286         char *first_input_type = *(g_input_type_data.input_type_array + 0);
287         char *second_input_type = *(g_input_type_data.input_type_array + 1);
288
289         if (!strcmp(part, "elm.icon.1") ||  (!strcmp(part, "elm.icon.2"))) {
290                 Evas_Object* btn = elm_button_add(obj);
291                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
292                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
293
294                 Evas_Object* ic = elm_image_add(btn);
295                 elm_image_resizable_set(ic, EINA_TRUE, EINA_TRUE);
296                 string path = get_resource_path();
297                 if (_WEARABLE)
298                         path = path + "wearable/";
299                 else if (_TV)
300                         path = path + "tv/";
301                 else
302                         path = path + "mobile/";
303
304                 if (!strcmp(part, "elm.icon.1")) {
305                         string path_ic;
306                         if (!strcmp(first_input_type, "input_voice")) {
307                                 elm_object_style_set(btn, "ime_button_stt");
308                                 path_ic = path + "images/w_mode_stt_ic.png";
309                         } else if (!strcmp(first_input_type, "input_emoticon")) {
310                                 elm_object_style_set(btn, "ime_button_emoticon");
311                                 path_ic = path + "images/Delta_w_mode_emoticon_ic.png";
312                         } else if (!strcmp(first_input_type, "input_keyboard")) {
313                                 elm_object_style_set(btn, "ime_button_keyboard");
314                                 path_ic = path + "images/w_mode_keyboard_ic.png";
315                                 evas_object_propagate_events_set(btn, EINA_FALSE);
316                         }
317                         elm_image_file_set(ic, path_ic.c_str(), NULL);
318                         elm_object_content_set(btn, ic);
319                         evas_object_layer_set(btn, 32000);
320                 } else if (!strcmp(part, "elm.icon.2")){
321                         string path_ic;
322                         if (!strcmp(second_input_type, "input_voice")) {
323                                 elm_object_style_set(btn, "ime_button_stt");
324                                 path_ic = path + "images/w_mode_stt_ic.png";
325                         } else if (!strcmp(second_input_type, "input_emoticon")) {
326                                 elm_object_style_set(btn, "ime_button_emoticon");
327                                 path_ic = path + "images/Delta_w_mode_emoticon_ic.png";
328                         } else if (!strcmp(second_input_type, "input_keyboard")) {
329                                 elm_object_style_set(btn, "ime_button_keyboard");
330                                 path_ic = path + "images/w_mode_keyboard_ic.png";
331                                 evas_object_propagate_events_set(btn, EINA_FALSE);
332                         }
333                         elm_image_file_set(ic, path_ic.c_str(), NULL);
334                         elm_object_content_set(btn, ic);
335                         evas_object_layer_set(btn, 32000);
336                 }
337                 return btn;
338         } else if (!strcmp(part, "elm.icon.1.touch_area") ||  (!strcmp(part, "elm.icon.2.touch_area"))) {
339                 Evas_Object* btn = elm_button_add(obj);
340                 elm_object_style_set(btn, "touch_area");
341                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
342                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
343                 string path = get_resource_path();
344                 if (!strcmp(part, "elm.icon.1.touch_area")) {
345                         evas_object_layer_set(btn, 32000);
346                         if (!strcmp(first_input_type, "input_voice")) {
347                                 evas_object_smart_callback_add(btn, "clicked", _stt_clicked_cb, app_data);
348                         } else if (!strcmp(first_input_type, "input_emoticon")) {
349                                 evas_object_smart_callback_add(btn, "clicked", _emoticon_clicked_cb, app_data);
350                         } else if (!strcmp(first_input_type, "input_keyboard")) {
351                                 evas_object_propagate_events_set(btn, EINA_FALSE);
352                                 evas_object_smart_callback_add(btn, "clicked", _keyboard_clicked_cb, app_data);
353                         }
354                 } else if (!strcmp(part, "elm.icon.2.touch_area")){
355                         evas_object_layer_set(btn, 32000);
356                         if (!strcmp(second_input_type, "input_voice")) {
357                                 evas_object_smart_callback_add(btn, "clicked", _stt_clicked_cb, app_data);
358                         } else if (!strcmp(second_input_type, "input_emoticon")) {
359                                 evas_object_smart_callback_add(btn, "clicked", _emoticon_clicked_cb, app_data);
360                         } else if (!strcmp(second_input_type, "input_keyboard")) {
361                                 evas_object_propagate_events_set(btn, EINA_FALSE);
362                                 evas_object_smart_callback_add(btn, "clicked", _keyboard_clicked_cb, app_data);
363                         }
364                 }
365                 return btn;
366         } else if (!strcmp(part, "base")) {
367                 Evas_Object* btn = elm_button_add(obj);
368                 elm_object_style_set(btn, "ime_transparent");
369                 return btn;
370         }
371         return NULL;
372 }
373
374 static Evas_Object * __ise_gl_3button_content_get(void *data, Evas_Object *obj, const char *part)
375 {
376         if (!strcmp(part, "elm.icon.1") ||  (!strcmp(part, "elm.icon.2")) ||  (!strcmp(part, "elm.icon.3"))) {
377                 Evas_Object* btn = elm_button_add(obj);
378                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
379                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
380                 Evas_Object* ic = elm_image_add(btn);
381                 elm_image_resizable_set(ic, EINA_TRUE, EINA_TRUE);
382                 string path = get_resource_path();
383                 if (_WEARABLE)
384                         path = path + "wearable/";
385                 else if (_TV)
386                         path = path + "tv/";
387                 else
388                         path = path + "mobile/";
389
390                 if (!strcmp(part, "elm.icon.1")) {
391                         elm_object_style_set(btn, "ime_button_stt");
392                         string path_ic = path + "images/w_mode_stt_ic.png";
393                         elm_image_file_set(ic, path_ic.c_str(), NULL);
394                         elm_object_content_set(btn, ic);
395                         evas_object_layer_set(btn, 32000);
396
397                 } else if (!strcmp(part, "elm.icon.2")){
398                         elm_object_style_set(btn, "ime_button_emoticon");
399                         string path_ic = path + "images/Delta_w_mode_emoticon_ic.png";
400                         elm_image_file_set(ic, path_ic.c_str(), NULL);
401                         elm_object_content_set(btn, ic);
402                         evas_object_layer_set(btn, 32000);
403
404                 } else if (!strcmp(part, "elm.icon.3")){
405                         elm_object_style_set(btn, "ime_button_keyboard");
406                         string path_ic = path + "images/w_mode_keyboard_ic.png";
407                         elm_image_file_set(ic, path_ic.c_str(), NULL);
408                         elm_object_content_set(btn, ic);
409                         evas_object_layer_set(btn, 32000);
410                         evas_object_propagate_events_set(btn, EINA_FALSE);
411                 }
412
413                 return btn;
414         } else if (!strcmp(part, "elm.icon.1.touch_area") ||  (!strcmp(part, "elm.icon.2.touch_area")) ||  (!strcmp(part, "elm.icon.3.touch_area"))) {
415                 Evas_Object* btn = elm_button_add(obj);
416                 elm_object_style_set(btn, "touch_area");
417                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
418                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
419                 string path = get_resource_path();
420                 if (!strcmp(part, "elm.icon.1.touch_area")) {
421                         evas_object_layer_set(btn, 32000);
422                         evas_object_smart_callback_add(btn, "clicked", _stt_clicked_cb, app_data);
423
424                 } else if (!strcmp(part, "elm.icon.2.touch_area")){
425                         evas_object_layer_set(btn, 32000);
426                         evas_object_smart_callback_add(btn, "clicked", _emoticon_clicked_cb, app_data);
427                 } else if (!strcmp(part, "elm.icon.3.touch_area")) {
428                         evas_object_layer_set(btn, 32000);
429                         evas_object_propagate_events_set(btn, EINA_FALSE);
430                         evas_object_smart_callback_add(btn, "clicked", _keyboard_clicked_cb, app_data);
431                 }
432
433                 return btn;
434         } else if (!strcmp(part, "base")) {
435                 Evas_Object* btn = elm_button_add(obj);
436                 elm_object_style_set(btn, "ime_transparent");
437                 return btn;
438         }
439         return NULL;
440 }
441
442 static char * __ise_smartreply_gl_text_get(void *data, Evas_Object *obj, const char *part)
443 {
444         if(!strcmp(part, "elm.text")) {
445                 int index;
446                 char *reply = NULL;
447                 index = (intptr_t)data;
448                 if (index < 0)
449                         return NULL;
450
451                 reply = input_smartreply_get_nth_item(index, NULL);
452                 if (reply == NULL)
453                         return NULL;
454
455                 return reply;
456         }
457         return NULL;
458 }
459
460 static void __ise_gl_lang_changed(void *data, Evas_Object *obj, void *event_info)
461 {
462         //Update genlist items. The Item texts will be translated in the _gl_text_get().
463         elm_genlist_realized_items_update(obj);
464 }
465
466 void set_source_caller_app_id(app_control_h app_control)
467 {
468         if (!app_control){
469                 PRINTFUNC(DLOG_ERROR, "can't get app_control");
470                 return;
471         }
472
473         char *caller = NULL;
474         app_control_get_caller(app_data->source_app_control, &caller);
475
476         if (caller){
477                 PRINTFUNC(DLOG_DEBUG, "caller = %s", caller);
478                 app_control_add_extra_data(app_control, "caller_appid", caller);
479                 free(caller);
480         }
481 }
482
483 void reply_to_sender_by_callback(const char *value, const char *type)
484 {
485         PRINTFUNC(DLOG_DEBUG, "");
486
487         app_control_h app_control;
488
489         if (app_control_create(&app_control) == 0) {
490                 int ret;
491
492                 if (value)
493                         app_control_add_extra_data(app_control, APP_CONTROL_DATA_TEXT, value);
494
495                 if (type)
496                         app_control_add_extra_data(app_control, "reply_type", type);
497
498                 set_source_caller_app_id(app_control);
499
500                 ret = app_control_reply_to_launch_request(app_control, app_data->source_app_control, APP_CONTROL_RESULT_SUCCEEDED);
501                 if (ret != APP_CONTROL_ERROR_NONE)
502                         PRINTFUNC(DLOG_ERROR, "reply failed : %d", ret);
503
504                 app_control_destroy(app_control);
505                 app_control_destroy(app_data->source_app_control);
506                 app_data->source_app_control = NULL;
507         }
508 }
509
510 void reply_to_sender_by_callback_for_back()
511 {
512         PRINTFUNC(DLOG_DEBUG, "");
513
514         app_control_h app_control;
515
516         if (app_control_create(&app_control) == 0) {
517                 int ret;
518
519                 app_control_add_extra_data(app_control, "back_to_composer", "yes");
520
521                 ret = app_control_reply_to_launch_request(app_control, app_data->source_app_control, APP_CONTROL_RESULT_SUCCEEDED);
522                 if (ret != APP_CONTROL_ERROR_NONE)
523                         PRINTFUNC(DLOG_ERROR, "reply failed : %d", ret);
524
525                 app_control_destroy(app_control);
526                 app_control_destroy(app_data->source_app_control);
527                 app_data->source_app_control = NULL;
528         }
529 }
530
531 char* get_resource_path()
532 {
533         if (NULL == app_data->res_path) {
534                 app_data->res_path = app_get_resource_path();
535                 PRINTFUNC(DLOG_INFO, "set resource path = %s", app_data->res_path);
536         }
537         return (app_data->res_path);
538 }
539
540 char* get_shared_resource_path()
541 {
542         if (NULL == app_data->shared_res_path) {
543                 app_data->shared_res_path = app_get_shared_resource_path();
544                 PRINTFUNC(DLOG_INFO, "set shared resource path = %s", app_data->shared_res_path);
545         }
546         return (app_data->shared_res_path);
547 }
548
549 void show_gl_focus(Eina_Bool bVisible){
550         if (app_data->genlist == NULL)
551                 return;
552
553         if (bVisible == EINA_TRUE){
554                 elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,enable", "elm");
555                 //elm_layout_theme_set(app_data->genlist, "genlist", "base", "focus_bg");
556                 //elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,show", "elm");
557         } else {
558                 elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,disable", "elm");
559                 //elm_layout_theme_set(app_data->genlist, "genlist", "base", "default");
560                 //elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,hide", "elm");
561         }
562 }
563
564 void show_popup_toast(const char *text, bool check_img)
565 {
566         PRINTFUNC(DLOG_ERROR, "show_popup_toast");
567
568         Evas_Object *popup;
569
570         popup = elm_popup_add(app_data->win_main);
571         elm_object_style_set(popup, "toast/circle");
572         elm_popup_orient_set(popup, ELM_POPUP_ORIENT_BOTTOM);
573         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
574
575         if (check_img) {
576                 string path = get_resource_path();
577                 if (_WEARABLE)
578                         path = path + "wearable/";
579                 else if (_TV)
580                         path = path + "tv/";
581                 else
582                         path = path + "mobile/";
583                 string path_ic = path + "/images/toast_check_icon.png";
584                 Evas_Object * img = elm_image_add(popup);
585                 elm_image_file_set(img, path_ic.c_str(), NULL);
586                 elm_object_part_content_set(popup, "toast,icon", img);
587         }
588         if (text) {
589                 elm_object_part_text_set(popup, "elm.text", text);
590         }
591
592         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, _popup_back_cb, NULL);
593         evas_object_smart_callback_add(popup, "dismissed", _popup_close_cb, NULL);
594         evas_object_smart_callback_add(popup, "block,clicked", _popup_back_cb, NULL);
595
596         elm_popup_timeout_set(popup, 2.0);
597         evas_object_show(popup);
598 }
599
600 static void _popup_close_cb(void *data, Evas_Object *obj, void *event_info)
601 {
602         if (obj){
603                 evas_object_hide(obj);
604                 evas_object_del(obj);
605         }
606 }
607
608 static void _popup_back_cb(void *data, Evas_Object *obj, void *event_info)
609 {
610         if (obj)
611                 elm_popup_dismiss(obj);
612 }
613
614
615 void _back_to_genlist_for_selector()
616 {
617         PRINTFUNC(DLOG_DEBUG, "");
618
619         if (!app_data) return;
620
621         if (_WEARABLE) {
622                 Evas_Object *circle_genlist = (Evas_Object *) evas_object_data_get(app_data->genlist, "circle");
623                 eext_rotary_object_event_activated_set(circle_genlist, EINA_TRUE);
624         }
625         if (app_data->app_type == APP_TYPE_STT || app_data->app_type == APP_TYPE_EMOTICON || app_data->app_type == APP_TYPE_KEYBOARD){
626                 PRINTFUNC(DLOG_DEBUG, "launched as STT/EMOTICON/KEYBOARD mode, So exit here.");
627                 reply_to_sender_by_callback(NULL, NULL);
628                 ui_app_exit();
629         }
630 }
631
632 static void _item_realized(void *data, Evas_Object *obj, void *event_info) //called when list scrolled
633 {
634         PRINTFUNC(DLOG_DEBUG, "%s", __func__);
635 }
636
637 Evas_Object* _create_genlist(Evas_Object* navi)
638 {
639         Evas_Object* genlist = elm_genlist_add(navi);
640         if (NULL == genlist)
641                 return NULL;
642
643         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
644         if (_WEARABLE) {
645                 Evas_Object* circle_object_genlist = eext_circle_object_genlist_add(genlist, app_data->circle_surface);
646                 eext_circle_object_genlist_scroller_policy_set(circle_object_genlist, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
647                 evas_object_data_set(genlist, "circle", (void *) circle_object_genlist);
648                 eext_rotary_object_event_activated_set(circle_object_genlist, EINA_TRUE);
649         }
650         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
651         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
652
653         evas_object_smart_callback_add(genlist, "language,changed", __ise_gl_lang_changed, genlist);
654         evas_object_show(genlist);
655
656 //      uxt_genlist_set_bottom_margin_enabled(genlist, EINA_TRUE);
657
658         show_gl_focus(EINA_FALSE);
659
660         const char *item_style = NULL;
661         if (_WEARABLE)
662                 item_style = "empty";
663         Elm_Object_Item *nf_main_item = elm_naviframe_item_push(navi,
664             NULL,
665             NULL,
666             NULL,
667             genlist,
668             item_style);
669
670         elm_naviframe_item_pop_cb_set(nf_main_item, back_cb, app_data);
671         evas_object_smart_callback_add(genlist, "realized", _item_realized, NULL);
672
673         return genlist;
674 }
675
676 static void _item_position_changed_cb(void *data, Evas_Object *obj, void *event_info)
677 {
678         if (!obj) return;
679         if (!data) return;
680
681         Evas_Object *genlist = (Evas_Object *)obj;
682         Elm_Object_Item *gen_item = (Elm_Object_Item *)data;
683
684         Evas_Coord y;
685         elm_scroller_region_get(genlist, NULL, &y, NULL, NULL);
686
687 //      PRINTFUNC(DLOG_DEBUG,"y=%d",y);
688
689         if (250 > y && y >= 100){
690                 if (last_step == 0) return;
691                 last_step = 0;
692                 elm_object_item_signal_emit(gen_item, "elm,action,ime,0.0", "elm");
693                 show_gl_focus(EINA_TRUE);
694         } else if (100 > y && y >= 50){
695                 if (last_step == 1) return;
696                 last_step = 1;
697                 elm_object_item_signal_emit(gen_item, "elm,action,ime,0.1", "elm");
698                 show_gl_focus(EINA_TRUE);
699         } else if (y < 50 && y >=0){
700                 if (last_step == 2) return;
701                 last_step = 2;
702                 elm_object_item_signal_emit(gen_item, "elm,action,ime,0.9", "elm");
703                 show_gl_focus(EINA_FALSE);
704         }
705 }
706
707 static char *
708 _main_menu_title_text_get(void *data, Evas_Object *obj, const char *part)
709 {
710         char buf[1024];
711
712         snprintf(buf, 1023, "%s", "Select method");
713         return strdup(buf);
714 }
715
716 void _create_genlist_items(void* user_data)
717 {
718         App_Data* app_data = (App_Data*) user_data;
719
720         if (NULL == app_data->genlist) {
721                 app_data->genlist = _create_genlist(app_data->naviframe);
722                 if (NULL == app_data->genlist)
723                 return;
724         }
725
726         elm_genlist_clear(app_data->genlist);
727
728         Elm_Genlist_Item_Class * itc0 = elm_genlist_item_class_new();
729         itc0->item_style = "title";
730         itc0->func.text_get = _main_menu_title_text_get;
731         itc0->func.content_get = NULL;
732         itc0->func.state_get = NULL;
733         itc0->func.del = NULL;
734
735         Elm_Genlist_Item_Class * itc1 = elm_genlist_item_class_new();
736         if (g_input_type_data.input_type_array_len == 2){
737                 itc1->item_style = "2button_flat";
738                 itc1->func.text_get = NULL;
739                 itc1->func.content_get = __ise_gl_2button_content_get;
740                 itc1->func.state_get = NULL;
741                 itc1->func.del = NULL;
742         } else {
743                 itc1->item_style = "3button_flat";
744                 itc1->func.text_get = NULL;
745                 itc1->func.content_get = __ise_gl_3button_content_get;
746                 itc1->func.state_get = NULL;
747                 itc1->func.del = NULL;
748         }
749
750         // dummy title for empty space
751         it_empty = elm_genlist_item_append(app_data->genlist, itc0,
752                         NULL, NULL,
753                         ELM_GENLIST_ITEM_NONE,
754                         NULL, NULL);
755
756         // 3 Buttons
757         it_title = elm_genlist_item_append(app_data->genlist, itc1,
758                         NULL, NULL,
759                         ELM_GENLIST_ITEM_NONE,
760                         NULL, NULL);
761
762         elm_genlist_item_select_mode_set(it_title, ELM_OBJECT_SELECT_MODE_NONE);
763
764         g_template_item_size = _update_template_items(app_data);
765
766         Elm_Object_Item *item = elm_genlist_item_next_get(it_title);
767         elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
768
769         evas_object_smart_callback_add(app_data->genlist, "elm,item,position,changed", _item_position_changed_cb, it_title);
770
771         elm_genlist_item_class_free(itc0);
772         elm_genlist_item_class_free(itc1);
773 }
774
775 void _create_header_items(void *user_data)
776 {
777         Elm_Genlist_Item_Class * itc0 = elm_genlist_item_class_new();
778         itc0->item_style = "title";
779         itc0->func.text_get = NULL;
780         itc0->func.content_get = NULL;
781         itc0->func.state_get = NULL;
782         itc0->func.del = NULL;
783
784         Elm_Genlist_Item_Class * itc1 = elm_genlist_item_class_new();
785         if (g_input_type_data.input_type_array_len == 2) {
786                 itc1->item_style = "2button_flat";
787                 itc1->func.text_get = NULL;
788                 itc1->func.content_get = __ise_gl_2button_content_get;
789                 itc1->func.state_get = NULL;
790                 itc1->func.del = NULL;
791         } else {
792                 itc1->item_style = "3button_flat";
793                 itc1->func.text_get = NULL;
794                 itc1->func.content_get = __ise_gl_3button_content_get;
795                 itc1->func.state_get = NULL;
796                 itc1->func.del = NULL;
797         }
798
799         // dummy title for empty space
800         it_empty = elm_genlist_item_append(app_data->genlist, itc0,
801                                 NULL, NULL,
802                                 ELM_GENLIST_ITEM_NONE,
803                                 NULL, NULL);
804
805         // 3 Buttons
806         it_title = elm_genlist_item_append(app_data->genlist, itc1,
807                                                         NULL, NULL,
808                                                         ELM_GENLIST_ITEM_NONE,
809                                                         NULL, NULL);
810
811         elm_genlist_item_select_mode_set(it_title, ELM_OBJECT_SELECT_MODE_NONE);
812
813         elm_genlist_item_class_free(itc0);
814         elm_genlist_item_class_free(itc1);
815 }
816
817 void _update_genlist_items(void *user_data)
818 {
819         elm_genlist_clear(app_data->genlist);
820
821         _create_header_items(user_data);
822
823         if (input_smartreply_is_enabled())
824                 g_smartreply_item_size = _update_smartreply_items(user_data);
825         else
826                 g_smartreply_item_size = 0;
827
828         g_template_item_size = _update_template_items(user_data);
829
830         /* Update genlist item position */
831         Elm_Object_Item *item = elm_genlist_item_next_get(it_title);
832         elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
833 }
834
835 unsigned int _update_smartreply_items(void *user_data)
836 {
837         App_Data* app_data;
838
839         Elm_Object_Item *first;
840         Elm_Object_Item *menu;
841         Elm_Object_Item *pos;
842
843         unsigned int i = 0;
844         unsigned int len = 0;
845         unsigned int item_size = 0;
846
847         app_data = (App_Data *)user_data;
848
849         if (app_data == NULL) {
850                 PRINTFUNC(DLOG_ERROR, "Can not get app_data");
851                 return item_size;
852         }
853
854         if (app_data->genlist == NULL) {
855                 /* smartreply will update when genlist is exist only */
856                 PRINTFUNC(DLOG_ERROR, "Can not get getlist");
857                 return item_size;
858         }
859
860         /* Move to smartreply */
861         first = elm_genlist_first_item_get(app_data->genlist);
862         menu = elm_genlist_item_next_get(first);
863
864         if (input_smartreply_is_enabled() == false)
865                 return item_size;
866
867         /* Append newly added smartreply list */
868         len = input_smartreply_get_reply_num();
869
870         if (len > 0) {
871                 const std::vector<TemplateData>  template_list = input_template_get_list();
872
873                 Elm_Genlist_Item_Class *itc;
874
875                 itc = elm_genlist_item_class_new();
876                 itc->item_style = "1text";
877                 itc->func.text_get = __ise_smartreply_gl_text_get;
878                 itc->func.content_get = NULL;
879                 itc->func.state_get = NULL;
880                 itc->func.del = NULL;
881
882                 pos = menu;
883
884                 for (i = 0; i < len; i++) {
885                         char *reply = "hello";
886                         unsigned int j;
887                         bool matched;
888
889                         matched = false;
890
891                         int type;
892                         reply = input_smartreply_get_nth_item(i, &type);
893                         if (reply == NULL)
894                                 continue;
895                         PRINTFUNC(DLOG_DEBUG, "SmartReply = [%d]%s", i, reply);
896
897
898                         for (j = 0; j < template_list.size(); j++) {
899                                 const char *template_str;
900
901                                 if (template_list[j].use_gettext)
902                                         template_str = gettext(template_list[j].text.c_str());
903                                 else
904                                         template_str = template_list[j].text.c_str();
905
906                                 if (!__compare_string(reply, template_str)) {
907                                         matched = true;
908                                         break;
909                                 }
910                         }
911
912                         if (matched == true)
913                                 continue;
914
915                         pos = elm_genlist_item_append(app_data->genlist,
916                                                 itc,
917                                                 (void *)(uintptr_t)i,
918                                                 NULL,
919                                                 ELM_GENLIST_ITEM_NONE,
920                                                 __ise_smartreply_gl_sel,
921                                                 app_data);
922
923                         item_size++;
924                         if (item_size >= 3)
925                                 break;
926                 }
927                 elm_genlist_item_class_free(itc);
928         }
929         return item_size;
930 }
931
932
933 unsigned int _update_template_items(void *user_data)
934 {
935         App_Data* app_data;
936
937         Elm_Object_Item *first;
938         Elm_Object_Item *menu;
939         Elm_Object_Item *pos;
940
941         unsigned int i = 0;
942         unsigned int item_size = 0;
943
944         app_data = (App_Data *)user_data;
945
946         if (app_data == NULL) {
947                 PRINTFUNC(DLOG_ERROR, "Can not get app_data");
948                 return item_size;
949         }
950
951         if (app_data->genlist == NULL) {
952                 /* smartreply will update when genlist is exist only */
953                 PRINTFUNC(DLOG_ERROR, "Can not get getlist");
954                 return item_size;
955         }
956
957         first = elm_genlist_first_item_get(app_data->genlist);
958         if (first == NULL)
959                 return 0;
960         menu = elm_genlist_item_next_get(first);
961
962         pos = menu;
963         /* move to smartreply next if it need */
964         if (input_smartreply_is_enabled()) {
965                 unsigned int j = 0;
966
967                 for (j = 0; j < g_smartreply_item_size; j++) {
968                         if (pos == NULL)
969                                 break;
970
971                         pos = elm_genlist_item_next_get(pos);
972                 }
973         }
974
975         /* Append New Template list */
976         const std::vector<TemplateData> template_list = input_template_get_list();
977
978         if (template_list.size() > 0) {
979                 Elm_Genlist_Item_Class *itc;
980
981                 itc = elm_genlist_item_class_new();
982
983                 itc->item_style = "1text";
984                 itc->func.text_get = __ise_template_gl_text_get;
985                 itc->func.content_get = NULL;
986                 itc->func.state_get = NULL;
987                 itc->func.del = NULL;
988
989                 for (i = 0; i < template_list.size(); i++) {
990                         pos = elm_genlist_item_append(app_data->genlist,
991                                         itc,
992                                         (void *)(uintptr_t)i,
993                                         NULL,
994                                         ELM_GENLIST_ITEM_NONE,
995                                         __ise_template_gl_sel,
996                                         app_data);
997                         item_size++;
998                 }
999                 elm_genlist_item_class_free(itc);
1000         }
1001
1002         return item_size;
1003 }
1004
1005 bool __compare_string(const char * smart_str, const char * template_str)
1006 {
1007         int src_len = 0;
1008         int dst_len = 0;
1009         bool ret = true;
1010
1011         if(!smart_str||!template_str)
1012                 return ret;
1013
1014         src_len = strlen(smart_str);
1015         dst_len = strlen(template_str);
1016
1017         if(smart_str[src_len-1] == '.')
1018                 src_len--;
1019
1020         while(template_str[dst_len-1] == ' ')
1021                 dst_len--;
1022         if(template_str[dst_len-1] == '.')
1023                 dst_len--;
1024
1025         dst_len = (dst_len > src_len)? dst_len : src_len;
1026
1027         if(!strncmp(smart_str, template_str, (size_t)dst_len))
1028                 ret = false;
1029
1030         return (ret);
1031 }
1032
1033 bool _app_create(void* user_data)
1034 {
1035         int width = 1000, height = 1000;
1036 //      App_Data* app_data = NULL;
1037         Evas_Object* layout = NULL;
1038         Evas_Object* conform = NULL;
1039         Evas_Object* bg = NULL;
1040         Evas_Object* window = NULL;
1041         Eext_Circle_Surface *surface;
1042
1043         if (!user_data) {
1044                 return false;
1045         }
1046
1047         _app_language_changed(NULL, NULL);
1048
1049         app_data = (App_Data*)user_data;
1050
1051         elm_app_base_scale_set(1.3);
1052
1053         window = elm_win_add(NULL, PACKAGE, ELM_WIN_BASIC);
1054         if (window) {
1055                 init_customizing_theme();
1056
1057                 elm_win_title_set(window, PACKAGE);
1058                 elm_win_borderless_set(window, EINA_TRUE);
1059 //              ecore_x_window_size_get(ecore_x_window_root_first_get(), &width, &height);
1060                 evas_object_resize(window, width, height);
1061                 elm_win_indicator_mode_set(window, ELM_WIN_INDICATOR_SHOW);
1062         } else {
1063                 LOGE("elm_win_add() is failed.");
1064                 return false;
1065         }
1066
1067         bg = elm_bg_add(window);
1068         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1069         elm_win_resize_object_add(window, bg);
1070         evas_object_show(bg);
1071
1072         layout = elm_layout_add(window);
1073         elm_layout_theme_set(layout, "layout", "application", "default");
1074         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1075
1076         conform = elm_conformant_add(window);
1077         if (_WEARABLE)
1078                 surface = eext_circle_surface_conformant_add(conform);
1079
1080         evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1081
1082         elm_win_resize_object_add(window, conform);
1083         elm_object_content_set(conform, layout);
1084
1085         evas_object_show(layout);
1086         evas_object_show(conform);
1087         evas_object_show(window);
1088         app_data->win_main = window;
1089         app_data->conform = conform;
1090         app_data->layout_main = layout;
1091         app_data->circle_surface = surface;
1092         app_data->app_type = APP_TYPE_SELECT_MODE;
1093
1094         Evas_Object *naviframe = elm_naviframe_add(layout);
1095         elm_naviframe_prev_btn_auto_pushed_set(naviframe, EINA_FALSE);
1096         eext_object_event_callback_add(naviframe, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, NULL);
1097         elm_object_part_content_set(layout, "elm.swallow.content", naviframe);
1098         evas_object_show(naviframe);
1099
1100         app_data->naviframe = naviframe;
1101
1102         return true;
1103 }
1104
1105 void _app_service(app_control_h service, void* user_data)
1106 {
1107         int ret;
1108         char *context = NULL;
1109         char **input_type_array = NULL;
1110         int input_type_array_len = -1;
1111         bool is_extra_data_array = false;
1112
1113         app_control_clone(&(app_data->source_app_control), service);
1114         app_data->reply_type = REPLY_APP_NORMAL;
1115
1116         if (_TV || _MOBILE) {
1117                 app_data->app_type = APP_TYPE_KEYBOARD;
1118                 input_keyboard_init(service);
1119                 _keyboard_clicked_cb((void *)app_data, NULL, NULL);
1120                 goto ACTIVATE;
1121         }
1122
1123         ret = app_control_is_extra_data_array(service, APP_CONTROL_DATA_INPUT_TYPE, &is_extra_data_array);
1124         if ( is_extra_data_array == true) {
1125                 ret = app_control_get_extra_data_array(service, APP_CONTROL_DATA_INPUT_TYPE, &input_type_array, &input_type_array_len);
1126                 g_input_type_data.input_type_array = input_type_array;
1127                 g_input_type_data.input_type_array_len = input_type_array_len;
1128         } else {
1129                 ret = app_control_get_extra_data(service, APP_CONTROL_DATA_INPUT_TYPE, &context);
1130                 if (ret == APP_CONTROL_ERROR_NONE) {
1131                         if (!strcmp(context, "input_voice")) {
1132                                 app_data->app_type = APP_TYPE_STT;
1133                                 _stt_clicked_cb((void *)app_data, NULL, NULL);
1134                                 goto ACTIVATE;
1135                         } else if (!strcmp(context, "input_emoticon")) {
1136                                 app_data->app_type = APP_TYPE_EMOTICON;
1137                                 _emoticon_clicked_cb((void *)app_data, NULL, NULL);
1138                                 goto ACTIVATE;
1139                         } else if (!strcmp(context, "input_keyboard")) {
1140                                 app_data->app_type = APP_TYPE_KEYBOARD;
1141                                 input_keyboard_init(service);
1142                                 _keyboard_clicked_cb((void *)app_data, NULL, NULL);
1143                                 goto ACTIVATE;
1144                         } else if (!strcmp(context, "input_reply")) {
1145                                 app_data->app_type = APP_TYPE_REPLY;
1146                         }
1147                 }
1148         }
1149
1150         if (app_data->genlist == NULL)
1151                 app_data->genlist = _create_genlist(app_data->naviframe);
1152
1153         input_keyboard_init(service);
1154
1155         input_smartreply_init(service);
1156         input_smartreply_set_notify(_input_smartreply_notify_cb, NULL);
1157
1158         if (input_smartreply_is_enabled())
1159                 input_smartreply_get_reply_async();
1160
1161         input_template_init(service);
1162         input_template_set_notify(_input_template_notify_cb,  NULL);
1163
1164         _create_genlist_items(app_data);
1165
1166 ACTIVATE :
1167         elm_win_activate(app_data->win_main);
1168
1169         if (context)
1170                 free(context);
1171 }
1172
1173
1174 void _app_pause(void* user_data)
1175 {
1176         PRINTFUNC(DLOG_DEBUG, "");
1177         pause_voice();
1178 }
1179
1180 void _app_resume(void* user_data)
1181 {
1182         PRINTFUNC(DLOG_DEBUG, "");
1183 }
1184
1185 void _app_terminate(void* user_data)
1186 {
1187         App_Data* app_data = NULL;
1188         app_data = (App_Data*)user_data;
1189
1190         if (app_data->genlist){
1191                 evas_object_smart_callback_del(app_data->genlist, "elm,item,position,changed", _item_position_changed_cb);
1192         }
1193
1194         if (app_data->res_path)
1195                 free(app_data->res_path);
1196
1197         if (app_data->shared_res_path)
1198                 free(app_data->shared_res_path);
1199
1200         input_keyboard_deinit();
1201         input_smartreply_deinit();
1202
1203         input_template_unset_notify();
1204         input_template_deinit();
1205
1206         input_type_deinit();
1207 }
1208
1209 static int init_i18n(const char *domain, const char *dir, char *lang_str)
1210 {
1211         if (setlocale(LC_ALL, "") == NULL) {
1212                 PRINTFUNC(DLOG_INFO, "Some environment variable is invalid, setlocale(LC_ALL, \"\") has returns\ed a null pointer");
1213                 if (setlocale(LC_ALL, lang_str) == NULL)
1214                         return -1;
1215         }
1216         if (bindtextdomain(domain, dir) == NULL)
1217                 return -1;
1218         if (textdomain(domain) == NULL)
1219                 return -1;
1220
1221         return 0;
1222 }
1223
1224 /**
1225  * @brief Set language and locale.
1226  *
1227  * @return void
1228  */
1229 static void _app_language_changed(app_event_info_h event_info, void *user_data)
1230 {
1231         char* lang_str = vconf_get_str(VCONFKEY_LANGSET);
1232         if (lang_str) {
1233                 setenv("LANG", lang_str, 1);
1234                 setenv("LC_MESSAGES", lang_str, 1);
1235         } else {
1236                 setenv("LANG", "en_GB.utf8", 1);
1237                 setenv("LC_MESSAGES", "en_GB.utf8", 1);
1238                 lang_str = strdup("en_GB.UTF-8");
1239         }
1240
1241         init_i18n(PACKAGE, LOCALEDIR, lang_str);
1242
1243         if (lang_str) {
1244                 elm_language_set(lang_str);
1245                 free(lang_str);
1246         }
1247 }
1248
1249 void input_type_deinit(void)
1250 {
1251         int i = 0;
1252         char **data_array = NULL;
1253
1254         data_array = g_input_type_data.input_type_array;
1255         if (data_array) {
1256                 for (i = 0; i < g_input_type_data.input_type_array_len; i++) {
1257                         if (*(data_array + i))
1258                                 free(*(data_array + i));
1259                 }
1260                 free(data_array);
1261         }
1262         g_input_type_data.input_type_array = NULL;
1263         g_input_type_data.input_type_array_len = 0;
1264 }
1265
1266 EXPORTED int main(int argc, char* argv[])
1267 {
1268         App_Data app_data = {0, };
1269         ui_app_lifecycle_callback_s event_callback = {0, };
1270         app_event_handler_h handlers[5] = {NULL, };
1271
1272         event_callback.create = _app_create;
1273         event_callback.terminate = _app_terminate;
1274         event_callback.pause = _app_pause;
1275         event_callback.resume = _app_resume;
1276         event_callback.app_control = _app_service;
1277
1278         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, NULL, &app_data);
1279         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, NULL, &app_data);
1280         ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, NULL, &app_data);
1281         ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _app_language_changed, &app_data);
1282         ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, NULL, &app_data);
1283
1284         _init_app_data(&app_data);
1285
1286         int ret = ui_app_main(argc, argv, &event_callback, &app_data);
1287         if (ret != APP_ERROR_NONE) {
1288                 LOGD("ui_app_main() is failed. err = %d", ret);
1289         }
1290
1291         return ret;
1292 }