From 09734209cea821356d8ef4d69db22feace4e0584 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=A2=81=E6=B8=85=E6=A2=A6?= <3449750381@qq.com> Date: Tue, 6 Aug 2024 10:58:12 +0000 Subject: [PATCH] Merge #652 into sdk602patch0626 from refs/changes/652/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from 袁清梦 * refs/changes/652/head: (8 commits squashed) - 屏蔽血氧监测过程中的数值显示 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 - 增加表盘星期string类model - 增加血氧&心率数据重启之后恢复 - 筛选表盘血氧无效数据 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 - 修复星期显示 Signed-off-by: Caisking <3449750381@qq.com> Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/652 --- .../wearable/fd230app/CMakeLists.txt | 2 + .../bloodoxygen/src/BloodOxygenModel.cpp | 3 + .../nativeui/heartrate/src/HeartModel.cpp | 4 + .../nativeui/main/include/dial/DialDataBase.h | 25 +- .../main/include/dial/DialModelWeekStr.h | 28 + .../nativeui/main/src/dial/DialLabelView.cpp | 58 +- .../nativeui/main/src/dial/DialModelSPO2.cpp | 8 + .../main/src/dial/DialModelWeekStr.cpp | 46 ++ .../nativeui/main/src/dial/DialViewGroup.cpp | 762 ++++++++++-------- .../main/src/dial/ModelDialDataFactory.cpp | 1 + .../main/src/dial/parser/DialBinParser.cpp | 1 + 11 files changed, 546 insertions(+), 392 deletions(-) create mode 100644 code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelWeekStr.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelWeekStr.cpp diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index a09ea586a..da16ed348 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -162,6 +162,8 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelSPO2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelDistance.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelCalorie.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelWeekStr.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/main/src/dial/DialModelWeather.cpp #exception handling ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/heart_blood/CheckAbnormalView.cpp diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenModel.cpp index 73ee6def2..105c0fe34 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenModel.cpp @@ -6,6 +6,7 @@ #include "heart_blood/health_service/health_service.h" #include "custom_utils.h" extern "C" errcode_t uapi_get_timestamp_ms(uint32_t *tm); + #include "custom_utils.h" #include "ppg_service.h" #include "ConfigModel.h" @@ -27,6 +28,8 @@ namespace OHOS { currentspo2 = data->SPO2; timestamp_ms = data->timestamp; + // 更新表盘血氧数据 + DialModelSPO2::GetInstance()->UpdateSPO2(currentspo2); delete data; } else diff --git a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp index 438cea677..fca77f369 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartModel.cpp @@ -8,6 +8,7 @@ #include "heartrate/include/HeartRateView.h" #include "heartrate/include/HeartDetectionPresenter.h" #include "heartrate/include/HeartResultPresenter.h" +#include "DialModelHeartRate.h" #include #include @@ -194,12 +195,15 @@ namespace OHOS HeartModel::HeartModel() { + /*初始化读取文件*/ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartModel::HeartModel()"); HeartRateData *data = HealthService::GetInstance()->ReadHeartRateData(); if (data != nullptr) { currentheart = data->Heart; timestamp_ms = data->timestamp; + // 更新表盘心率数据 + DialModelHeartRate::GetInstance()->UpdateHeartRate(currentheart); delete data; } else diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialDataBase.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialDataBase.h index 914dc8089..2a52f5b38 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialDataBase.h +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialDataBase.h @@ -1,22 +1,4 @@ -/*** - * @Date: 2024-04-15 10:55:58 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-07-31 17:52:21 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialDataBase.h - */ -/*** - * @Date: 2024-04-15 10:55:58 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-04-27 11:16:57 - * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialDataBase.h - */ -/* - * Copyright (c) CompanyNameMagicTag 2023. All rights reserved. - * Description: DialBaseModel - * Author: - * Create: 2023-12 - */ #ifndef DIAL_DATA_BASE_H #define DIAL_DATA_BASE_H @@ -50,11 +32,12 @@ enum class DialDataType DATA_TYPE_DISTANCE, // 运动距离 DATA_TYPE_WEATHER, // 天气 DATA_TYPE_POWER_STANDBY, // 备用电量数据类型 - + DATA_TYPE_MULTI_FLOAT_BASE = 0x2fff, // 多个浮点数据类型基值 - DATA_TYPE_TEXT_BASE = 0x4fff, // 文本数据类型基值 + DATA_TYPE_TEXT_BASE = 0x4fff, // 文本数据类型基值 + DATA_TYPE_WEEK_STR, // 星期(string) - DATA_TYPE_MAX = 0x7fff, // 数据类型的最大值 + DATA_TYPE_MAX = 0x7fff, // 数据类型的最大值 }; #endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelWeekStr.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelWeekStr.h new file mode 100644 index 000000000..7b7cffee4 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialModelWeekStr.h @@ -0,0 +1,28 @@ + +#ifndef DIAL_MODEL_PATH_H +#define DIAL_MODEL_PATH_H + +#include "DialBaseModel.h" +#include +#include + +namespace OHOS +{ + class DialModelWeekStr : public DialBaseModel + { + public: + DialModelWeekStr() {} + virtual ~DialModelWeekStr() {} + static DialModelWeekStr *GetInstance() + { + static DialModelWeekStr instance; + return &instance; + } + bool GetDialTextData(DialDataType &type, std::string *&out, int16_t &strNum) override; + void UpdateWeekStr(const std::string *&dialWeekStr); + + private: + std::string dialWeekStr_; + }; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialLabelView.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialLabelView.cpp index 9216d6751..dc84cb26b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialLabelView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialLabelView.cpp @@ -81,40 +81,48 @@ namespace OHOS void DialLabelView::HandleTextData(const std::string *data, uint16_t num) { - char tempBuf[MAX_BUF_SIZE] = {0}; - if (num == 1) + if (num == 0 || data == nullptr) { - if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0].c_str()) < 0) - { - GRAPHIC_LOGE("snprintf_s failed.\n"); - return; - } + GRAPHIC_LOGE("Invalid data or num."); + return; } - else if (num == 2) - { // 2: wildcard cnt - if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0].c_str(), data[1].c_str()) < 0) - { - GRAPHIC_LOGE("snprintf_s failed.\n"); - return; - } + + // printf("HandleTextData called with num: %d, data[0]: %s\n", num, data[0].c_str()); + + char tempBuf[MAX_BUF_SIZE] = {0}; +#if 0 + for (uint16_t i = 0; i < num; ++i) + { + printf("data[%d]: %s\n", i, data[i].c_str()); } - else if (num == 3) - { // 3: wildcard cnt - if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, - data[0].c_str(), "年", data[1].c_str(), "月", data[2].c_str(), "日") < 0) - { // 2: index - GRAPHIC_LOGE("snprintf_s failed.\n"); - return; - } +#endif + int ret; + switch (num) + { + case 1: + ret = snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0].c_str()); + break; + case 2: + ret = snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0].c_str(), data[1].c_str()); + break; + case 3: + ret = snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, + data[0].c_str(), "年", data[1].c_str(), "月", data[2].c_str(), "日"); + break; + default: + GRAPHIC_LOGE("Invalid num: %d. Max size is 3.\n", num); + return; } - else + + if (ret < 0) { - GRAPHIC_LOGE("max size is 3.\n"); + GRAPHIC_LOGE("snprintf_s failed with error code: %d\n", ret); return; } + + // printf("Constructed tempBuf: %s\n", tempBuf); SetTextWithWildcardInner(tempBuf); } - void DialLabelView::HandleFloatData(const float *data, uint16_t num) { char tempBuf[MAX_BUF_SIZE] = {0}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelSPO2.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelSPO2.cpp index 63c314755..fbda6a42c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelSPO2.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelSPO2.cpp @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-04-27 18:32:46 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-06 15:37:21 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelSPO2.cpp + */ /* * Copyright (c) CompanyNameMagicTag 2023. All rights reserved. * Description: DialModelSPO2 @@ -22,6 +28,8 @@ namespace OHOS void DialModelSPO2::UpdateSPO2(uint8_t SPO2) { + if (SPO2 == 0) + return; SPO2_ = static_cast(SPO2); if (onChangeListener_ != nullptr) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelWeekStr.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelWeekStr.cpp new file mode 100644 index 000000000..6be3e64ab --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelWeekStr.cpp @@ -0,0 +1,46 @@ +#include "RegisterDialModel.h" +#include "DialModelWeekStr.h" +#include +#include +#include +#include "sys/time.h" +#include "wearable_log.h" + +REGIST_DIAL_MODULE(DialDataType::DATA_TYPE_WEEK_STR, OHOS::DialModelWeekStr::GetInstance()); +namespace OHOS +{ + // Cnweekdays 是一个包含星期字符串的数组 + const std::string Cnweekdays[] = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}; + + bool DialModelWeekStr::GetDialTextData(DialDataType &type, std::string *&out, int16_t &strNum) + { + (void)type; + + struct tm local_time = {0}; + time_t seconds = time(nullptr); + + if (localtime_r(&seconds, &local_time) == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "get localtime error!"); + return false; + } + + dialWeekStr_.clear(); + dialWeekStr_ = Cnweekdays[local_time.tm_wday]; + // printf("dialWeekStr_:%s\r\n", dialWeekStr_.c_str()); + out = &dialWeekStr_; + strNum = 1; + // printf("GetDialTextData %d\r\n",strNum); + return true; + } + + void DialModelWeekStr::UpdateWeekStr(const std::string *&dialWeekStr) + { + dialWeekStr_.clear(); + dialWeekStr_ = *dialWeekStr; // 更新字符串 + if (onChangeListener_ != nullptr) + { + onChangeListener_->OnDialTextDataUpdate(DialDataType::DATA_TYPE_WEEK_STR, &dialWeekStr_, dialWeekStr_.size()); + } + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialViewGroup.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialViewGroup.cpp index b25a7ce80..5906b5ce7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialViewGroup.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialViewGroup.cpp @@ -14,437 +14,507 @@ #ifdef SUPPORT_AT_OHOSFWK #include "ui_screennotify.h" #endif -namespace OHOS { -static DialVideoView* g_video = nullptr; +namespace OHOS +{ + static DialVideoView *g_video = nullptr; #ifdef SUPPORT_AT_OHOSFWK -static void ScreenStatusNotify(ScreenStatus status) -{ - if (g_video == nullptr) { - return; - } - if (status == SCREEN_STATUS_OFF && g_video->IsPlayed()) { - g_video->PausePlay(); - } else if (status == SCREEN_STATUS_ON) { - if (g_video->IsPaused()) { - g_video->ResumePlay(); - } else if (!g_video->IsPlayed()) { - g_video->StartPlay(); + static void ScreenStatusNotify(ScreenStatus status) + { + if (g_video == nullptr) + { + return; + } + if (status == SCREEN_STATUS_OFF && g_video->IsPlayed()) + { + g_video->PausePlay(); + } + else if (status == SCREEN_STATUS_ON) + { + if (g_video->IsPaused()) + { + g_video->ResumePlay(); + } + else if (!g_video->IsPlayed()) + { + g_video->StartPlay(); + } } } -} #endif -DialViewGroup::DialViewGroup(void) -{ - SetTouchable(true); - SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - SetCoverable(true); -} + DialViewGroup::DialViewGroup(void) + { + SetTouchable(true); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetCoverable(true); + } -DialViewGroup::~DialViewGroup(void) -{ - if (video_ != nullptr) { + DialViewGroup::~DialViewGroup(void) + { + if (video_ != nullptr) + { #ifdef SUPPORT_AT_OHOSFWK - deregisterNotifyScreenStatus(ScreenStatusNotify); + deregisterNotifyScreenStatus(ScreenStatusNotify); #endif - g_video = nullptr; - } - if (kaleidoscope_ != nullptr) { - kaleidoscope_->ClearFocus(); - kaleidoscope_ = nullptr; - } - ClearDial(); -} - -void DialViewGroup::ClearDial() -{ - ImageCacheManager::GetInstance().UnloadAllInMultiRes(filePath_); - ListNode* passiveNode = passiveUpdateTypes_.Head(); - while (passiveNode != passiveUpdateTypes_.End()) { - DialDataType type = passiveNode->data_; - ModelDialDataFactory::GetInstance().UnRegisterDialDataListener(type); - passiveNode = passiveNode->next_; - } - passiveUpdateTypes_.Clear(); - - ListNode* clickNode = dialClicks_.Head(); - while (clickNode != dialClicks_.End()) { - DialClick click = clickNode->data_; - if (!click.isSliceType) { - UIFree(click.bundleName); + g_video = nullptr; + } + if (kaleidoscope_ != nullptr) + { + kaleidoscope_->ClearFocus(); + kaleidoscope_ = nullptr; } - clickNode = clickNode->next_; + ClearDial(); } - dialClicks_.Clear(); - - periodicUpdateTypes_.Clear(); - dataTypeMap_.clear(); + void DialViewGroup::ClearDial() + { + ImageCacheManager::GetInstance().UnloadAllInMultiRes(filePath_); + ListNode *passiveNode = passiveUpdateTypes_.Head(); + while (passiveNode != passiveUpdateTypes_.End()) + { + DialDataType type = passiveNode->data_; + ModelDialDataFactory::GetInstance().UnRegisterDialDataListener(type); + passiveNode = passiveNode->next_; + } + passiveUpdateTypes_.Clear(); + + ListNode *clickNode = dialClicks_.Head(); + while (clickNode != dialClicks_.End()) + { + DialClick click = clickNode->data_; + if (!click.isSliceType) + { + UIFree(click.bundleName); + } + clickNode = clickNode->next_; + } + dialClicks_.Clear(); - ListNode* viewNode = dialViews_.Head(); - while (viewNode != dialViews_.End()) { - UIViewGroup::Remove(viewNode->data_); - delete(viewNode->data_); - viewNode = viewNode->next_; - } - dialViews_.Clear(); + periodicUpdateTypes_.Clear(); - period_ = DEFAULT_TASK_PERIOD; + dataTypeMap_.clear(); - video_ = nullptr; + ListNode *viewNode = dialViews_.Head(); + while (viewNode != dialViews_.End()) + { + UIViewGroup::Remove(viewNode->data_); + delete (viewNode->data_); + viewNode = viewNode->next_; + } + dialViews_.Clear(); - if (fp_ != nullptr) { - fclose(fp_); - fp_ = nullptr; - } -} + period_ = DEFAULT_TASK_PERIOD; -void DialViewGroup::SetDial(std::string filePath) -{ - ClearDial(); - resPreloaded_ = false; - filePath_ = filePath; -} + video_ = nullptr; -void DialViewGroup::PreLoad(void) -{ - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DialViewGroup::PreLoad"); - uint32_t startTime_ = HALTick::GetInstance().GetTime(); - if (!resPreloaded_) { - fp_ = fopen(filePath_.c_str(), "rb"); - if (fp_ == nullptr) { - GRAPHIC_LOGE("cannot open file: %s\n", filePath_.c_str()); - return; + if (fp_ != nullptr) + { + fclose(fp_); + fp_ = nullptr; } - DialBinParser::GetInstance()->UpdateDial(filePath_, fp_, this); - resPreloaded_ = true; } - if(!resLoadStatus) + void DialViewGroup::SetDial(std::string filePath) { - // if(PullUpDownView::GetInstance()!=nullptr) - // { - // PullUpDownView::GetInstance()->PreLoad(); - // } - - // if(MessageControlView::GetInstance()!=nullptr) - // { - // MessageControlView::GetInstance()->PreLoad(); - // } - resLoadStatus = true; + ClearDial(); + resPreloaded_ = false; + filePath_ = filePath; } - uint32_t elapseTime = HALTick::GetInstance().GetElapseTime(startTime_); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DialViewGroup::GetElapseTime %d", elapseTime); -} -void DialViewGroup::UnLoad(void) -{ - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DialViewGroup::UnLoad"); - if(resLoadStatus) + void DialViewGroup::PreLoad(void) { - // if(PullUpDownView::GetInstance()!=nullptr) - // { - // PullUpDownView::GetInstance()->UnLoad(); - // } - - // if(MessageControlView::GetInstance()!=nullptr) - // { - // MessageControlView::GetInstance()->UnLoad(); - // } - resLoadStatus = false; - } -} + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DialViewGroup::PreLoad"); + uint32_t startTime_ = HALTick::GetInstance().GetTime(); + if (!resPreloaded_) + { + fp_ = fopen(filePath_.c_str(), "rb"); + if (fp_ == nullptr) + { + GRAPHIC_LOGE("cannot open file: %s\n", filePath_.c_str()); + return; + } + DialBinParser::GetInstance()->UpdateDial(filePath_, fp_, this); + resPreloaded_ = true; + } -void DialViewGroup::ProcessData(DialDataType type, DialView* view) -{ - int16_t value = static_cast(type) >> 13; // 13: bit shift - if (value == 0) { // 0: float - float floatData = 0; - ModelDialDataFactory::GetInstance().GetDialFloatData(type, floatData); - view->HandleFloatData(floatData); - } else if (value == 1) { // 1: text - std::string* textData = nullptr; - int16_t num = 0; - ModelDialDataFactory::GetInstance().GetDialTextData(type, textData, num); - view->HandleTextData(textData, num); - } else if (value == 2) { // 2: multifloat - float* floatsData = nullptr; - int16_t num = 0; - ModelDialDataFactory::GetInstance().GetDialFloatData(type, floatsData, num); - view->HandleFloatData(floatsData, num); + if (!resLoadStatus) + { + /*打印已经注册的表盘model类型*/ + ModelDialDataFactory::GetInstance().DumpModules(); + resLoadStatus = true; + } + uint32_t elapseTime = HALTick::GetInstance().GetElapseTime(startTime_); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DialViewGroup::GetElapseTime %d", elapseTime); } -} -void DialViewGroup::AddView(UIView* view, bool isDialVideoView) -{ - if (view == nullptr) { - GRAPHIC_LOGE("Parameter is nullptr.\n"); - return; + void DialViewGroup::UnLoad(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DialViewGroup::UnLoad"); + if (resLoadStatus) + { + resLoadStatus = false; + } } - dialViews_.PushBack(view); - Add(view); - if (view->GetViewType() == UI_KALEIDOSCOPE_VIEW) { - kaleidoscope_ = dynamic_cast(view); + void DialViewGroup::ProcessData(DialDataType type, DialView *view) + { + int16_t value = static_cast(type) >> 14; // 14: bit shift + if (value == 0) + { // 0: float + float floatData = 0; + ModelDialDataFactory::GetInstance().GetDialFloatData(type, floatData); + view->HandleFloatData(floatData); + } + else if (value == 1) + { // 1: text + std::string *textData = nullptr; + int16_t num = 0; + bool ret = ModelDialDataFactory::GetInstance().GetDialTextData(type, textData, num); + // printf("ModelDialDataFactory type %d num %d ret %d \r\n", type, num, ret); + view->HandleTextData(textData, num); + } + else if (value == 2) + { // 2: multifloat + float *floatsData = nullptr; + int16_t num = 0; + ModelDialDataFactory::GetInstance().GetDialFloatData(type, floatsData, num); + view->HandleFloatData(floatsData, num); + } } - if (isDialVideoView) { - if (video_ != nullptr) { - GRAPHIC_LOGE("Already added a video view.\n"); + void DialViewGroup::AddView(UIView *view, bool isDialVideoView) + { + if (view == nullptr) + { + GRAPHIC_LOGE("Parameter is nullptr.\n"); return; } - video_ = reinterpret_cast(view); - g_video = video_; + dialViews_.PushBack(view); + Add(view); + + if (view->GetViewType() == UI_KALEIDOSCOPE_VIEW) + { + kaleidoscope_ = dynamic_cast(view); + } + + if (isDialVideoView) + { + if (video_ != nullptr) + { + GRAPHIC_LOGE("Already added a video view.\n"); + return; + } + video_ = reinterpret_cast(view); + g_video = video_; #ifdef SUPPORT_AT_OHOSFWK - registerNotifyScreenStatus(ScreenStatusNotify); + registerNotifyScreenStatus(ScreenStatusNotify); #endif + } } -} -void DialViewGroup::AddView(DialDataType type, DialView* view, bool isPeriodic) -{ - if (view == nullptr) { - GRAPHIC_LOGE("Parameter is nullptr.\n"); - return; + void DialViewGroup::AddView(DialDataType type, DialView *view, bool isPeriodic) + { + if (view == nullptr) + { + GRAPHIC_LOGE("Parameter is nullptr.\n"); + return; + } + + dataTypeMap_.insert(std::make_pair(static_cast(type), view)); + if (isPeriodic) + { + periodicUpdateTypes_.PushBack(type); + } + else + { + ModelDialDataFactory::GetInstance().RegisterDialDataListener(type, this); + passiveUpdateTypes_.PushBack(type); + } + dialViews_.PushBack(dynamic_cast(view)); + ProcessData(type, view); + Add(dynamic_cast(view)); } - dataTypeMap_.insert(std::make_pair(static_cast(type), view)); - if (isPeriodic) { - periodicUpdateTypes_.PushBack(type); - } else { - ModelDialDataFactory::GetInstance().RegisterDialDataListener(type, this); - passiveUpdateTypes_.PushBack(type); + void DialViewGroup::SetPeriod(uint32_t period) + { + if (period_ < DEFAULT_TASK_PERIOD) + { + period_ = DEFAULT_TASK_PERIOD; + } + else + { + period_ = period; + } } - dialViews_.PushBack(dynamic_cast(view)); - ProcessData(type, view); - Add(dynamic_cast(view)); -} -void DialViewGroup::SetPeriod(uint32_t period) -{ - if (period_ < DEFAULT_TASK_PERIOD) { - period_ = DEFAULT_TASK_PERIOD; - } else { - period_ = period; + uint32_t DialViewGroup::GetPeriod() + { + return period_; } -} -uint32_t DialViewGroup::GetPeriod() -{ - return period_; -} + void DialViewGroup::UpdateViewsByPeriodicUpdateData() + { + ListNode *node = periodicUpdateTypes_.Head(); + while (node != periodicUpdateTypes_.End()) + { + DialDataType type = node->data_; + auto iter = dataTypeMap_.find(static_cast(type)); + if (iter != dataTypeMap_.end()) + { + ProcessData(type, iter->second); + } + node = node->next_; + } + if (LowPowerManager::GetInstance()->IsLiteSurfaceInRootView()) + { + Invalidate(); + } + } -void DialViewGroup::UpdateViewsByPeriodicUpdateData() -{ - ListNode* node = periodicUpdateTypes_.Head(); - while (node != periodicUpdateTypes_.End()) { - DialDataType type = node->data_; + void DialViewGroup::OnDialFloatDataUpdate(DialDataType type, float data) + { auto iter = dataTypeMap_.find(static_cast(type)); - if (iter != dataTypeMap_.end()) { - ProcessData(type, iter->second); + if (iter != dataTypeMap_.end()) + { + DialView *view = iter->second; + view->HandleFloatData(data); } - node = node->next_; - } - if (LowPowerManager::GetInstance()->IsLiteSurfaceInRootView()) { - Invalidate(); } -} -void DialViewGroup::OnDialFloatDataUpdate(DialDataType type, float data) -{ - auto iter = dataTypeMap_.find(static_cast(type)); - if (iter != dataTypeMap_.end()) { - DialView* view = iter->second; - view->HandleFloatData(data); + void DialViewGroup::OnDialFloatDataUpdate(DialDataType type, const float *data, uint16_t num) + { + auto iter = dataTypeMap_.find(static_cast(type)); + if (iter != dataTypeMap_.end()) + { + DialView *view = iter->second; + view->HandleFloatData(data, num); + } } -} -void DialViewGroup::OnDialFloatDataUpdate(DialDataType type, const float* data, uint16_t num) -{ - auto iter = dataTypeMap_.find(static_cast(type)); - if (iter != dataTypeMap_.end()) { - DialView* view = iter->second; - view->HandleFloatData(data, num); + void DialViewGroup::OnDialTextDataUpdate(DialDataType type, const std::string *data, uint16_t num) + { + auto iter = dataTypeMap_.find(static_cast(type)); + if (iter != dataTypeMap_.end()) + { + DialView *view = iter->second; + view->HandleTextData(data, num); + } } -} -void DialViewGroup::OnDialTextDataUpdate(DialDataType type, const std::string* data, uint16_t num) -{ - auto iter = dataTypeMap_.find(static_cast(type)); - if (iter != dataTypeMap_.end()) { - DialView* view = iter->second; - view->HandleTextData(data, num); + void DialViewGroup::AddDialClick(Rect &rect, const char *bundleName) + { + if (bundleName == nullptr) + { + return; + } + uint32_t len = static_cast(strlen(bundleName)); + char *name = static_cast(UIMalloc(++len)); + if (name == nullptr) + { + return; + } + if (memcpy_s(name, len, bundleName, len) != EOK) + { + UIFree(name); + name = nullptr; + return; + } + name[len] = '\0'; + DialClick click = {rect, false, {.bundleName = name}}; + dialClicks_.PushBack(click); } -} -void DialViewGroup::AddDialClick(Rect& rect, const char* bundleName) -{ - if (bundleName == nullptr) { - return; - } - uint32_t len = static_cast(strlen(bundleName)); - char* name = static_cast(UIMalloc(++len)); - if (name == nullptr) { - return; - } - if (memcpy_s(name, len, bundleName, len) != EOK) { - UIFree(name); - name = nullptr; - return; - } - name[len] = '\0'; - DialClick click = {rect, false, {.bundleName = name}}; - dialClicks_.PushBack(click); -} + void DialViewGroup::AddDialClick(Rect &rect, uint32_t sliceId) + { + if (sliceId == 0) + { + return; + } -void DialViewGroup::AddDialClick(Rect& rect, uint32_t sliceId) -{ - if (sliceId == 0) { - return; + DialClick click = {rect, true, {.sliceId = sliceId}}; + dialClicks_.PushBack(click); } - DialClick click = {rect, true, {.sliceId = sliceId}}; - dialClicks_.PushBack(click); -} - -bool DialViewGroup::OnClickEvent(const ClickEvent& event) -{ - Point point = event.GetCurrentPos(); - ListNode* node = dialClicks_.Head(); - while (node != dialClicks_.End()) { - DialClick dialClick = node->data_; - if (dialClick.area.IsContains(point)) { - if (dialClick.isSliceType) { - NativeAbility::GetInstance().ChangeSlice(dialClick.sliceId); - } else { + bool DialViewGroup::OnClickEvent(const ClickEvent &event) + { + Point point = event.GetCurrentPos(); + ListNode *node = dialClicks_.Head(); + while (node != dialClicks_.End()) + { + DialClick dialClick = node->data_; + if (dialClick.area.IsContains(point)) + { + if (dialClick.isSliceType) + { + NativeAbility::GetInstance().ChangeSlice(dialClick.sliceId); + } + else + { #ifdef JS_ENABLE - StartJsApp(dialClick.bundleName); + StartJsApp(dialClick.bundleName); #endif + } + return true; } - return true; + node = node->next_; } - node = node->next_; + return false; } - return false; -} -void DialViewGroup::ScrollBegin(bool isActive) -{ - if (kaleidoscope_ != nullptr) { - if (isActive) { - kaleidoscope_->ClearFocus(); - kaleidoscope_->StopRotateAnimator(); + void DialViewGroup::ScrollBegin(bool isActive) + { + if (kaleidoscope_ != nullptr) + { + if (isActive) + { + kaleidoscope_->ClearFocus(); + kaleidoscope_->StopRotateAnimator(); + } + return; } - return; - } - if (video_ == nullptr) { - return; - } - if (video_->IsPlayed()) { - video_->PausePlay(); + if (video_ == nullptr) + { + return; + } + if (video_->IsPlayed()) + { + video_->PausePlay(); + } } -} -void DialViewGroup::ScrollEnd(bool isActive) -{ - if (kaleidoscope_ != nullptr) { - if (isActive) { - kaleidoscope_->StartRotateAnimator(); - kaleidoscope_->RequestFocus(); + void DialViewGroup::ScrollEnd(bool isActive) + { + if (kaleidoscope_ != nullptr) + { + if (isActive) + { + kaleidoscope_->StartRotateAnimator(); + kaleidoscope_->RequestFocus(); + } + return; } - return; - } - if (video_ == nullptr) { - return; - } + if (video_ == nullptr) + { + return; + } - if (isActive) { - if (video_->IsPaused()) { - video_->ResumePlay(); - } else if (!video_->IsPlayed()) { - video_->StartPlay(); + if (isActive) + { + if (video_->IsPaused()) + { + video_->ResumePlay(); + } + else if (!video_->IsPlayed()) + { + video_->StartPlay(); + } + g_video = video_; } - g_video = video_; - } else { - if (video_->IsPaused() || video_->IsPlayed()) { - video_->StopPlay(); + else + { + if (video_->IsPaused() || video_->IsPlayed()) + { + video_->StopPlay(); + } + ClearCache(); + g_video = nullptr; } - ClearCache(); - g_video = nullptr; } -} -void DialViewGroup::CoverBegin(bool isCovered) -{ - if (kaleidoscope_ != nullptr) { - if (!isCovered) { - kaleidoscope_->StopRotateAnimator(); - kaleidoscope_->ClearFocus(); + void DialViewGroup::CoverBegin(bool isCovered) + { + if (kaleidoscope_ != nullptr) + { + if (!isCovered) + { + kaleidoscope_->StopRotateAnimator(); + kaleidoscope_->ClearFocus(); + } + return; } - return; - } - if (video_ == nullptr) { - return; + if (video_ == nullptr) + { + return; + } + + if (video_->IsPlayed()) + { + video_->PausePlay(); + } } - if (video_->IsPlayed()) { - video_->PausePlay(); + void DialViewGroup::CoverEnd(bool isCovered) + { + if (kaleidoscope_ != nullptr) + { + if (!isCovered) + { + kaleidoscope_->RequestFocus(); + kaleidoscope_->StartRotateAnimator(); + } + return; + } + if (video_ == nullptr) + { + return; + } + if (isCovered) + { + g_video = nullptr; + } + else + { + if (video_->IsPaused()) + { + video_->ResumePlay(); + } + else if (!video_->IsPlayed()) + { + video_->StartPlay(); + } + g_video = video_; + } } -} -void DialViewGroup::CoverEnd(bool isCovered) -{ - if (kaleidoscope_ != nullptr) { - if (!isCovered) { + void DialViewGroup::OnActive(void) + { + if (video_ != nullptr) + { + if (video_->IsPaused()) + { + video_->ResumePlay(); + } + else if (!video_->IsPlayed()) + { + video_->StartPlay(); + } + g_video = video_; + } + else if (kaleidoscope_ != nullptr) + { kaleidoscope_->RequestFocus(); kaleidoscope_->StartRotateAnimator(); } - return; - } - if (video_ == nullptr) { - return; } - if (isCovered) { - g_video = nullptr; - } else { - if (video_->IsPaused()) { - video_->ResumePlay(); - } else if (!video_->IsPlayed()) { - video_->StartPlay(); - } - g_video = video_; - } -} -void DialViewGroup::OnActive(void) -{ - if (video_ != nullptr) { - if (video_->IsPaused()) { - video_->ResumePlay(); - } else if (!video_->IsPlayed()) { - video_->StartPlay(); - } - g_video = video_; - } else if (kaleidoscope_ != nullptr) { - kaleidoscope_->RequestFocus(); - kaleidoscope_->StartRotateAnimator(); - } -} - -void DialViewGroup::OnInactive(void) -{ - if (video_ != nullptr) { - if (!video_->IsStopped()) { - video_->StopPlay(); - } - g_video = nullptr; - } else if (kaleidoscope_ != nullptr) { - kaleidoscope_->StopRotateAnimator(); - kaleidoscope_->ClearFocus(); + void DialViewGroup::OnInactive(void) + { + if (video_ != nullptr) + { + if (!video_->IsStopped()) + { + video_->StopPlay(); + } + g_video = nullptr; + } + else if (kaleidoscope_ != nullptr) + { + kaleidoscope_->StopRotateAnimator(); + kaleidoscope_->ClearFocus(); + } } } -} diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/ModelDialDataFactory.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/ModelDialDataFactory.cpp index d17de5b31..88ce467e3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/ModelDialDataFactory.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/ModelDialDataFactory.cpp @@ -13,6 +13,7 @@ bool ModelDialDataFactory::GetDialTextData(DialDataType& type, std::string*& out if (model == nullptr) { return false; } + // printf("type %d strNum %d\r\n",type,strNum); return model->GetDialTextData(type, out, strNum); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/parser/DialBinParser.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/parser/DialBinParser.cpp index a61df4821..21a4c3080 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/parser/DialBinParser.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/parser/DialBinParser.cpp @@ -418,6 +418,7 @@ int32_t DialBinParser::ParserDialLabel(FILE* fp) view->SetTextColor(color); view->SetAlign(static_cast(data->align)); if (data->bindData != 0) { + //printf("%s\r\n",data->text); view->SetTextWithWildcard(data->text); dialGroup_->AddView(static_cast(data->bindData), view, data->isPeriod); } else { -- 2.17.1