/*---------------------------------------------------------------------------- * Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved. * * Description: * * Author: huangshuyi * * Create: 2024-7 *--------------------------------------------------------------------------*/ #ifndef TJD_UI_APP_FLOAT_WINDOW_BLEND_H #define TJD_UI_APP_FLOAT_WINDOW_BLEND_H #include "NativeAbility.h" #include "components/ui_image_animator.h" #include "components/ui_image_view.h" #include "components/ui_scroll_view.h" #include namespace TJD { class TjdUiAppFloatWindowBlend : public OHOS::UIScrollView, public OHOS::UIView::OnDragListener, public OHOS::UIView::OnClickListener, public OHOS::UIView::OnRotateListener { public: TjdUiAppFloatWindowBlend(); virtual ~TjdUiAppFloatWindowBlend(); void HideFloatWindow(); void ShowFloatWindow(); bool IsFloatWindowVisible(void); double arcCenterX; double arcCenterY; double startAngle; double endAngle; double angleIcon; double angleReserve; double arcOuterRedius; static constexpr uint8_t DRAG_TIMES_COEFFICIENT = 18; static constexpr uint8_t MIN_DRAG_TIMES = 5; static constexpr uint8_t DRAG_ACC_FACTOR = 10; static constexpr uint8_t DRAG_DISTANCE_COEFFICIENT = 5; static constexpr uint8_t MAX_DELTA_SIZE = 3; bool DragThrowAnimator(OHOS::Point currentPos, OHOS::Point lastPos, uint8_t dragDirection) { int16_t dragDistanceX = 0; int16_t dragDistanceY = 0; dragDistanceY = (currentPos.y - lastPos.y) * DRAG_DISTANCE_COEFFICIENT; if (dragDistanceY > 0 || (dragDistanceY == 0 && dragDirection == OHOS::DragEvent::DIRECTION_TOP_TO_BOTTOM)) { dragDistanceY += GetMaxDelta() * GetSwipeACCLevel() / DRAG_ACC_FACTOR; } else if (dragDistanceY < 0 || (dragDistanceY == 0 && dragDirection == OHOS::DragEvent::DIRECTION_BOTTOM_TO_TOP)) { dragDistanceY -= GetMaxDelta() * GetSwipeACCLevel() / DRAG_ACC_FACTOR; } // printf("dragDistanceY:%d\n", dragDistanceY); StartSlideAnimator(dragDistanceY); return true; } void SetSwipeACCLevel(uint8_t value) { swipeAccCoefficient_ = value; } uint8_t GetSwipeACCLevel() { return swipeAccCoefficient_; } uint8_t GetDragACCLevel() { return dragAccCoefficient_; } void SetDragACCLevel(uint8_t value) { if (value != 0) { dragAccCoefficient_ = value; } } double FindCorrectIcon(void); bool OnDrag(OHOS::UIView &view, const OHOS::DragEvent &event) override; bool OnDragStart(OHOS::UIView &view, const OHOS::DragEvent &event) override { return true; } bool OnDragEnd(OHOS::UIView &view, const OHOS::DragEvent &event) override; bool OnRotate(OHOS::UIView &view, const OHOS::RotateEvent &event) override; bool OnRotateEnd(OHOS::UIView &view, const OHOS::RotateEvent &event) override; bool OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) override; private: friend class FloatWindowAnimatorCallback; OHOS::ImageInfo *finalImgInfo{nullptr}; OHOS::UIImageView *imageFloatWindow{nullptr}; std::list iconList; OHOS::BufferInfo bgDstBufferInfo; OHOS::BufferInfo bgSrcBufferInfo; void UpdateFuchuang(int16_t diffy, double angle, bool isUsedAngle); int16_t lastDelta_[MAX_DELTA_SIZE] = {0}; uint8_t deltaIndex_ = 0; void RefreshDelta(int16_t distance) { lastDelta_[deltaIndex_ % MAX_DELTA_SIZE] = distance; deltaIndex_++; } int16_t GetMaxDelta() { int16_t result = 0; for (int16_t i = 0; i < MAX_DELTA_SIZE; i++) { if (result < MATH_ABS(lastDelta_[i])) { result = MATH_ABS(lastDelta_[i]); } } return result; } class FloatWindowAnimatorCallback : public OHOS::AnimatorCallback { public: FloatWindowAnimatorCallback() {} virtual ~FloatWindowAnimatorCallback() {} void Callback(OHOS::UIView *view) override; void OnStop(OHOS::UIView &view) override; void SetDragTimes(uint16_t times) { dragTimes_ = times; } void SetDragStartValue(double startValueY) { startValueY_ = startValueY; previousValueY_ = startValueY; } void SetFloatWindowBlend(TjdUiAppFloatWindowBlend *instance) { instance_ = instance; } void SetDragEndValue(double endValueY) { endValueY_ = endValueY; } void SetDragStartValue(int16_t startValueY) { startValueY__ = startValueY; previousValueY__ = startValueY; } void SetDragEndValue(int16_t endValueY) { endValueY__ = endValueY; } void ResetCallback() { curtTime_ = 0; dragTimes_ = 0; startValueY_ = 0; endValueY_ = 0; startValueY__ = 0; endValueY__ = 0; } private: TjdUiAppFloatWindowBlend *instance_ = nullptr; uint16_t curtTime_; uint16_t dragTimes_; double startValueY_; double endValueY_; double previousValueY_; double addAngle; int16_t startValueY__; int16_t endValueY__; int16_t previousValueY__; bool IsNeedReCalculateDragEnd(); OHOS::EasingFunc easingFunc_ = OHOS::EasingEquation::CubicEaseOut; double CubicEaseOut1(double startPos, double endPos, uint16_t curTime, uint16_t durationTime); }; FloatWindowAnimatorCallback floatWindowAnimatorCallback_; OHOS::Animator floatWindowAnimator_; uint8_t swipeAccCoefficient_ = 50; uint8_t dragAccCoefficient_ = 10; uint8_t SlideOrAutoAlign_ = 0; // 0:slide 1:auto align int16_t lastRotate_{0}; int lastImageId_{-1}; void StartSlideAnimator(int16_t dragDistanceY); void StartAutoAlignAnimator(double diffAngle); void StopFloatWindowAnimator(); }; } #endif // MAIN_CLOCK_VIEW_H