From: xue <2144439972@qq.com> Date: Tue, 30 Sep 2025 07:31:49 +0000 (+0800) Subject: 增加下载切换界面 X-Git-Tag: V1.0.9_20251128_194606_LN~274^2~12 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=434ed7f1f35a8da77fe524071662068a593f2f19;p=mirrors%2FFD230.git 增加下载切换界面 --- diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/ota/include/OtaDownloadView.h b/code/sdk/application/wearable/ln/nativeapp/nativeui/ota/include/OtaDownloadView.h new file mode 100644 index 000000000..cd1b4e04b --- /dev/null +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/ota/include/OtaDownloadView.h @@ -0,0 +1,54 @@ +/* + * @Author: Assistant + * @Date: 2024-12-19 + * @Description: OTA Download View - OTA下载界面头文件 + */ +#ifndef OTA_DOWNLOAD_VIEW_H +#define OTA_DOWNLOAD_VIEW_H + +#include "View.h" +#include "Presenter.h" +#include "components/ui_view_group.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_box_progress.h" + +namespace OHOS +{ + class OtaPresenter; + + class OtaDownloadView : public View + { + public: + OtaDownloadView(); + ~OtaDownloadView(); + + static OtaDownloadView* GetInstance(); + + UIViewGroup* InitUI(); + void ClearAll(); + + // 更新下载进度 + void UpdateDownloadProgress(int progress); + + // 更新下载状态文本 + void UpdateDownloadStatus(const char* status); + + // 设置下载类型 + void SetDownloadType(int type); + + private: + UIViewGroup *group{nullptr}; + UILabelExt *TextLabel{nullptr}; + UILabelExt *StatusLabel{nullptr}; + UILabelExt *ProgressLabel{nullptr}; + UILabelExt *RemindLabel{nullptr}; + UIImageView *RemindIcon{nullptr}; + UIBoxProgress *ProgressBar{nullptr}; + + int downloadType{-1}; + int currentProgress{0}; + }; +} + +#endif // OTA_DOWNLOAD_VIEW_H diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/ota/include/OtaView.h b/code/sdk/application/wearable/ln/nativeapp/nativeui/ota/include/OtaView.h index adc2f7bcf..4c92b2955 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/ota/include/OtaView.h +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/ota/include/OtaView.h @@ -26,6 +26,7 @@ #include "ota/include/OtaMemoryErrorView.h" #include "ota/include/OtaNightUpdateView.h" #include "ota/include/OtaNightUpdateSuccessView.h" +#include "ota/include/OtaDownloadView.h" #include "thunderbird/include/ThunderBirdMainView.h" @@ -59,6 +60,7 @@ namespace OHOS OTA_VIEW_MEMORY_ERROR, // 内存不足 OTA_VIEW_UPDATE_SUCCESS, // 更新成功 OTA_VIEW_UPDATE_FAILED, // 更新未完成 + OTA_VIEW_DOWNLOAD, // 下载界面 MAX_OTA_VIEW, }; bool ChangeOtaNormalView(int16_t thisView); @@ -73,6 +75,7 @@ namespace OHOS bool ChangeOtaMemoryErrorView(int16_t thisView); bool ChangeOtaNightUpdateView(int16_t thisView); bool ChangeOtaNightUpdateSuccessView(int16_t thisView); + bool ChangeOtaDownloadView(int16_t thisView); bool ClickFunc(int16_t interface); void ChangeView(int16_t hideView, int16_t showView); int16_t GetCurrentView(); @@ -119,6 +122,7 @@ namespace OHOS OtaMemoryErrorView *g_pOtaMemoryErrorView{nullptr}; OtaNightUpdateView *g_pOtaNightUpdateView{nullptr}; OtaNightUpdateSuccessView *g_pOtaNightUpdateSuccessView{nullptr}; + OtaDownloadView *g_pOtaDownloadView{nullptr}; }; } diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/ota/src/OtaDownloadView.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/ota/src/OtaDownloadView.cpp new file mode 100644 index 000000000..8ecc83405 --- /dev/null +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/ota/src/OtaDownloadView.cpp @@ -0,0 +1,177 @@ +/* + * @Author: Assistant + * @Date: 2024-12-19 + * @Description: OTA Download View - OTA下载界面实现 + */ +#include "ota/include/OtaDownloadView.h" +#include "ota/include/OtaPresenter.h" +#include "wearable_log.h" + +namespace OHOS +{ + static OtaDownloadView *g_pOtaDownloadView{nullptr}; + + OtaDownloadView::OtaDownloadView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OtaDownloadView::OtaDownloadView"); + g_pOtaDownloadView = this; + } + + OtaDownloadView::~OtaDownloadView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OtaDownloadView::~OtaDownloadView"); + ClearAll(); + g_pOtaDownloadView = nullptr; + } + + OtaDownloadView* OtaDownloadView::GetInstance() + { + return g_pOtaDownloadView; + } + + UIViewGroup* OtaDownloadView::InitUI() + { + // 创建主容器 + group = new UIViewGroup(); + if (group) { + group->SetPosition(0, 0, 360, 360); + group->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + group->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + } + + // 创建背景 + // 背景图已移至OtaView.cpp作为最底层背景 + + // 创建主标题 + TextLabel = new UILabelExt(); + if (TextLabel) { + TextLabel->SetPosition(127, 100, 164, 42); + TextLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + TextLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24); + TextLabel->SetStyle(STYLE_TEXT_COLOR, 0xffffffff); + TextLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + TextLabel->SetText("正在下载"); + TextLabel->SetVisible(true); + group->Add(TextLabel); + } + + // 创建状态标签 + StatusLabel = new UILabelExt(); + if (StatusLabel) { + StatusLabel->SetPosition(80, 150, 220, 28); + StatusLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + StatusLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20); + StatusLabel->SetStyle(STYLE_TEXT_COLOR, 0xffffffff); + StatusLabel->SetText("准备下载..."); + StatusLabel->SetVisible(true); + group->Add(StatusLabel); + } + + // 创建进度条 + ProgressBar = new UIBoxProgress(); + if (ProgressBar) { + ProgressBar->SetPosition(80, 200, 200, 8); + ProgressBar->SetRange(100, 0); + ProgressBar->SetBackgroundStyle(STYLE_BACKGROUND_OPA, 0xff); + ProgressBar->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0xff333333); + ProgressBar->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xff00ff00); + ProgressBar->SetValue(0); + ProgressBar->SetVisible(true); + group->Add(ProgressBar); + } + + // 创建进度文本 + ProgressLabel = new UILabelExt(); + if (ProgressLabel) { + ProgressLabel->SetPosition(80, 220, 200, 24); + ProgressLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + ProgressLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 18); + ProgressLabel->SetStyle(STYLE_TEXT_COLOR, 0xffffffff); + ProgressLabel->SetText("0%"); + ProgressLabel->SetVisible(true); + group->Add(ProgressLabel); + } + // 创建提示标签 + RemindLabel = new UILabelExt(); + if (RemindLabel) { + RemindLabel->SetPosition(136, 300, 88, 25); + RemindLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + RemindLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20); + RemindLabel->SetStyle(STYLE_TEXT_COLOR, 0xffffffff); + RemindLabel->SetText("请稍候..."); + RemindLabel->SetVisible(true); + group->Add(RemindLabel); + } + + return group; + } + + void OtaDownloadView::ClearAll() + { + if (group) { + group->RemoveAll(); + delete group; + group = nullptr; + } + + if (TextLabel) { delete TextLabel; TextLabel = nullptr; } + if (StatusLabel) { delete StatusLabel; StatusLabel = nullptr; } + if (ProgressLabel) { delete ProgressLabel; ProgressLabel = nullptr; } + if (RemindLabel) { delete RemindLabel; RemindLabel = nullptr; } + if (RemindIcon) { delete RemindIcon; RemindIcon = nullptr; } + if (ProgressBar) { delete ProgressBar; ProgressBar = nullptr; } + } + + void OtaDownloadView::UpdateDownloadProgress(int progress) + { + if (progress < 0) progress = 0; + if (progress > 100) progress = 100; + + currentProgress = progress; + + if (ProgressBar) { + ProgressBar->SetValue(progress); + ProgressBar->Invalidate(); + } + + if (ProgressLabel) { + char progressText[16]; + snprintf(progressText, sizeof(progressText), "%d%%", progress); + ProgressLabel->SetText(progressText); + ProgressLabel->Invalidate(); + } + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OtaDownloadView::UpdateDownloadProgress: %d%%", progress); + } + + void OtaDownloadView::UpdateDownloadStatus(const char* status) + { + if (StatusLabel && status) { + StatusLabel->SetText(status); + StatusLabel->Invalidate(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OtaDownloadView::UpdateDownloadStatus: %s", status); + } + } + + void OtaDownloadView::SetDownloadType(int type) + { + downloadType = type; + + if (TextLabel) { + switch (type) { + case 1: // 屏保下载 + TextLabel->SetText("下载屏保"); + break; + case 2: // 表情下载 + TextLabel->SetText("下载表情"); + break; + default: + TextLabel->SetText("正在下载"); + break; + } + TextLabel->Invalidate(); + } + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OtaDownloadView::SetDownloadType: %d", type); + } +} diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/ota/src/OtaView.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/ota/src/OtaView.cpp index c7bed52a0..0f99c735d 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/ota/src/OtaView.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/ota/src/OtaView.cpp @@ -17,6 +17,7 @@ #include "ota/include/OtaUpdateNowView.h" #include "ota/include/OtaNightUpdateView.h" #include "ota/include/OtaNightUpdateSuccessView.h" +#include "ota/include/OtaDownloadView.h" #include "ota/include/OtaModel.h" #include "wearable_log.h" #include "custom_utils.h" @@ -88,6 +89,17 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "强制升级"); ChangeView(MAX_OTA_VIEW, OTA_VIEW_UPDATE_NOW); } + else //下载界面,需要根据文件下载类型判断 + { + int downloadFileType = ThunderBirdModel::GetInstance()->GetDownloadFile(); + if(downloadFileType != -1) + { + ChangeView(MAX_OTA_VIEW, OTA_VIEW_NIGHT_UPDATE); + } + + } + + // 添加状态栏(如果ThunderBirdMainView存在则复用,否则创建独立的状态栏) @@ -288,6 +300,21 @@ namespace OHOS } return true; } + bool OtaView::ChangeOtaDownloadView(int16_t thisView) // 切换下载界面接口 + { + if (group[thisView] == nullptr) + { + g_pOtaDownloadView = new OtaDownloadView(); + if (g_pOtaDownloadView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OtaDownloadView new fail %d", thisView); + return false; + } + group[thisView] = g_pOtaDownloadView->InitUI(); + ScrollView_->Add(group[thisView]); + } + return true; + } struct OtaViewMapper { @@ -308,6 +335,7 @@ namespace OHOS {OtaView::OTA_VIEW_MEMORY_ERROR, &OtaView::ChangeOtaMemoryErrorView}, {OtaView::OTA_VIEW_UPDATE_SUCCESS, &OtaView::ChangeOtaSuccessView}, {OtaView::OTA_VIEW_UPDATE_FAILED, &OtaView::ChangeOtaFailedView}, + {OtaView::OTA_VIEW_DOWNLOAD, &OtaView::ChangeOtaDownloadView}, }; bool OtaView::ClickFunc(int16_t interface) @@ -488,6 +516,10 @@ namespace OHOS delete g_pOtaNightUpdateSuccessView; g_pOtaNightUpdateSuccessView = nullptr; } + if (g_pOtaDownloadView) { + delete g_pOtaDownloadView; + g_pOtaDownloadView = nullptr; + } } @@ -743,4 +775,6 @@ namespace OHOS } } + + } diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h index e57f69f2a..1a3060f5c 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h @@ -195,6 +195,11 @@ namespace OHOS // API错误处理函数 void HandleApiError(const char* message); + // 文件下载处理函数 + void HandleDownloadFile(int type); + // 获取文件下载类型 + int GetDownloadFile(); + // 表情切换函数 bool SwitchExpression(const char* eyeShape, const char* eyeColor); @@ -273,6 +278,8 @@ namespace OHOS std::string hairStyle_; std::string screenImage_; bool screenImageAsEmoji_{false}; + + int downloadFileType = -1; }; } diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp index c60cc205a..2d14d2db8 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp @@ -1876,6 +1876,35 @@ } } + void ThunderBirdModel::HandleDownloadFile(int type) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::HandleDownloadFile"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Download type: %d", type); + + // 根据下载类型进行不同的处理 + switch (type) { + case DOWNLOAD_FILE_TYPE_SCREEN_IMAGE: // 屏保下载 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::HandleDownloadFile: Starting emoji download"); + // 这里可以添加表情下载的具体逻辑 + break; + case DOWNLOAD_FILE_TYPE_EMOJI: // 表情下载 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::HandleDownloadFile: Starting hair download"); + // 这里可以添加发型下载的具体逻辑 + break; + default: + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::HandleDownloadFile: Unknown download type: %d", type); + break; + } + //跳转到OTA下载界 + downloadFileType = type; + NativeAbility::GetInstance().ChangeSlice(VIEW_OTA); + } + + int ThunderBirdModel::GetDownloadFile() + { + return downloadFileType; + } + //减低视频帧率 开启对话调用开启 void ThunderBirdModel::LowFrequence() { diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp index d20e286f6..6ad44cb89 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp @@ -569,8 +569,8 @@ void HandDownloadFileNotify(Request *request) WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandDownloadFileNotify msg_id = %d", request->msgId); int type = *(int *)request->data; WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandDownloadFileNotify type = %d", type); - // GraphicService::GetInstance()->PostGraphicEvent( - // std::bind(&OHOS::ThunderBirdModel::HandleDownloadFile,OHOS::ThunderBirdModel::GetInstance(), type)); + GraphicService::GetInstance()->PostGraphicEvent( + std::bind(&OHOS::ThunderBirdModel::HandleDownloadFile,OHOS::ThunderBirdModel::GetInstance(), type)); } // 下载成功通知 void HandDownloadSuccessNotify(Request *request) @@ -583,6 +583,11 @@ void HandDownloadSuccessNotify(Request *request) GraphicService::GetInstance()->PostGraphicEvent( std::bind(&OHOS::ThunderBirdModel::HandleScreenImageDownloadSuccess,OHOS::ThunderBirdModel::GetInstance())); } + if(type == 1) //表情切换 + { + // GraphicService::GetInstance()->PostGraphicEvent( + // std::bind(&OHOS::ThunderBirdModel::HandleDownloadEmojiSuccess,OHOS::ThunderBirdModel::GetInstance())); + } } /* -------------------------------------------------------------------------- */ #ifdef __cplusplus