/***
- * @Date: 2024-04-23 16:04:40
+ * @Date: 2024-05-10 10:27:30
* @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-04-23 16:11:30
- * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/uicomponents/UIComponents.cpp
+ * @LastEditTime: 2024-05-10 11:03:56
+ * @FilePath: /sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp
*/
#include "uicomponents/UIComponents.h"
-
+#include <vector>
namespace OHOS
{
/***
// WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitImageView is succeed");
return true;
}
- /**
- * 创建包含图片文件路径的数组
- * @param basePath 包含图片文件的基本路径
- * @param fileExtension 图片文件的扩展名
- * @param numImages 图片文件的数量
- * @return 返回包含图片文件路径的数组
- */
- const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages)
- {
- const char **imagePaths = new const char *[numImages];
- 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);
- }
- return imagePaths;
- }
- /**
- * @brief 初始化UIImageAnimatorView,并设置为GIF动画。
- *
- * 该函数用于使用提供的GIF图像和属性初始化UIImageAnimatorView。
- *
- * @param imageAnimator 要初始化的UIImageAnimatorView对象的引用。
- * @param paths GIF图像文件路径的数组。
- * @param numFrames GIF中的帧数。
- * @param left 视图的左侧位置。
- * @param top 视图的顶部位置。
- * @param width 视图的宽度。
- * @param height 视图的高度。
- * @param viewId 视图的ID。
- * @param time 视图的帧速
- * @return 如果初始化成功则返回true,否则返回false。
- */
- void InitImageAnimatorSource(UIImageAnimatorView *&imageAnimator, const char **imagePaths, int numFrames, int left, int top, int width, int height, const char *viewId, int time)
- {
- if (imageAnimator == nullptr)
- {
- imageAnimator = new UIImageAnimatorView();
- }
- imageAnimator->SetPosition(left, top);
- imageAnimator->Resize(width, height);
- imageAnimator->SetViewId(viewId);
- // imageAnimator->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);
- imageAnimator->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
-
- ImageAnimatorInfo *imageAnimatorInfo = new ImageAnimatorInfo[numFrames];
- for (int i = 0; i < numFrames; i++)
- {
- imageAnimatorInfo[i].imagePath = imagePaths[i];
- imageAnimatorInfo[i].pos.x = left;
- imageAnimatorInfo[i].pos.y = top;
- imageAnimatorInfo[i].width = width;
- imageAnimatorInfo[i].height = height;
- imageAnimatorInfo[i].imageType = IMG_SRC_FILE_PATH;
- }
-
- imageAnimator->SetImageAnimatorSrc(imageAnimatorInfo, numFrames, time); // 200 is the default delay time
- imageAnimator->SetTimeOfPause(time);
- imageAnimator->SetRepeat(true);
- // imageAnimator->SetReverse(true);
- // imageAnimator->SetVisible(true);
- }
/*带默认参数的初始化label*/
void InitLabelDefault(UILabelExt *&label, int x, int y, int width, int height, const char *viewId, const char *text, int fontSize, const char *fontName)
{
InitLabel(label, x, y, width, height, viewId, text, fontName, fontSize);
}
-
+ /* -------------------------------------------------------------------------- */
/*替换字符串中的变量*/
std::string UpdateLabelText(UILabelExt *&label, const std::string &newText, UIResourceTextId id)
{
delete labelext;
}
+ /* -------------------------------------------------------------------------- */
+ /**
+ * 创建包含图片文件路径的数组
+ * @param basePath 包含图片文件的基本路径
+ * @param fileExtension 图片文件的扩展名
+ * @param numImages 图片文件的数量
+ * @return 返回包含图片文件路径的数组
+ */
+ const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages)
+ {
+ const char **imagePaths = new const char *[numImages];
+ 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);
+ }
+ return imagePaths;
+ }
+
/*解析动画资源数组 imageche*/
- void AnalysisArray(const char *fliename)
+ std::vector<ImageInfo *> AnalysisArray(const char *filename, uint32_t startId, uint32_t lastId)
{
-#if 0
+ std::vector<ImageInfo *> imageArray;
+
for (uint32_t i = startId; i <= lastId; i++)
{
- ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(i, file);
+ ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(i, filename);
if (image == nullptr)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadAppMultiImages %x fail", i);
- return;
+ // 如果加载失败,可以选择继续加载下一个,或者在这里处理其他逻辑
+ continue;
}
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LoadAppMultiImages %x", i);
+ imageArray.push_back(image);
}
-#endif
+ return imageArray;
+ }
+ /**
+ * @brief 初始化UIImageAnimatorView,并设置为GIF动画。
+ *
+ * 该函数用于使用提供的GIF图像和属性初始化UIImageAnimatorView。
+ *
+ * @param imageAnimator 要初始化的UIImageAnimatorView对象的引用。
+ * @param paths GIF图像文件路径的数组。
+ * @param numFrames GIF中的帧数。
+ * @param left 视图的左侧位置。
+ * @param top 视图的顶部位置。
+ * @param width 视图的宽度。
+ * @param height 视图的高度。
+ * @param viewId 视图的ID。
+ * @param time 视图的帧速
+ * @return 如果初始化成功则返回true,否则返回false。
+ */
+ void InitImageAnimatorSource(UIImageAnimatorView *&imageAnimator, const char **imagePaths, int numFrames, int left, int top, int width, int height, const char *viewId, int time)
+ {
+ if (imageAnimator == nullptr)
+ {
+ imageAnimator = new UIImageAnimatorView();
+ }
+ imageAnimator->SetPosition(left, top);
+ imageAnimator->Resize(width, height);
+ imageAnimator->SetViewId(viewId);
+ // imageAnimator->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);
+ imageAnimator->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+
+ ImageAnimatorInfo *imageAnimatorInfo = new ImageAnimatorInfo[numFrames];
+ for (int i = 0; i < numFrames; i++)
+ {
+ imageAnimatorInfo[i].imagePath = imagePaths[i];
+ imageAnimatorInfo[i].pos.x = left;
+ imageAnimatorInfo[i].pos.y = top;
+ imageAnimatorInfo[i].width = width;
+ imageAnimatorInfo[i].height = height;
+ imageAnimatorInfo[i].imageType = IMG_SRC_FILE_PATH;
+ }
+
+ imageAnimator->SetImageAnimatorSrc(imageAnimatorInfo, numFrames, time); // 200 is the default delay time
+ imageAnimator->SetTimeOfPause(time);
+ imageAnimator->SetRepeat(true);
+ // imageAnimator->SetReverse(true);
+ // imageAnimator->SetVisible(true);
}
}