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 #include "gesture_simulation.h"
17 #include "hilog_wrapper.h"
18 #include "parcel_util.h"
19
20 namespace OHOS {
21 namespace Accessibility {
GesturePathPositionDefine(float positionX,float positionY)22 GesturePathPositionDefine::GesturePathPositionDefine(float positionX, float positionY)
23 {
24 HILOG_DEBUG("start.");
25 positionX_ = positionX;
26 positionY_ = positionY;
27 }
28
GetPositionX()29 float GesturePathPositionDefine::GetPositionX()
30 {
31 HILOG_DEBUG("start and positionX_ is %{public}f", positionX_);
32 return positionX_;
33 }
34
GetPositionY()35 float GesturePathPositionDefine::GetPositionY()
36 {
37 HILOG_DEBUG("start and positionY_ is %{public}f", positionY_);
38 return positionY_;
39 }
40
SetPositionX(float positionX)41 void GesturePathPositionDefine::SetPositionX(float positionX)
42 {
43 HILOG_DEBUG("start.");
44 positionX_ = positionX;
45 }
46
SetPositionY(float positionY)47 void GesturePathPositionDefine::SetPositionY(float positionY)
48 {
49 HILOG_DEBUG("start.");
50 positionY_ = positionY;
51 }
52
ReadFromParcel(Parcel & parcel)53 bool GesturePathPositionDefine::ReadFromParcel(Parcel &parcel)
54 {
55 HILOG_DEBUG("start.");
56 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Float, parcel, positionX_);
57 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Float, parcel, positionY_);
58 return true;
59 }
60
Marshalling(Parcel & parcel) const61 bool GesturePathPositionDefine::Marshalling(Parcel &parcel) const
62 {
63 HILOG_DEBUG("start.");
64 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Float, parcel, positionX_);
65 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Float, parcel, positionY_);
66 return true;
67 }
68
Unmarshalling(Parcel & parcel)69 GesturePathPositionDefine *GesturePathPositionDefine::Unmarshalling(Parcel &parcel)
70 {
71 HILOG_DEBUG("start.");
72 GesturePathPositionDefine *gesturePathPositionDefine = new GesturePathPositionDefine();
73
74 if (gesturePathPositionDefine && !gesturePathPositionDefine->ReadFromParcel(parcel)) {
75 HILOG_ERROR("ReadFromParcel GesturePathPositionDefine failed.");
76 delete gesturePathPositionDefine;
77 gesturePathPositionDefine = nullptr;
78 }
79
80 return gesturePathPositionDefine;
81 }
82
GesturePathDefine(GesturePathPositionDefine & startPosition,GesturePathPositionDefine & endPosition,int64_t durationTime)83 GesturePathDefine::GesturePathDefine(GesturePathPositionDefine &startPosition,
84 GesturePathPositionDefine &endPosition, int64_t durationTime)
85 {
86 HILOG_DEBUG("start.");
87
88 if (startPosition.GetPositionX() < 0 || startPosition.GetPositionY() < 0) {
89 HILOG_ERROR("startPosition: (%{public}f , %{public}f) is not allowed.",
90 startPosition.GetPositionX(), startPosition.GetPositionY());
91 return;
92 }
93 startPosition_ = startPosition;
94
95 if (endPosition.GetPositionX() < 0 || endPosition.GetPositionY() < 0) {
96 HILOG_ERROR("endPosition : (%{public}f , %{public}f) is not allowed.",
97 endPosition.GetPositionX(), endPosition.GetPositionY());
98 return;
99 }
100 endPosition_ = endPosition;
101
102 durationTime_ = durationTime;
103 }
104
GetDurationTime()105 int64_t GesturePathDefine::GetDurationTime()
106 {
107 HILOG_DEBUG("start and max stroke duration is %{public}lld", durationTime_);
108 return durationTime_;
109 }
110
GetEndPosition()111 GesturePathPositionDefine &GesturePathDefine::GetEndPosition()
112 {
113 HILOG_DEBUG("start.");
114 return endPosition_;
115 }
116
GetMaxStrokeDuration()117 int64_t GesturePathDefine::GetMaxStrokeDuration()
118 {
119 HILOG_DEBUG("start and max stroke duration is %{public}lld", MAX_STROKE_DURATION);
120 return MAX_STROKE_DURATION;
121 }
122
GetMaxStrokes()123 uint32_t GesturePathDefine::GetMaxStrokes()
124 {
125 HILOG_DEBUG("start and max strokes is %{public}d", MAX_STROKES);
126 return MAX_STROKES;
127 }
128
GetStartPosition()129 GesturePathPositionDefine &GesturePathDefine::GetStartPosition()
130 {
131 HILOG_DEBUG("start.");
132 return startPosition_;
133 }
134
SetDurationTime(int64_t durationTime)135 void GesturePathDefine::SetDurationTime(int64_t durationTime)
136 {
137 HILOG_DEBUG("start.");
138 durationTime_ = durationTime;
139 }
140
SetEndPosition(GesturePathPositionDefine & endPosition)141 void GesturePathDefine::SetEndPosition(GesturePathPositionDefine &endPosition)
142 {
143 HILOG_DEBUG("start.");
144 endPosition_ = endPosition;
145 }
146
SetStartPosition(GesturePathPositionDefine & startPosition)147 void GesturePathDefine::SetStartPosition(GesturePathPositionDefine &startPosition)
148 {
149 HILOG_DEBUG("start.");
150 startPosition_ = startPosition;
151 }
152
ReadFromParcel(Parcel & parcel)153 bool GesturePathDefine::ReadFromParcel(Parcel &parcel)
154 {
155 HILOG_DEBUG("start.");
156
157 std::unique_ptr<GesturePathPositionDefine> startPosition(parcel.ReadParcelable<GesturePathPositionDefine>());
158 if (!startPosition) {
159 HILOG_ERROR("ReadParcelable startPosition failed.");
160 return false;
161 }
162 startPosition_ = *startPosition;
163
164 std::unique_ptr<GesturePathPositionDefine> endPosition(parcel.ReadParcelable<GesturePathPositionDefine>());
165 if (!endPosition) {
166 HILOG_ERROR("ReadParcelable endPosition failed.");
167 return false;
168 }
169 endPosition_ = *endPosition;
170
171 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, durationTime_);
172
173 return true;
174 }
175
Marshalling(Parcel & parcel) const176 bool GesturePathDefine::Marshalling(Parcel &parcel) const
177 {
178 HILOG_DEBUG("start.");
179 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &startPosition_);
180 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &endPosition_);
181 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, durationTime_);
182 return true;
183 }
184
Unmarshalling(Parcel & parcel)185 GesturePathDefine *GesturePathDefine::Unmarshalling(Parcel &parcel)
186 {
187 HILOG_DEBUG("start.");
188 GesturePathDefine *gesturePathDefine = new GesturePathDefine();
189
190 if (gesturePathDefine && !gesturePathDefine->ReadFromParcel(parcel)) {
191 HILOG_ERROR("ReadFromParcel GesturePathDefine failed.");
192 delete gesturePathDefine;
193 gesturePathDefine = nullptr;
194 }
195
196 return gesturePathDefine;
197 }
198 } // namespace Accessibility
199 } // namespace OHOS
200