VIEW_ADD_CARD 页面 和设置页面在OnResume处理按键注册,解决因弹窗导致按键监听被清除 2197/target/2 2199/1 2199/head 2200/target/1
authorluozheng <1732036298@qq.com>
Tue, 2 Sep 2025 09:23:58 +0000 (17:23 +0800)
committerluozheng <1732036298@qq.com>
Tue, 2 Sep 2025 09:23:58 +0000 (17:23 +0800)
code/sdk/application/wearable/fd230/nativeabilityfwk/src/AbilitySlice.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/add_card/include/AddCardPresenter.h
code/sdk/application/wearable/fd230/nativeapp/nativeui/add_card/src/AddCardPresenter.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/add_card/src/AddCardView.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/applist/src/ApplistPresenter.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/MainPresenterSample.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingPresenter.h
code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingPresenter.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingView.cpp
code/sdk/application/wearable/fd230/service/msg_center/src/msg_center_customer.cpp

index 899c81a..13bdd52 100644 (file)
@@ -55,7 +55,6 @@ void AbilitySlice::OnResume()
     }
     // Reset the default key listener
     // RootView::GetInstance()->SetOnKeyActListener(KeyInputListener::GetInstance());
-    RootView::GetInstance()->SetOnKeyActListener(RootView::GetInstance()->GetOnKeyActListener());
     NativeAbility::GetInstance().SetCurSlicePriority(gSliceDefaultPriority);
 
     UIView* backView = PageTransitionMgr::GetInstance().GetTopSlideBackImage();
index f5802cd..b6e1f85 100644 (file)
@@ -47,7 +47,7 @@ namespace OHOS
         ~AddCardPresenter() override;
 
 
-       
+        void OnResume() override;
         void OnTickEvent() override;
         void Notify() override {}
         bool OnClick(UIView &view, const ClickEvent &event) override;
index ec70283..df60ed0 100644 (file)
@@ -34,6 +34,10 @@ namespace OHOS
     }
 
    
+    void AddCardPresenter::OnResume()
+    {
+        RootView::GetInstance()->SetOnKeyActListener(this);
+    }
 
     bool AddCardPresenter::OnDrag(UIView &view, const DragEvent &event)
     {
index 0da9759..87a1c46 100644 (file)
@@ -34,8 +34,6 @@ namespace OHOS
         SetUpListInfo();
         SetUpListView();
         SetUpToast();
-        //按键监听
-        RootView::GetInstance()->SetOnKeyActListener(presenter_);
     }
 
    
index 3b43455..d18c039 100644 (file)
@@ -58,9 +58,7 @@ REGIST_SLICE(VIEW_APPLIST, ApplistView, ApplistPresenter);
         } else if  (GetCurrentStyle() == AppListStyle::WATERFALL_STYLE) {
             view_->ResumeWaterFallDraggable();
         }
-        // 避免与弹窗收起的时序冲突,放到UI线程消息队列
-        GraphicService::GetInstance()->PostGraphicEvent(
-        std::bind(&OHOS::RootView::SetOnKeyActListener, OHOS::RootView::GetInstance(), KeyInputListener::GetInstance()));
+        RootView::GetInstance()->SetOnKeyActListener(KeyInputListener::GetInstance());
     }
 
     bool ApplistPresenter::OnRotate(UIView& view, const RotateEvent& event)
index ece2fbd..42f1cba 100644 (file)
@@ -135,9 +135,7 @@ REGIST_SLICE(VIEW_MAIN, MainViewSample, MainPresenterSample);
         // Set current page again to invoke OnActive method.
         uint8_t curCardId = view_->GetHorCurrentCard();
         view_->SwitchToCard(curCardId);
-        // 避免与弹窗收起的时序冲突,放到UI线程消息队列
-        GraphicService::GetInstance()->PostGraphicEvent(
-        std::bind(&OHOS::RootView::SetOnKeyActListener, OHOS::RootView::GetInstance(), KeyInputListener::GetInstance()));
+        RootView::GetInstance()->SetOnKeyActListener(KeyInputListener::GetInstance());
 
     #if IS_SUPPORT_BIND_VOTE
 if (ConfigModel::GetInstance()->GetisFirstTimeStart() == true) {
index dbc767f..f0adc2f 100644 (file)
@@ -32,6 +32,7 @@ namespace OHOS
         int GetListItemNum();
 
         void OnStart() override;
+        void OnResume() override;
 
         bool OnClick(UIView &view, const ClickEvent &event) override;
         bool OnDrag(UIView &view, const DragEvent &event) override;
index 5fc810c..57f445f 100644 (file)
@@ -22,8 +22,8 @@ namespace OHOS
 {
 
     REGIST_MENU_PRO(VIEW_SETTING, SettingView, SettingPresenter,
-        PNG_APPLIST_SETTING_IMAGE_BIG, PNG_APPLIST_SETTING_IMAGE,PNG_APPLIST_SETTING_IMAGE, "设置", STR_SETTINGS);
-        
+                    PNG_APPLIST_SETTING_IMAGE_BIG, PNG_APPLIST_SETTING_IMAGE, PNG_APPLIST_SETTING_IMAGE, "设置", STR_SETTINGS);
+
     static SettingPresenter *g_pSettingPresenter = nullptr;
     SettingPresenter::SettingPresenter()
     {
@@ -88,6 +88,13 @@ namespace OHOS
         view_->RefreshSettingList(itemInfo);
     }
 
+    void SettingPresenter::OnResume()
+    {
+        RootView::GetInstance()->SetOnKeyActListener(this);
+        if (view_->GetSettingList())
+            view_->GetSettingList()->RequestFocus();
+    }
+
     bool SettingPresenter::OnDrag(UIView &view, const DragEvent &event)
     {
         UNUSED(view);
@@ -131,9 +138,9 @@ namespace OHOS
 
         SettingItemView *settingItemView = static_cast<SettingItemView *>(&view);
         AppViewId viewId = settingItemView->GetViewId();
-        
+
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%d\n", viewId);
-        NativeAbility::GetInstance().EnterSlice(viewId); //Test
+        NativeAbility::GetInstance().EnterSlice(viewId); // Test
         return true;
     }
 }
index da278de..3f9d8ad 100644 (file)
@@ -117,8 +117,6 @@ namespace OHOS
         contentList->SetSwipeACCLevel(200);      /*设置手指抬起屏幕后的补偿距离。*/
         // contentList->SetReboundSize(30);
         // contentList->SetScrollBlankSize(30);
-        FocusManager::GetInstance()->RequestFocus(contentList);
-        FocusManager::GetInstance()->RequestFocusByDirection(FOCUS_DIRECTION_UP);
         contentList->SetRotateFactor(1.0);
         /* ----------------------------------- Add ---------------------------------- */
         scrollView->Add(contentList);
@@ -134,8 +132,6 @@ namespace OHOS
             viewInitStatus = true;
         }
         settingListOnSetUpView();
-        // 增加按键监听
-       RootView::GetInstance()->SetOnKeyActListener(presenter_);
     }
 
    
index 60f5754..3fe4ea5 100644 (file)
@@ -484,6 +484,7 @@ void MsgCenterNotifyChargePlugProc(const Topic topic, Request* req)
     {
         if (CheckPriority(topic) && !uapi_dev_runtime_get_factory_test_status_flag()) //产测模式不弹充电弹窗
         {
+            NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO);
             NotificationManager::GetInstance()->ShowNotify(ShowChargeingNotify, (uint16_t)topic, true);
         }
     }