From 036e62faf8b4d0048cc978c0498603eb2f582a0d Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Sat, 25 Apr 2026 11:26:31 +0800 Subject: [PATCH] =?utf8?q?applist1201patch=E5=90=88=E5=B9=B6=EF=BC=8C?= =?utf8?q?=E6=96=B0=E5=A2=9E=E6=98=9F=E7=90=83=E6=A0=B7=E5=BC=8F=EF=BC=8C?= =?utf8?q?=E4=BC=98=E5=8C=96=E6=A0=B7=E5=BC=8F=E6=B7=BB=E5=8A=A0=E5=92=8C?= =?utf8?q?=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../applist/include/PlanetDesktopFragment.h | 96 +++---- .../applist/src/PlanetDesktopFragment.cpp | 238 +++++++++--------- .../main/src/dropdown/DropDownCardPage2.cpp | 61 +---- .../themestyle/include/ThemeStyleCatalog.h | 51 ++++ .../themestyle/include/ThemeStyleModel.h | 39 +-- .../themestyle/include/ThemeStyleView.h | 19 +- .../nativeui/themestyle/include/readme.txt | 87 +++++++ .../themestyle/src/ThemeStyleCatalog.cpp | 172 +++++++++++++ .../themestyle/src/ThemeStyleModel.cpp | 25 +- .../themestyle/src/ThemeStylePresenter.cpp | 31 +-- .../themestyle/src/ThemeStyleView.cpp | 60 ++--- 11 files changed, 531 insertions(+), 348 deletions(-) create mode 100644 code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/include/ThemeStyleCatalog.h create mode 100644 code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/include/readme.txt create mode 100644 code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/src/ThemeStyleCatalog.cpp diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/include/PlanetDesktopFragment.h b/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/include/PlanetDesktopFragment.h index f7c4bd246..fa4982c11 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/include/PlanetDesktopFragment.h +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/include/PlanetDesktopFragment.h @@ -1,48 +1,48 @@ -// /* -// * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. -// * Description: PlanetDesktop -// * Created: 2025-07-29 -// */ - -// #ifndef PLANET_DESKTOP_FRAGMENT_H -// #define PLANET_DESKTOP_FRAGMENT_H - -// #include "UIDesktopFragment.h" -// #include "components/ui_custom_planet_list.h" - -// namespace OHOS { -// class PlanetItemView; -// class PlanetDesktopFragment : public UIDesktopFragment { -// public: -// bool OnClick(UIView &view, const ClickEvent &event) override; -// void AddAppItemToList(const AppItem &item) override; -// void ClearAppItemToList() override; -// void RefreshAppList() override; - -// protected: -// void OnCreateView(void* data) override; -// void OnDestroyView() override; - -// private: -// UICustomPlanetList* planetList_{nullptr}; -// List pltItemList_; -// List pltLabelList_; -// }; - -// class PlanetItemView : public UIImageView { -// public: -// explicit PlanetItemView() {} -// ~PlanetItemView() {} -// void SetItemInfo(const AppItem &itemInfo); -// AppViewId GetViewId(); -// const char *GetAppUid(); -// const char *GetAppLabel(); - -// private: -// PlanetItemView(const PlanetItemView &) = delete; -// PlanetItemView &operator = (const PlanetItemView &) = delete; -// AppItem itemInfo_ = { VIEW_INVALID, nullptr, nullptr, nullptr, nullptr }; -// }; -// } - -// #endif // PLANET_DESKTOP_FRAGMENT_H +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PlanetDesktop + * Created: 2025-07-29 + */ + +#ifndef PLANET_DESKTOP_FRAGMENT_H +#define PLANET_DESKTOP_FRAGMENT_H + +#include "UIDesktopFragment.h" +#include "components/ui_custom_planet_list.h" + +namespace OHOS { +class PlanetItemView; +class PlanetDesktopFragment : public UIDesktopFragment { +public: + bool OnClick(UIView &view, const ClickEvent &event) override; + void AddAppItemToList(const AppItem &item) override; + void ClearAppItemToList() override; + void RefreshAppList() override; + +protected: + void OnCreateView(void* data) override; + void OnDestroyView() override; + +private: + UICustomPlanetList* planetList_{nullptr}; + List pltItemList_; + List pltLabelList_; +}; + +class PlanetItemView : public UIImageView { +public: + explicit PlanetItemView() {} + ~PlanetItemView() {} + void SetItemInfo(const AppItem &itemInfo); + AppViewId GetViewId(); + const char *GetAppUid(); + const char *GetAppLabel(); + +private: + PlanetItemView(const PlanetItemView &) = delete; + PlanetItemView &operator = (const PlanetItemView &) = delete; + AppItem itemInfo_ = { VIEW_INVALID, nullptr, nullptr, nullptr, nullptr }; +}; +} + +#endif // PLANET_DESKTOP_FRAGMENT_H diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/PlanetDesktopFragment.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/PlanetDesktopFragment.cpp index a0afaa508..55ef30d06 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/PlanetDesktopFragment.cpp +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/PlanetDesktopFragment.cpp @@ -1,134 +1,134 @@ -// /* -// * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. -// * Description: PlanetDesktop -// * Created: 2025-07-29 -// */ +/* + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2025-2025. All rights reserved. + * Description: PlanetDesktop + * Created: 2025-07-29 + */ -// #include "applist/include/PlanetDesktopFragment.h" -// #include "applist/include/DesktopFactory.h" -// #include "applist/include/ApplistModel.h" +#include "applist/include/PlanetDesktopFragment.h" +#include "applist/include/DesktopFactory.h" +#include "applist/include/ApplistModel.h" -// namespace OHOS { -// REGIST_DESKTOP_STYLE(PLANET_STYLE, PlanetDesktopFragment); +namespace OHOS { +REGIST_DESKTOP_STYLE(PLANET_STYLE, PlanetDesktopFragment); -// static constexpr int16 LABEL_FONT_SIZE = 15; +static constexpr int16 LABEL_FONT_SIZE = 15; -// void PlanetDesktopFragment::OnCreateView(void* data) -// { -// WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlanetDesktopFragment::OnCreateView "); -// imgSize_ = 100; // 100, size of item -// int16_t imageDistance = 5; // 5, image distance -// if (planetList_ == nullptr) { -// planetList_ = new UICustomPlanetList(imgSize_, imageDistance); -// } -// planetList_->SetPosition(0, 0, fragmentView_.GetWidth(), fragmentView_.GetHeight()); -// planetList_->SetDraggable(true); -// planetList_->SetThrowDrag(true); -// planetList_->SetItemClickListener(this); -// planetList_->RequestFocus(); -// fragmentView_.Add(planetList_); -// } +void PlanetDesktopFragment::OnCreateView(void* data) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlanetDesktopFragment::OnCreateView "); + imgSize_ = 100; // 100, size of item + int16_t imageDistance = 5; // 5, image distance + if (planetList_ == nullptr) { + planetList_ = new UICustomPlanetList(imgSize_, imageDistance); + } + planetList_->SetPosition(0, 0, fragmentView_.GetWidth(), fragmentView_.GetHeight()); + planetList_->SetDraggable(true); + planetList_->SetThrowDrag(true); + planetList_->SetItemClickListener(this); + planetList_->RequestFocus(); + fragmentView_.Add(planetList_); +} -// void PlanetDesktopFragment::OnDestroyView() -// { -// WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlanetDesktopFragment::OnDestroyView"); -// ClearAppItemToList(); -// if (planetList_ != nullptr) { -// delete planetList_; -// planetList_ = nullptr; -// } -// } +void PlanetDesktopFragment::OnDestroyView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlanetDesktopFragment::OnDestroyView"); + ClearAppItemToList(); + if (planetList_ != nullptr) { + delete planetList_; + planetList_ = nullptr; + } +} -// bool PlanetDesktopFragment::OnClick(UIView &view, const ClickEvent &event) -// { -// UNUSED(event); -// PlanetItemView *itemView = dynamic_cast(&view); -// AppViewId viewId = itemView->GetViewId(); -// char *uid = (char *)itemView->GetAppUid(); +bool PlanetDesktopFragment::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + PlanetItemView *itemView = dynamic_cast(&view); + AppViewId viewId = itemView->GetViewId(); + char *uid = (char *)itemView->GetAppUid(); -// WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlanetDesktopFragment::OnClick viewid = %d", viewId); -// return SwitchView(viewId, uid, TransitionType::TRANSITION_INVALID, PLANET_STYLE); -// } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlanetDesktopFragment::OnClick viewid = %d", viewId); + return SwitchView(viewId, uid, TransitionType::TRANSITION_INVALID, PLANET_STYLE); +} -// void PlanetDesktopFragment::AddAppItemToList(const AppItem &item) -// { -// WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlanetDesktopFragment::AddAppItemToList"); -// PlanetItemView* itemView = new PlanetItemView(); -// UILabel* label = new UILabel(); -// itemView->SetItemInfo(item); -// itemView->SetSrc(item.iconSmall); -// itemView->SetTouchable(true); -// itemView->SetAutoEnable(false); -// itemView->SetResizeMode(UIImageView::ImageResizeMode::CONTAIN); -// itemView->SetOnClickListener(this); -// label->SetText(item.label); -// label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT_SIZE); -// label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); -// label->SetVisible(false); -// label->SetHeight(30); // 30, label height -// label->SetWidth(100); // 100, label width -// planetList_->AddItemVIew(itemView); -// planetList_->AddLabel(label); -// pltItemList_.PushBack(itemView); -// pltLabelList_.PushBack(label); -// } +void PlanetDesktopFragment::AddAppItemToList(const AppItem &item) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlanetDesktopFragment::AddAppItemToList"); + PlanetItemView* itemView = new PlanetItemView(); + UILabel* label = new UILabel(); + itemView->SetItemInfo(item); + itemView->SetSrc(item.iconSmall); + itemView->SetTouchable(true); + itemView->SetAutoEnable(false); + itemView->SetResizeMode(UIImageView::ImageResizeMode::CONTAIN); + itemView->SetOnClickListener(this); + label->SetText(item.label); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT_SIZE); + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetVisible(false); + label->SetHeight(30); // 30, label height + label->SetWidth(100); // 100, label width + planetList_->AddItemVIew(itemView); + planetList_->AddLabel(label); + pltItemList_.PushBack(itemView); + pltLabelList_.PushBack(label); +} -// void PlanetDesktopFragment::ClearAppItemToList() -// { -// WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlanetDesktopFragment::ClearAppItemToList"); -// int16_t offsetX = 0; -// int16_t offsetY = 0; -// ApplistModel *model = &ApplistModel::GetInstance(); +void PlanetDesktopFragment::ClearAppItemToList() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlanetDesktopFragment::ClearAppItemToList"); + int16_t offsetX = 0; + int16_t offsetY = 0; + ApplistModel *model = &ApplistModel::GetInstance(); -// planetList_->RestoreItemState(); -// planetList_->GetLastOffset(offsetX, offsetY); -// model->SetLastOffset(offsetX, offsetY); -// if (planetList_ != nullptr) { -// planetList_->RemoveAll(); -// } -// ListNode* viewNode = pltItemList_.Head(); -// while (viewNode != pltItemList_.End()) { -// delete(viewNode->data_); -// viewNode = viewNode->next_; -// } -// pltItemList_.Clear(); -// ListNode* labelNode = pltLabelList_.Head(); -// while (labelNode != pltLabelList_.End()) { -// delete(labelNode->data_); -// labelNode = labelNode->next_; -// } -// pltLabelList_.Clear(); -// } + planetList_->RestoreItemState(); + planetList_->GetLastOffset(offsetX, offsetY); + model->SetLastOffset(offsetX, offsetY); + if (planetList_ != nullptr) { + planetList_->RemoveAll(); + } + ListNode* viewNode = pltItemList_.Head(); + while (viewNode != pltItemList_.End()) { + delete(viewNode->data_); + viewNode = viewNode->next_; + } + pltItemList_.Clear(); + ListNode* labelNode = pltLabelList_.Head(); + while (labelNode != pltLabelList_.End()) { + delete(labelNode->data_); + labelNode = labelNode->next_; + } + pltLabelList_.Clear(); +} -// void PlanetDesktopFragment::RefreshAppList(void) -// { -// WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlanetDesktopFragment::RefreshAppList"); -// int16_t offsetX = 0; -// int16_t offsetY = 0; -// ApplistModel *model = &ApplistModel::GetInstance(); -// model->GetLastOffset(offsetX, offsetY); -// planetList_->SetLastOffset(offsetX, offsetY); -// planetList_->LayoutChildren(true); -// planetList_->AddClickListenerToAppItems(); -// } +void PlanetDesktopFragment::RefreshAppList(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PlanetDesktopFragment::RefreshAppList"); + int16_t offsetX = 0; + int16_t offsetY = 0; + ApplistModel *model = &ApplistModel::GetInstance(); + model->GetLastOffset(offsetX, offsetY); + planetList_->SetLastOffset(offsetX, offsetY); + planetList_->LayoutChildren(true); + planetList_->AddClickListenerToAppItems(); +} -// void PlanetItemView::SetItemInfo(const AppItem &itemInfo) -// { -// itemInfo_ = itemInfo; -// } +void PlanetItemView::SetItemInfo(const AppItem &itemInfo) +{ + itemInfo_ = itemInfo; +} -// AppViewId PlanetItemView::GetViewId() -// { -// return static_cast(itemInfo_.id); -// } +AppViewId PlanetItemView::GetViewId() +{ + return static_cast(itemInfo_.id); +} -// const char *PlanetItemView::GetAppUid() -// { -// return itemInfo_.uid; -// } +const char *PlanetItemView::GetAppUid() +{ + return itemInfo_.uid; +} -// const char *PlanetItemView::GetAppLabel() -// { -// return itemInfo_.label; -// } -// } +const char *PlanetItemView::GetAppLabel() +{ + return itemInfo_.label; +} +} diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/main/src/dropdown/DropDownCardPage2.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/main/src/dropdown/DropDownCardPage2.cpp index 04b96aa78..ab0323fc6 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/main/src/dropdown/DropDownCardPage2.cpp +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/main/src/dropdown/DropDownCardPage2.cpp @@ -12,6 +12,7 @@ #include "AppViewIDs.h" #include "NativeAbility.h" #include "themestyle/include/ThemeStyleModel.h" +#include "themestyle/include/ThemeStyleCatalog.h" namespace OHOS { // viewId @@ -24,13 +25,6 @@ namespace OHOS static constexpr const char *DROPDOWN_LIGHTING_IMAGE = "/user/res/dropdown/DROPDOWN_LIGHTING.bin"; - static constexpr const char *DROPDOWN_APPLIST_DISPLAY_IMAGE[] = - { - "/user/res/themestyle/list.bin", // 列表 - "/user/res/themestyle/arclist.bin", // 弧形列表 - "/user/res/themestyle/hexagons.bin", // 蜂窝 - }; - static DropDownCardPage2 *g_pDropDownCardPage2{nullptr}; DropDownCardPage2::DropDownCardPage2() { @@ -54,28 +48,11 @@ namespace OHOS void DropDownCardPage2::SetApplistDisplay(void) { ThemeStyle style = ThemeStyleModel::GetInstance().GetAppListDisplayStyle(); - if (style == ThemeStyle::APPLIST_STYLE) - { - toggleButton[2]->SetImages(DROPDOWN_APPLIST_DISPLAY_IMAGE[1], DROPDOWN_APPLIST_DISPLAY_IMAGE[1]); // 切换到弧形列表 - ThemeStyleModel::GetInstance().SetAppListDisplayStyle(ThemeStyle::ARC_SCALE_LIST_STYLE); - } - else if (style == ThemeStyle::ARC_SCALE_LIST_STYLE) - { - toggleButton[2]->SetImages(DROPDOWN_APPLIST_DISPLAY_IMAGE[2], DROPDOWN_APPLIST_DISPLAY_IMAGE[2]);// 切换到蜂窝 - ThemeStyleModel::GetInstance().SetAppListDisplayStyle(ThemeStyle::HEXAGONS_STYLE); - } - else if (style == ThemeStyle::HEXAGONS_STYLE) - { - toggleButton[2]->SetImages(DROPDOWN_APPLIST_DISPLAY_IMAGE[0], DROPDOWN_APPLIST_DISPLAY_IMAGE[0]); // 切换到列表 - ThemeStyleModel::GetInstance().SetAppListDisplayStyle(ThemeStyle::APPLIST_STYLE); - } - // 如果当前是拨号盘或瀑布流,直接切换到列表 - else if (style == ThemeStyle::CIRCLE_LIST_STYLE || style == ThemeStyle::WATERFALL_STYLE) - { - toggleButton[2]->SetImages(DROPDOWN_APPLIST_DISPLAY_IMAGE[0], DROPDOWN_APPLIST_DISPLAY_IMAGE[0]); // 切换到列表 - ThemeStyleModel::GetInstance().SetAppListDisplayStyle(ThemeStyle::APPLIST_STYLE); - } - + ThemeStyle next = GetThemeStyleDropdownNextStyle(style); + ThemeStyleModel::GetInstance().SetAppListDisplayStyle(next); + int imgOrder = GetThemeStyleDropdownImageIndex(next); + const char *img = GetThemeStyleDropdownImagePathByCycleOrder(static_cast(imgOrder)); + toggleButton[2]->SetImages(img, img); return; } bool DropDownCardPage2::OnClick(UIView &view, const ClickEvent &event) @@ -142,29 +119,13 @@ namespace OHOS { int size = sizeof(toggleButton) / sizeof(toggleButton[0]); ThemeStyle style = ThemeStyleModel::GetInstance().GetAppListDisplayStyle(); - int index = 0; - if (style == ThemeStyle::APPLIST_STYLE) // 列表 - { - index = 0; - } - else if (style == ThemeStyle::ARC_SCALE_LIST_STYLE) // 弧形列表 - { - index = 1; - } - else if (style == ThemeStyle::HEXAGONS_STYLE) // 蜂窝 - { - index = 2; - } - // 如果当前是拨号盘或瀑布流,显示为列表样式 - else if (style == ThemeStyle::CIRCLE_LIST_STYLE || style == ThemeStyle::WATERFALL_STYLE) - { - index = 0; - } - + int imgOrder = GetThemeStyleDropdownImageIndex(style); + const char *applistImg = GetThemeStyleDropdownImagePathByCycleOrder(static_cast(imgOrder)); + ToggleButtonConfig toggleButtonConfig[] = { {0, 0, 100, 100, DROPDOWN_FINDPHONE_TOGGLEBUTTON_VIEWID, DROPDOWN_FINDPHONE_IMAGE, DROPDOWN_FINDPHONE_IMAGE, true}, {110, 0, 100, 100, DROPDOWN_LIGHTING_TOGGLEBUTTON_VIEWID, DROPDOWN_LIGHTING_IMAGE, DROPDOWN_LIGHTING_IMAGE, true}, - {220, 0, 100, 100, DROPDOWN_APPLIST_DISPLAY_TOGGLEBUTTON_VIEWID, DROPDOWN_APPLIST_DISPLAY_IMAGE[index], DROPDOWN_APPLIST_DISPLAY_IMAGE[index], true}, + {220, 0, 100, 100, DROPDOWN_APPLIST_DISPLAY_TOGGLEBUTTON_VIEWID, applistImg, applistImg, true}, }; for (int i = 0; i < size; i++) @@ -192,6 +153,8 @@ namespace OHOS } SetDraggable(true); SetTouchable(true); + + // ThemeStyleModel::GetInstance().SetAppListDisplayStyle(ThemeStyle::PLANET_STYLE); return true; } diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/include/ThemeStyleCatalog.h b/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/include/ThemeStyleCatalog.h new file mode 100644 index 000000000..5c09a64e4 --- /dev/null +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/include/ThemeStyleCatalog.h @@ -0,0 +1,51 @@ +/* + * Single place to register N9 theme style UI rows and persistence keys. + * To add a row on the settings page: append one entry to kThemeStyleSettingsRows in ThemeStyleCatalog.cpp + * and extend ThemeStyle enum / config if needed. To remove: delete the entry (and unused enum if applicable). + */ +#ifndef THEME_STYLE_CATALOG_H +#define THEME_STYLE_CATALOG_H + +#include +#include +#include +#include "themestyle/include/ThemeStyleModel.h" + +namespace OHOS +{ +/** Capacity for fixed UI arrays in ThemeStyleView (must be >= settings row count). */ +constexpr uint16_t THEME_STYLE_SETTINGS_UI_CAPACITY = 8; + +struct ThemeStyleSettingsRow +{ + ThemeStyle style; + const char *persistValue; + const char *buttonViewId; + int16_t titleTextId; + const char *previewImagePath; + /** Order in the quick-style dropdown (0..n-1), or 0xFF if not in that cycle. */ + uint8_t dropdownCycleOrder; + static constexpr uint8_t kNotInDropdownCycle = 0xFF; +}; + +size_t GetThemeStyleSettingsRowCount(void); +const ThemeStyleSettingsRow &GetThemeStyleSettingsRow(size_t index); + +/** Config string <-> ThemeStyle for all persisted styles (including styles hidden from the settings list). */ +const char *GetPersistStringForThemeStyle(ThemeStyle style); +ThemeStyle GetThemeStyleFromPersistString(const std::string &value); + +/** Which settings row should show the checkmark for the current persisted style. */ +int GetThemeStyleSettingsHighlightIndex(ThemeStyle current); + +int FindThemeStyleSettingsRowIndexByViewId(const char *viewId); + +/** Dropdown tile: image index 0..GetThemeStyleDropdownCycleCount()-1 for the current style. */ +int GetThemeStyleDropdownImageIndex(ThemeStyle current); +/** Next style when the user taps the dropdown applist-style control. */ +ThemeStyle GetThemeStyleDropdownNextStyle(ThemeStyle current); +size_t GetThemeStyleDropdownCycleCount(void); +const char *GetThemeStyleDropdownImagePathByCycleOrder(size_t order); +} // namespace OHOS + +#endif diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/include/ThemeStyleModel.h b/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/include/ThemeStyleModel.h index 9620dacbb..c3ace9480 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/include/ThemeStyleModel.h +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/include/ThemeStyleModel.h @@ -9,9 +9,6 @@ #define SET_THEMESTYLE_MODEL_H #include -#include -#include -#include #include "AppViewIDs.h" #include "UiConfig.h" @@ -25,40 +22,20 @@ namespace OHOS static constexpr const char *THEMESTYLE_VALUE_WATERFALL = "waterfall"; static constexpr const char *THEMESTYLE_VALUE_ARC_SCALE_LIST = "arc_scale_list"; static constexpr const char *THEMESTYLE_VALUE_CIRCLE_LIST = "circle_list"; + static constexpr const char *THEMESTYLE_VALUE_PLANET = "planet"; typedef enum : uint16_t { - ARC_SCALE_LIST_STYLE,//弧形列表 - HEXAGONS_STYLE, // 蜂窝显示 - CIRCLE_LIST_STYLE,//拨号盘 - WATERFALL_STYLE, // 瀑布流显示 - APPLIST_STYLE, // 列表显示 - FOOTBALL_STYLE, //足球 + ARC_SCALE_LIST_STYLE, //弧形列表 + HEXAGONS_STYLE, // 蜂窝显示 + CIRCLE_LIST_STYLE, //拨号盘 + WATERFALL_STYLE, // 瀑布流显示 + APPLIST_STYLE, // 列表显示 + FOOTBALL_STYLE, //足球 + PLANET_STYLE, //行星 MAX_THEME_STYLE, } ThemeStyle; - // 映射[枚举值]->[显示样式值}的关系 - const std::map ThemeStyleMap = { - {ThemeStyle::APPLIST_STYLE, THEMESTYLE_VALUE_LIST}, - {ThemeStyle::HEXAGONS_STYLE, THEMESTYLE_VALUE_HEXAGONS}, - {ThemeStyle::FOOTBALL_STYLE, THEMESTYLE_VALUE_FOOTBALL}, - {ThemeStyle::WATERFALL_STYLE, THEMESTYLE_VALUE_WATERFALL}, - {ThemeStyle::ARC_SCALE_LIST_STYLE, THEMESTYLE_VALUE_ARC_SCALE_LIST}, - {ThemeStyle::CIRCLE_LIST_STYLE, THEMESTYLE_VALUE_CIRCLE_LIST}, - // 在此处添加更多的映射关系 - }; - - // 映射[显示样式值]->[枚举值]的关系 - const std::unordered_map ReverseThemeStyleMap = { - {THEMESTYLE_VALUE_LIST, ThemeStyle::APPLIST_STYLE}, - {THEMESTYLE_VALUE_HEXAGONS, ThemeStyle::HEXAGONS_STYLE}, - {THEMESTYLE_VALUE_FOOTBALL, ThemeStyle::FOOTBALL_STYLE}, - {THEMESTYLE_VALUE_WATERFALL, ThemeStyle::WATERFALL_STYLE}, - {THEMESTYLE_VALUE_ARC_SCALE_LIST, ThemeStyle::ARC_SCALE_LIST_STYLE}, - {THEMESTYLE_VALUE_CIRCLE_LIST, ThemeStyle::CIRCLE_LIST_STYLE}, - // 在此处添加更多的映射关系 - }; - class ThemeStyleModel { public: diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/include/ThemeStyleView.h b/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/include/ThemeStyleView.h index 4f29e0dcc..27db28f3b 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/include/ThemeStyleView.h +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/include/ThemeStyleView.h @@ -21,24 +21,13 @@ #include "ChangeSliceListener.h" #include "UiConfig.h" #include "themestyle/include/ThemeStyleModel.h" +#include "themestyle/include/ThemeStyleCatalog.h" namespace OHOS { - static constexpr const uint16_t MAX_STYLE = MAX_THEME_STYLE - 3; //直线列表和足球不显示所以删除了两个 - static constexpr char *THEME_STYLE_LIST = "themestyleList"; // 列表 - static constexpr char *THEME_STYLE_HEXAGONS = "themestyleHexagons"; // 蜂窝 - static constexpr char *THEME_STYLE_FOOTBALL = "themestyleFootball"; // 足球 - static constexpr char *THEME_STYLE_WATERFALL = "themestyleWaterFall"; // 瀑布流 - static constexpr char *THEME_STYLE_ARC_LIST = "themestyleArcList"; // 弧形列表 - static constexpr char *THEME_STYLE_CIRCLE_LIST = "themestyleCircleList"; // 拨号盘 - static constexpr char *THEMESTYLEVIEWEXIT = "ThemeStyleViewExit"; // exit - - static constexpr char *THEMESTYLE_LIST_IMAGEPATH = "/user/res/themestyle/list.bin"; - static constexpr char *THEMESTYLE_HEXAGONS_IMAGEPATH = "/user/res/themestyle/hexagons.bin"; - static constexpr char *THEMESTYLE_FOOTBALL_IMAGEPATH = "/user/res/themestyle/grid.bin"; - static constexpr char *THEMESTYLE_WATERFALL_IMAGEPATH = "/user/res/themestyle/grid.bin"; - static constexpr char *THEMESTYLE_ARCLIST_IMAGEPATH = "/user/res/themestyle/arclist.bin"; - static constexpr char *THEMESTYLE_CIRCLELIST_IMAGEPATH = "/user/res/themestyle/dialplate.bin"; + /** Max UI slots for style rows; actual row count comes from ThemeStyleCatalog. */ + static constexpr const uint16_t MAX_STYLE = THEME_STYLE_SETTINGS_UI_CAPACITY; + static constexpr char *THEMESTYLEVIEWEXIT = "ThemeStyleViewExit"; // exit class ThemeStylePresenter; class ThemeStyleView : public View diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/include/readme.txt b/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/include/readme.txt new file mode 100644 index 000000000..e87df938f --- /dev/null +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/include/readme.txt @@ -0,0 +1,87 @@ +## 思路 + +把「设置页每一行」和「能写进配置里的所有样式」收成**两张表,只在一个 `.cpp` 里维护**,其它地方只调查询函数。这样加/删 `STR_*` 对应的展示项时,主要改 **`ThemeStyleCatalog.cpp`**,不必再在 `ThemeStyleView` / `ThemeStylePresenter` / `ThemeStyleModel` / 下拉卡片里各抄一遍数组和 `if-else`。 + +## 已实现内容 + +1. **`ThemeStyleCatalog.h` / `ThemeStyleCatalog.cpp`(新建)** + - **`kThemeStyleSettingsRows[]`**:设置页顺序 = `ThemeStyle` + 持久化键 + 按钮 `viewId` + 标题 `textId` + 预览图路径 + 是否参与下拉条循环(`dropdownCycleOrder` 或 `0xFF`)。 + - **`kThemeStylePersistPairs[]`**:所有可持久化的 `ThemeStyle` ↔ 配置字符串(原先 `ThemeStyleMap` / `ReverseThemeStyleMap` 两份表合并为一份数据源)。 + - 对外提供:`GetThemeStyleSettingsRowCount` / `GetThemeStyleSettingsRow`、`GetPersistStringForThemeStyle`、`GetThemeStyleFromPersistString`、`GetThemeStyleSettingsHighlightIndex`、`FindThemeStyleSettingsRowIndexByViewId`,以及下拉条用的 `GetThemeStyleDropdownImageIndex` / `GetThemeStyleDropdownNextStyle` / `GetThemeStyleDropdownImagePathByCycleOrder`。 + +2. **`ThemeStyleModel.h/.cpp`** + 去掉 `ThemeStyleMap` / `ReverseThemeStyleMap`,读写配置改为调用上面的持久化接口。 + +3. **`ThemeStyleView.h/.cpp`** + 用目录表驱动标签、按钮、`viewId`、预览图循环;`UpdateSelectedStyle` 用 `GetThemeStyleSettingsHighlightIndex`;`ClearAll` 按实际行数释放。 + `MAX_STYLE` 改为 **`THEME_STYLE_SETTINGS_UI_CAPACITY`**(在 `ThemeStyleCatalog.h` 里默认 8,行数变多时再改这一处上限即可)。 + +4. **`ThemeStylePresenter.cpp`** + 点击用 `FindThemeStyleSettingsRowIndexByViewId` + `GetThemeStyleSettingsRow`,不再写一长串 `viewId == THEME_STYLE_*`。 + +5. **`DropDownCardPage2.cpp`** + 图标与切换顺序从目录里的 `dropdownCycleOrder` 与同一套预览路径推导,去掉本地写死的三个路径数组。 + +`nativeui/*.cpp` 是 **GLOB** 编进来的,新文件会自动参与编译。 + +--- + +## 你以后怎么加 / 删一条(例如新文案 ID) + +**仍要做的(和原来一样,无法完全省掉):** +- 在 **`ui_resource_string.h` / 语言包**里加 `STR_*`; +- 若有**新 `ThemeStyle` 枚举**,在 **`ThemeStyleModel.h`** 里加枚举和 `THEMESTYLE_VALUE_*` 常量; +- 准备 **`/user/res/themestyle/*.bin`** 等资源。 + +**集中在一处维护的:** 编辑 **`ThemeStyleCatalog.cpp`**: +- 在 **`kThemeStylePersistPairs`** 里增删一行(否则存盘/读盘不认); +- 若要在「显示方式」里展示:在 **`kThemeStyleSettingsRows`** 里增删一行(顺序即 UI 顺序); +- 若要进**下拉快捷循环**:把该行的 `dropdownCycleOrder` 设为 `0,1,2,...`,不要参与则保持 **`ThemeStyleSettingsRow::kNotInDropdownCycle`**; +- 若设置项超过 8 个:把 **`ThemeStyleCatalog.h`** 里的 **`THEME_STYLE_SETTINGS_UI_CAPACITY`** 调大(`static_assert` 会防止忘了改)。 + +字符串 ID、预览图、`viewId` 只在这一张「设置行」表里对齐一次即可,不必再在 Presenter / View 里同步改多份数组或分支。 + +可以,给你一个**最实用的例子**: +假设你要新增一个样式 **`RING_DISPLAY`**(文案 `STR_RING_DISPLAY`,配置值 `"ring"`,图标 `"/user/res/themestyle/ring.bin"`),并且它要出现在设置页,但**不参与下拉快捷循环**。 + +你现在主要改这几处: + +- 在 `ThemeStyleModel.h` 增加: + - `THEMESTYLE_VALUE_RING = "ring"` + - `ThemeStyle` 枚举里加 `RING_STYLE` + +- 在资源里增加: + - `ui_resource_string.h` 的 `STR_RING_DISPLAY` + - 语言包里的对应多语言文案 + - 图资源 `ring.bin` + +- 然后只在 `ThemeStyleCatalog.cpp` 改两张表: + +```cpp +// 1) 持久化映射表:让配置可读写 +static const ThemeStylePersistPair kThemeStylePersistPairs[] = { + {ThemeStyle::APPLIST_STYLE, THEMESTYLE_VALUE_LIST}, + {ThemeStyle::HEXAGONS_STYLE, THEMESTYLE_VALUE_HEXAGONS}, + // ... + {ThemeStyle::RING_STYLE, THEMESTYLE_VALUE_RING}, // 新增 +}; + +// 2) 设置页展示表:让“显示方式”页面自动出现这一行 +static const ThemeStyleSettingsRow kThemeStyleSettingsRows[] = { + {ThemeStyle::APPLIST_STYLE, THEMESTYLE_VALUE_LIST, "themestyleList", STR_LIST_DISPLAY, + "/user/res/themestyle/list.bin", 0}, + // ... + {ThemeStyle::RING_STYLE, THEMESTYLE_VALUE_RING, "themestyleRing", STR_RING_DISPLAY, + "/user/res/themestyle/ring.bin", ThemeStyleSettingsRow::kNotInDropdownCycle}, // 新增 +}; +``` + +改完后: +- `ThemeStyleView` 会自动多一行(文本、按钮、图标都来自表) +- `ThemeStylePresenter` 会自动识别点击并设置 `RING_STYLE` +- `ThemeStyleModel` 会自动存取 `"ring"` +- 下拉快捷切换不会包含它(因为你给的是 `kNotInDropdownCycle`) + +--- + +如果你希望,我下一步可以直接按这个例子给你做一版“真实可编译的 `RING_STYLE` 补丁”(把 enum、字符串 ID、catalog 一次性补齐)。 \ No newline at end of file diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/src/ThemeStyleCatalog.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/src/ThemeStyleCatalog.cpp new file mode 100644 index 000000000..0bef192bd --- /dev/null +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/src/ThemeStyleCatalog.cpp @@ -0,0 +1,172 @@ +#include "themestyle/include/ThemeStyleCatalog.h" +#include "ui_resource_string.h" +#include + +namespace OHOS +{ +namespace +{ +/* Button view ids (must stay stable for saved UI / tests). */ +static constexpr const char *VIEW_ID_LIST = "themestyleList"; +static constexpr const char *VIEW_ID_HEXAGONS = "themestyleHexagons"; +static constexpr const char *VIEW_ID_ARC_LIST = "themestyleArcList"; +static constexpr const char *VIEW_ID_PLANET = "themestylePlanet"; + +static constexpr const char *IMG_LIST = "/user/res/themestyle/list.bin"; +static constexpr const char *IMG_HEXAGONS = "/user/res/themestyle/hexagons.bin"; +static constexpr const char *IMG_ARCLIST = "/user/res/themestyle/arclist.bin"; +static constexpr const char *IMG_DIALPLATE = "/user/res/themestyle/dialplate.bin"; + +/** Ordered rows on the “显示方式” settings page (label + checkbox + preview). */ +static const ThemeStyleSettingsRow kThemeStyleSettingsRows[] = { + {ThemeStyle::APPLIST_STYLE, THEMESTYLE_VALUE_LIST, VIEW_ID_LIST, STR_LIST_DISPLAY, IMG_LIST, 0}, + {ThemeStyle::ARC_SCALE_LIST_STYLE, THEMESTYLE_VALUE_ARC_SCALE_LIST, VIEW_ID_ARC_LIST, STR_ARC_SCALE_LIST_DISPLAY,IMG_ARCLIST, 1}, + {ThemeStyle::HEXAGONS_STYLE, THEMESTYLE_VALUE_HEXAGONS, VIEW_ID_HEXAGONS, STR_CELLULAR_DISPLAY, IMG_HEXAGONS, 2}, + {ThemeStyle::PLANET_STYLE, THEMESTYLE_VALUE_PLANET, VIEW_ID_PLANET, STR_GRID_DISPLAY, IMG_DIALPLATE, 3}, +}; + +struct ThemeStylePersistPair +{ + ThemeStyle style; + const char *value; +}; + +/** 所有可能存储在配置中的 ThemeStyle 值(设置页面可能仅显示其中一部分). */ +static const ThemeStylePersistPair kThemeStylePersistPairs[] = { + {ThemeStyle::APPLIST_STYLE, THEMESTYLE_VALUE_LIST}, + {ThemeStyle::HEXAGONS_STYLE, THEMESTYLE_VALUE_HEXAGONS}, + {ThemeStyle::FOOTBALL_STYLE, THEMESTYLE_VALUE_FOOTBALL}, + {ThemeStyle::WATERFALL_STYLE, THEMESTYLE_VALUE_WATERFALL}, + {ThemeStyle::ARC_SCALE_LIST_STYLE, THEMESTYLE_VALUE_ARC_SCALE_LIST}, + {ThemeStyle::CIRCLE_LIST_STYLE, THEMESTYLE_VALUE_CIRCLE_LIST}, + {ThemeStyle::PLANET_STYLE, THEMESTYLE_VALUE_PLANET}, +}; + +// 归一化 ThemeStyle 值,确保在下拉列表中显示一致 +static ThemeStyle NormalizeStyleForDropdown(ThemeStyle s) +{ + if (s == ThemeStyle::CIRCLE_LIST_STYLE || s == ThemeStyle::WATERFALL_STYLE) { + return ThemeStyle::APPLIST_STYLE; + } + if (s == ThemeStyle::FOOTBALL_STYLE) { + return ThemeStyle::APPLIST_STYLE; + } + return s; +} +} // namespace + +static_assert(sizeof(kThemeStyleSettingsRows) / sizeof(kThemeStyleSettingsRows[0]) <= THEME_STYLE_SETTINGS_UI_CAPACITY, + "Increase THEME_STYLE_SETTINGS_UI_CAPACITY in ThemeStyleCatalog.h"); + +size_t GetThemeStyleSettingsRowCount(void) +{ + return sizeof(kThemeStyleSettingsRows) / sizeof(kThemeStyleSettingsRows[0]); +} + +const ThemeStyleSettingsRow &GetThemeStyleSettingsRow(size_t index) +{ + return kThemeStyleSettingsRows[index]; +} + +const char *GetPersistStringForThemeStyle(ThemeStyle style) +{ + for (const auto &p : kThemeStylePersistPairs) { + if (p.style == style) { + return p.value; + } + } + return nullptr; +} + +ThemeStyle GetThemeStyleFromPersistString(const std::string &value) +{ + for (const auto &p : kThemeStylePersistPairs) { + if (value == p.value) { + return p.style; + } + } + return ThemeStyle::APPLIST_STYLE; +} + +int GetThemeStyleSettingsHighlightIndex(ThemeStyle current) +{ + const size_t n = sizeof(kThemeStyleSettingsRows) / sizeof(kThemeStyleSettingsRows[0]); + for (size_t i = 0; i < n; ++i) { + if (kThemeStyleSettingsRows[i].style == current) { + return static_cast(i); + } + } + if (current == ThemeStyle::CIRCLE_LIST_STYLE || current == ThemeStyle::WATERFALL_STYLE) { + return 0; + } + return 0; +} + +int FindThemeStyleSettingsRowIndexByViewId(const char *viewId) +{ + if (viewId == nullptr) { + return -1; + } + const size_t n = sizeof(kThemeStyleSettingsRows) / sizeof(kThemeStyleSettingsRows[0]); + for (size_t i = 0; i < n; ++i) { + if (strcmp(viewId, kThemeStyleSettingsRows[i].buttonViewId) == 0) { + return static_cast(i); + } + } + return -1; +} + +size_t GetThemeStyleDropdownCycleCount(void) +{ + size_t c = 0; + const size_t n = sizeof(kThemeStyleSettingsRows) / sizeof(kThemeStyleSettingsRows[0]); + for (size_t i = 0; i < n; ++i) { + if (kThemeStyleSettingsRows[i].dropdownCycleOrder != ThemeStyleSettingsRow::kNotInDropdownCycle) { + ++c; + } + } + return c; +} + +int GetThemeStyleDropdownImageIndex(ThemeStyle current) +{ + ThemeStyle norm = NormalizeStyleForDropdown(current); + const size_t n = sizeof(kThemeStyleSettingsRows) / sizeof(kThemeStyleSettingsRows[0]); + for (size_t i = 0; i < n; ++i) { + if (kThemeStyleSettingsRows[i].style == norm && + kThemeStyleSettingsRows[i].dropdownCycleOrder != ThemeStyleSettingsRow::kNotInDropdownCycle) { + return static_cast(kThemeStyleSettingsRows[i].dropdownCycleOrder); + } + } + return 0; +} + +ThemeStyle GetThemeStyleDropdownNextStyle(ThemeStyle current) +{ + ThemeStyle norm = NormalizeStyleForDropdown(current); + if (norm == ThemeStyle::APPLIST_STYLE) { + return ThemeStyle::ARC_SCALE_LIST_STYLE; + } + if (norm == ThemeStyle::ARC_SCALE_LIST_STYLE) { + return ThemeStyle::HEXAGONS_STYLE; + } + if (norm == ThemeStyle::HEXAGONS_STYLE) { + return ThemeStyle::PLANET_STYLE; + } + if (norm == ThemeStyle::PLANET_STYLE) { + return ThemeStyle::APPLIST_STYLE; + } + return ThemeStyle::APPLIST_STYLE; +} + +const char *GetThemeStyleDropdownImagePathByCycleOrder(size_t order) +{ + const size_t n = sizeof(kThemeStyleSettingsRows) / sizeof(kThemeStyleSettingsRows[0]); + for (size_t i = 0; i < n; ++i) { + if (kThemeStyleSettingsRows[i].dropdownCycleOrder == order) { + return kThemeStyleSettingsRows[i].previewImagePath; + } + } + return kThemeStyleSettingsRows[0].previewImagePath; +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/src/ThemeStyleModel.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/src/ThemeStyleModel.cpp index 4498c85c1..2c1a06bff 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/src/ThemeStyleModel.cpp +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/src/ThemeStyleModel.cpp @@ -13,6 +13,7 @@ */ #include "themestyle/include/ThemeStyleModel.h" +#include "themestyle/include/ThemeStyleCatalog.h" #include "kv_store.h" #include "securec.h" #include "wearable_log.h" @@ -37,17 +38,8 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThemeStyleModel::GetAppListDisplayStyle"); - // 检查是否存在对应的样式选项 - auto it = ReverseThemeStyleMap.find(OHOS::ConfigModel::GetInstance()->get_configData_string(OHOS::ConfigModel::CONFIGMODEL_ITEM_APPLIST_STYLE)); - if (it != ReverseThemeStyleMap.end()) - { - return it->second; - } - else - { - // 默认返回列表显示 - return ThemeStyle::APPLIST_STYLE; - } + return GetThemeStyleFromPersistString( + OHOS::ConfigModel::GetInstance()->get_configData_string(OHOS::ConfigModel::CONFIGMODEL_ITEM_APPLIST_STYLE)); } /// @brief 设置applist的显示样式 @@ -56,16 +48,11 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThemeStyleModel::SetAppListDisplayStyle,style = %d", style); - // 检查是否存在对应的样式选项 - if (ThemeStyleMap.find(style) != ThemeStyleMap.end()) - { - const char *value = ThemeStyleMap.at(style).c_str(); + const char *value = GetPersistStringForThemeStyle(style); + if (value != nullptr) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "value:%s", value); - // 根据映射设置显示样式值 OHOS::ConfigModel::GetInstance()->set_condigData_String(OHOS::ConfigModel::CONFIGMODEL_ITEM_APPLIST_STYLE, value); - } - else - { + } else { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetAppListDisplayStyle fail!!"); } } diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/src/ThemeStylePresenter.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/src/ThemeStylePresenter.cpp index 7a9d97860..51be00355 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/src/ThemeStylePresenter.cpp +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/src/ThemeStylePresenter.cpp @@ -8,6 +8,7 @@ #include "themestyle/include/ThemeStyleView.h" #include "themestyle/include/ThemeStyleModel.h" +#include "themestyle/include/ThemeStyleCatalog.h" #include "themestyle/include/ThemeStylePresenter.h" #include "common/key_code.h" #include @@ -64,33 +65,11 @@ namespace OHOS return true; } - if (viewId == THEME_STYLE_LIST) - { - ThemeStyleModel::GetInstance().SetAppListDisplayStyle(ThemeStyle::APPLIST_STYLE); - } - else if (viewId == THEME_STYLE_HEXAGONS) - { - ThemeStyleModel::GetInstance().SetAppListDisplayStyle(ThemeStyle::HEXAGONS_STYLE); - } - else if (viewId == THEME_STYLE_FOOTBALL) - { - ThemeStyleModel::GetInstance().SetAppListDisplayStyle(ThemeStyle::FOOTBALL_STYLE); - } - // 拨号盘和瀑布流已屏蔽,不再处理 - // else if (viewId == THEME_STYLE_WATERFALL) - // { - // ThemeStyleModel::GetInstance().SetAppListDisplayStyle(ThemeStyle::WATERFALL_STYLE); - // } - else if (viewId == THEME_STYLE_ARC_LIST) - { - ThemeStyleModel::GetInstance().SetAppListDisplayStyle(ThemeStyle::ARC_SCALE_LIST_STYLE); + int row = FindThemeStyleSettingsRowIndexByViewId(viewId.c_str()); + if (row >= 0) { + ThemeStyleModel::GetInstance().SetAppListDisplayStyle(GetThemeStyleSettingsRow(static_cast(row)).style); } - // 拨号盘和瀑布流已屏蔽,不再处理 - // else if (viewId == THEME_STYLE_CIRCLE_LIST) - // { - // ThemeStyleModel::GetInstance().SetAppListDisplayStyle(ThemeStyle::CIRCLE_LIST_STYLE); - // } - + /* -------------------------------------------------------------------------- */ view_->UpdateSelectedStyle(); /* -------------------------------------------------------------------------- */ diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/src/ThemeStyleView.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/src/ThemeStyleView.cpp index 17981edc7..1051dbb19 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/src/ThemeStyleView.cpp +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/themestyle/src/ThemeStyleView.cpp @@ -6,7 +6,6 @@ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/themestyle/src/ThemeStyleView.cpp */ -#include #include "themestyle/include/ThemeStyleView.h" #include "themestyle/include/ThemeStylePresenter.h" #include "ui_resource_string.h" @@ -38,8 +37,6 @@ namespace OHOS void ThemeStyleView::ClearAll(void) { - - if (initViewStatus) { if (scrollView != nullptr) @@ -50,7 +47,8 @@ namespace OHOS delete titleText; titleText = nullptr; } - for (int i = 0; i < MAX_STYLE; i++) + const int rowSlots = static_cast(GetThemeStyleSettingsRowCount()); + for (int i = 0; i < rowSlots; i++) { delete ThemeStyleLabelButton[i]; ThemeStyleLabelButton[i] = nullptr; @@ -180,9 +178,6 @@ namespace OHOS titleText->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); titleText->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); scrollView->Add(titleText); - /* -------------------------------------------------------------------------- */ - // int16_t textId[] = {STR_LIST_DISPLAY, STR_CELLULAR_DISPLAY, STR_ARC_SCALE_LIST_DISPLAY,STR_DIAL_PLATE}; - int16_t textId[] = {STR_LIST_DISPLAY,STR_ARC_SCALE_LIST_DISPLAY, STR_CELLULAR_DISPLAY}; LabelConfig labelConfig = { .left = 143, .top = 153, @@ -193,10 +188,11 @@ namespace OHOS .textId = 0, .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, }; - for (int16_t i = 0; i < sizeof(textId) / sizeof(textId[0]); i++) + const size_t rowCount = GetThemeStyleSettingsRowCount(); + for (size_t i = 0; i < rowCount; i++) { - labelConfig.top = 153 + 120 * i; - labelConfig.textId = textId[i]; + labelConfig.top = 153 + 120 * static_cast(i); + labelConfig.textId = GetThemeStyleSettingsRow(i).titleTextId; ThemeStyleLabel[i] = ThemeStyleLabelViewinit(labelConfig); if (ThemeStyleLabel[i] == nullptr) { @@ -231,15 +227,14 @@ namespace OHOS .top = 120, .width = 380, .height = 100, - .viewId = THEME_STYLE_LIST, + .viewId = GetThemeStyleSettingsRow(0).buttonViewId, }; - // const char *viewId[] = {THEME_STYLE_LIST, THEME_STYLE_HEXAGONS, THEME_STYLE_ARC_LIST,THEME_STYLE_CIRCLE_LIST}; - const char *viewId[] = {THEME_STYLE_LIST,THEME_STYLE_ARC_LIST, THEME_STYLE_HEXAGONS}; - for (int i = 0; i < sizeof(viewId) / sizeof(viewId[0]); i++) + const size_t rowCount = GetThemeStyleSettingsRowCount(); + for (size_t i = 0; i < rowCount; i++) { - labelbuttonconfig.top = 120 + 120 * i; - labelbuttonconfig.viewId = viewId[i]; + labelbuttonconfig.top = 120 + 120 * static_cast(i); + labelbuttonconfig.viewId = GetThemeStyleSettingsRow(i).buttonViewId; ThemeStyleLabelButton[i] = ThemeStyleLabelButtonViewInit(labelbuttonconfig); if (ThemeStyleLabelButton[i] == nullptr) { @@ -273,15 +268,14 @@ namespace OHOS .y = 150, .w = 40, .h = 40, - .src = THEMESTYLE_LIST_IMAGEPATH, + .src = GetThemeStyleSettingsRow(0).previewImagePath, }; int y = 150; - // const char *src[MAX_STYLE] = {THEMESTYLE_LIST_IMAGEPATH, THEMESTYLE_HEXAGONS_IMAGEPATH, THEMESTYLE_ARCLIST_IMAGEPATH,THEMESTYLE_CIRCLELIST_IMAGEPATH}; - const char *src[] = {THEMESTYLE_LIST_IMAGEPATH,THEMESTYLE_ARCLIST_IMAGEPATH, THEMESTYLE_HEXAGONS_IMAGEPATH}; - for (int i = 0; i < sizeof(src) / sizeof(src[0]); i++) + const size_t rowCount = GetThemeStyleSettingsRowCount(); + for (size_t i = 0; i < rowCount; i++) { - imageconfig.y = y + 120 * i; - imageconfig.src = src[i]; + imageconfig.y = y + 120 * static_cast(i); + imageconfig.src = GetThemeStyleSettingsRow(i).previewImagePath; ThemeStyleImage[i] = ThemeStyleImageViewInit(imageconfig); if (ThemeStyleImage[i] == nullptr) { @@ -339,25 +333,9 @@ namespace OHOS void ThemeStyleView::UpdateSelectedStyle(void) { ThemeStyle style = ThemeStyleModel::GetInstance().GetAppListDisplayStyle(); - int index = 0; - if (style == ThemeStyle::APPLIST_STYLE) - { - index = 0; - } - else if (style == ThemeStyle::ARC_SCALE_LIST_STYLE) - { - index = 1; - } - else if (style == ThemeStyle::HEXAGONS_STYLE) - { - index = 2; - } - // 如果当前是拨号盘或瀑布流,显示为列表样式 - else if (style == ThemeStyle::CIRCLE_LIST_STYLE || style == ThemeStyle::WATERFALL_STYLE) - { - index = 0; - } - for (int i = 0; i < MAX_STYLE; i++) + int index = GetThemeStyleSettingsHighlightIndex(style); + const int rowCount = static_cast(GetThemeStyleSettingsRowCount()); + for (int i = 0; i < rowCount; i++) { if (i == index) { -- 2.17.1