From 24c525bc0de9ddfdb97da5952afdafb85b4a1cf2 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Fri, 31 May 2024 15:00:30 +0800 Subject: [PATCH] =?utf8?q?=E4=B8=8B=E6=8B=89=E8=A7=86=E5=9B=BE=20=E6=9B=B4?= =?utf8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/main/include/PullUpDownView.h | 1 - .../nativeui/main/src/MainPresenterSample.cpp | 2 +- .../nativeui/main/src/PullUpDownView.cpp | 230 +++++++++--------- 3 files changed, 110 insertions(+), 123 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/PullUpDownView.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/PullUpDownView.h index 660b26136..30b4c8539 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/include/PullUpDownView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/PullUpDownView.h @@ -57,7 +57,6 @@ namespace OHOS void UpdateBlueToothStatus(int status); void UpdateDnotDisturbStatus(int status); bool InitBaseData(); // 初始化基础数据组件 - void RefreshData(); // 刷新数据 UILabel *GetTimeLabel(); UILabel *GetDateLabel(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp index 8cbab9f6a..3d1523812 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp @@ -396,7 +396,7 @@ namespace OHOS { // 获取当前时间 char *timeStr = (char *)malloc(9); - if (!timeStr || uapi_get_HHMMSS_Time(timeStr, ':', false) != ERRCODE_SUCC) + if (uapi_get_HHMMSS_Time(timeStr, ':', false) != ERRCODE_SUCC) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get start time"); free(timeStr); diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp index d8a17b8dd..a51016211 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/PullUpDownView.cpp @@ -116,75 +116,105 @@ namespace OHOS void PullUpDownView::ClearAll() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpDownView::ClearAll"); + RemoveAll(); if (group[DROPDOWNVIEW] != nullptr) { - RemoveAll(); group[DROPDOWNVIEW]->RemoveAll(); group[DROPDOWNVIEW]->ClearBackgroundBlur(); + delete group[DROPDOWNVIEW]; + group[DROPDOWNVIEW] = nullptr; + } - for (int i = 0; i < MAX_INDEX; i++) + for (int i = 0; i < MAX_INDEX; i++) + { + if (dropIconBackground[i] != nullptr) { delete dropIconBackground[i]; dropIconBackground[i] = nullptr; } + } + if (dropSetting != nullptr) + { delete dropSetting; dropSetting = nullptr; + } + if (dropLighting != nullptr) + { delete dropLighting; dropLighting = nullptr; + } + if (dropDnotDisturb != nullptr) + { delete dropDnotDisturb; dropDnotDisturb = nullptr; + } + if (dropLine != nullptr) + { delete dropLine; dropLine = nullptr; + } + if (dropSavePower != nullptr) + { delete dropSavePower; dropSavePower = nullptr; + } + if (drofindPhone != nullptr) + { delete drofindPhone; drofindPhone = nullptr; + } + if (showTimeLabel != nullptr) + { delete showTimeLabel; showTimeLabel = nullptr; + } + if (showDateLabel != nullptr) + { delete showDateLabel; showDateLabel = nullptr; + } + if (showWeekLabel != nullptr) + { delete showWeekLabel; showWeekLabel = nullptr; - /* -------------------------------------------------------------------------- */ - ClearAllSingalComponentsView(); - ClearAllConnectedStatusComponentsView(); - /* -------------------------------------------------------------------------- */ - if (batteryimage != nullptr) - { - delete batteryimage; - batteryimage = nullptr; - } - - if (progress != nullptr) - { - delete progress; - progress = nullptr; - } + } + /* -------------------------------------------------------------------------- */ + ClearAllSingalComponentsView(); + ClearAllConnectedStatusComponentsView(); + /* -------------------------------------------------------------------------- */ + if (batteryimage != nullptr) + { + delete batteryimage; + batteryimage = nullptr; + } - if (progresscallback_ != nullptr) - { - delete progresscallback_; - progresscallback_ = nullptr; - } + if (progress != nullptr) + { + delete progress; + progress = nullptr; + } - if (progressanimator_ != nullptr) - { - progressanimator_->Stop(); - delete progressanimator_; - progressanimator_ = nullptr; - } + if (progresscallback_ != nullptr) + { + delete progresscallback_; + progresscallback_ = nullptr; + } - delete group[DROPDOWNVIEW]; - group[DROPDOWNVIEW] = nullptr; + if (progressanimator_ != nullptr) + { + progressanimator_->Stop(); + delete progressanimator_; + progressanimator_ = nullptr; } if (connectedStatusView != nullptr) @@ -193,12 +223,14 @@ namespace OHOS connectedStatusView = nullptr; group[CONNECTEDSTATUSVIEW] = nullptr; } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpDownView::ClearAll end!!"); } /// @brief 初始化icon图标背景 /// @param void void PullUpDownView::InitViewImgBackGround(void) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitViewImgBackGround"); for (int i = 0; i < MAX_INDEX; i++) { dropIconBackground[i] = new UIImageView(); @@ -231,6 +263,7 @@ namespace OHOS /// @param void void PullUpDownView::InitViewImg(void) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitViewImg"); UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::MainPresenterSample::GetInstance(); InitViewImgBackGround(); /* ---------------------------------- 下拉设置图片 ---------------------------------- */ @@ -325,40 +358,44 @@ namespace OHOS // 获取手机连接状态 bool PullUpDownView::GetPhoneConnectedStatus(void) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::GetPhoneConnectedStatus"); uint8_t ret = uapi_dev_runtime_get_ble_connect_stat(); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ble phone connect stat = %d", ret); if (ret == 1) - return true; - else - return false; + return true; + else + return false; } // 获取蓝牙耳机连接状态 bool PullUpDownView::GetEarPhoneConnectedStatus(void) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::GetEarPhoneConnectedStatus"); uint8_t ret = uapi_dev_runtime_get_earphone_connect_stat(); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "earphone connect stat = %d", ret); if (ret == 1) - return true; - else - return false; + return true; + else + return false; } // 获取蓝牙连接状态 bool PullUpDownView::GetBluetoothConnectedStatus(void) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::GetBluetoothConnectedStatus"); uint8_t ret = uapi_dev_runtime_get_br_connect_stat(); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "br connect stat = %d [0 no connect, 1 a2dp, 2 hfp, 3 both]", ret); if (ret != 0) - return true; - else - return false; + return true; + else + return false; } /// @brief 连接状态 /// @param void void PullUpDownView::InitTimeDateWeekLabelAndConnectedStatusImage(void) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitTimeDateWeekLabelAndConnectedStatusImage"); connectedStatusBackgroundButton = new UIButton(); if (connectedStatusBackgroundButton == nullptr) { @@ -444,17 +481,30 @@ namespace OHOS // 清除所有与连接状态相关的视图组件 void PullUpDownView::ClearAllConnectedStatusComponentsView() { - delete connectedStatusBackgroundButton; - connectedStatusBackgroundButton = nullptr; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::ClearAllConnectedStatusComponentsView"); + if (connectedStatusBackgroundButton != nullptr) + { + delete connectedStatusBackgroundButton; + connectedStatusBackgroundButton = nullptr; + } - delete showPhoneConnectedStatus; - showPhoneConnectedStatus = nullptr; + if (showPhoneConnectedStatus != nullptr) + { + delete showPhoneConnectedStatus; + showPhoneConnectedStatus = nullptr; + } - delete showEarPhoneConnectedStatus; - showEarPhoneConnectedStatus = nullptr; + if (showEarPhoneConnectedStatus != nullptr) + { + delete showEarPhoneConnectedStatus; + showEarPhoneConnectedStatus = nullptr; + } - delete showBluetoothConnectedStatus; - showBluetoothConnectedStatus = nullptr; + if (showBluetoothConnectedStatus != nullptr) + { + delete showBluetoothConnectedStatus; + showBluetoothConnectedStatus = nullptr; + } } /*** @@ -462,7 +512,7 @@ namespace OHOS */ bool PullUpDownView::InitBaseData() { - + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitBaseData"); if (!InitSingalComponentsView()) { return false; @@ -553,7 +603,7 @@ namespace OHOS // 初始化信号强度相关组件 bool PullUpDownView::InitSingalComponentsView() { - + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitSingalComponentsView"); /* -------------------------------------------------------------------------- */ NoSignal = new UIImageView(); if (NoSignal == nullptr) @@ -624,6 +674,7 @@ namespace OHOS // 获取信号强度 int PullUpDownView::GetSignalStrength(void) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::GetSignalStrength"); runtime_status_t *g_runtime = get_device_runtime_status(); int SignalStrength = g_runtime->cat1_runtime.signal; // 信号强度 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SignalStrength = %d", SignalStrength); @@ -633,6 +684,7 @@ namespace OHOS int PullUpDownView::CalculateSignalBars(int signalStrength) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::CalculateSignalBars"); if (signalStrength < 0 || signalStrength > 32) return 99; // 无信号 or Invalid signal strength @@ -644,6 +696,7 @@ namespace OHOS void PullUpDownView::UpdateSignalDisplay(int signalBars) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::UpdateSignalDisplay"); bool noSignal = (signalBars == 99); for (int i = 0; i < 4; i++) { @@ -661,6 +714,7 @@ namespace OHOS void PullUpDownView::UpdateBatteryPosition(int signalBars) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::UpdateBatteryPosition"); if (signalBars == 99) { batteryimage->SetPosition(209, 180, BATTERY_IMAGE_WIDTH, BATTERY_IMAGE_HEIGHT); @@ -687,6 +741,7 @@ namespace OHOS // 清除信号强度相关组件 void PullUpDownView::ClearAllSingalComponentsView() { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::ClearAllSingalComponentsView"); if (NoSignal != nullptr) { delete NoSignal; @@ -711,7 +766,7 @@ namespace OHOS bool PullUpDownView::InitView() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitDropDownView caller:"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::InitView"); group[DROPDOWNVIEW] = new UIViewGroup(); if (group[DROPDOWNVIEW] == nullptr) @@ -728,7 +783,7 @@ namespace OHOS if (InitBaseData()) { - RefreshData(); + MainPresenterSample::GetInstance()->UpdataBaseData(); } else { @@ -743,6 +798,7 @@ namespace OHOS void PullUpDownView::PreLoad(void) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::PreLoad"); if (!viewiInitStatus) { InitView(); @@ -752,6 +808,7 @@ namespace OHOS void PullUpDownView::UpdateBlueToothStatus(int status) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::UpdateBlueToothStatus"); if (showBluetoothConnectedStatus == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showBluetoothConnectedStatus nullptr"); @@ -772,6 +829,7 @@ namespace OHOS /*更新勿扰模式状态*/ void PullUpDownView::UpdateDnotDisturbStatus(int status) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::UpdateDnotDisturbStatus"); for (int i = 0; i < MAX_INDEX; i++) { if (dropIconBackground[i] == nullptr) @@ -798,76 +856,6 @@ namespace OHOS return; } } - /*** - * @brief 刷新界面数据 - */ - void PullUpDownView::RefreshData() - { - PRINT("RefreshData Begin!\n"); - // 解析日期信息 - char *dateStr = (char *)malloc(9); - if (uapi_get_YYMMDD_Time(dateStr, '/') != ERRCODE_SUCC) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get start date"); - free(dateStr); - return; - } - // 获取当前时间 - char *timeStr = (char *)malloc(9); - if (uapi_get_HHMMSS_Time(timeStr, ':', false) != ERRCODE_SUCC) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get start time"); - free(dateStr); - free(timeStr); - return; - } - // 解析星期信息 - char *weekStr = (char *)malloc(10); - if (uapi_get_WeekStr(weekStr) != ERRCODE_SUCC) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get week information"); - free(dateStr); - free(timeStr); - free(weekStr); - return; - } - // 获取电池电量信息 - float voltage = 0.0F; - uint8_t value = 0; - value = battery_get_voltage(&voltage); - PRINT("Read ALLData!\n"); - - // 更新界面显示 - showTimeLabel->SetText(timeStr); - showWeekLabel->SetText(weekStr); - showDateLabel->SetText(dateStr); - PRINT("Update Label Data!\n"); - - // 更新电池信息 - const char *progressImages[3] = { - "/user/res/Battery/Battery_Limit.bin", // 低电量图片路径 - "/user/res/Battery/Battery_Save.bin", // 中等电量图片路径 - "/user/res/Battery/Battery_Normal.bin" // 正常电量图片路径 - }; - const char *progressImageSrc = nullptr; - for (int i = 0; i < 3; i++) - { - if (value <= (i + 1) * 10) - { - progressImageSrc = progressImages[i]; - PRINT("Update progressImageSrc [%d]!\r\n", i); - break; - } - } - progress->SetImage(progressImageSrc, nullptr); - progress->SetValue(value); - PRINT("RefreshData End!\n"); - - // 释放动态分配的内存 - free(dateStr); - free(timeStr); - free(weekStr); - } UILabel *PullUpDownView::GetTimeLabel() { -- 2.17.1