* @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
*/
#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
{
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};
};
}
* @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"
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()
{
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;
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");
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");
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);
* @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"
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");
ClickFunc(showView);
AiVoiceScrollView[showView]->SetVisible(true);
Draw();
+ DestroyTempView(hideView);
+ return;
}
UIScrollView *AiVoiceView::GetAiVoiceScrollView(int16_t index)