增加自定义视频表盘相关配置;修复电量变红的bug 1930/1 1930/head 1931/target/1
authorCaisking <Casiking@zhihuishixun.com>
Fri, 4 Jul 2025 09:18:46 +0000 (17:18 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Fri, 4 Jul 2025 09:18:46 +0000 (17:18 +0800)
code/sdk/application/wearable/fd230app/nativeui/clock/include/MainClockView.h
code/sdk/application/wearable/fd230app/nativeui/clock/src/MainClockView.cpp
code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c

index 5f3a8d3..eaebfa2 100644 (file)
@@ -15,7 +15,6 @@
 #define MAIN_CLOCK_VIEW_H
 
 #include <string>
-#include <time.h>
 #include "View.h"
 #include "components/ui_view_group.h"
 #include "components/ui_image_view.h"
@@ -39,6 +38,9 @@
 #include "animator/animator_manager.h"
 #include "time.h"
 #include "sys/time.h"
+#include "components/ui_lite_surface_view.h"
+#include "video_play_wrapper.h"
+#include "DialVideoView.h"
 
 namespace OHOS
 {
@@ -69,7 +71,7 @@ namespace OHOS
         TIME_DISPLAY_DEFAULT = TIME_DISPLAY_BELOW // 默认:下方
     };
 
-    class MainClockView : public UICardPage
+    class MainClockView : public UICardPage 
     {
     public:
         MainClockView();
@@ -103,6 +105,14 @@ namespace OHOS
 
         void UpdateStateShow(void);
 
+
+        void ScrollBegin(bool isActive) override;
+        void ScrollEnd(bool isActive) override;
+        void CoverBegin(bool isCovered) override;
+        void CoverEnd(bool isCovered) override;
+        void OnActive(void) override;
+        void OnInactive(void) override;
+
     private:
         void InitStepValue();
         bool InitLabelView(void);
@@ -115,6 +125,8 @@ namespace OHOS
 
         /*表盘背景*/
         UIImageView *curFace{nullptr};
+        DialVideoView* videoPlayer_ = nullptr;
+        UILiteSurfaceView *surfaceView_ = nullptr;
         
         /*时间相关*/
         UILabel *timerlabel{nullptr};
@@ -155,7 +167,7 @@ namespace OHOS
         BatteryDisplayType batterySetting = BATTERY_DISPLAY_NONE; // 电池设置
         TimeDisplayPosition timePosition = TIME_DISPLAY_DEFAULT;  // 时间位置
         int64_t color_ = Color::White().full;                     // 电量颜色
-        int32_t power_ = -1;                                      // 电量
+        int32_t power_ = 100;                                     // 电量
         bool isBatteryIconVisible{false};                         // 电池暂停
     };
 } // namespace OHOS
index fd4c7f4..183b33d 100644 (file)
@@ -21,6 +21,9 @@
 #include "custom_runtime.h"
 #include "main/include/PullUpDownView.h"
 #include "message/include/MessageControlView.h"
+#include "components/ui_lite_surface_view.h"
+#include "video_play_wrapper.h"
+// #include "main/include/dial/DialVideoView.h"
 #include "ui_resource_image.h"
 #include "wearable_log.h"
 #include <cwchar>
@@ -99,6 +102,17 @@ namespace OHOS
 #endif
     static constexpr uint16_t STEP_CHAR_NUM = 255;
     static MainClockView *g_pMainClockView = nullptr;
+    static constexpr int16_t JPEG_HEIGHT_DIVISOR = 2;
+    static constexpr int16_t JPEG_WIDTH_BYTE_ALIGNMENT = 128;
+    static constexpr int16_t JPEG_HEIGHT_BYTE_ALIGNMENT = 16;
+    static constexpr int16_t BUFFER_QUEUE_SIZE = 2;
+    static constexpr int16_t STRIDE_ALIGNMENT_VALUE = 128;
+
+    static inline int32_t MediaByteAlign(int16_t value, int16_t align)
+    {
+        return (((value) + (align) - 1) & (~((align) - 1)));
+    }
+
     MainClockView::MainClockView()
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainClockView::MainClockView");
@@ -134,11 +148,14 @@ namespace OHOS
           delete dialstateicon_;
           dialstateicon_ = nullptr;
         }
-
         if (messageicon_ != nullptr) {
           delete messageicon_;
           messageicon_ = nullptr;
         }
+        if (videoPlayer_ != nullptr) {
+            delete videoPlayer_;
+            videoPlayer_ = nullptr;
+        }
 
         g_pMainClockView = nullptr;
     }
@@ -157,8 +174,15 @@ namespace OHOS
         DialLayout dialconfig;
         if (SetDialModel::GetInstance().loadDialConfig(Id, dialconfig))
         {
-            // 设置背景
-            dialFile = SetDialModel::GetInstance().GetSaveDir(Id) + "/" + "main_bg.bin";
+            // 设置背景 Id == 2(实际是1) 视频表盘
+            if(Id == 2)
+            {
+                dialFile = SetDialModel::GetInstance().GetSaveDir(Id) + "/" + "main_bg.mp4";
+            }
+            else // 图片表盘
+            {
+                dialFile = SetDialModel::GetInstance().GetSaveDir(Id) + "/" + "main_bg.bin";
+            }
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dialFile is %s", dialFile.c_str());
 
             // 设置表盘配置
@@ -192,36 +216,67 @@ namespace OHOS
         InitColor(colorType);
         return true;
     }
-    /*初始化表盘背景*/
-    bool MainClockView::InitBackground(const char *filename) {
 
+    /*初始化表盘背景 图片 视频*/
+    bool MainClockView::InitBackground(const char *filename) {
         if (filename == nullptr) {
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "filename is null");
             return false;
         }
-        curFace = new UIImageView();
-        if (curFace == nullptr)
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "curFace new fail");
-            return false;
-        }
-        curFace->SetPosition(0, 0);
 
