ebd4b5dda619802c9c060bbf6cd488debdf8eb1e
[framework/osp/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        FUixSensorMotion.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 receive an event about the conceptual states of the device's movement.
41  *
42  * @since       2.0
43  *
44  * The %Motion class allows an application to know about the movement of the device. The information is given in 2 ways:
45  * the application probes the state or the application registers a listener and receives an event when a movement is observed.
46  * 
47  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/uix/device_motions.htm">Device Motions</a>.
48  *
49  * The following example demonstrates how to use the %Motion class to register a motion event listener and receive motion events.
50  *
51  * @code
52  * class MotionExample : public Tizen::Uix::IMotionEventListener
53  * {
54  * public:
55  *   result Initialize();
56  *
57  *   // IMotionEventListener
58  *   void OnDoubleTapDetected(void);
59  *   void OnShakeDetected(Tizen::Uix::Sensor::MotionState motionState);
60  *   void OnSnapDetected(Tizen::Uix::Sensor::MotionSnapType snapType);
61  *
62  * private:
63  *   Tizen::Uix::Sensor::Motion* pMotion;
64  * };
65  *
66  * result MotionExample::Initialize(void)
67  * {
68  *   pMotion = new Motion();
69  *   pMotion->Construct(*this);
70  *   pMotion->SetEnabled(MOTION_TYPE_DOUBLETAP | MOTION_TYPE_SHAKE);
71  *
72  *   return E_SUCCESS;
73  * }
74  *
75  * void
76  * MotionExample::OnDoubleTapDetected(void)
77  * {
78  *      // ....
79  * }
80  *
81  * void
82  * MotionExample::OnShakeDetected(MotionState motionState)
83  * {
84  *      // ....
85  * }
86  *
87  * void
88  * MotionExample::OnSnapDetected(MotionSnapType snapType)
89  * {
90  *   // In this example, since Snap is not enabled, this listener will not be called.
91  * }
92  * @endcode
93  */
94
95 class _OSP_EXPORT_ Motion
96         : public Tizen::Base::Object
97 {
98 // Lifecycle
99 public:
100         /**
101          * This is the default constructor for this class.
102          *
103          * @since   2.0
104          */
105         Motion(void);
106
107         /**
108          * This is the destructor for this class.
109          *
110          * @since   2.0
111          */
112         virtual ~Motion(void);
113
114 //Operation
115 public:
116         /**
117          * Initializes this instance of %Motion with the specified @c listener.
118          *
119          * @since       2.0
120          *
121          * @return      An error code
122          * @param[in]   listener                    An instance of IMotionEventListener
123          * @exception   E_SUCCESS                   The method is successful.
124          * @exception   E_OUT_OF_MEMORY             The memory is insufficient.
125          * @exception   E_INVALID_STATE             This instance is in an invalid state.
126          * @exception   E_MAX_EXCEEDED              The application has reached the maximum number of motion instances.
127          * @exception   E_UNSUPPORTED_OPERATION     The motion detection is not supported.
128          */
129         result Construct(IMotionEventListener& listener);
130
131         /**
132          * Sets the motion event type. @n
133          * If the %SetEnabled() method is not called, then by default all the motion event types are captured by the listener.
134          * If the motion events are not to be captured, this method can be called with @c type set to @c MOTION_TYPE_NONE.
135          *
136          * @since       2.0
137          *
138          * @param[in]   type                The type of motions that are captured by a listener @n
139          *                                  Multiple motion types of type Tizen::Uix::Sensor::MotionType can be combined using the logical OR operator.
140          * @exception   E_SUCCESS           The method is successful.
141          * @exception   E_INVALID_STATE     This instance has not been constructed as yet.
142          * @exception   E_INVALID_ARG       The specified input parameter is invalid.
143          * @remarks     The specific error code can be accessed using the GetLastResult() method.
144          */
145         void SetEnabled(unsigned long type);
146
147         /**
148          * Checks whether the specified @c type is supported. @n
149          * @c MOTION_TYPE_NONE and @c MOTION_TYPE_ALL are unsupported types, and @c false is returned for these types.
150          *
151          * @since       2.0
152          *
153          * @return      @c true if the specified motion type is supported, @n
154          *              else @c false
155          * @param[in]   type    The type of the motion to query
156          */
157         bool IsSupported(MotionType type) const;
158
159 private:
160         Motion(const Motion& value);
161         Motion& operator =(const Motion& value);
162
163 private:
164         _MotionImpl* __pMotionImpl;
165         friend class _MotionImpl;
166
167 }; // Motion
168
169 } } } // Tizen::Uix::Sensor
170
171 #endif //_FUIX_SENSOR_MOTION_H_