Change emoticon mode form rotary selector to list UI
[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
26 //#include "ui_extension.h"
27 #include "w-input-selector.h"
28 #include "w-input-keyboard.h"
29 #include "w-input-stt-ise.h"
30 #include "w-input-emoticon.h"
31 #include "w-input-stt-tos.h"
32
33 #include <stt.h>
34
35
36 using namespace std;
37
38 App_Data* app_data = NULL;
39
40 InputKeyboardData g_input_keyboard_data;
41 InputTypeData g_input_type_data;
42
43 static Elm_Object_Item *it_empty;
44 static Elm_Object_Item *it_title;
45
46 Evas_Coord last_step; // 0 ~ 9 for gesture, 10~11 for rotary
47
48 void _init_app_data(App_Data* app_data);
49 static void _app_language_changed(app_event_info_h event_info, void *user_data);
50
51 Evas_Object* _create_genlist(Evas_Object* parent);
52 void _create_genlist_items(void* user_data);
53 static void _popup_close_cb(void *data, Evas_Object *obj, void *event_info);
54 static void _popup_back_cb(void *data, Evas_Object *obj, void *event_info);
55 static void input_type_deinit(void);
56
57
58
59 void _init_app_data(App_Data* app_data)
60 {
61     app_data->win_main = NULL;
62     app_data->layout_main = NULL;
63     app_data->conform = NULL;
64     app_data->naviframe = NULL;
65     app_data->genlist = NULL;
66
67     app_data->res_path = NULL;
68 }
69
70
71
72 Evas_Object* load_edj(Evas_Object* parent, const char* file, const char* group)
73 {
74         Evas_Object* window;
75         Evas_Object* content;
76         int ret;
77
78         window = elm_layout_add(parent);
79         if (window) {
80                 ret = elm_layout_file_set(window, file, group);
81                 if (!ret) {
82                         evas_object_del(window);
83                         return NULL;
84                 }
85
86                 content = elm_layout_add(parent);
87                 elm_layout_theme_set(content, "layout", "application", "default");
88                 elm_object_part_content_set(window, "elm.swallow.content", content);
89
90                 evas_object_size_hint_weight_set(window, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
91         }
92
93         return window;
94 }
95
96 void init_customizing_theme(void)
97 {
98         string stt_edj_path = get_resource_path();
99         string app_edj_path = get_resource_path();
100
101         stt_edj_path = stt_edj_path + STT_EDJ_FILE;
102         app_edj_path = app_edj_path + APP_EDJ_FILE;
103
104         elm_theme_extension_add(NULL, stt_edj_path.c_str());
105         elm_theme_extension_add(NULL, app_edj_path.c_str());
106 }
107
108
109 static Eina_Bool back_cb(void *data, Elm_Object_Item *it)
110 {
111     reply_to_sender_by_callback_for_back();
112     elm_exit();
113     return EINA_FALSE;
114 }
115
116 static void _stt_clicked_cb(void *data, Evas_Object * obj, void *event_info)
117 {
118         App_Data* ad = (App_Data*)data;
119
120         PRINTFUNC(DLOG_DEBUG, "");
121
122         if(!ad)
123                 return;
124
125 #if 0
126         bool bAgreed = false;
127         stt_get_user_agreement(&bAgreed);
128         if(!bAgreed){
129 #endif
130         if(is_tos_N66_agreed() == EINA_FALSE){
131                 if(is_sap_connection() == EINA_TRUE){
132                         ise_show_tos_n66_popup(ad);
133                 } else {
134                         launch_bt_connection_popup(ad);
135                 }
136         } else {
137                 ise_show_stt_popup(ad);
138         }
139 }
140
141 static void _emoticon_clicked_cb(void *data, Evas_Object * obj, void *event_info)
142 {
143         App_Data* ad = (App_Data*)data;
144
145         PRINTFUNC(DLOG_DEBUG, "");
146
147         if(!ad)
148                 return;
149
150     ise_show_emoticon_list(ad);
151 }
152
153 static void _keyboard_clicked_cb(void *data, Evas_Object * obj, void *event_info)
154 {
155         App_Data* ad = (App_Data *)data;
156
157         PRINTFUNC(DLOG_DEBUG, "");
158
159         if (!ad)
160                 return;
161
162         input_keyboard_launch(ad->win_main, data);
163 }
164
165 static Evas_Object * __ise_gl_2button_content_get(void *data, Evas_Object *obj, const char *part)
166 {
167         char *first_input_type = *(g_input_type_data.input_type_array + 0);
168         char *second_input_type = *(g_input_type_data.input_type_array + 1);
169
170         if (!strcmp(part, "elm.icon.1") ||  (!strcmp(part, "elm.icon.2"))) {
171                 Evas_Object* btn = elm_button_add(obj);
172                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
173                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
174
175                 Evas_Object* ic = elm_image_add(btn);
176                 elm_image_resizable_set(ic, EINA_TRUE, EINA_TRUE);
177                 string path = get_resource_path();
178                 if (!strcmp(part, "elm.icon.1")) {
179                         string path_ic;
180                         if(!strcmp(first_input_type, "input_voice")) {
181                                 elm_object_style_set(btn, "ime_button_stt");
182                                 path_ic = path + "images/w_mode_stt_ic.png";
183                         } else if (!strcmp(first_input_type, "input_emoticon")) {
184                                 elm_object_style_set(btn, "ime_button_emoticon");
185                                 path_ic = path + "images/Delta_w_mode_emoticon_ic.png";
186                         } else if (!strcmp(first_input_type, "input_keyboard")) {
187                                 elm_object_style_set(btn, "ime_button_keyboard");
188                                 path_ic = path + "images/w_mode_keyboard_ic.png";
189                                 evas_object_propagate_events_set(btn, EINA_FALSE);
190                         }
191                         elm_image_file_set(ic, path_ic.c_str(), NULL);
192                         elm_object_content_set(btn, ic);
193                         evas_object_layer_set(btn, 32000);
194                 } else if (!strcmp(part, "elm.icon.2")){
195                         string path_ic;
196                         if(!strcmp(second_input_type, "input_voice")) {
197                                 elm_object_style_set(btn, "ime_button_stt");
198                                 path_ic = path + "images/w_mode_stt_ic.png";
199                         } else if (!strcmp(second_input_type, "input_emoticon")) {
200                                 elm_object_style_set(btn, "ime_button_emoticon");
201                                 path_ic = path + "images/Delta_w_mode_emoticon_ic.png";
202                         } else if (!strcmp(second_input_type, "input_keyboard")) {
203                                 elm_object_style_set(btn, "ime_button_keyboard");
204                                 path_ic = path + "images/w_mode_keyboard_ic.png";
205                                 evas_object_propagate_events_set(btn, EINA_FALSE);
206                         }
207                         elm_image_file_set(ic, path_ic.c_str(), NULL);
208                         elm_object_content_set(btn, ic);
209                         evas_object_layer_set(btn, 32000);
210                 }
211                 return btn;
212         } else if (!strcmp(part, "elm.icon.1.touch_area") ||  (!strcmp(part, "elm.icon.2.touch_area"))) {
213                 Evas_Object* btn = elm_button_add(obj);
214                 elm_object_style_set(btn, "touch_area");
215                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
216                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
217                 string path = get_resource_path();
218                 if (!strcmp(part, "elm.icon.1.touch_area")) {
219                         evas_object_layer_set(btn, 32000);
220                         if(!strcmp(first_input_type, "input_voice")) {
221                                 evas_object_smart_callback_add(btn, "clicked", _stt_clicked_cb, app_data);
222                         } else if (!strcmp(first_input_type, "input_emoticon")) {
223                                 evas_object_smart_callback_add(btn, "clicked", _emoticon_clicked_cb, app_data);
224                         } else if (!strcmp(first_input_type, "input_keyboard")) {
225                                 evas_object_propagate_events_set(btn, EINA_FALSE);
226                                 evas_object_smart_callback_add(btn, "clicked", _keyboard_clicked_cb, app_data);
227                         }
228                 } else if (!strcmp(part, "elm.icon.2.touch_area")){
229                         evas_object_layer_set(btn, 32000);
230                         if(!strcmp(second_input_type, "input_voice")) {
231                                 evas_object_smart_callback_add(btn, "clicked", _stt_clicked_cb, app_data);
232                         } else if (!strcmp(second_input_type, "input_emoticon")) {
233                                 evas_object_smart_callback_add(btn, "clicked", _emoticon_clicked_cb, app_data);
234                         } else if (!strcmp(second_input_type, "input_keyboard")) {
235                                 evas_object_propagate_events_set(btn, EINA_FALSE);
236                                 evas_object_smart_callback_add(btn, "clicked", _keyboard_clicked_cb, app_data);
237                         }
238                 }
239                 return btn;
240         } else if (!strcmp(part, "base")) {
241                 Evas_Object* btn = elm_button_add(obj);
242                 elm_object_style_set(btn, "ime_transparent");
243                 return btn;
244         }
245         return NULL;
246 }
247
248 static Evas_Object * __ise_gl_3button_content_get(void *data, Evas_Object *obj, const char *part)
249 {
250         if (!strcmp(part, "elm.icon.1") ||  (!strcmp(part, "elm.icon.2")) ||  (!strcmp(part, "elm.icon.3"))) {
251                 Evas_Object* btn = elm_button_add(obj);
252                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
253                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
254                 Evas_Object* ic = elm_image_add(btn);
255                 elm_image_resizable_set(ic, EINA_TRUE, EINA_TRUE);
256                 string path = get_resource_path();
257                 if (!strcmp(part, "elm.icon.1")) {
258                         elm_object_style_set(btn, "ime_button_stt");
259                         string path_ic = path + "images/w_mode_stt_ic.png";
260                         elm_image_file_set(ic, path_ic.c_str(), NULL);
261                         elm_object_content_set(btn, ic);
262                         evas_object_layer_set(btn, 32000);
263
264                 } else if (!strcmp(part, "elm.icon.2")){
265                         elm_object_style_set(btn, "ime_button_emoticon");
266                         string path_ic = path + "images/Delta_w_mode_emoticon_ic.png";
267                         elm_image_file_set(ic, path_ic.c_str(), NULL);
268                         elm_object_content_set(btn, ic);
269                         evas_object_layer_set(btn, 32000);
270
271                 } else if (!strcmp(part, "elm.icon.3")){
272                         elm_object_style_set(btn, "ime_button_keyboard");
273                         string path_ic = path + "images/w_mode_keyboard_ic.png";
274                         elm_image_file_set(ic, path_ic.c_str(), NULL);
275                         elm_object_content_set(btn, ic);
276                         evas_object_layer_set(btn, 32000);
277                         evas_object_propagate_events_set(btn, EINA_FALSE);
278                 }
279
280                 return btn;
281         } else if (!strcmp(part, "elm.icon.1.touch_area") ||  (!strcmp(part, "elm.icon.2.touch_area")) ||  (!strcmp(part, "elm.icon.3.touch_area"))) {
282                 Evas_Object* btn = elm_button_add(obj);
283                 elm_object_style_set(btn, "touch_area");
284                 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
285                 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
286                 string path = get_resource_path();
287                 if (!strcmp(part, "elm.icon.1.touch_area")) {
288                         evas_object_layer_set(btn, 32000);
289                         evas_object_smart_callback_add(btn, "clicked", _stt_clicked_cb, app_data);
290
291                 } else if (!strcmp(part, "elm.icon.2.touch_area")){
292                         evas_object_layer_set(btn, 32000);
293                         evas_object_smart_callback_add(btn, "clicked", _emoticon_clicked_cb, app_data);
294                 } else if (!strcmp(part, "elm.icon.3.touch_area")) {
295                         evas_object_layer_set(btn, 32000);
296                         evas_object_propagate_events_set(btn, EINA_FALSE);
297                         evas_object_smart_callback_add(btn, "clicked", _keyboard_clicked_cb, app_data);
298                 }
299
300                 return btn;
301         } else if (!strcmp(part, "base")) {
302                 Evas_Object* btn = elm_button_add(obj);
303                 elm_object_style_set(btn, "ime_transparent");
304                 return btn;
305         }
306         return NULL;
307 }
308
309
310 static void __ise_gl_lang_changed(void *data, Evas_Object *obj, void *event_info)
311 {
312         //Update genlist items. The Item texts will be translated in the _gl_text_get().
313         elm_genlist_realized_items_update(obj);
314 }
315
316 void set_source_caller_app_id(app_control_h app_control)
317 {
318         if(!app_control){
319                 PRINTFUNC(DLOG_ERROR, "can't get app_control");
320                 return;
321         }
322
323         char *caller = NULL;
324         app_control_get_caller(app_data->source_app_control, &caller);
325
326         if(caller){
327                 PRINTFUNC(DLOG_DEBUG, "caller = %s", caller);
328                 app_control_add_extra_data(app_control, "caller_appid", caller);
329                 free(caller);
330         }
331 }
332
333 void reply_to_sender_by_callback(const char *value, const char *type)
334 {
335         PRINTFUNC(DLOG_DEBUG, "");
336
337         app_control_h app_control;
338
339         if(app_control_create(&app_control) == 0) {
340                 int ret;
341
342                 if (value)
343                         app_control_add_extra_data(app_control, APP_CONTROL_DATA_TEXT, value);
344
345                 if (type)
346                         app_control_add_extra_data(app_control, "reply_type", type);
347
348                 set_source_caller_app_id(app_control);
349
350                 ret = app_control_reply_to_launch_request(app_control, app_data->source_app_control, APP_CONTROL_RESULT_SUCCEEDED);
351                 if (ret != APP_CONTROL_ERROR_NONE)
352                         PRINTFUNC(DLOG_ERROR, "reply failed : %d", ret);
353
354                 app_control_destroy(app_control);
355                 app_control_destroy(app_data->source_app_control);
356                 app_data->source_app_control = NULL;
357         }
358 }
359
360 void reply_to_sender_by_callback_for_back()
361 {
362         PRINTFUNC(DLOG_DEBUG, "");
363
364         app_control_h app_control;
365
366         if(app_control_create(&app_control) == 0) {
367                 int ret;
368
369                 app_control_add_extra_data(app_control, "back_to_composer", "yes");
370
371                 ret = app_control_reply_to_launch_request(app_control, app_data->source_app_control, APP_CONTROL_RESULT_SUCCEEDED);
372                 if (ret != APP_CONTROL_ERROR_NONE)
373                         PRINTFUNC(DLOG_ERROR, "reply failed : %d", ret);
374
375                 app_control_destroy(app_control);
376                 app_control_destroy(app_data->source_app_control);
377                 app_data->source_app_control = NULL;
378         }
379 }
380
381 char* get_resource_path()
382 {
383         if(NULL == app_data->res_path) {
384                 app_data->res_path = app_get_resource_path();
385                 PRINTFUNC(DLOG_INFO, "set resource path = %s", app_data->res_path);
386         }
387         return (app_data->res_path);
388 }
389
390 char* get_shared_resource_path()
391 {
392         if(NULL == app_data->shared_res_path) {
393                 app_data->shared_res_path = app_get_shared_resource_path();
394                 PRINTFUNC(DLOG_INFO, "set shared resource path = %s", app_data->shared_res_path);
395         }
396         return (app_data->shared_res_path);
397 }
398
399 void show_gl_focus(Eina_Bool bVisible){
400         if(app_data->genlist == NULL)
401                 return;
402
403         if(bVisible == EINA_TRUE){
404                 elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,enable", "elm");
405                 //elm_layout_theme_set(app_data->genlist, "genlist", "base", "focus_bg");
406                 //elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,show", "elm");
407         } else {
408                 elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,disable", "elm");
409                 //elm_layout_theme_set(app_data->genlist, "genlist", "base", "default");
410                 //elm_object_signal_emit(app_data->genlist, "elm,state,focus_bg,hide", "elm");
411         }
412 }
413
414 void show_popup_toast(const char *text, bool check_img)
415 {
416         PRINTFUNC(DLOG_ERROR, "show_popup_toast");
417
418         Evas_Object *popup;
419
420         popup = elm_popup_add(app_data->win_main);
421         elm_object_style_set(popup, "toast/circle");
422         elm_popup_orient_set(popup, ELM_POPUP_ORIENT_BOTTOM);
423         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
424
425         if (check_img) {
426                 string path = get_resource_path();
427                 string path_ic = path + "/images/toast_check_icon.png";
428                 Evas_Object * img = elm_image_add(popup);
429                 elm_image_file_set(img, path_ic.c_str(), NULL);
430                 elm_object_part_content_set(popup, "toast,icon", img);
431         }
432         if(text) {
433                 elm_object_part_text_set(popup, "elm.text", text);
434         }
435
436         eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, _popup_back_cb, NULL);
437         evas_object_smart_callback_add(popup, "dismissed", _popup_close_cb, NULL);
438         evas_object_smart_callback_add(popup, "block,clicked", _popup_back_cb, NULL);
439
440         elm_popup_timeout_set(popup, 2.0);
441         evas_object_show(popup);
442 }
443
444 static void _popup_close_cb(void *data, Evas_Object *obj, void *event_info)
445 {
446         if(obj){
447                 evas_object_hide(obj);
448                 evas_object_del(obj);
449         }
450 }
451
452 static void _popup_back_cb(void *data, Evas_Object *obj, void *event_info)
453 {
454         if(obj)
455                 elm_popup_dismiss(obj);
456 }
457
458
459 void _back_to_genlist_for_selector()
460 {
461         PRINTFUNC(DLOG_DEBUG, "");
462
463         if(!app_data) return;
464
465         if(app_data->app_type == APP_TYPE_STT || app_data->app_type == APP_TYPE_EMOTICON){
466                 PRINTFUNC(DLOG_DEBUG, "launched as STT/EMOTICON mode, So exit here.");
467                 reply_to_sender_by_callback(NULL, NULL);
468                 elm_exit();
469         }
470
471         Evas_Object *circle_genlist = (Evas_Object *) evas_object_data_get(app_data->genlist, "circle");
472
473         eext_rotary_object_event_activated_set(circle_genlist, EINA_TRUE);
474 }
475
476 static void _item_realized(void *data, Evas_Object *obj, void *event_info) //called when list scrolled
477 {
478         PRINTFUNC(DLOG_DEBUG, "%s", __func__);
479 }
480
481 Evas_Object* _create_genlist(Evas_Object* navi)
482 {
483         Evas_Object* genlist = elm_genlist_add(navi);
484         if(NULL == genlist)
485                 return NULL;
486
487         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
488
489         Evas_Object* circle_object_genlist = eext_circle_object_genlist_add(genlist, app_data->circle_surface);
490         eext_circle_object_genlist_scroller_policy_set(circle_object_genlist, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
491         evas_object_data_set(genlist, "circle", (void *) circle_object_genlist);
492         eext_rotary_object_event_activated_set(circle_object_genlist, EINA_TRUE);
493
494         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
495         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
496
497         evas_object_smart_callback_add(genlist, "language,changed", __ise_gl_lang_changed, genlist);
498         evas_object_show(genlist);
499
500 //      uxt_genlist_set_bottom_margin_enabled(genlist, EINA_TRUE);
501
502         show_gl_focus(EINA_FALSE);
503
504         Elm_Object_Item *nf_main_item = elm_naviframe_item_push(navi,
505             NULL,
506             NULL,
507             NULL,
508             genlist,
509             "empty");
510
511         elm_naviframe_item_pop_cb_set(nf_main_item, back_cb, app_data);
512         evas_object_smart_callback_add(genlist, "realized", _item_realized, NULL);
513
514         return genlist;
515 }
516
517 static void _item_position_changed_cb(void *data, Evas_Object *obj, void *event_info)
518 {
519         if(!obj) return;
520         if(!data) return;
521
522         Evas_Object *genlist = (Evas_Object *)obj;
523         Elm_Object_Item *gen_item = (Elm_Object_Item *)data;
524
525         Evas_Coord y;
526         elm_scroller_region_get(genlist, NULL, &y, NULL, NULL);
527
528 //      PRINTFUNC(DLOG_DEBUG,"y=%d",y);
529
530         if (250 > y && y >= 100){
531                 if (last_step == 0) return;
532                 last_step = 0;
533                 elm_object_item_signal_emit(gen_item, "elm,action,ime,0.0", "elm");
534                 show_gl_focus(EINA_TRUE);
535         } else if (100 > y && y >= 50){
536                 if (last_step == 1) return;
537                 last_step = 1;
538                 elm_object_item_signal_emit(gen_item, "elm,action,ime,0.1", "elm");
539                 show_gl_focus(EINA_TRUE);
540         } else if (y < 50 && y >=0){
541                 if (last_step == 2) return;
542                 last_step = 2;
543                 elm_object_item_signal_emit(gen_item, "elm,action,ime,0.9", "elm");
544                 show_gl_focus(EINA_FALSE);
545         }
546 }
547
548 static char *
549 _main_menu_title_text_get(void *data, Evas_Object *obj, const char *part)
550 {
551         char buf[1024];
552
553         snprintf(buf, 1023, "%s", "Select method");
554         return strdup(buf);
555 }
556
557 void _create_genlist_items(void* user_data)
558 {
559         LOGD("[psw] _create_genlist_items");
560
561         App_Data* app_data = (App_Data*) user_data;
562
563         if(NULL == app_data->genlist) {
564                 app_data->genlist = _create_genlist(app_data->naviframe);
565                 if(NULL == app_data->genlist)
566                 return;
567         }
568
569         elm_genlist_clear(app_data->genlist);
570
571         Elm_Genlist_Item_Class * itc0 = elm_genlist_item_class_new();
572         itc0->item_style = "title";
573         itc0->func.text_get = _main_menu_title_text_get;
574         itc0->func.content_get = NULL;
575         itc0->func.state_get = NULL;
576         itc0->func.del = NULL;
577
578         Elm_Genlist_Item_Class * itc1 = elm_genlist_item_class_new();
579         if(g_input_type_data.input_type_array_len == 2){
580                 itc1->item_style = "2button_flat";
581                 itc1->func.text_get = NULL;
582                 itc1->func.content_get = __ise_gl_2button_content_get;
583                 itc1->func.state_get = NULL;
584                 itc1->func.del = NULL;
585         } else {
586                 itc1->item_style = "3button_flat";
587                 itc1->func.text_get = NULL;
588                 itc1->func.content_get = __ise_gl_3button_content_get;
589                 itc1->func.state_get = NULL;
590                 itc1->func.del = NULL;
591         }
592
593         // dummy title for empty space
594         it_empty = elm_genlist_item_append(app_data->genlist, itc0,
595                         NULL, NULL,
596                         ELM_GENLIST_ITEM_NONE,
597                         NULL, NULL);
598
599         // 3 Buttons
600         it_title = elm_genlist_item_append(app_data->genlist, itc1,
601                         NULL, NULL,
602                         ELM_GENLIST_ITEM_NONE,
603                         NULL, NULL);
604
605         elm_genlist_item_select_mode_set(it_title, ELM_OBJECT_SELECT_MODE_NONE);
606
607         Elm_Object_Item *item = elm_genlist_item_next_get(it_title);
608         elm_genlist_item_show(item, ELM_GENLIST_ITEM_SCROLLTO_MIDDLE);
609
610         evas_object_smart_callback_add(app_data->genlist, "elm,item,position,changed", _item_position_changed_cb, it_title);
611
612         elm_genlist_item_class_free(itc0);
613         elm_genlist_item_class_free(itc1);
614 }
615
616 bool _app_create(void* user_data)
617 {
618         int width = 1000, height = 1000;
619 //      App_Data* app_data = NULL;
620         Evas_Object* layout = NULL;
621         Evas_Object* conform = NULL;
622         Evas_Object* bg = NULL;
623         Evas_Object* window = NULL;
624         Eext_Circle_Surface *surface;
625
626         if (!user_data) {
627                 return false;
628         }
629
630         _app_language_changed(NULL, NULL);
631
632         app_data = (App_Data*)user_data;
633
634         elm_app_base_scale_set(1.3);
635
636         window = elm_win_add(NULL, PACKAGE, ELM_WIN_BASIC);
637         if (window) {
638                 init_customizing_theme();
639
640                 elm_win_title_set(window, PACKAGE);
641                 elm_win_borderless_set(window, EINA_TRUE);
642 //              ecore_x_window_size_get(ecore_x_window_root_first_get(), &width, &height);
643                 evas_object_resize(window, width, height);
644                 elm_win_indicator_mode_set(window, ELM_WIN_INDICATOR_SHOW);
645         } else {
646                 LOGE("elm_win_add() is failed.");
647                 return false;
648         }
649
650         bg = elm_bg_add(window);
651         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
652         elm_win_resize_object_add(window, bg);
653         evas_object_show(bg);
654
655         layout = elm_layout_add(window);
656         elm_layout_theme_set(layout, "layout", "application", "default");
657         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
658
659         conform = elm_conformant_add(window);
660         surface = eext_circle_surface_conformant_add(conform);
661         evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
662
663
664         elm_win_resize_object_add(window, conform);
665         elm_object_content_set(conform, layout);
666
667         evas_object_show(layout);
668         evas_object_show(conform);
669         evas_object_show(window);
670         app_data->win_main = window;
671         app_data->conform = conform;
672         app_data->layout_main = layout;
673         app_data->circle_surface = surface;
674         app_data->app_type = APP_TYPE_SELECT_MODE;
675
676         Evas_Object *naviframe = elm_naviframe_add(layout);
677         elm_naviframe_prev_btn_auto_pushed_set(naviframe, EINA_FALSE);
678         eext_object_event_callback_add(naviframe, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, NULL);
679         elm_object_part_content_set(layout, "elm.swallow.content", naviframe);
680         evas_object_show(naviframe);
681
682         app_data->naviframe = naviframe;
683
684         return true;
685 }
686
687 void _app_service(app_control_h service, void* user_data)
688 {
689         int ret;
690         char *context = NULL;
691         char **input_type_array = NULL;
692         int input_type_array_len = -1;
693         bool is_extra_data_array = false;
694
695         app_control_clone(&(app_data->source_app_control), service);
696         app_data->reply_type = REPLY_APP_NORMAL;
697
698         ret = app_control_is_extra_data_array(service, APP_CONTROL_DATA_INPUT_TYPE, &is_extra_data_array);
699         if( is_extra_data_array == true) {
700                 ret = app_control_get_extra_data_array(service, APP_CONTROL_DATA_INPUT_TYPE, &input_type_array, &input_type_array_len);
701                 g_input_type_data.input_type_array = input_type_array;
702                 g_input_type_data.input_type_array_len = input_type_array_len;
703         } else {
704                 ret = app_control_get_extra_data(service, APP_CONTROL_DATA_INPUT_TYPE, &context);
705                 if (ret == APP_CONTROL_ERROR_NONE) {
706                         if (!strcmp(context, "input_voice")) {
707                                 app_data->app_type = APP_TYPE_STT;
708                                 _stt_clicked_cb((void *)app_data, NULL, NULL);
709                                 goto ACTIVATE;
710                         } else if (!strcmp(context, "input_emoticon")) {
711                                 app_data->app_type = APP_TYPE_EMOTICON;
712                                 _emoticon_clicked_cb((void *)app_data, NULL, NULL);
713                                 goto ACTIVATE;
714                         } else if (!strcmp(context, "input_keyboard")) {
715                                 app_data->app_type = APP_TYPE_KEYBOARD;
716                                 input_keyboard_init(service);
717                                 _keyboard_clicked_cb((void *)app_data, NULL, NULL);
718                                 goto ACTIVATE;
719                         } else if (!strcmp(context, "input_reply")) {
720                                 app_data->app_type = APP_TYPE_REPLY;
721                         }
722                 }
723         }
724
725         if (app_data->genlist == NULL)
726                 app_data->genlist = _create_genlist(app_data->naviframe);
727
728         input_keyboard_init(service);
729
730         _create_genlist_items(app_data);
731
732 ACTIVATE :
733         elm_win_activate(app_data->win_main);
734
735         if(context)
736                 free(context);
737 }
738
739
740 void _app_pause(void* user_data)
741 {
742         PRINTFUNC(DLOG_DEBUG, "");
743         pause_voice();
744 }
745
746 void _app_resume(void* user_data)
747 {
748         PRINTFUNC(DLOG_DEBUG, "");
749 }
750
751 void _app_terminate(void* user_data)
752 {
753         App_Data* app_data = NULL;
754         app_data = (App_Data*)user_data;
755
756         if(app_data->genlist){
757                 evas_object_smart_callback_del(app_data->genlist, "elm,item,position,changed", _item_position_changed_cb);
758         }
759
760         if(app_data->res_path)
761                 free(app_data->res_path);
762
763         if(app_data->shared_res_path)
764                 free(app_data->shared_res_path);
765
766         input_keyboard_deinit();
767         input_type_deinit();
768 }
769
770 static int init_i18n(const char *domain, const char *dir, char *lang_str)
771 {
772         if (setlocale(LC_ALL, "") == NULL) {
773                 PRINTFUNC(DLOG_INFO, "Some environment variable is invalid, setlocale(LC_ALL, \"\") has returns\ed a null pointer");
774                 if (setlocale(LC_ALL, lang_str) == NULL)
775                         return -1;
776         }
777         if (bindtextdomain(domain, dir) == NULL)
778                 return -1;
779         if (textdomain(domain) == NULL)
780                 return -1;
781
782         return 0;
783 }
784
785 /**
786  * @brief Set language and locale.
787  *
788  * @return void
789  */
790 static void _app_language_changed(app_event_info_h event_info, void *user_data)
791 {
792         char* lang_str = vconf_get_str(VCONFKEY_LANGSET);
793         if (lang_str) {
794                 setenv("LANG", lang_str, 1);
795                 setenv("LC_MESSAGES", lang_str, 1);
796         } else {
797                 setenv("LANG", "en_GB.utf8", 1);
798                 setenv("LC_MESSAGES", "en_GB.utf8", 1);
799                 lang_str = strdup("en_GB.UTF-8");
800         }
801
802         init_i18n(PACKAGE, LOCALEDIR, lang_str);
803
804         if (lang_str) {
805                 elm_language_set(lang_str);
806                 free(lang_str);
807         }
808 }
809
810 void input_type_deinit(void)
811 {
812         int i = 0;
813         char **data_array = NULL;
814
815         data_array = g_input_type_data.input_type_array;
816         if (data_array) {
817                 for (i = 0; i < g_input_type_data.input_type_array_len; i++) {
818                         if (*(data_array + i))
819                                 free(*(data_array + i));
820                 }
821                 free(data_array);
822         }
823         g_input_type_data.input_type_array = NULL;
824         g_input_type_data.input_type_array_len = 0;
825 }
826
827 int main(int argc, char* argv[])
828 {
829         App_Data app_data = {0, };
830         ui_app_lifecycle_callback_s event_callback = {0, };
831         app_event_handler_h handlers[5] = {NULL, };
832
833         event_callback.create = _app_create;
834         event_callback.terminate = _app_terminate;
835         event_callback.pause = _app_pause;
836         event_callback.resume = _app_resume;
837         event_callback.app_control = _app_service;
838
839         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, NULL, &app_data);
840         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, NULL, &app_data);
841         ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, NULL, &app_data);
842         ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, _app_language_changed, &app_data);
843         ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, NULL, &app_data);
844
845         _init_app_data(&app_data);
846
847         int ret = ui_app_main(argc, argv, &event_callback, &app_data);
848         if (ret != APP_ERROR_NONE) {
849                 LOGD("ui_app_main() is failed. err = %d", ret);
850         }
851
852         return ret;
853 }