From: 罗正yun <1732036298@qq.com> Date: Fri, 26 Jan 2024 09:51:00 +0000 (+0800) Subject: 系统视图优化:只有一个slice其他为subView X-Git-Tag: release_V1.2.70_20241020_135402~1321^2~3^2~1 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=4dac6d06ea525a585fcb39b7d9ad06398902b189;p=mirrors%2FFD230.git 系统视图优化:只有一个slice其他为subView --- diff --git a/autuobuild.sh b/autuobuild.sh index 88e2b59e7..10d9bbcd2 100644 --- a/autuobuild.sh +++ b/autuobuild.sh @@ -13,9 +13,9 @@ fi if [ "$2" == "" ] then -RELEASE_BUILD=release -else RELEASE_BUILD=debug +else +RELEASE_BUILD=release fi CURRENT_BRANCH=`git branch |awk '$1=="*"{print $2}'` COMMIT_ID=`git rev-parse HEAD` diff --git a/code/sdk/application/wearable/nativeapp/CMakeLists.txt b/code/sdk/application/wearable/nativeapp/CMakeLists.txt index 55a1d84b5..e65b8826e 100755 --- a/code/sdk/application/wearable/nativeapp/CMakeLists.txt +++ b/code/sdk/application/wearable/nativeapp/CMakeLists.txt @@ -213,11 +213,11 @@ set(SOURCES #系统 ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/system/src/SystemPresenter.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/system/src/SystemView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/system/src/SystemView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/system/src/SystemModel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/system/src/SystemAboutTheWatchView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/system/src/SystemSuperviseView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/system/src/SystemLanguageView.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/system/src/SystemFactoryResetPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/system/src/SystemFactoryResetView.cpp #声音与震动 diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h index 8ef146e42..417d287e7 100755 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h @@ -46,7 +46,6 @@ typedef enum : uint16_t VIEW_FUTURE_WEATHER, // 未来天气 VIEW_GET_WEATHER_DATA_ERROR, // 获取天气数据失败 VIEW_SYSTEM, // 系统 - VIEW_SYSTEM_FACTORY_RESET, // 系统:恢复出厂设置 VIEW_SOUND_VIBRATION, // 声音与震动 VIEW_SYSTEM_VOLUME, // 系统音量 VIEW_CALL_VOLUME, // 通话音量 diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h index 2b334b65e..853ac77e7 100755 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h @@ -50,7 +50,6 @@ namespace OHOS void InitGetWeatherDataErrorSlice(void); /* -------------------------------------------------------------------------- */ void InitSystemSlice(void); - void InitSystemFactoryResetSlice(void); /* -------------------------------------------------------------------------- */ void InitSoundAndVibrationSlice(void); void InitSystemVolumeSlice(void); diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp index b82253864..9ed64bca3 100755 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp @@ -71,8 +71,6 @@ #include "system/include/SystemPresenter.h" #include "system/include/SystemView.h" -#include "system/include/SystemFactoryResetPresenter.h" -#include "system/include/SystemFactoryResetView.h" #include "soundandvibration/include/SoundAndVibrationPresenter.h" #include "soundandvibration/include/SoundAndVibrationView.h" @@ -140,7 +138,6 @@ namespace OHOS {VIEW_FUTURE_WEATHER, &NativeLauncher::InitFutureWeatherSlice}, // 未来天气 {VIEW_GET_WEATHER_DATA_ERROR, &NativeLauncher::InitGetWeatherDataErrorSlice}, // 获取天气数据失败 {VIEW_SYSTEM, &NativeLauncher::InitSystemSlice}, // 系统实例化地址 - {VIEW_SYSTEM_FACTORY_RESET, &NativeLauncher::InitSystemFactoryResetSlice}, // 系统:恢复出厂设置实例化地址 {VIEW_SOUND_VIBRATION, &NativeLauncher::InitSoundAndVibrationSlice}, // 声音与震动实例化地址 {VIEW_SYSTEM_VOLUME, &NativeLauncher::InitSystemVolumeSlice}, // 系统音量 @@ -492,16 +489,6 @@ namespace OHOS NativeAbility::GetInstance().AddSliceProxy(VIEW_SYSTEM, system); } - void NativeLauncher::InitSystemFactoryResetSlice(void) // 系统:恢复出厂设置 - { - SliceProxy *systemfactoryreset = new AbilitySliceProxy; - if (systemfactoryreset == nullptr) - { - return; - } - NativeAbility::GetInstance().AddSliceProxy(VIEW_SYSTEM_FACTORY_RESET, systemfactoryreset); - } - void NativeLauncher::InitMessageSlice(void) // 消息中心 { SliceProxy *messageview = new AbilitySliceProxy; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/system/include/SystemFactoryResetPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/system/include/SystemFactoryResetPresenter.h deleted file mode 100644 index f23356dfc..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/system/include/SystemFactoryResetPresenter.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef SYSTEM_FACTORYRESET_PRESENTER_H -#define SYSTEM_FACTORYRESET_PRESENTER_H - -#include "Presenter.h" - -#include "SystemFactoryResetView.h" - -namespace OHOS -{ - class SystemFactoryResetView; - - class SystemFactoryResetPresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener - { - public: - SystemFactoryResetPresenter(); - virtual ~SystemFactoryResetPresenter(); - - void OnStart() override; - void OnPause() override; - void OnResume() override; - void OnStop() override; - - static SystemFactoryResetPresenter *GetInstance(); - - private: - // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; - bool OnClick(UIView &view, const ClickEvent &event) override; - bool OnDrag(UIView &view, const DragEvent &event) override; - }; -} // namespace OHOS - -#endif // SLEEPDETAIL_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/system/include/SystemFactoryResetView.h b/code/sdk/application/wearable/nativeapp/nativeui/system/include/SystemFactoryResetView.h index c8487005a..957df8377 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/system/include/SystemFactoryResetView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/system/include/SystemFactoryResetView.h @@ -4,15 +4,12 @@ #include "BaseView.h" #include "View.h" -#include "components/ui_view_group.h" #include "components/ui_image_view.h" #include "components/ui_button.h" +#include "components/ui_scroll_view.h" namespace OHOS { - static const char *FACTORYRESET_CHECKON = "ShoutDownButtonCheckOn";//确认 - static const char *FACTORYRESET_CHECKOFF = "ShoutDownButtonCheckOff";//取消 - class SystemFactoryResetPresenter; - class SystemFactoryResetView : public View + class SystemFactoryResetView { public: @@ -20,20 +17,15 @@ namespace OHOS virtual ~SystemFactoryResetView(); static SystemFactoryResetView *GetInstance(void); - void OnStart() override; - void OnSetUpView() override; - void OnTearDownView() override; - void OnStop() override; + UIScrollView *SystemFactoryResetViewInit(void); + void ClearAll(void); private: - - void InitView(void); - void DeInitView(void); - - UIViewGroup *container_ = nullptr; - UIImageView *FactoryResetImage = nullptr; - UIButton *FactoryResetButtonCheckOn = nullptr; - UIButton *FactoryResetButtonCheckOff = nullptr; + UIScrollView *scrollView{nullptr}; + UIImageView *FactoryResetImage{nullptr}; // 恢复出厂设置背景图片 + UIButton *FactoryResetButtonCheckOn{nullptr}; // 重置确认 + UIButton *FactoryResetButtonCheckOff{nullptr}; // 重置否定 + bool initViewStatus{false}; }; } // namespace OHOS #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/system/include/SystemModel.h b/code/sdk/application/wearable/nativeapp/nativeui/system/include/SystemModel.h new file mode 100644 index 000000000..4715f7371 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/system/include/SystemModel.h @@ -0,0 +1,20 @@ +#ifndef SYSTEM_MODEL_H +#define SYSTEM_MODEL_H + +namespace OHOS +{ + class SystemModel + { + public: + static SystemModel *GetInstance(void); + + private: + SystemModel() = default; + ~SystemModel(){} + SystemModel(const SystemModel &) = delete; + SystemModel &operator=(const SystemModel &) = delete; + + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/system/include/SystemPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/system/include/SystemPresenter.h index d48e2796a..57140a529 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/system/include/SystemPresenter.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/system/include/SystemPresenter.h @@ -3,12 +3,26 @@ #include "Presenter.h" #include "SystemView.h" +#include "system/include/SystemModel.h" #include "components/ui_radio_button.h" namespace OHOS { + typedef enum + { + SYSTEMVIEW = 0, // 系统视图(slice) + ABOUTTHEWATCHVIEW, // 关于手表视图(subView) + SUPERVISEVIEW, // 监管视图(subView) + SYSTEMLANGUAGEVIEW, // 系统语言视图(subView) + FACTORYRESETVIEW, // 恢复出厂设置视图(subView) + MAX_VIEWID, + } SYSTEMVIEWId; + /* ---------------------------- 系统语言界面单选按钮VIEWID ---------------------------- */ static const char *SIMPLIFIED_CHINESE_CHECKBOX = "SimplifiedChineseCheckBox"; // 简体中文 static const char *ENGLISH_CHECKBOX = "EnglishCheckBox"; // English + /* ---------------------------- 恢复出厂设置界面按钮的VIEWID --------------------------- */ + static const char *FACTORYRESET_CHECKON = "ShoutDownButtonCheckOn"; // 确认 + static const char *FACTORYRESET_CHECKOFF = "ShoutDownButtonCheckOff"; // 取消 class RadiobuttonOnChangeListener : public UICheckBox::OnChangeListener { public: @@ -29,13 +43,12 @@ namespace OHOS { public: SystemViewOnDragListener() {} - ~SystemViewOnDragListener() {} - bool OnDrag(UIView &view, const DragEvent &event) override; }; class SystemView; + class UISampleModel; class SystemPresenter : public Presenter, public UIView::OnClickListener, public UIView::OnDragListener @@ -56,6 +69,9 @@ namespace OHOS bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView &view, const DragEvent &event) override; bool OnDragEnd(UIView &view, const DragEvent &event) override; + + private: + SystemModel *systemModel; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/nativeapp/nativeui/system/include/SystemView.h b/code/sdk/application/wearable/nativeapp/nativeui/system/include/SystemView.h index 4e9a968a2..f02778015 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/system/include/SystemView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/system/include/SystemView.h @@ -12,6 +12,7 @@ #include "system/include/SystemAboutTheWatchView.h" #include "system/include/SystemSuperviseView.h" #include "system/include/SystemLanguageView.h" +#include "system/include/SystemFactoryResetView.h" namespace OHOS { static const char *ABOUT_THE_WATCH = "AboutTheWatchButton"; // 关于手表 @@ -48,8 +49,10 @@ namespace OHOS bool ChangeSystemAboutView(int16_t thisView); bool ChangeSystemSuperviseView(int16_t thisView); bool ChangeSystemLanguageView(int16_t thisView); + bool ChangeSystemFactoryResetView(int16_t thisView); bool ClickFunc(int16_t interface); void ChangeView(int16_t hideView, int16_t showView); + UIScrollView *GetSystemScrollView(int ViewId); private: void InitIView(void); void ClearAll(void); @@ -59,6 +62,7 @@ namespace OHOS SystemAboutTheWatchView *p_SystemAboutTheWatchView{nullptr}; SystemSuperviseView *p_SystemSuperviseView{nullptr}; SystemLanguageView *p_SystemLanguageView{nullptr}; + SystemFactoryResetView *p_SystemFactoryResetView{nullptr}; UIScrollView *SystemScrollView[5]{nullptr}; UILabel *SystemLabel{nullptr}; // 标题 UIButton *AboutTheWatchButton{nullptr}; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemFactoryResetPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemFactoryResetPresenter.cpp deleted file mode 100644 index 358f02239..000000000 --- a/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemFactoryResetPresenter.cpp +++ /dev/null @@ -1,78 +0,0 @@ -#include "AppViewIDs.h" -#include "NativeAbility.h" -#include "graphic_math.h" -#include "string.h" -#include "system/include/SystemFactoryResetPresenter.h" - -namespace OHOS -{ - - // 当前Presenter属性实例化的内存指针 - static SystemFactoryResetPresenter *g_pSystemFactoryResetPresenter = nullptr; - - SystemFactoryResetPresenter::SystemFactoryResetPresenter() - { - - g_pSystemFactoryResetPresenter = this; - } - - SystemFactoryResetPresenter::~SystemFactoryResetPresenter() - { - - g_pSystemFactoryResetPresenter = nullptr; - } - - SystemFactoryResetPresenter *SystemFactoryResetPresenter::GetInstance() - { - - return g_pSystemFactoryResetPresenter; - } - - void SystemFactoryResetPresenter::OnStart() - { - - Presenter::OnStart(); - } - - void SystemFactoryResetPresenter::OnPause(void) - { - - Presenter::OnPause(); - } - - void SystemFactoryResetPresenter::OnResume(void) - { - - Presenter::OnResume(); - } - - void SystemFactoryResetPresenter::OnStop(void) - { - - Presenter::OnStop(); - } - - bool SystemFactoryResetPresenter::OnDrag(UIView &view, const DragEvent &event) - { - - UNUSED(view); - UNUSED(event); - return true; - } - - bool SystemFactoryResetPresenter::OnClick(UIView &view, const ClickEvent &event) - { - - // 根据控件id查找是哪个控件触发了点击回调 - if (strcmp(view.GetViewId(), FACTORYRESET_CHECKON) == 0) - { - return true; - } - else if (strcmp(view.GetViewId(), FACTORYRESET_CHECKOFF) == 0) - { - NativeAbility::GetInstance().ChangeSlice(VIEW_SYSTEM); - return true; - } - return false; - } -} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemFactoryResetView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemFactoryResetView.cpp index b63e39e29..5bca4daf8 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemFactoryResetView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemFactoryResetView.cpp @@ -1,6 +1,6 @@ #include "system/include/SystemFactoryResetView.h" -#include "system/include/SystemFactoryResetPresenter.h" - +#include "system/include/SystemPresenter.h" +#include "wearable_log.h" #include "UiConfig.h" namespace OHOS @@ -10,12 +10,14 @@ namespace OHOS SystemFactoryResetView::SystemFactoryResetView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemFactoryResetView::SystemFactoryResetView"); g_pSystemFactoryResetView = this; } SystemFactoryResetView::~SystemFactoryResetView() { - DeInitView(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemFactoryResetView::~SystemFactoryResetView"); + ClearAll(); g_pSystemFactoryResetView = nullptr; } @@ -24,115 +26,80 @@ namespace OHOS return g_pSystemFactoryResetView; } - void SystemFactoryResetView::InitView() + void SystemFactoryResetView::ClearAll() { - if (container_ == nullptr) + if (initViewStatus == true) { - container_ = new UIViewGroup(); - container_->SetPosition(0, 0, 466, 466); - container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + scrollView->RemoveAll(); + delete FactoryResetImage; + FactoryResetImage = nullptr; + delete FactoryResetButtonCheckOn; + FactoryResetButtonCheckOn = nullptr; + delete FactoryResetButtonCheckOff; + FactoryResetButtonCheckOff = nullptr; + delete scrollView; + scrollView = nullptr; } - // Add ImageView to App - if (FactoryResetImage == nullptr) + } + + UIScrollView *SystemFactoryResetView::SystemFactoryResetViewInit(void) + { + scrollView = new UIScrollView(); + if (scrollView == nullptr) { - FactoryResetImage = new UIImageView(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemFactoryResetView::new scrollView fail!"); + return nullptr; } - FactoryResetImage->SetPosition(0, 0); // widget's left position and top position - FactoryResetImage->Resize(466, 466); // widget's width and height - FactoryResetImage->SetViewId("FactoryResetImage"); // Set style - FactoryResetImage->SetStyle(STYLE_BORDER_RADIUS, 300); - FactoryResetImage->SetSrc("/user/res/system/factoryreset.bin"); //恢复出厂设置 - // Add to rootView - container_->Add(FactoryResetImage); - FactoryResetImage->SetVisible(true); - - // Add Button to App - if (FactoryResetButtonCheckOn == nullptr) + scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollView->SetStyle(STYLE_BORDER_RADIUS, 1294); + /* ---------------------------- FactoryResetImage --------------------------- */ + FactoryResetImage = new UIImageView(); + if (FactoryResetImage == nullptr) { - FactoryResetButtonCheckOn = new UIButton(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemFactoryResetView::new FactoryResetImage fail!"); + return nullptr; } - FactoryResetButtonCheckOn->SetPosition(256, 336); // widget's left position and top position - FactoryResetButtonCheckOn->Resize(100, 100); // widget's width and height - FactoryResetButtonCheckOn->SetViewId(FACTORYRESET_CHECKON); // Set style - FactoryResetButtonCheckOn->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - FactoryResetButtonCheckOn->SetImageSrc(PNG_SYSTEM_CHECK_ON_IMAGE, nullptr); - FactoryResetButtonCheckOn->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED); - FactoryResetButtonCheckOn->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - // Add the CallBack about events - UIView::OnClickListener *FactoryResetButtonCheckOnClick = static_cast(SystemFactoryResetPresenter::GetInstance()); - FactoryResetButtonCheckOn->SetOnClickListener(FactoryResetButtonCheckOnClick); - // Add to rootView - container_->Add(FactoryResetButtonCheckOn); - FactoryResetButtonCheckOn->SetVisible(true); - - // Add Button to App + FactoryResetImage->SetPosition(0, 0, 466, 466); + FactoryResetImage->SetStyle(STYLE_BORDER_RADIUS, 300); + FactoryResetImage->SetSrc("/user/res/system/factoryreset.bin"); // 恢复出厂设置 + /* ----------------------- FactoryResetButtonCheckOff ----------------------- */ + FactoryResetButtonCheckOff = new UIButton(); if (FactoryResetButtonCheckOff == nullptr) { - FactoryResetButtonCheckOff = new UIButton(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemFactoryResetView::new FactoryResetButtonCheckOff fail!"); + return nullptr; } - FactoryResetButtonCheckOff->SetPosition(111, 336); // widget's left position and top position - FactoryResetButtonCheckOff->Resize(100, 100); // widget's width and height - FactoryResetButtonCheckOff->SetViewId(FACTORYRESET_CHECKOFF); // Set style - FactoryResetButtonCheckOff->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - FactoryResetButtonCheckOff->SetImageSrc(PNG_SYSTEM_CHECK_OFF_IMAGE, nullptr); + FactoryResetButtonCheckOff->SetPosition(240, 320, 130, 130); + FactoryResetButtonCheckOff->SetViewId(FACTORYRESET_CHECKOFF); + FactoryResetButtonCheckOff->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + FactoryResetButtonCheckOff->SetStyle(STYLE_BACKGROUND_OPA, 0x00); FactoryResetButtonCheckOff->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED); FactoryResetButtonCheckOff->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - // Add the CallBack about events - UIView::OnClickListener *FactoryResetButtonCheckOffClick = static_cast(SystemFactoryResetPresenter::GetInstance()); + UIView::OnClickListener *FactoryResetButtonCheckOffClick = static_cast(SystemPresenter::GetInstance()); FactoryResetButtonCheckOff->SetOnClickListener(FactoryResetButtonCheckOffClick); - // Add to rootView - container_->Add(FactoryResetButtonCheckOff); - FactoryResetButtonCheckOff->SetVisible(true); - } - - void SystemFactoryResetView::DeInitView() - { - if (container_ != nullptr) - { - container_->RemoveAll(); - delete container_; - container_ = nullptr; - } - if (FactoryResetImage != nullptr) - { - delete FactoryResetImage; - FactoryResetImage = nullptr; - } - if (FactoryResetButtonCheckOn != nullptr) - { - delete FactoryResetButtonCheckOn; - FactoryResetButtonCheckOn = nullptr; - } - if (FactoryResetButtonCheckOff != nullptr) + /* ------------------------ FactoryResetButtonCheckOn ----------------------- */ + FactoryResetButtonCheckOn = new UIButton(); + if (FactoryResetButtonCheckOn == nullptr) { - delete FactoryResetButtonCheckOff; - FactoryResetButtonCheckOff = nullptr; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemFactoryResetView::new FactoryResetButtonCheckOn fail!"); + return nullptr; } - } - - void SystemFactoryResetView::OnStart() - { - View::OnStart(); - InitView(); - RootView::GetInstance()->Add(container_); - } - - void SystemFactoryResetView::OnSetUpView() - { - View::OnSetUpView(); - Draw(); - } + FactoryResetButtonCheckOn->SetPosition(97, 320, 130, 130); + FactoryResetButtonCheckOn->SetViewId(FACTORYRESET_CHECKON); + FactoryResetButtonCheckOn->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + FactoryResetButtonCheckOn->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + FactoryResetButtonCheckOn->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED); + FactoryResetButtonCheckOn->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + UIView::OnClickListener *FactoryResetButtonCheckOnClick = static_cast(SystemPresenter::GetInstance()); + FactoryResetButtonCheckOn->SetOnClickListener(FactoryResetButtonCheckOnClick); - void SystemFactoryResetView::OnTearDownView() - { - View::OnTearDownView(); - return; + /* ----------------------------- Add to scroView ---------------------------- */ + scrollView->Add(FactoryResetImage); + scrollView->Add(FactoryResetButtonCheckOff); + scrollView->Add(FactoryResetButtonCheckOn); + initViewStatus = true; + return scrollView; } - void SystemFactoryResetView::OnStop() - { - View::OnStop(); - RootView::GetInstance()->RemoveAll(); - return; - } } \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemLanguageView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemLanguageView.cpp index e0457aee1..9ae0227e9 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemLanguageView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemLanguageView.cpp @@ -123,7 +123,6 @@ namespace OHOS scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); scrollView->SetStyle(STYLE_BORDER_RADIUS, 1294); - scrollView->SetVisible(true); UIView::OnDragListener *draglistener = static_cast(SystemPresenter::GetInstance()); if (draglistener == nullptr) { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemModel.cpp new file mode 100644 index 000000000..8e77ce1da --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemModel.cpp @@ -0,0 +1,12 @@ +#include "system/include/SystemModel.h" + +namespace OHOS +{ + + SystemModel *SystemModel::GetInstance(void) + { + static SystemModel instance; + return &instance; + } + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemPresenter.cpp index a7d67a647..27d1d3542 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemPresenter.cpp @@ -11,13 +11,14 @@ namespace OHOS SystemPresenter::SystemPresenter() { - + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemPresenter::SystemPresenter"); g_pSystemPresenter = this; + systemModel = SystemModel::GetInstance(); } SystemPresenter::~SystemPresenter() { - + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemPresenter::~SystemPresenter"); g_pSystemPresenter = nullptr; } @@ -58,42 +59,60 @@ namespace OHOS bool SystemPresenter::OnDragEnd(UIView &view, const DragEvent &event) { - + SystemView *p_SystemView = SystemView::GetInstance(); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - NativeAbility::GetInstance().ChangeSlice(VIEW_SYSTEM); + for (int i = 1; i < MAX_VIEWID; i++) + { + if (p_SystemView->GetSystemScrollView(i)->IsVisible() == true) + { + p_SystemView->ChangeView(i, SYSTEMVIEW); + break; + } + } return true; } return false; } + // 该点击回调主要用于在系统视图界面进行跳转视图 bool SystemPresenter::OnClick(UIView &view, const ClickEvent &event) { - + SystemView *p_SystemView = SystemView::GetInstance(); // 根据控件id查找是哪个控件触发了点击回调 if (strcmp(view.GetViewId(), ABOUT_THE_WATCH) == 0) { - SystemView::GetInstance()->ChangeView(0, 1); + SystemView::GetInstance()->ChangeView(SYSTEMVIEW, ABOUTTHEWATCHVIEW); return true; } else if (strcmp(view.GetViewId(), SUPERVISE) == 0) { - SystemView::GetInstance()->ChangeView(0, 2); + SystemView::GetInstance()->ChangeView(SYSTEMVIEW, SUPERVISEVIEW); return true; } else if (strcmp(view.GetViewId(), SYSTEM_LANGUAGE) == 0) { - SystemView::GetInstance()->ChangeView(0, 3); + SystemView::GetInstance()->ChangeView(SYSTEMVIEW, SYSTEMLANGUAGEVIEW); return true; } else if (strcmp(view.GetViewId(), FACTORY_RESET) == 0) { - NativeAbility::GetInstance().ChangeSlice(VIEW_SYSTEM_FACTORY_RESET); + SystemView::GetInstance()->ChangeView(SYSTEMVIEW, FACTORYRESETVIEW); + return true; + } + else if (strcmp(view.GetViewId(), FACTORYRESET_CHECKON)) + { + return true; + } + else if (strcmp(view.GetViewId(), FACTORYRESET_CHECKOFF)) + { + p_SystemView->ChangeView(FACTORYRESETVIEW, SYSTEMVIEW); return true; } return false; } + // 该拖拽是用来处理系统视图(slice)的左滑退出事件和子视图的左滑退出到系统视图区分开 bool SystemViewOnDragListener::OnDrag(UIView &view, const DragEvent &event) { if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && @@ -128,6 +147,7 @@ namespace OHOS return false; } + // 用来监听语言切换 bool RadiobuttonOnChangeListener::OnChange(UICheckBox::UICheckBoxState state) { switch (state) diff --git a/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemView.cpp index 4760d3d53..6e126acf1 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/system/src/SystemView.cpp @@ -28,13 +28,21 @@ namespace OHOS { if (initViewStatus == true) { - SystemScrollView[0]->RemoveAll(); + SystemScrollView[SYSTEMVIEW]->RemoveAll(); + UIView::OnDragListener *draglistener = SystemScrollView[SYSTEMVIEW]->GetOnDragListener(); + if (draglistener != nullptr) + { + delete draglistener; + draglistener = nullptr; + } delete p_SystemAboutTheWatchView; p_SystemAboutTheWatchView = nullptr; delete p_SystemSuperviseView; p_SystemSuperviseView = nullptr; delete p_SystemLanguageView; p_SystemLanguageView = nullptr; + delete p_SystemFactoryResetView; + p_SystemFactoryResetView = nullptr; delete SystemLabel; SystemLabel = nullptr; delete AboutTheWatchButton; @@ -53,26 +61,26 @@ namespace OHOS /// @return true 设置成功,false 失败 bool SystemView::SetTheSystemScrollView(void) { - SystemScrollView[0] = new UIScrollView(); - if (SystemScrollView == nullptr) + SystemScrollView[SYSTEMVIEW] = new UIScrollView(); + if (SystemScrollView[SYSTEMVIEW] == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::SystemScrollView new fail!"); return false; } - SystemScrollView[0]->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - SystemScrollView[0]->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - SystemScrollView[0]->SetScrollBlankSize(35); - SystemScrollView[0]->SetReboundSize(50); - SystemScrollView[0]->SetDirection(1); + SystemScrollView[SYSTEMVIEW]->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + SystemScrollView[SYSTEMVIEW]->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + SystemScrollView[SYSTEMVIEW]->SetScrollBlankSize(35); + SystemScrollView[SYSTEMVIEW]->SetReboundSize(50); + SystemScrollView[SYSTEMVIEW]->SetDirection(1); UIView::OnDragListener *draglistener = static_cast(new SystemViewOnDragListener()); if (draglistener == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::draglistener can not be nullptr!"); return false; } - SystemScrollView[0]->SetOnDragListener(draglistener); - SystemScrollView[0]->SetTouchable(true); - SystemScrollView[0]->SetDraggable(true); + SystemScrollView[SYSTEMVIEW]->SetOnDragListener(draglistener); + SystemScrollView[SYSTEMVIEW]->SetTouchable(true); + SystemScrollView[SYSTEMVIEW]->SetDraggable(true); return true; } @@ -114,7 +122,7 @@ namespace OHOS button->SetViewId(buttonconfig.ViewId); button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); button->SetStyle(STYLE_BACKGROUND_OPA, 0x00); - button->SetImageSrc(buttonconfig.ImageSrc, nullptr); + button->SetImageSrc(buttonconfig.ImageSrc, buttonconfig.ImageSrc); button->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); button->SetOnClickListener(clickListener); return button; @@ -180,11 +188,14 @@ namespace OHOS initViewStatus = true; } - // 0.跳转到系统视图,其他视图都市通过这个视图跳转 + // 0.跳转到系统视图,其他视图都市通过这个视图跳转 bool SystemView::ChangeSystemView(int16_t thisView) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::ChangeSystemView"); - RootView::GetInstance()->Add(SystemScrollView[thisView]); + if (SystemScrollView[thisView] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::ChangeSystemView"); + RootView::GetInstance()->Add(SystemScrollView[thisView]); + } return true; } @@ -242,6 +253,29 @@ namespace OHOS return true; } + // 4.跳转到恢复出厂设置界面 + bool SystemView::ChangeSystemFactoryResetView(int16_t thisView) + { + if (SystemScrollView[thisView] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView::ChangeSystemFactoryResetView"); + p_SystemFactoryResetView = new SystemFactoryResetView(); + if (p_SystemFactoryResetView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView:: new scrollView[%d] fail", thisView); + return false; + } + SystemScrollView[thisView] = p_SystemFactoryResetView->SystemFactoryResetViewInit(); + RootView::GetInstance()->Add(SystemScrollView[thisView]); + } + return true; + } + + UIScrollView *SystemView::GetSystemScrollView(int ViewId) + { + return SystemScrollView[ViewId]; + } + /* -------------------------------------------------------------------------- */ // 1.MainStopWatchViewMapper:结构体定义了一个将视图ID映射到特定成员函数指针的映射表。 struct SystemViewMapper @@ -251,18 +285,18 @@ namespace OHOS }; // 2.ViewMapper[] 是一个静态的视图映射数组,将视图ID与MainStopWatchView类中的特定成员函数指针进行了绑定。 - static const SystemViewMapper ViewMapper[] = - { - {0, &SystemView::ChangeSystemView}, - {1, &SystemView::ChangeSystemAboutView}, - {2, &SystemView::ChangeSystemSuperviseView}, - {3, &SystemView::ChangeSystemLanguageView}, + static const SystemViewMapper ViewMapper[] = { + {SYSTEMVIEW, &SystemView::ChangeSystemView}, + {ABOUTTHEWATCHVIEW, &SystemView::ChangeSystemAboutView}, + {SUPERVISEVIEW, &SystemView::ChangeSystemSuperviseView}, + {SYSTEMLANGUAGEVIEW, &SystemView::ChangeSystemLanguageView}, + {FACTORYRESETVIEW, &SystemView::ChangeSystemFactoryResetView}, }; // 3.根据传入的interface参数执行相应视图ID关联的成员函数。 bool SystemView::ClickFunc(int16_t interface) { - int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[0]); + int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[SYSTEMVIEW]); for (int i = 0; i < funcSize; i++) { if (interface == ViewMapper[i].viewId) @@ -281,7 +315,7 @@ namespace OHOS // 4.切换视图 void SystemView::ChangeView(int16_t hideView, int16_t showView) { - if (hideView > 5) + if (hideView > MAX_VIEWID) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView:: SystemViewId Overstep ones bounds"); return; @@ -302,17 +336,17 @@ namespace OHOS void SystemView::OnSetUpView() { View::OnSetUpView(); - if (SystemScrollView[0] == nullptr) + if (SystemScrollView[SYSTEMVIEW] == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemView:: OnSetUpView has nullptr"); return; } - SystemScrollView[0]->Add(SystemLabel); - SystemScrollView[0]->Add(AboutTheWatchButton); - SystemScrollView[0]->Add(SuperviseButton); - SystemScrollView[0]->Add(SystemLanguageButton); - SystemScrollView[0]->Add(FactoryResetButton); - RootView::GetInstance()->Add(SystemScrollView[0]); + SystemScrollView[SYSTEMVIEW]->Add(SystemLabel); + SystemScrollView[SYSTEMVIEW]->Add(AboutTheWatchButton); + SystemScrollView[SYSTEMVIEW]->Add(SuperviseButton); + SystemScrollView[SYSTEMVIEW]->Add(SystemLanguageButton); + SystemScrollView[SYSTEMVIEW]->Add(FactoryResetButton); + RootView::GetInstance()->Add(SystemScrollView[SYSTEMVIEW]); Draw(); }