Support to delegate various MIME types to caller as like voice recording
[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", NULL);
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", NULL);
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, const char *path[])
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                 if (path != NULL) {
499                         app_control_add_extra_data_array(app_control, APP_CONTROL_DATA_PATH, path, 1);
500                 }
501
502                 set_source_caller_app_id(app_control);
503
504                 ret = app_control_reply_to_launch_request(app_control, app_data->source_app_control, APP_CONTROL_RESULT_SUCCEEDED);
505                 if (ret != APP_CONTROL_ERROR_NONE)
506                         PRINTFUNC(DLOG_ERROR, "reply failed : %d", ret);
507
508                 app_control_destroy(app_control);
509                 app_control_destroy(app_data->source_app_control);
510                 app_data->source_app_control = NULL;
511         }
512 }
513
514 void reply_to_sender_by_callback_for_back()
515 {
516         PRINTFUNC(DLOG_DEBUG, "");
517
518         app_control_h app_control;
519
520         if (app_control_create(&app_control) == 0) {
521                 int ret;
522
523                 app_control_add_extra_data(app_control, "back_to_composer", "yes");
524
525                 ret = app_control_reply_to_launch_request(app_control, app_data->source_app_control, APP_CONTROL_RESULT_SUCCEEDED);
526                 if (ret != APP_CONTROL_ERROR_NONE)
527                         PRINTFUNC(DLOG_ERROR, "reply failed : %d", ret);
528
529                 app_control_destroy(app_control);
530                 app_control_destroy(app_data->source_app_control);
531                 app_data->source_app_control = NULL;
532         }
533 }
534
535 char* get_resource_path()
536 {
537         if (NULL == app_data->res_path) {
538                 app_data->res_path = app_get_resource_path();
539                 PRINTFUNC(DLOG_INFO, "set resource path = %s", app_data->res_path);
540         }
541         return (app_data->res_path);
542 }
543
544 char* get_shared_resource_path()
545 {
546         if (NULL == app_data->shared_res_path) {
547                 app_data->shared_res_path = app_get_shared_resource_path();
548                 PRINTFUNC(DLOG_INFO, "set shared resource path = %s", app_data->shared_res_path);
549         }
550         return (app_data->shared_res_path);
551 }
552
553 void show_gl_focus(Eina_Bool bVisible){
554         if (app_data->genlist == NULL)
555                 return;
556
557         if (bVisible == EINA_TRUE){
558                 elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,enable", "elm");
559                 //elm_layout_theme_set(app_data->genlist, "genlist", "base", "focus_bg");
560                 //elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,show", "elm");
561         } else {
562                 elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,disable", "elm");
563                 //elm_layout_theme_set(app_data->genlist, "genlist", "base", "default");
564                 //elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,hide", "elm");
565         }
566 }
567
568 void show_popup_toast(const char *text, bool check_img)
569 {
570         PRINTFUNC(DLOG_ERROR, "show_popup_toast");
571
572         Evas_Object *popup;
573
574         popup = elm_popup_add(app_data->win_main);
575         elm_object_style_set(popup, "toast/circle");
576         elm_popup_orient_set(popup, ELM_POPUP_ORIENT_BOTTOM);
577         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
578
579         if (check_img) {
580                 string path = get_resource_path();
581                 if (_WEARABLE)
582                         path = path + "wearable/";
583                 else if (_TV)
584                         path = path + "tv/";
585                 else
586                         path = path + "mobile/";
587                 string path_ic = path + "/images/toast_check_icon.png";
588                 Evas_Object * img = elm_image_add(popup);
589                 elm_image_file_set(img, path_ic.c_str(), NULL);
590                 elm_object_part_content_set(popup, "toast,icon", img);
591         }
592         if (text) {
593                 elm_object_part_text_set(popup, "elm.text", text);
594         }
595
596         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, _popup_back_cb, NULL);
597         evas_object_smart_callback_add(popup, "dismissed", _popup_close_cb, NULL);
598         evas_object_smart_callback_add(popup, "block,clicked", _popup_back_cb, NULL);
599
600         elm_popup_timeout_set(popup, 2.0);
601         evas_object_show(popup);
602 }
603
604 static void _popup_close_cb(void *data, Evas_Object *obj, void *event_info)
605 {
606         if (obj){
607                 evas_object_hide(obj);
608                 evas_object_del(obj);
609         }
610 }
611
612 static void _popup_back_cb(void *data, Evas_Object *obj, void *event_info)
613 {
614         if (obj)
615                 elm_popup_dismiss(obj);
616 }
617
618
619 void _back_to_genlist_for_selector()
620 {
621         PRINTFUNC(DLOG_DEBUG, "");
622
623         if (!app_data) return;
624
625         if (_WEARABLE) {
626                 Evas_Object *circle_genlist = (Evas_Object *) evas_object_data_get(app_data->genlist, "circle");
627                 eext_rotary_object_event_activated_set(circle_genlist, EINA_TRUE);
628         }
629         if (app_data->app_type == APP_TYPE_STT || app_data->app_type == APP_TYPE_EMOTICON || app_data->app_type == APP_TYPE_KEYBOARD){
630                 PRINTFUNC(DLOG_DEBUG, "launched as STT/EMOTICON/KEYBOARD mode, So exit here.");
631                 reply_to_sender_by_callback(NULL, NULL, NULL);
632                 ui_app_exit();
633         }
634 }
635
636 static void _item_realized(void *data, Evas_Object *obj, void *event_info) //called when list scrolled
637 {
638         PRINTFUNC(DLOG_DEBUG, "%s", __func__);
639 }
640
641 Evas_Object* _create_genlist(Evas_Object* navi)
642 {
643         Evas_Object* genlist = elm_genlist_add(navi);
644         if (NULL == genlist)
645                 return NULL;
646
647         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
648         if (_WEARABLE) {
649                 Evas_Object* circle_object_genlist = eext_circle_object_genlist_add(genlist, app_data->circle_surface);
650                 eext_circle_object_genlist_scroller_policy_set(circle_object_genlist, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
651                 evas_object_data_set(genlist, "circle", (void *) circle_object_genlist);
652                 eext_rotary_object_event_activated_set(circle_object_genlist, EINA_TRUE);
653         }
654         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
655         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
656
657         evas_object_smart_callback_add(genlist, "language,changed", __ise_gl_lang_changed, genlist);
658         evas_object_show(genlist);
659
660 //      uxt_genlist_set_bottom_margin_enabled(genlist, EINA_TRUE);
661
662         show_gl_focus(EINA_FALSE);
663
664         const char *item_style = NULL;
665         if (_WEARABLE)
666                 item_style = "empty";
667         Elm_Object_Item *nf_main_item = elm_naviframe_item_push(navi,
668             NULL,
669             NULL,
670             NULL,
671             genlist,
672             item_style);
673
674         elm_naviframe_item_pop_cb_set(nf_main_item, back_cb, app_data);
675         evas_object_smart_callback_add(genlist, "realized", _item_realized, NULL);
676
677         return genlist;
678 }
679
680 static void _item_position_changed_cb(void *data, Evas_Object *obj, void *event_info)
681 {
682         if (!obj) return;
683         if (!data) return;
684
685         Evas_Object *genlist = (Evas_Object *)obj;
686         Elm_Object_Item *gen_item = (Elm_Object_Item *)data;
687
688         Evas_Coord y;
689         elm_scroller_region_get(genlist, NULL, &y, NULL, NULL);
690
691 //      PRINTFUNC(DLOG_DEBUG,"y=%d",y);
692
693         if (250 > y && y >= 100){
694                 if (last_step == 0) return;
695                 last_step = 0;
696                 elm_object_item_signal_emit(gen_item, "elm,action,ime,0.0", "elm");
697                 show_gl_focus(EINA_TRUE);
698         } else if (100 > y && y >= 50){
699                 if (last_step == 1) return;
700                 last_step = 1;
701                 elm_object_item_signal_emit(gen_item, "elm,action,ime,0.1", "elm");
702                 show_gl_focus(EINA_TRUE);
703         } else if (y < 50 && y >=0){
704                 if (last_step == 2) return;
705                 last_step = 2;
706                 elm_object_item_signal_emit(gen_item, "elm,action,ime,0.9", "elm");
707                 show_gl_focus(EINA_FALSE);
708         }
709 }
710
711 static char *
712 _main_menu_title_text_get(void *data, Evas_Object *obj, const char *part)
713 {
714         char buf[1024];
715
716         snprintf(buf, 1023, "%s", "Select method");
717         return strdup(buf);
718 }
719
720 void _create_genlist_items(void* user_data)
721 {
722         App_Data* app_data = (App_Data*) user_data;
723
724         if (NULL == app_data->genlist) {
725                 app_data->genlist = _create_genlist(app_data->naviframe);
726                 if (NULL == app_data->genlist)
727                 return;
728         }
729
730         elm_genlist_clear(app_data->genlist);
731
732         Elm_Genlist_Item_Class * itc0 = elm_genlist_item_class_new();
733         itc0->item_style = "title";
734         itc0->func.text_get = _main_menu_title_text_get;
735         itc0->func.content_get = NULL;
736         itc0->func.state_get = NULL;
737         itc0->func.del = NULL;
738
739         Elm_Genlist_Item_Class * itc1 = elm_genlist_item_class_new();
740         if (g_input_type_data.input_type_array_len == 2){
741                 itc1->item_style = "2button_flat";
742                 itc1->func.text_get = NULL;
743                 itc1->func.content_get = __ise_gl_2button_content_get;
744                 itc1->func.state_get = NULL;
745                 itc1->func.del = NULL;
746         } else {
747                 itc1->item_style = "3button_flat";
748                 itc1->func.text_get = NULL;
749                 itc1->func.content_get = __ise_gl_3button_content_get;
750                 itc1->func.state_get = NULL;
751                 itc1->func.del = NULL;
752         }
753
754         // dummy title for empty space
755         it_empty = elm_genlist_item_append(app_data->genlist, itc0,
756                         NULL, NULL,
757                         ELM_GENLIST_ITEM_NONE,
758                         NULL, NULL);
759
760         // 3 Buttons
761         it_title = elm_genlist_item_append(app_data->genlist, itc1,
762                         NULL, NULL,
763                         ELM_GENLIST_ITEM_NONE,
764                         NULL, NULL);
765
766         elm_genlist_item_select_mode_set(it_title, ELM_OBJECT_SELECT_MODE_NONE);
767
768         g_template_item_size = _update_template_items(app_data);
769
770         Elm_Object_Item *item = elm_genlist_item_next_get(it_title);
771         elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
772
773         evas_object_smart_callback_add(app_data->genlist, "elm,item,position,changed", _item_position_changed_cb, it_title);
774
775         elm_genlist_item_class_free(itc0);
776         elm_genlist_item_class_free(itc1);
777 }
778
779 void _create_header_items(void *user_data)
780 {
781         Elm_Genlist_Item_Class * itc0 = elm_genlist_item_class_new();
782         itc0->item_style = "title";
783         itc0->func.text_get = NULL;
784         itc0->func.content_get = NULL;
785         itc0->func.state_get = NULL;
786         itc0->func.del = NULL;
787
788         Elm_Genlist_Item_Class * itc1 = elm_genlist_item_class_new();
789         if (g_input_type_data.input_type_array_len == 2) {
790                 itc1->item_style = "2button_flat";
791                 itc1->func.text_get = NULL;
792                 itc1->func.content_get = __ise_gl_2button_content_get;
793                 itc1->func.state_get = NULL;
794                 itc1->func.del = NULL;
795         } else {
796                 itc1->item_style = "3button_flat";
797                 itc1->func.text_get = NULL;
798                 itc1->func.content_get = __ise_gl_3button_content_get;
799                 itc1->func.state_get = NULL;
800                 itc1->func.del = NULL;
801         }
802
803         // dummy title for empty space
804         it_empty = elm_genlist_item_append(app_data->genlist, itc0,
805                                 NULL, NULL,
806                                 ELM_GENLIST_ITEM_NONE,
807                                 NULL, NULL);
808
809         // 3 Buttons
810         it_title = elm_genlist_item_append(app_data->genlist, itc1,
811                                                         NULL, NULL,
812                                                         ELM_GENLIST_ITEM_NONE,
813                                                         NULL, NULL);
814
815         elm_genlist_item_select_mode_set(it_title, ELM_OBJECT_SELECT_MODE_NONE);
816
817         elm_genlist_item_class_free(itc0);
818         elm_genlist_item_class_free(itc1);
819 }
820
821 void _update_genlist_items(void *user_data)
822 {
823         elm_genlist_clear(app_data->genlist);
824
825         _create_header_items(user_data);
826
827         if (input_smartreply_is_enabled())
828                 g_smartreply_item_size = _update_smartreply_items(user_data);
829         else
830                 g_smartreply_item_size = 0;
831
832         g_template_item_size = _update_template_items(user_data);
833
834         /* Update genlist item position */
835         Elm_Object_Item *item = elm_genlist_item_next_get(it_title);
836         elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
837 }
838
839 unsigned int _update_smartreply_items(void *user_data)
840 {
841         App_Data* app_data;
842
843         Elm_Object_Item *first;
844         Elm_Object_Item *menu;
845         Elm_Object_Item *pos;
846
847         unsigned int i = 0;
848         unsigned int len = 0;
849         unsigned int item_size = 0;
850
851         app_data = (App_Data *)user_data;
852
853         if (app_data == NULL) {
854                 PRINTFUNC(DLOG_ERROR, "Can not get app_data");
855                 return item_size;
856         }
857
858         if (app_data->genlist == NULL) {
859                 /* smartreply will update when genlist is exist only */
860                 PRINTFUNC(DLOG_ERROR, "Can not get getlist");
861                 return item_size;
862         }
863
864         /* Move to smartreply */
865         first = elm_genlist_first_item_get(app_data->genlist);
866         menu = elm_genlist_item_next_get(first);
867
868         if (input_smartreply_is_enabled() == false)
869                 return item_size;
870
871         /* Append newly added smartreply list */
872         len = input_smartreply_get_reply_num();
873
874         if (len > 0) {
875                 const std::vector<TemplateData>  template_list = input_template_get_list();
876
877                 Elm_Genlist_Item_Class *itc;
878
879                 itc = elm_genlist_item_class_new();
880                 itc->item_style = "1text";
881                 itc->func.text_get = __ise_smartreply_gl_text_get;
882                 itc->func.content_get = NULL;
883                 itc->func.state_get = NULL;
884                 itc->func.del = NULL;
885
886                 pos = menu;
887
888                 for (i = 0; i < len; i++) {
889                         char *reply = "hello";
890                         unsigned int j;
891                         bool matched;
892
893                         matched = false;
894
895                         int type;
896                         reply = input_smartreply_get_nth_item(i, &type);
897                         if (reply == NULL)
898                                 continue;
899                         PRINTFUNC(DLOG_DEBUG, "SmartReply = [%d]%s", i, reply);
900
901
902                         for (j = 0; j < template_list.size(); j++) {
903                                 const char *template_str;
904
905                                 if (template_list[j].use_gettext)
906                                         template_str = gettext(template_list[j].text.c_str());
907                                 else
908                                         template_str = template_list[j].text.c_str();
909
910                                 if (!__compare_string(reply, template_str)) {
911                                         matched = true;
912                                         break;
913                                 }
914                         }
915
916                         if (matched == true)
917                                 continue;
918
919                         pos = elm_genlist_item_append(app_data->genlist,
920                                                 itc,
921                                                 (void *)(uintptr_t)i,
922                                                 NULL,
923                                                 ELM_GENLIST_ITEM_NONE,
924                                                 __ise_smartreply_gl_sel,
925                                                 app_data);
926
927                         item_size++;
928                         if (item_size >= 3)
929                                 break;
930                 }
931                 elm_genlist_item_class_free(itc);
932         }
933         return item_size;
934 }
935
936
937 unsigned int _update_template_items(void *user_data)
938 {
939         App_Data* app_data;
940
941         Elm_Object_Item *first;
942         Elm_Object_Item *menu;
943         Elm_Object_Item *pos;
944
945         unsigned int i = 0;
946         unsigned int item_size = 0;
947
948         app_data = (App_Data *)user_data;
949
950         if (app_data == NULL) {
951                 PRINTFUNC(DLOG_ERROR, "Can not get app_data");
952                 return item_size;
953         }
954
955         if (app_data->genlist == NULL) {
956                 /* smartreply will update when genlist is exist only */
957                 PRINTFUNC(DLOG_ERROR, "Can not get getlist");
958                 return item_size;
959         }
960
961         first = elm_genlist_first_item_get(app_data->genlist);
962         if (first == NULL)
963                 return 0;
964         menu = elm_genlist_item_next_get(first);
965
966         pos = menu;
967         /* move to smartreply next if it need */
968         if (input_smartreply_is_enabled()) {
969                 unsigned int j = 0;
970
971                 for (j = 0; j < g_smartreply_item_size; j++) {
972                         if (pos == NULL)
973                                 break;
974
975                         pos = elm_genlist_item_next_get(pos);
976                 }
977         }
978
979         /* Append New Template list */
980         const std::vector<TemplateData> template_list = input_template_get_list();
981
982         if (template_list.size() > 0) {
983                 Elm_Genlist_Item_Class *itc;
984
985                 itc = elm_genlist_item_class_new();
986
987                 itc->item_style = "1text";
988                 itc->func.text_get = __ise_template_gl_text_get;
989                 itc->func.content_get = NULL;
990                 itc->func.state_get = NULL;
991                 itc->func.del = NULL;
992
993                 for (i = 0; i < template_list.size(); i++) {
994                         pos = elm_genlist_item_append(app_data->genlist,
995                                         itc,
996                                         (void *)(uintptr_t)i,
997                                         NULL,
998                                         ELM_GENLIST_ITEM_NONE,
999                                         __ise_template_gl_sel,
1000                                         app_data);
1001                         item_size++;
1002                 }
1003                 elm_genlist_item_class_free(itc);
1004         }
1005
1006         return item_size;
1007 }
1008
1009 bool __compare_string(const char * smart_str, const char * template_str)
1010 {
1011         int src_len = 0;
1012         int dst_len = 0;
1013         bool ret = true;
1014
1015         if(!smart_str||!template_str)
1016                 return ret;
1017
1018         src_len = strlen(smart_str);
1019         dst_len = strlen(template_str);
1020
1021         if(smart_str[src_len-1] == '.')
1022                 src_len--;
1023
1024         while(template_str[dst_len-1] == ' ')
1025                 dst_len--;
1026         if(template_str[dst_len-1] == '.')
1027                 dst_len--;
1028
1029         dst_len = (dst_len > src_len)? dst_len : src_len;
1030
1031         if(!strncmp(smart_str, template_str, (size_t)dst_len))
1032                 ret = false;
1033
1034         return (ret);
1035 }
1036
1037 bool _app_create(void* user_data)
1038 {
1039         int width = 1000, height = 1000;
1040 //      App_Data* app_data = NULL;
1041         Evas_Object* layout = NULL;
1042         Evas_Object* conform = NULL;
1043         Evas_Object* bg = NULL;
1044         Evas_Object* window = NULL;
1045         Eext_Circle_Surface *surface = NULL;
1046
1047         if (!user_data) {
1048                 return false;
1049         }
1050
1051         _app_language_changed(NULL, NULL);
1052
1053         app_data = (App_Data*)user_data;
1054
1055         elm_app_base_scale_set(1.3);
1056
1057         window = elm_win_add(NULL, PACKAGE, ELM_WIN_BASIC);
1058         if (window) {
1059                 init_customizing_theme();
1060
1061                 elm_win_title_set(window, PACKAGE);
1062                 elm_win_borderless_set(window, EINA_TRUE);
1063 //              ecore_x_window_size_get(ecore_x_window_root_first_get(), &width, &height);
1064                 evas_object_resize(window, width, height);
1065                 elm_win_indicator_mode_set(window, ELM_WIN_INDICATOR_SHOW);
1066         } else {
1067                 LOGE("elm_win_add() is failed.");
1068                 return false;
1069         }
1070
1071         bg = elm_bg_add(window);
1072         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1073         elm_win_resize_object_add(window, bg);
1074         evas_object_show(bg);
1075
1076         layout = elm_layout_add(window);
1077         elm_layout_theme_set(layout, "layout", "application", "default");
1078         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1079
1080         conform = elm_conformant_add(window);
1081         if (_WEARABLE)
1082                 surface = eext_circle_surface_conformant_add(conform);
1083
1084         evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1085
1086         elm_win_resize_object_add(window, conform);
1087         elm_object_content_set(conform, layout);
1088
1089         evas_object_show(layout);
1090         evas_object_show(conform);
1091         evas_object_show(window);
1092         app_data->win_main = window;
1093         app_data->conform = conform;
1094         app_data->layout_main = layout;
1095         app_data->circle_surface = surface;
1096         app_data->app_type = APP_TYPE_SELECT_MODE;
1097
1098         Evas_Object *naviframe = elm_naviframe_add(layout);
1099         elm_naviframe_prev_btn_auto_pushed_set(naviframe, EINA_FALSE);
1100         eext_object_event_callback_add(naviframe, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, NULL);
1101         elm_object_part_content_set(layout, "elm.swallow.content", naviframe);
1102         evas_object_show(naviframe);
1103
1104         app_data->naviframe = naviframe;
1105
1106         return true;
1107 }
1108
1109 void _app_service(app_control_h service, void* user_data)
1110 {
1111         int ret;
1112         char *context = NULL;
1113         char **input_type_array = NULL;
1114         int input_type_array_len = -1;
1115         bool is_extra_data_array = false;
1116
1117         app_control_clone(&(app_data->source_app_control), service);
1118         app_data->reply_type = REPLY_APP_NORMAL;
1119
1120         if (_TV || _MOBILE) {
1121                 app_data->app_type = APP_TYPE_KEYBOARD;
1122                 input_keyboard_init(service);
1123                 _keyboard_clicked_cb((void *)app_data, NULL, NULL);
1124                 goto ACTIVATE;
1125         }
1126
1127         ret = app_control_is_extra_data_array(service, APP_CONTROL_DATA_INPUT_TYPE, &is_extra_data_array);
1128         if ( is_extra_data_array == true) {
1129                 ret = app_control_get_extra_data_array(service, APP_CONTROL_DATA_INPUT_TYPE, &input_type_array, &input_type_array_len);
1130                 g_input_type_data.input_type_array = input_type_array;
1131                 g_input_type_data.input_type_array_len = input_type_array_len;
1132         } else {
1133                 ret = app_control_get_extra_data(service, APP_CONTROL_DATA_INPUT_TYPE, &context);
1134                 if (ret == APP_CONTROL_ERROR_NONE) {
1135                         if (!strcmp(context, "input_voice")) {
1136                                 app_data->app_type = APP_TYPE_STT;
1137                                 _stt_clicked_cb((void *)app_data, NULL, NULL);
1138                                 goto ACTIVATE;
1139                         } else if (!strcmp(context, "input_emoticon")) {
1140                                 app_data->app_type = APP_TYPE_EMOTICON;
1141                                 _emoticon_clicked_cb((void *)app_data, NULL, NULL);
1142                                 goto ACTIVATE;
1143                         } else if (!strcmp(context, "input_keyboard")) {
1144                                 app_data->app_type = APP_TYPE_KEYBOARD;
1145                                 input_keyboard_init(service);
1146                                 _keyboard_clicked_cb((void *)app_data, NULL, NULL);
1147                                 goto ACTIVATE;
1148                         } else if (!strcmp(context, "input_reply")) {
1149                                 app_data->app_type = APP_TYPE_REPLY;
1150                         }
1151                 }
1152         }
1153
1154         if (app_data->genlist == NULL)
1155                 app_data->genlist = _create_genlist(app_data->naviframe);
1156
1157         input_keyboard_init(service);
1158
1159         input_smartreply_init(service);
1160         input_smartreply_set_notify(_input_smartreply_notify_cb, NULL);
1161
1162         if (input_smartreply_is_enabled())
1163                 input_smartreply_get_reply_async();
1164
1165         input_template_init(service);
1166         input_template_set_notify(_input_template_notify_cb,  NULL);
1167
1168         _create_genlist_items(app_data);
1169
1170 ACTIVATE :
1171         elm_win_activate(app_data->win_main);
1172
1173         if (context)
1174                 free(context);
1175 }
1176
1177
1178 void _app_pause(void* user_data)
1179 {
1180         PRINTFUNC(DLOG_DEBUG, "");
1181         pause_voice();
1182 }
1183
1184 void _app_resume(void* user_data)
1185 {
1186         PRINTFUNC(DLOG_DEBUG, "");
1187 }
1188
1189 void _app_terminate(void* user_data)
1190 {
1191         App_Data* app_data = NULL;
1192         app_data = (App_Data*)user_data;
1193
1194         if (app_data->genlist){
1195                 evas_object_smart_callback_del(app_data->genlist, "elm,item,position,changed", _item_position_changed_cb);
1196         }
1197
1198         if (app_data->res_path)
1199                 free(app_data->res_path);
1200
1201         if (app_data->shared_res_path)
1202                 free(app_data->shared_res_path);
1203
1204         input_keyboard_deinit();
1205         input_smartreply_deinit();
1206
1207         input_template_unset_notify();
1208         input_template_deinit();
1209
1210         input_type_deinit();
1211 }
1212
1213 static int init_i18n(const char *domain, const char *dir, char *lang_str)
1214 {
1215         if (setlocale(LC_ALL, "") == NULL) {
1216                 PRINTFUNC(DLOG_INFO, "Some environment variable is invalid, setlocale(LC_ALL, \"\") has returns\ed a null pointer");
1217                 if (setlocale(LC_ALL, lang_str) == NULL)
1218                         return -1;
1219         }
1220         if (bindtextdomain(domain, dir) == NULL)
1221                 return -1;
1222         if (textdomain(domain) == NULL)
1223                 return -1;
1224
1225         return 0;
1226 }
1227
1228 /**
1229  * @brief Set language and locale.
1230  *
1231  * @return void
1232  */
1233 static void _app_language_changed(app_event_info_h event_info, void *user_data)
1234 {
1235         char* lang_str = vconf_get_str(VCONFKEY_LANGSET);
1236         if (lang_str) {
1237                 setenv("LANG", lang_str, 1);
1238                 setenv("LC_MESSAGES", lang_str, 1);
1239         } else {
1240                 setenv("LANG", "en_GB.utf8", 1);
1241                 setenv("LC_MESSAGES", "en_GB.utf8", 1);
1242                 lang_str = strdup("en_GB.UTF-8");
1243         }
1244
1245         init_i18n(PACKAGE, LOCALEDIR, lang_str);
1246
1247         if (lang_str) {
1248                 elm_language_set(lang_str);
1249                 free(lang_str);
1250         }
1251 }
1252
1253 void input_type_deinit(void)
1254 {
1255         int i = 0;
1256         char **data_array = NULL;
1257
1258         data_array = g_input_type_data.input_type_array;
1259         if (data_array) {
1260                 for (i = 0; i < g_input_type_data.input_type_array_len; i++) {
1261                         if (*(data_array + i))
1262                                 free(*(data_array + i));
1263                 }
1264                 free(data_array);
1265         }
1266         g_input_type_data.input_type_array = NULL;
1267         g_input_type_data.input_type_array_len = 0;
1268 }
1269
1270 EXPORTED int main(int argc, char* argv[])
1271 {
1272         App_Data app_data = {0, };
1273         ui_app_lifecycle_callback_s event_callback = {0, };
1274         app_event_handler_h handlers[5] = {NULL, };
1275
1276         event_callback.create = _app_create;
1277         event_callback.terminate = _app_terminate;
1278         event_callback.pause = _app_pause;
1279         event_callback.resume = _app_resume;
1280         event_callback.app_control = _app_service;
1281
1282         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, NULL, &app_data);
1283         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, NULL, &app_data);
1284         ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, NULL, &app_data);
1285         ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _app_language_changed, &app_data);
1286         ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, NULL, &app_data);
1287
1288         _init_app_data(&app_data);
1289
1290         int ret = ui_app_main(argc, argv, &event_callback, &app_data);
1291         if (ret != APP_ERROR_NONE) {
1292                 LOGD("ui_app_main() is failed. err = %d", ret);
1293         }
1294
1295         return ret;
1296 }