ec8fbcf833b565adffd17331deb92657ffdf6ae8
[platform/framework/native/uix.git] / inc / FUixSensorMotion.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FUixMotion.h
20  * @brief       This is the header file for the %Motion class.
21  *
22  * This header file contains the declarations of the %Motion class.
23  */
24
25 #ifndef _FUIX_SENSOR_MOTION_H_
26 #define _FUIX_SENSOR_MOTION_H_
27
28 #include <FUixSensorMotionCommon.h>
29 #include <FUixSensorIMotionEventListener.h>
30 #include <FBaseObject.h>
31 #include <FBaseDataType.h>
32
33 namespace Tizen { namespace Uix { namespace Sensor
34 {
35
36 class _MotionImpl;
37
38 /**
39  * @class       Motion
40  * @brief       This class is used to probe the state or to receive an event about the conceptual states of the device's movement.
41  *
42  * @since       2.0
43  *
44  * @remarks     @b Header @b %file: @b \#include @b <FUix.h> @n
45  *              @b Library : @b osp-uix
46  *
47  * The %Motion class allows an application to know about the movement of the device. The information is given in 2 ways:
48  * the application probes the state or the application registers a listener and receives an event when a movement is observed.
49  * @n
50  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/uix/device_motions.htm">Device Motions</a>.
51  *
52  * The following example demonstrates how to use the %Motion class to register a motion event listener and receive motion events.
53  *
54  * @code
55  * class MotionExample : public Tizen::Uix::IMotionEventListener
56  * {
57  * public:
58  *   result Initialize();
59  *
60  *   // IMotionEventListener
61  *   void OnDoubleTapDetected(void);
62  *   void OnShakeDetected(Tizen::Uix::Sensor::MotionState motionState);
63  *   void OnSnapDetected(Tizen::Uix::Sensor::MotionSnapType snapType);
64  *
65  * private:
66  *   Tizen::Uix::Motion* pMotion;
67  * };
68  *
69  * result MotionExample::Initialize(void)
70  * {
71  *   pMotion = new Motion();
72  *   pMotion->Construct(*this);
73  *   pMotion->SetEnabled(MOTION_TYPE_DOUBLETAP | MOTION_TYPE_SHAKE);
74  *
75  *   return E_SUCCESS;
76  * }
77  *
78  * void
79  * MotionExample::OnDoubleTapDetected(void)
80  * {
81  *      // ....
82  * }
83  *
84  * void
85  * MotionExample::OnShakeDetected(MotionState motionState)
86  * {
87  *      // ....
88  * }
89  *
90  * void
91  * MotionExample::OnSnapDetected(MotionSnapType snapType)
92  * {
93  *   // In this example, since Snap is not enabled, this listener will not be called.
94  * }
95  * @endcode
96  */
97
98 class _OSP_EXPORT_ Motion
99         : public Tizen::Base::Object
100 {
101 // Lifecycle
102 public:
103         /**
104          * This is the default constructor for this class.
105          *
106          * @since   2.0
107          */
108         Motion(void);
109
110         /**
111          * This is the destructor for this class.
112          *
113          * @since   2.0
114          */
115         virtual ~Motion(void);
116
117 //Operation
118 public:
119         /**
120          * Initializes this instance of %Motion with the specified listener.
121          *
122          * @since       2.0
123          *
124          * @return      An error code
125          * @param[in]   listener                    An instance of IMotionEventListener
126          * @exception   E_SUCCESS                   The method is successful.
127          * @exception   E_OUT_OF_MEMORY             The memory is insufficient.
128          * @exception   E_INVALID_STATE             This instance is in an invalid state.
129          * @exception   E_MAX_EXCEEDED              The application has reached the maximum number of motion instances.
130          * @exception   E_UNSUPPORTED_OPERATION     The motion detection is not supported.
131          */
132         result Construct(IMotionEventListener& listener);
133
134         /**
135          * Sets the motion event type. @n
136          * If this method is not called, then by default all the motion event types will be captured by the listener.
137          * If the motion events are not be captured, this method can be called with @c type set to @c MOTION_TYPE_NONE.
138          *
139          * @since       2.0
140          *
141          * @param[in]   type                The type of motions that are captured by a listener @n
142          *                                  Multiple motion types of type Tizen::Uix::Sensor::MotionType can be combined using the logical OR operator.
143          * @exception   E_SUCCESS           The method is successful.
144          * @exception   E_INVALID_STATE     This instance has not been constructed as yet.
145          * @exception   E_INVALID_ARG       A specified input parameter is invalid.  @if OSPCOMPAT @b Since: @b 2.0 @endif
146          * @remarks     The specific error code can be accessed using the GetLastResult() method.
147          */
148         void SetEnabled(unsigned long type);
149
150         /**
151          * Checks whether the specified @c MotionType is supported. @n
152          * @c MOTION_TYPE_NONE and @c MOTION_TYPE_ALL are invalid, and @c false will be returned for these types.
153          *
154          * @since       2.0
155          *
156          * @return      @c true if the specified motion type is supported, @n
157          *              else @c false
158          * @param[in]   type    The type of the motion to query
159          */
160         bool IsSupported(MotionType type) const;
161
162 private:
163         Motion(const Motion& value);
164         Motion& operator =(const Motion& value);
165
166 private:
167         _MotionImpl* __pMotionImpl;
168         friend class _MotionImpl;
169
170 }; // Motion
171
172 } } } // Tizen::Uix::Sensor
173
174 #endif //_FUIX_SENSOR_MOTION_H_