From: Caisking <3449750381@qq.com> Date: Mon, 27 Nov 2023 03:05:47 +0000 (+0800) Subject: 表盘长按事件绑定 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=d4d703ba9e5b9ba799e79f26dcaf45f141411c8c;p=mirrors%2FFD230.git 表盘长按事件绑定 --- diff --git a/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp index b076bd132..4a0532475 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp @@ -131,9 +131,9 @@ void MainClockView::InitStepValue() bool MainClockView::InitLabelView(void) { - UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); + //UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); // 创建长按事件监听器对象 - UIView::OnLongPressListener* longPressListener = (UIView::OnLongPressListener*)OHOS::MainPresenterSample::GetInstance(); + //UIView::OnLongPressListener* longPressListener = (UIView::OnLongPressListener*)OHOS::MainPresenterSample::GetInstance(); stepLabel = new UILabelButton(); @@ -147,7 +147,8 @@ bool MainClockView::InitLabelView(void) stepLabel->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); stepLabel->SetViewId(MAIN_CLICK_ACTIVITY); stepLabel->SetTouchable(true); - stepLabel->SetOnClickListener(clickListener); + //stepLabel->SetOnClickListener(clickListener); + //stepLabel->SetOnLongPressListener(longPressListener); InitStepValue(); batteryLabel = new UILabel(); @@ -351,13 +352,16 @@ void MainClockView::UnLoad(void) bool MainClockView::InitView(void) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::InitView"); - mainSweepClock = new UISweepClock(); if (mainSweepClock == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainSweepClock new fail"); return false; - } + } + UIView::OnLongPressListener* longPressListener = (UIView::OnLongPressListener*)OHOS::MainPresenterSample::GetInstance(); + mainSweepClock->SetOnLongPressListener(longPressListener); + if (InitSweepClock() == false) { return false; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainPresenterSample.h b/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainPresenterSample.h index 62082c75b..892549d77 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainPresenterSample.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/include/MainPresenterSample.h @@ -42,7 +42,7 @@ constexpr uint16_t HORIZONTAL_STATUS = 0; class MainViewSample; class MainPresenterSample : public Presenter, public ModelListenerSample, public UIView::OnClickListener, public UISwipeView::OnSwipeListener, - public UISwipeView, public CompassPresenter { + public UISwipeView, public CompassPresenter, public UIView::OnLongPressListener { public: MainPresenterSample(); virtual ~MainPresenterSample(); @@ -54,6 +54,7 @@ public: void OnStop() override; virtual void Notify() override; bool OnClick(UIView& view, const ClickEvent& event) override; + bool OnLongPress(UIView& view, const LongPressEvent& event) override; virtual void OnSwipe(UISwipeView& view) override; void setCallback(ZoomEffect* callback) { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainPresenterSample.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainPresenterSample.cpp index ca923bc77..3470989c3 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainPresenterSample.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainPresenterSample.cpp @@ -136,7 +136,19 @@ namespace OHOS } return true; } - + bool MainPresenterSample::OnLongPress(UIView& view, const LongPressEvent& event) + { + printf("coming LongPress\n"); + UNUSED(event); + //string curViewId = view.GetViewId(); + int page = MainViewSample::GetInstance()->GetHorCurrentPage(); + //callback_->OnSwipe(view); + if(page == WATCH_FACE) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_DIAL); + return true; + } + } void MainPresenterSample::OnSwipe(UISwipeView &view) { UNUSED(view);