提交 b0f82a1a 编写于 作者: O openharmony_ci 提交者: Gitee

!392 修复旋转表冠无惯性滑动问题

Merge pull request !392 from YueBiang/rotate_master
......@@ -26,12 +26,6 @@
#include "graphic_timer.h"
#endif
namespace {
#if ENABLE_ROTATE_INPUT
constexpr uint8_t DEFAULT_ROTATE_THRESHOLD = 4;
#endif
}
namespace OHOS {
#if DEFAULT_ANIMATION
class BarEaseInOutAnimator final : public AnimatorCallback {
......@@ -142,8 +136,9 @@ UIAbstractScroll::UIAbstractScroll()
#endif
#if ENABLE_ROTATE_INPUT
rotateFactor_ = DEFAULT_SCROLL_VIEW_ROTATE_FACTOR;
threshold_ = DEFAULT_ROTATE_THRESHOLD;
rotateThrowthreshold_ = DEFAULT_ROTATE_THROW_THRESHOLD;
lastRotateLen_ = 0;
isRotating_ = false;
#endif
isViewGroup_ = true;
touchable_ = true;
......@@ -249,7 +244,12 @@ void UIAbstractScroll::CalculateDragDistance(Point currentPos,
int16_t& dragDistanceY)
{
if ((direction_ == VERTICAL) || (direction_ == HORIZONTAL_AND_VERTICAL)) {
dragDistanceY = (currentPos.y - lastPos.y) * DRAG_DISTANCE_COEFFICIENT;
dragDistanceY = currentPos.y - lastPos.y;
if (isRotating_) {
dragDistanceY *= ROTATE_DISTANCE_COEFFICIENT;
} else {
dragDistanceY *= DRAG_DISTANCE_COEFFICIENT;
}
if (dragDistanceY > 0 || (dragDistanceY == 0 && dragDirection == DragEvent::DIRECTION_TOP_TO_BOTTOM)) {
dragDistanceY += GetMaxDelta() * GetSwipeACCLevel() / DRAG_ACC_FACTOR;
} else if (dragDistanceY < 0 || (dragDistanceY == 0 && dragDirection == DragEvent::DIRECTION_BOTTOM_TO_TOP)) {
......@@ -258,7 +258,12 @@ void UIAbstractScroll::CalculateDragDistance(Point currentPos,
}
if ((direction_ == HORIZONTAL) || (direction_ == HORIZONTAL_AND_VERTICAL)) {
dragDistanceX = (currentPos.x - lastPos.x) * DRAG_DISTANCE_COEFFICIENT;
dragDistanceX = currentPos.x - lastPos.x;
if (isRotating_) {
dragDistanceX *= ROTATE_DISTANCE_COEFFICIENT;
} else {
dragDistanceX *= DRAG_DISTANCE_COEFFICIENT;
}
if (dragDistanceX > 0 || (dragDistanceX == 0 && dragDirection == DragEvent::DIRECTION_LEFT_TO_RIGHT)) {
dragDistanceX += GetMaxDelta() * GetSwipeACCLevel() / DRAG_ACC_FACTOR;
} else if (dragDistanceX < 0 || (dragDistanceX == 0 && dragDirection == DragEvent::DIRECTION_RIGHT_TO_LEFT)) {
......@@ -317,6 +322,12 @@ void UIAbstractScroll::ListAnimatorCallback::Callback(UIView* view)
}
#if ENABLE_ROTATE_INPUT
bool UIAbstractScroll::OnRotateStartEvent(const RotateEvent& event)
{
isRotating_ = true;
return UIView::OnRotateStartEvent(event);
}
bool UIAbstractScroll::OnRotateEvent(const RotateEvent& event)
{
lastRotateLen_ = static_cast<int16_t>(event.GetRotate() * rotateFactor_);
......@@ -330,6 +341,7 @@ bool UIAbstractScroll::OnRotateEvent(const RotateEvent& event)
bool UIAbstractScroll::OnRotateEndEvent(const RotateEvent& event)
{
isRotating_ = false;
if (memset_s(lastDelta_, sizeof(lastDelta_), 0, sizeof(lastDelta_)) != EOK) {
return UIView::OnRotateEndEvent(event);
}
......@@ -340,8 +352,8 @@ bool UIAbstractScroll::OnRotateEndEvent(const RotateEvent& event)
} else {
dir = (lastRotateLen_ >= 0) ? DragEvent::DIRECTION_TOP_TO_BOTTOM : DragEvent::DIRECTION_BOTTOM_TO_TOP;
}
bool triggerAnimator = (MATH_ABS(lastRotateLen_) >= (GetWidth() / threshold_)) ||
(MATH_ABS(lastRotateLen_) >= (GetHeight() / threshold_));
bool triggerAnimator = (MATH_ABS(lastRotateLen_) >= (GetWidth() / rotateThrowthreshold_)) ||
(MATH_ABS(lastRotateLen_) >= (GetHeight() / rotateThrowthreshold_));
if (throwDrag_ && triggerAnimator) {
Point current;
if (direction_ == HORIZONTAL) {
......
......@@ -169,7 +169,6 @@ UIList::UIList(uint8_t direction)
lastRotateLen_ = 0;
#endif
#if ENABLE_VIBRATOR
needVibration_ = false;
vibratorType_ = VibratorType::VIBRATOR_TYPE_ONE;
#endif
#if ENABLE_FOCUS_MANAGER
......@@ -240,16 +239,12 @@ bool UIList::OnRotateStartEvent(const RotateEvent& event)
if (scrollAnimator_.GetState() != Animator::STOP) {
UIAbstractScroll::StopAnimator();
}
#if ENABLE_VIBRATOR
needVibration_ = true;
#endif
isReCalculateDragEnd_ = true;
return UIView::OnRotateStartEvent(event);
return UIAbstractScroll::OnRotateStartEvent(event);
}
bool UIList::OnRotateEndEvent(const RotateEvent& event)
{
needVibration_ = false;
isReCalculateDragEnd_ = false;
return UIAbstractScroll::OnRotateEndEvent(event);
}
......@@ -645,7 +640,7 @@ void UIList::MoveChildByOffset(int16_t xOffset, int16_t yOffset)
}
#if ENABLE_VIBRATOR
VibratorFunc vibratorFunc = VibratorManager::GetInstance()->GetVibratorFunc();
if (isSelectViewFind && needVibration_ && vibratorFunc != nullptr) {
if (isSelectViewFind && isRotating_ && vibratorFunc != nullptr) {
if (!isLoopList_ && (onSelectedIndex_ == 0 || onSelectedIndex_ == recycle_.adapter_->GetCount() - 1)) {
vibratorFunc(VibratorType::VIBRATOR_TYPE_THREE);
GRAPHIC_LOGI("UIList::MoveChildByOffset calls TYPE_THREE vibrator");
......
......@@ -28,7 +28,6 @@ UISwipeView::UISwipeView(uint8_t direction)
#endif
#if ENABLE_VIBRATOR
lastIndex_ = 0;
needVibration_ = false;
#endif
direction_ = direction;
tickTime_ = ANIMATOR_TIME;
......@@ -199,14 +198,12 @@ bool UISwipeView::OnRotateStartEvent(const RotateEvent& event)
if (scrollAnimator_.GetState() != Animator::STOP) {
UIAbstractScroll::StopAnimator();
}
#if ENABLE_VIBRATOR
needVibration_ = true;
#endif
return UIView::OnRotateStartEvent(event);
return UIAbstractScroll::OnRotateStartEvent(event);
}
bool UISwipeView::OnRotateEndEvent(const RotateEvent& event)
{
isRotating_ = false;
uint8_t dir;
if (direction_ == HORIZONTAL) {
dir = (lastRotateLen_ >= 0) ? DragEvent::DIRECTION_LEFT_TO_RIGHT : DragEvent::DIRECTION_RIGHT_TO_LEFT;
......@@ -219,9 +216,6 @@ bool UISwipeView::OnRotateEndEvent(const RotateEvent& event)
}
SwitchToPage(curIndex_);
lastRotateLen_ = 0;
#if ENABLE_VIBRATOR
needVibration_ = false;
#endif
return UIView::OnRotateEndEvent(event);
}
#endif
......@@ -430,7 +424,7 @@ void UISwipeView::RefreshCurrentViewInner(int16_t distance,
}
#if ENABLE_VIBRATOR
VibratorFunc vibratorFunc = VibratorManager::GetInstance()->GetVibratorFunc();
if (vibratorFunc != nullptr && needVibration_ && curIndex_ != lastIndex_) {
if (vibratorFunc != nullptr && isRotating_ && curIndex_ != lastIndex_) {
if (!loop_ && (curIndex_ == 0 || curIndex_ == childrenNum_ - 1)) {
vibratorFunc(VibratorType::VIBRATOR_TYPE_THREE);
GRAPHIC_LOGI("UISwipeView::RefreshCurrentViewInner calls TYPE_THREE vibrator");
......
......@@ -143,15 +143,11 @@ void UITimePicker::InitPicker(UIPicker*& picker, int16_t start, int16_t end)
#if ENABLE_ROTATE_INPUT
if (end == HOUR_END) {
picker->GetChildrenHead()->SetViewId(HOUR_LIST_NAME);
return;
} else if (end == MIN_END) {
if (minutePicker_->GetChildById(MIN_LIST_NAME) == nullptr) {
} else if (end == MIN_END && secondPicker_ == nullptr) {
picker->GetChildrenHead()->SetViewId(MIN_LIST_NAME);
return;
}
}
} else if (end == SEC_END) {
picker->GetChildrenHead()->SetViewId(SEC_LIST_NAME);
return;
}
#endif
}
......
......@@ -255,16 +255,19 @@ public:
* @brief 设置触发惯性滑动的组件大小比例阈值.
*
* @param threshold 设置触发惯性滑动的比例阈值.
* 旋转表冠结束,如果最后一次旋转位移数值大于组件的宽或高除以threshold,则触发惯性滑动.
* @since 6
*/
void SetRotateThreshold(uint8_t threshold)
void SetRotateThrowThreshold(uint8_t threshold)
{
if (threshold == 0) {
return;
}
threshold_ = threshold;
rotateThrowthreshold_ = threshold;
}
bool OnRotateStartEvent(const RotateEvent& event) override;
bool OnRotateEvent(const RotateEvent& event) override;
bool OnRotateEndEvent(const RotateEvent& event) override;
......@@ -435,8 +438,9 @@ protected:
Animator scrollAnimator_;
#if ENABLE_ROTATE_INPUT
float rotateFactor_;
int16_t threshold_;
int16_t rotateThrowthreshold_;
int16_t lastRotateLen_;
bool isRotating_;
#endif
bool yScrollBarVisible_ = false;
UIAbstractScrollBar* yScrollBar_ = nullptr;
......
......@@ -467,7 +467,6 @@ private:
void FixHorDistance(int16_t& distanceX);
void FixVerDistance(int16_t& distanceY);
#if ENABLE_VIBRATOR
bool needVibration_;
void SetMotorType(VibratorType vibratorType);
VibratorType vibratorType_;
#endif
......
......@@ -455,6 +455,18 @@ public:
{
return list_.GetRotateFactor();
}
/**
* @brief 设置触发惯性滑动的组件大小比例阈值.
*
* @param threshold 设置触发惯性滑动的比例阈值.
* 旋转表冠结束,如果最后一次旋转位移数值大于组件的宽或高除以threshold,则触发惯性滑动.
* @since 6
*/
void SetRotateThrowThreshold(uint8_t threshold)
{
list_.SetRotateThrowThreshold(threshold);
}
#endif
protected:
......
......@@ -366,7 +366,6 @@ protected:
bool loop_;
#if ENABLE_VIBRATOR
uint16_t lastIndex_;
bool needVibration_;
#endif
private:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册