Add initial code for inputdelegator
[platform/core/uifw/inputdelegator.git] / src / w-input-emoticon.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 <app.h>
18 #include <Elementary.h>
19 #include <string>
20 #include <efl_assist.h>
21
22 #include "Debug.h"
23 #include "w-input-selector.h"
24 #include "w-input-smartreply.h"
25
26 #define EMOTICON_CNT 27
27
28 static int previous_icon = -1;
29
30 using namespace std;
31
32 typedef struct {
33     int code;
34     char* name;
35 }Emoticon;
36
37 Emoticon emoticon_info[EMOTICON_CNT] = {
38     {0x1f44c, "IDS_IME_BODY_OK_HAND_SIGN_M_EMOTICON_NAME_TTS"},
39     {0x1f44d, "IDS_IME_BODY_THUMBS_UP_SIGN_M_EMOTICON_NAME"},
40     {0x1f44e, "IDS_IME_BODY_THUMBS_DOWN_SIGN_M_EMOTICON_NAME"},
41     {0x1f604, "IDS_IME_BODY_SMILING_FACE_WITH_OPEN_MOUTH_AND_SMILING_EYES_M_EMOTICON_NAME"},
42     {0x1f606, "IDS_IME_BODY_SMILING_FACE_WITH_OPEN_MOUTH_AND_TIGHTLY_CLOSED_EYES_M_EMOTICON_NAME"},
43     {0x1f60a, "IDS_IME_BODY_SMILING_FACE_WITH_SMILING_EYES_M_EMOTICON_NAME"},
44     {0x1f60d, "IDS_IME_BODY_SMILING_FACE_WITH_HEART_SHAPED_EYES_M_EMOTICON_NAME"},
45     {0x1f61a, "IDS_IME_BODY_KISSING_FACE_WITH_CLOSED_EYES_M_EMOTICON_NAME"},
46     {0x1f61c, "IDS_IME_BODY_FACE_WITH_STUCK_OUT_TONGUE_AND_WINKING_EYE_M_EMOTICON_NAME"},
47     {0x1f620, "IDS_IME_BODY_ANGRY_FACE_M_EMOTICON_NAME"},
48     {0x1f621, "IDS_IME_BODY_POUTING_FACE_M_EMOTICON_NAME"},
49     {0x1f622, "IDS_IME_BODY_CRYING_FACE_M_EMOTICON_NAME"},
50     {0x1f624, "IDS_IME_BODY_FACE_WITH_LOOK_OF_TRIUMPH_M_EMOTICON_NAME"},
51     {0x1f625, "IDS_IME_BODY_DISAPPOINTED_BUT_RELIEVED_FACE_M_EMOTICON_NAME"},
52     {0x1f62a, "IDS_IME_BODY_SLEEPY_FACE_M_EMOTICON_NAME"},
53     {0x1f62b, "IDS_IME_BODY_TIRED_FACE_M_EMOTICON_NAME"},
54     {0x1f631, "IDS_IME_BODY_FACE_SCREAMING_IN_FEAR_M_EMOTICON_NAME"},
55     {0x1f632, "IDS_IME_BODY_ASTONISHED_FACE_M_EMOTICON_NAME"},
56     {0x1f637, "IDS_IME_BODY_FACE_WITH_MEDICAL_MASK_M_EMOTICON_NAME"},
57     {0x1f495, "IDS_IME_BODY_TWO_HEARTS_M_EMOTICON_NAME"},
58     {0x1f43d, "IDS_IME_BODY_PIG_NOSE_M_EMOTICON_NAME"},
59     {0x1f415, "IDS_IME_BODY_DOG_M_EMOTICON_NAME"},
60     {0x1f408, "IDS_IME_BODY_CAT_M_EMOTICON_NAME"},
61     {0x1f414, "IDS_IME_BODY_CHICKEN_M_EMOTICON_NAME"},
62     {0x1f433, "IDS_IME_BODY_SPOUTING_WHALE_M_EMOTICON_NAME"},
63     {0x1f43c, "IDS_IME_BODY_PANDA_FACE_M_EMOTICON_NAME"},
64     {0x1f42f, "IDS_IME_BODY_TIGER_FACE_M_EMOTICON_NAME"},
65 };
66
67 const char * get_emoticon_file_name(int index)
68 {
69     static string path = get_resource_path() + string("images/u00000.png");
70
71     int ipos = path.size()-9;
72     char str_emoticon_code[10] = {0};
73     sprintf(str_emoticon_code, "%x", emoticon_info[index].code);
74     path.erase(ipos,5);
75     path.insert(ipos, str_emoticon_code);
76     return path.c_str();
77 }
78
79 static Eina_Bool _custom_back_cb(void *data, Elm_Object_Item *it)
80 {
81     _back_to_genlist_for_selector();
82     return EINA_TRUE;
83 }
84
85 static Eina_Bool
86 _rotary_selector_rotary_cb(void *data, Evas_Object *obj, Eext_Rotary_Event_Info *info)
87 {
88     PRINTFUNC(DLOG_DEBUG,"%s", __func__);
89
90    if (info->direction == EEXT_ROTARY_DIRECTION_CLOCKWISE){
91                 evas_object_smart_callback_call(obj, "item,selected", (void*)data);
92                 eext_rotary_object_event_callback_del(obj, _rotary_selector_rotary_cb);
93    }
94
95         return ECORE_CALLBACK_PASS_ON;
96 }
97
98 static char *_access_info_prepend_cb(void *data, Evas_Object *obj)
99 {
100
101    PRINTFUNC(DLOG_DEBUG,"%s", __func__);
102
103    std::string text;
104
105    if(previous_icon == 10 || previous_icon == 11){
106                 text = std::string("Page") + " " +std::string(dgettext(PACKAGE, emoticon_info[previous_icon].name));
107                 text = text + " " + gettext("WDS_TTS_TBBODY_DOUBLE_TAP_TO_SEND");
108    } else {
109            text = std::string("Page");
110    }
111    return strdup(text.c_str());
112 }
113
114 static void _rotary_selector_item_clicked(void *data, Evas_Object *obj, void *event_info)
115 {
116     PRINTFUNC(DLOG_DEBUG,"%s", __func__);
117     App_Data* ad = (App_Data*) data;
118     if (!ad)
119         return;
120
121     Eext_Object_Item *selected_item = (Eext_Object_Item *)event_info;
122     Eina_List *rotary_selector_list = (Eina_List *)eext_rotary_selector_items_get(obj);
123
124     int i = 0;
125     Eina_List *l = rotary_selector_list;
126     Eext_Object_Item *item = (Eext_Object_Item *)eina_list_data_get(l);
127
128     for (i=0; l!=NULL; i++) {
129         if (selected_item == item)
130             break;
131
132         l = eina_list_next(l);
133         item = (Eext_Object_Item *)eina_list_data_get(l);
134     }
135
136     int length;
137     const Eina_Unicode unicode_event[2] = { emoticon_info[i].code, 0 };
138     char* utf_8 = eina_unicode_unicode_to_utf8(unicode_event, &length);
139
140     input_smartreply_send_feedback(utf_8);
141         if(ad->reply_type == REPLY_APP_CONTROL)
142         reply_to_sender_by_appcontrol(data, (const char*)utf_8, "emoticon");
143         else
144         reply_to_sender_by_callback((const char*)utf_8, "emoticon");
145
146     PRINTFUNC(SECURE_DEBUG,"[%d]%s", i, utf_8);
147     if(utf_8)
148         free(utf_8);
149
150         if(ad->reply_type == REPLY_APP_NORMAL)
151             elm_exit();
152 }
153
154 static void _rotary_selector_item_selected(void *data, Evas_Object *obj, void *event_info)
155 {
156     PRINTFUNC(DLOG_DEBUG,"%s", __func__);
157     if (elm_config_access_get())
158     {
159         Eext_Object_Item *selected_item = (Eext_Object_Item *)event_info;
160         Eina_List *rotary_selector_list = (Eina_List *)eext_rotary_selector_items_get(obj);
161
162         int i = 0;
163         Eina_List *l = rotary_selector_list;
164         Eext_Object_Item *item = (Eext_Object_Item *)eina_list_data_get(l);
165
166         for (i=0; l!=NULL; i++) {
167             if (selected_item == item)
168                 break;
169
170             l = eina_list_next(l);
171             item = (Eext_Object_Item *)eina_list_data_get(l);
172         }
173
174
175                 previous_icon = i;
176
177         Evas_Object *content = (Evas_Object *)edje_object_part_object_get(elm_layout_edje_get(obj), "content");
178         if (!content) return;
179
180         Evas_Object *content_access = elm_access_object_get(content);
181         if (!content_access)
182             return;
183
184
185                 std::string text = std::string(dgettext(PACKAGE, emoticon_info[i].name));
186         PRINTFUNC(DLOG_DEBUG,"[%d]%s",i,text.c_str());
187                 text = text + " " + gettext("WDS_TTS_TBBODY_DOUBLE_TAP_TO_SEND");
188                 elm_access_say(text.c_str());
189
190     }
191 }
192
193 void ise_show_emoticon_popup_rotary(void *data)
194 {
195     PRINTFUNC(DLOG_DEBUG,"%s", __func__);
196     App_Data* ad = (App_Data*) data;
197     if (!ad)
198         return;
199
200
201         Eext_Object_Item *first_it;
202
203     Evas_Object *rotary_selector = eext_rotary_selector_add(ad->naviframe);
204 //    uxt_theme_object_replace_color(rotary_selector, "B01153", "AO0117");
205     PRINTFUNC(DLOG_DEBUG,"replace color");
206     for (int i = 0; i < EMOTICON_CNT; ++i)
207     {
208         Evas_Object *img = NULL;
209         Eext_Object_Item *item = eext_rotary_selector_item_append(rotary_selector);
210
211         if(i==0) first_it=item;
212
213         img = elm_image_add(rotary_selector);
214         elm_image_file_set(img, get_emoticon_file_name(i), NULL);
215         eext_rotary_selector_item_part_content_set(item, "item,bg_image", EEXT_ROTARY_SELECTOR_ITEM_STATE_NORMAL, img);
216
217         img = elm_image_add(rotary_selector);
218         elm_image_file_set(img, get_emoticon_file_name(i), NULL);
219         eext_rotary_selector_item_part_content_set(item, "selector,icon", EEXT_ROTARY_SELECTOR_ITEM_STATE_NORMAL, img);
220     }
221
222     evas_object_smart_callback_add(rotary_selector, "item,selected", _rotary_selector_item_selected, rotary_selector);
223     evas_object_smart_callback_add(rotary_selector, "item,clicked", _rotary_selector_item_clicked, (void*)ad);
224
225     Elm_Object_Item *nf_item = elm_naviframe_item_push(ad->naviframe, NULL, NULL, NULL, rotary_selector, "empty");
226     elm_naviframe_item_pop_cb_set(nf_item, _custom_back_cb, NULL);
227     eext_rotary_object_event_activated_set(rotary_selector, EINA_TRUE);
228
229     if (elm_config_access_get()){
230                 Evas_Object *selector_access = elm_access_object_get(rotary_selector);
231         elm_access_highlight_set(selector_access);
232                 eext_rotary_object_event_callback_add(rotary_selector, _rotary_selector_rotary_cb, first_it);
233
234 //              ea_screen_reader_access_info_append_cb_set(selector_access, ELM_ACCESS_CONTEXT_INFO, _access_info_prepend_cb, NULL);
235
236     }
237
238     PRINTFUNC(DLOG_DEBUG,"%s", __func__);
239 }