From fd074df11fbbfd78f9b277a229f32369c3f63023 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Mon, 15 Jul 2024 14:37:12 +0800 Subject: [PATCH] =?utf8?q?=E5=8D=A1=E7=89=87=E7=AE=A1=E7=90=86Slice?= =?utf8?q?=E5=A2=9E=E5=8A=A0=E6=8C=89=E9=94=AE=E9=80=82=E9=85=8D=E5=9B=9E?= =?utf8?q?=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../add_card/include/AddCardPresenter.h | 19 +++++- .../nativeui/add_card/src/AddCardItem.cpp | 4 +- .../add_card/src/AddCardPresenter.cpp | 63 +++++++++++++------ .../nativeui/add_card/src/AddCardView.cpp | 6 +- .../fd230app/nativeui/main/src/MainModel.cpp | 23 +++++-- 5 files changed, 86 insertions(+), 29 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardPresenter.h index 09ce84860..2e3c81a26 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardPresenter.h @@ -1,4 +1,10 @@ -/*** +/*** + * @Date: 2024-05-30 15:59:37 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-07-15 11:31:56 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/add_card/include/AddCardPresenter.h + */ +/*** * @Date: 2024-05-30 15:59:37 * @LastEditors: Caisking 3449750381@qq.com * @LastEditTime: 2024-06-29 14:46:02 @@ -28,7 +34,12 @@ namespace OHOS class AddCardView; class AddCardModel; - class AddCardPresenter : public Presenter, public ModelListenerSample, public UIView::OnClickListener, public UIView::OnDragListener, public ListScrollListener + class AddCardPresenter : public Presenter, + public ModelListenerSample, + public UIView::OnClickListener, + public UIView::OnDragListener, + public ListScrollListener, + public RootView::OnKeyActListener { public: AddCardPresenter(); @@ -45,6 +56,10 @@ namespace OHOS void OnItemSelected(int16_t index, UIView *view) override; bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 + + static AddCardPresenter *GetInstance(); + private: void ResetTickTimer(void); AddCardModel *model{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardItem.cpp b/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardItem.cpp index 65eea3a65..5aaa4d931 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardItem.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardItem.cpp @@ -1,7 +1,7 @@ /*** * @Date: 2024-04-15 10:55:58 * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-07-06 17:57:00 + * @LastEditTime: 2024-07-15 14:10:35 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardItem.cpp */ /*** @@ -79,7 +79,7 @@ namespace OHOS void AddCardItem::SetOnClickListener(OnClickListener *onClickListener) { - cardLabel_.SetOnClickListener(onClickListener); + // cardLabel_.SetOnClickListener(onClickListener); cardToggleButton_.SetOnClickListener(onClickListener); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardPresenter.cpp index a803d3560..2129729c1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardPresenter.cpp @@ -9,38 +9,51 @@ #include "AddCardModel.h" #include "AddCardPresenter.h" +#include "KeyInputListener.h" +#include "custom_utils.h" +#include "common/key_code.h" namespace OHOS { + + // 当前Presenter属性实例化的内存指针 + static AddCardPresenter *g_pAddCardPresenter = nullptr; + AddCardPresenter::AddCardPresenter() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardPresenter::AddCardPresenter"); model = &AddCardModel::GetInstance(); + g_pAddCardPresenter = this; } AddCardPresenter::~AddCardPresenter() { - if (keyActListenr != nullptr) - { - delete keyActListenr; - keyActListenr = nullptr; - } + // if (keyActListenr != nullptr) + // { + // delete keyActListenr; + // keyActListenr = nullptr; + // } } void AddCardPresenter::OnStart() { Presenter::OnStart(); - if (keyActListenr == nullptr) - { - keyActListenr = new KeyInputListener(); - if (keyActListenr != nullptr) - { - RootView::GetInstance()->SetOnKeyActListener(keyActListenr); - } - else - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnStart: new KeyInputListener fail"); - } - } + // if (keyActListenr == nullptr) + // { + // keyActListenr = new KeyInputListener(); + // if (keyActListenr != nullptr) + // { + // RootView::GetInstance()->SetOnKeyActListener(keyActListenr); + // } + // else + // { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnStart: new KeyInputListener fail"); + // } + // } + } + + AddCardPresenter *AddCardPresenter::GetInstance() + { + return g_pAddCardPresenter; } void AddCardPresenter::OnResume(void) @@ -65,10 +78,11 @@ namespace OHOS bool AddCardPresenter::OnClick(UIView &view, const ClickEvent &event) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardPresenter::OnClick"); uint8_t index = model->GetSelectedCardIndex(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardPresenter::OnClick index %d", index); if (!MainModel::GetInstance().GetCardInfoSet(index)) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCardPresenter::OnClick GetCardInfoSet ture"); if (MainModel::GetInstance().GetCardSettingCount() >= CARD_SETTING_COUNT_MAX) { cardCountEvent = true; @@ -133,4 +147,17 @@ namespace OHOS startTime = osKernelGetTick2ms(); return; } + // 增加按键事件 + bool AddCardPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + unsigned short keyID = event.GetKeyId(); + unsigned short keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0) + { + // 回退 + NativeAbility::GetInstance().Back(); + } + return true; + } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardView.cpp b/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardView.cpp index 358459910..5c8f15071 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/add_card/src/AddCardView.cpp @@ -37,6 +37,11 @@ namespace OHOS SetUpListInfo(); SetUpListView(); SetUpToast(); + + SetContainerView(container_); + // 增加按键监听 + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::AddCardPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); } void AddCardView::OnSetUpView() @@ -139,5 +144,4 @@ namespace OHOS toastLabel_.SetVisible(isVisible); toastLabel_.Invalidate(); } - } diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp index a9cf3d08f..1b5628517 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp @@ -184,11 +184,15 @@ namespace OHOS return; } // 检查要插入的位置是否有效 - if (index < 0 || index > cardSettingCount) + int count = sizeof(cardInfoSet) / sizeof(cardInfoSet[0]); + if (index < 0 || index > count) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "index %d is error or cardSettingCount %d is error", index, cardSettingCount); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "index %d is error or count %d is error", index, count); return; } + // 删除的卡片 + cardInfoSet[index].isVisible = false; +#if 0 int count = sizeof(cardInfoSet) / sizeof(cardInfoSet[0]); WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "count:%d\r\n", count); // 设置map里面的属性 @@ -203,6 +207,7 @@ namespace OHOS } WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "cardInfoSet[%d]:id%d\r\n", i, cardInfoSet[i].id); } +#endif int mapindex = 0; // 重新生成cardSettings for (uint8_t i = 0; i < CARD_SETTING_COUNT_MAX; i++) @@ -252,11 +257,15 @@ namespace OHOS } // 检查要插入的位置是否有效 - if (index < 0 || index > cardSettingCount) + int count = sizeof(cardInfoSet) / sizeof(cardInfoSet[0]); + if (index < 0 || index > count) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "index %d is error or count %d is error", index, count); return; } // 设置map里面的属性 + cardInfoSet[index].isVisible = true; +#if 0 int count = sizeof(cardInfoSet) / sizeof(cardInfoSet[0]); for (uint8_t i = 0; i < count; i++) { @@ -264,11 +273,13 @@ namespace OHOS if (cardInfoMap[index].id == cardInfoSet[i].id) { cardInfoSet[i].isVisible = true; - WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "添加卡片:cardSettings[%d] is %d \r\n", index, cardInfoMap[index].id); - WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "设置添加卡片属性:cardInfoSet[%d] is %d \r\n", i, cardInfoSet[i].isVisible); + WEARABLE_LOGE(WEARABL_LOG_MODULE_APP, "添加卡片:cardSettings[%d] is %d \r\n", index, cardInfoMap[index].id); + WEARABLE_LOGE(WEARABL_LOG_MODULE_APP, "设置添加卡片属性:cardInfoSet[%d] is %d \r\n", i, cardInfoSet[i].isVisible); + break; } - WEARABLE_LOGD(WEARABL_LOG_MODULE_APP, "cardInfoSet[%d]:id%d\r\n", i, cardInfoSet[i].id); + WEARABLE_LOGE(WEARABL_LOG_MODULE_APP, "cardInfoSet[%d]:id%d\r\n", i, cardInfoSet[i].id); } +#endif // 设置map里面的属性 int mapindex = 0; -- 2.17.1