• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef GESTURE_SIMULATION_H
17 #define GESTURE_SIMULATION_H
18 
19 #include <cstdint>
20 #include <vector>
21 #include "parcel_util.h"
22 
23 namespace OHOS {
24 namespace Accessibility {
25 class GesturePathPositionDefine : public Parcelable {
26 public:
GesturePathPositionDefine()27     GesturePathPositionDefine() {}
~GesturePathPositionDefine()28     ~GesturePathPositionDefine() {}
29 
30     GesturePathPositionDefine(float positionX, float positionY);
31 
32     /**
33      * @brief Obtains the X coordinate of the position.
34      * @param
35      * @return Return the X coordinate of the position.
36      */
37     float GetPositionX();
38 
39     /**
40      * @brief Obtains the Y coordinate of the position.
41      * @param
42      * @return Return the Y coordinate of the position.
43      */
44     float GetPositionY();
45 
46     /**
47      * @brief Sets the X coordinate of the position.
48      * @param positionX The X coordinate of the position.
49      * @return
50      */
51     void SetPositionX(float positionX);
52 
53     /**
54      * @brief Sets the Y coordinate of the position.
55      * @param positionX The Y coordinate of the position.
56      * @return
57      */
58     void SetPositionY(float positionY);
59 
60     /**
61      * @brief read this sequenceable object from a Parcel.
62      * @param parcel Indicates the Parcel object into which the sequenceable object has been marshaled.
63      * @return Return true if read successfully, else return false.
64      */
65     bool ReadFromParcel(Parcel &parcel);
66 
67     /**
68      * @brief Marshals this sequenceable object into a Parcel.
69      * @param parcel Indicates the Parcel object to which the sequenceable object will be marshaled.
70      * @return Return true if Marshal successfully, else return false.
71      */
72     virtual bool Marshalling(Parcel &parcel) const override;
73 
74     /**
75      * @brief Unmarshals this sequenceable object from a Parcel.
76      * @param parcel Indicates the Parcel object into which the sequenceable object has been marshaled.
77      * @return Return a sequenceable object of GesturePathPositionDefine.
78      */
79     static GesturePathPositionDefine *Unmarshalling(Parcel &parcel);
80 
81 private:
82     float positionX_ = .0f;
83     float positionY_ = .0f;
84 };
85 
86 class GesturePathDefine : public Parcelable {
87 public:
GesturePathDefine()88     GesturePathDefine() {}
~GesturePathDefine()89     ~GesturePathDefine() {}
90 
91     GesturePathDefine(GesturePathPositionDefine &startPosition,
92         GesturePathPositionDefine &endPosition, int64_t durationTime);
93 
94     /**
95      * @brief Obtains the duration for completing the maximum number of gesture strokes.
96      * @param
97      * @return Return the duration for completing the maximum number of gesture strokes.
98      */
99     static int64_t GetMaxStrokeDuration();
100 
101     /**
102      * @brief Obtains the maximum number of strokes in this gesture path.
103      * @param
104      * @return Return the maximum number of strokes in this gesture path.
105      */
106     static uint32_t GetMaxStrokes();
107 
108     /**
109      * @brief Obtains the duration in which this gesture path continues.
110      * @param
111      * @return Return the duration in which this gesture path continues.
112      */
113     int64_t GetDurationTime();
114 
115     /**
116      * @brief Obtains the end position of this gesture path.
117      * @param
118      * @return Return the end position of this gesture path.
119      */
120     GesturePathPositionDefine &GetEndPosition();
121 
122     /**
123      * @brief Obtains the start position of this gesture path.
124      * @param
125      * @return Return the start position of this gesture path.
126      */
127     GesturePathPositionDefine &GetStartPosition();
128 
129     /**
130      * @brief Sets the duration for this gesture path to continue.
131      * @param durationTime The duration for this gesture path to continue.
132      * @return
133      */
134     void SetDurationTime(int64_t durationTime);
135 
136     /**
137      * @brief Sets the end position of this gesture path.
138      * @param endPosition The end position of this gesture path.
139      * @return
140      */
141     void SetEndPosition(GesturePathPositionDefine &endPosition);
142 
143     /**
144      * @brief Sets the start position of this gesture path.
145      * @param startPosition The start position of this gesture path.
146      * @return
147      */
148     void SetStartPosition(GesturePathPositionDefine &startPosition);
149 
150     /**
151      * @brief read this sequenceable object from a Parcel.
152      * @param parcel Indicates the Parcel object into which the sequenceable object has been marshaled.
153      * @return Return true if read successfully, else return false.
154      */
155     bool ReadFromParcel(Parcel &parcel);
156 
157     /**
158      * @brief Marshals this sequenceable object into a Parcel.
159      * @param parcel Indicates the Parcel object to which the sequenceable object will be marshaled.
160      * @return Return true if Marshal successfully, else return false.
161      */
162     virtual bool Marshalling(Parcel &parcel) const override;
163 
164     /**
165      * @brief Unmarshals this sequenceable object from a Parcel.
166      * @param parcel Indicates the Parcel object into which the sequenceable object has been marshaled.
167      * @return Return a sequenceable object of GesturePathDefine.
168      */
169     static GesturePathDefine *Unmarshalling(Parcel &parcel);
170 
171 private:
172     const static int64_t MAX_STROKE_DURATION = 60 * 1000;
173     const static uint32_t MAX_STROKES = 10;
174 
175     GesturePathPositionDefine startPosition_;
176     GesturePathPositionDefine endPosition_;
177     int64_t durationTime_ = 0;
178 };
179 
180 class GestureResultListener {
181 public:
182     /**
183      * @brief Called when the gesture is finished.
184      * @param sequence
185      * @param result Return true if the gesture which is listened is injected successfully, else return false.
186      * @return
187      */
188     virtual void OnGestureInjectResult(uint32_t sequence, bool result) = 0;
189 };
190 } // namespace Accessibility
191 } // namespace OHOS
192 #endif // GESTURE_SIMULATION_H