From 107698a1418e1494a3f1fdb6f93e30e7ba79d54e Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Mon, 22 Jul 2024 11:43:15 +0800 Subject: [PATCH] =?utf8?q?1.=E4=BC=98=E5=8C=96=E8=AE=BE=E7=BD=AE=E8=A7=86?= =?utf8?q?=E5=9B=BE=EF=BC=9A=E6=B7=BB=E5=8A=A0=E4=BA=86=E8=A1=A8=E5=86=A0?= =?utf8?q?=E6=8E=A7=E5=88=B6=E4=BD=86=E6=95=88=E6=9E=9C=E4=B8=8D=E4=BD=B3?= =?utf8?q?=202.=E6=BB=91=E5=8A=A8=E5=85=B3=E6=9C=BA=E5=92=8C=E9=87=8D?= =?utf8?q?=E5=90=AF=E8=A7=86=E5=9B=BE=E6=B7=BB=E5=8A=A0=E6=8C=89=E9=94=AE?= =?utf8?q?=E6=B3=A8=E5=86=8C=E5=8A=9F=E8=83=BD=203.=E7=8E=B0=E5=9C=A8?= =?utf8?q?=E8=AE=BE=E7=BD=AE=E8=A7=86=E5=9B=BE=E8=BF=9B=E5=85=A5=E5=85=B3?= =?utf8?q?=E6=9C=BA=E5=92=8C=E9=87=8D=E5=90=AF=E4=B8=BA=E2=80=9C=E6=BB=91?= =?utf8?q?=E5=8A=A8=E5=85=B3=E6=9C=BA=E9=87=8D=E5=90=AFSlice=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativelauncher/src/NativeLauncher.cpp | 6 +- .../include/RebootAndShutdownModel.h | 11 +- .../src/RebootAndShutdownModel.cpp | 252 +++++++++++++++++- .../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 ++++++----- 9 files changed, 394 insertions(+), 94 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index 2da956644..986bbf5a3 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/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/RebootAndShutdownModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp index 618de55c9..af0dbbae5 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 10:45:31 * @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,257 @@ 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) { + 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; } -- 2.17.1