1 /* 2 * Copyright (c) 2023 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 POINTER_INFO_H 17 #define POINTER_INFO_H 18 #include <string> 19 #include <vector> 20 #include <iostream> 21 #include <sstream> 22 #include <nlohmann/json.hpp> 23 #include "ui_model.h" 24 #include "touch_event.h" 25 #include "velocity.h" 26 #include "offset.h" 27 28 namespace OHOS::uitest { 29 enum TouchOpt : uint8_t { 30 OP_CLICK = 1, OP_LONG_CLICK, OP_DOUBLE_CLICK, OP_SWIPE, OP_DRAG, OP_FLING, OP_PINCH, 31 OP_HOME, OP_RECENT, OP_RETURN 32 }; 33 34 class FingerInfo { 35 public: 36 static const int MAX_VELOCITY = 40000; 37 38 nlohmann::json WriteData(); 39 std::string WriteWindowData(std::string actionType); 40 SetFirstTouchEventInfo(TouchEventInfo & first)41 void SetFirstTouchEventInfo(TouchEventInfo& first) 42 { 43 firstTouchEventInfo = first; 44 } 45 GetFirstTouchEventInfo()46 TouchEventInfo& GetFirstTouchEventInfo() 47 { 48 return firstTouchEventInfo; 49 } 50 SetLastTouchEventInfo(TouchEventInfo & last)51 void SetLastTouchEventInfo(TouchEventInfo& last) 52 { 53 lastTouchEventInfo = last; 54 } 55 GetLastTouchEventInfo()56 TouchEventInfo& GetLastTouchEventInfo() 57 { 58 return lastTouchEventInfo; 59 } 60 SetStepLength(int step)61 void SetStepLength(int step) 62 { 63 stepLength = step; 64 } 65 GetStepLength()66 int GetStepLength() 67 { 68 return stepLength; 69 } 70 SetVelocity(double vel)71 void SetVelocity(double vel) 72 { 73 velocity = vel; 74 } 75 GetVelocity()76 double GetVelocity() 77 { 78 return velocity; 79 } 80 SetDirection(const Offset & dir)81 void SetDirection(const Offset& dir) 82 { 83 direction = dir; 84 } 85 GetDirection()86 Offset& GetDirection() 87 { 88 return direction; 89 } 90 91 private: 92 TouchEventInfo firstTouchEventInfo; 93 TouchEventInfo lastTouchEventInfo; 94 int stepLength = 0; // 步长 95 double velocity; // 离手速度 96 Offset direction; // 方向 97 }; 98 99 class PointerInfo { 100 public: 101 static const std::string EVENT_TYPE; 102 static std::map <int32_t, std::string> OP_TYPE; 103 // json 104 nlohmann::json WriteData(); 105 std::string WriteWindowData(); 106 SetTouchOpt(TouchOpt opt)107 void SetTouchOpt(TouchOpt opt) 108 { 109 touchOpt = opt; 110 } 111 GetTouchOpt()112 TouchOpt& GetTouchOpt() 113 { 114 return touchOpt; 115 } 116 SetFingerNumber(int8_t num)117 void SetFingerNumber(int8_t num) 118 { 119 fingerNumber = num; 120 } 121 GetFingerNumber()122 int8_t GetFingerNumber() 123 { 124 return fingerNumber; 125 } 126 AddFingerInfo(FingerInfo & fingerInfo)127 void AddFingerInfo(FingerInfo& fingerInfo) 128 { 129 fingers.push_back(fingerInfo); 130 } 131 GetFingerInfoList()132 std::vector<FingerInfo>& GetFingerInfoList() 133 { 134 return fingers; 135 } 136 SetDuration(double dur)137 void SetDuration(double dur) 138 { 139 duration = dur; 140 } 141 GetDuration()142 double GetDuration() 143 { 144 return duration; 145 } 146 SetBundleName(std::string name)147 void SetBundleName(std::string name) 148 { 149 bundleName = name; 150 } 151 GetBundleName()152 std::string GetBundleName() 153 { 154 return bundleName; 155 } 156 SetAbilityName(std::string name)157 void SetAbilityName(std::string name) 158 { 159 abilityName = name; 160 } 161 GetAbilityName()162 std::string GetAbilityName() 163 { 164 return abilityName; 165 } 166 SetAvgDirection(Offset & direction)167 void SetAvgDirection(Offset& direction) 168 { 169 avgDirection = direction; 170 } 171 GetAvgDirection()172 Offset& GetAvgDirection() 173 { 174 return avgDirection; 175 } 176 SetAvgStepLength(int stepLength)177 void SetAvgStepLength(int stepLength) 178 { 179 avgStepLength = stepLength; 180 } 181 GetAvgStepLength()182 int GetAvgStepLength() 183 { 184 return avgStepLength; 185 } 186 SetAvgVelocity(double velocity)187 void SetAvgVelocity(double velocity) 188 { 189 avgVelocity = velocity; 190 } 191 GetAvgVelocity()192 double GetAvgVelocity() 193 { 194 return avgVelocity; 195 } 196 SetCenterSet(Point & center)197 void SetCenterSet(Point& center) 198 { 199 centerSet = center; 200 } 201 GetCenterSet()202 Point& GetCenterSet() 203 { 204 return centerSet; 205 } 206 SetFirstTrackPoint(TouchEventInfo firstTrackPoint)207 void SetFirstTrackPoint(TouchEventInfo firstTrackPoint) 208 { 209 firstTrackPoint_ = firstTrackPoint; 210 } 211 GetFirstTrackPoint()212 TouchEventInfo GetFirstTrackPoint() const 213 { 214 return firstTrackPoint_; 215 } 216 217 private: 218 TouchOpt touchOpt = OP_CLICK; 219 int8_t fingerNumber = 0; 220 std::vector<FingerInfo> fingers; 221 double duration; 222 std::string bundleName; 223 std::string abilityName; 224 Offset avgDirection; 225 int avgStepLength = 0; 226 double avgVelocity; 227 Point centerSet; 228 TouchEventInfo firstTrackPoint_; 229 }; 230 } 231 #endif // POINTER_INFO_H