1 /* 2 * Copyright (c) 2025 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 PULL_THROW_SUBSCRIBER_HANDLER_H 17 #define PULL_THROW_SUBSCRIBER_HANDLER_H 18 19 #include <algorithm> 20 #include <atomic> 21 #include <list> 22 #include <map> 23 #include <memory> 24 #include <mutex> 25 #include <set> 26 #include <thread> 27 28 #include "singleton.h" 29 30 #include "long_press_event.h" 31 #include "pointer_event.h" 32 #include "uds_server.h" 33 34 35 namespace OHOS { 36 namespace MMI { 37 38 class PullThrowSubscriberHandler final { 39 DECLARE_DELAYED_SINGLETON(PullThrowSubscriberHandler); 40 public: 41 DISALLOW_COPY_AND_MOVE(PullThrowSubscriberHandler); 42 43 struct FingerGesture { 44 struct { 45 int32_t id { 0 }; 46 int32_t x { 0 }; 47 int32_t y { 0 }; 48 int64_t downTime { 0 }; 49 } touches[2]; 50 }; 51 52 void HandleFingerGestureDownEvent(std::shared_ptr<PointerEvent> touchEvent); 53 void HandleFingerGestureMoveEvent(std::shared_ptr<PointerEvent> touchEvent); 54 void HandleFingerGesturePullMoveEvent(std::shared_ptr<PointerEvent> touchEvent); 55 void HandleFingerGesturePullUpEvent(std::shared_ptr<PointerEvent> touchEvent); 56 void HandleFingerGestureUpEvent(std::shared_ptr<PointerEvent> touchEvent); 57 int SetHotZoneArea(double locationX, double locationY, double width, double height); 58 59 private: 60 void StopFingerGesture(std::shared_ptr<PointerEvent> touchEvent); 61 void StartFingerGesture(); 62 bool CheckFingerValidation(std::shared_ptr<PointerEvent> touchEvent) const; 63 bool CheckProgressValid(std::shared_ptr<PointerEvent> touchEvent); 64 bool CheckThrowAngleValid(double angle); 65 bool CheckThrowDirection(double angle, int32_t posY); 66 void UpdateFingerPoisition(std::shared_ptr<PointerEvent> touchEvent); 67 void UpdatePositionHistory(double x, double y, double time); 68 bool CheckSuddenStop() const; 69 70 private: 71 FingerGesture fingerGesture_; 72 std::shared_ptr<PointerEvent> touchEvent_ { nullptr }; 73 bool gestureInProgress_ = false; 74 double triggerTime_ = 0.0; // trigger time milliseconds 75 bool alreadyTouchDown_ = false; 76 77 // Store historical positions and times 78 struct PositionRecord { 79 double x { 0.0 }; 80 double y { 0.0 }; 81 double time { 0.0 }; // milliseconds 82 }; 83 std::vector<PositionRecord> positionHistory_; // Store the most recent location record 84 static constexpr size_t MAX_HISTORY_SIZE = 10; 85 static constexpr size_t MIN_HISTORY_SIZE = 3; 86 87 static constexpr double THRES_SPEED = 0.6; // unit: pix 88 static constexpr int64_t MIN_THRES_DIST = 50; // unit: pix 89 static constexpr double MAX_DECELERATION = 0.0; 90 static constexpr int32_t FIRST_TOUCH_FINGER = 0; 91 92 static constexpr double ANGLE_DOWN_MIN {45.0}; 93 static constexpr double ANGLE_DOWN_MAX {135.0}; 94 static constexpr double ANGLE_UP_MIN {225.0}; 95 static constexpr double ANGLE_UP_MAX {315.0}; 96 static constexpr double FULL_CIRCLE_DEGREES {360.0}; 97 static constexpr double NUM_EPSILON {1e-3}; 98 static constexpr double SPIN_UP_AREA_Y = 600; // Y value close to the spin from up screen side 99 static constexpr double SPIN_DOWN_AREA_Y = 2400; // Y value close to the spin from down screen side 100 static constexpr double UP_SCREEN_AREA_Y = 1600; 101 static constexpr double DOWN_SCREEN_AREA_Y = 1700; 102 static constexpr double SPEED_SCALE = 2.0; 103 const int64_t WINDOW_TIME_INTERVAL = 0.20e6; // sample window, unit: u sec 104 }; 105 #define PULL_THROW_EVENT_HANDLER ::OHOS::DelayedSingleton<PullThrowSubscriberHandler>::GetInstance() 106 } // namespace MMI 107 } // namespace OHOS 108 #endif // PULL_THROW_SUBSCRIBER_HANDLER_H 109