表盘长按事件绑定
authorCaisking <3449750381@qq.com>
Mon, 27 Nov 2023 03:05:47 +0000 (11:05 +0800)
committerCaisking <3449750381@qq.com>
Mon, 27 Nov 2023 03:05:47 +0000 (11:05 +0800)
code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp
code/sdk/application/wearable/nativeapp/nativeui/main/include/MainPresenterSample.h
code/sdk/application/wearable/nativeapp/nativeui/main/src/MainPresenterSample.cpp

index b076bd1..4a05324 100644 (file)
@@ -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;
     }
index 62082c7..892549d 100644 (file)
@@ -42,7 +42,7 @@ constexpr uint16_t HORIZONTAL_STATUS = 0;
 class MainViewSample;
 class MainPresenterSample : public Presenter<MainViewSample>, 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)
     {
index ca923bc..3470989 100644 (file)
@@ -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);