-        ImageCacheManager::GetInstance().UnloadSingleRes(filename);
-        ImageInfo *image = ImageCacheManager::GetInstance().LoadSingleRes(filename, false);
-        if (image == nullptr)
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadAllDialFromRam loadimage %s fail",
-                            filename);
-            curFace->SetSrc(DEFAULT_DIALBACK_PATH);
+        // 判断是否为视频表盘(图片表盘后缀为.bin,视频表盘后缀为.mp4)
+        const char* ext = strrchr(filename, '.');
+        bool isVideo = (ext != nullptr && strcasecmp(ext, ".mp4") == 0);
+
+        if (isVideo) {
+            // 判断文件是否存在
+            if (access(filename, F_OK) == -1) {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Error: The specified video file does not exist: %s", filename);
+                return false;
+            }
+
+            // 检查视频播放器是否已初始化
+            if (videoPlayer_ != nullptr) {
+                GRAPHIC_LOGE("Cannot set video res repeatedly!\n");
+                return false;
+            }
+
+            // 打开视频文件
+            FILE* fp = fopen(filename, "rb");
+            if (fp == nullptr) {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to open video file: %s", filename);
+                return false;
+            }
+
+            videoPlayer_ = new DialVideoView();
+            videoPlayer_->SetPosition(0 ,0,466, 466);
+            videoPlayer_->SetSurfaceColorkey(Color::White());
+            videoPlayer_->SetVideoRes(fp, 0);
+           
+            Add(videoPlayer_);
+            return true;
+        } else {
+            // 处理图片表盘
+            curFace = new UIImageView();
+            if (curFace == nullptr) {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "curFace new fail");
+                return false;
+            }
+            curFace->SetPosition(0, 0);
+
+            ImageCacheManager::GetInstance().UnloadSingleRes(filename);
+            ImageInfo *image = ImageCacheManager::GetInstance().LoadSingleRes(filename, false);
+            if (image == nullptr) {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadAllDialFromRam loadimage %s fail", filename);
+                curFace->SetSrc(DEFAULT_DIALBACK_PATH);
+                Add(curFace);
+                return false;
+            }
+            curFace->SetSrc(image);
             Add(curFace);
-            return false;
+            return true;
         }
-        curFace->SetSrc(image);
-        Add(curFace);
-        return true;
     }
-
     /*
         时间显示 [时间 日期 星期]
         0 显示在表盘上方
@@ -806,4 +861,106 @@ namespace OHOS
         view->SetSrc(image);
         return true;
     }
+
+    void MainClockView::ScrollBegin(bool isActive)
+    {
+        if (videoPlayer_ == nullptr)
+        {
+            return;
+        }
+        if (videoPlayer_->IsPlayed())
+        {
+            videoPlayer_->PausePlay();
+        }
+    }
+
+    void MainClockView::ScrollEnd(bool isActive)
+    {
+        if (videoPlayer_ == nullptr)
+        {
+            return;
+        }
+
+        if (isActive)
+        {
+            if (videoPlayer_->IsPaused())
+            {
+                videoPlayer_->ResumePlay();
+            }
+            else if (!videoPlayer_->IsPlayed())
+            {
+                videoPlayer_->StartPlay();
+            }
+        }
+        else
+        {
+            if (videoPlayer_->IsPaused() || videoPlayer_->IsPlayed())
+            {
+                videoPlayer_->StopPlay();
+            }
+            ClearCache();
+        }
+    }
+
+    void MainClockView::CoverBegin(bool isCovered)
+    {
+        if (videoPlayer_ == nullptr)
+        {
+            return;
+        }
+
+        if (videoPlayer_->IsPlayed())
+        {
+            videoPlayer_->PausePlay();
+        }
+    }
+
+    void MainClockView::CoverEnd(bool isCovered)
+    {
+        if (videoPlayer_ == nullptr)
+        {
+            return;
+        }
+        if (isCovered)
+        {
+            return;
+        }
+        else
+        {
+            if (videoPlayer_->IsPaused())
+            {
+                videoPlayer_->ResumePlay();
+            }
+            else if (!videoPlayer_->IsPlayed())
+            {
+                videoPlayer_->StartPlay();
+            }
+        }
+    }
+
+    void MainClockView::OnActive(void)
+    {
+        if (videoPlayer_ != nullptr)
+        {
+            if (videoPlayer_->IsPaused())
+            {
+                videoPlayer_->ResumePlay();
+            }
+            else if (!videoPlayer_->IsPlayed())
+            {
+                videoPlayer_->StartPlay();
+            }
+        }
+    }
+
+    void MainClockView::OnInactive(void)
+    {
+        if (videoPlayer_ != nullptr)
+        {
+            if (!videoPlayer_->IsStopped())
+            {
+                videoPlayer_->StopPlay();
+            }
+        }
+    }
 }
index 988a53d..775469b 100644 (file)
@@ -216,8 +216,15 @@ static errcode_t get_custom_dial_file_path(uint16_t id,char *filename,uint32_t i
     }\r
     char name[64]={0};\r
     ble_get_dial_path(name,id);\r
-\r
-    int ret = sprintf_s(output_file_path,max_output_size,"%s/%s.bin",name,filename);\r
+    int ret;\r
+    if(id == 1) //自定义视频表盘Id 1\r
+    {\r
+        ret = sprintf_s(output_file_path,max_output_size,"%s/%s.mp4",name,filename);  \r
+    }\r
+    else\r
+    {\r
+        ret = sprintf_s(output_file_path,max_output_size,"%s/%s.bin",name,filename);\r
+    }\r
     if (ret < 0)\r
         return ERRCODE_FAIL;\r
 \r