From ba11ca7016984334d09a8bff8dce7ec90b25bdfc Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E7=BD=97=E6=AD=A3?= <1732036298@qq.com> Date: Fri, 2 Aug 2024 10:43:19 +0000 Subject: [PATCH] Merge #632 into sdk602patch0626 from refs/changes/632/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 解决狂按电源键或function键死机问题 * refs/changes/632/head: (7 commits squashed) - 解决狂按电源键或function键死机问题 - 修改AI语音等待录音录完时间为1s,目前还未测试 - AI语音界面title的top位置修改由52修改为50 - 搭建音乐播放器基本框架,并提供存放音乐路径接口 - 添加后退多级Slice函数,优化EnterSlice - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 - Ability 文件中BackCountSlice函数最后一个参数默认跳转1级 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/632 --- .../wearable/fd230app/CMakeLists.txt | 6 + .../nativelauncher/include/AppViewIDs.h | 1 + .../nativelauncher/include/NativeLauncher.h | 1 + .../nativelauncher/src/NativeLauncher.cpp | 16 +++ .../nativeui/aivoice/include/AiVoiceModel.h | 4 +- .../src/AiVoiceBluetoothFailedStartView.cpp | 4 +- .../nativeui/aivoice/src/AiVoiceModel.cpp | 6 +- .../nativeui/aivoice/src/AiVoicePresenter.cpp | 3 +- .../aivoice/src/AivoiceConnectTimeoutView.cpp | 4 +- .../aivoice/src/AivoiceListeningView.cpp | 4 +- .../src/AivoiceMobileDataFailedStartView.cpp | 4 +- .../aivoice/src/AivoiceThinkingView.cpp | 4 +- .../nativeui/key/src/KeyInputListener.cpp | 4 +- .../include/MusicPlayerControlView.h | 22 ++++ .../musicplayer/include/MusicPlayerModel.h | 34 ++++++ .../include/MusicPlayerPresenter.h | 45 +++++++ .../musicplayer/include/MusicPlayerView.h | 39 ++++++ .../src/MusicPlayerControlView.cpp | 30 +++++ .../musicplayer/src/MusicPlayerModel.cpp | 30 +++++ .../musicplayer/src/MusicPlayerPresenter.cpp | 114 ++++++++++++++++++ .../musicplayer/src/MusicPlayerView.cpp | 109 +++++++++++++++++ .../src/RebootAndShutdownModel.cpp | 64 +++++++--- .../nativeabilityfwk/include/Ability.h | 60 ++++++++- .../wearable/nativeabilityfwk/src/Ability.cpp | 1 + .../fd230/fs/user/userdata/music/music.txt | 0 25 files changed, 574 insertions(+), 35 deletions(-) create mode 100644 code/sdk/application/wearable/fd230app/nativeui/musicplayer/include/MusicPlayerControlView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/musicplayer/include/MusicPlayerModel.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/musicplayer/include/MusicPlayerPresenter.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/musicplayer/include/MusicPlayerView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/musicplayer/src/MusicPlayerControlView.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/musicplayer/src/MusicPlayerModel.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/musicplayer/src/MusicPlayerPresenter.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/musicplayer/src/MusicPlayerView.cpp create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/userdata/music/music.txt diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index b842bc98c..8b05d560b 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -419,6 +419,12 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aimodels/src/AiModelsView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aimodels/src/AiModelsPresenter.cpp + #音乐播放器 + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/musicplayer/src/MusicPlayerControlView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/musicplayer/src/MusicPlayerModel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/musicplayer/src/MusicPlayerPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/musicplayer/src/MusicPlayerView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/rebootandshutdown/src/RebootAndShutdownView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/rebootandshutdown/src/RebootAndShutdownPresenter.cpp diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h index 3988b2e0d..1df389f0d 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h @@ -68,6 +68,7 @@ typedef enum : uint16_t VIEW_AI_MODELS, // AI模型选择界面 VIEW_REBOOTANDSHUTDOWN, //(滑动关机和重启带恢复出厂设置) VIEW_RECORD, + VIEW_MUSIC_PLAYER, //音乐播放器 /* -------------------------------------------------------------------------- */ VIEW_OBU_MESSAGE, /* -------------------------------------------------------------------------- */ diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index 228d6fd04..536a7718e 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -65,6 +65,7 @@ namespace OHOS void InitAiModelsSlice(void); void InitRebootAndShutdownSlice(void); void InitOBUMessageSlice(void); + void InitMusicPlayerSlice(void); /* --------------------------------界面------------------------------------ */ void InitRotateSlice(void); void InitBloodSlice(void); diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index 6a6edb2bb..2c6a3148a 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -220,6 +220,9 @@ #include "obumessage/include/OBUMessagePresenter.h" #include "obumessage/include/OBUMessageView.h" + +#include "musicplayer/include/MusicPlayerPresenter.h" +#include "musicplayer/include/MusicPlayerView.h" /* -------------------------------------------------------------------------- */ #include "traing/include/TraingView.h" #include "traing/include/TraingPresenter.h" @@ -316,6 +319,7 @@ namespace OHOS {VIEW_AI_VOICE, &NativeLauncher::InitAiVoiceSlice}, // Ai Voice(人工智能语音) {VIEW_AI_MODELS, &NativeLauncher::InitAiModelsSlice}, // Ai Models(Ai模型选择界面) {VIEW_REBOOTANDSHUTDOWN, &NativeLauncher::InitRebootAndShutdownSlice}, // 滑动关机和重启带恢复出厂设置 + {VIEW_MUSIC_PLAYER, &NativeLauncher::InitMusicPlayerSlice}, // 音乐播放器 /* -------------------------------------------------------------------------- */ {VIEW_OBU_MESSAGE, &NativeLauncher::InitOBUMessageSlice}, @@ -1401,6 +1405,18 @@ namespace OHOS NativeAbility::GetInstance().AddSliceProxy(VIEW_REBOOTANDSHUTDOWN, rebootandshutdown); } + /*音乐播放器*/ + void NativeLauncher::InitMusicPlayerSlice(void) + { + SliceProxy *musicplayer = new AbilitySliceProxy; + if (musicplayer == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "musicplayer"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_MUSIC_PLAYER, musicplayer); + } + /*OBU Message*/ void NativeLauncher::InitOBUMessageSlice(void) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h index 034254842..e408d0f8e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 15:14:43 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-01 15:01:20 + * @LastEditTime: 2024-08-02 09:46:58 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h */ #ifndef AI_VOICE_MODEL_H @@ -73,7 +73,7 @@ namespace OHOS void StopListenAndRecordingUserQuestion(void); // 定时器管理 - void AIVoice_StartTimer(uint32_t interval = 2000); + void AIVoice_StartTimer(uint32_t interval = 1000); void AIVoice_StopTimer(void); void SetSelectAiModel(int index); diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceBluetoothFailedStartView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceBluetoothFailedStartView.cpp index 126a1af5b..c8372af06 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceBluetoothFailedStartView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceBluetoothFailedStartView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-05-07 11:25:58 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-31 15:01:20 + * @LastEditTime: 2024-08-02 15:43:57 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AiVoiceBluetoothFailedStartView.cpp */ #include "aivoice/include/AiVoicePresenter.h" @@ -151,7 +151,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::CreateAiVoiceBluetoothFailedStartLabel"); LabelConfig labelconfig = { .left = 83, - .top = 52, + .top = 50, .width = 300, .height = 35, .fontSize = 30, diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp index ea95c967f..1b8f401bd 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 15:14:50 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-01 16:01:59 + * @LastEditTime: 2024-08-02 09:48:30 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp */ #include "aivoice/include/AiVoiceModel.h" @@ -28,7 +28,7 @@ namespace OHOS { // 声明定时器变量 static osTimerId_t g_timer = NULL; - static constexpr uint16_t THIRTY_TIME = 32; + static constexpr uint16_t THIRTY_TIME = 31; static int Time = THIRTY_TIME; AiVoiceModel::AiVoiceModel() {} @@ -548,7 +548,7 @@ namespace OHOS static void AIVoice_TimerCallbackProc(int data) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AIVoice_TimerCallbackProc,Time = %d", Time); - Time -= 2; + Time -= 1; if (Time == 30) { AiVoiceModel::GetInstance().CheckFileAndSendAIIsReady(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp index 95c8ed63e..02643d7ac 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 15:11:17 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-01 15:55:48 + * @LastEditTime: 2024-08-02 14:35:52 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp */ #include "AppViewIDs.h" @@ -214,6 +214,7 @@ namespace OHOS bool netWork4GState = model->GetMobileDataIsOpen(); bool appBluetoothConnectState = model->GetAPPBluetoothIsConnect(); bool aivoiceConnectState = model->GetAiVoiceConnectStatus(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "netWork4GState = %d,appBluetoothConnectState = %d,aivoiceConnectState =%d",netWork4GState,appBluetoothConnectState,aivoiceConnectState); if (netWork4GState) // 1.手表4G网络正常 { diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp index 4b96a102f..3687cca0c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-05-07 11:25:58 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-30 19:10:30 + * @LastEditTime: 2024-08-02 15:44:02 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceConnectTimeoutView.cpp */ #include "aivoice/include/AiVoicePresenter.h" @@ -153,7 +153,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::CreateAivoiceConnectTimeoutLabel"); LabelConfig labelconfig = { .left = 83, - .top = 52, + .top = 50, .width = 300, .height = 35, .fontSize = 30, diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceListeningView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceListeningView.cpp index 9483cf6f0..808c30d7e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceListeningView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceListeningView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-05-07 11:25:58 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-30 19:11:15 + * @LastEditTime: 2024-08-02 15:44:32 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceListeningView.cpp */ #include "aivoice/include/AiVoicePresenter.h" @@ -193,7 +193,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::CreateAivoiceListeningLabel"); LabelConfig labelconfig = { .left = 83, - .top = 52, + .top = 50, .width = 300, .height = 35, .fontSize = 30, diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceMobileDataFailedStartView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceMobileDataFailedStartView.cpp index 2c4d4c5a5..da0d3f158 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceMobileDataFailedStartView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceMobileDataFailedStartView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-05-07 11:25:58 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-31 15:08:38 + * @LastEditTime: 2024-08-02 15:44:58 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceMobileDataFailedStartView.cpp */ #include "aivoice/include/AiVoicePresenter.h" @@ -152,7 +152,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceMobileDataFailedStartView::CreateAivoiceMobileDataFailedStartLabel"); LabelConfig labelconfig = { .left = 83, - .top = 52, + .top = 50, .width = 300, .height = 35, .fontSize = 30, diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceThinkingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceThinkingView.cpp index aaa107db0..527551025 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceThinkingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceThinkingView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-05-07 11:25:58 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-30 19:09:31 + * @LastEditTime: 2024-08-02 15:44:41 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceThinkingView.cpp */ #include "aivoice/include/AiVoicePresenter.h" @@ -193,7 +193,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::CreateAivoiceThinkingLabel"); LabelConfig labelconfig = { .left = 83, - .top = 52, + .top = 50, .width = 300, .height = 35, .fontSize = 30, diff --git a/code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp b/code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp index 8f293635b..19835ba2e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp @@ -135,6 +135,7 @@ void KeyInputListener::CallVolumeDipSwitchControl(VolumeChangeStatus status) if (mcu_pms_is_screen_on()) { PressAlarmNotify(); + NativeAbility::GetInstance().ClearSliceIdStack(); NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN, TransitionType::TRANSITION_ZOOM); } } @@ -149,7 +150,8 @@ void KeyInputListener::CallVolumeDipSwitchControl(VolumeChangeStatus status) } else { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_ZOOM); + // NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_ZOOM); + NativeAbility::GetInstance().EnterSlice(VIEW_APPLIST, TransitionType::TRANSITION_ZOOM); } } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/musicplayer/include/MusicPlayerControlView.h b/code/sdk/application/wearable/fd230app/nativeui/musicplayer/include/MusicPlayerControlView.h new file mode 100644 index 000000000..9f46aa7d5 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/musicplayer/include/MusicPlayerControlView.h @@ -0,0 +1,22 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-08-02 15:21:47 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-08-02 15:58:32 + * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/musicplayer/include/MusicPlayerControlView.h + */ +#include "components/ui_card_page.h" + +namespace OHOS +{ + class MusicPlayerControlView : public UICardPage + { + public: + MusicPlayerControlView(); + ~MusicPlayerControlView(); + static MusicPlayerControlView *GetInstance(void); + + private: + }; + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/musicplayer/include/MusicPlayerModel.h b/code/sdk/application/wearable/fd230app/nativeui/musicplayer/include/MusicPlayerModel.h new file mode 100644 index 000000000..16ae9bff1 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/musicplayer/include/MusicPlayerModel.h @@ -0,0 +1,34 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-08-02 10:00:21 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-08-02 16:08:39 + * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/musicplayer/include/MusicPlayerModel.h + */ + +#ifndef MUSIC_PLAYER_MODEL_H +#define MUSIC_PLAYER_MODEL_H + +#include "iostream" +#include "string" + +namespace OHOS +{ + class MusicPlayerModel + { + public: + static MusicPlayerModel &GetInstance(void); + std::string GetMusicPlayPath(void); + + private: + MusicPlayerModel(); + ~MusicPlayerModel(); + MusicPlayerModel(const MusicPlayerModel &) = delete; + MusicPlayerModel &operator=(const MusicPlayerModel &) = delete; + + private: + std::string musicPlayPath = "/user/userdata/music/"; /*音乐播放路径*/ + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/musicplayer/include/MusicPlayerPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/musicplayer/include/MusicPlayerPresenter.h new file mode 100644 index 000000000..a5e6ffa33 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/musicplayer/include/MusicPlayerPresenter.h @@ -0,0 +1,45 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-07-08 09:39:10 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-08-02 14:54:01 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aimodels/include/MusicPlayerPresenter.h + */ + +#ifndef MUSIC_PLAYER_PRESENTER_H +#define MUSIC_PLAYER_PRESENTER_H + +#include "Presenter.h" +#include "View.h" + +namespace OHOS +{ + class MusicPlayerView; + class MusicPlayerModel; + class MusicPlayerPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener, + public RootView::OnKeyActListener + { + public: + MusicPlayerPresenter(); + virtual ~MusicPlayerPresenter(); + static MusicPlayerPresenter *GetInstance(); + + void OnStart() override; + void OnResume() override; + void OnPause() override; + void OnStop() override; + + private: + 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; // 增加按键事件 + + MusicPlayerModel *model; + bool X_DRAG_FLAG{false}; + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/musicplayer/include/MusicPlayerView.h b/code/sdk/application/wearable/fd230app/nativeui/musicplayer/include/MusicPlayerView.h new file mode 100644 index 000000000..452977770 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/musicplayer/include/MusicPlayerView.h @@ -0,0 +1,39 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-08-01 18:02:51 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-08-02 15:57:46 + * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/musicplayer/include/MusicPlayerView.h + */ + + +#ifndef MUSIC_PLAYER_VIEW_H +#define MUSIC_PLAYER_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include "musicplayer/include/MusicPlayerControlView.h" +namespace OHOS +{ + + class MusicPlayerPresenter; + class MusicPlayerView : public View + { + public: + MusicPlayerView(); + ~MusicPlayerView(); + static MusicPlayerView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + + private: + void CreateMusicPlayerView(void); + void ClearAll(void); + MusicPlayerControlView *musicPlayerControlView{nullptr}; + bool viewInitStatus{false}; + }; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/musicplayer/src/MusicPlayerControlView.cpp b/code/sdk/application/wearable/fd230app/nativeui/musicplayer/src/MusicPlayerControlView.cpp new file mode 100644 index 000000000..ce48fb6f5 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/musicplayer/src/MusicPlayerControlView.cpp @@ -0,0 +1,30 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-08-02 15:26:48 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-08-02 15:56:37 + * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/musicplayer/src/MusicPlayerControlView.cpp + */ +#include "musicplayer/include/MusicPlayerControlView.h" +#include "wearable_log.h" +namespace OHOS +{ + static MusicPlayerControlView *g_pMusicPlayerControlView{nullptr}; + MusicPlayerControlView::MusicPlayerControlView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MusicPlayerControlView::MusicPlayerControlView"); + g_pMusicPlayerControlView = this; + } + + MusicPlayerControlView::~MusicPlayerControlView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MusicPlayerControlView::~MusicPlayerControlView"); + g_pMusicPlayerControlView = nullptr; + } + + MusicPlayerControlView *MusicPlayerControlView::GetInstance(void) + { + return g_pMusicPlayerControlView; + } + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/musicplayer/src/MusicPlayerModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/musicplayer/src/MusicPlayerModel.cpp new file mode 100644 index 000000000..954a9a0d1 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/musicplayer/src/MusicPlayerModel.cpp @@ -0,0 +1,30 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-08-02 10:00:33 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-08-02 16:06:48 + * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/musicplayer/src/MusicPlayerModel.cpp + */ + +#include "musicplayer/include/MusicPlayerModel.h" +#include "wearable_log.h" + +namespace OHOS +{ + MusicPlayerModel::MusicPlayerModel() {} + + MusicPlayerModel::~MusicPlayerModel() {} + + MusicPlayerModel &MusicPlayerModel::GetInstance() + { + static MusicPlayerModel instance; + return instance; + } + + /*获取音乐播放路径*/ + std::string MusicPlayerModel::GetMusicPlayPath(void) + { + return musicPlayPath; + } + +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/musicplayer/src/MusicPlayerPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/musicplayer/src/MusicPlayerPresenter.cpp new file mode 100644 index 000000000..2d2b0e0b2 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/musicplayer/src/MusicPlayerPresenter.cpp @@ -0,0 +1,114 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-08-02 09:59:59 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-08-02 14:54:21 + * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/musicplayer/src/MusicPlayerPresenter.cpp + */ + +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "common/key_code.h" +#include +#include "UiConfig.h" +#include "musicplayer/include/MusicPlayerPresenter.h" +#include "musicplayer/include/MusicPlayerView.h" +#include "musicplayer/include/MusicPlayerModel.h" + +namespace OHOS +{ + + static MusicPlayerPresenter *g_pMusicPlayerPresenter = nullptr; + + MusicPlayerPresenter::MusicPlayerPresenter() + { + model = &MusicPlayerModel::GetInstance(); + g_pMusicPlayerPresenter = this; + } + + MusicPlayerPresenter::~MusicPlayerPresenter() + { + g_pMusicPlayerPresenter = nullptr; + } + + MusicPlayerPresenter *MusicPlayerPresenter::GetInstance() + { + return g_pMusicPlayerPresenter; + } + + // 启动时执行的逻辑 + void MusicPlayerPresenter::OnStart() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerPresenter::OnStart"); + Presenter::OnStart(); + } + + // 页面已经展示后的调用逻辑 + void MusicPlayerPresenter::OnResume(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerPresenter::OnResume"); + Presenter::OnResume(); + if (view_ == nullptr) + { + return; + } + } + + // 页面准备切换到后台前执行的逻辑 + void MusicPlayerPresenter::OnPause(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerPresenter::OnPause"); + Presenter::OnPause(); + } + + // 页面完全置于后台时的逻辑。 + void MusicPlayerPresenter::OnStop(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerPresenter::OnStop"); + Presenter::OnStop(); + } + + bool MusicPlayerPresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerPresenter::OnClick"); + return true; + } + + bool MusicPlayerPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerPresenter::OnDrag"); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + MusicPlayerPresenter::X_DRAG_FLAG = true; + } + return true; + } + + bool MusicPlayerPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerPresenter::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && MusicPlayerPresenter::X_DRAG_FLAG) + { + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + MusicPlayerPresenter::X_DRAG_FLAG = false; + } + return true; + } + + bool MusicPlayerPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerPresenter::OnKeyAct"); + uint16_t keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0) + { + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } + return true; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/musicplayer/src/MusicPlayerView.cpp b/code/sdk/application/wearable/fd230app/nativeui/musicplayer/src/MusicPlayerView.cpp new file mode 100644 index 000000000..8738d4b93 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/musicplayer/src/MusicPlayerView.cpp @@ -0,0 +1,109 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-05-07 11:25:58 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-08-02 16:13:00 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/MusicPlayer/src/MusicPlayerView.cpp + */ +#include "musicplayer/include/MusicPlayerPresenter.h" +#include "musicplayer/include/MusicPlayerView.h" +#include "wearable_log.h" + +namespace OHOS +{ + + static MusicPlayerView *g_pMusicPlayerView{nullptr}; + MusicPlayerView::MusicPlayerView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MusicPlayerView::MusicPlayerView"); + g_pMusicPlayerView = this; + } + + MusicPlayerView::~MusicPlayerView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MusicPlayerView::~MusicPlayerView"); + g_pMusicPlayerView = nullptr; + } + + MusicPlayerView *MusicPlayerView::GetInstance() + { + return g_pMusicPlayerView; + } + + void MusicPlayerView::ClearAll(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerView::ClearAll"); + if (viewInitStatus) + { + } + } + + void MusicPlayerView::CreateMusicPlayerView(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerView::CreateMusicPlayerView"); + if (musicPlayerControlView == nullptr) + { + musicPlayerControlView = new MusicPlayerControlView(); + if (musicPlayerControlView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "musicPlayerControlView new fail!!"); + return; + } + } + container_->Add(musicPlayerControlView); + } + + void MusicPlayerView::OnStart() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerView::OnStart"); + View::OnStart(); + SetContainerView(new UIViewGroup()); + if (GetContainer() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetContainerView fail!!"); + return; + } + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + container_->SetOnDragListener(presenter_); + container_->SetTouchable(true); + container_->SetDraggable(true); + + if (!viewInitStatus) + { + CreateMusicPlayerView(); + viewInitStatus = true; + } + + RootView::GetInstance()->SetOnKeyActListener(presenter_); + return; + } + void MusicPlayerView::OnSetUpView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerView::OnSetUpView"); + View::OnSetUpView(); + Draw(); + return; + } + + void MusicPlayerView::OnTearDownView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerView::OnTearDownView"); + View::OnTearDownView(); + return; + } + + void MusicPlayerView::OnStop() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MusicPlayerView::OnStop"); + View::OnStop(); + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + RootView::GetInstance()->ClearOnKeyActListener(); + ClearAll(); + return; + } +} \ No newline at end of file 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 f653658aa..7981ad104 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-31 10:49:15 + * @LastEditTime: 2024-08-02 11:57:16 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp */ @@ -16,6 +16,8 @@ #include #include "themestyle/include/ThemeStyleModel.h" #include "aimodels/include/AiModelsModel.h" +#include "ConfigModel.h" +#include "graphic_service.h" namespace OHOS { RebootAndShutdownModel::RebootAndShutdownModel() {} @@ -53,9 +55,9 @@ namespace OHOS #endif #include - static void HandlePowerKeyLongPress(void) + static void PowerKeyLongPressCallBack(void) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HandlePowerKeyLongPress"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PowerKeyLongPressCallBack"); RebootAndShutdownPresenter *rebootAndShutdownPresenter = RebootAndShutdownPresenter::GetInstance(); if (rebootAndShutdownPresenter != nullptr && true == rebootAndShutdownPresenter->GetIsShutDownImageAnimator()) @@ -79,6 +81,11 @@ namespace OHOS NativeAbility::GetInstance().EnterSlice(VIEW_REBOOTANDSHUTDOWN); } + static void HandlePowerKeyLongPress(void) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(PowerKeyLongPressCallBack)); + } + /*注册电源键的长按事件*/ bool RebootAndShutdownModel::RegisterPowerKeyLongPressEvent(void) { @@ -92,9 +99,9 @@ namespace OHOS return true; } - static void HandlePowerKeyDoubleClick(void) + static void PowerKeyDoubleClickCallBack(void) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HandlePowerKeyDoubleClick"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PowerKeyDoubleClickCallBack"); RebootAndShutdownPresenter *rebootAndShutdownPresenter = RebootAndShutdownPresenter::GetInstance(); if (rebootAndShutdownPresenter != nullptr && true == rebootAndShutdownPresenter->GetIsShutDownImageAnimator()) @@ -128,6 +135,11 @@ namespace OHOS } } + static void HandlePowerKeyDoubleClick(void) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(PowerKeyDoubleClickCallBack)); + } + /*注册电源键的双击事件*/ bool RebootAndShutdownModel::RegisterPowerKeyDoubleClickEvent(void) { @@ -142,9 +154,9 @@ namespace OHOS return true; } - static void HandFuncKeyOnPress(void) + static void FuncKeyOnPressCallBack(void) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RebootAndShutdownModel::HandFuncKeyOnPress"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RebootAndShutdownModel::FuncKeyOnPressCallBack"); RebootAndShutdownPresenter *rebootAndShutdownPresenter = RebootAndShutdownPresenter::GetInstance(); if (rebootAndShutdownPresenter != nullptr && true == rebootAndShutdownPresenter->GetIsShutDownImageAnimator()) @@ -162,6 +174,11 @@ namespace OHOS return; } + static void HandFuncKeyOnPress(void) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(FuncKeyOnPressCallBack)); + } + /*注册功能键的按下事件*/ bool RebootAndShutdownModel::RegisterFuncKeyPressEvent(void) { @@ -176,9 +193,9 @@ namespace OHOS return true; } - static void HandFuncKeyOnLongPress(void) + static void FuncKeyOnLongPressCallBack(void) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HandFuncKeyOnLongPress"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FuncKeyOnLongPressCallBack"); RebootAndShutdownPresenter *rebootAndShutdownPresenter = RebootAndShutdownPresenter::GetInstance(); if (rebootAndShutdownPresenter != nullptr && true == rebootAndShutdownPresenter->GetIsShutDownImageAnimator()) @@ -188,7 +205,7 @@ namespace OHOS if (true == ConfigModel::GetInstance()->GetisFirstTimeStart()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HandFuncKeyOnLongPress: first time power on"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FuncKeyOnLongPressCallBack: first time power on"); return; } @@ -216,6 +233,11 @@ namespace OHOS } } + static void HandFuncKeyOnLongPress(void) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(FuncKeyOnLongPressCallBack)); + } + /*注册功能键的长按(2s)事件*/ bool RebootAndShutdownModel::RegisterFuncKeyLongPressEvent(void) { @@ -229,9 +251,9 @@ namespace OHOS return true; } - static void HandleFuncKeyOnClick(void) + static void FuncKeyOnClickCallBack(void) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HandleFuncKeyOnClick"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FuncKeyOnClickCallBack"); RebootAndShutdownPresenter *rebootAndShutdownPresenter = RebootAndShutdownPresenter::GetInstance(); if (rebootAndShutdownPresenter != nullptr && true == rebootAndShutdownPresenter->GetIsShutDownImageAnimator()) @@ -241,7 +263,7 @@ namespace OHOS if (true == ConfigModel::GetInstance()->GetisFirstTimeStart()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HandleFuncKeyOnClick: first time power on"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FuncKeyOnClickCallBack: first time power on"); return; } @@ -266,6 +288,11 @@ namespace OHOS } } + static void HandleFuncKeyOnClick(void) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(FuncKeyOnClickCallBack)); + } + /*注册功能键的单击事件*/ bool RebootAndShutdownModel::RegisterFuncKeyClickEvent(void) { @@ -279,9 +306,9 @@ namespace OHOS return true; } - static void HandleFuncKeyDoubleClick(void) + static void FuncKeyDoubleClickCallBack(void) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HandleFuncKeyDoubleClick"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FuncKeyDoubleClickCallBack"); RebootAndShutdownPresenter *rebootAndShutdownPresenter = RebootAndShutdownPresenter::GetInstance(); if (rebootAndShutdownPresenter != nullptr && true == rebootAndShutdownPresenter->GetIsShutDownImageAnimator()) @@ -291,7 +318,7 @@ namespace OHOS if (true == ConfigModel::GetInstance()->GetisFirstTimeStart()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HandleFuncKeyDoubleClick: first time power on"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FuncKeyDoubleClickCallBack: first time power on"); return; } @@ -312,6 +339,11 @@ namespace OHOS } } + static void HandleFuncKeyDoubleClick(void) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(FuncKeyDoubleClickCallBack)); + } + /*注册功能键双击事件*/ bool RebootAndShutdownModel::RegisterFuncKeyDoubleClickEvent(void) { diff --git a/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h b/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h index 6127a7d9f..2e3beb7a0 100755 --- a/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h +++ b/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h @@ -67,7 +67,12 @@ public: return curSlicePriority_; } - // 当从一个Slice进入另一个Slice时调用 + /* -------------------------------------------------------------------------- */ + + /// @brief 当从一个切片(Slice)进入另一个切片时被调用。 + /// @param sliceId sliceId + /// @param transitionId 切换的动画类型 + /// @param priority 切换优先级 void EnterSlice(uint16_t sliceId,const TransitionType transitionId = TransitionType::TRANSITION_INVALID, const uint16_t priority = gSliceDefaultPriority) { // 获取当前SliceID @@ -79,7 +84,11 @@ public: } // 处理后退操作 - bool Back(const TransitionType transitionId = TransitionType::TRANSITION_INVALID, + + /// @brief 处理后退操作。 + /// @param transitionId 切换的动画类型 + /// @param priority 切换优先级 + bool Back(const TransitionType transitionId = TransitionType::TRANSITION_INVALID, const uint16_t priority = gSliceDefaultPriority) { /* if (backStack_.empty()) { @@ -100,6 +109,37 @@ public: } } + /// @brief 处理后退多级切片的操作。 + /// @param transitionId 切换的动画类型 + /// @param priority 切换优先级 + /// @param count 指定的后退级数 + bool BackCountSlice(const TransitionType transitionId = TransitionType::TRANSITION_INVALID, + const uint16_t priority = gSliceDefaultPriority,int count = 1) { + //如果指定的后退级数 count 为 0 ,直接返回 false 。 + if(count == 0) { + return false; + } + while(!backStack_.empty() && count != 0) //当 count 不为 0 且 backStack_ 栈不为空时,弹出栈顶元素 count 次。 + { + backStack_.pop(); + count--; + } + if(!backStack_.empty()) + { + // 如果此时 backStack_ 栈不为空,取出栈顶的切片 ID ,并调用 ChangeSlice 切换到该切片,返回 true 。 + uint16_t preSlice = backStack_.top(); + ChangeSlice(preSlice,transitionId,priority); + return true; + } + else + { + //如果 backStack_ 栈为空,切换到默认切片,返回 false 。 + ChangeSlice(defaultSliceId_, transitionId, priority); + return false; // 返回false表示无前一个slice,退回到默认slice + } + } + + /*清空后退栈*/ void ClearSliceIdStack(void) { while(!backStack_.empty()) @@ -108,6 +148,22 @@ public: } } + /*打印栈中元素*/ + void showsStackSliceId() + { + printf("\n%d\n",backStack_.size()); + std::stack tempStack = backStack_; + printf("\n["); + while(!tempStack.empty()) + { + printf("%d,",tempStack.top()); + tempStack.pop(); + } + printf("]\n"); + printf("\n%d\n",backStack_.size()); + } + /* -------------------------------------------------------------------------- */ + protected: Ability() = default; virtual ~Ability() = default; diff --git a/code/sdk/application/wearable/nativeabilityfwk/src/Ability.cpp b/code/sdk/application/wearable/nativeabilityfwk/src/Ability.cpp index 8d5467b82..c1be851e8 100755 --- a/code/sdk/application/wearable/nativeabilityfwk/src/Ability.cpp +++ b/code/sdk/application/wearable/nativeabilityfwk/src/Ability.cpp @@ -118,6 +118,7 @@ ListsNode* Ability::Find(const uint16_t sliceId) */ void Ability::ChangeSlice(const uint16_t targetSliceId, TransitionType type, const uint16_t priority) { + showsStackSliceId(); /* if (GetCurSliceId() == targetSliceId) { return; diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/userdata/music/music.txt b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/userdata/music/music.txt new file mode 100644 index 000000000..e69de29bb -- 2.17.1