Fix issue that Black screen displayed when exiting Voice input screen
[platform/core/uifw/inputdelegator.git] / src / w-input-stt-voice.cpp
index 56514f7..d39c87c 100755 (executable)
 #include <string>
 #include <efl_extension.h>
 #include <feedback.h>
+#include <stdint.h>
 
 #include "Debug.h"
 #include "w-input-selector.h"
 #include "w-input-stt-voice.h"
 #include "w-input-stt-engine.h"
 #include "w-input-stt-ise.h"
+#include "voice-recorder.h"
 
 using namespace std;
 
@@ -40,7 +42,7 @@ using namespace std;
 #define GRP_PORTRAIT "mic_control"
 
 #define item_append(obj, style, index, cb, udata) \
-               elm_genlist_item_append(obj, &(style), (void *)index, NULL, ELM_GENLIST_ITEM_NONE, cb, udata)
+               elm_genlist_item_append(obj, &(style), (void *)(uintptr_t)index, NULL, ELM_GENLIST_ITEM_NONE, cb, udata)
 
 #define VIRTUAL_TEXT_AREA_FONT_STYLE \
                "DEFAULT='font=Tizen:style=Regular  font_size=32 color=#FFFFFF color_class=AT013 text_class=tizen wrap=mixed align=center' \
@@ -472,10 +474,15 @@ static void on_confirm_button_clicked_cb(void *data, Evas_Object *obj, void *eve
 
        PRINTFUNC(DLOG_DEBUG, "result_text = %s", result_text.c_str());
 
-       reply_to_sender_by_callback(result_text.c_str(), "voice");
+       char *filePath = NULL;
+       voice_recorder *vr = _voice_recorder_get_data();
+       if (!vr)
+               filePath = vr->file_path;
+       char *path[] = {filePath, };
+       reply_to_sender_by_callback(result_text.c_str(), "voice", (const char **)path);
        destroy_voice();
        powerUnlock();
-       elm_exit();
+       ui_app_exit();
 
        return;
 }
@@ -562,14 +569,13 @@ static Eina_Bool _idler_cb(void *data)
        Evas_Object *canvas = elm_object_part_content_get(voicedata->layout_main, "EFFECT_BG");
 
        is::ui::WInputSttMicEffect *ieffect = new is::ui::WInputSttMicEffect();
-       if (ieffect)
+       if (ieffect) {
                ieffect->SetSttHandle(voicedata->sttmanager->GetSttHandle());
 
-       is::ui::MicEffector *effector = new is::ui::MicEffector(canvas, voicedata->layout_main, *ieffect);
-       voicedata->ieffect = ieffect;
-       voicedata->effector = effector;
+               is::ui::MicEffector *effector = new is::ui::MicEffector(canvas, voicedata->layout_main, *ieffect);
+               voicedata->ieffect = ieffect;
+               voicedata->effector = effector;
 
-       if (ieffect) {
                ieffect->SetProgressBar(voicedata->progressbar);
                ieffect->SetSttHandle(voicedata->sttmanager->GetSttHandle());
        }
@@ -778,6 +784,9 @@ static Eina_Bool _start_timer_cb(void* data)
                }
                voicedata->start_timer = NULL;
        }
+
+       start_voice_recorder();
+
        return ECORE_CALLBACK_CANCEL;
 }
 
