1 /* 2 * Copyright (c) 2024 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 RESSCHED_SCENE_RECOGNIZE_SLIDE_RECOGNIZER_H 17 #define RESSCHED_SCENE_RECOGNIZE_SLIDE_RECOGNIZER_H 18 19 #include "scene_recognizer_base.h" 20 #include "ffrt.h" 21 22 namespace OHOS { 23 namespace ResourceSchedule { 24 namespace SlideRecognizeStat { 25 enum : uint32_t { 26 IDLE, 27 SLIDE_NORMAL_DETECTING, 28 SLIDE_NORMAL, 29 LIST_FLING, 30 }; 31 } 32 static constexpr int64_t DEFAULT_LIST_FLINT_TIME_OUT_TIME = 3 * 1000 * 1000; 33 static constexpr int64_t DEFAULT_LIST_FLINT_END_TIME = 150 * 1000; 34 static constexpr float DEFAULT_LIST_FLING_SPEED_LIMIT = 3.0; 35 static constexpr int64_t DEFAULT_SLIDE_NORMAL_DETECTING_TIME = 50; 36 class SlideRecognizer : public SceneRecognizerBase { 37 public: 38 SlideRecognizer() = default; 39 ~SlideRecognizer(); 40 void OnDispatchResource(uint32_t, int64_t value, const nlohmann::json& payload) override; 41 void SetListFlingTimeoutTime(int64_t value); 42 void SetListFlingEndTime(int64_t value); 43 void SetListFlingSpeedLimit(float value); 44 void SetSlideNormalDetectingTime(int64_t value); 45 private: 46 void HandleSlideEvent(int64_t value, const nlohmann::json& payload); 47 void HandleSendFrameEvent(const nlohmann::json& payload); 48 void HandleClickEvent(int64_t value, const nlohmann::json& payload); 49 void HandleSlideDetecting(const nlohmann::json& payload); 50 void HandleListFlingStart(const nlohmann::json& payload); 51 void HandleSlideOFFEvent(); 52 nlohmann::json FillRealPid(const nlohmann::json& payload); 53 ffrt::task_handle listFlingEndTask_ = nullptr; 54 ffrt::task_handle listFlingTimeOutTask_ = nullptr; 55 int64_t slideDetectingTime_ = -1; 56 uint32_t state_ = SlideRecognizeStat::IDLE; 57 int64_t listFlingTimeOutTime_ = DEFAULT_LIST_FLINT_TIME_OUT_TIME; 58 int64_t listFlingEndTime_ = DEFAULT_LIST_FLINT_END_TIME; 59 float listFlingSpeedLimit_ = DEFAULT_LIST_FLING_SPEED_LIMIT; 60 int64_t slideNormalDecectingTime_ = DEFAULT_SLIDE_NORMAL_DETECTING_TIME; 61 std::string slidePid_ = ""; 62 }; 63 } // namespace ResourceSchedule 64 } // namespace OHOS 65 #endif // RESSCHED_SCENE_RECOGNIZE_SLIDE_RECOGNIZER_H