4 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 * @ingroup CAPI_CONTEXT_FRAMEWORK
22 * @defgroup CAPI_CONTEXT_GESTURE_MODULE Gesture Recognition
24 * @brief The gesture recognition API allows applications to be notified and
25 * react when the user performs a gesture.
27 * @section CAPI_CONTEXT_GESTURE_MODULE_HEADER Required Header
28 * \#include <gesture_recognition.h>
30 * @section CAPI_CONTEXT_GESTURE_MODULE_OVERVIEW Overview
33 * The gesture recognition API allows to register callback functions to be called
34 * when the user performs meaningful gestures listed in #gesture_type_e, for example,
37 * Regardless of the gesture types,
38 * the overall process of using the gesture recognition API is as follows.
40 * If necessary, applications can check whether a gesture type is supported in the current device in advance.
41 * Note that, some gestures may not be supported in some devices, if the devices do not have necessary sensors.
44 bool supported = false;
45 gesture_is_supported(GESTURE_SHAKE, &supported);
48 // Not supported in the current device.
52 * If the gesture type is supported, to use the recognition engine,
53 * an @c handle for the gesture recognition needs to be initialized first.
58 result = gesture_create(&handle);
60 if (result != GESTURE_ERROR_NONE) {
65 * With the @c handle initialized, a callback function,
66 * which will be called when a specified gesture is detected,
67 * is registered by using gesture_start_recognition().
70 result = gesture_start_recognition(handle, GESTURE_SHAKE, GESTURE_OPTION_DEFAULT, gesture_cb, NULL);
72 if (result != GESTURE_ERROR_NONE) {
73 // An error occurred. Do necessary error handling here.
77 * Then the callback function @c gesture_cb will be called whenever the shake gesture is detected.
79 * Note that, calling gesture_start_recognition() twice on the same handle returns #GESTURE_ERROR_ALREADY_STARTED.
80 * If it needs to recognize another gesture using the same handle,
81 * the started recognition session should be stopped and restarted with the new gesture type.
82 * Otherwise, the application needs to created multiple handles, one handle for each gesture needed.
84 * An example callback function is as follows.
87 void gesture_cb(gesture_type_e type, const gesture_data_h data, double timestamp, gesture_error_e error, void *user_data)
90 gesture_event_e event;
92 if (error != GESTURE_ERROR_NONE) {
93 // An error occurred. Do necessary error handling here.
97 if (type == GESTURE_SHAKE) {
98 // More than one gestures can be started using the same callback function.
100 result = gesture_get_event(data, &event);
102 if (result != GESTURE_ERROR_NONE) {
103 // An error occurred. Do necessary error handling here.
107 if (event == GESTURE_SHAKE_DETECTED) {
108 // Shake gesture is started
110 } else if (event == GESTURE_SHAKE_FINISHED) {
111 // Shake gesture is stopped
117 * As we started gesture recognition with #GESTURE_SHAKE,
118 * gesture_get_event() returns either #GESTURE_SHAKE_DETECTED or #GESTURE_SHAKE_FINISHED
119 * as it has two different states, the gesture is started, or finished.
120 * Most of the gesture types, however, simply provide #GESTURE_EVENT_DETECTED.
121 * In such cases, #GESTURE_EVENT_NONE may not be delivered at all.
123 * If #GESTURE_TILT is started, within the callback function,
124 * gesture_get_tilt() can be used to extract the tilting degrees.
126 * Finally, if the application does not need to be notified the gesture event,
127 * it can be stopped as follows.
130 gesture_stop_recognition(handle);
132 // If the handle will not be used anymore, its resources needs be released explicitly.
133 gesture_release(handle);
136 * @section CAPI_CONTEXT_GESTURE_MODULE_FEATURE Related Features
137 * This API is related with the following features:\n
138 * - http://tizen.org/feature/sensor.gesture_recognition\n
139 * - http://tizen.org/feature/sensor.wrist_up
141 * It is recommended to design feature related code in your application for reliability.\n
143 * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
145 * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
147 * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tizen-studio/native-tools/configuring-your-app/manifest-text-editor#feature"><b>Feature Element</b>.</a>