2 * Copyright 2012 Samsung Electronics Co., Ltd
\r
4 * Licensed under the Flora License, Version 1.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://floralicense.org/license/
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
22 #include <Elementary.h>
\r
24 #include "cam_long_press.h"
\r
26 typedef struct cb_item {
\r
27 LONG_PRESS_START_CALLBACK start_func;
\r
28 LONG_PRESS_CANCEL_CALLBACK cancel_func;
\r
34 Ecore_Timer *hold_timer;
\r
38 }long_press_timer_t;
\r
40 static long_press_timer_t g_timer[LONG_PRESS_ID_MAX_NUMS];
\r
42 bool cam_get_long_press_running_state(int index)
\r
44 if (index >=LONG_PRESS_ID_MAX_NUMS || index < 0) {
\r
47 return g_timer[index].runing;
\r
49 static Eina_Bool _timer_cb(void *data)
\r
55 long_press_timer_t *item = (long_press_timer_t*)data;
\r
57 item->hold_timer = NULL;
\r
58 if (item->start_func) {
\r
59 item->start_func(item->data, item->x, item->y);
\r
60 item->runing = TRUE;
\r
62 return ECORE_CALLBACK_CANCEL;
\r
65 int cam_long_press_register(int index, double time,
\r
66 LONG_PRESS_START_CALLBACK start_func,
\r
67 LONG_PRESS_CANCEL_CALLBACK end_func,
\r
70 if(index >= LONG_PRESS_ID_MAX_NUMS)
\r
71 return EXIT_FAILURE;
\r
73 if(g_timer[index].hold_timer != NULL) {
\r
74 DEBUG_TRACE("Already register! \n");
\r
75 return EXIT_SUCCESS;
\r
78 g_timer[index].start_func = start_func;
\r
79 g_timer[index].cancel_func = end_func;
\r
80 g_timer[index].data = data;
\r
81 g_timer[index].runing = FALSE;
\r
82 g_timer[index].time = time;
\r
84 return EXIT_SUCCESS;
\r
87 int cam_long_press_unregister(int index)
\r
89 if(index >= LONG_PRESS_ID_MAX_NUMS)
\r
90 return EXIT_FAILURE;
\r
92 if (g_timer[index].hold_timer) {
\r
93 ecore_timer_del(g_timer[index].hold_timer);
\r
94 g_timer[index].hold_timer = NULL;
\r
97 return EXIT_SUCCESS;
\r
100 void cam_long_press_trigger(int index, Evas_Coord x, Evas_Coord y)
\r
102 if(index >= LONG_PRESS_ID_MAX_NUMS)
\r
105 if (g_timer[index].hold_timer) {
\r
109 g_timer[index].hold_timer = ecore_timer_add(g_timer[index].time, _timer_cb, &g_timer[index]);
\r
110 if (!g_timer[index].hold_timer) {
\r
111 DEBUG_TRACE("Failed to trigger the hold timer\n");
\r
114 /*Update valid region*/
\r
115 g_timer[index].x = x;
\r
116 g_timer[index].y = y;
\r
117 g_timer[index].runing = FALSE;
\r
120 void cam_long_press_validate(int index, Evas_Coord x, Evas_Coord y)
\r
122 if(index >= LONG_PRESS_ID_MAX_NUMS)
\r
128 if (!g_timer[index].hold_timer) {
\r
132 dx = (g_timer[index].x - x);
\r
135 dy = (g_timer[index].y - y);
\r
138 /*TODO:this condision is too strict*/
\r
139 if ((dx + dy) > ((elm_config_finger_size_get() / 2) * (elm_config_finger_size_get() / 2))) {
\r
140 DEBUG_TRACE("validate failed, del timer\n");
\r
141 ecore_timer_del(g_timer[index].hold_timer);
\r
142 g_timer[index].hold_timer = NULL;
\r
147 void cam_long_press_cancel(int index)
\r
149 if(index >= LONG_PRESS_ID_MAX_NUMS)
\r
152 if (g_timer[index].hold_timer) {
\r
153 ecore_timer_del(g_timer[index].hold_timer);
\r
154 g_timer[index].hold_timer = NULL;
\r
156 g_timer[index].runing = FALSE;
\r
157 if (g_timer[index].cancel_func) {
\r
158 g_timer[index].cancel_func(g_timer[index].data, g_timer[index].x, g_timer[index].y);
\r