From 944557023b71a8d4e4ea016baeac2d8ec8334f6a Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Sat, 25 Apr 2026 10:07:19 +0800 Subject: [PATCH] =?utf8?q?=20applist1201patch=E8=9C=82=E7=AA=9D=E6=A0=B7?= =?utf8?q?=E5=BC=8F=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/applist/include/ApplistModel.h | 4 + .../applist/include/HexagonsDesktopFragment.h | 80 ++--- .../nativeui/applist/src/ApplistView.cpp | 1 - .../src/ArcScaleListDesktopFragment.cpp | 4 +- .../applist/src/HexagonsDesktopFragment.cpp | 278 +++++++++--------- .../applist/src/ListDesktopFragment.cpp | 2 +- 6 files changed, 186 insertions(+), 183 deletions(-) diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/include/ApplistModel.h b/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/include/ApplistModel.h index 2459fc40b..539b61cba 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/include/ApplistModel.h +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/include/ApplistModel.h @@ -26,6 +26,10 @@ struct AppItem { const char *label = nullptr; const char *uid = nullptr; uint16_t labelId = STR_MAX_ID; + uint32_t resId = 0x0; // 小图标压缩资源对应的id + uint32_t hexagonId = 0x0; // 六边形图标压缩资源对应的id + const char *resPath = nullptr; // 小图标压缩资源路径 + const char *hexagonPath = nullptr; // 六边形图标压缩资源路径 AppItem() = default; AppItem(uint16_t id, const char *iconLarge,const char *iconHexagon, const char *label, const char *uid) : diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/include/HexagonsDesktopFragment.h b/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/include/HexagonsDesktopFragment.h index fb24447fb..fded07dcc 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/include/HexagonsDesktopFragment.h +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/include/HexagonsDesktopFragment.h @@ -1,47 +1,47 @@ -// /* -// * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. -// * Description: HexagonsDesktopFragment.h -// * Author: -// * Create: 2025-07-04 -// */ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: HexagonsDesktopFragment.h + * Author: + * Create: 2025-07-04 + */ -// #ifndef HEXAGONS_DESKTOP_FRAGMENT_H -// #define HEXAGONS_DESKTOP_FRAGMENT_H +#ifndef HEXAGONS_DESKTOP_FRAGMENT_H +#define HEXAGONS_DESKTOP_FRAGMENT_H -// #include "UIDesktopFragment.h" -// #include "components/ui_custom_hexagons_list.h" +#include "UIDesktopFragment.h" +#include "components/ui_custom_hexagons_list.h" -// namespace OHOS { -// class HexagonsItemView; -// class HexagonsDesktopFragment : public UIDesktopFragment { -// public: -// bool OnClick(UIView &view, const ClickEvent &event) override; -// bool OnRotate(UIView& view, const RotateEvent& event) override; -// void AddAppItemToList(const AppItem &item) override; -// void ClearAppItemToList() override; -// void RefreshAppList() override; +namespace OHOS { +class HexagonsItemView; +class HexagonsDesktopFragment : public UIDesktopFragment { +public: + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnRotate(UIView& view, const RotateEvent& event) override; + void AddAppItemToList(const AppItem &item) override; + void ClearAppItemToList() override; + void RefreshAppList() override; -// protected: -// void OnCreateView(void* data) override; -// void OnDestroyView() override; +protected: + void OnCreateView(void* data) override; + void OnDestroyView() override; -// private: -// UICustomHexagonsList* hexagonsList_{nullptr}; -// List listHexagonsView_; -// }; +private: + UICustomHexagonsList* hexagonsList_{nullptr}; + List listHexagonsView_; +}; -// class HexagonsItemView : public UIImageView { -// public: -// explicit HexagonsItemView() {}; -// ~HexagonsItemView(); -// bool SetItemInfo(const AppItem &itemInfo); -// AppViewId GetViewId(); -// const char *GetAppUid(); -// private: -// HexagonsItemView(const HexagonsItemView &); -// HexagonsItemView &operator = (const HexagonsItemView &); -// AppItem itemInfo_; -// }; -// } +class HexagonsItemView : public UIImageView { +public: + explicit HexagonsItemView() {}; + ~HexagonsItemView(); + bool SetItemInfo(const AppItem &itemInfo); + AppViewId GetViewId(); + const char *GetAppUid(); +private: + HexagonsItemView(const HexagonsItemView &); + HexagonsItemView &operator = (const HexagonsItemView &); + AppItem itemInfo_; +}; +} -// #endif // HEXAGONS_DESKTOP_FRAGMENT_H +#endif // HEXAGONS_DESKTOP_FRAGMENT_H diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/ApplistView.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/ApplistView.cpp index 7bac38779..b888e4272 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/ApplistView.cpp +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/ApplistView.cpp @@ -19,7 +19,6 @@ void ApplistView::OnStart() OnStop(); } ThemeStyle style = ThemeStyleModel::GetInstance().GetAppListDisplayStyle(); //根据显示样式界面设置的返回当前applit样式 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistView::OnStart,style = %d", style); desktopFragment_ = DesktopFactory::GetInstance().CreateDesktopStyle(style); desktopFragment_->SetPosition(0, 0, GetRootContainer()->GetWidth(), GetRootContainer()->GetHeight()); desktopFragment_->CreateView(); diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/ArcScaleListDesktopFragment.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/ArcScaleListDesktopFragment.cpp index 02d9402d2..1282029e9 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/ArcScaleListDesktopFragment.cpp +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/ArcScaleListDesktopFragment.cpp @@ -74,7 +74,7 @@ static bool TransformItemBaseOnPosition(UITransformList* list, UIView* item) void ArcScaleListDesktopFragment::OnCreateView(void* data) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ArcScaleListDesktopFragment::OnCreateView"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ArcScaleListDesktopFragment::OnCreateView:弧形列表"); if(nullptr == ArcScaleListAdapter_) { ArcScaleListAdapter_ = new ArcScaleListItemAdapter(); @@ -126,7 +126,7 @@ void ArcScaleListDesktopFragment::OnCreateView(void* data) void ArcScaleListDesktopFragment::OnDestroyView() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ArcScaleListDesktopFragment::OnDestroyView"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ArcScaleListDesktopFragment::OnDestroyView"); int16_t arclistHeadY = ArcScaleList_->GetChildrenHead()->GetY(); int16_t arclistHeadIndex = ArcScaleList_->GetChildrenHead()->GetViewIndex(); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[%d],listHeadY = %d,listHeadIndex = %d", __LINE__,arclistHeadY,arclistHeadIndex); diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/HexagonsDesktopFragment.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/HexagonsDesktopFragment.cpp index 516b5b96e..51ada6642 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/HexagonsDesktopFragment.cpp +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/HexagonsDesktopFragment.cpp @@ -1,153 +1,153 @@ -// /* -// * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. -// * Description: HexagonsDesktopFragment.cpp -// * Author: -// * Create: 2025-07-04 -// */ +/* + * Copyright (c) CompanyNameMagicTag 2025-2025. All rights reserved. + * Description: HexagonsDesktopFragment.cpp + * Author: + * Create: 2025-07-04 + */ -// #include "applist/include/HexagonsDesktopFragment.h" -// #include "applist/include/DesktopFactory.h" -// #include "common/image_cache_manager.h" -// #include "NativeAbility.h" +#include "applist/include/HexagonsDesktopFragment.h" +#include "applist/include/DesktopFactory.h" +#include "common/image_cache_manager.h" +#include "NativeAbility.h" -// namespace OHOS { -// REGIST_DESKTOP_STYLE(HEXAGONS_STYLE, HexagonsDesktopFragment); +namespace OHOS { +REGIST_DESKTOP_STYLE(HEXAGONS_STYLE, HexagonsDesktopFragment); -// void HexagonsDesktopFragment::OnCreateView(void* data) -// { -// WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HexagonsDesktopFragment::OnCreateView "); -// if (hexagonsList_ == nullptr) { -// hexagonsList_ = new UICustomHexagonsList(); -// } -// hexagonsList_->SetPosition(0, 0, fragmentView_.GetWidth(), fragmentView_.GetHeight()); // 2, two -// imgDistance_ = hexagonsList_->GetWidth() * 0.25991; // 0.25991, empirical coefficient -// imgSize_ = hexagonsList_->GetWidth() * 0.23348; // 0.23348, empirical coefficient -// hexagonsList_->SetImageDistance(imgDistance_); -// hexagonsList_->SetImageSizeInCenter(imgSize_); -// int16_t blankSize = hexagonsList_->GetRelativeRect().GetWidth() > hexagonsList_->GetRelativeRect().GetHeight() ? -// hexagonsList_->GetRelativeRect().GetWidth() / 2 : hexagonsList_->GetRelativeRect().GetHeight() / 2; // 2, half -// hexagonsList_->SetScrollBlankSize(blankSize); -// hexagonsList_->SetReboundSize(blankSize); -// hexagonsList_->SetThrowDrag(true); -// hexagonsList_->SetOnRotateListener(this); -// hexagonsList_->RequestFocus(); -// fragmentView_.Add(hexagonsList_); -// } +void HexagonsDesktopFragment::OnCreateView(void* data) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HexagonsDesktopFragment::OnCreateView:蜂窝列表"); + if (hexagonsList_ == nullptr) { + hexagonsList_ = new UICustomHexagonsList(); + } + hexagonsList_->SetPosition(0, 0, fragmentView_.GetWidth(), fragmentView_.GetHeight()); // 2, two + imgDistance_ = hexagonsList_->GetWidth() * 0.25991; // 0.25991, empirical coefficient + imgSize_ = hexagonsList_->GetWidth() * 0.23348; // 0.23348, empirical coefficient + hexagonsList_->SetImageDistance(imgDistance_); + hexagonsList_->SetImageSizeInCenter(imgSize_); + int16_t blankSize = hexagonsList_->GetRelativeRect().GetWidth() > hexagonsList_->GetRelativeRect().GetHeight() ? + hexagonsList_->GetRelativeRect().GetWidth() / 2 : hexagonsList_->GetRelativeRect().GetHeight() / 2; // 2, half + hexagonsList_->SetScrollBlankSize(blankSize); + hexagonsList_->SetReboundSize(blankSize); + hexagonsList_->SetThrowDrag(true); + hexagonsList_->SetOnRotateListener(this); + hexagonsList_->RequestFocus(); + fragmentView_.Add(hexagonsList_); +} -// void HexagonsDesktopFragment::OnDestroyView() -// { -// WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HexagonsDesktopFragment::OnDestroyView"); -// ClearAppItemToList(); -// if (hexagonsList_ != nullptr) { -// delete hexagonsList_; -// hexagonsList_ = nullptr; -// } -// } +void HexagonsDesktopFragment::OnDestroyView() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HexagonsDesktopFragment::OnDestroyView"); + ClearAppItemToList(); + if (hexagonsList_ != nullptr) { + delete hexagonsList_; + hexagonsList_ = nullptr; + } +} -// bool HexagonsDesktopFragment::OnRotate(UIView& view, const RotateEvent& event) -// { -// UICustomHexagonsList* hexagonsView = dynamic_cast(&view); -// if (hexagonsView == nullptr) { -// return false; -// } -// int8_t index = hexagonsView->GetFocusedImgIndex(); -// uint8_t focusIndex_ = 0; -// if (index >= 0) { -// focusIndex_ = static_cast(index); -// } -// HexagonsItemView *itemView = dynamic_cast(hexagonsView->GetViewByIndex(focusIndex_)); -// AppViewId viewId = itemView->GetViewId(); -// if (FloatMore(hexagonsView->GetGlobalScale(), 2.0f)) { // 2.0 threshold for beginning transition -// hexagonsView->StopRotateAnimator(); -// NativeAbility::GetInstance().ChangeSlice(viewId, TransitionType::TRANSITION_HEXAGONS); -// hexagonsView->ClearFocus(); -// } -// return true; -// } +bool HexagonsDesktopFragment::OnRotate(UIView& view, const RotateEvent& event) +{ + UICustomHexagonsList* hexagonsView = dynamic_cast(&view); + if (hexagonsView == nullptr) { + return false; + } + int8_t index = hexagonsView->GetFocusedImgIndex(); + uint8_t focusIndex_ = 0; + if (index >= 0) { + focusIndex_ = static_cast(index); + } + HexagonsItemView *itemView = dynamic_cast(hexagonsView->GetViewByIndex(focusIndex_)); + AppViewId viewId = itemView->GetViewId(); + if (FloatMore(hexagonsView->GetGlobalScale(), 2.0f)) { // 2.0 threshold for beginning transition + hexagonsView->StopRotateAnimator(); + NativeAbility::GetInstance().EnterSlice(viewId, TransitionType::TRANSITION_HEXAGONS); + hexagonsView->ClearFocus(); + } + return true; +} -// bool HexagonsDesktopFragment::OnClick(UIView &view, const ClickEvent &event) -// { -// UNUSED(event); -// HexagonsItemView *itemView = dynamic_cast(&view); -// UIHexagonsList *hexagonsView = dynamic_cast(itemView->GetParent()); -// if (hexagonsView == nullptr || itemView == nullptr) { -// WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hexagonsView or itemView is nullptr"); -// return false; -// } -// AppViewId viewId = itemView->GetViewId(); -// char *uid = (char *)itemView->GetAppUid(); -// hexagonsView->SetDraggable(false); -// hexagonsView->Scale(1.0f, itemView->GetViewIndex()); // switch focus to click view +bool HexagonsDesktopFragment::OnClick(UIView &view, const ClickEvent &event) +{ + UNUSED(event); + HexagonsItemView *itemView = dynamic_cast(&view); + UIHexagonsList *hexagonsView = dynamic_cast(itemView->GetParent()); + if (hexagonsView == nullptr || itemView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hexagonsView or itemView is nullptr"); + return false; + } + AppViewId viewId = itemView->GetViewId(); + char *uid = (char *)itemView->GetAppUid(); + hexagonsView->SetDraggable(false); + hexagonsView->Scale(1.0f, itemView->GetViewIndex()); // switch focus to click view -// WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WaterfallDesktopFragment::OnClick viewid = %d", viewId); -// return SwitchView(viewId, uid, TransitionType::TRANSITION_HEXAGONS, HEXAGONS_STYLE); -// } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WaterfallDesktopFragment::OnClick viewid = %d", viewId); + return SwitchView(viewId, uid, TransitionType::TRANSITION_HEXAGONS, HEXAGONS_STYLE); +} -// void HexagonsDesktopFragment::AddAppItemToList(const AppItem &item) -// { -// WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WaterfallDesktopFragment::AddAppItemToList"); -// HexagonsItemView *itemView = new HexagonsItemView(); -// if (!itemView->SetItemInfo(item)) { -// delete itemView; -// return; -// } -// itemView->SetTouchable(true); -// itemView->SetOnClickListener(this); -// hexagonsList_->Add(itemView); -// listHexagonsView_.PushBack(itemView); -// } +void HexagonsDesktopFragment::AddAppItemToList(const AppItem &item) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WaterfallDesktopFragment::AddAppItemToList"); + HexagonsItemView *itemView = new HexagonsItemView(); + if (!itemView->SetItemInfo(item)) { + delete itemView; + return; + } + itemView->SetTouchable(true); + itemView->SetOnClickListener(this); + hexagonsList_->Add(itemView); + listHexagonsView_.PushBack(itemView); +} -// void HexagonsDesktopFragment::ClearAppItemToList() -// { -// WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HexagonsDesktopFragment::ClearAppItemToList"); -// if (hexagonsList_ != nullptr) { -// hexagonsList_->RemoveAll(); -// } -// ListNode* viewNode = listHexagonsView_.Head(); -// while (viewNode != listHexagonsView_.End()) { -// delete(viewNode->data_); -// viewNode = viewNode->next_; -// } -// listHexagonsView_.Clear(); -// } +void HexagonsDesktopFragment::ClearAppItemToList() +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HexagonsDesktopFragment::ClearAppItemToList"); + if (hexagonsList_ != nullptr) { + hexagonsList_->RemoveAll(); + } + ListNode* viewNode = listHexagonsView_.Head(); + while (viewNode != listHexagonsView_.End()) { + delete(viewNode->data_); + viewNode = viewNode->next_; + } + listHexagonsView_.Clear(); +} -// void HexagonsDesktopFragment::RefreshAppList(void) -// { -// WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WaterfallDesktopFragment::RefreshAppList"); -// hexagonsList_->LayoutChildren(true); -// } +void HexagonsDesktopFragment::RefreshAppList(void) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WaterfallDesktopFragment::RefreshAppList"); + hexagonsList_->LayoutChildren(true); +} -// HexagonsItemView::~HexagonsItemView() -// { -// if (itemInfo_.iconSmall == nullptr && itemInfo_.resPath != nullptr) { -// ImageCacheManager::GetInstance().UnloadOneInMultiRes(itemInfo_.resId, itemInfo_.resPath); -// } -// } +HexagonsItemView::~HexagonsItemView() +{ + if (itemInfo_.iconSmall == nullptr && itemInfo_.resPath != nullptr) { + ImageCacheManager::GetInstance().UnloadOneInMultiRes(itemInfo_.resId, itemInfo_.resPath); + } +} -// bool HexagonsItemView::SetItemInfo(const AppItem &itemInfo) -// { -// itemInfo_ = itemInfo; -// if (itemInfo.iconSmall == nullptr && itemInfo.resPath != nullptr) { -// ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(itemInfo.resId, itemInfo.resPath); -// if (image == nullptr) { -// WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Load App Icon path %s Image %x fail", -// itemInfo.resId, itemInfo.resPath); -// return false; -// } -// SetSrc(image); -// } else { -// SetSrc(itemInfo.iconSmall); -// } -// return true; -// } +bool HexagonsItemView::SetItemInfo(const AppItem &itemInfo) +{ + itemInfo_ = itemInfo; + if (itemInfo.iconSmall == nullptr && itemInfo.resPath != nullptr) { + ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(itemInfo.resId, itemInfo.resPath); + if (image == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Load App Icon path %s Image %x fail", + itemInfo.resId, itemInfo.resPath); + return false; + } + SetSrc(image); + } else { + SetSrc(itemInfo.iconSmall); + } + return true; +} -// AppViewId HexagonsItemView::GetViewId() -// { -// return static_cast(itemInfo_.id); -// } +AppViewId HexagonsItemView::GetViewId() +{ + return static_cast(itemInfo_.id); +} -// const char *HexagonsItemView::GetAppUid() -// { -// return itemInfo_.uid; -// } -// } +const char *HexagonsItemView::GetAppUid() +{ + return itemInfo_.uid; +} +} diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/ListDesktopFragment.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/ListDesktopFragment.cpp index 18457b016..104b1fffc 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/ListDesktopFragment.cpp +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/applist/src/ListDesktopFragment.cpp @@ -17,7 +17,7 @@ static constexpr int16 MAX_SCROLL_DIS = 1000; void ListDesktopFragment::OnCreateView(void* data) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ListDesktopFragment::OnCreateView"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ListDesktopFragment::OnCreateView:直线列表"); listAdapter_ = new ApplistAdapter(); if (listAdapter_ == nullptr) { return; -- 2.17.1