Add LCOV remarkers to increase line coverage rate
[platform/core/api/maps-service.git] / src / view / gesture_detector_statemachine.cpp
1 /* Copyright (c) 2010-2014 Samsung Electronics Co., Ltd. All rights reserved.
2  *
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
18 #include "gesture_detector_statemachine.h"
19 #include <glib.h>
20
21 //LCOV_EXCL_START
22 view::gesture_detector_statemachine::gesture_detector_statemachine(maps_view_h v)
23         : gesture_detector(v)
24         , _current_state(STATE_NONE)
25         , is_rotating(false)
26         , is_zoomming(false)
27         , is_2fingers_panning(false)
28 {
29         for(int i = 0; i < MAX_FINGERS; i ++)
30                 is_panning[i] = false;
31 }
32
33 view::gesture_detector_statemachine::~gesture_detector_statemachine()
34 {
35 }
36
37 void view::gesture_detector_statemachine::tap(int finger_no,
38                                               const touch_point &tp)
39 {
40         switch(finger_no) {
41         case 0: /* Single finger pressed */
42                 _info._finger_down[0] = tp;
43                 _info._finger_move[0] = tp;
44                 _info._prev_finger_down[0] = tp;
45                 _info._is_finger_pressed[0] = true;
46
47                 _info._fingers_pressed = _info.calc_finger_pressed();
48
49                 if(_info._fingers_pressed > 2)
50                         log("ERROR! Too many fingers pressed!!!", FG_RED);
51
52                 /* Run state machine */
53                 state_machine_on_event(FINGER_DOWN);
54                 break;
55
56         case 1: /* Second finger pressed */
57                 _info._finger_down[1] = tp;
58                 _info._finger_move[1] = tp;
59                 _info._prev_finger_down[1] = tp;
60                 _info._is_finger_pressed[1] = true;
61
62                 _info._fingers_pressed = _info.calc_finger_pressed();
63
64                 if(_info._fingers_pressed > 2)
65                         log("ERROR! Too many fingers pressed!!!", FG_RED);
66
67                 /* Run state machine */
68                 state_machine_on_event(FINGER2_DOWN);
69                 break;
70
71         default:
72                 break;
73         }
74
75         stop_tap_timer();
76
77         MAPS_LOGI("%c[%d;%d;%dm"
78                   "Fingers pressed [after press]: %d"
79                   "%c[%d;%d;%dm",
80                   0x1B, 1, 0, FG_LITE_WHITE,
81                   _info._fingers_pressed,
82                   0x1B, 0, 0, 0);
83 }
84
85 void view::gesture_detector_statemachine::up(int finger_no,
86                                              const touch_point &tp)
87 {
88         switch(finger_no) {
89         case 0: /* Up the single finger */
90                 _info._finger_up[0] = tp;
91
92                 /* Run state machine */
93                 state_machine_on_event(FINGER_UP);
94
95                 /* Remove the info about lifted finger */
96                 _info._is_finger_pressed[0] = false;
97
98                 _info._fingers_pressed = _info.calc_finger_pressed();
99
100                 if(_info._fingers_pressed < 0)
101                         log("ERROR! Too few fingers pressed!!!", FG_RED);
102
103                 /* This is the end of the gesture */
104                 if(_info._fingers_pressed <= 0)
105                         reset();
106                 break;
107
108         case 1: /* Up the second finger */
109
110                 _info._finger_move[1] = tp;
111                 _info._finger_up[1] = tp;
112
113                 /* Run state machine */
114                 state_machine_on_event(FINGER2_UP);
115
116                 /* Remove the info about lifted finger */
117                 _info._is_finger_pressed[1] = false;
118
119                 _info._fingers_pressed = _info.calc_finger_pressed();
120
121                 if(_info._fingers_pressed < 0)
122                         log("ERROR! Too few fingers pressed!!!", FG_RED);
123
124                 /* This is the end of the gesture */
125                 if(_info._fingers_pressed <= 0)
126                         reset();
127                 break;
128
129         default:
130                 break;
131         }
132
133         stop_long_press_timer();
134
135         MAPS_LOGI("%c[%d;%d;%dm"
136                   "Fingers pressed [after unpress]: %d"
137                   "%c[%d;%d;%dm",
138                   0x1B, 1, 0, FG_LITE_WHITE,
139                   _info._fingers_pressed,
140                   0x1B, 0, 0, 0);
141 }
142
143 void view::gesture_detector_statemachine::move(int finger_no,
144                                                const touch_point &tp)
145 {
146         /* There can not be a long press any more */
147         stop_long_press_timer();
148
149         switch(finger_no) {
150         case 0: /* Moving the first (single) finger */
151                 _info._prev_finger_down[0] = _info._finger_move[0];
152                 _info._finger_move[0] = tp;
153
154                 /* Run state machine */
155                 state_machine_on_event(FINGER_MOVE);
156                 break;
157
158         case 1: /* Moving the second finger */
159                 _info._prev_finger_down[1] = _info._finger_move[1];
160                 _info._finger_move[1] = tp;
161
162                 /* Run state machine */
163                 state_machine_on_event(FINGER2_MOVE);
164                 break;
165         default:
166                 break;
167         }
168 }
169
170 void view::gesture_detector_statemachine::start_panning(int finger_no)
171 {
172         if(!is_panning[finger_no]) {
173                 /*_info._prev_finger_down[finger_no] =
174                         _info._finger_move[finger_no];*/
175                 is_panning[finger_no] = true;
176         }
177 }
178
179 void view::gesture_detector_statemachine::finish_panning(int finger_no)
180 {
181         if(is_panning[finger_no]) {
182                 _gp.on_panning_finished(finger_no);
183
184                 _info._start_view_state.capture(_view);
185                 _info._finger_down[finger_no] = _info._finger_move[finger_no];
186         }
187         is_panning[finger_no] = false;
188 }
189
190 void view::gesture_detector_statemachine::on_tap_timer()
191 {
192         /* TODO: think about concurent access to following member variables */
193
194         /* Run state machine */
195         state_machine_on_event(TAP_TIMER);
196 }
197
198 void view::gesture_detector_statemachine::on_long_press_timer()
199 {
200         /* TODO: think about concurent access to following member variables */
201
202         /* Run state machine */
203         state_machine_on_event(LONG_PRESS_TIMER);
204 }
205
206 void view::gesture_detector_statemachine::halt_gesture()
207 {
208         _current_state = STATE_NONE;
209         g_usleep(5 * 1000);
210         reset();
211 }
212
213 void view::gesture_detector_statemachine::state_machine_on_event(view_event_e event)
214 {
215         log_event(event);
216         detector_states_e old_state = _current_state;
217
218         switch(_current_state) {
219         case STATE_NONE: {
220                 _info._start_view_state.capture(_view);
221                 log_map_center(FG_WHITE);
222
223                 switch(event) {
224                 case FINGER_DOWN:
225                         _current_state = STATE_PRESSED;
226                         start_long_press_timer();
227                         break;
228
229                 default:
230                         log_state(event, _current_state);
231                         break;
232                 }
233
234                 break;
235         }
236
237         case STATE_PRESSED: {
238                 switch(event) {
239                 case FINGER_MOVE:
240                         _current_state = STATE_MOVING;
241                         break;
242                 case FINGER_UP: {
243                         if(finger_pressed_enough(0, 0, __CLICK_DURATION)) {
244                                 _current_state = STATE_CLICKED;
245                                 start_tap_timer();
246                         } else {
247                                 _current_state = STATE_NONE;
248                         }
249                         break;
250                 }
251                 case LONG_PRESS_TIMER:
252                         _current_state = STATE_LONG_PRESSED;
253                         detected_long_press();  /* Long Press */
254                         break;
255                 case FINGER2_DOWN:
256                         _current_state = STATE_2FINGERS_PRESSED;
257                         break;
258                 default:
259                         log_state(event, _current_state);
260                         break;
261                 }
262                 break;
263         }
264
265         case STATE_CLICKED: {
266                 switch(event) {
267                 case FINGER_DOWN: {
268                         /* Calculate the time between clicks */
269                         unsigned int last_click_time =
270                                 _info_history._finger_up[0]._timestamp;
271                         unsigned int cur_time =
272                                 _info._finger_down[0]._timestamp;
273                         unsigned int duration = cur_time - last_click_time;
274
275                         /* Decide if we can have a souble click, or just a
276                          *  second click */
277                         if(duration < __DOUBLE_CLICK_DURATION)
278                                 _current_state = STATE_SECOND_PRESSED;
279                         else
280                                 _current_state = STATE_PRESSED;
281
282                         /* Start timer expecting the long press */
283                         start_long_press_timer();
284                         break;
285                 }
286                 case TAP_TIMER:
287                         stop_long_press_timer();
288                         _current_state = STATE_NONE;
289                         detected_tap(); /* Tap */
290                         break;
291                 default:
292                         log_state(event, _current_state);
293                         break;
294                 }
295                 break;
296         }
297
298         case STATE_LONG_PRESSED: {
299                 switch(event) {
300                 case FINGER_UP:
301                         _current_state = STATE_NONE;
302                         break;
303                 case FINGER_MOVE:
304                         _current_state = STATE_MOVING;
305                         break;
306                 case FINGER2_DOWN:
307                         _current_state = STATE_2FINGERS_PRESSED;
308                         break;
309                 default:
310                         log_state(event, _current_state);
311                         break;
312                 }
313                 break;
314         }
315
316         case STATE_SECOND_PRESSED: {
317                 switch(event) {
318                 case FINGER_UP: {
319                         /* First click position */
320                         const touch_point p1 = _info_history._finger_down[0];
321
322                         /* Second click position */
323                         const touch_point p2 = _info._finger_down[0];
324
325                         MAPS_LOGI("Checking double tap: [%d, %d] -> [%d, %d]",
326                                   p1._x, p1._y, p2._x, p2._y);
327
328                         /*
329                          * Check if tapped in the same point
330                          * Note: accuracy is decreased for the sake of user's
331                          * convenience
332                          */
333
334                         if(get_trajectory_effective_length(p1, p2) <= (4 * __CLICK_AREA)) {
335                                 /* Switching to Double Tap state */
336                                 _current_state = STATE_SECOND_CLICKED;
337
338                                 detected_double_tap();  /* Double Tap */
339
340                                 /*
341                                  * No need to expect other events here.
342                                  * Immediatelly switching to the initial State
343                                  */
344
345                                 _current_state = STATE_NONE;
346                         } else {
347                                 /* Seems like it is a simple click */
348                                 _current_state = STATE_CLICKED;
349                                 stop_long_press_timer();
350                                 start_tap_timer();
351                         }
352                         break;
353                 }
354                 case TAP_TIMER:
355                         _current_state = STATE_NONE;
356                         detected_tap(); /* Tap */
357                         break;
358                 case LONG_PRESS_TIMER:
359                         _current_state = STATE_SECOND_LONG_PRESSED;
360                         detected_second_long_press();   /* Second Long Press */
361                         break;
362                 case FINGER_MOVE: {
363                         _current_state = STATE_MOVING;
364                         detected_pan(); /* Tap */
365                         break;
366                 }
367                 case FINGER2_DOWN:
368                         _current_state = STATE_2FINGERS_PRESSED;
369                         break;
370                 default:
371                         log_state(event, _current_state);
372                         break;
373                 }
374
375                 break;
376         }
377
378         case STATE_SECOND_CLICKED: {
379                 /* Empty */
380                 _current_state = STATE_NONE;
381                 break;
382         }
383
384         case STATE_SECOND_LONG_PRESSED: {
385                 switch(event) {
386                 case FINGER_UP:
387                         _current_state = STATE_NONE;
388                         break;
389                 case FINGER_MOVE: {
390                         _current_state = STATE_MOVING;
391                         detected_pan();
392                         break;
393                 }
394                 case FINGER_DOWN:
395                         _current_state = STATE_2FINGERS_PRESSED;
396                         break;
397                 default:
398                         log_state(event, _current_state);
399                         break;
400                 }
401                 break;
402         }
403
404         case STATE_MOVING: {
405                 if(event != FINGER_MOVE)
406                         finish_panning(0);
407
408                 switch(event) {
409                 case FINGER_MOVE:
410                         _current_state = STATE_MOVING;
411                         detected_pan();         /* Pan */
412                         break;
413                 case FINGER_UP:
414
415                         /* When two fingers untouched simultaneously,
416                          * Ecore sends finger1_up and then finger2_up
417                          * sequentially.
418                          * The finger1_up switches the detector from
419                          * STATE_2FINGERS_MOVING to STATE_MOVING.
420                          * Now we are receiving finger2_up and should switch to
421                          * the initial state.
422                          */
423
424                         _current_state = STATE_NONE;
425                         break;
426                 case FINGER2_DOWN:
427                         _current_state = STATE_2FINGERS_PRESSED;
428                         break;
429                 default:
430                         log_state(event, _current_state);
431                         break;
432                 }
433                 break;
434         }
435
436         case STATE_FINGER2_MOVING: {
437                 if(event != FINGER2_MOVE)
438                         finish_panning(1);
439
440                 switch(event) {
441                 case FINGER2_MOVE:
442                         _current_state = STATE_FINGER2_MOVING;
443                         detected_finger2_pan();         /* Pan (finger2) */
444                         break;
445                 case FINGER2_UP:
446                         _current_state = STATE_NONE;
447                         break;
448                 case FINGER_DOWN:
449                         _current_state = STATE_2FINGERS_PRESSED;
450                         break;
451
452                 default:
453                         log_state(event, _current_state);
454                         break;
455                 }
456                 break;
457         }
458
459         case STATE_2FINGERS_PRESSED: {
460                 if(event != FINGER_MOVE && event != FINGER2_MOVE) {
461                         finish_zoomming();
462                         finish_rotating();
463                         finish_2fingers_panning();
464                 }
465
466                 switch(event) {
467                 case FINGER_UP:
468                         _current_state = STATE_FINGER2_PRESSED;
469                         break;
470                 case FINGER2_UP:
471                         _current_state = STATE_FINGER1_PRESSED;
472                         break;
473                 case FINGER_MOVE:
474                 case FINGER2_MOVE:
475                         _current_state = STATE_2FINGERS_MOVING;
476                         detected_zoom_rotate();         /* Zoom, Rotate etc */
477                         break;
478                 case LONG_PRESS_TIMER:
479                         /* Just ignoring this event */
480                         _current_state = STATE_2FINGERS_PRESSED;
481                         break;
482                 default:
483                         log_state(event, _current_state);
484                         break;
485                 }
486                 break;
487         }
488
489         case STATE_FINGER2_PRESSED: {
490                 switch(event) {
491                 case FINGER2_UP:
492
493                         if(finger_pressed_enough(0, 0, __CLICK_DURATION)
494                            &&  finger_pressed_enough(1, 0, __CLICK_DURATION)){
495                                 _current_state = STATE_2FINGERS_CLICKED;
496                                 detected_2finger_tap(); /* 2Finger Tap */
497                         }
498
499                         /* Nothing to do here: switching to initial state */
500                         _current_state = STATE_NONE;
501                         break;
502                 case FINGER2_MOVE:
503                         _current_state = STATE_FINGER2_MOVING;
504                         detected_finger2_pan(); /* Pan (by second finger) */
505                         break;
506                 case FINGER_DOWN:
507                         _current_state = STATE_2FINGERS_PRESSED;
508                         break;
509                 case LONG_PRESS_TIMER:
510                         /* Just ignoring this event */
511                         _current_state = STATE_FINGER2_PRESSED;
512                         break;
513                 default:
514                         log_state(event, _current_state);
515                         break;
516                 }
517                 break;
518         }
519
520         case STATE_FINGER1_PRESSED: {
521                 switch(event) {
522                 case FINGER_UP:
523                         if(finger_pressed_enough(0, 0, __CLICK_DURATION)
524                            &&  finger_pressed_enough(1, 0, __CLICK_DURATION)){
525                                 _current_state = STATE_2FINGERS_CLICKED;
526                                 detected_2finger_tap(); /* 2Finger Tap */
527                         }
528
529                         /* No need to expect other events here.
530                         *  Immediatelly switching to the initial State */
531                         _current_state = STATE_NONE;
532                         break;
533                 case FINGER2_DOWN:
534                         _current_state = STATE_2FINGERS_PRESSED;
535                         break;
536                 case FINGER_MOVE:
537                         _current_state = STATE_MOVING;
538                         detected_pan(); /* Pan */
539                         break;
540
541                 default:
542                         log_state(event, _current_state);
543                         break;
544                 }
545                 break;
546         }
547
548         case STATE_2FINGERS_CLICKED: {
549                 /* Empty */
550                 break;
551         }
552
553         case STATE_2FINGERS_MOVING: {
554                 if(event != FINGER_MOVE && event != FINGER2_MOVE) {
555                         finish_zoomming();
556                         finish_rotating();
557                         finish_2fingers_panning();
558                         _info._start_view_state.capture(_view);
559                 }
560
561                 switch(event) {
562                 case FINGER_MOVE:
563                         _current_state = STATE_2FINGERS_MOVING;
564                         detected_zoom_rotate();         /* Zoom, Rotate etc */
565                         break;
566                 case FINGER2_MOVE:
567                         _current_state = STATE_2FINGERS_MOVING;
568                         detected_zoom_rotate();         /* Zoom, Rotate etc */
569                         break;
570                 case FINGER_UP:
571                         _current_state = STATE_FINGER2_MOVING;
572                         break;
573                 case FINGER2_UP:
574                         _current_state = STATE_MOVING;
575                         break;
576                 default:
577                         log_state(event, _current_state);
578                         break;
579                 }
580                 break;
581         }
582
583         case STATE_MOVING_AFTER_SECOND_PRESS: {
584                 switch(event) {
585                 case FINGER_UP:
586                         _current_state = STATE_NONE;
587                         break;
588                 case FINGER2_DOWN:
589                         _current_state = STATE_2FINGERS_PRESSED;
590                         break;
591                 case FINGER_MOVE:
592                         _current_state = STATE_MOVING_AFTER_SECOND_PRESS;
593                         break;
594                 default:
595                         log_state(event, _current_state);
596                         break;
597                 }
598                 break;
599         }
600
601         default:
602                 log_state(event, _current_state);
603                 _current_state = STATE_NONE;
604                 break;
605         }
606
607         string s_old = get_state_str(old_state);
608         string s = get_state_str(_current_state);
609         MAPS_LOGI("%c[%d;%d;%dm"
610                   "switched from %s[%d] to %s[%d]"
611                   "%c[%d;%d;%dm",
612                   0x1B, 1, 0, FG_LITE_CYAN,
613                   s_old.c_str(), old_state,
614                   s.c_str(), _current_state,
615                   0x1B, 0, 0, 0);
616
617         /* DEBUG: trace current central coordinates */
618         log_map_center();
619 }
620
621 void view::gesture_detector_statemachine::detected_tap()        /* Tap */
622 {
623         if (!is_gesture_available(MAPS_VIEW_GESTURE_TAP))
624                 return;
625
626         log("GESTURE TAP DETECTED", FG_GREEN);
627         _gp.on_tap();
628 }
629
630 void view::gesture_detector_statemachine::detected_long_press() /* Long Press */
631 {
632         if (!is_gesture_available(MAPS_VIEW_GESTURE_LONG_PRESS))
633                 return;
634
635         log("GESTURE LONG PRESS DETECTED", FG_GREEN);
636         _gp.on_long_press();
637 }
638
639 void view::gesture_detector_statemachine::detected_double_tap() /* Double Tap */
640 {
641         if (!is_gesture_available(MAPS_VIEW_GESTURE_DOUBLE_TAP))
642                 return;
643
644         log("GESTURE DOUBLE TAP DETECTED", FG_GREEN);
645         _gp.on_double_tap();
646 }
647
648 void view::gesture_detector_statemachine::detected_second_long_press()  /* Second Long Press */
649 {
650         if (!is_gesture_available(MAPS_VIEW_GESTURE_LONG_PRESS))
651                 return;
652
653         log("GESTURE SECOND LONG PRESS DETECTED", FG_GREEN);
654         _gp.on_long_press();
655 }
656
657 void view::gesture_detector_statemachine::detected_pan()                /* Pan */
658 {
659         if (!is_gesture_available(MAPS_VIEW_GESTURE_SCROLL))
660                 return;
661
662         log("GESTURE PAN DETECTED", FG_GREEN);
663         start_panning(0);
664         _gp.on_pan(0);
665 }
666
667 void view::gesture_detector_statemachine::detected_finger2_pan()        /* Pan (second finger)*/
668 {
669         if (!is_gesture_available(MAPS_VIEW_GESTURE_SCROLL))
670                 return;
671
672         log("GESTURE FINGER2 PAN DETECTED", FG_GREEN);
673         start_panning(1);
674         _gp.on_pan(1);
675 }
676
677 /* Zoom, Rotate etc */
678 void view::gesture_detector_statemachine::detected_zoom_rotate()
679 {
680         if (!is_gesture_available(MAPS_VIEW_GESTURE_ZOOM)
681             && !is_gesture_available(MAPS_VIEW_GESTURE_ROTATE)
682             && !is_gesture_available(MAPS_VIEW_GESTURE_SCROLL))
683                 return;
684
685         log("GESTURE ZOOM ROTATE DETECTED", FG_GREEN);
686
687         bool zoom_changed = false;
688         bool rotation_changed = false;
689         bool panning_changed = false;
690         double zoom_factor = .0;
691         double rotation_angle = .0;
692         int panning_x = 0;
693         int panning_y = 0;
694
695         zoom_changed = _gp.on_zoom(is_zoomming, is_rotating, zoom_factor);
696         if (zoom_changed)
697                 start_zoomming();
698
699         rotation_changed = _gp.on_rotate(is_zoomming, is_rotating, rotation_angle);
700         if (rotation_changed)
701                 start_rotating();
702
703         panning_changed = _gp.on_two_fingers_pan(is_2fingers_panning, &panning_x, &panning_y);
704         if (panning_changed)
705                 start_2fingers_panning();
706
707         _gp.on_zoom_rotate(zoom_changed, zoom_factor, rotation_changed, rotation_angle, panning_changed, panning_x, panning_y);
708 }
709
710 void view::gesture_detector_statemachine::detected_2finger_tap()        /* 2Finger Tap */
711 {
712         if (!is_gesture_available(MAPS_VIEW_GESTURE_2_FINGER_TAP))
713                 return;
714
715         log("GESTURE 2 FINGER TAP DETECTED", FG_GREEN);
716         _gp.on_two_finger_tap();
717 }
718
719 string view::gesture_detector_statemachine::get_state_str(detector_states_e
720                                                           state)
721 {
722         string s;
723         switch(state) {
724         case STATE_NONE:
725                 s = "STATE_NONE";
726                 break;
727         case STATE_PRESSED:
728                 s = "STATE_PRESSED";
729                 break;
730         case STATE_CLICKED:
731                 s = "STATE_CLICKED";
732                 break;
733         case STATE_LONG_PRESSED:
734                 s = "STATE_LONG_PRESSED";
735                 break;
736         case STATE_SECOND_PRESSED:
737                 s = "STATE_SECOND_PRESSED";
738                 break;
739         case STATE_SECOND_CLICKED:
740                 s = "STATE_SECOND_CLICKED";
741                 break;
742         case STATE_SECOND_LONG_PRESSED:
743                 s = "STATE_SECOND_LONG_PRESSED";
744                 break;
745         case STATE_MOVING:
746                 s = "STATE_MOVING";
747                 break;
748         case STATE_FINGER2_MOVING:
749                 s = "STATE_FINGER2_MOVING";
750                 break;
751         case STATE_FINGER2_PRESSED:
752                 s = "STATE_FINGER2_PRESSED";
753                 break;
754         case STATE_FINGER1_PRESSED:
755                 s = "STATE_FINGER1_PRESSED";
756                 break;
757         case STATE_2FINGERS_PRESSED:
758                 s = "STATE_2FINGERS_PRESSED";
759                 break;
760         case STATE_2FINGERS_CLICKED:
761                 s = "STATE_2FINGERS_CLICKED";
762                 break;
763         case STATE_2FINGERS_MOVING:
764                 s = "STATE_2FINGERS_MOVING";
765                 break;
766         case STATE_MOVING_AFTER_SECOND_PRESS:
767                 s = "STATE_MOVING_AFTER_SECOND_PRESS";
768                 break;
769         default:
770                 s = "UNKNOWN";
771                 break;
772         }
773         return s;
774 }
775
776 string view::gesture_detector_statemachine::get_event_str(view_event_e event)
777 {
778         string e;
779         switch(event) {
780         case FINGER_DOWN:
781                 e = "FINGER_DOWN";
782                 break;
783         case FINGER_MOVE:
784                 e = "FINGER_MOVE";
785                 break;
786         case FINGER_UP:
787                 e = "FINGER_UP";
788                 break;
789         case FINGER2_DOWN:
790                 e = "FINGER2_DOWN";
791                 break;
792         case FINGER2_MOVE:
793                 e = "FINGER2_MOVE";
794                 break;
795         case FINGER2_UP:
796                 e = "FINGER2_UP";
797                 break;
798         case LONG_PRESS_TIMER:
799                 e = "LONG_PRESS_TIMER";
800                 break;
801         case TAP_TIMER:
802                 e = "TAP_TIMER";
803                 break;
804         default:
805                 e = "UNKNOWN";
806                 break;
807         }
808         return e;
809 }
810
811 void view::gesture_detector_statemachine::log_event(view_event_e event)
812 {
813         string e = get_event_str(event);
814         log(e.c_str(), FG_BLUE);
815 }
816
817 void view::gesture_detector_statemachine::log_state(view_event_e event,
818                                        detector_states_e state)
819 {
820         string e = get_event_str(event);
821         string s = get_state_str(state);
822
823         MAPS_LOGE("%c[%d;%d;%dm"
824                   "DEFAULT: state: %s[%d],\tevent: %s[%d]"
825                   "%c[%d;%d;%dm",
826                   0x1B, 1, 0, FG_RED,
827                   s.c_str(), state, e.c_str(), event,
828                   0x1B, 0, 0, 0);
829 }
830 //LCOV_EXCL_STOP