2 * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
10 * @brief touch action of menu
14 #include "CicoHSSwipeTouch.h"
15 #include "CicoHSAppInfo.h"
16 #include "CicoHomeScreen.h"
17 #include "CicoHSSystemState.h"
18 #include "ico_syc_inputctl.h"
19 #include <linux/input.h>
21 /*============================================================================*/
23 /*============================================================================*/
24 CicoHSControlBarWindow* CicoHSSwipeTouch::ctl_bar_window;
25 CicoHSAppHistoryExt* CicoHSSwipeTouch::app_history;
26 int CicoHSSwipeTouch::full_width;
27 int CicoHSSwipeTouch::full_height;
28 int CicoHSSwipeTouch::touch_state_b_x;
29 int CicoHSSwipeTouch::touch_state_b_y;
30 int CicoHSSwipeTouch::touch_state_a_x;
31 int CicoHSSwipeTouch::touch_state_a_y;
33 int CicoHSSwipeTouch::touch_down;
34 bool CicoHSSwipeTouch::set_xy_pos;
36 int CicoHSSwipeTouch::num_windows;
37 CicoHSSwipeInputWindow* CicoHSSwipeTouch::swipe_windows[ICO_HS_MAX_SWIPEWINDOWS];
39 /*============================================================================*/
41 /*============================================================================*/
42 /*--------------------------------------------------------------------------*/
44 * @brief CicoHSSwipeTouch::Initialize
47 * @param[in] ctl_bar instance of control bar window
48 * @param[in] apphist instance of application history control
49 * @param[in] width screen full width
50 * @param[in] height screen full height
53 /*--------------------------------------------------------------------------*/
55 CicoHSSwipeTouch::Initialize(CicoHSControlBarWindow* ctl_bar, CicoHSAppHistoryExt* apphist,
56 int width, int height)
62 ctl_bar_window = ctl_bar;
63 app_history = apphist;
66 ICO_DBG("Initialize: ctlbar=%08x apphist=%08x width=%d height=%d",
67 (int)ctl_bar, (int)apphist, width, height);
70 /*--------------------------------------------------------------------------*/
72 * @brief CicoHSSwipeTouch::Finalize
78 /*--------------------------------------------------------------------------*/
80 CicoHSSwipeTouch::Finalize(void)
85 /*--------------------------------------------------------------------------*/
87 * @brief CicoHSSwipeTouch::TouchSwipe
88 * touch down action at swipe input window
90 * @param[in] data CicoHSSwipeInputWindow object
91 * @param[in] evas evas
92 * @param[in] obj object
93 * @param[in] event_info event information
96 /*--------------------------------------------------------------------------*/
98 CicoHSSwipeTouch::TouchDownSwipe(void *data, Evas *evas, Evas_Object *obj, void *event_info)
100 Evas_Event_Mouse_Down *info;
101 CicoHSSwipeInputWindow *window;
106 info = reinterpret_cast<Evas_Event_Mouse_Down*>(event_info);
107 window = (CicoHSSwipeInputWindow *)data;
108 x = info->output.x + window->GetPosX();
109 y = info->output.y + window->GetPosY();
110 ICO_PRF("TOUCH_EVENT Swipe Down (%d,%d)->(%d,%d) (%d)",
111 info->output.x, info->output.y, x, y, touch_down);
113 if ((x >= 0) && (x < 4096) && (y >= 0) && (y < 4096)) {
114 if (set_xy_pos == false) {
124 /*--------------------------------------------------------------------------*/
126 * @brief CicoHSSwipeTouch::TouchUpSwipe
127 * touch up action at swipe input window
129 * @param[in] data CicoHSSwipeInputWindow object
130 * @param[in] evas evas
131 * @param[in] obj object
132 * @param[in] event_info event information
135 /*--------------------------------------------------------------------------*/
137 CicoHSSwipeTouch::TouchUpSwipe(void *data, Evas *evas, Evas_Object *obj, void *event_info)
139 Evas_Event_Mouse_Up *info;
140 CicoHSSwipeInputWindow *window;
141 CicoHSAppInfo *appinfo;
142 ico_hs_window_info *wininfo;
143 ico_syc_animation_t animation;
151 info = reinterpret_cast<Evas_Event_Mouse_Up*>(event_info);
152 window = (CicoHSSwipeInputWindow *)data;
153 x = info->output.x + window->GetPosX();
154 y = info->output.y + window->GetPosY();
155 if ((x >= 0) && (x < 4096) && (y >= 0) && (y < 4096)) {
160 ICO_PRF("TOUCH_EVENT Swipe Up (%d,%d)->(%d,%d) before(%d,%d) (%d)",
161 info->output.x, info->output.y, touch_state_a_x, touch_state_a_y,
162 touch_state_b_x, touch_state_b_y, touch_down - 1);
164 if (touch_down > 1) {
166 ICO_DBG("TouchUpSwipe: touch counter not 0(%d), Skip", touch_down);
170 if (touch_down == 0) {
172 ICO_DBG("TouchUpSwipe: no touch down, Skip");
178 if (set_xy_pos == false) {
179 ICO_DBG("TouchUpSwipe: unknown coordinate, Skip");
183 sub = touch_state_a_x - touch_state_b_x;
185 /* check swipe left to right or right to left */
186 if (sub > ICO_HS_SWIPE_TOUCH_SWIPE_THREASHOLD_DISTANCE) {
187 if (touch_state_b_x < ICO_HS_SWIPE_TOUCH_SWIPE_WIDTH) {
188 /* get current application */
189 curapp = app_history->getSwipeCurrentAppid();
191 if (CicoHSSystemState::getInstance()->getRegulation() == true) {
192 ICO_DBG("TouchUpSwipe: Swipe left side to right, but Regulation=ON");
193 appinfo = CicoHomeScreen::GetAppInfo(curapp.c_str());
195 ico_syc_change_active(appinfo->GetAppId(), appinfo->GetLastSurface());
199 /* swipe at left side to right = back before application*/
200 ICO_DBG("TouchUpSwipe: Swipe left side to right");
202 /* get before application */
203 histapp = app_history->prevSwipe();
204 ICO_DBG("TouchUpSwipe: Swipe left to right(cur/prev=%s/%s)",
205 curapp.c_str(), histapp.c_str());
206 if (histapp.empty()) {
207 ICO_DBG("TouchUpSwipe: Swipe left to right(prev not exist)");
208 appinfo = CicoHomeScreen::GetAppInfo(curapp.c_str());
210 ico_syc_change_active(appinfo->GetAppId(), appinfo->GetLastSurface());
214 animation.time = ICO_HS_SWIPE_TOUCH_SWIPE_ANIMA_TIME |
215 ICO_SYC_WIN_SURF_RAISE | ICO_SYC_WIN_SURF_NORESCTL |
216 ICO_SYC_WIN_SURF_ONESHOT;
218 /* show before application with slide to right */
219 appinfo = CicoHomeScreen::GetAppInfo(histapp.c_str());
221 animation.name = (char *)"slide.toright";
222 for (idx = 0; ; idx++) {
223 wininfo = appinfo->GetWindowInfo(idx);
224 if (! wininfo) break;
226 /* reset avtive surface */
228 ico_syc_change_active(wininfo->appid, 0);
230 ICO_DBG("TouchUpSwipe: %s.%d surface=%08x",
231 wininfo->appid, idx, wininfo->surface);
232 ico_syc_show(wininfo->appid, wininfo->surface, &animation);
235 /* hide current applicaiton with slide to right */
236 if (curapp.empty()) {
237 ICO_DBG("TouchUpSwipe: Swipe left to right(current not exist)");
240 animation.time = ICO_HS_SWIPE_TOUCH_SWIPE_ANIMA_TIME |
241 ICO_SYC_WIN_SURF_NORESCTL |
242 ICO_SYC_WIN_SURF_ONESHOT;
243 appinfo = CicoHomeScreen::GetAppInfo(curapp.c_str());
245 animation.name = (char *)"slide.toleft";
246 for (idx = 0; ; idx++) {
247 wininfo = appinfo->GetWindowInfo(idx);
248 if (! wininfo) break;
249 ICO_DBG("TouchUpSwipe: %s.%d surface=%08x",
250 wininfo->appid, idx, wininfo->surface);
251 ico_syc_hide(wininfo->appid,
252 wininfo->surface, &animation);
256 ICO_DBG("TouchUpSwipe: current app(%s) dose not exist",
260 /* set history timer */
261 app_history->selectApp(histapp.c_str());
264 ICO_DBG("TouchUpSwipe: prev app(%s) dose not exist", histapp.c_str());
265 appinfo = CicoHomeScreen::GetAppInfo(curapp.c_str());
267 ico_syc_change_active(appinfo->GetAppId(), appinfo->GetLastSurface());
275 ICO_DBG("TouchUpSwipe: Swipe left to right, but nop");
279 else if (sub < (-1 * ICO_HS_SWIPE_TOUCH_SWIPE_THREASHOLD_DISTANCE)) {
280 if (touch_state_b_x >= (full_width - ICO_HS_SWIPE_TOUCH_SWIPE_WIDTH)) {
281 /* get current application */
282 curapp = app_history->getSwipeCurrentAppid();
284 if (CicoHSSystemState::getInstance()->getRegulation() == true) {
285 ICO_DBG("TouchUpSwipe: Swipe right side to left, but Regulation=ON");
286 appinfo = CicoHomeScreen::GetAppInfo(curapp.c_str());
288 ico_syc_change_active(appinfo->GetAppId(), appinfo->GetLastSurface());
292 /* swipe at right side to left = go next applicaton */
294 /* get next application */
295 histapp = app_history->nextSwipe();
296 ICO_DBG("TouchUpSwipe: Swipe right to left(cur/next=%s/%s)",
297 curapp.c_str(), histapp.c_str());
298 if (histapp.empty()) {
299 ICO_DBG("TouchUpSwipe: Swipe right to left(next not exist)");
300 appinfo = CicoHomeScreen::GetAppInfo(curapp.c_str());
302 ico_syc_change_active(appinfo->GetAppId(), appinfo->GetLastSurface());
306 animation.time = ICO_HS_SWIPE_TOUCH_SWIPE_ANIMA_TIME |
307 ICO_SYC_WIN_SURF_RAISE | ICO_SYC_WIN_SURF_NORESCTL |
308 ICO_SYC_WIN_SURF_ONESHOT;
310 /* show next application with slide to left */
311 appinfo = CicoHomeScreen::GetAppInfo(histapp.c_str());
313 animation.name = (char *)"slide.toleft";
314 for (idx = 0; ; idx++) {
315 wininfo = appinfo->GetWindowInfo(idx);
316 if (! wininfo) break;
318 /* reset avtive surface */
320 ico_syc_change_active(wininfo->appid, 0);
322 ICO_DBG("TouchUpSwipe: %s.%d surface=%08x",
323 wininfo->appid, idx, wininfo->surface);
324 ico_syc_show(wininfo->appid, wininfo->surface, &animation);
327 /* hide current applicaiton with slide to left */
328 if (curapp.empty()) {
329 ICO_DBG("TouchUpSwipe: Swipe right to left(current not exist)");
332 animation.time = ICO_HS_SWIPE_TOUCH_SWIPE_ANIMA_TIME |
333 ICO_SYC_WIN_SURF_NORESCTL |
334 ICO_SYC_WIN_SURF_ONESHOT;
335 appinfo = CicoHomeScreen::GetAppInfo(curapp.c_str());
337 animation.name = (char *)"slide.toright";
338 for (idx = 0; ; idx++) {
339 wininfo = appinfo->GetWindowInfo(idx);
340 if (! wininfo) break;
341 ICO_DBG("TouchUpSwipe: %s.%d surface=%08x",
342 wininfo->appid, idx, wininfo->surface);
343 ico_syc_hide(wininfo->appid,
344 wininfo->surface, &animation);
348 ICO_DBG("TouchUpSwipe: current app(%s) dose not exist",
352 /* set history timer */
353 app_history->selectApp(histapp.c_str());
356 ICO_DBG("TouchUpSwipe: next app(%s) dose not exist", histapp.c_str());
357 appinfo = CicoHomeScreen::GetAppInfo(curapp.c_str());
359 ico_syc_change_active(appinfo->GetAppId(), appinfo->GetLastSurface());
367 ICO_DBG("TouchUpSwipe: Swipe right side to left, but nop");
372 #if 0 /* currently not support */
373 /* check swipe buttom to top or top to buttom */
374 sub = touch_state_a_y - touch_state_b_y;
375 if (sub > ICO_HS_SWIPE_TOUCH_SWIPE_THREASHOLD_DISTANCE) {
376 if (touch_state_b_y < ICO_HS_SWIPE_TOUCH_SWIPE_THREASHOLD_DISTANCE) {
377 /* swipe at top side to buttom = unknown */
378 ICO_DBG("TouchUpSwipe: Swipe top side to buttom");
382 ICO_DBG("TouchUpSwipe: Swipe top side to buttom, but nop");
386 else if (sub < (-1 * ICO_HS_SWIPE_TOUCH_SWIPE_THREASHOLD_DISTANCE)) {
387 if (touch_state_b_y >
388 (full_width - ICO_HS_SWIPE_TOUCH_SWIPE_THREASHOLD_DISTANCE)) {
389 /* swipe at buttom side to top = show home menu screen */
390 ICO_DBG("TouchUpSwipe: Swipe buttom side to top");
392 if (ctl_bar_window) {
393 ctl_bar_window->TouchHome();
397 ICO_DBG("TouchUpSwipe: Swipe buttom side to top, but nop");
407 /*--------------------------------------------------------------------------*/
409 * @brief CicoHSSwipeTouch::TouchMoveSwipe
410 * touch move action at swipe input window
412 * @param[in] data CicoHSSwipeInputWindow object
413 * @param[in] evas evas
414 * @param[in] obj object
415 * @param[in] event_info event information
418 /*--------------------------------------------------------------------------*/
420 CicoHSSwipeTouch::TouchMoveSwipe(void *data, Evas *evas, Evas_Object *obj, void *event_info)
422 Evas_Event_Mouse_Move *info;
423 CicoHSSwipeInputWindow *window;
426 info = reinterpret_cast<Evas_Event_Mouse_Move*>(event_info);
428 window = (CicoHSSwipeInputWindow *)data;
429 x = info->cur.output.x + window->GetPosX();
430 y = info->cur.output.y + window->GetPosY();
431 if ((x < 0) || (x >= 4096) || (y < 0) || (y >= 4096)) {
432 ICO_DBG("TouchMoveSwipe: Illegal position(x/y=%d/%d->%d/%d), Skip",
433 info->cur.output.x, info->cur.output.y, touch_state_a_x, touch_state_a_y);
439 if ((set_xy_pos == false) || (touch_down == 0)) {
441 touch_state_b_x = touch_state_a_x;
442 touch_state_b_y = touch_state_a_y;
443 // ICO_DBG("TouchMoveSwipe: save x/y=%d/%d", touch_state_b_x, touch_state_b_y);
445 #if 0 /* too many log */
446 ICO_DBG("TouchMoveSwipe: Swipe Move (%d,%d)->(%d,%d) Button=%x",
447 info->cur.output.x, info->cur.output.y,
448 touch_state_a_x, touch_state_a_y, info->buttons);
451 // vim: set expandtab ts=4 sw=4: