From b254b85291ff8b94971f36aaeed692dfec34e364 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Sat, 3 Aug 2024 17:37:27 +0800 Subject: [PATCH] =?utf8?q?AI=E8=AF=AD=E9=9F=B3=E7=95=8C=E9=9D=A2=E4=BC=98?= =?utf8?q?=E5=8C=96=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../aivoice/include/AiVoiceConnectingView.h | 23 +++- .../aivoice/include/AiVoicePresenter.h | 4 +- .../nativeui/aivoice/include/AiVoiceView.h | 3 +- .../aivoice/src/AiVoiceConnectingView.cpp | 106 +++++++++++++++++- .../nativeui/aivoice/src/AiVoiceView.cpp | 34 +++++- .../nativeabilityfwk/include/Ability.h | 2 +- 6 files changed, 164 insertions(+), 8 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h index 2f1187bce..ec7cdbe14 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-08-03 11:09:56 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-03 11:32:24 + * @LastEditTime: 2024-08-03 16:55:59 * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h */ @@ -11,9 +11,11 @@ #include "components/ui_button.h" #include "components/ui_scroll_view.h" #include "components/ui_label_ext.h" +#include "components/ui_image_animator.h" namespace OHOS { static constexpr const char *AIVOICECONNECTINGVIEW_CANCEL_BUTTON_VIEW_ID = "AivoiceConnectingcancelButton"; // 正在连接中界面取消按钮 + static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 20; // 图片帧数 class AiVoiceConnectingView { @@ -38,22 +40,41 @@ namespace OHOS const char *viewId; }; + struct ImageAnimatorConfig + { + int16_t x; + int16_t y; + int16_t width; + int16_t height; + ImageAnimatorInfo *imageInfoArray; + const char *const *pathsArray; + uint8_t numFrames; + int delay; + }; + AiVoiceConnectingView(); ~AiVoiceConnectingView(); static AiVoiceConnectingView *GetInstance(void); UIScrollView *CreateAiVoiceConnectingView(void); private: + const char **CreateImagePathsArray(const char *basePath, const int numImages, const char *fileExtension = "bin"); + void FreeImagePathsArray(const char **imagePaths, const int numImages); + UIImageAnimatorView *connectingImageAnimatorInit(ImageAnimatorConfig &imageanimatorconfig); UILabelExt *AiVoiceConnectingViewLabelInit(LabelConfig &labelconfig); UIButton *AiVoiceConnectingViewButtonInit(ButtonConfig &buttonconfig); bool CreateAiVoiceConnectingViewLabel(void); bool CreateAiVoiceConnectingViewButton(void); + bool CreateAivoiceConnectingImageAnimator(void); bool CreateAiVoiceConnectingScrollView(void); void ClearAll(void); UIScrollView *scrollView{nullptr}; UILabelExt *title{nullptr}; UILabelExt *cancelLabel{nullptr}; UIButton *cancelButton{nullptr}; + UIImageAnimatorView *connectingAnimatorView{nullptr}; + ImageAnimatorInfo connectingImageInfo[AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; + const char **connectingPathsArray{nullptr}; }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h index abc91fa57..4438950fa 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-20 14:44:22 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-03 14:27:50 + * @LastEditTime: 2024-08-03 17:28:03 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h */ #ifndef AI_VOICE_PRESENTER_H @@ -51,7 +51,7 @@ namespace OHOS bool OnDrag(UIView &view, const DragEvent &event) override; bool OnDragEnd(UIView &view, const DragEvent &event) override; bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 - void OnPickerStoped(UIPicker& picker); + void OnPickerStoped(UIPicker& picker) override; AiVoiceModel *model; bool X_DRAG_FLAG{false}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceView.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceView.h index d194567ee..927d3502e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-08 09:36:01 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-03 11:37:00 + * @LastEditTime: 2024-08-03 16:40:55 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/respiratorytraining/include/AiVoiceView.h */ #ifndef AI_VOICE_VIEW_H @@ -108,6 +108,7 @@ namespace OHOS UIScrollView *GetAiVoiceScrollView(int16_t index); bool ClickFunc(int16_t interface); bool CheckViewParam(int16_t hideView, int16_t showView); + void DestroyTempView(int16_t hideView); void ChangeView(int16_t hideView, int16_t showView); bool ChangeAiVoiceStartChatView(int16_t thisView); bool ChangeAiVoiceBluetoothFailedStartView(int16_t thisView); diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp index 1523f1ced..790abdcea 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-08-03 11:10:08 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-03 15:19:28 + * @LastEditTime: 2024-08-03 17:27:27 * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp */ #include "aivoice/include/AiVoiceConnectingView.h" @@ -12,6 +12,13 @@ namespace OHOS { + static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_X = 183; + static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_Y = 153; + static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_W = 100; + static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_H = 120; + static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_DELAY = 200; // 图片更新间隔 + static constexpr const char *AIVoiceListeningImagePaths = "/user/res/connect/"; + static AiVoiceConnectingView *g_pAiVoiceConnecting{nullptr}; AiVoiceConnectingView::AiVoiceConnectingView() { @@ -36,6 +43,13 @@ namespace OHOS delete title; title = nullptr; } + if (connectingAnimatorView) + { + connectingAnimatorView->Stop(); + delete connectingAnimatorView; + connectingAnimatorView = nullptr; + FreeImagePathsArray(connectingPathsArray, AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + } if (cancelLabel) { delete cancelLabel; @@ -91,6 +105,63 @@ namespace OHOS return button; } + const char **AiVoiceConnectingView::CreateImagePathsArray(const char *basePath, const int numImages, const char *fileExtension) + { + const char **imagePaths = new const char *[numImages]; + if (imagePaths == nullptr) + { + return nullptr; + } + + char buffer[256]; + for (int i = 0; i < numImages; i++) + { + snprintf(buffer, sizeof(buffer), "%s%d.%s", basePath, i + 1, fileExtension); + imagePaths[i] = strdup(buffer); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " imagePaths[%d] = %s", i, imagePaths[i]); + } + return imagePaths; + } + + void AiVoiceConnectingView::FreeImagePathsArray(const char **imagePaths, const int numImages) + { + for (int i = 0; i < numImages; i++) + { + delete imagePaths[i]; + imagePaths[i] = nullptr; + } + } + + UIImageAnimatorView *AiVoiceConnectingView::connectingImageAnimatorInit(ImageAnimatorConfig &imageanimatorconfig) + { + UIImageAnimatorView *animatorView = new UIImageAnimatorView(); + if (animatorView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceListeningImageAnimatorView::AiVoiceListeningImageAnimatorView new fail"); + return nullptr; + } + + for (uint8_t i = 0; i < imageanimatorconfig.numFrames; i++) + { + // imageanimatorconfig.imageInfoArray[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(imageanimatorconfig.pathsArray[i]); + imageanimatorconfig.imageInfoArray[i].imagePath = (imageanimatorconfig.pathsArray[i]); + imageanimatorconfig.imageInfoArray[i].imageType = IMG_SRC_FILE_PATH; + imageanimatorconfig.imageInfoArray[i].pos.x = imageanimatorconfig.x; + imageanimatorconfig.imageInfoArray[i].pos.y = imageanimatorconfig.y; + imageanimatorconfig.imageInfoArray[i].width = imageanimatorconfig.width; + imageanimatorconfig.imageInfoArray[i].height = imageanimatorconfig.height; + } + + animatorView->SetPosition(imageanimatorconfig.x, imageanimatorconfig.y, imageanimatorconfig.width, imageanimatorconfig.height); + animatorView->SetImageAnimatorSrc(imageanimatorconfig.imageInfoArray, imageanimatorconfig.numFrames, imageanimatorconfig.delay); + animatorView->SetRepeat(true); + animatorView->SetAutoEnable(false); + animatorView->SetResizeMode(UIImageAnimatorView::FILL); + animatorView->Start(); + + return animatorView; + } + bool AiVoiceConnectingView::CreateAiVoiceConnectingViewLabel(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingViewLabel"); @@ -159,6 +230,36 @@ namespace OHOS return true; } + bool AiVoiceConnectingView::CreateAivoiceConnectingImageAnimator(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAivoiceConnectingImageAnimator"); + connectingPathsArray = CreateImagePathsArray(AIVoiceListeningImagePaths, AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + if (connectingPathsArray == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::connectingPathsArray is nullptr!!"); + return false; + } + + ImageAnimatorConfig imageanimatorconfig = { + .x = AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_X, + .y = AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_Y, + .width = AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_W, + .height = AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_H, + .imageInfoArray = connectingImageInfo, + .pathsArray = connectingPathsArray, + .numFrames = AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, + .delay = AIVOICE_CONNECTING_IMAGE_ANIMATOR_DELAY, + }; + connectingAnimatorView = connectingImageAnimatorInit(imageanimatorconfig); + if (connectingAnimatorView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::connectingAnimatorView new fail"); + return false; + } + + return true; + } + bool AiVoiceConnectingView::CreateAiVoiceConnectingScrollView(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingScrollView"); @@ -185,12 +286,13 @@ namespace OHOS UIScrollView *AiVoiceConnectingView::CreateAiVoiceConnectingView(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingView"); - if (!CreateAiVoiceConnectingScrollView() || !CreateAiVoiceConnectingViewLabel() || !CreateAiVoiceConnectingViewButton()) + if (!CreateAiVoiceConnectingScrollView() || !CreateAivoiceConnectingImageAnimator()|| !CreateAiVoiceConnectingViewLabel() || !CreateAiVoiceConnectingViewButton()) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingView fail!!"); return nullptr; } scrollView->Add(title); + scrollView->Add(connectingAnimatorView); scrollView->Add(cancelButton); scrollView->Add(cancelLabel); diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp index 6cf64de36..63a19962b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-05-07 11:25:58 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-03 16:24:36 + * @LastEditTime: 2024-08-03 16:45:06 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AiVoiceView.cpp */ #include "aivoice/include/AiVoicePresenter.h" @@ -715,6 +715,36 @@ namespace OHOS return true; } + static const int16 AiVoiceDestroyMapper[] = { + AIVOICE_AIMODE_CONNECTING, + }; + + void AiVoiceView::DestroyTempView(int16_t hideView) + { + int viewSize = sizeof(AiVoiceDestroyMapper) / sizeof(AiVoiceDestroyMapper[0]); + for (int i = 0; i < viewSize; i++) + { + if (hideView == AiVoiceDestroyMapper[i]) + { + container_->Remove(AiVoiceScrollView[hideView]); + AiVoiceScrollView[hideView] = nullptr; + break; + } + } + switch (hideView) + { + case AIVOICE_AIMODE_CONNECTING: + if (p_AiVoiceConnectingView) + { + delete p_AiVoiceConnectingView; + p_AiVoiceConnectingView = nullptr; + } + break; + default: + break; + } + } + void AiVoiceView::ChangeView(int16_t hideView, int16_t showView) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeView"); @@ -727,6 +757,8 @@ namespace OHOS ClickFunc(showView); AiVoiceScrollView[showView]->SetVisible(true); Draw(); + DestroyTempView(hideView); + return; } UIScrollView *AiVoiceView::GetAiVoiceScrollView(int16_t index) diff --git a/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h b/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h index d176bc223..4a3b4f87e 100755 --- a/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h +++ b/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h @@ -155,7 +155,7 @@ public: std::stack tempStack = backStack_; while(!tempStack.empty()) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "%d,", tempStack.top()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%d,", tempStack.top()); tempStack.pop(); } } -- 2.17.1