提交 40d915a6 编写于 作者: Y YueBiang

fix bugs of rotate input

Signed-off-by: NYueBiang <suyue7@huawei.com>
上级 14c0bd04
......@@ -30,6 +30,13 @@
#define BAR_OP(obj, op, ...) obj.yScrollBar_->op(__VA_ARGS__)
#endif
namespace {
#if ENABLE_ROTATE_INPUT
constexpr float DEFAULT_ABSTRACT_SCROLL_ROTATE_FACTOR = 2.5;
constexpr uint8_t DEFAULT_ROTATE_THRESHOLD = 4;
#endif
}
namespace OHOS {
#if DEFAULT_ANIMATION
class BarEaseInOutAnimator final : private AnimatorCallback {
......@@ -139,6 +146,10 @@ UIAbstractScroll::UIAbstractScroll()
#endif
#if ENABLE_FOCUS_MANAGER
focusable_ = true;
#endif
#if ENABLE_ROTATE_INPUT
rotateFactor_ = DEFAULT_ABSTRACT_SCROLL_ROTATE_FACTOR;
threshold_ = DEFAULT_ROTATE_THRESHOLD;
#endif
isViewGroup_ = true;
touchable_ = true;
......
......@@ -15,6 +15,13 @@
#include "components/ui_list.h"
#include "components/ui_abstract_scroll_bar.h"
#include "gfx_utils/graphic_log.h"
namespace {
#if ENABLE_ROTATE_INPUT
constexpr float DEFAULT_LIST_ROTATE_FACTOR = 2.5;
#endif
} // namespace
namespace OHOS {
UIList::Recycle::~Recycle()
......@@ -155,11 +162,11 @@ UIList::UIList(uint8_t direction)
scrollListener_(nullptr)
{
#if ENABLE_ROTATE_INPUT
rotateFactor_ = DEFAULT_ROTATE_FACTOR;
isRotating_ = false;
rotateFactor_ = DEFAULT_LIST_ROTATE_FACTOR;
lastRotateLen_ = 0;
#endif
#if ENABLE_VIBRATOR
needVibration_ = false;
vibratorType_ = VibratorType::VIBRATOR_TYPE_ONE;
#endif
#if ENABLE_FOCUS_MANAGER
......@@ -223,30 +230,49 @@ bool UIList::OnPressEvent(const PressEvent& event)
}
#if ENABLE_ROTATE_INPUT
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);
}
bool UIList::OnRotateEvent(const RotateEvent& event)
{
int16_t midPointX = static_cast<int16_t>(GetWidth() / 2); // 2 : Get the middle point X coord of the view
int16_t midPointY = static_cast<int16_t>(GetHeight() / 2); // 2 : Get the middle point Y coord of the view
Point last, current;
isRotating_ = true;
if (throwDrag_ && event.GetRotate() == 0) {
last = Point {midPointX, midPointY};
(direction_ == VERTICAL) ? (current = Point {midPointX, static_cast<int16_t>(midPointY + lastRotateLen_)})
: (current = Point {static_cast<int16_t>(midPointX + lastRotateLen_), midPointY});
isReCalculateDragEnd_ = false;
DragThrowAnimator(current, last);
lastRotateLen_ = 0;
lastRotateLen_ = static_cast<int16_t>(event.GetRotate() * rotateFactor_);
if (direction_ == VERTICAL) {
DragYInner(lastRotateLen_);
} else {
lastRotateLen_ = static_cast<int16_t>(event.GetRotate() * rotateFactor_);
DragXInner(lastRotateLen_);
}
return UIView::OnRotateEvent(event);
}
bool UIList::OnRotateEndEvent(const RotateEvent& event)
{
needVibration_ = false;
isReCalculateDragEnd_ = false;
bool triggerAnimator = (MATH_ABS(lastRotateLen_) >= (GetWidth() / threshold_)) ||
(MATH_ABS(lastRotateLen_) >= (GetHeight() / threshold_));
if (throwDrag_ && triggerAnimator) {
Point current;
if (direction_ == VERTICAL) {
DragYInner(lastRotateLen_);
current = {0, lastRotateLen_};
} else {
DragXInner(lastRotateLen_);
current = {lastRotateLen_, 0};
}
DragThrowAnimator(current, {0, 0});
} else {
DragThrowAnimator({0, 0}, {0, 0});
}
isRotating_ = false;
return UIView::OnRotateEvent(event);
lastRotateLen_ = 0;
return UIView::OnRotateEndEvent(event);
}
#endif
......@@ -630,6 +656,13 @@ void UIList::MoveChildByOffset(int16_t xOffset, int16_t yOffset)
scrollListener_->OnItemSelected(onSelectedIndex_, onSelectedView_);
}
isSelectViewFind = true;
#if ENABLE_VIBRATOR
VibratorFunc vibratorFunc = VibratorManager::GetInstance()->GetVibratorFunc();
if (needVibration_ && vibratorFunc != nullptr) {
GRAPHIC_LOGI("UIList::MoveChildByOffset Call vibrator function");
vibratorFunc(VibratorType::VIBRATOR_TYPE_TWO);
}
#endif
}
} else {
width = view->GetRelativeRect().GetWidth();
......@@ -642,18 +675,18 @@ void UIList::MoveChildByOffset(int16_t xOffset, int16_t yOffset)
scrollListener_->OnItemSelected(onSelectedIndex_, onSelectedView_);
}
isSelectViewFind = true;
#if ENABLE_VIBRATOR
VibratorFunc vibratorFunc = VibratorManager::GetInstance()->GetVibratorFunc();
if (needVibration_ && vibratorFunc != nullptr) {
GRAPHIC_LOGI("UIList::MoveChildByOffset Call vibrator function");
vibratorFunc(VibratorType::VIBRATOR_TYPE_TWO);
}
#endif
}
}
}
view = view->GetNextSibling();
} while (view != nullptr);
#if ENABLE_ROTATE_INPUT && ENABLE_VIBRATOR
VibratorFunc vibratorFunc = VibratorManager::GetInstance()->GetVibratorFunc();
if (isRotating_ && vibratorFunc != nullptr && isSelectViewFind) {
vibratorFunc(VibratorType::VIBRATOR_TYPE_TWO);
}
#endif
}
void UIList::StopAnimator()
......
......@@ -19,6 +19,12 @@
#include "draw/draw_rect.h"
#include "themes/theme_manager.h"
namespace {
#if ENABLE_ROTATE_INPUT
constexpr float DEFAULT_PICKER_ROTATE_FACTOR = 1.668;
#endif
}
namespace OHOS {
class PickerListScrollListener : public ListScrollListener {
public:
......@@ -167,7 +173,7 @@ UIPicker::UIPicker()
list_.SetThrowDrag(true);
#if ENABLE_ROTATE_INPUT
list_.rotateFactor_ = DEFAULT_ROTATE_FACTOR;
list_.rotateFactor_ = DEFAULT_PICKER_ROTATE_FACTOR;
#endif
#if ENABLE_VIBRATOR
list_.SetMotorType(VibratorType::VIBRATOR_TYPE_TWO);
......
......@@ -17,6 +17,16 @@
#include "dock/focus_manager.h"
#include "dock/vibrator_manager.h"
#include "draw/draw_rect.h"
#include "gfx_utils/graphic_log.h"
namespace {
#if ENABLE_ROTATE_INPUT
constexpr float DEFAULT_SCROLL_ROTATE_FACTOR = 2.5;
#endif
#if ENABLE_VIBRATOR
constexpr float DEFAULT_VIBRATOR_LEN = 1.0;
#endif
} // namespace
namespace OHOS {
UIScrollView::UIScrollView()
......@@ -29,9 +39,13 @@ UIScrollView::UIScrollView()
scrollListener_(nullptr)
{
#if ENABLE_ROTATE_INPUT
rotateFactor_ = DEFAULT_ROTATE_FACTOR;
rotateFactor_ = DEFAULT_SCROLL_ROTATE_FACTOR;
lastRotateLen_ = 0;
#endif
#if ENABLE_VIBRATOR
totalRotateLen_ = 0;
lastVibratorRotateLen_ = 0;
#endif
#if ENABLE_FOCUS_MANAGER
focusable_ = true;
#endif
......@@ -90,52 +104,65 @@ bool UIScrollView::OnPressEvent(const PressEvent& event)
}
#if ENABLE_ROTATE_INPUT
bool UIScrollView::OnRotateStartEvent(const RotateEvent& event)
{
if (scrollAnimator_.GetState() != Animator::STOP) {
UIAbstractScroll::StopAnimator();
}
return UIView::OnRotateStartEvent(event);
}
bool UIScrollView::OnRotateEvent(const RotateEvent& event)
{
int16_t midPointX = static_cast<int16_t>(GetWidth() / 2); // 2 : Get the middle point X coord of the view
int16_t midPointY = static_cast<int16_t>(GetHeight() / 2); // 2 : Get the middle point Y coord of the view
Point last, current;
if (throwDrag_ && event.GetRotate() == 0) {
last = Point{midPointX, midPointY};
yScrollable_ ? (current = Point{midPointX, static_cast<int16_t>(midPointY + lastRotateLen_)}) :
(current = Point{static_cast<int16_t>(midPointX + lastRotateLen_), midPointY});
DragThrowAnimator(current, last);
lastRotateLen_ = 0;
lastRotateLen_ = static_cast<int16_t>(event.GetRotate() * rotateFactor_);
if (yScrollable_) {
DragYInner(lastRotateLen_);
} else {
lastRotateLen_ = static_cast<int16_t>(event.GetRotate() * rotateFactor_);
if (yScrollable_) {
DragYInner(lastRotateLen_);
} else {
DragXInner(lastRotateLen_);
}
DragXInner(lastRotateLen_);
}
#if ENABLE_VIBRATOR
Rect rect = GetAllChildRelativeRect();
int16_t top = rect.GetTop();
int16_t bottom = rect.GetBottom();
int16_t scrollHeight = GetHeight();
int16_t left = rect.GetLeft();
int16_t right = rect.GetRight();
int16_t scrollWidth = GetWidth();
bool needMotor = true;
totalRotateLen_ += lastRotateLen_;
Rect childRect = GetAllChildRelativeRect();
bool needVibration = true;
if (yScrollable_) {
if ((top > 0 && top <= reboundSize_) ||
(bottom >= (scrollHeight - reboundSize_ - 1) && bottom < scrollHeight)) {
needMotor = false;
if (childRect.GetTop() - scrollBlankSize_ >= 0 || childRect.GetBottom() + scrollBlankSize_ <= GetHeight()) {
needVibration = false;
}
} else {
if ((left > 0 && left <= reboundSize_) || (right >= (scrollWidth - reboundSize_ - 1) && right < scrollWidth)) {
needMotor = false;
if (childRect.GetLeft() - scrollBlankSize_ >= 0 || childRect.GetRight() + scrollBlankSize_ <= GetWidth()) {
needVibration = false;
}
}
VibratorFunc vibratorFunc = VibratorManager::GetInstance()->GetVibratorFunc();
if (vibratorFunc != nullptr && needMotor) {
if (vibratorFunc != nullptr && needVibration &&
MATH_ABS(totalRotateLen_ - lastVibratorRotateLen_) > DEFAULT_VIBRATOR_LEN) {
GRAPHIC_LOGI("UIScrollView::OnRotateEvent Call vibrator function");
vibratorFunc(VibratorType::VIBRATOR_TYPE_ONE);
lastVibratorRotateLen_ = totalRotateLen_;
}
#endif
RefreshAnimator();
return UIView::OnRotateEvent(event);
}
bool UIScrollView::OnRotateEndEvent(const RotateEvent& event)
{
bool triggerAnimator = (MATH_ABS(lastRotateLen_) >= (GetWidth() / threshold_)) ||
(MATH_ABS(lastRotateLen_) >= (GetHeight() / threshold_));
if (throwDrag_ && triggerAnimator) {
Point current;
if (yScrollable_) {
current = {0, lastRotateLen_};
} else {
current = {lastRotateLen_, 0};
}
DragThrowAnimator(current, {0, 0});
} else {
DragThrowAnimator({0, 0}, {0, 0});
}
lastRotateLen_ = 0;
return UIView::OnRotateEndEvent(event);
}
#endif
void UIScrollView::ScrollBy(int16_t xDistance, int16_t yDistance)
......
......@@ -23,6 +23,13 @@
#include "imgdecode/cache_manager.h"
#include "themes/theme_manager.h"
namespace {
#ifdef _WIN32
constexpr float DEFAULT_SLIDER_ROTATE_FACTOR = -1;
#else
constexpr float DEFAULT_SLIDER_ROTATE_FACTOR = -0.1;
#endif
}
namespace OHOS {
UISlider::UISlider()
: knobWidth_(0), knobWidthSetFlag_(false), knobStyleAllocFlag_(false), knobImage_(nullptr), listener_(nullptr)
......@@ -33,7 +40,9 @@ UISlider::UISlider()
#if ENABLE_FOCUS_MANAGER
focusable_ = true;
#endif
#if ENABLE_ROTATE_INPUT
rotateFactor_ = DEFAULT_SLIDER_ROTATE_FACTOR;
#endif
SetBackgroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND);
SetBackgroundStyle(STYLE_BACKGROUND_OPA, BACKGROUND_OPA);
SetBackgroundStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
......@@ -386,9 +395,6 @@ bool UISlider::OnDragEndEvent(const DragEvent& event)
#if ENABLE_ROTATE_INPUT
bool UISlider::OnRotateEvent(const RotateEvent& event)
{
if (event.GetRotate() == 0) {
return false;
}
int32_t lastValue = curValue_;
int32_t tmp = static_cast<int32_t>(event.GetRotate()) * rotateFactor_;
SetValue(curValue_ + tmp);
......@@ -398,6 +404,7 @@ bool UISlider::OnRotateEvent(const RotateEvent& event)
#if ENABLE_VIBRATOR
VibratorFunc vibratorFunc = VibratorManager::GetInstance()->GetVibratorFunc();
if (vibratorFunc != nullptr && lastValue != curValue_) {
GRAPHIC_LOGI("UISlider::OnRotateEvent Call vibrator function");
vibratorFunc(VibratorType::VIBRATOR_TYPE_TWO);
}
#endif
......
......@@ -16,13 +16,25 @@
#include "components/ui_swipe_view.h"
#include "dock/focus_manager.h"
#include "dock/vibrator_manager.h"
#include "gfx_utils/graphic_log.h"
namespace {
#if ENABLE_ROTATE_INPUT
constexpr float DEFAULT_SWIPE_ROTATE_FACTOR = 5;
#endif
} // namespace
namespace OHOS {
UISwipeView::UISwipeView(uint8_t direction)
: swipeListener_(nullptr), curIndex_(0), blankSize_(DEFAULT_BLANK_SIZE), curView_(nullptr), loop_(false)
{
#if ENABLE_ROTATE_INPUT
rotateFactor_ = DEFAULT_ROTATE_FACTOR;
rotateFactor_ = DEFAULT_SWIPE_ROTATE_FACTOR;
lastRotateLen_ = 0;
#endif
#if ENABLE_VIBRATOR
lastIndex_ = 0;
needVibration_ = false;
#endif
direction_ = direction;
tickTime_ = ANIMATOR_TIME;
......@@ -164,26 +176,37 @@ bool UISwipeView::OnDragEndEvent(const DragEvent& event)
}
#if ENABLE_ROTATE_INPUT
bool UISwipeView::OnRotateStartEvent(const RotateEvent& event)
{
if (scrollAnimator_.GetState() != Animator::STOP) {
UIAbstractScroll::StopAnimator();
}
#if ENABLE_VIBRATOR
needVibration_ = true;
#endif
return UIView::OnRotateStartEvent(event);
}
bool UISwipeView::OnRotateEvent(const RotateEvent& event)
{
if (rotateFactor_ == 0) {
return UIView::OnRotateEvent(event);
}
uint16_t lastIndex_ = curIndex_;
if (event.GetRotate() != 0) {
int16_t rotateLen = event.GetRotate() * rotateFactor_;
(direction_ == HORIZONTAL) ? DragXInner(rotateLen) : DragYInner(rotateLen);
RefreshCurrentView(rotateLen);
lastRotateLen_ = event.GetRotate() * rotateFactor_;
if (direction_ == HORIZONTAL) {
DragXInner(lastRotateLen_);
} else {
SwitchToPage(curIndex_);
DragYInner(lastRotateLen_);
}
RefreshCurrentView(lastRotateLen_);
return UIView::OnRotateEvent(event);
}
bool UISwipeView::OnRotateEndEvent(const RotateEvent& event)
{
SwitchToPage(curIndex_);
lastRotateLen_ = 0;
#if ENABLE_VIBRATOR
VibratorFunc vibratorFunc = VibratorManager::GetInstance()->GetVibratorFunc();
if (vibratorFunc != nullptr && curIndex_ != lastIndex_) {
vibratorFunc(VibratorType::VIBRATOR_TYPE_ONE);
}
needVibration_ = false;
#endif
return UIView::OnRotateEvent(event);
return UIView::OnRotateEndEvent(event);
}
#endif
......@@ -370,6 +393,14 @@ void UISwipeView::RefreshCurrentViewInner(int16_t distance,
}
}
}
#if ENABLE_VIBRATOR
VibratorFunc vibratorFunc = VibratorManager::GetInstance()->GetVibratorFunc();
if (vibratorFunc != nullptr && needVibration_ && curIndex_ != lastIndex_) {
GRAPHIC_LOGI("UISwipeView::RefreshCurrentViewInner Call vibrator function");
vibratorFunc(VibratorType::VIBRATOR_TYPE_ONE);
lastIndex_ = curIndex_;
}
#endif
}
void UISwipeView::RefreshCurrentView(int16_t distance)
......
......@@ -436,6 +436,14 @@ bool UIView::OnCancelEvent(const CancelEvent& event)
}
#if ENABLE_ROTATE_INPUT
bool UIView::OnRotateStartEvent(const RotateEvent& event)
{
if (onRotateListener_ != nullptr) {
return onRotateListener_->OnRotateStart(*this, event);
}
return false;
}
bool UIView::OnRotateEvent(const RotateEvent& event)
{
if (onRotateListener_ != nullptr) {
......@@ -443,6 +451,14 @@ bool UIView::OnRotateEvent(const RotateEvent& event)
}
return isIntercept_;
}
bool UIView::OnRotateEndEvent(const RotateEvent& event)
{
if (onRotateListener_ != nullptr) {
return onRotateListener_->OnRotateEnd(*this, event);
}
return false;
}
#endif
void UIView::GetTargetView(const Point& point, UIView** last)
......
......@@ -17,22 +17,50 @@
#include "dock/focus_manager.h"
#if ENABLE_ROTATE_INPUT
namespace {
#ifdef _WIN32
constexpr int16_t ROTATE_INPUT_THRESHOLD = 1;
#else
constexpr int16_t ROTATE_INPUT_THRESHOLD = 10;
#endif
}
namespace OHOS {
RotateInputDevice::RotateInputDevice() : rotateStart_(false), threshold_(ROTATE_INPUT_THRESHOLD), cachedRotation_(0) {}
void RotateInputDevice::DispatchEvent(const DeviceData& data)
{
bool cachedToRotate = false;
if (data.rotate == 0 || rotateStart_) {
cachedRotation_ = 0;
} else {
cachedRotation_ += data.rotate;
if (MATH_ABS(cachedRotation_) >= threshold_) {
cachedToRotate = true;
}
}
if (!cachedToRotate && !rotateStart_) {
return;
}
UIView *view_ = FocusManager::GetInstance()->GetFocusedView();
if (view_ == nullptr) {
return;
} else if (data.rotate == 0 && rotateStart) {
view_->OnRotateEvent(0);
rotateStart = false;
}
if (MATH_ABS(data.rotate) < threshold_ && !rotateStart_ && !cachedToRotate) {
return;
} else if (MATH_ABS(data.rotate) < threshold_) {
}
if (data.rotate == 0 && rotateStart_) {
view_->OnRotateEndEvent(0);
rotateStart_ = false;
return;
} else {
view_->OnRotateEvent(data.rotate);
rotateStart = true;
}
if (!rotateStart_) {
view_->OnRotateStartEvent(data.rotate);
}
view_->OnRotateEvent(data.rotate);
rotateStart_ = true;
}
} // namespace OHOS
#endif
......@@ -25,7 +25,7 @@ namespace OHOS {
class RotateInputDevice : public InputDevice {
public:
/** @brief Constructor */
RotateInputDevice(){};
RotateInputDevice();
/** @brief Destructor */
virtual ~RotateInputDevice(){};
......@@ -35,14 +35,10 @@ public:
}
protected:
#ifdef _WIN32
static constexpr int16_t ROTATE_INPUT_THRESHOLD = 1;
#else
static constexpr int16_t ROTATE_INPUT_THRESHOLD = 10;
#endif
void DispatchEvent(const DeviceData& data) override;
bool rotateStart = false;
int16_t threshold_ = ROTATE_INPUT_THRESHOLD;
bool rotateStart_;
int16_t threshold_;
int16_t cachedRotation_;
};
} // namespace OHOS
......
......@@ -245,8 +245,26 @@ public:
*/
void SetRotateFactor(float factor)
{
if (MATH_ABS(factor) > MAX_ROTATE_FACTOR) {
rotateFactor_ = (factor > 0) ? MAX_ROTATE_FACTOR : -MAX_ROTATE_FACTOR;
return;
}
rotateFactor_ = factor;
}
/**
* @brief 设置触发惯性滑动的组件大小比例阈值.
*
* @param threshold 设置触发惯性滑动的比例阈值.
* @since 6
*/
void SetRotateThreshold(uint8_t threshold)
{
if (threshold == 0) {
return;
}
threshold_ = threshold;
}
#endif
void SetXScrollBarVisible(bool visible)
......@@ -282,6 +300,7 @@ protected:
static constexpr uint8_t MAX_DELTA_Y_SIZE = 3;
static constexpr uint16_t SCROLL_BAR_WIDTH = 5;
static constexpr uint8_t MAX_ROTATE_FACTOR = 128;
class ListAnimatorCallback : public AnimatorCallback {
public:
......@@ -370,8 +389,8 @@ protected:
ListAnimatorCallback animatorCallback_;
Animator scrollAnimator_;
#if ENABLE_ROTATE_INPUT
static constexpr float DEFAULT_ROTATE_FACTOR = 1.0;
float rotateFactor_ = DEFAULT_ROTATE_FACTOR;
float rotateFactor_;
int16_t threshold_;
#endif
bool yScrollBarVisible_ = false;
UIAbstractScrollBar* yScrollBar_ = nullptr;
......
......@@ -188,7 +188,11 @@ public:
bool OnPressEvent(const PressEvent& event) override;
#if ENABLE_ROTATE_INPUT
bool OnRotateStartEvent(const RotateEvent& event) override;
bool OnRotateEvent(const RotateEvent& event) override;
bool OnRotateEndEvent(const RotateEvent& event) override;
#endif
/**
......@@ -465,11 +469,10 @@ private:
bool IsNeedReCalculateDragEnd();
bool ReCalculateDragEnd();
#if ENABLE_ROTATE_INPUT
bool isRotating_;
int16_t lastRotateLen_;
static constexpr float DEFAULT_ROTATE_FACTOR = 5.0;
#endif
#if ENABLE_VIBRATOR
bool needVibration_;
void SetMotorType(VibratorType vibratorType);
VibratorType vibratorType_;
#endif
......
......@@ -399,9 +399,6 @@ protected:
uint16_t setSelectedIndex_;
private:
#if ENABLE_ROTATE_INPUT
static constexpr float DEFAULT_ROTATE_FACTOR = 1.0;
#endif
friend class PickerListScrollListener;
bool RefreshValues(const char* value[], uint16_t count);
bool RefreshValues(int16_t start, int16_t end);
......
......@@ -143,7 +143,11 @@ public:
}
#if ENABLE_ROTATE_INPUT
bool OnRotateStartEvent(const RotateEvent& event) override;
bool OnRotateEvent(const RotateEvent& event) override;
bool OnRotateEndEvent(const RotateEvent& event) override;
#endif
bool OnDragEvent(const DragEvent& event) override;
......@@ -265,9 +269,12 @@ private:
int16_t minScrollBarLen_;
OnScrollListener* scrollListener_;
#if ENABLE_ROTATE_INPUT
static constexpr float DEFAULT_ROTATE_FACTOR = 3.0;
int16_t lastRotateLen_;
#endif
#if ENABLE_VIBRATOR
int16_t totalRotateLen_;
int16_t lastVibratorRotateLen_;
#endif
};
} // namespace OHOS
#endif // GRAPHIC_LITE_UI_SCROLL_VIEW_H
......@@ -269,6 +269,10 @@ public:
*/
void SetRotateFactor(float factor)
{
if (MATH_ABS(factor) > MAX_ROTATE_FACTOR) {
rotateFactor_ = (factor > 0) ? MAX_ROTATE_FACTOR : -MAX_ROTATE_FACTOR;
return;
}
rotateFactor_ = factor;
}
......@@ -347,6 +351,7 @@ private:
static constexpr uint8_t FOREGROUND_COLOR_R = 0x1f;
static constexpr uint8_t FOREGROUND_COLOR_G = 0x71;
static constexpr uint8_t FOREGROUND_COLOR_B = 0xff;
static constexpr uint8_t MAX_ROTATE_FACTOR = 128;
#if ENABLE_SLIDER_KNOB
void DrawKnob(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, const Rect& foregroundRect);
#else
......@@ -361,8 +366,7 @@ private:
int32_t CalculateCurrentValue(int16_t length, int16_t totalLength);
int32_t UpdateCurrentValue(const Point& knobPosition);
#if ENABLE_ROTATE_INPUT
static constexpr float DEFAULT_ROTATE_FACTOR = -0.1;
float rotateFactor_ = DEFAULT_ROTATE_FACTOR;
float rotateFactor_;
#endif
UISliderEventListener* listener_;
}; // class UISlider
......
......@@ -214,7 +214,11 @@ public:
bool OnDragEndEvent(const DragEvent& event) override;
#if ENABLE_ROTATE_INPUT
bool OnRotateStartEvent(const RotateEvent& event) override;
bool OnRotateEvent(const RotateEvent& event) override;
bool OnRotateEndEvent(const RotateEvent& event) override;
#endif
/**
......@@ -355,7 +359,11 @@ protected:
AlignMode alignMode_ = ALIGN_CENTER;
bool loop_;
#if ENABLE_ROTATE_INPUT
static constexpr float DEFAULT_ROTATE_FACTOR = 2.0;
int16_t lastRotateLen_;
#endif
#if ENABLE_VIBRATOR
uint16_t lastIndex_;
bool needVibration_;
#endif
private:
......
......@@ -313,6 +313,18 @@ public:
*/
class OnRotateListener : public HeapBase {
public:
/**
* @brief Called when the view starts to rotate.
* @param view Indicates the view that responds to the rotation event.
* @param event Indicates the rotation event.
* @return Returns <b>true</b> if the rotation event is consumed; returns <b>false</b> otherwise.
* @since 6
*/
virtual bool OnRotateStart(UIView& view, const RotateEvent& event)
{
return false;
}
/**
* @brief Called when a rotation event occurs on a view.
* @param view Indicates the view that responds to the rotation event.
......@@ -323,8 +335,21 @@ public:
*/
virtual bool OnRotate(UIView& view, const RotateEvent& event)
{
return true;
return false;
}
/**
* @brief Called when the view stops rotating.
* @param view Indicates the view that responds to the rotation event.
* @param event Indicates the rotation event.
* @return Returns <b>true</b> if the rotation event is consumed; returns <b>false</b> otherwise.
* @since 6
*/
virtual bool OnRotateEnd(UIView& view, const RotateEvent& event)
{
return false;
}
/**
* @brief A destructor used to delete an <b>OnRotateListener</b> instance.
* @since 5.0
......@@ -333,6 +358,13 @@ public:
virtual ~OnRotateListener() {}
};
/**
* @brief Called when the view starts to rotate.
* @param event Indicates the rotation event.
* @since 6
*/
virtual bool OnRotateStartEvent(const RotateEvent& event);
/**
* @brief Called when a rotation event occurs on the view.
* @param event Indicates the rotation event.
......@@ -341,6 +373,13 @@ public:
*/
virtual bool OnRotateEvent(const RotateEvent& event);
/**
* @brief Called when the view stops rotating.
* @param event Indicates the rotation event.
* @since 6
*/
virtual bool OnRotateEndEvent(const RotateEvent& event);
/**
* @brief Sets a rotation event listener for the view.
* @param onRotateListener Indicates the pointer to the rotation event listener to set.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册