@@ -886,11 +895,12 @@ static inline void ea_naviframe_back(void *data, Evas_Object *obj, void *event_i
                ecore_event_handler_del(g_evt_key_down);
 
        g_evt_key_down = NULL;
-
-       //Hide more option
-       if(g_more_option_layout){
-               if(eext_more_option_opened_get(g_more_option_layout) == EINA_TRUE) {
-                       eext_more_option_opened_set(g_more_option_layout, EINA_FALSE);
+       if (_WEARABLE) {
+               //Hide more option
+               if(g_more_option_layout){
+                       if(eext_more_option_opened_get(g_more_option_layout) == EINA_TRUE) {
+                               eext_more_option_opened_set(g_more_option_layout, EINA_FALSE);
+                       }
                }
        }
 }
@@ -902,30 +912,31 @@ static char *__get_genlist_title_label(void *data, Evas_Object *obj, const char
 
 char *__get_genlist_item_label(void *data, Evas_Object *obj, const char *part)
 {
-       char text[128] = {0, };
+       const int BUF_LEN = 128;
+       char text[BUF_LEN] = {'\0', };
 
        if(!strcmp(part, "elm.text"))
        {
-               if((int)data == 0) {
+               if((uintptr_t)data == 0) {
                        return strdup(_("IDS_VC_BODY_AUTOMATIC"));
                } else {
                        char *s = NULL;
-                       s = (char *)disp_lang_array[(int)data];
+                       s = (char *)disp_lang_array[(uintptr_t)data];
 
                        if(s) {
                                char *p = strchr(s, '(');
                                if(p) {
                                        strncpy(text, s, p-s);
                                } else {
-                                       strncpy(text, s, strlen(s));
+                                       snprintf(text, BUF_LEN, "%s", s);
                                }
                        } else {
-                               strncpy(text, "", strlen(""));
+                               snprintf(text, BUF_LEN, "%s", "");
                        }
                }
                return strdup(text);
        } else if (!strcmp(part, "elm.text.1")) {
-               if ((int)data == 0) {
+               if ((uintptr_t)data == 0) {
                        char* value = NULL;
                        value = vconf_get_str(VCONFKEY_LANGSET);
                        if (NULL == value) {
@@ -945,17 +956,17 @@ char *__get_genlist_item_label(void *data, Evas_Object *obj, const char *part)
 
                } else {
                        char *s = NULL;
-                       s = (char *)disp_lang_array[(int)data];
+                       s = (char *)disp_lang_array[(uintptr_t)data];
 
                        if(s) {
                                char *p = strchr(s, '(');
                                if(p) {
                                        strncpy(text, p+1, strlen(s)-(p-s)-2);
                                } else {
-                                       strncpy(text, s, strlen(s));
+                                       snprintf(text, BUF_LEN, "%s", s);
                                }
                        } else {
-                               strncpy(text, "", strlen(""));
+                               snprintf(text, BUF_LEN, "%s", "");
                        }
                        return strdup(text);
                }
@@ -1103,7 +1114,7 @@ static void language_set_genlist_radio_cb(void *data, Evas_Object *obj, void *ev
        Elm_Object_Item * item = (Elm_Object_Item *) event_info;
        if (item) {
                elm_genlist_item_selected_set(item, 0);
-               index = (int)elm_object_item_data_get(item);
+               index = (uintptr_t)elm_object_item_data_get(item);
                elm_genlist_item_update(item);
        }
        set_language_value(index);
@@ -1169,16 +1180,16 @@ static Evas_Object *create_language_list(Evas_Object *parent)
        itc_title.item_style = "title";
        itc_title.func.text_get = __get_genlist_title_label;
        itc_title.func.content_get = NULL;
-#ifdef _WEARABLE
-       item = elm_genlist_item_append(genlist, &itc_title, (void *)-1, NULL, ELM_GENLIST_ITEM_GROUP, NULL, genlist);
-#endif
+       if (_WEARABLE) {
+               item = elm_genlist_item_append(genlist, &itc_title, (void *)-1, NULL, ELM_GENLIST_ITEM_GROUP, NULL, genlist);
+       }
 
        // 2 line text
-#ifdef _WEARABLE
-       itc_2text.item_style = "2text.1icon.1/sub1.multiline";
-#else
-       itc_2text.item_style = "type1";
-#endif
+       if (_WEARABLE) {
+               itc_2text.item_style = "2text.1icon.1/sub1.multiline";
+       } else {
+               itc_2text.item_style = "type1";
+       }
        itc_2text.func.text_get = __get_genlist_item_label;
        itc_2text.func.content_get = __get_genlist_item_content;
 
@@ -1195,11 +1206,11 @@ static Evas_Object *create_language_list(Evas_Object *parent)
        }
 
        // 1 line text
-#ifdef _WEARABLE
-       itc_1text.item_style = "1text.1icon.1";
-#else
-       itc_1text.item_style = "type1";
-#endif
+       if (_WEARABLE) {
+               itc_1text.item_style = "1text.1icon.1";
+       } else {
+               itc_1text.item_style = "type1";
+       }
        itc_1text.func.text_get = __get_genlist_item_label;
        itc_1text.func.content_get = __get_genlist_item_content;
 
@@ -1321,8 +1332,11 @@ void create_setting_window(Evas_Object *more_option_layout)
         */
        genlist = create_language_list(naviframe);
 
+       const char *item_style = NULL;
+       if (_WEARABLE)
+               item_style = "empty";
        //item = elm_naviframe_item_push(naviframe, "IDS_VC_HEADER_VOICE_INPUT_LANGUAGE", NULL, NULL, genlist, NULL);
-       elm_naviframe_item_push(naviframe, NULL, NULL, NULL, genlist, "empty");
+       elm_naviframe_item_push(naviframe, NULL, NULL, NULL, genlist, item_style);
        //elm_object_item_domain_text_translatable_set(item, PACKAGE, EINA_TRUE);
 
        g_setting_window = window;
@@ -1386,8 +1400,12 @@ static void __stt_detailed_entry_del_cb(void *data, Evas *e, Evas_Object *obj, v
 static Evas_Object *create_text_detiled_view(Evas_Object *parent)
 {
        string edj_path = get_resource_path();
-       edj_path = edj_path + STT_EDJ_FILE;
-
+       if(_WEARABLE)
+               edj_path = edj_path + STT_EDJ_FILE_WEARABLE;
+       else if (_TV)
+               edj_path = edj_path + STT_EDJ_FILE_TV;
+       else
+               edj_path = edj_path + STT_EDJ_FILE_MOBILE;
        //layout
        Evas_Object *layout = elm_layout_add(parent);
        elm_layout_file_set(layout, edj_path.c_str(), "entry_focused_layout");
@@ -1511,11 +1529,12 @@ void activate_circle_scroller_for_stt_textbox(void* data, Eina_Bool bActivate)
        VoiceData *voicedata = (VoiceData *)data;
 
        Evas_Object *scroller = NULL;
-       Evas_Object *circle_scroller = NULL;
-
        scroller = elm_layout_content_get((Evas_Object *)voicedata->layout_main, "text_area");
-       circle_scroller = (Evas_Object *) evas_object_data_get(scroller, "circle");
-       eext_rotary_object_event_activated_set(circle_scroller, bActivate);
+       if (_WEARABLE) {
+               Evas_Object *circle_scroller = NULL;
+               circle_scroller = (Evas_Object *) evas_object_data_get(scroller, "circle");
+               eext_rotary_object_event_activated_set(circle_scroller, bActivate);
+       }
 }
 
 static Evas_Object *create_textblock(void* data)
@@ -1531,7 +1550,12 @@ static Evas_Object *create_textblock(void* data)
        Evas_Object *circle_scroller = NULL;
 
        string edj_path = get_resource_path();
-       edj_path = edj_path + STT_EDJ_FILE;
+       if(_WEARABLE)
+               edj_path = edj_path + STT_EDJ_FILE_WEARABLE;
+       else if (_TV)
+               edj_path = edj_path + STT_EDJ_FILE_TV;
+       else
+               edj_path = edj_path + STT_EDJ_FILE_MOBILE;
 
        scroller = elm_scroller_add(voicedata->layout_main);
 
@@ -1544,13 +1568,11 @@ static Evas_Object *create_textblock(void* data)
        elm_scroller_page_scroll_limit_set(scroller, 0, 1);
 
        elm_object_scroll_lock_x_set(scroller, EINA_TRUE);
-
-//     uxt_scroller_set_auto_scroll_enabled(scroller, EINA_FALSE);
-
-       circle_scroller = eext_circle_object_scroller_add(scroller, app_data->circle_surface);
-       eext_circle_object_scroller_policy_set(circle_scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
-       eext_rotary_object_event_activated_set(circle_scroller, EINA_TRUE);
-
+       if (_WEARABLE) {
+               circle_scroller = eext_circle_object_scroller_add(scroller, app_data->circle_surface);
+               eext_circle_object_scroller_policy_set(circle_scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
+               eext_rotary_object_event_activated_set(circle_scroller, EINA_TRUE);
+       }
        box = elm_box_add(scroller);
 
        inner_layout = elm_layout_add(scroller);
@@ -1609,6 +1631,13 @@ static Evas_Object *create_progressbar(Evas_Object *parent)
        return progressbar;
 }
 
+static Eina_Bool _custom_back_cb(void *data, Elm_Object_Item *it)
+{
+       PRINTFUNC(DLOG_DEBUG, "");
+       _back_to_genlist_for_selector();
+       return EINA_TRUE;
+}
+
 static Evas_Object *create_fullview(Evas_Object *parent, VoiceData *r_voicedata)
 {
        PRINTFUNC(NO_PRINT, "");
@@ -1637,7 +1666,12 @@ static Evas_Object *create_fullview(Evas_Object *parent, VoiceData *r_voicedata)
        voicedata->layout_main = layout_main;
 
        string edj_path = get_resource_path();
-       edj_path = edj_path + STT_EDJ_FILE;
+       if(_WEARABLE)
+               edj_path = edj_path + STT_EDJ_FILE_WEARABLE;
+       else if (_TV)
+               edj_path = edj_path + STT_EDJ_FILE_TV;
+       else
+               edj_path = edj_path + STT_EDJ_FILE_MOBILE;
 
        if (vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &is_screen_reader_on) == -1) {
                PRINTFUNC(DLOG_ERROR, "Cannot read value of screen reader from vconf");
@@ -1667,7 +1701,6 @@ static Evas_Object *create_fullview(Evas_Object *parent, VoiceData *r_voicedata)
 
        elm_object_part_content_set(layout_main, "EFFECT_BG", canvas);
 
-
        // MIC Button
        Evas_Object *m_mic_button = elm_button_add(layout_main);
        elm_object_style_set(m_mic_button, "vic/micbutton");
@@ -1743,6 +1776,43 @@ int is_lang_supported_by_stt(char lang[])
        return FALSE;
 }
 
+int init_voicedata(VoiceData *r_voicedata)
+{
+       VoiceData *voicedata = (VoiceData *)r_voicedata;
+       if (!voicedata) {
+               return FALSE;
+       }
+
+       voicedata->voicefw_state = 0;
+       voicedata->voicefw_handle = NULL;
+       voicedata->naviframe = NULL;
+       voicedata->layout_main = NULL;
+       voicedata->progressbar = NULL;
+       voicedata->scroller = NULL;
+       voicedata->main_entry = NULL;
+       voicedata->mic_button = NULL;
+       voicedata->state = STT_STATE_VAL_INIT;
+       voicedata->kbd_lang = NULL;
+       voicedata->start_timer = NULL;
+       voicedata->refresh_timer = NULL;
+       voicedata->progressbar_timer = NULL;
+       voicedata->textblock_timer = NULL;
+       voicedata->guide_text_timer = NULL;
+       voicedata->btn_disabling_timer = NULL;
+       voicedata->power_unlock_timer = NULL;
+
+       voicedata->partial_result = NULL;
+       voicedata->result_type = 0;
+       voicedata->disclaimer = 1;
+       voicedata->mo = NULL;
+       voicedata->sttfeedback = NULL;
+       voicedata->sttmanager = NULL;
+       voicedata->ieffect = NULL;
+       voicedata->effector = NULL;
+
+       return TRUE;
+}
+
 int init_voice(Evas_Object *parent, const char *lang, VoiceData *r_voicedata)
 {
        PRINTFUNC(DLOG_DEBUG, "[init_voice]");
@@ -1789,6 +1859,8 @@ int init_voice(Evas_Object *parent, const char *lang, VoiceData *r_voicedata)
                voicedata->textblock_timer = NULL;
        }
 
+       init_voice_recorder(NULL);
+
        return TRUE;
 }
 
@@ -1799,6 +1871,12 @@ static Eina_Bool init_view(void *data)
        if(voicedata == NULL)
                return ECORE_CALLBACK_CANCEL;
 
+       const char *item_style = NULL;
+       if (_WEARABLE)
+               item_style = "empty";
+       Elm_Object_Item *nf_voice_item = elm_naviframe_item_push(voicedata->naviframe, NULL, NULL, NULL, NULL, item_style);
+       elm_naviframe_item_pop_cb_set(nf_voice_item, _custom_back_cb, NULL);
+
        voicedata->layout_main = create_fullview(voicedata->naviframe, voicedata);
 
        if (voicedata->layout_main) {
@@ -1869,9 +1947,11 @@ void on_stt_pause(VoiceData *r_voicedata){
                //Hide more option and language settings by interrupt scenario.
                close_setting_window_idler_cb(NULL);
                Evas_Object *mo_layout = voicedata->mo->getMoreOptionLayout();
-               if(mo_layout){
-                       if(eext_more_option_opened_get(mo_layout) == EINA_TRUE) {
-                               eext_more_option_opened_set(mo_layout, EINA_FALSE);
+               if (_WEARABLE) {
+                       if(mo_layout){
+                               if(eext_more_option_opened_get(mo_layout) == EINA_TRUE) {
+                                       eext_more_option_opened_set(mo_layout, EINA_FALSE);
+                               }
                        }
                }
        }