From 32d2e712fef521026dba131d4b218f612bea8491 Mon Sep 17 00:00:00 2001 From: Caisking Date: Mon, 28 Apr 2025 11:30:28 +0800 Subject: [PATCH] =?utf8?q?=E3=80=90=E8=AE=BE=E7=BD=AE=E3=80=91UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../settings/include/SettingAdapter.h | 74 ++--- .../nativeui/settings/include/SettingItem.h | 30 +- .../settings/include/SettingItemView.h | 54 ++-- .../nativeui/settings/include/SettingModel.h | 37 ++- .../settings/include/SettingPresenter.h | 58 ++-- .../nativeui/settings/include/SettingView.h | 51 ++-- .../nativeui/settings/src/SettingAdapter.cpp | 131 +++++---- .../nativeui/settings/src/SettingItemView.cpp | 157 +++++++--- .../nativeui/settings/src/SettingModel.cpp | 153 ++++++++-- .../settings/src/SettingPresenter.cpp | 163 ++++++++--- .../nativeui/settings/src/SettingView.cpp | 277 +++++++++++------- 11 files changed, 802 insertions(+), 383 deletions(-) diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingAdapter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingAdapter.h index d89fe3ee0..7efd6af1a 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingAdapter.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingAdapter.h @@ -12,6 +12,7 @@ #include #include "components/ui_list.h" #include "components/ui_label.h" +#include "components/ui_label_ext.h" #include "components/ui_view_group.h" #include "components/ui_image_view.h" #include "components/abstract_adapter.h" @@ -20,42 +21,45 @@ #include "SettingModel.h" #include "SettingItemView.h" -namespace OHOS { -class SettingAdapter : public AbstractAdapter { -public: - explicit SettingAdapter(); - ~SettingAdapter() override; - - /* * - * @brief Sets the UIView adapter data, which is a SettingItem linked list. - * - * @param data Indicates the SettingItem linked list data. - * @since 1.0 - * @version 1.0 - */ - void SetData(std::list &data); - - /* * - * @brief Obtains the data size of the UILabel adapter. - * - * @return Returns the data size of the UILabel adapter. - * @since 1.0 - * @version 1.0 - */ - uint16_t GetCount(void) override; - - UIView *GetView(UIView *inView, int16_t index) override; - - void AddListItem(const SettingItem &item); - - void SetItemClickListener(UIView::OnClickListener *itemclicklistener) +namespace OHOS +{ + class SettingAdapter : public AbstractAdapter { - itemClickListener = itemclicklistener; - } -private: - std::list listData; - UIView::OnClickListener *itemClickListener{nullptr}; -}; + public: + explicit SettingAdapter(); + ~SettingAdapter() override; + + /* * + * @brief Sets the UIView adapter data, which is a SettingItem linked list. + * + * @param data Indicates the SettingItem linked list data. + * @since 1.0 + * @version 1.0 + */ + void SetData(std::list &data); + + /* * + * @brief Obtains the data size of the UILabel adapter. + * + * @return Returns the data size of the UILabel adapter. + * @since 1.0 + * @version 1.0 + */ + uint16_t GetCount(void) override; + + UIView *GetView(UIView *inView, int16_t index) override; + + void AddListItem(const SettingItem &item); + + void SetItemClickListener(UIView::OnClickListener *itemclicklistener) + { + itemClickListener = itemclicklistener; + } + + private: + std::list listData; + UIView::OnClickListener *itemClickListener{nullptr}; + }; } #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingItem.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingItem.h index 0031350f1..48c7fc877 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingItem.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingItem.h @@ -1,22 +1,24 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingItem.h - * Author: - * Create: 2021-11-23 + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-23 18:09:12 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingItem.h */ - #ifndef SETTING_ITEM_H #define SETTING_ITEM_H #include - -namespace OHOS { -typedef struct { - AppViewId viewId; - const char *icon; - const char *label; - bool hasSecondMenu; - bool enableSlideBack; -} SettingItem; +#include +#include "ui_resource_string.h" +namespace OHOS +{ + typedef struct + { + AppViewId viewId; + const char *icon; + UIResourceTextId textId; + bool hasSecondMenu; + } SettingItem; } #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingItemView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingItemView.h index f045d1cbe..82e1797c1 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingItemView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingItemView.h @@ -1,3 +1,10 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-05-07 20:06:31 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingItemView.h + */ /* * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. * Description: SettingItemView.h @@ -8,32 +15,35 @@ #ifndef SETTING_ITEM_VIEW_H #define SETTING_ITEM_VIEW_H -#include "components/ui_label.h" #include "components/ui_view_group.h" -#include "components/ui_image_view.h" - #include "UiConfig.h" #include "SettingModel.h" - -namespace OHOS { -class SettingItemView : public UIViewGroup { -public: - explicit SettingItemView(); - ~SettingItemView() override; - virtual void SetItemInfo(const SettingItem itemInfo); - virtual void SetUpChild(); - bool SlideBackEnabled() const +#include "components/ui_label_button_ext.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +namespace OHOS +{ + class SettingItemView : public UIViewGroup { - return sItemInfo.enableSlideBack; - } - AppViewId GetViewId(); - const char* GetIconId(); -private: - UIImageView sIcon; - UILabel sLabel; - UIImageView sNextImage; - SettingItem sItemInfo = { VIEW_INVALID, nullptr, nullptr, false, false }; -}; + public: + explicit SettingItemView(); + ~SettingItemView() override; + virtual void SetItemInfo(const SettingItem itemInfo); + virtual void SetUpChild(); + AppViewId GetViewId(); + const char *GetIconId(); + UIImageView *GetNeedToUpdateImage(void); + + private: + UIImageView Icon; + UILabelExt settingLabelExt; + UILabelButtonExt settingLabelButtonExt; + SettingItem sItemInfo = {VIEW_INVALID, nullptr, STR_EXERCISE_GENERAL, false}; + /* -------------------------------------------------------------------------- */ + void NeedToUpdateImageinit(void); + UIImageView NeedToUpdateImage; // 提示需要系统更新的icon图片 + /* -------------------------------------------------------------------------- */ + }; } #endif diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingModel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingModel.h index 6a50ebfc8..c8a4cd819 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingModel.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingModel.h @@ -1,8 +1,9 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingModel.h - * Author: - * Create: 2021-11-23 + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-09-14 19:57:56 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingModel.h */ #ifndef SETTING_MODEL_H @@ -11,27 +12,43 @@ #include #include #include "AppViewIDs.h" +#include "components/ui_label_ext.h" #include "UiConfig.h" #include "SettingItem.h" #include "SettingPresenter.h" -namespace OHOS { - static const uint16_t SETTING_ITEM_COUNT = 10; - class SettingModel { +namespace OHOS +{ + static const uint16_t SETTING_ITEM_COUNT = 15; + class SettingModel + { public: static SettingModel &GetInstance(void); void InitSettingItem(); const SettingItem *GetSettinglistItems() const; uint8_t GetSettingListNum() const; + void SetStartIndex(uint16_t index); + uint16_t GetStartIndex(void); + void SetHeadItemY(int y); + int GetHeadItemY(void); + bool GetPhoneConnectStatus(void); + bool GetEarPhoneConnectStatus(void); bool GetBlueToothConnectStatus(void); + void UpdatePhoneConnectStatus(bool status); + void UpdateEarPhoneConnectStatus(bool status); void UpdateBlueToothConnectStatus(bool status); + private: SettingModel(); - SettingModel(const SettingModel &); - SettingModel &operator=(const SettingModel &); + SettingModel(const SettingModel &) = delete; + SettingModel &operator=(const SettingModel &) = delete; virtual ~SettingModel(); - SettingItem settings[SETTING_ITEM_COUNT] = { VIEW_INVALID, nullptr, nullptr, false }; + SettingItem settings[SETTING_ITEM_COUNT] = {VIEW_INVALID, nullptr, STR_EXERCISE_GENERAL, false}; int usedLen; + uint16_t startIndex{0}; + int headItemY{0}; + bool phoneConnectStatus{false}; + bool earphoneConnectStatus{false}; bool btConnectStatus{false}; }; } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingPresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingPresenter.h index 6edba6ab1..c29e368f0 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingPresenter.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingPresenter.h @@ -1,34 +1,48 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingPresenter.h - * Author: - * Create: 2021-11-23 + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-02-19 11:58:05 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-09-14 20:14:00 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingPresenter.h */ - #ifndef SETTING_PRESENTER_H #define SETTING_PRESENTER_H #include "Presenter.h" #include "components/ui_view.h" -#include "SettingAdapter.h" +#include "View.h" +namespace OHOS +{ + class SettingView; + class SettingModel; + class SettingPresenter : public Presenter, + public UIView::OnClickListener, + public RootView::OnKeyActListener, + public UIView::OnDragListener + { + public: + SettingPresenter(); + ~SettingPresenter() override; + static SettingPresenter *GetInstance(); + void SetStartIndex(uint16_t index); + uint16_t GetStartIndex(void); + void SetHeadItemY(int y); + int GetHeadItemY(void); + int GetListItemNum(); -namespace OHOS { -class SettingView; -class SettingModel; -class SettingAdapter; -class SettingPresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener { -public: - SettingPresenter(); - ~SettingPresenter() override; + void OnStart() override; + void OnResume() override; + void OnPause() override; + void OnStop() override; - void OnStart() override; - bool OnClick(UIView &view, const ClickEvent &event) override; - bool OnDrag(UIView& view, const DragEvent& event) override; -private: - SettingModel *settingModel; -}; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 + private: + SettingModel *settingModel; + bool X_DRAG_FLAG{false}; + }; } #endif // SETTING_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingView.h index f8936c6db..a1ef83847 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/include/SettingView.h @@ -1,10 +1,10 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingView.h - * Author: - * Create: 2021-11-23 + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-09-14 20:06:44 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingView.h */ - #ifndef SETTING_VIEW_H #define SETTING_VIEW_H @@ -12,24 +12,35 @@ #include "components/root_view.h" #include "components/ui_view_group.h" #include "components/ui_scroll_view.h" -#include "components/ui_label.h" +#include "components/ui_label_ext.h" #include "components/ui_list.h" +#include "window/window.h" + #include "SettingAdapter.h" #include "ChangeSliceListener.h" -namespace OHOS { -class SettingPresenter; -class SettingView : public View { -public: - SettingView(); - ~SettingView() override; +namespace OHOS +{ + class SettingPresenter; + class SettingView : public View + { + public: + SettingView(); + ~SettingView() override; + + void OnStart() override; + + void AddSettingItemToList(const SettingItem &item); - void OnStart() override; - void RefreshSettingsList(const SettingItem* item, uint8_t count); -private: - SettingAdapter *listAdapter{nullptr}; - UIScrollView *scrollView{nullptr}; - UIList *contentList{nullptr}; - UILabel *title{nullptr}; -}; + private: + void CreateSettingView(void); + void ClearAll(void); + void settingListOnSetUpView(void); + void settingListOnStop(void); + SettingAdapter *listAdapter{nullptr}; + UIScrollView *scrollView{nullptr}; + UIList *contentList{nullptr}; + UILabelExt *title{nullptr}; + bool viewInitStatus{false}; + }; } #endif // SETTING_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingAdapter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingAdapter.cpp index 3ffb62c85..73cb3088c 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingAdapter.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingAdapter.cpp @@ -1,68 +1,89 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingAdapter.cpp - * Author: - * Create: 2021-11-23 + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-10-02 15:33:51 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingAdapter.cpp */ - -#include "SettingAdapter.h" - -namespace OHOS { -SettingAdapter::SettingAdapter() {} - -SettingAdapter::~SettingAdapter() -{ - listData.clear(); -} - -uint16_t SettingAdapter::GetCount(void) +// #include "SettingAdapter.h" +#include "settings/include/SettingAdapter.h" +namespace OHOS { - return listData.size(); -} + SettingAdapter::SettingAdapter() {} -void SettingAdapter::SetData(std::list &data) -{ - if (!listData.empty()) { + SettingAdapter::~SettingAdapter() + { listData.clear(); } - std::list::iterator it; - for (it = data.begin(); it != data.end(); it++) { - listData.push_back(*it); - } -} -UIView *SettingAdapter::GetView(UIView *inView, int16_t index) -{ - if (listData.empty()) { - return nullptr; - } - if (index < 0) { - return nullptr; - } - size_t uindex = index; - if (uindex >= listData.size()) { - return nullptr; + uint16_t SettingAdapter::GetCount(void) + { + return listData.size(); } - std::list::iterator it = listData.begin(); - for (int i = 0; i < index; i++) { - it++; - } - SettingItem itemData = *it; - SettingItemView *item = nullptr; - if (inView == nullptr) { - item = new SettingItemView(); - } else { - item = static_cast(inView); + void SettingAdapter::SetData(std::list &data) + { + if (!listData.empty()) + { + listData.clear(); + } + std::list::iterator it; + for (it = data.begin(); it != data.end(); it++) + { + listData.push_back(*it); + } } - item->SetItemInfo(itemData); - item->SetOnClickListener(itemClickListener); - return item; -} + UIView *SettingAdapter::GetView(UIView *inView, int16_t index) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingAdapter::GetView:%d", index); + if (listData.empty()) + { + return nullptr; + } + if (index < 0) + { + return nullptr; + } + size_t uindex = index; + if (uindex >= listData.size()) + { + return nullptr; + } -void SettingAdapter::AddListItem(const SettingItem &item) -{ - listData.push_back(item); -} + std::list::iterator it = listData.begin(); + for (int i = 0; i < index; i++) + { + it++; + } + SettingItem itemData = *it; + SettingItemView *item = nullptr; + if (inView == nullptr) + { + item = new SettingItemView(); + } + else + { + item = static_cast(inView); + } + + item->SetItemInfo(itemData); + item->SetOnClickListener(itemClickListener); + // UIImageView *view = dynamic_cast(item->GetNeedToUpdateImage()); + // if (view != nullptr && index == 6) + // { + // item->GetNeedToUpdateImage()->SetVisible(true); + // } + // else + // { + // item->GetNeedToUpdateImage()->SetVisible(false); + // } + item->SetViewIndex(index); + return item; + } + + void SettingAdapter::AddListItem(const SettingItem &item) + { + listData.push_back(item); + } } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingItemView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingItemView.cpp index fed442ced..17580ce28 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingItemView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingItemView.cpp @@ -1,70 +1,121 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingItemView.cpp - * Author: - * Create: 2021-11-23 + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-27 19:48:49 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-10-02 15:34:50 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingItemView.cpp */ #include "wearable_log.h" -#include "SettingItemView.h" - -namespace OHOS { - static constexpr int16 SETTING_ICON_X = 20; - static constexpr int16 NUM_22 = 22; - static constexpr int16_t SETTING_ITEM_BUTTON_HEIGHT = 100; - static constexpr int16_t SETTING_ITEM_LABEL_WIDTH = 155; - static constexpr int16_t SETTING_ITEM_LABEL_HEIGHT = 100; - static constexpr int16 SETTING_ITEM_FONT_SIZE = 35; - static constexpr int16_t SETTINGS_RESIZE_SIZE = 100; - static constexpr int16_t SETTING_SICON_Y = 15; - static constexpr int16 NUMS_2 = 2; - static constexpr int16 NUMS_50 = 50; +#include "settings/include/SettingItemView.h" +#include "systemupdate/include/SystemUpdateModel.h" +namespace OHOS +{ + static constexpr int16_t SETTING_ICON_X = 19 + 43; + static constexpr int16_t SETTING_SICON_Y = 19; + static constexpr int16_t SETTING_SICON_W = 62; + static constexpr int16_t SETTING_SICON_H = 62; + + static constexpr int16_t SETTINGLABELEXT_X = 115 + 43; + static constexpr int16_t SETTINGLABELEXT_Y = 33; + static constexpr int16_t SETTINGLABELEXT_W = 180; + static constexpr int16_t SETTINGLABELEXT_H = 35; + static constexpr int16_t SETTINGLABELEXT_X2 = 83; + static constexpr int16_t SETTINGLABELEXT_Y2 = 50; + static constexpr int16_t SETTINGLABELEXT_W2 = 300; + static constexpr int16_t SETTINGLABELEXT_H2 = 35; + static constexpr int16_t SETTINGLABELEXT_TEXT_FONT = 30; + static constexpr int16_t SETTINGLABELEXT_LINE_HEIGHT = 35; + static constexpr int16_t SETTINGLABELEXT_ROLLSPEED = 70; + + static constexpr int16_t SETTINGLABELBUTTONEXT_X = 43; + static constexpr int16_t SETTINGLABELBUTTONEXT_Y = 0; + static constexpr int16_t SETTINGLABELBUTTONEXT_W = 380; + 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, 0, HORIZONTAL_RESOLUTION, SETTING_ITEM_BUTTON_HEIGHT); + SetPosition(43, 120, 466, 120); SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); - SetTouchable(true); SetUpChild(); - - Add(&sIcon); - Add(&sLabel); - Add(&sNextImage); + Add(&settingLabelButtonExt); + Add(&settingLabelExt); + Add(&Icon); } SettingItemView::~SettingItemView() { - Remove(&sIcon); - Remove(&sLabel); - Remove(&sNextImage); + RemoveAll(); } void SettingItemView::SetItemInfo(const SettingItem itemInfo) { sItemInfo = itemInfo; - sIcon.SetSrc(itemInfo.icon); - sLabel.SetText(itemInfo.label); - sNextImage.SetVisible(itemInfo.hasSecondMenu); + if (itemInfo.hasSecondMenu) + { + Icon.SetVisible(true); + Icon.SetSrc(itemInfo.icon); + settingLabelExt.SetVisible(true); + settingLabelExt.SetPosition(SETTINGLABELEXT_X, SETTINGLABELEXT_Y, SETTINGLABELEXT_W, SETTINGLABELEXT_H); + settingLabelExt.SetTextId(itemInfo.textId); + settingLabelExt.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + settingLabelButtonExt.SetVisible(true); + SetHeight(120); + SetTouchable(true); + } + else + { + + Icon.SetVisible(false); + if (itemInfo.viewId == VIEW_INVALID && itemInfo.textId == STR_MAX_ID) + { + settingLabelExt.SetVisible(false); + SetHeight(60); + } + else + { + settingLabelExt.SetVisible(true); + SetHeight(120); + } + settingLabelExt.SetPosition(SETTINGLABELEXT_X2, SETTINGLABELEXT_Y2, SETTINGLABELEXT_W2, SETTINGLABELEXT_H2); + settingLabelExt.SetTextId(itemInfo.textId); + settingLabelExt.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + settingLabelButtonExt.SetVisible(false); + SetTouchable(false); + } + + // if (itemInfo.textId == STR_SYSTEM && SystemUpdateModel::GetInstance().IsLatestVersion() == false) // 如果不是最新系统版本出现小圆点 + // { + // NeedToUpdateImageinit(); + // } } void SettingItemView::SetUpChild() { - sIcon.SetPosition(SETTING_ICON_X, SETTING_SICON_Y); - sIcon.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); - - sLabel.SetPosition(SETTING_ITEM_LABEL_WIDTH, 0); - sLabel.Resize(SETTING_ITEM_LABEL_WIDTH, SETTING_ITEM_LABEL_HEIGHT); - sLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTING_ITEM_FONT_SIZE); - sLabel.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - sLabel.SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - sLabel.SetStyle(STYLE_TEXT_COLOR, Color::White().full); - sLabel.SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - sLabel.SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); - - sNextImage.SetSrc(PNG_SETTING_NEXT_IMAGE); - sNextImage.SetPosition(LA_HORIZONTAL_RESOLUTION - NUMS_50, (SETTING_ITEM_HEIGHT - sNextImage.GetHeight()) / NUMS_2); - sNextImage.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + Icon.SetPosition(SETTING_ICON_X, SETTING_SICON_Y, SETTING_SICON_W, SETTING_SICON_H); + Icon.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + + settingLabelExt.SetPosition(SETTINGLABELEXT_X, SETTINGLABELEXT_Y, SETTINGLABELEXT_W, SETTINGLABELEXT_H); + settingLabelExt.SetStyle(STYLE_TEXT_FONT, SETTINGLABELEXT_TEXT_FONT); + settingLabelExt.SetStyle(STYLE_LINE_HEIGHT, SETTINGLABELEXT_LINE_HEIGHT); + settingLabelExt.SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + settingLabelExt.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + settingLabelExt.SetRollSpeed(SETTINGLABELEXT_ROLLSPEED); + settingLabelExt.SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTINGLABELEXT_TEXT_FONT); + + settingLabelButtonExt.SetPosition(SETTINGLABELBUTTONEXT_X, SETTINGLABELBUTTONEXT_Y, SETTINGLABELBUTTONEXT_W, SETTINGLABELBUTTONEXT_H); + settingLabelButtonExt.SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + settingLabelButtonExt.SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTINGLABELBUTTONEXT_TEXT_FONT); + settingLabelButtonExt.SetStyle(STYLE_LINE_HEIGHT, SETTINGLABELBUTTONEXT_LINE_HEIGHT); + settingLabelButtonExt.SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); + settingLabelButtonExt.SetAlign(TEXT_ALIGNMENT_LEFT); + settingLabelButtonExt.SetLabelPosition(115, 0); + settingLabelButtonExt.SetImagePosition(326, 37); + settingLabelButtonExt.SetTouchable(false); + settingLabelButtonExt.SetImageSrc(PNG_SETTING_NEXT_IMAGE, PNG_SETTING_NEXT_IMAGE); } AppViewId SettingItemView::GetViewId() @@ -72,8 +123,24 @@ namespace OHOS { return sItemInfo.viewId; } - const char* SettingItemView::GetIconId() + const char *SettingItemView::GetIconId() { return sItemInfo.icon; } + + void SettingItemView::NeedToUpdateImageinit(void) + { + NeedToUpdateImage.SetPosition(280, 40, 20, 20); + NeedToUpdateImage.SetStyle(STYLE_BORDER_RADIUS, 200); + char *imagesPath = "/user/res/system/SYSTEM_UPDATE_FLAG.bin"; + NeedToUpdateImage.SetSrc(imagesPath); + NeedToUpdateImage.SetVisible(false); + + Add(&NeedToUpdateImage); + } + + UIImageView *SettingItemView::GetNeedToUpdateImage(void) + { + return &NeedToUpdateImage; + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingModel.cpp index 3345274df..2ef68abe8 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingModel.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingModel.cpp @@ -1,14 +1,26 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingModel.cpp - * Author: - * Create: 2021-11-23 + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-02-18 09:09:13 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2025-01-18 12:26:57 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp */ +#include "settings/include/SettingModel.h" +#include "main/include/PullUpDownView.h" +#include "ui_resource_string.h" +#include "classicbluetooth/include/BluetoothServiceOptionsView.h" +#include "player/include/PlayersView.h" +#include "player/include/PlayersModel.h" +#include "PhoneService.h" +#include "phoneservice/include/PhoneService.h" +#include "BluetoothModel.h" +#include "player/include/MusicPlayerSourceView.h" +extern "C" { -#include "SettingModel.h" -#include "PullUpDownView.h" - -namespace OHOS { +#include "custom_runtime.h" +} +namespace OHOS +{ SettingModel::SettingModel() {} SettingModel::~SettingModel() {} @@ -22,18 +34,42 @@ namespace OHOS { void SettingModel::InitSettingItem() { int index = 0; - settings[index++] = {VIEW_BLUETOOTH_EARPHONE, PNG_BLUETOOTH_STITLE, "蓝牙耳机", true, false}; - settings[index++] = {VIEW_CONNECT_PHONE, PNG_CONNECT_PHONE_IMAGE, "连接手机", true, true}; - settings[index++] = {VIEW_REBOOT, PNG_SETTTING_REBOOT_IMAGE, "重启", true, true}; - settings[index++] = {VIEW_REBOOT, PNG_SETTTING_SHUTDOWN_IMAGE, "关机", true, true}; - settings[index++] = {VIEW_SET_DESKTOP, PNG_SETTTING_DESKTOP_IMAGE, "桌面", true, true}; - settings[index++] = {VIEW_SET_DIAL, PNG_SETTTING_DESKTOP_IMAGE, "表盘", true, false}; - settings[index++] = {VIEW_SET_CARD, PNG_SETTTING_DESKTOP_IMAGE, "卡片", true, false}; - settings[index++] = {VIEW_SET_DIAL_STYLE, PNG_SETTTING_DESKTOP_IMAGE, "表盘风格", true, true}; - settings[index++] = {VIEW_RESTORE_DEFAULTS, PNG_SETTTING_DESKTOP_IMAGE, "恢复出厂", true, true}; + settings[index++] = {VIEW_SETTING, nullptr, STR_SETTINGS, false};//标题:设置 + 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_THEME_STYLE, PNG_SETTINGS_DISPLAY_MODE, STR_DISPLAY_MODE, true}; + settings[index++] = {VIEW_MOTION_RECOGNITION, PNG_SETTINGS_MOTION_RECOGNITION, STR_MOTION_RECOGNITION, true}; + settings[index++] = {VIEW_DNOTDISTURB, PNG_SETTINGS_DISTURB_IMAGE, STR_DO_NOT_DISTURB, true}; + settings[index++] = {VIEW_ADD_CARD, PNG_SETTINGS_CARDSET_IMAGE, STR_CARD_MANAGEMENT, true}; + settings[index++] = {VIEW_SET_DIAL_STYLE, PNG_SETTINGS_CHANGEDIAL_IMAGE, STR_DIAL_BROWSING_SPECIAL_EFFECTS, true}; + settings[index++] = {VIEW_SAVEELE, PNG_SETTINGS_SAVEELE_IMAGE, STR_POWER_SAVE_MODE, true}; + settings[index++] = {VIEW_SYSTEM, PNG_SETTINGS_SYSTEM, STR_SYSTEM, true}; + settings[index++] = {VIEW_INVALID, nullptr, STR_MAX_ID, false}; usedLen = index; } + void SettingModel::SetStartIndex(uint16_t index) + { + startIndex = index; + } + + uint16_t SettingModel::GetStartIndex(void) + { + return startIndex; + } + + void SettingModel::SetHeadItemY(int y) + { + headItemY = y; + } + + int SettingModel::GetHeadItemY(void) + { + return headItemY; + } + const SettingItem *SettingModel::GetSettinglistItems() const { return settings; @@ -44,16 +80,93 @@ namespace OHOS { return usedLen; } + // 获取手机连接状态 + bool SettingModel::GetPhoneConnectStatus(void) + { + // return phoneConnectStatus; + return uapi_dev_runtime_get_ble_connect_stat(); + } + + // 获取蓝牙耳机连接状态 + bool SettingModel::GetEarPhoneConnectStatus(void) + { + return uapi_dev_runtime_get_earphone_connect_stat(); + } + + // 获取蓝牙连接状态 bool SettingModel::GetBlueToothConnectStatus(void) { + #if SUPPORT_BLE_SERVICE + if(!uapi_a2dp_snk_get_device_connect_state()&& !uapi_hfp_connect_state()) + { + btConnectStatus = false; + } + else + { + btConnectStatus = true; + } + #else + btConnectStatus = false; + #endif return btConnectStatus; } + // 更新手机连接状态 + void SettingModel::UpdatePhoneConnectStatus(bool status) + { + // phoneConnectStatus = status; + if (PullUpDownView::GetInstance() != nullptr) + { + PullUpDownView::GetInstance()->UpdatePhoneStatus(status); + } + //更新系统全局状态 + if (status) + uapi_dev_runtime_set_ble_connect_stat(1); + else + uapi_dev_runtime_set_ble_connect_stat(0); + + } + + // 更新耳机连接状态 + void SettingModel::UpdateEarPhoneConnectStatus(bool status) + { + earphoneConnectStatus = status; + if (PullUpDownView::GetInstance() != nullptr) + { + PullUpDownView::GetInstance()->UpdateEarPhoneStatus(status); + } + if (BluetoothServiceOptionsView::GetInstance()) + { + BluetoothServiceOptionsView::GetInstance()->Button_UPdata(); + } + if(MusicPlayerSourceView::GetInstance()) + { + MusicPlayerSourceView::GetInstance()->UpdateBluetoothHeadsetConnectLabel(); + } + } + + // 更新蓝牙连接状态 void SettingModel::UpdateBlueToothConnectStatus(bool status) { - btConnectStatus = status; - if (PullUpDownView::GetInstance() != nullptr) { - PullUpDownView::GetInstance()->UpdateBlueToothStatus(status); + // btConnectStatus = status; + if (PullUpDownView::GetInstance() != nullptr) + { + #if SUPPORT_BLE_SERVICE + if(!uapi_a2dp_snk_get_device_connect_state()&& !uapi_hfp_connect_state()) + PullUpDownView::GetInstance()->UpdateBlueToothStatus(false); + else + PullUpDownView::GetInstance()->UpdateBlueToothStatus(true); + #else + PullUpDownView::GetInstance()->UpdateBlueToothStatus(false); + #endif + } + if (BluetoothServiceOptionsView::GetInstance()) + { + BluetoothServiceOptionsView::GetInstance()->Button_UPdata(); + } + if (PlayersView::GetInstance()) + { + PlayersView::GetInstance()->UpdatePlayerView(); } } } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingPresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingPresenter.cpp index 16499b9f7..c4b2e6277 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingPresenter.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingPresenter.cpp @@ -1,56 +1,148 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-06-12 11:44:04 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-09-18 09:39:55 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp + */ /* * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. * Description: SettingPresenter.cpp * Author: * Create: 2021-11-23 */ - -#include "SettingView.h" -#include "SettingModel.h" -#include "SettingPresenter.h" -#include "RebootModel.h" -#include "SetDesktopModel.h" +#include "gfx_utils/mem_check.h" +#include "settings/include/SettingView.h" +#include "settings/include/SettingModel.h" +#include "settings/include/SettingPresenter.h" +#include "common/key_code.h" +#include #include "NativeRegisterManager.h" +namespace OHOS +{ -namespace OHOS { - -REGIST_MENU(VIEW_SETTING, SettingView, SettingPresenter, PNG_APPLIST_SETTING_IMAGE, PNG_APPLIST_DEFAULT_IMG, "设置"); - + REGIST_MENU_PRO(VIEW_SETTING, SettingView, SettingPresenter, + PNG_APPLIST_SETTING_IMAGE_BIG, PNG_APPLIST_SETTING_IMAGE,PNG_APPLIST_SETTING_IMAGE, "设置", STR_SETTINGS); + + static SettingPresenter *g_pSettingPresenter = nullptr; SettingPresenter::SettingPresenter() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::SettingPresenter()"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::SettingPresenter"); settingModel = &SettingModel::GetInstance(); + g_pSettingPresenter = this; +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(true); +#endif } - SettingPresenter::~SettingPresenter() {} + SettingPresenter::~SettingPresenter() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::~SettingPresenter"); + g_pSettingPresenter = nullptr; +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(false); +#endif + } + + SettingPresenter *SettingPresenter::GetInstance() + { + return g_pSettingPresenter; + } + + void SettingPresenter::SetStartIndex(uint16_t index) + { + settingModel->SetStartIndex(index); + } + + uint16_t SettingPresenter::GetStartIndex(void) + { + return settingModel->GetStartIndex(); + } + + void SettingPresenter::SetHeadItemY(int y) + { + settingModel->SetHeadItemY(y); + } + + int SettingPresenter::GetHeadItemY(void) + { + return settingModel->GetHeadItemY(); + } + + int SettingPresenter::GetListItemNum() + { + return settingModel->GetSettingListNum(); + } void SettingPresenter::OnStart() { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnStart"); + Presenter::OnStart(); settingModel->InitSettingItem(); - if (view_ == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "view_ is nullptr!!"); + } + + void SettingPresenter::OnResume(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnResume"); + if (view_ == nullptr) + { return; } const SettingItem *itemInfo = settingModel->GetSettinglistItems(); - view_->RefreshSettingsList(itemInfo, settingModel->GetSettingListNum()); + for (uint8_t i = 0; i < settingModel->GetSettingListNum(); i++) + { + view_->AddSettingItemToList(itemInfo[i]); + } + } + + // 页面准备切换到后台前执行的逻辑 + void SettingPresenter::OnPause(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnPause"); + Presenter::OnPause(); + } + + void SettingPresenter::OnStop(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnStop"); + Presenter::OnPause(); + return; } - bool SettingPresenter::OnDrag(UIView& view, const DragEvent& event) + bool SettingPresenter::OnDrag(UIView &view, const DragEvent &event) { + UNUSED(view); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnDrag"); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + X_DRAG_FLAG = true; + } + return true; + } + + bool SettingPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { UNUSED(view); - 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)"); - if (SetDesktopModel::GetInstance().GetDesktopStyle() == HEXAGONS_STYLE) { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_BACK_TO_HEXAGONS); - } else if (SetDesktopModel::GetInstance().GetDesktopStyle() == WATERFALL_STYLE) { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_BACK_TO_WATERFALL); - } else { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); - } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) + { + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + X_DRAG_FLAG = false; + } + return true; + } + + // 增加按键事件 + bool SettingPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16 keyState = event.GetState(); + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); } - return false; + return true; } bool SettingPresenter::OnClick(UIView &view, const ClickEvent &event) @@ -58,21 +150,8 @@ REGIST_MENU(VIEW_SETTING, SettingView, SettingPresenter, PNG_APPLIST_SETTING_IMA UNUSED(event); SettingItemView *settingItemView = static_cast(&view); AppViewId viewId = settingItemView->GetViewId(); - if (viewId == VIEW_REBOOT) { - if (strstr(settingItemView->GetIconId(), "REBOOT") != nullptr) { - RebootModel::GetInstance()->SetSelectViewId(REBOOTDEVICE); - RebootModel::GetInstance()->SetExitsView(true); - } else { - RebootModel::GetInstance()->SetSelectViewId(SHUTDOWNDEVICE); - RebootModel::GetInstance()->SetExitsView(true); - } - } - if (settingItemView->SlideBackEnabled()) { - NativeAbility::GetInstance().ChangeSlice(viewId, TransitionType::TRANSITION_INVALID, - gSliceDefaultPriority, true); - } else { - NativeAbility::GetInstance().ChangeSlice(viewId); - } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "%d\n", viewId); + NativeAbility::GetInstance().EnterSlice(viewId); return true; } } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingView.cpp index 2b03b50ce..590a5306b 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingView.cpp @@ -1,121 +1,202 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: SettingView.cpp - * Author: - * Create: 2021-11-23 + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-07-12 09:55:29 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-11-05 14:41:44 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingView.cpp */ #include - -#include "SettingView.h" -#include "SettingItem.h" -#include "SettingPresenter.h" -#include "components/ui_list_nested.h" -#include "components/ui_scroll_view_nested.h" - -namespace OHOS { -static constexpr uint8_t SETTINGS_ITEM_FONT_SIZE = 40; -static constexpr int16_t SETTINGS_RESIZE_SIZE_WIDTH = 100; -static constexpr int16_t SETTINGS_RESIZE_SIZE_HEIGHT = 60; -static constexpr int16_t SETTING_TITLE_POSITION_X = 187; -static constexpr int16_t SETTING_LIST_POSITION_X = 32; -static constexpr int16_t SETTING_LIST_POSITION_Y = 90; -static constexpr int16_t SETTING_SCROLLBLANKSIZE = 50; -static constexpr int16 MAX_SCR_DIS = 1000; -static constexpr int16 LIST_POS = 20; -static constexpr int16 SNUM_2 = 2; - -SettingView::SettingView() +#include "settings/include/SettingView.h" +#include "settings/include/SettingItem.h" +#include "settings/include/SettingPresenter.h" +#include "ui_resource_string.h" +namespace OHOS { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::SettingView"); -} + /* ---------------------------------- 设置标签 ---------------------------------- */ + static constexpr int16_t SETTING_TITLE_POSITION_X = 83; + static constexpr int16_t SETTING_TITLE_POSITION_Y = 52; + static constexpr int16_t SETTING_TITLE_SIZE_WIDTH = 300; + static constexpr int16_t SETTING_TITLE_SIZE_HEIGHT = 35; + static constexpr uint8_t SETTINGS_TITLE_FONT_SIZE = 30; // 字体大小 + static constexpr uint8_t SETTINGS_TITLE_FONT_HEIGHT = 35; // 字体高度 + /* --------------------------------- 设置List --------------------------------- */ + static constexpr int16_t SETTING_LIST_POSITION_X = 0; + static constexpr int16_t SETTING_LIST_POSITION_Y = 0; + static constexpr int16_t SETTING_SCROLLBLANKSIZE = 50; // 设置此滚动视图的空白大小。 + static constexpr int16 MAX_SCR_DIS = 1000; + static constexpr int16 LIST_POS = 20; + static constexpr int16 SNUM_2 = 2; + static constexpr int16 ROLLSPEED = 70; + static constexpr int16 REBOUNDSIZE = 30; -SettingView::~SettingView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::~SettingView"); - if (scrollView != nullptr) { - scrollView->RemoveAll(); - delete scrollView; - scrollView = nullptr; + SettingView::SettingView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::SettingView"); } - if (title != nullptr) { - delete title; - title = nullptr; + SettingView::~SettingView() + { + settingListOnStop(); + ClearAll(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::~SettingView"); } - if (listAdapter != nullptr) { - delete listAdapter; - listAdapter = nullptr; + void SettingView::ClearAll(void) + { + if (viewInitStatus) + { + + if (scrollView != nullptr) + { + scrollView->RemoveAll(); + if (listAdapter != nullptr) + { + delete listAdapter; + listAdapter = nullptr; + } + if (contentList != nullptr) + { + delete contentList; + contentList = nullptr; + } + delete scrollView; + scrollView = nullptr; + } + + } } - if (contentList != nullptr) { - delete contentList; - contentList = nullptr; + void SettingView::CreateSettingView(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::CreateSettingView"); + /* -------------------------------------------------------------------------- */ + if (scrollView == nullptr) + { + scrollView = new UIScrollView(); + if (scrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::scrollView is new fail!!"); + return; + } + } + scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + scrollView->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + scrollView->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); + scrollView->SetHorizontalScrollState(false); + scrollView->SetTouchable(true); + scrollView->SetThrowDrag(true); + scrollView->SetOnDragListener(presenter_); + /* -------------------------------------------------------------------------- */ + if (listAdapter == nullptr) + { + listAdapter = new SettingAdapter(); + if (listAdapter == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::listAdapter is new fail!!"); + return; + } + } + listAdapter->SetItemClickListener(presenter_); + /* -------------------------------------------------------------------------- */ + if (contentList == nullptr) + { + contentList = new UIList(UIList::VERTICAL); + if (contentList == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::contentList is new fail!!"); + return; + } + } + contentList->SetPosition(SETTING_LIST_POSITION_X, SETTING_LIST_POSITION_Y, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + contentList->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + contentList->EnableAutoAlign(true); // 设置此列表的自动对齐状态。当滚动停止时,子视图被选中,其位置自动与预设位置对齐 + contentList->SetThrowDrag(true); // 设置手指抬起屏幕后是否继续滚动。 + contentList->SetMaxScrollDistance(1000); // 设置手指抬起屏幕后的最大滚动距离。 + contentList->SetSwipeACCLevel(200); /*设置手指抬起屏幕后的补偿距离。*/ + // contentList->SetReboundSize(30); + // contentList->SetScrollBlankSize(30); + FocusManager::GetInstance()->RequestFocus(contentList); + FocusManager::GetInstance()->RequestFocusByDirection(FOCUS_DIRECTION_UP); + contentList->SetRotateFactor(1.0); + /* ----------------------------------- Add ---------------------------------- */ + scrollView->Add(contentList); + AddViewToRootContainer(scrollView); } -} -void SettingView::OnStart() -{ - title = new UILabel(); - if (title == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::title is nullptr"); - return; - } - title->SetPosition(SETTING_TITLE_POSITION_X, 0); - title->SetText("设置"); - title->Resize(SETTINGS_RESIZE_SIZE_WIDTH, SETTINGS_RESIZE_SIZE_HEIGHT); - title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTINGS_ITEM_FONT_SIZE); - title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - title->SetStyle(STYLE_TEXT_OPA, OPA_OPAQUE); - title->SetStyle(STYLE_TEXT_COLOR, Color::White().full); - title->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - title->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + void SettingView::OnStart() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart"); + if (!viewInitStatus) + { + CreateSettingView(); + viewInitStatus = true; + } - contentList = new UIListNested(); - if (contentList == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::contentList is nullptr"); - return; + // 增加按键监听 + RootView::GetInstance()->SetOnKeyActListener(presenter_); } - contentList->SetPosition(SETTING_LIST_POSITION_X, SETTING_LIST_POSITION_Y); - contentList->Resize(HORIZONTAL_RESOLUTION, 364); // 364: height - contentList->SetScrollBlankSize(SETTING_SCROLLBLANKSIZE); - contentList->SetSelectPosition(HORIZONTAL_RESOLUTION / SNUM_2); // middle position - contentList->SetDraggable(true); - contentList->SetThrowDrag(true); - contentList->EnableAutoAlign(true); - contentList->SetMaxScrollDistance(MAX_SCR_DIS); - scrollView = new UIScrollViewNested(); - if (scrollView == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::scrollView is nullptr"); - return; - } - scrollView->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - scrollView->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - scrollView->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); - scrollView->SetThrowDrag(true); + - if (PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { // support default slide back firstly - scrollView->SetOnDragListener(presenter_); + + + void SettingView::AddSettingItemToList(const SettingItem &item) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::AddSettingItemToList"); + listAdapter->AddListItem(item); } - scrollView->Add(title); - scrollView->Add(contentList); - AddViewToRootContainer(scrollView); -} -void SettingView::RefreshSettingsList(const SettingItem* item, uint8_t count) -{ - listAdapter = new SettingAdapter(); - if (listAdapter == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::listAdapter is nullptr"); - return; + void SettingView::settingListOnSetUpView(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::settingListOnSetUpView"); + if (contentList == nullptr || listAdapter == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingView::settingListOnSetUpView fail!!"); + return; + } + uint16_t startIndex = 0; + int16_t headY = 0; + int NUM_2 = 2; + int screen_h = Screen::GetInstance().GetHeight(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetStartIndex = %d,GetListItemNum = %d", presenter_->GetStartIndex(), presenter_->GetListItemNum()); + if (presenter_->GetStartIndex() >= presenter_->GetListItemNum()) + { + startIndex = presenter_->GetListItemNum() - 1; + headY = screen_h / NUM_2; + } + else + { + uint16_t presliceId = NativeAbility::GetInstance().GetPreSliceId(); + if (presliceId == VIEW_MAIN) + { + startIndex = 0; + headY = 0; + } + else + { + startIndex = presenter_->GetStartIndex(); + headY = presenter_->GetHeadItemY(); + } + if (headY == 0) + { + headY = screen_h / NUM_2; + } + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "startIndex = %d,headY = %d", startIndex, headY); + contentList->SetStartIndex(startIndex); + contentList->SetAdapter(listAdapter); + contentList->RefreshList(); + contentList->ScrollBy(headY); } - listAdapter->SetItemClickListener(presenter_); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::RefreshSettingsList"); - for (int i = 0; i < count; i++) { - listAdapter->AddListItem(item[i]); + + void SettingView::settingListOnStop(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::settingListOnStop"); + int16_t listHeadY = contentList->GetChildrenHead()->GetY(); + int16_t listHeadIndex = contentList->GetChildrenHead()->GetViewIndex(); + presenter_->SetHeadItemY(listHeadY); + presenter_->SetStartIndex(listHeadIndex); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "listHeadY = %d,listHeadIndex = %d", listHeadY, listHeadIndex); } - contentList->SetAdapter(listAdapter); -} } -- 2.17.1