76e60464645a8c25e79e927aefa8757fef26aa1b
[profile/ivi/ico-uxf-homescreen.git] / src / homescreen / CicoHSSwipeTouch.cpp
1 /*
2  * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
3  *
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
7  *
8  */
9 /**
10  * @brief   touch action of menu
11  *
12  * @date    Sep^2--2013
13  */
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>
20
21 /*============================================================================*/
22 /* static members                                                             */
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;
32
33 int CicoHSSwipeTouch::touch_down;
34 bool CicoHSSwipeTouch::set_xy_pos;
35
36 int CicoHSSwipeTouch::num_windows;
37 CicoHSSwipeInputWindow* CicoHSSwipeTouch::swipe_windows[ICO_HS_MAX_SWIPEWINDOWS];
38
39 /*============================================================================*/
40 /* functions                                                                  */
41 /*============================================================================*/
42 /*--------------------------------------------------------------------------*/
43 /**
44  * @brief   CicoHSSwipeTouch::Initialize
45  *          Initialize
46  *
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
51  * @return      none
52  */
53 /*--------------------------------------------------------------------------*/
54 void
55 CicoHSSwipeTouch::Initialize(CicoHSControlBarWindow* ctl_bar, CicoHSAppHistoryExt* apphist,
56                              int width, int height)
57 {
58     num_windows = 0;
59     touch_down = 0;
60     set_xy_pos = false;
61
62     ctl_bar_window = ctl_bar;
63     app_history = apphist;
64     full_width = width;
65     full_height = height;
66     ICO_DBG("Initialize: ctlbar=%08x apphist=%08x width=%d height=%d",
67             (int)ctl_bar, (int)apphist, width, height);
68 }
69
70 /*--------------------------------------------------------------------------*/
71 /**
72  * @brief   CicoHSSwipeTouch::Finalize
73  *          Finalize
74  *
75  * @param[in]   none
76  * @return      none
77  */
78 /*--------------------------------------------------------------------------*/
79 void
80 CicoHSSwipeTouch::Finalize(void)
81 {
82   /*nothing to do*/
83 }
84
85 /*--------------------------------------------------------------------------*/
86 /**
87  * @brief   CicoHSSwipeTouch::TouchSwipe
88  *          touch down action at swipe input window
89  *
90  * @param[in]   data    CicoHSSwipeInputWindow object
91  * @param[in]   evas    evas
92  * @param[in]   obj     object
93  * @param[in]   event_info    event information
94  * @return      none
95  */
96 /*--------------------------------------------------------------------------*/
97 void
98 CicoHSSwipeTouch::TouchDownSwipe(void *data, Evas *evas, Evas_Object *obj, void *event_info)
99 {
100     Evas_Event_Mouse_Down   *info;
101     CicoHSSwipeInputWindow  *window;
102     int     x, y;
103
104     touch_down ++;
105
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);
112
113     if ((x >= 0) && (x < 4096) && (y >= 0) && (y < 4096))   {
114         if (set_xy_pos == false)    {
115             set_xy_pos = true;
116             touch_state_b_x = x;
117             touch_state_b_y = y;
118         }
119         touch_state_a_x = x;
120         touch_state_a_y = y;
121     }
122 }
123
124 /*--------------------------------------------------------------------------*/
125 /**
126  * @brief   CicoHSSwipeTouch::TouchUpSwipe
127  *          touch up action at swipe input window
128  *
129  * @param[in]   data    CicoHSSwipeInputWindow object
130  * @param[in]   evas    evas
131  * @param[in]   obj     object
132  * @param[in]   event_info    event information
133  * @return      none
134  */
135 /*--------------------------------------------------------------------------*/
136 void
137 CicoHSSwipeTouch::TouchUpSwipe(void *data, Evas *evas, Evas_Object *obj, void *event_info)
138 {
139     Evas_Event_Mouse_Up     *info;
140     CicoHSSwipeInputWindow  *window;
141     CicoHSAppInfo           *appinfo;
142     ico_hs_window_info      *wininfo;
143     ico_syc_animation_t     animation;
144     int sub;
145     int idx;
146     int swipe = 0;
147     std::string histapp;
148     std::string curapp;
149     int x, y;
150
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))   {
156         touch_state_a_x = x;
157         touch_state_a_y = y;
158     }
159
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);
163
164     if (touch_down > 1) {
165         touch_down --;
166         ICO_DBG("TouchUpSwipe: touch counter not 0(%d), Skip", touch_down);
167         return;
168     }
169
170     if (touch_down == 0)    {
171         set_xy_pos = false;
172         ICO_DBG("TouchUpSwipe: no touch down, Skip");
173         return;
174     }
175
176     touch_down --;
177
178     if (set_xy_pos == false)    {
179         ICO_DBG("TouchUpSwipe: unknown coordinate, Skip");
180         return;
181     }
182     set_xy_pos = false;
183     sub = touch_state_a_x - touch_state_b_x;
184
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();
190
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());
194                 if (appinfo)    {
195                     ico_syc_change_active(appinfo->GetAppId(), appinfo->GetLastSurface());
196                 }
197             }
198             else    {
199                 /* swipe at left side to right = back before application*/
200                 ICO_DBG("TouchUpSwipe: Swipe left side to right");
201
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());
209                     if (appinfo)    {
210                         ico_syc_change_active(appinfo->GetAppId(), appinfo->GetLastSurface());
211                     }
212                 }
213                 else    {
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;
217
218                     /* show before application with slide to right  */
219                     appinfo = CicoHomeScreen::GetAppInfo(histapp.c_str());
220                     if (appinfo)    {
221                         animation.name = (char *)"slide.toright";
222                         for (idx = 0; ; idx++)  {
223                             wininfo = appinfo->GetWindowInfo(idx);
224                             if (! wininfo)  break;
225
226                             /* reset avtive surface         */
227                             if (idx == 0)   {
228                                 ico_syc_change_active(wininfo->appid, 0);
229                             }
230                             ICO_DBG("TouchUpSwipe: %s.%d surface=%08x",
231                                     wininfo->appid, idx, wininfo->surface);
232                             ico_syc_show(wininfo->appid, wininfo->surface, &animation);
233                         }
234
235                         /* hide current applicaiton with slide to right */
236                         if (curapp.empty()) {
237                             ICO_DBG("TouchUpSwipe: Swipe left to right(current not exist)");
238                         }
239                         else    {
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());
244                             if (appinfo)    {
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);
253                                 }
254                             }
255                             else    {
256                                 ICO_DBG("TouchUpSwipe: current app(%s) dose not exist",
257                                         curapp.c_str());
258                             }
259                         }
260                         /* set history timer                        */
261                         app_history->selectApp(histapp.c_str());
262                     }
263                     else    {
264                         ICO_DBG("TouchUpSwipe: prev app(%s) dose not exist", histapp.c_str());
265                         appinfo = CicoHomeScreen::GetAppInfo(curapp.c_str());
266                         if (appinfo)    {
267                             ico_syc_change_active(appinfo->GetAppId(), appinfo->GetLastSurface());
268                         }
269                     }
270                 }
271             }
272             swipe = 1;
273         }
274         else    {
275             ICO_DBG("TouchUpSwipe: Swipe left to right, but nop");
276             swipe = -1;
277         }
278     }
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();
283
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());
287                 if (appinfo)    {
288                     ico_syc_change_active(appinfo->GetAppId(), appinfo->GetLastSurface());
289                 }
290             }
291             else    {
292                 /* swipe at right side to left = go next applicaton     */
293
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());
301                     if (appinfo)    {
302                         ico_syc_change_active(appinfo->GetAppId(), appinfo->GetLastSurface());
303                     }
304                 }
305                 else    {
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;
309
310                     /* show next application with slide to left     */
311                     appinfo = CicoHomeScreen::GetAppInfo(histapp.c_str());
312                     if (appinfo)    {
313                         animation.name = (char *)"slide.toleft";
314                         for (idx = 0; ; idx++)  {
315                             wininfo = appinfo->GetWindowInfo(idx);
316                             if (! wininfo)  break;
317
318                             /* reset avtive surface         */
319                             if (idx == 0)   {
320                                 ico_syc_change_active(wininfo->appid, 0);
321                             }
322                             ICO_DBG("TouchUpSwipe: %s.%d surface=%08x",
323                                     wininfo->appid, idx, wininfo->surface);
324                             ico_syc_show(wininfo->appid, wininfo->surface, &animation);
325                         }
326
327                         /* hide current applicaiton with slide to left  */
328                         if (curapp.empty()) {
329                             ICO_DBG("TouchUpSwipe: Swipe right to left(current not exist)");
330                         }
331                         else    {
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());
336                             if (appinfo)    {
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);
345                                 }
346                             }
347                             else    {
348                                 ICO_DBG("TouchUpSwipe: current app(%s) dose not exist",
349                                         curapp.c_str());
350                             }
351                         }
352                         /* set history timer                            */
353                         app_history->selectApp(histapp.c_str());
354                     }
355                     else    {
356                         ICO_DBG("TouchUpSwipe: next app(%s) dose not exist", histapp.c_str());
357                         appinfo = CicoHomeScreen::GetAppInfo(curapp.c_str());
358                         if (appinfo)    {
359                             ico_syc_change_active(appinfo->GetAppId(), appinfo->GetLastSurface());
360                         }
361                     }
362                 }
363             }
364             swipe = 1;
365         }
366         else    {
367             ICO_DBG("TouchUpSwipe: Swipe right side to left, but nop");
368             swipe = -1;
369         }
370     }
371
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");
379             swipe = 1;
380         }
381         else    {
382             ICO_DBG("TouchUpSwipe: Swipe top side to buttom, but nop");
383             swipe = -1;
384         }
385     }
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");
391             swipe = 1;
392             if (ctl_bar_window) {
393                 ctl_bar_window->TouchHome();
394             }
395         }
396         else    {
397             ICO_DBG("TouchUpSwipe: Swipe buttom side to top, but nop");
398             swipe = -1;
399         }
400     }
401 #endif
402     if (swipe <= 0) {
403         set_xy_pos = false;
404     }
405 }
406
407 /*--------------------------------------------------------------------------*/
408 /**
409  * @brief   CicoHSSwipeTouch::TouchMoveSwipe
410  *          touch move action at swipe input window
411  *
412  * @param[in]   data    CicoHSSwipeInputWindow object
413  * @param[in]   evas    evas
414  * @param[in]   obj     object
415  * @param[in]   event_info    event information
416  * @return      none
417  */
418 /*--------------------------------------------------------------------------*/
419 void
420 CicoHSSwipeTouch::TouchMoveSwipe(void *data, Evas *evas, Evas_Object *obj, void *event_info)
421 {
422     Evas_Event_Mouse_Move   *info;
423     CicoHSSwipeInputWindow  *window;
424     int x, y;
425
426     info = reinterpret_cast<Evas_Event_Mouse_Move*>(event_info);
427
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);
434         return;
435     }
436     touch_state_a_x = x;
437     touch_state_a_y = y;
438
439     if ((set_xy_pos == false) || (touch_down == 0)) {
440         set_xy_pos = true;
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);
444     }
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);
449 #endif
450 }
451 // vim: set expandtab ts=4 sw=4: