From: luozheng <1732036298@qq.com> Date: Thu, 30 May 2024 08:19:30 +0000 (+0800) Subject: settings 文件夹优化更新 X-Git-Tag: release_V1.2.70_20241020_135402~1065 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=9ab3aaae53b79be743e2a02ee6557c535a0f4c49;p=mirrors%2FFD230.git settings 文件夹优化更新 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingItem.h b/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingItem.h index 8c17b999c..968e08b27 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingItem.h +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingItem.h @@ -9,29 +9,13 @@ #define SETTING_ITEM_H #include +#include #include "language/font/ui_resource_string.h" namespace OHOS { - /* - * setting id. - */ - typedef enum : uint16_t - { - // setting item index - SETTING_ITEM_ZERO = 0x0000, - SETTING_ITEM_ONE, - SETTING_ITEM_TWO, - SETTING_ITEM_THREE, - SETTING_ITEM_FOUR, - SETTING_ITEM_FIVE, - SETTING_ITEM_SIX, - SETTING_ITEM_SEVEN, - SETTING_ITEM_MAX, - } SettingIndex; - typedef struct { - SettingIndex index; + AppViewId viewId; const char *icon; UIResourceTextId textId; bool hasSecondMenu; diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingItemView.h b/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingItemView.h index ed09a0d78..82e1797c1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingItemView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingItemView.h @@ -27,21 +27,21 @@ namespace OHOS { public: explicit SettingItemView(); - virtual ~SettingItemView(); + ~SettingItemView() override; virtual void SetItemInfo(const SettingItem itemInfo); virtual void SetUpChild(); - SettingIndex GetSettingIndex(); + AppViewId GetViewId(); + const char *GetIconId(); UIImageView *GetNeedToUpdateImage(void); private: - SettingItemView(const SettingItemView &); UIImageView Icon; UILabelExt settingLabelExt; UILabelButtonExt settingLabelButtonExt; - SettingItem sItemInfo = {SETTING_ITEM_ZERO, nullptr, STR_EXERCISE_GENERAL, false}; + SettingItem sItemInfo = {VIEW_INVALID, nullptr, STR_EXERCISE_GENERAL, false}; /* -------------------------------------------------------------------------- */ void NeedToUpdateImageinit(void); - UIImageView NeedToUpdateImage; //提示需要系统更新的icon图片 + UIImageView NeedToUpdateImage; // 提示需要系统更新的icon图片 /* -------------------------------------------------------------------------- */ }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingModel.h b/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingModel.h index 89bf96f23..3c8c4789c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingModel.h @@ -19,6 +19,7 @@ namespace OHOS { + static const uint16_t SETTING_ITEM_COUNT = 10; class SettingModel { public: @@ -26,7 +27,6 @@ namespace OHOS void InitSettingItem(); const SettingItem *GetSettinglistItems() const; uint8_t GetSettingListNum() const; - const std::map &GetSettingIdToViewId() const; bool GetBlueToothConnectStatus(void); void UpdateBlueToothConnectStatus(bool status); @@ -35,9 +35,8 @@ namespace OHOS SettingModel(const SettingModel &) = delete; SettingModel &operator=(const SettingModel &) = delete; virtual ~SettingModel(); - static const uint16_t SETTING_ITEM_LEN = SETTING_ITEM_MAX; - SettingItem settings[SETTING_ITEM_LEN] = {SETTING_ITEM_ZERO, nullptr, STR_EXERCISE_GENERAL, false}; - std::map settingIdToViewId; + SettingItem settings[SETTING_ITEM_COUNT] = {VIEW_INVALID, nullptr, STR_EXERCISE_GENERAL, false}; + int usedLen; bool btConnectStatus{false}; }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingPresenter.h index 1dc7a162d..3aa1fb87f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingPresenter.h @@ -22,17 +22,17 @@ namespace OHOS { public: SettingPresenter(); - virtual ~SettingPresenter(); + ~SettingPresenter() override; + static SettingPresenter *GetInstance(); + - virtual void OnStart() override; - virtual void OnResume() override; - virtual void OnStop() override; + void OnStart() override; + void OnResume() override; + void OnStop() override; bool OnClick(UIView &view, const ClickEvent &event) override; - virtual bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 - static SettingPresenter *GetInstance(); - private: SettingModel *settingModel; }; diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingItemView.cpp b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingItemView.cpp index 901e69490..1d2671d0f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingItemView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingItemView.cpp @@ -31,7 +31,7 @@ namespace OHOS static constexpr int16_t SETTINGLABELBUTTONEXT_H = 100; static constexpr int16_t SETTINGLABELBUTTONEXT_TEXT_FONT = 30; static constexpr int16_t SETTINGLABELBUTTONEXT_LINE_HEIGHT = 35; - + SettingItemView::SettingItemView() { SetPosition(0, 120, 380, 120); @@ -56,10 +56,9 @@ namespace OHOS { sItemInfo = itemInfo; Icon.SetSrc(itemInfo.icon); - //WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%d", itemInfo.textId); settingLabelExt.SetTextId(itemInfo.textId); - if (itemInfo.textId == STR_SYSTEM && SystemUpdateModel::GetInstance().IsLatestVersion() == false) // 如果不是最新系统版本出现小圆点 + if (itemInfo.textId == STR_SYSTEM && SystemUpdateModel::GetInstance().IsLatestVersion() == false) // 如果不是最新系统版本出现小圆点 { NeedToUpdateImageinit(); } @@ -67,11 +66,11 @@ namespace OHOS void SettingItemView::SetUpChild() { - Icon.SetPosition(SETTING_ICON_X, SETTING_SICON_Y,SETTING_SICON_W,SETTING_SICON_H); + Icon.SetPosition(SETTING_ICON_X, SETTING_SICON_Y, SETTING_SICON_W, SETTING_SICON_H); Icon.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); Icon.SetAutoEnable(false); Icon.SetResizeMode(UIImageView::FILL); - Icon.SetStyle(STYLE_BORDER_RADIUS,100); + Icon.SetStyle(STYLE_BORDER_RADIUS, 100); settingLabelExt.SetPosition(SETTINGLABELEXT_X, SETTINGLABELEXT_Y, SETTINGLABELEXT_W, SETTINGLABELEXT_H); settingLabelExt.SetStyle(STYLE_TEXT_FONT, SETTINGLABELEXT_TEXT_FONT); @@ -93,9 +92,14 @@ namespace OHOS settingLabelButtonExt.SetImageSrc(img, img); } - SettingIndex SettingItemView::GetSettingIndex() + AppViewId SettingItemView::GetViewId() { - return sItemInfo.index; + return sItemInfo.viewId; + } + + const char *SettingItemView::GetIconId() + { + return sItemInfo.icon; } void SettingItemView::NeedToUpdateImageinit(void) @@ -105,7 +109,7 @@ namespace OHOS char *imagesPath = "/user/res/system/SYSTEM_UPDATE_FLAG.bin"; NeedToUpdateImage.SetSrc(imagesPath); NeedToUpdateImage.SetVisible(false); - + Add(&NeedToUpdateImage); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp index 0ac99f392..658ec6d69 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp @@ -22,23 +22,16 @@ namespace OHOS void SettingModel::InitSettingItem() { - int settingLen = 0; - settings[settingLen++] = {SETTING_ITEM_ZERO, PNG_SETTINGS_DISPLAY_BRIGHTNESS, STR_SCREEN_AND_BRIGHTNESS, true}; - settings[settingLen++] = {SETTING_ITEM_ONE, PNG_SETTINGS_NETWORKANDCALL, STR_NETWORKANDCALL, true}; - settings[settingLen++] = {SETTING_ITEM_TWO, PNG_SETTINGS_BLUETOOTH, STR_BLUETOOTH, true}; - settings[settingLen++] = {SETTING_ITEM_THREE, PNG_SETTINGS_SOUND_VIBRATION, STR_SOUND_AND_VIBRATION, true}; - settings[settingLen++] = {SETTING_ITEM_FOUR, PNG_SETTINGS_DISPLAY_MODE, STR_DISPLAY_MODE, true}; - settings[settingLen++] = {SETTING_ITEM_FIVE, PNG_SETTINGS_MOTION_RECOGNITION, STR_MOTION_RECOGNITION, true}; - settings[settingLen++] = {SETTING_ITEM_SIX, PNG_SETTINGS_SYSTEM, STR_SYSTEM, true}; - settings[settingLen++] = {SETTING_ITEM_SEVEN, PNG_SETTINGS_SHUTDOWN_AND_RESTART, STR_SHUTDOWN_AND_RESTART, true}; - settingIdToViewId.insert(std::pair(SETTING_ITEM_ZERO, VIEW_DISPLAY_BRIGHTNESS)); - settingIdToViewId.insert(std::pair(SETTING_ITEM_ONE, VIEW_NETWORKANDCALL)); - settingIdToViewId.insert(std::pair(SETTING_ITEM_TWO, VIEW_CLASSIC_BLUETOOTH)); - settingIdToViewId.insert(std::pair(SETTING_ITEM_THREE, VIEW_SOUND_VIBRATION)); - settingIdToViewId.insert(std::pair(SETTING_ITEM_FOUR, VIEW_SET_DESKTOP)); - settingIdToViewId.insert(std::pair(SETTING_ITEM_FIVE, VIEW_MOTION_RECOGNITION)); - settingIdToViewId.insert(std::pair(SETTING_ITEM_SIX, VIEW_SYSTEM)); - settingIdToViewId.insert(std::pair(SETTING_ITEM_SEVEN, VIEW_SHUTDOWN_OR_REBOOT)); + int index = 0; + settings[index++] = {VIEW_DISPLAY_BRIGHTNESS, PNG_SETTINGS_DISPLAY_BRIGHTNESS, STR_SCREEN_AND_BRIGHTNESS, true}; + settings[index++] = {VIEW_NETWORKANDCALL, PNG_SETTINGS_NETWORKANDCALL, STR_NETWORKANDCALL, true}; + settings[index++] = {VIEW_CLASSIC_BLUETOOTH, PNG_SETTINGS_BLUETOOTH, STR_BLUETOOTH, true}; + settings[index++] = {VIEW_SOUND_VIBRATION, PNG_SETTINGS_SOUND_VIBRATION, STR_SOUND_AND_VIBRATION, true}; + settings[index++] = {VIEW_SET_DESKTOP, PNG_SETTINGS_DISPLAY_MODE, STR_DISPLAY_MODE, true}; + settings[index++] = {VIEW_MOTION_RECOGNITION, PNG_SETTINGS_MOTION_RECOGNITION, STR_MOTION_RECOGNITION, true}; + settings[index++] = {VIEW_SYSTEM, PNG_SETTINGS_SYSTEM, STR_SYSTEM, true}; + settings[index++] = {VIEW_SHUTDOWN_OR_REBOOT, PNG_SETTINGS_SHUTDOWN_AND_RESTART, STR_SHUTDOWN_AND_RESTART, true}; + usedLen = index; } const SettingItem *SettingModel::GetSettinglistItems() const @@ -48,12 +41,7 @@ namespace OHOS uint8_t SettingModel::GetSettingListNum() const { - return SETTING_ITEM_LEN; - } - - const std::map &SettingModel::GetSettingIdToViewId() const - { - return settingIdToViewId; + return usedLen; } bool SettingModel::GetBlueToothConnectStatus(void) diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp index a6a895ee3..a41033f99 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp @@ -28,6 +28,11 @@ namespace OHOS g_pSettingPresenter = nullptr; } + SettingPresenter *SettingPresenter::GetInstance() + { + return g_pSettingPresenter; + } + void SettingPresenter::OnStart() { Presenter::OnStart(); @@ -46,10 +51,7 @@ namespace OHOS view_->AddSettingItemToList(itemInfo[i]); } } - SettingPresenter *SettingPresenter::GetInstance() - { - return g_pSettingPresenter; - } + void SettingPresenter::OnStop(void) { return; @@ -62,22 +64,8 @@ namespace OHOS if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) { - // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnDrag ChangeSlice(VIEW_APPLIST)"); - // /* - // GetPreSliceId作用:是从已存储的切片中获取上一个切片的ID,并且在切片数小于2的情况下返回一个无效的切片ID。 - // */ - // uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - // if (preSlice == VIEW_APPLIST) - // { - // NativeAbility::GetInstance().ChangeSlice(preSlice); - // return true; - // } - // else - // { - // NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); - // return true; - // } - NativeAbility::GetInstance().Back(); + // NativeAbility::GetInstance().Back(); + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); } return true; } @@ -87,18 +75,8 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnKeyAct"); uint16 keyID = event.GetKeyId(); uint16 keyState = event.GetState(); - // 如果是power键就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0) { - // uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - // if (preSlice == VIEW_APPLIST) - // { - // NativeAbility::GetInstance().ChangeSlice(preSlice); - // } - // else - // { - // NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); - // } NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); } return true; @@ -108,31 +86,9 @@ namespace OHOS { UNUSED(event); SettingItemView *settingItemView = static_cast(&view); - SettingIndex index = settingItemView->GetSettingIndex(); - if (index >= SettingModel::GetInstance().GetSettingListNum()) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnClick is no index"); - return false; - } - else - { - NativeAbility::GetInstance().EnterSlice(SettingModel::GetInstance().GetSettingIdToViewId().at(index)); - // NativeAbility::GetInstance().ChangeSlice(SettingModel::GetInstance().GetSettingIdToViewId().at(index)); -/* -------------------------------------------------------------------------- */ -#if 0 - if (index == SETTING_ITEM_TWO) - { - RebootModel::GetInstance()->SetSelectViewId(REBOOTDEVICE); - RebootModel::GetInstance()->SetExitsView(true); - } - else if (index == SETTING_ITEM_THREE) - { - RebootModel::GetInstance()->SetSelectViewId(SHUTDOWNDEVICE); - RebootModel::GetInstance()->SetExitsView(true); - } - NativeAbility::GetInstance().ChangeSlice(SettingModel::GetInstance().GetSettingIdToViewId().at(index)); -#endif - return true; - } + AppViewId viewId = settingItemView->GetViewId(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "%d\n", viewId); + NativeAbility::GetInstance().EnterSlice(viewId); + return true; } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingView.cpp index 52f28c241..f23090e78 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingView.cpp @@ -38,21 +38,36 @@ namespace OHOS SettingView::~SettingView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::~SettingView"); - scrollView->RemoveAll(); - delete title; - title = nullptr; + if (scrollView != nullptr) + { + scrollView->RemoveAll(); + delete scrollView; + scrollView = nullptr; + } - delete listAdapter; - listAdapter = nullptr; + if (title != nullptr) + { + delete title; + title = nullptr; + } - delete contentList; - contentList = nullptr; + if (listAdapter != nullptr) + { + delete listAdapter; + listAdapter = nullptr; + } - delete scrollView; - scrollView = nullptr; + if (contentList != nullptr) + { + delete contentList; + contentList = nullptr; + } - delete dragListener; - dragListener = nullptr; + if (dragListener != nullptr) + { + delete dragListener; + dragListener = nullptr; + } } void SettingView::OnStart() @@ -88,8 +103,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::listAdapter is nullptr"); return; } - UIView::OnClickListener *clicklistener = static_cast(SettingPresenter::GetInstance()); - listAdapter->SetItemClickListener(clicklistener); + listAdapter->SetItemClickListener(presenter_); contentList = new UIList(UIList::VERTICAL); if (contentList == nullptr) { @@ -120,11 +134,6 @@ namespace OHOS scrollView->SetTouchable(true); scrollView->SetThrowDrag(true); - // 增加按键监听 - RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::SettingPresenter::GetInstance(); - RootView::GetInstance()->SetOnKeyActListener(keyactListener); - RootView::GetInstance()->SetIntercept(true); - dragListener = new SettingPresenter(); if (dragListener == nullptr) { @@ -132,6 +141,11 @@ namespace OHOS return; } scrollView->SetOnDragListener(dragListener); + // scrollView->SetYScrollBarVisible(true); + + // 增加按键监听 + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::SettingPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); } void SettingView::OnSetUpView() @@ -147,7 +161,8 @@ namespace OHOS scrollView->Add(contentList); RootView::GetInstance()->Add(scrollView); contentList->SetAdapter(listAdapter); - Draw(); + container_ = scrollView; + return; } @@ -155,6 +170,7 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::OnTearDownView"); View::OnTearDownView(); + Draw(); return; }