From 253b38b57686573c33d7a945783579ffb697dd3b Mon Sep 17 00:00:00 2001 From: Caisking Date: Tue, 9 Sep 2025 11:32:07 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89?= =?utf8?q?=E8=A1=A8=E7=9B=98=E7=9A=84=E5=86=85=E5=AE=B9=E7=A7=BB=E6=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/clock/include/MainClockView.h | 20 +- .../nativeui/clock/src/MainClockView.cpp | 276 ++++++++++++++---- .../ble_service/bleservice/bleEvent.c | 13 +- 3 files changed, 253 insertions(+), 56 deletions(-) diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/clock/include/MainClockView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/clock/include/MainClockView.h index 13b254ad2..732cce462 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/clock/include/MainClockView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/clock/include/MainClockView.h @@ -14,8 +14,8 @@ #ifndef MAIN_CLOCK_VIEW_H #define MAIN_CLOCK_VIEW_H + #include #include - #include #include "View.h" #include "components/ui_view_group.h" #include "components/ui_image_view.h" @@ -38,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 "main/include/dial/DialVideoView.h" namespace OHOS { @@ -68,7 +71,7 @@ TIME_DISPLAY_DEFAULT = TIME_DISPLAY_BELOW // 默认:下方 }; - class MainClockView : public UICardPage + class MainClockView : public UICardPage { public: MainClockView(); @@ -102,6 +105,14 @@ 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); @@ -114,6 +125,8 @@ /*表盘背景*/ UIImageView *curFace{nullptr}; + DialVideoView* videoPlayer_ = nullptr; + UILiteSurfaceView *surfaceView_ = nullptr; /*时间相关*/ UILabel *timerlabel{nullptr}; @@ -154,8 +167,9 @@ BatteryDisplayType batterySetting = BATTERY_DISPLAY_NONE; // 电池设置 TimeDisplayPosition timePosition = TIME_DISPLAY_DEFAULT; // 时间位置 int64_t color_ = Color::White().full; // 电量颜色 - int32_t power_ = 101; // 电量 + int32_t power_ = 101; // 电量 bool isBatteryIconVisible{false}; // 电池暂停 + uint8_t custom_id = 0; }; } // namespace OHOS #endif // MAIN_CLOCK_VIEW_H diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/clock/src/MainClockView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/clock/src/MainClockView.cpp index dd2b957e0..da206580d 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/clock/src/MainClockView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/clock/src/MainClockView.cpp @@ -22,9 +22,10 @@ #include "main/include/PullUpDownView.h" #include "message/include/MessageControlView.h" #include "uicomponents/UIComponents.h" + #include "components/ui_lite_surface_view.h" + #include "video_play_wrapper.h" #include "ui_resource_image.h" - #include "wearable_log.h" #include #include @@ -104,6 +105,17 @@ #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"); @@ -139,11 +151,14 @@ delete dialstateicon_; dialstateicon_ = nullptr; } - if (messageicon_ != nullptr) { delete messageicon_; messageicon_ = nullptr; } + if (videoPlayer_ != nullptr) { + delete videoPlayer_; + videoPlayer_ = nullptr; + } g_pMainClockView = nullptr; } @@ -159,17 +174,32 @@ if (Id == DIAL_CLOCK || Id > DIAL_MAX) return; + //赋值id + custom_id = Id; + DialLayout dialconfig; - if (SetDialModel::GetInstance().loadDialConfig(Id, dialconfig)) + if (SetDialModel::GetInstance().loadDialConfig(custom_id, dialconfig)) { - // 设置背景 - dialFile = SetDialModel::GetInstance().GetSaveDir(Id) + "/" + "main_bg.bin"; + // 设置背景 Id == 2(实际是1) 视频表盘 + if(Id == 2) + { + dialFile = SetDialModel::GetInstance().GetSaveDir(custom_id) + "/" + "main_bg.mp4"; + } + else // 图片表盘 + { + dialFile = SetDialModel::GetInstance().GetSaveDir(custom_id) + "/" + "main_bg.bin"; + } WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dialFile is %s", dialFile.c_str()); // 设置表盘配置 timePosition = static_cast(dialconfig.timeDisplay); batterySetting = static_cast(dialconfig.batteryDisplay); colorType = static_cast(dialconfig.colorTypeSet); + + //打印表盘配置 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timePosition is %d", timePosition); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batterySetting is %d", batterySetting); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "colorType is %d", colorType); } else { @@ -197,36 +227,77 @@ 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::GetColorFromRGBA(0xff,0x21,0x23,0x24)); + videoPlayer_->SetVideoRes(fp, 0); + //阅览帧 preview.bin + std::string preview_img = SetDialModel::GetInstance().GetSaveDir(custom_id) + "/" + "preview.bin"; + ImageInfo *image = ImageCacheManager::GetInstance().LoadSingleRes(preview_img.c_str(), false); + if (image != nullptr) { + videoPlayer_->SetPreview(image); + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadAllDialFromRam loadimage %s fail", preview_img.c_str()); + return false; + } + 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 显示在表盘上方 @@ -287,8 +358,6 @@ Add(timerlabel); Add(datelabel); // Add(weekLabel); - - // timerlabel->SetWorkMode(UISweepClock::WorkMode::NORMAL); return true; } /* @@ -465,7 +534,6 @@ /*增加手表状态图标*/ InitImageView(dialstateicon_, 213, 2, 40, 40, "disturbicon", DISTURBICON); - dialstateicon_->SetVisible(false); /*增加未读图标*/ InitImageView(messageicon_, 223, 444, 20, 20, "messageicon_", MESSAGEICON); @@ -480,14 +548,14 @@ if (!resLoadStatus) { - // if (PullUpDownView::GetInstance() != nullptr) - // { - // PullUpDownView::GetInstance()->PreLoad(); - // } - // if (MessageControlView::GetInstance() != nullptr) - // { - // MessageControlView::GetInstance()->PreLoad(); - // } + if (PullUpDownView::GetInstance() != nullptr) + { + PullUpDownView::GetInstance()->PreLoad(); + } + if (MessageControlView::GetInstance() != nullptr) + { + MessageControlView::GetInstance()->PreLoad(); + } resLoadStatus = true; } } @@ -498,15 +566,15 @@ if (resLoadStatus) { - // if (PullUpDownView::GetInstance() != nullptr) - // { - // PullUpDownView::GetInstance()->UnLoad(); - // } + if (PullUpDownView::GetInstance() != nullptr) + { + PullUpDownView::GetInstance()->UnLoad(); + } - // if (MessageControlView::GetInstance() != nullptr) - // { - // MessageControlView::GetInstance()->UnLoad(); - // } + if (MessageControlView::GetInstance() != nullptr) + { + MessageControlView::GetInstance()->UnLoad(); + } resLoadStatus = false; } } @@ -534,13 +602,11 @@ struct tm local_time = {0}; time_t seconds = time(nullptr); - // Get local time if (localtime_r(&seconds, &local_time) == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "get localtime error!"); return; } - // Extract hour and minute uint8_t hour = local_time.tm_hour % HOURS_IN_DAY; uint8_t minute = local_time.tm_min % MINUTES_IN_HOUR; char timebuf[64] = {0}; @@ -560,11 +626,10 @@ sprintf_s(timebuf, sizeof(timebuf), "%02d:%02d", hour, minute); #endif - // Update display labels if (timerlabel != nullptr) timerlabel->SetText(timebuf); - // Update date and week day + std::string weekStr = Cnweekdays[local_time.tm_wday]; std::string dateStr = std::to_string(local_time.tm_mon + 1) + "月" + std::to_string(local_time.tm_mday) + "号 " + weekStr; @@ -572,9 +637,11 @@ if (datelabel != nullptr) datelabel->SetText(dateStr.c_str()); - // Update battery status + + //电量显示配置 if (batterySetting == BATTERY_DISPLAY_NONE) return; + UpdateBatteryColor(); @@ -815,5 +882,114 @@ 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) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnActive"); + if (videoPlayer_ != nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnActive videoPlayer_"); + if (videoPlayer_->IsPaused()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnActive videoPlayer_ resume"); + videoPlayer_->ResumePlay(); + } + else if (!videoPlayer_->IsPlayed()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnActive videoPlayer_ start"); + videoPlayer_->StartPlay(); + } + } + } + + void MainClockView::OnInactive(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnInactive"); + if (videoPlayer_ != nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnInactive videoPlayer_"); + if (!videoPlayer_->IsStopped()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnInactive videoPlayer_ stop"); + videoPlayer_->StopPlay(); + } + } + } } \ No newline at end of file diff --git a/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c b/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c index 4378e2db9..2e152e411 100644 --- a/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c +++ b/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c @@ -235,14 +235,21 @@ static errcode_t get_app_file_path(char* input_filename ,uint32_t input_size, ch } static errcode_t get_custom_dial_file_path(uint16_t id,char *filename,uint32_t input_size, char* output_file_path , uint32_t max_output_size) { - if( id >=5 || output_file_path == NULL) + if( id >=5 || output_file_path == NULL || filename == NULL) { return ERRCODE_FAIL; } char name[64]={0}; ble_get_dial_path(name,id); - - int ret = sprintf_s(output_file_path,max_output_size,"%s/%s.bin",name,filename); + int ret; + if(id == 1 && strcmp(filename, "main_bg") == 0) //自定义视频表盘Id 1 只有背景需要是mp4 main_bg + { + ret = sprintf_s(output_file_path,max_output_size,"%s/%s.mp4",name,filename); + } + else + { + ret = sprintf_s(output_file_path,max_output_size,"%s/%s.bin",name,filename); + } if (ret < 0) return ERRCODE_FAIL; -- 2.17.1