From 1f6d37d6d199b2b220878e6159d775d2db4544aa Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E7=BD=97=E6=AD=A3?= <1732036298@qq.com> Date: Tue, 23 Jul 2024 01:58:55 +0000 Subject: [PATCH] Merge #570 into sdk602patch0626 from refs/changes/570/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from 罗正 * refs/changes/570/head: (4 commits squashed) - 修改恢复出厂设置适配多国语言 - 1.优化设置视图:添加了表冠控制但效果不佳 2.滑动关机和重启视图添加按键注册功能 3.现在设置视图进入关机和重启为“滑动关机重启Slice” - 优化屏幕与亮度Slice: 1.添加了scrollview的表冠控制, 2.标签断行模式为LINE_BREAK_OSCILLATION改为LINE_BREAK_OSCILLATION 3.亮屏时长视图实现点击按钮该变亮屏时长单选按钮选中状态 - 解决手表解绑后恢复出厂设置,如果手机是直接与手表配对成功未选择语言,进入主界面后发现手表缺少字体问题。 1.如果手机与手表先绑定成功,未选择语言,需选择语言才进入主界面。 2.如果已选择语言,这时手机与手表绑定成功将自动进入主界面。 Signed-off-by: 罗正 <1732036298@qq.com> Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/570 --- .../nativelauncher/src/NativeLauncher.cpp | 6 +- .../include/DisplayBrightnessPresenter.h | 6 +- .../include/DisplayBrightnessView.h | 31 +-- .../include/ScreenDurationView.h | 14 +- .../src/DisplayBrightnessModel.cpp | 5 +- .../src/DisplayBrightnessPresent.cpp | 74 ++++- .../src/DisplayBrightnessView.cpp | 224 ++++++--------- .../src/ScreenDurationView.cpp | 192 +++++++------ .../src/LanguageSwitchPresenter.cpp | 14 +- .../include/FactoryResetView.h | 4 +- .../include/RebootAndShutdownModel.h | 11 +- .../src/FactoryResetView.cpp | 88 +++--- .../src/RebootAndShutdownModel.cpp | 259 +++++++++++++++++- .../settings/include/SettingPresenter.h | 5 +- .../nativeui/settings/include/SettingView.h | 6 +- .../nativeui/settings/src/SettingItemView.cpp | 9 +- .../nativeui/settings/src/SettingModel.cpp | 4 +- .../settings/src/SettingPresenter.cpp | 41 ++- .../nativeui/settings/src/SettingView.cpp | 154 ++++++----- .../system/src/SystemFactoryResetView.cpp | 25 +- .../nativeui/uiservice/src/ui_service.cpp | 2 +- .../service/ble_service/blemoder/bletest.cpp | 1 + .../peripheral/config/src/ConfigModel.cpp | 2 +- 23 files changed, 771 insertions(+), 406 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index 373a5d552..9c35cbc88 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -126,7 +126,7 @@ // #include "dialupdate/include/DialUpdateView.h" #include "ConfigModel.h" -#include "rebootdevice/include/RebootModel.h" +#include "rebootandshutdown/include/RebootAndShutdownModel.h" //#include "phone/include/PhoneView.h" //#include "phone/include/PhonePresenter.h" @@ -280,7 +280,7 @@ namespace OHOS {VIEW_COMPASS, &NativeLauncher::InitCompassSlice}, {VIEW_CONNECT_PHONE, &NativeLauncher::InitConnectPhoneSlice}, {VIEW_INDOORWALK, &NativeLauncher::InitIndoorWalkSlice}, - {VIEW_SHUTDOWN_OR_REBOOT, &NativeLauncher::InitRebootSlice}, + // {VIEW_SHUTDOWN_OR_REBOOT, &NativeLauncher::InitRebootSlice}, {VIEW_WEATHER, &NativeLauncher::InitWeatherSlice}, // 天气 {VIEW_GOAL, &NativeLauncher::InitGoalSlice}, // 每日目标 {VIEW_SYSTEM, &NativeLauncher::InitSystemSlice}, // 系统实例化地址 @@ -440,7 +440,7 @@ namespace OHOS ScreenModels::GetInstance()->PreLoadAppimages(); // NativeAbility::GetInstance().SetDefaultSliceId(VIEW_MAIN); // 注册按键事件 - RebootModel::GetInstance()->RegisterAllKeyEvents(); + RebootAndShutdownModel::GetInstance().RegisterAllKeyEvents(); // 开机检测充电状态 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "get_charge_stat is %d", get_charge_stat()); diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessPresenter.h index 1e070aebb..255e916cf 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessPresenter.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-02-18 09:10:05 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-07 19:25:27 + * @LastEditTime: 2024-07-22 16:24:31 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessPresenter.h */ #ifndef _DISPLAY_BRIGHTNESS_PRESENTER_H @@ -58,15 +58,17 @@ namespace OHOS static const char *SCREENDURATIONBUTTON_VIEWID = "SCREENDURATIONBUTTON"; // 亮屏时长按钮视图id static const char *RAISETOBRIGHTNESSCHECKBOXBUTTON_VIEWID = "RAISETOBRIGHTNESSCHECKBOXBUTTON"; // 抬腕亮屏checkbox按钮视图id - class ScreenDurationRadiobuttonOnChangeListener : public UICheckBox::OnChangeListener + class ScreenDurationRadiobuttonOnChangeListener : public UICheckBox::OnChangeListener, public UIView::OnClickListener { public: + ScreenDurationRadiobuttonOnChangeListener() {} ScreenDurationRadiobuttonOnChangeListener(UIView *view) { m_view = view; } ~ScreenDurationRadiobuttonOnChangeListener() {} bool OnChange(UICheckBox::UICheckBoxState state) override; + bool OnClick(UIView &view, const ClickEvent &event) override; private: UIView *m_view{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessView.h b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessView.h index 84b41b670..ea9dcb659 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessView.h @@ -35,7 +35,7 @@ namespace OHOS int16_t w; int16_t h; const char *ViewId; - //const char *ImageSrc; + // const char *ImageSrc; }; struct LabelConfig { @@ -43,9 +43,9 @@ namespace OHOS int16_t top; int16_t width; int16_t height; - int16_t fontSize; // 字体大小 - int16_t lineHeigh; // 行高 - //std::string text; // 文本 + int16_t fontSize; // 字体大小 + int16_t lineHeigh; // 行高 + // std::string text; // 文本 int16_t textId; uint8_t lineBreakMode; // 断行模式。 }; @@ -62,17 +62,15 @@ namespace OHOS DisplayBrightnessView(); virtual ~DisplayBrightnessView(); static DisplayBrightnessView *GetInstance(void); - void DisplayAndBrightnessViewInit(void); - void ClearAll(void); + bool ChangeDisplayBrightnessView(int16_t thisView); // 切换到“屏幕与亮度”视图 bool ChangeScreenDurationView(int16_t thisView); // 切换到亮屏时长视图 bool ClickFunc(int16_t interface); void ChangeView(int16_t hideView, int16_t showView); - UIScrollView *GetDisplayBrightnessScrollView(int16_t i); - UICheckBox::UICheckBoxState GetRaiseToBrightnessCheckBoxButtonState(void); void SetRaiseToBrightnessCheckBoxButtonState(UICheckBox::UICheckBoxState state); ScreenDurationView *GetScreenDurationView(void); - UILabelExt * GetSelectScreenDurationLabel(void); + UILabelExt *GetSelectScreenDurationLabel(void); + public: void OnStart() override; void OnSetUpView() override; @@ -80,20 +78,21 @@ namespace OHOS void OnStop() override; private: - // ScreenDurationView *p_ScreenDurationView{nullptr}; // 亮屏时长视图 - std::shared_ptr p_ScreenDurationView; + ScreenDurationView *p_ScreenDurationView{nullptr}; // 亮屏时长视图 private: - bool SetUpScrollView(void); - bool SetTheTitle(void); + UILabelExt *SetUpLabel(LabelConfig &labelconfig); // 设置标签 + UIImageView *SetUpImageView(ImageConfig &imageconfig); // 设置图片 + UICheckBox *SetUpCheckBox(CheckBoxConfig &checkboxconfig); // 设置复选框 UIButton *SetTheButton(ButtonConfig &buttonconfig, UIView::OnClickListener *clickListener); + bool SetTheTitle(void); bool InitDisplayBrightnessViewButton(void); - UILabelExt *SetUpLabel(LabelConfig &labelconfig); // 设置标签 bool InitDisplayBrightnessViewLabel(void); - UIImageView *SetUpImageView(ImageConfig &imageconfig); // 设置图片 bool InitDisplayBrightnessViewImage(void); - UICheckBox *SetUpCheckBox(CheckBoxConfig &checkboxconfig); // 设置复选框 bool InitDisplayBrightnessViewCheckBox(void); + bool SetUpScrollView(void); + void DisplayAndBrightnessViewInit(void); + void ClearAll(void); UIScrollView *DisplayBrightnessScrollView[2]{nullptr}; UILabelExt *DisplayBrightnessTitleLabel = nullptr; // 显示与亮度标题 UIButton *BringhtnessControlButton = nullptr; // 亮度调节按钮 diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/ScreenDurationView.h b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/ScreenDurationView.h index 0a04d4cda..66b0f20f7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/ScreenDurationView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/ScreenDurationView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-30 09:14:38 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-05-06 11:14:31 + * @LastEditTime: 2024-07-22 16:30:36 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/ScreenDurationView.h */ #ifndef SCREEN_DUATION_VIEW_H @@ -14,6 +14,7 @@ #include "components/ui_image_view.h" #include "components/ui_label_ext.h" #include "components/ui_radio_button.h" +#include "components/ui_button.h" namespace OHOS { #define DURATIONS 6 @@ -21,7 +22,7 @@ namespace OHOS class ScreenDurationView { public: - struct ImageConfig + struct ButtonConfig { int16_t x; int16_t y; @@ -36,8 +37,7 @@ namespace OHOS int16_t height; int16_t fontSize; // 字体大小 int16_t lineHeigh; // 行高 - //const char *text; // 文本 - int16_t textId; + int16_t textId; // 文本id uint8_t lineBreakMode; // 断行模式。 }; struct RadioButtonConfig @@ -57,9 +57,10 @@ namespace OHOS void ClearAll(void); UIRadioButton *GetRadioButton(int16_t i); void SetRadioButtonSelectStatus(int16_t i); + UIButton *GetScreenDurationButton(int16_t i); private: - UIImageView *SetUpImageView(ImageConfig &imageconfig); // 设置图片 + UIButton *SetUpButtonView(ButtonConfig &buttonConfig); // 设置按钮 UILabelExt *SetUpLabel(LabelConfig &labelconfig); // 设置标签 UIRadioButton *SetUpRadioButton(RadioButtonConfig &radiobuttonconfig); // 设置单选框 bool SetUpScrollView(void); @@ -69,9 +70,10 @@ namespace OHOS UIScrollView *ScreenDurationScrollView = nullptr; UILabelExt *ScreenDurationTitleLabel = nullptr; // 标题 UILabelExt *ScreenDurationLabel[DURATIONS]{nullptr}; // 亮屏时长标签 - UIImageView *BackGroundImage[DURATIONS]{nullptr}; // 放置组件的背景 + UIButton *ScreenDurationButton[DURATIONS]{nullptr}; // 放置组件的按钮 UIRadioButton *ScreenDurationRadioButton[DURATIONS]{nullptr}; // 单选框 UICheckBox::OnChangeListener *SimplifiedChineseRadioButtonChange[DURATIONS]{nullptr}; + UIView::OnClickListener *ScreenDurationButtonClickListener{nullptr}; bool initViewStatus{false}; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp index 95fe4873b..2add7fbc1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-12 20:11:04 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-18 15:31:55 + * @LastEditTime: 2024-07-22 12:00:13 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp */ #include "displaybrightness/include/DisplayBrightnessModel.h" @@ -60,7 +60,8 @@ namespace OHOS return false; } displayBrightnessPresent->SetSelectScreenDurationLabel(GetScreenDurationTime()); - UpdateRaiseToBrightnessCheckBoxButtonStatus(); + // UpdateRaiseToBrightnessCheckBoxButtonStatus(); + UpdateScreenDurationRadioButtonSlectStatus(); return true; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp index 96e0d9ef7..88e1133a0 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-30 09:14:38 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-18 14:11:36 + * @LastEditTime: 2024-07-22 16:37:02 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp */ #include "AppViewIDs.h" @@ -20,6 +20,7 @@ #include #include "map" #include "iostream" +#include "string" #include "ConfigModel.h" namespace OHOS { @@ -102,6 +103,12 @@ namespace OHOS return; } + if (p_DisplayBrightnessView->GetSelectScreenDurationLabel() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_DisplayBrightnessView->GetSelectScreenDurationLabel() is nullptr!"); + return; + } + const std::map durationMap = { {SCREENDURATION_FIVE, STR_5_SECONDS}, {SCREENDURATION_TEN, STR_10_SECONDS}, @@ -127,24 +134,25 @@ namespace OHOS void DisplayBrightnessPresenter::OnStart() { - + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnStart"); Presenter::OnStart(); } void DisplayBrightnessPresenter::OnPause(void) { - + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnPause"); Presenter::OnPause(); } void DisplayBrightnessPresenter::OnResume(void) { - + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnResume"); Presenter::OnResume(); } void DisplayBrightnessPresenter::OnStop(void) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnStop"); Presenter::OnStop(); } @@ -159,11 +167,11 @@ namespace OHOS } if (strcmp(view.GetViewId(), BRINGHTNESSCONTROLBUTTON_VIEW) == 0) { - NativeAbility::GetInstance().EnterSlice(VIEW_BRIGHTNESSLEVEL); + NativeAbility::GetInstance().EnterSlice(VIEW_BRIGHTNESSLEVEL); /*切换到亮度调节slice*/ } else if (strcmp(view.GetViewId(), SCREENDURATIONBUTTON_VIEWID) == 0) { - p_DisplayBrightnessView->ChangeView(DISPLAYBRIGHTNESSVIEW, SCREENDURATIONVIEW); // 切换到亮屏时长视图 + p_DisplayBrightnessView->ChangeView(DISPLAYBRIGHTNESSVIEW, SCREENDURATIONVIEW); // 屏幕与亮度视图切换到亮屏时长视图 } return true; } @@ -181,7 +189,13 @@ namespace OHOS bool DisplayBrightnessPresenter::OnDragEnd(UIView &view, const DragEvent &event) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnDragEnd"); DisplayBrightnessView *p_DisplayBrightnessView = DisplayBrightnessView::GetInstance(); + if (p_DisplayBrightnessView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView GetInstance fail"); + return false; + } if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && DisplayBrightnessPresenter::X_DRAG_FLAG) { if (strcmp(view.GetViewId(), SCREENDURATIONSCROLLVIEW) == 0) @@ -203,12 +217,12 @@ namespace OHOS switch (state) { case UICheckBox::SELECTED: - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Raise to Wake switched on!"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Raise to Wake switched on!"); uapi_take_to_wake(WRIST_RAISE_TO_WAKE_ENABLED); ConfigModel::GetInstance()->SetRaiseToWake(true); break; case UICheckBox::UNSELECTED: - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Raise to Wake switched off!"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Raise to Wake switched off!"); uapi_take_to_wake(WRIST_RAISE_TO_WAKE_DISENABLED); ConfigModel::GetInstance()->SetRaiseToWake(false); break; @@ -281,4 +295,48 @@ namespace OHOS return true; } + + bool ScreenDurationRadiobuttonOnChangeListener::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScreenDurationRadiobuttonOnChangeListener::OnClick"); + UIButton *button = dynamic_cast(&view); + if (button == nullptr) + { + return false; + } + + DisplayBrightnessView *p_DisplayBrightnessView = DisplayBrightnessView::GetInstance(); + if (p_DisplayBrightnessView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::GetInstance fail!"); + return false; + } + + ScreenDurationView *p_ScreenDurationView = p_DisplayBrightnessView->GetScreenDurationView(); + if (p_ScreenDurationView == nullptr) + { + return false; // 相关视图不存在,直接返回 + } + // 关联单选按钮视图和对应的持续时间 + std::map durationMap = { + {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton1), ScreenDurationRadioButton1}, + {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton2), ScreenDurationRadioButton2}, + {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton3), ScreenDurationRadioButton3}, + {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton4), ScreenDurationRadioButton4}, + {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton5), ScreenDurationRadioButton5}, + {p_ScreenDurationView->GetScreenDurationButton(ScreenDurationRadioButton6), ScreenDurationRadioButton6}}; + + auto it = durationMap.find((UIButton *)button); + if (it != durationMap.end()) + { + p_ScreenDurationView->SetRadioButtonSelectStatus(it->second); + } + else + { + // 如果没有找到对应的映射项,可能是逻辑错误或数据不一致 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Logic error or data inconsistency."); + } + + return true; + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp index 022e1556b..7fdfd3474 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp @@ -3,20 +3,20 @@ #include "wearable_log.h" #include "ConfigModel.h" #include "ui_resource_string.h" +#include namespace OHOS { static DisplayBrightnessView *g_pDisplayBrightnessView{nullptr}; DisplayBrightnessView::DisplayBrightnessView() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::DisplayBrightnessView"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::DisplayBrightnessView"); g_pDisplayBrightnessView = this; } DisplayBrightnessView::~DisplayBrightnessView() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::~DisplayBrightnessView"); - ClearAll(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::~DisplayBrightnessView"); g_pDisplayBrightnessView = nullptr; } @@ -67,6 +67,11 @@ namespace OHOS delete DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]; DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW] = nullptr; } + if (p_ScreenDurationView != nullptr) + { + delete p_ScreenDurationView; + p_ScreenDurationView = nullptr; + } } // 显示与亮度视图scrollView初始化 @@ -85,6 +90,8 @@ namespace OHOS DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->SetDirection(1); DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->SetMaxScrollDistance(1000); DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->SetThrowDrag(true); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->RequestFocus(); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->SetRotateFactor(2); UIView::OnDragListener *draglistener = static_cast(DisplayBrightnessPresenter::GetInstance()); if (draglistener == nullptr) { @@ -108,13 +115,13 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::DisplayBrightnessTitleLabel new fail!"); return false; } - DisplayBrightnessTitleLabel->SetPosition(83, 52, 300, 35); + DisplayBrightnessTitleLabel->SetPosition(83, 50, 300, 35); DisplayBrightnessTitleLabel->SetStyle(STYLE_BACKGROUND_OPA, 0xff); DisplayBrightnessTitleLabel->SetStyle(STYLE_TEXT_FONT, 30); DisplayBrightnessTitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35); - // DisplayBrightnessTitleLabel->SetText("屏幕与亮度"); - DisplayBrightnessTitleLabel->SetTextId(STR_SCREEN_AND_BRIGHTNESS); - DisplayBrightnessTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + DisplayBrightnessTitleLabel->SetTextId(STR_SCREEN_AND_BRIGHTNESS); /*屏幕与亮度*/ + DisplayBrightnessTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + DisplayBrightnessTitleLabel->SetRollSpeed(70); DisplayBrightnessTitleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); DisplayBrightnessTitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); return true; @@ -135,7 +142,6 @@ namespace OHOS button->SetViewId(buttonconfig.ViewId); button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); button->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - // button->SetImageSrc(buttonconfig.ImageSrc, buttonconfig.ImageSrc); button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); button->SetOnClickListener(clickListener); return button; @@ -146,8 +152,6 @@ namespace OHOS /// @return true 设置成功,false 失败 bool DisplayBrightnessView::InitDisplayBrightnessViewButton(void) { - /* -------------------------------------------------------------------------- */ - UIView::OnClickListener *clickListener = static_cast(DisplayBrightnessPresenter::GetInstance()); /* -------------------------------------------------------------------------- */ ButtonConfig buttonconfig; buttonconfig.x = 43; @@ -155,8 +159,7 @@ namespace OHOS buttonconfig.w = 380; buttonconfig.h = 100; buttonconfig.ViewId = BRINGHTNESSCONTROLBUTTON_VIEW; - // buttonconfig.ImageSrc = "/user/res/SETTING_BACKGROUND.bin"; - BringhtnessControlButton = SetTheButton(buttonconfig, clickListener); + BringhtnessControlButton = SetTheButton(buttonconfig, presenter_); if (nullptr == BringhtnessControlButton) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::BringhtnessControlButton new fail!"); @@ -165,7 +168,7 @@ namespace OHOS /* -------------------------------------------------------------------------- */ buttonconfig.y = 240; buttonconfig.ViewId = SCREENDURATIONBUTTON_VIEWID; - ScreenDurationButton = SetTheButton(buttonconfig, clickListener); + ScreenDurationButton = SetTheButton(buttonconfig, presenter_); if (nullptr == ScreenDurationButton) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::ScreenDurationButton new fail!"); @@ -185,11 +188,9 @@ namespace OHOS label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); // 位置大小 label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); // 字体大小 label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); // 字体行高 - // label->SetText(labelconfig.text.c_str()); // 内容 label->SetTextId(labelconfig.textId); label->SetLineBreakMode(labelconfig.lineBreakMode); // 断行模式。 - // label->SetRollSpeed(40); - // label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetRollSpeed(70); label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); return label; } @@ -206,9 +207,8 @@ namespace OHOS .height = 35, .fontSize = 30, .lineHeigh = 35, - //.text = "亮度调节", - .textId = STR_BRIGHTNESS_ADJUSTMENT, - .lineBreakMode = UILabel::LINE_BREAK_MARQUEE, + .textId = STR_BRIGHTNESS_ADJUSTMENT, /*亮度调节*/ + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, }; BringhtnessControlLabel = SetUpLabel(labelconfig); if (BringhtnessControlLabel == nullptr) @@ -219,8 +219,7 @@ namespace OHOS /* -------------------------------------------------------------------------- */ labelconfig.top = 273; labelconfig.width = 180; - // labelconfig.text = "亮屏时长"; - labelconfig.textId = STR_SCREEN_ON_DURATION; + labelconfig.textId = STR_SCREEN_ON_DURATION; /*亮屏时长*/ ScreenDurationLabel = SetUpLabel(labelconfig); if (ScreenDurationLabel == nullptr) { @@ -229,8 +228,7 @@ namespace OHOS } /* -------------------------------------------------------------------------- */ labelconfig.top = 393; - // labelconfig.text = "抬腕亮屏"; - labelconfig.textId = STR_RAISE_TO_WAKE; + labelconfig.textId = STR_RAISE_TO_WAKE; /*抬腕亮屏*/ RaiseToBrightnessLabel = SetUpLabel(labelconfig); if (RaiseToBrightnessLabel == nullptr) { @@ -245,9 +243,8 @@ namespace OHOS .height = 40, .fontSize = 30, .lineHeigh = 35, - //.text = "", .textId = 0, - .lineBreakMode = UILabel::LINE_BREAK_MARQUEE, + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, }; selectScreenDurationLabel = SetUpLabel(labelconfig); if (selectScreenDurationLabel == nullptr) @@ -278,13 +275,12 @@ namespace OHOS /// @return true 设置成功,false 失败 bool DisplayBrightnessView::InitDisplayBrightnessViewImage(void) { - const char *NextImageSrc = "/user/res/SETTING_NEXT.bin"; ImageConfig imageconfig = { .x = 369, .y = 157, .w = 14, .h = 26, - .ImageSrc = NextImageSrc, + .ImageSrc = PNG_SETTING_NEXT_IMAGE, }; NextImage[0] = SetUpImageView(imageconfig); if (nullptr == NextImage[0]) @@ -306,7 +302,7 @@ namespace OHOS .y = 360, .w = 380, .h = 100, - .ImageSrc = "/user/res/SETTING_BACKGROUND.bin", + .ImageSrc = PNG_SETTING_BACKGROUND_IMAGE, }; RaiseToBrightnessImage = SetUpImageView(imageconfig); if (nullptr == RaiseToBrightnessImage) @@ -342,8 +338,8 @@ namespace OHOS .w = 100, .h = 50, .ViewId = RAISETOBRIGHTNESSCHECKBOXBUTTON_VIEWID, - .select = "/user/res/TOGGLEBUTTON_ON.bin", - .unselect = "/user/res/TOGGLEBUTTON_OFF.bin", + .select = PNG_TOGGLEBUTTON_ON_IMAGE, + .unselect = PNG_TOGGLEBUTTON_OFF_IMAGE, }; RaiseToBrightnessCheckBoxButton = SetUpCheckBox(checkboxconfig); if (nullptr == RaiseToBrightnessCheckBoxButton) @@ -351,97 +347,92 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::RaiseToBrightnessCheckBoxButton is nullptr"); return false; } - UICheckBox::OnChangeListener *checkBoxListener = static_cast(DisplayBrightnessPresenter::GetInstance()); - RaiseToBrightnessCheckBoxButton->SetOnChangeListener(checkBoxListener); + RaiseToBrightnessCheckBoxButton->SetOnChangeListener(presenter_); return true; } // 显示与亮度视图初始化 void DisplayBrightnessView::DisplayAndBrightnessViewInit() { - if (SetUpScrollView() != true) - { - return; - } - if (SetTheTitle() != true) - { - return; - } - if (InitDisplayBrightnessViewButton() != true) - { - return; - } - if (InitDisplayBrightnessViewLabel() != true) - { - return; - } - if (InitDisplayBrightnessViewImage() != true) - { - return; - } - if (InitDisplayBrightnessViewCheckBox() != true) + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayAndBrightnessViewInit"); + + if (!SetUpScrollView() || !SetTheTitle() || !InitDisplayBrightnessViewButton() || !InitDisplayBrightnessViewLabel() || + !InitDisplayBrightnessViewImage() || !InitDisplayBrightnessViewCheckBox()) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayAndBrightnessViewInit fail!!"); return; } - if (!DisplayBrightnessModel::GetInstance()->UpdateRaiseToBrightnessCheckBoxButtonStatus()) + DisplayBrightnessModel::GetInstance()->UpdateRaiseToBrightnessCheckBoxButtonStatus(); + DisplayBrightnessModel::GetInstance()->UpdateSelectScreenDurationLabel(); + } + + void DisplayBrightnessView::OnStart() + { + View::OnStart(); + if (!initViewStatus) { - return; + DisplayAndBrightnessViewInit(); + initViewStatus = true; } - if (!DisplayBrightnessModel::GetInstance()->UpdateSelectScreenDurationLabel()) + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::DisplayBrightnessPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); + } + + void DisplayBrightnessView::OnSetUpView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::OnSetUpView"); + View::OnSetUpView(); + if (DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView:: OnSetUpView has nullptr"); return; } + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(DisplayBrightnessTitleLabel); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(BringhtnessControlButton); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(ScreenDurationButton); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(BringhtnessControlLabel); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(ScreenDurationLabel); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(selectScreenDurationLabel); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(NextImage[0]); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(NextImage[1]); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(RaiseToBrightnessImage); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(RaiseToBrightnessLabel); + DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(RaiseToBrightnessCheckBoxButton); + RootView::GetInstance()->Add(DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]); + Draw(); } - /// @brief 获取抬腕亮屏按钮状态 - /// @param void - /// @return 获取此复选框的状态。 - UICheckBox::UICheckBoxState DisplayBrightnessView::GetRaiseToBrightnessCheckBoxButtonState(void) + void DisplayBrightnessView::OnTearDownView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::OnTearDownView"); + View::OnTearDownView(); + return; + } + + void DisplayBrightnessView::OnStop() { - return RaiseToBrightnessCheckBoxButton->GetState(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::OnStop"); + View::OnStop(); + RootView::GetInstance()->ClearOnKeyActListener(); + RootView::GetInstance()->RemoveAll(); + ClearAll(); + return; } /// @brief 设置抬腕亮屏按钮状态 /// @param state void DisplayBrightnessView::SetRaiseToBrightnessCheckBoxButtonState(UICheckBox::UICheckBoxState state) { - if (RaiseToBrightnessCheckBoxButton == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RaiseToBrightnessCheckBoxButton is nullptr!"); - return; - } RaiseToBrightnessCheckBoxButton->SetState(state); } - /// @brief 获取显示与亮度视图中的scrollView - /// @param i 第几个scrollView - /// @return 第几个scrollView的指针 - UIScrollView *DisplayBrightnessView::GetDisplayBrightnessScrollView(int16_t i) - { - if (DisplayBrightnessScrollView[i] == nullptr) - { - return nullptr; - } - return DisplayBrightnessScrollView[i]; - } - ScreenDurationView *DisplayBrightnessView::GetScreenDurationView(void) { - if (p_ScreenDurationView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::GetScreenDurationView p_ScreenDurationView is nullptr!"); - return nullptr; - } - return p_ScreenDurationView.get(); + return p_ScreenDurationView; } UILabelExt *DisplayBrightnessView::GetSelectScreenDurationLabel(void) { - if (selectScreenDurationLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::GetSelectScreenDurationLabel selectScreenDurationLabel is nullptr!"); - return nullptr; - } return selectScreenDurationLabel; } @@ -462,7 +453,7 @@ namespace OHOS if (DisplayBrightnessScrollView[thisView] == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView::ChangeScreenDurationView"); - p_ScreenDurationView = std::make_shared(); + p_ScreenDurationView = new ScreenDurationView(); if (p_ScreenDurationView == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView:: new scrollView[%d] fail", thisView); @@ -474,7 +465,6 @@ namespace OHOS return true; } - /* -------------------------------------------------------------------------- */ // 1.DisplayBrightnessViewMapper:结构体定义了一个将视图ID映射到特定成员函数指针的映射表。 struct DisplayBrightnessViewMapper { @@ -520,56 +510,4 @@ namespace OHOS DisplayBrightnessScrollView[showView]->SetVisible(true); Draw(); } - /* -------------------------------------------------------------------------- */ - - void DisplayBrightnessView::OnStart() - { - View::OnStart(); - if (!initViewStatus) - { - DisplayAndBrightnessViewInit(); - initViewStatus = true; - } - RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::DisplayBrightnessPresenter::GetInstance(); - RootView::GetInstance()->SetOnKeyActListener(keyactListener); - } - - void DisplayBrightnessView::OnSetUpView() - { - View::OnSetUpView(); - if (DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW] == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessView:: OnSetUpView has nullptr"); - return; - } - DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(DisplayBrightnessTitleLabel); - DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(BringhtnessControlButton); - DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(ScreenDurationButton); - DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(BringhtnessControlLabel); - DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(ScreenDurationLabel); - DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(selectScreenDurationLabel); - DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(NextImage[0]); - DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(NextImage[1]); - DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(RaiseToBrightnessImage); - DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(RaiseToBrightnessLabel); - DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]->Add(RaiseToBrightnessCheckBoxButton); - RootView::GetInstance()->Add(DisplayBrightnessScrollView[DISPLAYBRIGHTNESSVIEW]); - Draw(); - } - - void DisplayBrightnessView::OnTearDownView() - { - - View::OnTearDownView(); - return; - } - - void DisplayBrightnessView::OnStop() - { - - View::OnStop(); - RootView::GetInstance()->ClearOnKeyActListener(); - RootView::GetInstance()->RemoveAll(); - return; - } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/ScreenDurationView.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/ScreenDurationView.cpp index d1dc43866..546b2ceba 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/ScreenDurationView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/ScreenDurationView.cpp @@ -3,6 +3,7 @@ #include "displaybrightness/include/DisplayBrightnessModel.h" #include "wearable_log.h" #include "ui_resource_string.h" +#include namespace OHOS { @@ -10,13 +11,13 @@ namespace OHOS ScreenDurationView::ScreenDurationView() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationView"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationView"); g_pScreenDurationView = this; } ScreenDurationView::~ScreenDurationView() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::~ScreenDurationView"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::~ScreenDurationView"); ClearAll(); g_pScreenDurationView = nullptr; } @@ -30,43 +31,61 @@ namespace OHOS { if (initViewStatus == true) { - ScreenDurationScrollView->RemoveAll(); - - delete ScreenDurationTitleLabel; - ScreenDurationTitleLabel = nullptr; - - for (int i = 0; i < DURATIONS; i++) + if (ScreenDurationScrollView != nullptr) { - delete ScreenDurationLabel[i]; - ScreenDurationLabel[i] = nullptr; - - delete BackGroundImage[i]; - BackGroundImage[i] = nullptr; - - delete SimplifiedChineseRadioButtonChange[i]; - SimplifiedChineseRadioButtonChange[i] = nullptr; - - delete ScreenDurationRadioButton[i]; - ScreenDurationRadioButton[i] = nullptr; + ScreenDurationScrollView->RemoveAll(); + if (ScreenDurationTitleLabel != nullptr) + { + delete ScreenDurationTitleLabel; + ScreenDurationTitleLabel = nullptr; + } + for (int i = 0; i < DURATIONS; i++) + { + if (ScreenDurationLabel[i] != nullptr) + { + delete ScreenDurationLabel[i]; + ScreenDurationLabel[i] = nullptr; + } + if (ScreenDurationButton[i]) + { + delete ScreenDurationButton[i]; + ScreenDurationButton[i] = nullptr; + } + if (SimplifiedChineseRadioButtonChange[i] != nullptr) + { + delete SimplifiedChineseRadioButtonChange[i]; + SimplifiedChineseRadioButtonChange[i] = nullptr; + } + if (ScreenDurationRadioButton[i]) + { + delete ScreenDurationRadioButton[i]; + ScreenDurationRadioButton[i] = nullptr; + } + } + if (ScreenDurationButtonClickListener != nullptr) + { + delete ScreenDurationButtonClickListener; + ScreenDurationButtonClickListener = nullptr; + } + delete ScreenDurationScrollView; + ScreenDurationScrollView = nullptr; } - delete ScreenDurationScrollView; - ScreenDurationScrollView = nullptr; } } // 设置图片 - UIImageView *ScreenDurationView::SetUpImageView(ImageConfig &imageconfig) + UIButton *ScreenDurationView::SetUpButtonView(ButtonConfig &buttonConfig) { - UIImageView *Image = new UIImageView(); - if (Image == nullptr) + UIButton *button = new UIButton(); + if (button == nullptr) { return nullptr; } - Image->SetPosition(imageconfig.x, imageconfig.y, imageconfig.w, imageconfig.h); - Image->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - Image->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - Image->SetStyle(STYLE_BORDER_RADIUS, 100); - return Image; + button->SetPosition(buttonConfig.x, buttonConfig.y, buttonConfig.w, buttonConfig.h); + button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); + + return button; } // 设置标签 @@ -80,10 +99,9 @@ namespace OHOS label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); // 位置大小 label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); // 字体大小 label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); // 字体行高 - // label->SetText(labelconfig.text); // 内容 - label->SetTextId(labelconfig.textId); // 内容 - label->SetLineBreakMode(labelconfig.lineBreakMode); // 断行模式。 - // label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetTextId(labelconfig.textId); // 内容 + label->SetLineBreakMode(labelconfig.lineBreakMode); // 断行模式。 + label->SetRollSpeed(70); label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); return label; } @@ -118,6 +136,8 @@ namespace OHOS ScreenDurationScrollView->SetDirection(1); ScreenDurationScrollView->SetMaxScrollDistance(1000); ScreenDurationScrollView->SetThrowDrag(true); + ScreenDurationScrollView->RequestFocus(); + ScreenDurationScrollView->SetRotateFactor(2); UIView::OnDragListener *draglistener = static_cast(DisplayBrightnessPresenter::GetInstance()); if (draglistener == nullptr) { @@ -133,22 +153,25 @@ namespace OHOS // 亮屏时长视图“图片”初始化 bool ScreenDurationView::SetUpScreenDurationViewImageView(void) { - ImageConfig imageconfig = { + ButtonConfig buttonConfig = { .x = 39, .y = 120, .w = 380, .h = 100, }; + ScreenDurationButtonClickListener = static_cast(new ScreenDurationRadiobuttonOnChangeListener()); + for (int i = 0; i < DURATIONS; i++) { - imageconfig.y = 120 + (i * 120); - BackGroundImage[i] = SetUpImageView(imageconfig); - if (BackGroundImage[i] == nullptr) + buttonConfig.y = 120 + (i * 120); + ScreenDurationButton[i] = SetUpButtonView(buttonConfig); + if (ScreenDurationButton[i] == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::BackGroundImage[%d] is nullptr!", i); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationButton[%d] is nullptr!", i); return false; } + ScreenDurationButton[i]->SetOnClickListener(ScreenDurationButtonClickListener); } return true; } @@ -159,14 +182,13 @@ namespace OHOS // 创建ScreenDurationTitleLabel LabelConfig labelconfig = { .left = 83, - .top = 52, + .top = 50, .width = 300, .height = 35, .fontSize = 30, .lineHeigh = 35, - //.text = "亮屏时长", - .textId = STR_SCREEN_ON_DURATION, - .lineBreakMode = UILabel::LINE_BREAK_MARQUEE, + .textId = STR_SCREEN_ON_DURATION, /*亮屏时长*/ + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, }; ScreenDurationTitleLabel = SetUpLabel(labelconfig); @@ -186,7 +208,7 @@ namespace OHOS .fontSize = 30, .lineHeigh = 35, .textId = STR_SCREEN_ON_DURATION, - .lineBreakMode = UILabel::LINE_BREAK_MARQUEE, + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, }; // const char *durations[DURATIONS] = {"5秒", "10秒", "15秒", "30秒", "60秒", "300秒"}; @@ -215,8 +237,8 @@ namespace OHOS .x = 300, .w = 80, .h = 80, - .select = "/user/res/CHECKBOX_ON.bin", - .unselect = "/user/res/CHECKBOX_OFF.bin", + .select = PNG_CHECKBOX_ON_IMAGE, + .unselect = PNG_CHECKBOX_OFF_IMAGE, }; int y_positions = 130; @@ -236,68 +258,66 @@ namespace OHOS return true; } - // 设置哪个单选按钮被选中 - void ScreenDurationView::SetRadioButtonSelectStatus(int16_t i) + // 亮屏时长视图初始化 + UIScrollView *ScreenDurationView::ScreenDurationViewInit(void) { - if (GetRadioButton(i) != nullptr) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationViewInit"); + if (!SetUpScrollView() || !SetUpScreenDurationViewImageView() || + !SetUpScreenDurationViewLabel() || !SetUpScreenDurationViewRadioButton()) { - GetRadioButton(i)->SetState(UICheckBox::SELECTED); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationViewInit fail!!"); + return nullptr; } - else + + if (!DisplayBrightnessModel::GetInstance()->UpdateScreenDurationRadioButtonSlectStatus()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::GetRadioButton(%d) is nullptr!", i); + return nullptr; } - } - UIRadioButton *ScreenDurationView::GetRadioButton(int16_t i) - { - if (ScreenDurationRadioButton[i] == nullptr) + /* ----------------------------------- Add ---------------------------------- */ + ScreenDurationScrollView->Add(ScreenDurationTitleLabel); + for (int i = 0; i < DURATIONS; i++) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationRadioButton[%d] is nullptr!", i); - return nullptr; + ScreenDurationScrollView->Add(ScreenDurationButton[i]); + ScreenDurationScrollView->Add(ScreenDurationLabel[i]); + ScreenDurationScrollView->Add(ScreenDurationRadioButton[i]); } - return ScreenDurationRadioButton[i]; + initViewStatus = true; + return ScreenDurationScrollView; } - // 亮屏时长视图初始化 - UIScrollView *ScreenDurationView::ScreenDurationViewInit(void) + // 设置哪个单选按钮被选中 + void ScreenDurationView::SetRadioButtonSelectStatus(int16_t index) { - /* ------------------------ ScreenDurationScrollView ------------------------ */ - if (!SetUpScrollView()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationScrollView is nullptr!"); - return nullptr; - } - /* ----------------------------- BackGroundImage[] ---------------------------- */ - if (!SetUpScreenDurationViewImageView()) + if (index >= DURATIONS || index < 0) { - return nullptr; + return; } - /* -------------------------- ScreenDurationLabel[] ------------------------- */ - if (!SetUpScreenDurationViewLabel()) + + if (ScreenDurationRadioButton[index] == nullptr) { - return nullptr; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationRadioButton[%d] is nullptr!", index); + return; } - /* ----------------------- ScreenDurationRadioButton[] ---------------------- */ - if (!SetUpScreenDurationViewRadioButton()) + + for (int i = 0; i < DURATIONS; i++) { - return nullptr; + ScreenDurationRadioButton[i]->SetState(i == index ? UICheckBox::SELECTED : UICheckBox::UNSELECTED); } + } - if (!DisplayBrightnessModel::GetInstance()->UpdateScreenDurationRadioButtonSlectStatus()) + UIRadioButton *ScreenDurationView::GetRadioButton(int16_t i) + { + if (ScreenDurationRadioButton[i] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScreenDurationView::ScreenDurationRadioButton[%d] is nullptr!", i); return nullptr; } + return ScreenDurationRadioButton[i]; + } - /* ----------------------------------- Add ---------------------------------- */ - ScreenDurationScrollView->Add(ScreenDurationTitleLabel); - for (int i = 0; i < DURATIONS; i++) - { - ScreenDurationScrollView->Add(BackGroundImage[i]); - ScreenDurationScrollView->Add(ScreenDurationLabel[i]); - ScreenDurationScrollView->Add(ScreenDurationRadioButton[i]); - } - initViewStatus = true; - return ScreenDurationScrollView; + UIButton *ScreenDurationView::GetScreenDurationButton(int16_t i) + { + return ScreenDurationButton[i]; } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/languagecode/src/LanguageSwitchPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/languagecode/src/LanguageSwitchPresenter.cpp index fa31424c7..c7baeb376 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/languagecode/src/LanguageSwitchPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/languagecode/src/LanguageSwitchPresenter.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-28 14:17:43 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-20 18:11:50 + * @LastEditTime: 2024-07-22 19:03:52 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/languagecode/src/LanguageSwitchPresenter.cpp */ #include "AppViewIDs.h" @@ -14,6 +14,7 @@ #include #include "languagecode/LanguageInit.h" #include "ConfigModel.h" +#include "settings/include/SettingModel.h" namespace OHOS { extern Language languages[]; @@ -94,10 +95,19 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RespiratoryTrainingPresenter::OnClick"); /* -------------------------------------------------------------------------- */ - if (ConfigModel::GetInstance()->GetisFirstTimeStart() == true) + if (ConfigModel::GetInstance()->GetisFirstTimeStart() == true && SettingModel::GetInstance().GetPhoneConnectStatus() == false) { NativeAbility::GetInstance().EnterSlice(VIEW_WATCH_QR_CODE); } + else if(ConfigModel::GetInstance()->GetisFirstTimeStart() == true && SettingModel::GetInstance().GetPhoneConnectStatus() == true) + { + if (ConfigModel::GetInstance()->GetLanguage() == -1) + { + uapi_set_screen_on_api(); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); + ConfigModel::GetInstance()->SetisFirstTimeStart(false); + } + } /* -------------------------------------------------------------------------- */ UNUSED(event); diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/include/FactoryResetView.h b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/include/FactoryResetView.h index d6199e585..91f8a8097 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/include/FactoryResetView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/include/FactoryResetView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-07-20 14:12:16 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-20 14:54:48 + * @LastEditTime: 2024-07-22 09:33:26 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/include/FactoryResetVIew.h * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ @@ -17,6 +17,7 @@ #include "components/ui_button.h" #include "components/ui_view_group.h" #include "components/ui_label_ext.h" +#include "components/ui_scroll_view.h" namespace OHOS { static constexpr const char *FACTORY_RESET_GROUPVIEW = "FactoryResetGroupView"; @@ -35,6 +36,7 @@ namespace OHOS private: UIViewGroup *group{nullptr}; + UIScrollView*scrollView{nullptr}; UILabelExt *Title{nullptr}; UIImageView *FactoryResetImage{nullptr}; UILabelExt *FactoryResetNote{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/include/RebootAndShutdownModel.h b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/include/RebootAndShutdownModel.h index 2702c8187..d1393fdbf 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/include/RebootAndShutdownModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/include/RebootAndShutdownModel.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-07-18 14:55:21 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-20 18:53:51 + * @LastEditTime: 2024-07-22 10:28:51 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/include/RebootAndShutdownModel.h */ @@ -16,12 +16,21 @@ namespace OHOS public: static RebootAndShutdownModel &GetInstance(void); void HandFirstTimeStartJumpToMainView(void); + void RegisterAllKeyEvents(void); private: RebootAndShutdownModel(); ~RebootAndShutdownModel(); RebootAndShutdownModel(const RebootAndShutdownModel &) = delete; RebootAndShutdownModel &operator=(const RebootAndShutdownModel &) = delete; + + bool RegisterPowerKeyLongPressEvent(void); + bool RegisterPowerKeyDoubleClickEvent(void); + bool RegisterFuncKeyPressEvent(void); + bool RegisterFuncKeyLongPressEvent(void); + bool RegisterFuncKeyClickEvent(void); + bool RegisterFuncKeyDoubleClickEvent(void); + }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/FactoryResetView.cpp b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/FactoryResetView.cpp index b09d102cb..06a74c4bf 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/FactoryResetView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/FactoryResetView.cpp @@ -31,37 +31,41 @@ namespace OHOS { if (initViewStatus == true) { - group->RemoveAll(); - - if (Title != nullptr) + if (scrollView != nullptr) { - delete Title; - Title = nullptr; - } + scrollView->RemoveAll(); + if (Title != nullptr) + { + delete Title; + Title = nullptr; + } - if (FactoryResetImage != nullptr) - { - delete FactoryResetImage; - FactoryResetImage = nullptr; - } + if (FactoryResetImage != nullptr) + { + delete FactoryResetImage; + FactoryResetImage = nullptr; + } - if (FactoryResetNote != nullptr) - { - delete FactoryResetNote; - FactoryResetNote = nullptr; - } + if (FactoryResetNote != nullptr) + { + delete FactoryResetNote; + FactoryResetNote = nullptr; + } - if (FactoryResetButtonCheckOn != nullptr) - { - delete FactoryResetButtonCheckOn; - FactoryResetButtonCheckOn = nullptr; + if (FactoryResetButtonCheckOn != nullptr) + { + delete FactoryResetButtonCheckOn; + FactoryResetButtonCheckOn = nullptr; + } + if (FactoryResetButtonCheckOff != nullptr) + { + delete FactoryResetButtonCheckOff; + FactoryResetButtonCheckOff = nullptr; + } + group->Remove(scrollView); + delete scrollView; + scrollView = nullptr; } - if (FactoryResetButtonCheckOff != nullptr) - { - delete FactoryResetButtonCheckOff; - FactoryResetButtonCheckOff = nullptr; - } - delete group; group = nullptr; } @@ -91,6 +95,21 @@ namespace OHOS return nullptr; } group->SetOnDragListener(dragListener); + /* ------------------------------- scrollView ------------------------------- */ + scrollView = new UIScrollView(); + if (scrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FactoryResetView::scrollView new fail!"); + return nullptr; + } + scrollView->SetPosition(0, 0, 466, 466); + scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollView->SetScrollBlankSize(50); + scrollView->SetReboundSize(35); + scrollView->SetMaxScrollDistance(1000); + scrollView->SetThrowDrag(true); + scrollView->RequestFocus(); + scrollView->SetRotateFactor(2); /* ---------------------------------- Title --------------------------------- */ Title = new UILabelExt(); if (Title == nullptr) @@ -137,10 +156,11 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FactoryResetView::new FactoryResetButtonCheckOff fail!"); return nullptr; } - FactoryResetButtonCheckOff->SetPosition(97, 320, 130, 130); + FactoryResetButtonCheckOff->SetPosition(97, FactoryResetNote->GetTextHeight() + FactoryResetNote->GetY() + 30, 130, 130); FactoryResetButtonCheckOff->SetViewId(FACTORY_RESET_BUTTON_CHECK_OFF); FactoryResetButtonCheckOff->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); FactoryResetButtonCheckOff->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + FactoryResetButtonCheckOff->SetImagePosition(15, 15); FactoryResetButtonCheckOff->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED); FactoryResetButtonCheckOff->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); FactoryResetButtonCheckOff->SetImageSrc(PNG_SYSTEM_CHECK_OFF_IMAGE, PNG_SYSTEM_CHECK_OFF_IMAGE); @@ -158,10 +178,11 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FactoryResetView::new FactoryResetButtonCheckOn fail!"); return nullptr; } - FactoryResetButtonCheckOn->SetPosition(240, 320, 130, 130); + FactoryResetButtonCheckOn->SetPosition(240, FactoryResetButtonCheckOff->GetY(), 130, 130); FactoryResetButtonCheckOn->SetViewId(FACTORY_RESET_BUTTON_CHECK_ON); FactoryResetButtonCheckOn->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); FactoryResetButtonCheckOn->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + FactoryResetButtonCheckOn->SetImagePosition(15, 15); FactoryResetButtonCheckOn->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED); FactoryResetButtonCheckOn->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); FactoryResetButtonCheckOn->SetImageSrc(PNG_SYSTEM_CHECK_ON_IMAGE, PNG_SYSTEM_CHECK_ON_IMAGE); @@ -174,11 +195,12 @@ namespace OHOS FactoryResetButtonCheckOn->SetOnClickListener(FactoryResetButtonCheckOnClick); /* ----------------------------- Add to scroView ---------------------------- */ - group->Add(Title); - group->Add(FactoryResetImage); - group->Add(FactoryResetNote); - group->Add(FactoryResetButtonCheckOff); - group->Add(FactoryResetButtonCheckOn); + scrollView->Add(Title); + scrollView->Add(FactoryResetImage); + scrollView->Add(FactoryResetNote); + scrollView->Add(FactoryResetButtonCheckOff); + scrollView->Add(FactoryResetButtonCheckOn); + group->Add(scrollView); initViewStatus = true; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp index 618de55c9..227c699be 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-07-18 14:55:27 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-20 18:55:10 + * @LastEditTime: 2024-07-22 18:52:05 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp */ @@ -12,6 +12,9 @@ #include "NativeAbility.h" #include #include "settings/include/SettingModel.h" +#include +#include "themestyle/include/ThemeStyleModel.h" +#include "aimodels/include/AiModelsModel.h" namespace OHOS { RebootAndShutdownModel::RebootAndShutdownModel() {} @@ -24,12 +27,260 @@ namespace OHOS return instance; } + /*处理恢复出厂设置后第一次跳转主界面*/ void RebootAndShutdownModel::HandFirstTimeStartJumpToMainView(void) { - if(ConfigModel::GetInstance()->GetisFirstTimeStart() == true && SettingModel::GetInstance().GetPhoneConnectStatus() == true) + if (ConfigModel::GetInstance()->GetisFirstTimeStart() == true && SettingModel::GetInstance().GetPhoneConnectStatus() == true) { - NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); - ConfigModel::GetInstance()->SetisFirstTimeStart(false); + if (ConfigModel::GetInstance()->GetLanguage() != -1) + { + uapi_set_screen_on_api(); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); + ConfigModel::GetInstance()->SetisFirstTimeStart(false); + } } } + +#ifdef __cplusplus + extern "C" + { +#endif + +#include "input_app.h" +#ifdef __cplusplus + } +#endif +#include + + static void HandlePowerKeyLongPress(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HandlePowerKeyLongPress"); + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (!display_api) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "power_display_svr_get_api returned nullptr"); + return; + } + + if (display_api->get_screen_state() != SCREEN_ON) + { + display_api->turn_on_screen(); + } + + // 切换到关机/重启卡片 + NativeAbility::GetInstance().EnterSlice(VIEW_REBOOTANDSHUTDOWN); + } + + /*注册电源键的长按事件*/ + bool RebootAndShutdownModel::RegisterPowerKeyLongPressEvent(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RebootAndShutdownModel::RegisterPowerKeyLongPressEvent"); + int32_t ret = uapi_button_register_event_cb(HandlePowerKeyLongPress, BUTTON_PWR_LONGPRESS_3S); + if (ret != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register PowerKey LongPress Event error, ret = %d", ret); + return false; + } + return true; + } + + static void HandlePowerKeyDoubleClick(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HandlePowerKeyDoubleClick"); + // Handle PowerKey DoubleClick logic here + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (!display_api) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "power_display_svr_get_api returned nullptr"); + return; + } + + if (display_api->get_screen_state() == SCREEN_ON) + { + 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 + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Screen is not on, skipping applist style change"); + } + } + + /*注册电源键的双击事件*/ + bool RebootAndShutdownModel::RegisterPowerKeyDoubleClickEvent(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RebootAndShutdownModel::RegisterPowerKeyDoubleClickEvent"); + // Register PowerKey DoubleClick event here + int32_t ret = uapi_button_register_event_cb(HandlePowerKeyDoubleClick, BUTTON_PWR_CLICKUP_2); + if (ret != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register PowerKey DoubleClick Event error, ret = %d", ret); + return false; + } + return true; + } + + static void HandFuncKeyOnPress(void) + { + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (!display_api) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "power_display_svr_get_api returned nullptr"); + return; + } + display_api->turn_on_screen(); + // if (display_api->get_screen_state() == SCREEN_OFF) /*处于灭屏状态才亮屏*/ + // { + + // } + // else + // { + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Screen is on not to turn_on_screen"); + // } + return; + } + + /*注册功能键的按下事件*/ + bool RebootAndShutdownModel::RegisterFuncKeyPressEvent(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RebootAndShutdownModel::RegisterFuncKeyPressEvent"); + // Register FuncKey Press event here + int32_t ret = uapi_button_register_event_cb(HandFuncKeyOnPress, BUTTON1_PRESS); + if (ret != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register FuncKey Press Event error, ret = %d", ret); + return false; + } + return true; + } + + static void HandFuncKeyOnLongPress(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HandFuncKeyOnLongPress"); + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (!display_api) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "power_display_svr_get_api returned nullptr"); + return; + } + + if (display_api->get_screen_state() == SCREEN_ON) + { + uint16_t curSliceId = NativeAbility::GetInstance().GetCurSliceId(); + if (curSliceId == VIEW_AI_VOICE) // 如果当前已在ai语音界面不做切换 + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VIEW_AI_VOICE is not switched"); + return; + } + // 全局切换到Ai语音界面 + NativeAbility::GetInstance().EnterSlice(VIEW_AI_VOICE); + } + else + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Screen is not on, skipping AI voice change"); + } + } + + /*注册功能键的长按(2s)事件*/ + bool RebootAndShutdownModel::RegisterFuncKeyLongPressEvent(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RebootAndShutdownModel::RegisterFuncKeyLongPressEvent"); + int32_t ret = uapi_button_register_event_cb(HandFuncKeyOnLongPress, BUTTON1_LONGPRESS_2S); + if (ret != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register FuncKey LongPress Event error, ret = %d", ret); + return false; + } + return true; + } + + static void HandleFuncKeyOnClick(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HandleFuncKeyOnClick"); + + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (!display_api) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "power_display_svr_get_api returned nullptr"); + return; + } + + if (display_api->get_screen_state() == SCREEN_ON) + { + AiModelsModel &aiModelsModel = AiModelsModel::GetInstance(); + if (!aiModelsModel.ChangeAiModel()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to change AI model"); + } + } + else + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Screen is not on, skipping AI model change"); + } + } + + /*注册功能键的单击事件*/ + bool RebootAndShutdownModel::RegisterFuncKeyClickEvent(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RebootAndShutdownModel::RegisterFuncKeyClickEvent"); + int32_t ret = uapi_button_register_event_cb(HandleFuncKeyOnClick, BUTTON1_CLICKUP); + if (ret != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register FuncKey Click Event error, ret = %d", ret); + return false; + } + return true; + } + + static void HandleFuncKeyDoubleClick(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HandleFuncKeyDoubleClick"); + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (!display_api) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "power_display_svr_get_api returned nullptr"); + return; + } + if (display_api->get_screen_state() == SCREEN_ON) + { + // 切换到显示方式界面 + NativeAbility::GetInstance().EnterSlice(VIEW_AI_MODELS); + } + else + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Screen is not on, skipping Slice change"); + } + } + + /*注册功能键双击事件*/ + bool RebootAndShutdownModel::RegisterFuncKeyDoubleClickEvent(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RebootAndShutdownModel::RegisterFuncKeyDoubleClickEvent"); + int32_t ret = uapi_button_register_event_cb(HandleFuncKeyDoubleClick, BUTTON1_CLICKUP_2); + if (ret != ERRCODE_SUCC) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register FuncKey DoubleClick Event error, ret = %d", ret); + return false; + } + return true; + } + + /*注册所有按键事件*/ + void RebootAndShutdownModel::RegisterAllKeyEvents(void) + { + RegisterPowerKeyDoubleClickEvent(); + RegisterPowerKeyLongPressEvent(); + RegisterFuncKeyPressEvent(); + RegisterFuncKeyLongPressEvent(); + RegisterFuncKeyClickEvent(); + RegisterFuncKeyDoubleClickEvent(); + } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingPresenter.h index 3aa1fb87f..fe5692830 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingPresenter.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-02-19 11:58:05 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-03 09:36:58 + * @LastEditTime: 2024-07-22 11:05:00 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingPresenter.h */ #ifndef SETTING_PRESENTER_H @@ -28,13 +28,16 @@ namespace OHOS void OnStart() override; void OnResume() override; + void OnPause() override; void OnStop() override; 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}; }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingView.h b/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingView.h index a3832d716..02d1af315 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-30 09:14:38 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-02 16:39:44 + * @LastEditTime: 2024-07-22 11:13:50 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/settings/include/SettingView.h */ #ifndef SETTING_VIEW_H @@ -34,11 +34,13 @@ namespace OHOS void AddSettingItemToList(const SettingItem &item); private: + void CreateSettingView(void); + void ClearAll(void); SettingAdapter *listAdapter{nullptr}; UIScrollView *scrollView{nullptr}; UIList *contentList{nullptr}; UILabelExt *title{nullptr}; - UIView::OnDragListener *dragListener{nullptr}; + bool viewInitStatus{false}; }; } #endif // SETTING_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingItemView.cpp b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingItemView.cpp index fa0df2e11..f3e53517d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingItemView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingItemView.cpp @@ -2,12 +2,12 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-27 19:48:49 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-28 09:49:17 + * @LastEditTime: 2024-07-22 11:26:36 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingItemView.cpp */ #include "wearable_log.h" -#include "SettingItemView.h" +#include "settings/include/SettingItemView.h" #include "systemupdate/include/SystemUpdateModel.h" namespace OHOS { @@ -22,7 +22,7 @@ namespace OHOS static constexpr int16_t SETTINGLABELEXT_H = 40; static constexpr int16_t SETTINGLABELEXT_TEXT_FONT = 30; static constexpr int16_t SETTINGLABELEXT_LINE_HEIGHT = 35; - static constexpr int16_t SETTINGLABELEXT_ROLLSPEED = 40; + static constexpr int16_t SETTINGLABELEXT_ROLLSPEED = 70; static constexpr int16_t SETTINGLABELBUTTONEXT_X = 0; static constexpr int16_t SETTINGLABELBUTTONEXT_Y = 0; @@ -74,7 +74,8 @@ namespace OHOS 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_MARQUEE); + 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); diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp index 69c7f7c4d..19ba3ac47 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-02-18 09:09:13 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-17 18:34:15 + * @LastEditTime: 2024-07-22 10:51:12 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp */ #include "settings/include/SettingModel.h" @@ -30,7 +30,7 @@ namespace OHOS 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_SYSTEM, PNG_SETTINGS_SYSTEM, STR_SYSTEM, true}; - settings[index++] = {VIEW_SHUTDOWN_OR_REBOOT, PNG_SETTINGS_SHUTDOWN_AND_RESTART, STR_SHUTDOWN_AND_RESTART, true}; + settings[index++] = {VIEW_REBOOTANDSHUTDOWN, PNG_SETTINGS_SHUTDOWN_AND_RESTART, STR_SHUTDOWN_AND_RESTART, true}; usedLen = index; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp index a41033f99..8761ed31f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp @@ -1,3 +1,10 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-06-12 11:44:04 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-07-22 11:08:39 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp + */ /* * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. * Description: SettingPresenter.cpp @@ -5,9 +12,9 @@ * Create: 2021-11-23 */ -#include "SettingView.h" -#include "SettingModel.h" -#include "SettingPresenter.h" +#include "settings/include/SettingView.h" +#include "settings/include/SettingModel.h" +#include "settings/include/SettingPresenter.h" #include "RebootModel.h" #include "common/key_code.h" #include @@ -35,12 +42,14 @@ namespace OHOS void SettingPresenter::OnStart() { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnStart"); Presenter::OnStart(); settingModel->InitSettingItem(); } void SettingPresenter::OnResume(void) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnResume"); if (view_ == nullptr) { return; @@ -52,23 +61,43 @@ namespace OHOS } } + // 页面准备切换到后台前执行的逻辑 + 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) { + 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::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) { - // NativeAbility::GetInstance().Back(); NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + X_DRAG_FLAG = false; } return true; } + // 增加按键事件 bool SettingPresenter::OnKeyAct(UIView &view, const KeyEvent &event) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingView.cpp index 05964964e..02a307348 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingView.cpp @@ -1,15 +1,15 @@ /* - * 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-07-22 11:33:17 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingView.cpp */ #include - -#include "SettingView.h" -#include "SettingItem.h" -#include "SettingPresenter.h" +#include "settings/include/SettingView.h" +#include "settings/include/SettingItem.h" +#include "settings/include/SettingPresenter.h" #include "ui_resource_string.h" namespace OHOS { @@ -23,12 +23,12 @@ namespace OHOS /* --------------------------------- 设置List --------------------------------- */ static constexpr int16_t SETTING_LIST_POSITION_X = 43; static constexpr int16_t SETTING_LIST_POSITION_Y = 120; - static constexpr int16_t SETTING_SCROLLBLANKSIZE = 35; // 设置此滚动视图的空白大小。 + 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 = 40; - static constexpr int16 REBOUNDSIZE = 30; + static constexpr int16 ROLLSPEED = 70; + static constexpr int16 REBOUNDSIZE = 35; SettingView::SettingView() { @@ -38,45 +38,61 @@ namespace OHOS SettingView::~SettingView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::~SettingView"); - if (scrollView != nullptr) - { - scrollView->RemoveAll(); - delete scrollView; - scrollView = nullptr; - } - - if (title != nullptr) - { - delete title; - title = nullptr; - } - - if (listAdapter != nullptr) - { - delete listAdapter; - listAdapter = nullptr; - } - - if (contentList != nullptr) - { - delete contentList; - contentList = nullptr; - } + } - if (dragListener != nullptr) + void SettingView::ClearAll(void) + { + if (viewInitStatus) { - delete dragListener; - dragListener = nullptr; + if (container_ != nullptr) + { + container_->RemoveAll(); + if (scrollView != nullptr) + { + scrollView->RemoveAll(); + if (title != nullptr) + { + delete title; + title = nullptr; + } + if (listAdapter != nullptr) + { + delete listAdapter; + listAdapter = nullptr; + } + if (contentList != nullptr) + { + delete contentList; + contentList = nullptr; + } + delete scrollView; + scrollView = nullptr; + } + delete container_; + container_ = nullptr; + } } } - void SettingView::OnStart() + void SettingView::CreateSettingView(void) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart"); - View::OnStart(); - - BaseView::RootView(Color::Black().full); - + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::CreateSettingView"); + /* -------------------------------------------------------------------------- */ + scrollView = new UIScrollView(); + 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->SetScrollBlankSize(SETTING_SCROLLBLANKSIZE); + scrollView->SetHorizontalScrollState(false); + scrollView->SetTouchable(true); + scrollView->SetThrowDrag(true); + scrollView->SetOnDragListener(presenter_); + /* -------------------------------------------------------------------------- */ title = new UILabelExt(); if (title == nullptr) { @@ -84,11 +100,10 @@ namespace OHOS return; } title->SetPosition(SETTING_TITLE_POSITION_X, SETTING_TITLE_POSITION_Y, SETTING_TITLE_SIZE_WIDTH, SETTING_TITLE_SIZE_HEIGHT); - // title->SetText("设置"); - title->SetTextId(STR_SETTINGS); + title->SetTextId(STR_SETTINGS); /*设置*/ title->SetStyle(STYLE_TEXT_FONT, SETTINGS_TITLE_FONT_SIZE); title->SetStyle(STYLE_LINE_HEIGHT, SETTINGS_TITLE_FONT_HEIGHT); - title->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + title->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); title->SetRollSpeed(ROLLSPEED); title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, SETTINGS_TITLE_FONT_SIZE); title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); @@ -116,36 +131,31 @@ namespace OHOS contentList->SetSelectPosition(HORIZONTAL_RESOLUTION / SNUM_2); // middle position contentList->SetDraggable(true); contentList->SetThrowDrag(true); - contentList->EnableAutoAlign(true); contentList->SetReboundSize(REBOUNDSIZE); - contentList->SetMaxScrollDistance(MAX_SCR_DIS / SNUM_2); + contentList->SetMaxScrollDistance(MAX_SCR_DIS); + contentList->RequestFocus(); + contentList->SetRotateFactor(2); + } - scrollView = new UIScrollView(); - if (scrollView == nullptr) + void SettingView::OnStart() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart"); + View::OnStart(); + SetContainerView(new UIViewGroup()); + if (GetContainer() == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::scrollView is nullptr"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetContainerView fail!!"); return; } - scrollView->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - scrollView->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - scrollView->SetStyle(STYLE_BACKGROUND_OPA, UN_OPACITY); - scrollView->SetScrollBlankSize(SETTING_SCROLLBLANKSIZE); - scrollView->SetHorizontalScrollState(false); - scrollView->SetTouchable(true); - scrollView->SetThrowDrag(true); - - dragListener = new SettingPresenter(); - if (dragListener == nullptr) + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + if (!viewInitStatus) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView:: OnStart::new dragListener is nullptr"); - return; + CreateSettingView(); + viewInitStatus = true; } - scrollView->SetOnDragListener(dragListener); - // scrollView->SetYScrollBarVisible(true); // 增加按键监听 - RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::SettingPresenter::GetInstance(); - RootView::GetInstance()->SetOnKeyActListener(keyactListener); + RootView::GetInstance()->SetOnKeyActListener(presenter_); } void SettingView::OnSetUpView() @@ -159,10 +169,9 @@ namespace OHOS } scrollView->Add(title); scrollView->Add(contentList); - RootView::GetInstance()->Add(scrollView); contentList->SetAdapter(listAdapter); - container_ = scrollView; - + container_->Add(scrollView); + Draw(); return; } @@ -170,7 +179,6 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::OnTearDownView"); View::OnTearDownView(); - Draw(); return; } @@ -179,7 +187,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingView::OnStop"); View::OnStop(); RootView::GetInstance()->ClearOnKeyActListener(); - RootView::GetInstance()->RemoveAll(); + ClearAll(); return; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemFactoryResetView.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemFactoryResetView.cpp index 249133539..e0002e5a7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemFactoryResetView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemFactoryResetView.cpp @@ -64,6 +64,12 @@ namespace OHOS scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); scrollView->SetStyle(STYLE_BORDER_RADIUS, 100); + scrollView->SetScrollBlankSize(50); + scrollView->SetReboundSize(35); + scrollView->SetMaxScrollDistance(1000); + scrollView->SetThrowDrag(true); + scrollView->RequestFocus(); + scrollView->SetRotateFactor(2); UIView::OnDragListener *dragListener = static_cast(SystemPresenter::GetInstance()); if (dragListener == nullptr) { @@ -81,9 +87,9 @@ namespace OHOS Title->SetPosition(83, 52, 300, 35); Title->SetStyle(STYLE_TEXT_FONT, 30); Title->SetStyle(STYLE_LINE_HEIGHT, 35); - // Title->SetText("恢复出厂"); - Title->SetTextId(STR_FACTORY_RESET); - Title->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + Title->SetTextId(STR_FACTORY_RESET);/*恢复出厂*/ + Title->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + Title->SetRollSpeed(70); Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); /* ---------------------------- FactoryResetImage --------------------------- */ @@ -105,8 +111,7 @@ namespace OHOS FactoryResetNote->SetPosition(53, 228, 360, 70); FactoryResetNote->SetStyle(STYLE_TEXT_FONT, 30); FactoryResetNote->SetStyle(STYLE_LINE_HEIGHT, 35); - // FactoryResetNote->SetText("该操作会清空并重置手表数据,是否确认继续?"); - FactoryResetNote->SetTextId(STR_RESET_CONFIRM_NOTE); + FactoryResetNote->SetTextId(STR_RESET_CONFIRM_NOTE); /*该操作会清空并重置手表数据,是否确认继续?*/ FactoryResetNote->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); FactoryResetNote->SetTextColor(Color::GetColorFromRGBA(0xff, 0x8a, 0x36, 0xff)); FactoryResetNote->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); @@ -118,12 +123,13 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemFactoryResetView::new FactoryResetButtonCheckOff fail!"); return nullptr; } - FactoryResetButtonCheckOff->SetPosition(97, 320, 130, 130); + FactoryResetButtonCheckOff->SetPosition(97, FactoryResetNote->GetY() + FactoryResetNote->GetTextHeight() + 30, 130, 130); FactoryResetButtonCheckOff->SetViewId(FACTORYRESET_CHECKOFF); FactoryResetButtonCheckOff->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); FactoryResetButtonCheckOff->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + FactoryResetButtonCheckOff->SetImagePosition(15, 15); FactoryResetButtonCheckOff->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED); - FactoryResetButtonCheckOff->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + FactoryResetButtonCheckOff->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); FactoryResetButtonCheckOff->SetImageSrc(PNG_SYSTEM_CHECK_OFF_IMAGE, PNG_SYSTEM_CHECK_OFF_IMAGE); UIView::OnClickListener *FactoryResetButtonCheckOffClick = static_cast(SystemPresenter::GetInstance()); FactoryResetButtonCheckOff->SetOnClickListener(FactoryResetButtonCheckOffClick); @@ -134,12 +140,13 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemFactoryResetView::new FactoryResetButtonCheckOn fail!"); return nullptr; } - FactoryResetButtonCheckOn->SetPosition(240, 320, 130, 130); + FactoryResetButtonCheckOn->SetPosition(240, FactoryResetButtonCheckOff->GetY(), 130, 130); FactoryResetButtonCheckOn->SetViewId(FACTORYRESET_CHECKON); FactoryResetButtonCheckOn->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); FactoryResetButtonCheckOn->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + FactoryResetButtonCheckOn->SetImagePosition(15, 15); FactoryResetButtonCheckOn->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED); - FactoryResetButtonCheckOn->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + FactoryResetButtonCheckOn->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); FactoryResetButtonCheckOn->SetImageSrc(PNG_SYSTEM_CHECK_ON_IMAGE, PNG_SYSTEM_CHECK_ON_IMAGE); UIView::OnClickListener *FactoryResetButtonCheckOnClick = static_cast(SystemPresenter::GetInstance()); FactoryResetButtonCheckOn->SetOnClickListener(FactoryResetButtonCheckOnClick); diff --git a/code/sdk/application/wearable/fd230app/nativeui/uiservice/src/ui_service.cpp b/code/sdk/application/wearable/fd230app/nativeui/uiservice/src/ui_service.cpp index 4ba3c78c5..0393384c6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/uiservice/src/ui_service.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/uiservice/src/ui_service.cpp @@ -463,7 +463,7 @@ void HandleRemoveSleepVeto(Request *request) //处理更新选择的亮屏时长标签内容 void HandleUpdateScreenDuration(Request *request) { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_UI_SERVICE, "HandleUpdateRaiseToBrightness"); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_UI_SERVICE, "HandleUpdateScreenDuration"); GraphicService::GetInstance()->PostGraphicEvent( std::bind(&OHOS::DisplayBrightnessModel::UpdateSelectScreenDurationLabel, OHOS::DisplayBrightnessModel::GetInstance())); } diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp index 071f256b2..cf5ac79f4 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -1552,6 +1552,7 @@ void set_ScreenDuration(int data) //设置亮屏时长 { OHOS::ConfigModel *p_ConfigModel = OHOS::ConfigModel::GetInstance(); p_ConfigModel->SetScreenDuration(data); + uapi_setScreenDuration(data); #ifdef FD230 SendMsgToUIService(UI_UPDATE_SCREEN_DURATION,0,nullptr,0); #endif diff --git a/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp b/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp index 93bcf2a7c..7ff27384b 100644 --- a/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp +++ b/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp @@ -792,7 +792,7 @@ namespace OHOS void ConfigModel::SetScreenDuration(unsigned int value) { set_condigData_Int(CONFIGMODEL_ITEM_SCREEN_OFF_TIMEOUT_VALUE,value); - cm_initializeScreenDuration(); + // cm_initializeScreenDuration(); } /// @brief 获取亮屏时长单位ms -- 2.17.1