From: luozheng <1732036298@qq.com> Date: Wed, 17 Jul 2024 07:36:07 +0000 (+0800) Subject: applist实现power键双击切换样式功能 X-Git-Tag: release_V1.2.70_20241020_135402~806 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=81b8263a1cb75b511611dfff1f3fd449b317749d;p=mirrors%2FFD230.git applist实现power键双击切换样式功能 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistView.h b/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistView.h index dc2e81e85..b5a238853 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistView.h @@ -119,6 +119,7 @@ private: void ListStyleOnStart(); void ListStyleOnSetUpView(); void ListStyleOnStop(); + UIViewGroup *listGroup{nullptr}; ApplistAdapter *listAdapter_{nullptr}; UIList *contentList_{nullptr}; UIView::OnDragListener *dragListener{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistView.cpp b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistView.cpp index fede9a3eb..fcb583b94 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistView.cpp @@ -6,11 +6,12 @@ */ #include "components/ui_view_group.h" -#include "ApplistView.h" +#include "applist/include/AppItemView.h" #include "ApplistPresenter.h" #include "AppItemView.h" #include "common/image_cache_manager.h" #include "hal_tick.h" +#include "themestyle/include/ThemeStyleModel.h" namespace OHOS { static constexpr int16 NUM_2 = 2; @@ -24,7 +25,12 @@ ApplistView::ApplistView() ApplistView::~ApplistView() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::~ApplistView "); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::~ApplistView start..."); + if(listGroup != nullptr) + { + delete listGroup; + listGroup = nullptr; + } if (listAdapter_ != nullptr) { delete listAdapter_; listAdapter_ = nullptr; @@ -46,11 +52,12 @@ ApplistView::~ApplistView() callback_ = nullptr; } enterAnimator_ = nullptr; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::~ApplistView end..."); } void ApplistView::OnStart() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnStart "); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnStart start..."); View::OnStart(); AppListStyle style = presenter_->GetCurrentStyle(); if (style == AppListStyle::FOOTBALL_STYLE) { @@ -60,6 +67,7 @@ void ApplistView::OnStart() } else { ListStyleOnStart(); } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnStart end..."); } //足球OnStart @@ -92,7 +100,7 @@ void ApplistView::FootballStyleOnStart() //蜂窝OnStart void ApplistView::HexagonsStyleOnStart() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::HexagonsStyleOnStart "); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::HexagonsStyleOnStart start..."); if (hexagonsList_ == nullptr) { hexagonsList_ = new UICustomHexagonsList(); } @@ -109,23 +117,33 @@ void ApplistView::HexagonsStyleOnStart() hexagonsList_->SetOnRotateListener(presenter_); hexagonsList_->RequestFocus(); SetContainerView(hexagonsList_); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::HexagonsStyleOnStart start..."); } //列表OnStart void ApplistView::ListStyleOnStart() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ListStyleOnStart"); - SetContainerView(new UIViewGroup()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ListStyleOnStart start..."); + if(listGroup == nullptr) { + listGroup = new UIViewGroup(); + if (listGroup == nullptr){ + return; + } + } + SetContainerView(listGroup); container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - listAdapter_ = new ApplistAdapter(); - if (listAdapter_ == nullptr) { - return; + if(listAdapter_== nullptr) { + listAdapter_ = new ApplistAdapter(); + if (listAdapter_ == nullptr){ + return; + } } listAdapter_->SetItemClickListener(presenter_); - - contentList_ = new UIList(UIList::VERTICAL); - if (contentList_ == nullptr) { - return; + if(contentList_ == nullptr) { + contentList_ = new UIList(UIList::VERTICAL); + if (contentList_ == nullptr){ + return; + } } contentList_->SetPosition(0, 0); contentList_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); @@ -146,6 +164,7 @@ void ApplistView::ListStyleOnStart() return; } contentList_->SetOnDragListener(dragListener); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ListStyleOnStart end..."); } void ApplistView::OnSetUpView() @@ -213,26 +232,37 @@ void ApplistView::OnTearDownView() void ApplistView::OnStop() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnStop"); - AppListStyle style = presenter_->GetCurrentStyle(); - if (style == AppListStyle::FOOTBALL_STYLE) { - FootballStyleOnStop(); - RootView::GetInstance()->ClearOnKeyActListener(); - } else if (style == AppListStyle::HEXAGONS_STYLE) { - HexagonsStyleOnStop(); - } else { - ListStyleOnStop(); - RootView::GetInstance()->ClearOnKeyActListener(); - } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnStop start..."); View::OnStop(); if (container_ != nullptr) { container_->RemoveAll(); - delete container_; container_ = nullptr; } - //RootView::GetInstance()->ClearOnKeyActListener(); - //FocusManager::GetInstance()->ClearFocus(); - return; + if(!ThemeStyleModel::GetInstance().GetTheSameSliceChangeFlag()) { + AppListStyle style = presenter_->GetCurrentStyle(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnStop GetPreApplistStyleFlag == false"); + if (style == AppListStyle::FOOTBALL_STYLE) { + FootballStyleOnStop();//足球 + RootView::GetInstance()->ClearOnKeyActListener(); + } else if (style == AppListStyle::HEXAGONS_STYLE) { + HexagonsStyleOnStop();//蜂窝 + } else { + ListStyleOnStop();//list + RootView::GetInstance()->ClearOnKeyActListener(); + } + } else { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnStop GetPreApplistStyleFlag == true"); + if(ThemeStyleModel::GetInstance().GetPreApplistStyle() == AppListStyle::HEXAGONS_STYLE) + { + HexagonsStyleOnStop(); + } + else if(ThemeStyleModel::GetInstance().GetPreApplistStyle() == AppListStyle::APPLIST_STYLE) + { + ListStyleOnStop(); + } + ThemeStyleModel::GetInstance().SetTheSameSliceChangeFlag(false); + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::OnStop end..."); } //足球OnStop @@ -260,7 +290,7 @@ void ApplistView::FootballStyleOnStop() //蜂窝OnStop void ApplistView::HexagonsStyleOnStop() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::HexagonsStyleOnStop"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::HexagonsStyleOnStop start..."); if (hexagonsList_ != nullptr) { hexagonsList_->RemoveAll(); } @@ -270,16 +300,21 @@ void ApplistView::HexagonsStyleOnStop() viewNode = viewNode->next_; } listHexagonsView_.Clear(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::HexagonsStyleOnStop end ..."); } //列表OnStop void ApplistView::ListStyleOnStop() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ListStyleOnStop"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ListStyleOnStop start..."); + if(listGroup != nullptr) { + listGroup->RemoveAll(); + } int16_t listHeadY = contentList_->GetChildrenHead()->GetY(); int16_t listHeadIndex = contentList_->GetChildrenHead()->GetViewIndex(); presenter_->SetHeadItemY(listHeadY); presenter_->SetStartIndex(listHeadIndex); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::ListStyleOnStop end..."); } void ApplistView::AddAppItemToList(const AppItem &item) diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootModel.cpp index e2cce7a99..b86bd43c5 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-28 11:50:42 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-12 11:40:13 + * @LastEditTime: 2024-07-17 15:29:21 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootModel.cpp */ @@ -103,15 +103,16 @@ namespace OHOS if (display_api->get_screen_state() == SCREEN_ON) { - // ThemeStyleModel &themeStyleModel = ThemeStyleModel::GetInstance(); - // ThemeStyle style = themeStyleModel.GetAppListDisplayStyle(); - // themeStyleModel.SwitchApplistStyleOnPowerClick(); // 切换样式 - // uint16_t sliceId = NativeAbility::GetInstance().GetCurSliceId(); - // if (sliceId == VIEW_APPLIST) - // { - // NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_ZOOM); - // } - NativeAbility::GetInstance().EnterSlice(VIEW_THEME_STYLE); + uint16_t cursliceId = NativeAbility::GetInstance().GetCurSliceId(); + if (cursliceId == VIEW_APPLIST) + { + ThemeStyleModel &themeStyleModel = ThemeStyleModel::GetInstance(); + ThemeStyle style = themeStyleModel.GetAppListDisplayStyle(); + themeStyleModel.SetPreApplistStyle(style); + themeStyleModel.SetTheSameSliceChangeFlag(true); + themeStyleModel.SwitchApplistStyleOnPowerClick(); // 切换样式 + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } } else { diff --git a/code/sdk/application/wearable/fd230app/nativeui/themestyle/include/ThemeStyleModel.h b/code/sdk/application/wearable/fd230app/nativeui/themestyle/include/ThemeStyleModel.h index 24581446c..9bc8fbbb3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/themestyle/include/ThemeStyleModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/themestyle/include/ThemeStyleModel.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-14 09:40:13 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-11 17:17:52 + * @LastEditTime: 2024-07-17 15:29:00 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/themestyle/include/ThemeStyleModel.h */ #ifndef SET_THEMESTYLE_MODEL_H @@ -53,12 +53,18 @@ namespace OHOS ThemeStyle GetAppListDisplayStyle(void); void SetAppListDisplayStyle(ThemeStyle style); void SwitchApplistStyleOnPowerClick(void); + void SetPreApplistStyle(ThemeStyle style); + ThemeStyle GetPreApplistStyle(void); + void SetTheSameSliceChangeFlag(bool state); + bool GetTheSameSliceChangeFlag(void); private: ThemeStyleModel(); virtual ~ThemeStyleModel(); ThemeStyleModel(const ThemeStyleModel &) = delete; ThemeStyleModel &operator=(const ThemeStyleModel &) = delete; + ThemeStyle preApplistStyle; //保存上一个applist的样式 + bool theSameSliceChangeFlag{false}; }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/themestyle/src/ThemeStyleModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/themestyle/src/ThemeStyleModel.cpp index db0801ce3..7ae3c1115 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/themestyle/src/ThemeStyleModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/themestyle/src/ThemeStyleModel.cpp @@ -8,7 +8,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-07 09:21:47 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-11 17:52:54 + * @LastEditTime: 2024-07-17 15:35:23 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/set_desktop/src/ThemeStyleModel.cpp */ @@ -101,4 +101,30 @@ namespace OHOS SetAppListDisplayStyle(static_cast(style)); return; } + + /*设置上一个applist的显示样式*/ + void ThemeStyleModel::SetPreApplistStyle(ThemeStyle style) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "preApplistStyle = %d", style); + preApplistStyle = style; + } + + /*获取上一个applist的显示样式*/ + ThemeStyle ThemeStyleModel::GetPreApplistStyle() + { + return preApplistStyle; + } + + /*设置是否是相同Slice切换*/ + void ThemeStyleModel::SetTheSameSliceChangeFlag(bool state) + { + theSameSliceChangeFlag = state; + } + + /*获取是否是相同Slice切换*/ + bool ThemeStyleModel::GetTheSameSliceChangeFlag(void) + { + return theSameSliceChangeFlag; + } + }