2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <Elementary.h>
24 #include "w-input-keyboard.h"
25 #include "w-input-selector.h"
26 #include "w-input-smartreply.h"
28 extern InputKeyboardData g_input_keyboard_data;
29 extern App_Data* app_data;
33 static void input_keyboard_app_control_send_reply_cb(app_control_h request, app_control_h reply,
34 app_control_result_e result, void *user_data);
36 static void input_keyboard_app_control_send_reply_cb(app_control_h request, app_control_h reply,
37 app_control_result_e result, void *user_data)
39 char *feedback = NULL;
40 if (result == APP_CONTROL_RESULT_SUCCEEDED) {
43 ret = app_control_get_extra_data(reply,
44 "template_feedback", &feedback);
46 if (ret == APP_CONTROL_ERROR_NONE) {
48 input_smartreply_send_feedback(feedback);
52 reply_to_sender_by_callback(feedback, "keyboard");
59 bool input_keyboard_init(app_control_h app_control)
64 char **data_array = NULL;
65 int data_array_len = -1;
66 char *default_text = NULL;
67 char *guide_text = NULL;
69 input_keyboard_deinit();
71 ret = app_control_get_extra_data(app_control, APP_CONTROL_DATA_INPUT_DEFAULT_TEXT, &default_text);
72 if (ret == APP_CONTROL_ERROR_NONE) {
73 g_input_keyboard_data.default_text = default_text;
75 ret = app_control_get_extra_data(app_control, APP_CONTROL_DATA_INPUT_GUIDE_TEXT, &guide_text);
76 if (ret == APP_CONTROL_ERROR_NONE) {
77 g_input_keyboard_data.guide_text = guide_text;
80 ret = app_control_get_extra_data(app_control,
81 "selector_keyboard_app_id",
84 if (ret != APP_CONTROL_ERROR_NONE) {
85 PRINTFUNC(DLOG_WARN, "can not get selector_keyboard_app_id: %d", ret);
89 ret = app_control_get_extra_data_array(app_control,
90 "selector_keyboard_data_array",
91 &data_array, &data_array_len);
94 if (ret != APP_CONTROL_ERROR_NONE) {
98 PRINTFUNC(DLOG_WARN, "can not get selector_keyboard_data_array : %d", ret);
103 g_input_keyboard_data.app_id = app_id;
106 g_input_keyboard_data.data_array = data_array;
108 g_input_keyboard_data.data_array_len = data_array_len;
110 PRINTFUNC(DLOG_WARN, "app_id = %s", app_id);
111 PRINTFUNC(DLOG_WARN, "data_array = %s", data_array);
116 void input_keyboard_deinit(void)
119 char **data_array = NULL;
121 if (g_input_keyboard_data.guide_text)
122 free(g_input_keyboard_data.guide_text);
124 if (g_input_keyboard_data.default_text)
125 free(g_input_keyboard_data.default_text);
127 if (g_input_keyboard_data.app_id)
128 free(g_input_keyboard_data.app_id);
130 data_array = g_input_keyboard_data.data_array;
132 for (i = 0; i < g_input_keyboard_data.data_array_len; i++) {
133 if (*(data_array + i))
134 free(*(data_array + i));
140 g_input_keyboard_data.app_id = NULL;
141 g_input_keyboard_data.data_array = NULL;
142 g_input_keyboard_data.data_array_len = 0;
147 bool input_keyboard_launch(Evas_Object *window)
153 app_control_h app_control;
155 if (window == NULL) {
156 PRINTFUNC(DLOG_ERROR, "Can not get window");
160 ret = app_control_create(&app_control);
161 if (ret != APP_CONTROL_ERROR_NONE) {
162 PRINTFUNC(DLOG_ERROR, "Can not create app_control : %d", ret);
166 app_id = g_input_keyboard_data.app_id;
167 if (app_id == NULL) {
168 PRINTFUNC(DLOG_INFO, "app id is undefined, use defualt");
169 app_id = "com.samsung.message.appcontrol.compose";
172 app_control_set_app_id(app_control, app_id);
173 app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
175 ret = app_control_set_window(app_control,
176 elm_win_xwindow_get(window));
177 if (ret != APP_CONTROL_ERROR_NONE) {
178 PRINTFUNC(DLOG_ERROR, "Can not app control set window : %d", ret);
179 app_control_destroy(app_control);
183 if (g_input_keyboard_data.data_array && g_input_keyboard_data.data_array_len > 0) {
184 app_control_add_extra_data_array(app_control,
185 "selector_keyboard_data_array",
186 (const char**)(g_input_keyboard_data.data_array),
187 g_input_keyboard_data.data_array_len);
190 set_source_caller_app_id(app_control);
192 ret = app_control_send_launch_request(app_control,
193 input_keyboard_app_control_send_reply_cb,
195 if (ret != APP_CONTROL_ERROR_NONE)
196 PRINTFUNC(DLOG_ERROR, "Can not launch app_control: %d", ret);
198 app_control_destroy(app_control);
203 void btn_clicked_cb(void *data, Evas_Object *obj, void *event_info)
205 app_control_h app_control;
206 int ret = app_control_create(&app_control);
207 if (ret != APP_CONTROL_ERROR_NONE) {
208 PRINTFUNC(DLOG_ERROR, "Can not create app_control : %d", ret);
212 const char *getText = elm_entry_entry_get(entry);
213 LOGD("button key clicked!! : getText = %s", getText);
216 input_smartreply_send_feedback(getText);
219 app_control_get_caller(app_data->source_app_control, &app_id);
221 app_control_set_app_id(app_control, app_id);
222 app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
223 set_source_caller_app_id(app_control);
225 reply_to_sender_by_callback(getText, "keyboard");
229 static Eina_Bool custom_back_cb(void *data, Elm_Object_Item *it)
231 _back_to_genlist_for_selector();
235 void create_fullscreen_editor(void *data)
237 App_Data *ad = (App_Data *)data;
239 Evas_Object *box = elm_box_add(ad->naviframe);
240 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
241 evas_object_show(box);
242 elm_win_resize_object_add(ad->naviframe, box);
244 entry = elm_entry_add(box);
245 elm_entry_single_line_set(entry, EINA_TRUE);
246 elm_entry_scrollable_set(entry, EINA_TRUE);
247 elm_scroller_policy_set(entry, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO);
248 elm_object_part_text_set(entry, "elm.guide", g_input_keyboard_data.guide_text);
249 elm_entry_entry_set(entry, g_input_keyboard_data.default_text);
250 elm_entry_cursor_end_set(entry);
251 evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
252 evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
253 evas_object_show(entry);
254 elm_box_pack_end(box, entry);
256 Evas_Object *btn = elm_button_add(box);
257 elm_object_text_set(btn, "SEND");
258 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, 0.5);
259 evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
260 evas_object_smart_callback_add(btn, "clicked", btn_clicked_cb, NULL);
261 evas_object_show(btn);
262 elm_box_pack_end(box, btn);
263 evas_object_resize(ad->naviframe, 360, 360);
264 evas_object_show(ad->naviframe);
266 Elm_Object_Item *nf_item = elm_naviframe_item_push(ad->naviframe, NULL, NULL, NULL, box, "empty");
267 elm_naviframe_item_pop_cb_set(nf_item, custom_back_cb, NULL);
270 bool input_keyboard_launch_with_ui(Evas_Object *window, void *data) {
271 if (window == NULL) {
272 PRINTFUNC(DLOG_ERROR, "Can not get window");
275 create_fullscreen_editor(data);