From: Caisking Date: Wed, 30 Jul 2025 09:39:41 +0000 (+0800) Subject: 合并dial文件 X-Git-Tag: leiniao_debug_1.0.0_20250922_020716~207^2~2 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=0af384d8fb12fed53afa83d0a28f98b84c9918f1;p=mirrors%2FFD230.git 合并dial文件 --- diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialArcLabelView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialArcLabelView.cpp index 02ce99c31..fa4a34771 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialArcLabelView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialArcLabelView.cpp @@ -2,7 +2,7 @@ * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ -#include "DialArcLabelView.h" +#include "main/dial/DialArcLabelView.h" #include "securec.h" namespace OHOS { diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialArcProgressView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialArcProgressView.cpp index b9ab85499..d045de8e7 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialArcProgressView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialArcProgressView.cpp @@ -2,7 +2,7 @@ * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ -#include "DialArcProgressView.h" +#include "main/dial/DialArcProgressView.h" namespace OHOS { DialArcProgressView::DialArcProgressView(void) @@ -13,8 +13,8 @@ DialArcProgressView::~DialArcProgressView(void) { } -void DialArcProgressView::HandleFloatData(float data) { - // printf("HandleFloatData: %f\n", data); +void DialArcProgressView::HandleFloatData(float data) +{ float ratio = data; if (ratio > 1.0f) { ratio = 1.0f; @@ -28,4 +28,16 @@ void DialArcProgressView::HandleFloatData(float data) { value_ = value; SetValue(value_); } + +void DialArcProgressView::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) +{ + if (foregroundStopCount_ != 0) { + Rect rect = GetOrigRect(); + foregroundGradient_.startX = rect.GetX(); + foregroundGradient_.startY = rect.GetY(); + foregroundGradient_.endX = rect.GetRight(); + foregroundGradient_.endY = rect.GetBottom(); + } + UICircleProgress::OnDraw(gfxDstBuffer, invalidatedArea); +} } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialDataBase.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialDataBase.cpp index e75718ef0..6ec5d3810 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialDataBase.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialDataBase.cpp @@ -6,7 +6,7 @@ */ #include -#include "dial/DialDataBase.h" +#include "main/dial/DialDataBase.h" namespace { struct DataTypeHash { diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialDigitalImgView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialDigitalImgView.cpp index 4f316171e..50e7b59df 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialDigitalImgView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialDigitalImgView.cpp @@ -2,7 +2,7 @@ * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ -#include "DialDigitalImgView.h" +#include "main/dial/DialDigitalImgView.h" #include #include "securec.h" diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialLabelView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialLabelView.cpp index 526d0a2fd..38a544fd6 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialLabelView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialLabelView.cpp @@ -2,189 +2,147 @@ * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ -#include "DialLabelView.h" +#include "main/dial/DialLabelView.h" #include "securec.h" -namespace OHOS +namespace OHOS { +DialLabelView::DialLabelView(void) { - DialLabelView::DialLabelView(void) - { - } +} - DialLabelView::~DialLabelView(void) - { - if (text_ != nullptr) - { - UIFree(text_); - } +DialLabelView::~DialLabelView(void) +{ + if (text_ != nullptr) { + UIFree(text_); } +} - bool DialLabelView::SetText(const char *text) - { - if (text == nullptr) - { - return false; - } - UILabel::SetText(text); - return true; +bool DialLabelView::SetText(const char* text) +{ + if (text == nullptr) { + return false; } + UILabel::SetText(text); + return true; +} - void DialLabelView::SetTextWithWildcardInner(const char *text) - { - if (strcmp(text, dstBuf_) == 0) - { - return; - } - memset_s(dstBuf_, sizeof(dstBuf_), 0, sizeof(dstBuf_)); - if (strcpy_s(dstBuf_, MAX_BUF_SIZE, text) != EOK) - { - GRAPHIC_LOGE("strcpy_s failed!\n"); - } - UILabel::SetText(dstBuf_); +void DialLabelView::SetTextWithWildcardInner(const char* text) +{ + if (strcmp(text, dstBuf_) == 0) { + return; } + memset_s(dstBuf_, sizeof(dstBuf_), 0, sizeof(dstBuf_)); + if (strcpy_s(dstBuf_, MAX_BUF_SIZE, text) != EOK) { + GRAPHIC_LOGE("strcpy_s failed!\n"); + } + UILabel::SetText(dstBuf_); +} - bool DialLabelView::SetTextWithWildcard(const char *text) - { - if (text == nullptr) - { - return false; - } - if (text_ != nullptr) - { - if (strcmp(text, text_) == 0) - { - return true; - } - UIFree(text_); - text_ = nullptr; +bool DialLabelView::SetTextWithWildcard(const char* text) +{ + if (text == nullptr) { + return false; + } + if (text_ != nullptr) { + if (strcmp(text, text_) == 0) { + return true; } + UIFree(text_); + text_ = nullptr; + } - uint32_t textLen = static_cast(strlen(text)); - if (textLen > (MAX_BUF_SIZE - 1)) - { - return false; - } - text_ = static_cast(UIMalloc(++textLen)); - if (text_ == nullptr) - { - return false; - } - if (strcpy_s(text_, textLen, text) != EOK) { - GRAPHIC_LOGE("strcpy_s failed"); - UIFree(text_); - text_ = nullptr; - return false; - } - return true; + uint32_t textLen = static_cast(strlen(text)); + if (textLen > (MAX_BUF_SIZE - 1)) { + return false; + } + text_ = static_cast(UIMalloc(++textLen)); + if (text_ == nullptr) { + return false; } + if (strcpy_s(text_, textLen, text) != EOK) { + GRAPHIC_LOGE("strcpy_s failed"); + UIFree(text_); + text_ = nullptr; + return false; + } + return true; +} - void DialLabelView::HandleTextData(const std::string *data, uint16_t num) - { - if (num == 0 || data == nullptr) - { - // GRAPHIC_LOGE("Invalid data or num."); +void DialLabelView::HandleTextData(const std::string* data, uint16_t num) +{ + char tempBuf[MAX_BUF_SIZE] = {0}; + if (num == 1) { + if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0].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}; - - 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; - case 4: /*8月7号 星期三*/ - 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); + } 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; } - - if (ret < 0) - { - GRAPHIC_LOGE("snprintf_s failed with error code: %d\n", ret); + } 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; } - - // printf("Constructed tempBuf: %s\n", tempBuf); - SetTextWithWildcardInner(tempBuf); + } else { + GRAPHIC_LOGE("max size is 3.\n"); + return; } - void DialLabelView::HandleFloatData(const float *data, uint16_t num) - { - char tempBuf[MAX_BUF_SIZE] = {0}; - if (num == 1) - { - if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0]) < 0) - { - GRAPHIC_LOGE("snprintf_s failed.\n"); - return; - } - } - else if (num == 2) - { // 2: wildcard cnt - if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0], data[1]) < 0) - { - GRAPHIC_LOGE("snprintf_s failed.\n"); - return; - } - } - else if (num == 3) - { // 3: wildcard cnt - if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0], data[1], data[2]) < 0) - { // 2: index - GRAPHIC_LOGE("snprintf_s failed.\n"); - return; - } + SetTextWithWildcardInner(tempBuf); +} + +void DialLabelView::HandleFloatData(const float* data, uint16_t num) +{ + char tempBuf[MAX_BUF_SIZE] = {0}; + if (num == 1) { + if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0]) < 0) { + GRAPHIC_LOGE("snprintf_s failed.\n"); + return; } - else - { - GRAPHIC_LOGE("max size is 3.\n"); + } else if (num == 2) { // 2: wildcard cnt + if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0], data[1]) < 0) { + GRAPHIC_LOGE("snprintf_s failed.\n"); return; } - SetTextWithWildcardInner(tempBuf); - } - - void DialLabelView::HandleFloatData(float data) - { - char tempBuf[MAX_BUF_SIZE] = {0}; - if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data) < 0) - { + } else if (num == 3) { // 3: wildcard cnt + if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data[0], data[1], data[2]) < 0) { // 2: index GRAPHIC_LOGE("snprintf_s failed.\n"); return; } - SetTextWithWildcardInner(tempBuf); + } else { + GRAPHIC_LOGE("max size is 3.\n"); + return; } - void DialLabelView::SetLang(uint8_t lang) - { - language_ = lang; - OnLangChange(FontGlobalManager::GetInstance()->GetCurrentLangId()); + SetTextWithWildcardInner(tempBuf); +} + +void DialLabelView::HandleFloatData(float data) +{ + char tempBuf[MAX_BUF_SIZE] = {0}; + if (snprintf_s(tempBuf, MAX_BUF_SIZE, MAX_BUF_SIZE - 1, text_, data) < 0) { + GRAPHIC_LOGE("snprintf_s failed.\n"); + return; } + SetTextWithWildcardInner(tempBuf); +} - void DialLabelView::OnLangChange(uint8_t langId) - { - if (language_ == FontGlobalManager::INVALID_LANG_ID) - { - SetVisible(true); - } - else if (language_ == langId) - { - SetVisible(true); - } - else - { - SetVisible(false); - } +void DialLabelView::SetLang(uint8_t lang) +{ + language_ = lang; + OnLangChange(FontGlobalManager::GetInstance()->GetCurrentLangId()); +} + +void DialLabelView::OnLangChange(uint8_t langId) +{ + if (language_ == FontGlobalManager::INVALID_LANG_ID) { + SetVisible(true); + } else if (language_ == langId) { + SetVisible(true); + } else { + SetVisible(false); } +} } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialModelSteps.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialModelSteps.cpp index 3eeb3ff71..6050117ba 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialModelSteps.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialModelSteps.cpp @@ -6,7 +6,7 @@ */ #include "DialModelSteps.h" -#include "RegisterDialModel.h" +#include "main/dial/RegisterDialModel.h" #include "goal/include/goalmodel.h" REGIST_DIAL_MODULE(OHOS::DialDataType::STEP_COUNT, diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialModelTime.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialModelTime.cpp index a08366bdd..e710dd9a8 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialModelTime.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialModelTime.cpp @@ -7,8 +7,8 @@ #include #include "sys/time.h" -#include "RegisterDialModel.h" -#include "DialModelTime.h" +#include "main/dial/RegisterDialModel.h" +#include "main/dial/DialModelTime.h" #include "components/root_view.h" #include "custom_runtime.h" @@ -42,6 +42,8 @@ REGIST_DIAL_MODULE_YEAR(OHOS::DialDataType::SOLAR_YEAR, OHOS::DialModelTime::Get REGIST_DIAL_MODULE_GEAR_POSITIVE(OHOS::DialDataType::SWIVEL_GEAR_POSITIVE, OHOS::DialModelTime::GetInstance()); REGIST_DIAL_MODULE_GEAR_NEGATIVE(OHOS::DialDataType::SWIVEL_GEAR_NEGATIVE, OHOS::DialModelTime::GetInstance()); +static OHOS::RegisterDialModel REGIST_MOUNTH_80(OHOS::DialDataType::MONTH_DATA, OHOS::DialModelTime::GetInstance()); + namespace OHOS { static constexpr int16_t S_MS_US_TRANS = 1000; // 1000: seconds, milliseconds, microsecond transform value static constexpr uint8_t ONE_MINUTE_IN_SECOND = 60; // 60: 60 seconds per minute @@ -148,37 +150,37 @@ bool DialModelTime::GetDialFloatData(DialDataType& type, float& out) } switch (type) { - case OHOS::DialDataType::CLOCK_ANGLE: + case DialDataType::CLOCK_ANGLE: out = static_cast(angleH_); break; - case OHOS::DialDataType::MINUTE_ANGLE: + case DialDataType::MINUTE_ANGLE: out = static_cast(angleM_); break; - case OHOS::DialDataType::SECOND_ANGLE: + case DialDataType::SECOND_ANGLE: out = static_cast(angleS_); break; - case OHOS::DialDataType::MILLISECOND_ANGLE: + case DialDataType::MILLISECOND_ANGLE: out = static_cast(angleMS_); break; - case OHOS::DialDataType::SOLAR_YEAR: - out = static_cast(tblock_->tm_year + 1900); + case DialDataType::SOLAR_YEAR: + out = static_cast(tblock_->tm_year + 1900); // 1900: since 1900 break; - case OHOS::DialDataType::MONTH: - out = static_cast(tblock_->tm_mon + 1); + case DialDataType::MONTH: + out = static_cast(tblock_->tm_mon); break; - case OHOS::DialDataType::WEEKDAY_DATA: + case DialDataType::WEEKDAY_DATA: out = static_cast(tblock_->tm_wday); break; - case OHOS::DialDataType::DATE: + case DialDataType::DATE: out = static_cast(tblock_->tm_mday); break; - case OHOS::DialDataType::CLOCK: + case DialDataType::CLOCK: out = static_cast(tblock_->tm_hour); break; - case OHOS::DialDataType::MINUTE_TIME: + case DialDataType::MINUTE_TIME: out = static_cast(tblock_->tm_min); break; - case OHOS::DialDataType::SECOND_TIME: + case DialDataType::SECOND_TIME: out = static_cast(tblock_->tm_sec); break; case DialDataType::SWIVEL_GEAR_POSITIVE: { @@ -193,6 +195,10 @@ bool DialModelTime::GetDialFloatData(DialDataType& type, float& out) out = static_cast(accleratedAngle * -1.0 + CIRCLE_IN_DEGREE); break; } + case DialDataType::MONTH_DATA: { + out = static_cast(tblock_->tm_mon) + 1.0; + break; + } default: return false; } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialOptionImgView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialOptionImgView.cpp index 980d438cd..4175937c2 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialOptionImgView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialOptionImgView.cpp @@ -2,7 +2,7 @@ * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ -#include "DialOptionImgView.h" +#include "main/dial/DialOptionImgView.h" #include "securec.h" namespace OHOS { diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialRotateImgView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialRotateImgView.cpp index bec17ca81..171aeea7e 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialRotateImgView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialRotateImgView.cpp @@ -2,7 +2,7 @@ * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ -#include "DialRotateImgView.h" +#include "main/dial/DialRotateImgView.h" namespace OHOS { DialRotateImgView::DialRotateImgView(void) diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialSequenceImgView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialSequenceImgView.cpp index c7d1c24e7..8741d4c9a 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialSequenceImgView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialSequenceImgView.cpp @@ -2,7 +2,7 @@ * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ -#include "DialSequenceImgView.h" +#include "main/dial/DialSequenceImgView.h" #include "securec.h" #include "common/graphic_utils.h" #include "common/image_cache_manager.h" diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialStaticImgView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialStaticImgView.cpp index ffc87a701..bfa5182ea 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialStaticImgView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialStaticImgView.cpp @@ -2,7 +2,7 @@ * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ -#include "DialStaticImgView.h" +#include "main/dial/DialStaticImgView.h" namespace OHOS { DialStaticImgView::DialStaticImgView() diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialVideoView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialVideoView.cpp index 13113cd1c..9ac7b75d1 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialVideoView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialVideoView.cpp @@ -2,7 +2,7 @@ * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ -#include "DialVideoView.h" +#include "main/dial/DialVideoView.h" namespace OHOS { static constexpr int16_t JPEG_HEIGHT_DIVISOR = 2; @@ -23,8 +23,7 @@ DialVideoView::DialVideoView() DialVideoView::~DialVideoView() { if (videoPlayer_ != nullptr) { - delete videoPlayer_; - videoPlayer_ = nullptr; + delete videoPlayer_; } } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialViewContainer.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialViewContainer.cpp index 8ed4cf710..198c0679b 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialViewContainer.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/DialViewContainer.cpp @@ -5,9 +5,9 @@ * Create: 2025-02-06 */ -#include "DialViewContainer.h" -#include "DialDigitalImgView.h" -#include "ModelDialDataFactory.h" +#include "main/dial/DialViewContainer.h" +#include "main/dial/DialDigitalImgView.h" +#include "main/dial/ModelDialDataFactory.h" namespace OHOS { DialViewContainer::~DialViewContainer() diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/ModelDialDataFactory.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/ModelDialDataFactory.cpp index d17de5b31..71ea7a19f 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/ModelDialDataFactory.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/ModelDialDataFactory.cpp @@ -5,7 +5,7 @@ * Create: 2023-12 */ -#include "ModelDialDataFactory.h" +#include "main/dial/ModelDialDataFactory.h" namespace OHOS { bool ModelDialDataFactory::GetDialTextData(DialDataType& type, std::string*& out, int16_t& strNum) { diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/WatchInterface.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/WatchInterface.cpp index 45e63594e..11f98448d 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/WatchInterface.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/main/src/dial/WatchInterface.cpp @@ -6,24 +6,35 @@ */ #include +#include #include "dirent.h" -#include "DialBinParser.h" +#include "main/DialBinParser.h" #include "UiConfig.h" -#include "WatchInterface.h" +#include "main/dial/WatchInterface.h" #include "gfx_utils/vector.h" #include "common/screen.h" -#include "MainModel.h" -#include "MainViewSample.h" -#include "SetDialModel.h" +#include "main/MainModel.h" +#include "main/MainViewSample.h" +#include "set_dial/SetDialModel.h" #include "graphic_service.h" #include "NativeAbility.h" +#include "graphic_mutex.h" +#include "set_dial/SetDialModel.h" +#include "set_dial/SetDialPresenter.h" +#include "power_display_service.h" using namespace OHOS; namespace { -struct { - Graphic::Vector fileNames; // only for 3.0 - Graphic::Vector watchInfo; // only for 3.0 -} g_info; +struct WatchInfoInner { + std::string fileName; + watch_dial_info watchInfo; +}; + +Graphic::Vector g_info; +GraphicMutex g_mutex; +GraphicCond g_cond; +bool g_eventFinished = true; +const uint16_t INVALID_INFO_INDEX = 0xFFFF; bool GetActiveWatchPath(std::string &path) { @@ -34,7 +45,7 @@ bool GetActiveWatchPath(std::string &path) return false; } -bool GetPreviewInfo(const std::string &fileName, DialPreviewInfo &preview) +bool GetPreviewInfo(const std::string &fileName, DialPreviewInfo &preview, bool isNeedVerify = false) { const std::string type(".bin"); if (!(fileName.length() > type.length() && @@ -45,7 +56,7 @@ bool GetPreviewInfo(const std::string &fileName, DialPreviewInfo &preview) FILE *file = fopen(fileName.c_str(), "rb"); bool isSuccess = false; if (file != nullptr) { - isSuccess = DialBinParserManager::GetInstance()->GetDialPreviewInfo(file, &preview); + isSuccess = DialBinParserManager::GetInstance()->GetDialPreviewInfo(fileName, file, &preview, isNeedVerify); fclose(file); } return isSuccess; @@ -70,19 +81,14 @@ bool ConvertPreview2WatchDialInfo(const DialPreviewInfo &preview, watch_dial_inf return true; } -#define APP_DIAL_PATH "user/dial/" //为了编译过加的 - -bool GetAllWatchInfo() +void RefreshAllWatchInfo() { - g_info.fileNames.Clear(); - g_info.watchInfo.Clear(); + g_info.Clear(); struct dirent *direntp = nullptr; - - // ��Ŀ¼ + // 打开目录 DIR *dirp = opendir(APP_DIAL_PATH); - bool isSuccess = true; - // �����ļ� + // 遍历文件 DialPreviewInfo info; watch_dial_info watchInfo; std::string activePath; @@ -90,56 +96,133 @@ bool GetAllWatchInfo() if (dirp != nullptr) { while ((direntp = readdir(dirp)) != nullptr) { std::string fileName = std::string(APP_DIAL_PATH) + std::string("/") + std::string(direntp->d_name); - isSuccess = GetPreviewInfo(fileName, info); - if (!isSuccess) { + if (!GetPreviewInfo(fileName, info)) { continue; } const std::string lowestVersion("3.0"); std::string curVersion(info.protocolVersion); if (curVersion >= lowestVersion) { - isSuccess = ConvertPreview2WatchDialInfo(info, watchInfo); - if (!isSuccess) { + if (!ConvertPreview2WatchDialInfo(info, watchInfo)) { break; } watchInfo.install_state = true; watchInfo.is_current_watch = isActiveExist ? (activePath == fileName) : false; - g_info.fileNames.PushBack(fileName); - g_info.watchInfo.PushBack(watchInfo); + g_info.PushBack({fileName, watchInfo}); } } } - // �ر�Ŀ¼ + // 关闭目录 closedir(dirp); - return isSuccess; } -} // namespace -bool GetAllWatchFaceInfo(watch_dial_info *info, uint8_t *num, uint8_t maxCnt) +inline bool IsFileExists(const std::string &file) +{ + return access(file.c_str(), F_OK) == 0; +} + +uint16_t FindMaxVersionIndex(uint16_t indexArray[], uint16_t num) +{ + if (num == 0) { + return INVALID_INFO_INDEX; + } + + if (num == 0) { + return indexArray[0]; + } + std::string version = reinterpret_cast(g_info[indexArray[0]].watchInfo.watch_version); + uint16_t index = 0; + for (uint16_t i = 1; i < num; ++i) { + std::string curVerion = std::string(reinterpret_cast(g_info[indexArray[i]].watchInfo.watch_version)); + if (curVerion > version) { + version = curVerion; + index = i; + } + } + if (num > 1) { + GRAPHIC_LOGE("There are watches with the same uuid. %u", g_info[indexArray[index]].watchInfo.uuid); + } + index = indexArray[index]; + return index; +} + +void GetWatchInfo(uint32_t uuid, uint16_t &index) +{ + index = INVALID_INFO_INDEX; + if (g_info.IsEmpty()) { + RefreshAllWatchInfo(); + } + const uint16_t MAX_INFO_NUM = 128; + static uint16_t indexArray[MAX_INFO_NUM]; + uint16_t num = 0; + std::string activePath; + bool isActive = GetActiveWatchPath(activePath); + bool isNeedRequery = false; + for (uint16_t i = 0; i < g_info.Size(); ++i) { + if (uuid == g_info[i].watchInfo.uuid && num < MAX_INFO_NUM) { + if (IsFileExists(g_info[i].fileName)) { + g_info[i].watchInfo.is_current_watch = isActive ? (g_info[i].fileName == activePath) : false; + indexArray[num++] = i; + } else { + RefreshAllWatchInfo(); + isNeedRequery = true; + break; + } + } + } + + if (!isNeedRequery) { + index = FindMaxVersionIndex(indexArray, num); + return; + } + num = 0; + for (uint16_t i = 0; i < g_info.Size(); ++i) { + if (uuid == g_info[i].watchInfo.uuid && num < MAX_INFO_NUM) { + indexArray[num++] = i; + } + } + index = FindMaxVersionIndex(indexArray, num); +} + +void TryToTurnOnScreen() +{ + const power_display_svr_api_t *ctx = power_display_svr_get_api(); + if (ctx == nullptr) { + return; + } + if (ctx->get_screen_state != nullptr && ctx->get_screen_state() != SCREEN_ON) { + if (ctx->turn_on_screen != nullptr) { + ctx->turn_on_screen(); + } + } +} +} // anonymous namespace + +bool GetAllWatchFaceInfo(watch_dial_info **info, uint8_t *num) { if (info == nullptr || num == nullptr) { GRAPHIC_LOGE("para error!"); return false; } - if (!GetAllWatchInfo()) { - GRAPHIC_LOGE("failed to get all watch info."); - return false; + GraphicLockGuard guard(g_mutex); + while (!g_eventFinished) { + g_cond.Wait(g_mutex); } - if (g_info.watchInfo.Size() > maxCnt) { - GRAPHIC_LOGE("mem is not enough."); - return false; - } - *num = g_info.watchInfo.Size(); + RefreshAllWatchInfo(); + *num = g_info.Size(); if (*num == 0) { - return false; + *info = nullptr; + return true; } - if (memcpy_s(info, - g_info.watchInfo.Size() * sizeof(watch_dial_info), - &g_info.watchInfo[0], - g_info.watchInfo.Size() * sizeof(watch_dial_info)) != 0) { - GRAPHIC_LOGE("copy info error!"); + watch_dial_info *mem = static_cast(malloc(*num * sizeof(watch_dial_info))); + if (mem == nullptr) { + GRAPHIC_LOGE("failed to malloc"); return false; } + for (uint16_t i = 0; i < g_info.Size(); ++i) { + memcpy_s(&mem[i], sizeof(watch_dial_info), &g_info[i].watchInfo, sizeof(watch_dial_info)); + } + *info = mem; return true; } @@ -149,17 +232,19 @@ bool GetWatchFaceInfo(uint32_t uuid, watch_dial_info *watch) GRAPHIC_LOGE("para error!"); return false; } - if (!GetAllWatchInfo()) { - GRAPHIC_LOGE("failed to get all watch info."); + + uint16_t index = INVALID_INFO_INDEX; + GraphicLockGuard guard(g_mutex); + while (!g_eventFinished) { + g_cond.Wait(g_mutex); + } + GetWatchInfo(uuid, index); + if (index == INVALID_INFO_INDEX) { + GRAPHIC_LOGE("uuid %u does not exist", uuid); return false; } - for (uint16_t i = 0; i < g_info.watchInfo.Size(); ++i) { - if (g_info.watchInfo[i].uuid == uuid) { - *watch = g_info.watchInfo[i]; - return true; - } - } - return false; + memcpy_s(watch, sizeof(watch_dial_info), &g_info[index].watchInfo, sizeof(watch_dial_info)); + return true; } bool GetWatchCapability(watch_dev_cap_info *capability) @@ -238,98 +323,118 @@ bool GetCurrentWatchFaceInfo(watch_dial_info *watch) bool SetCurrentWatchFace(uint32_t uuid) { - if (!GetAllWatchInfo()) { - GRAPHIC_LOGE("failed to get all watch info."); + uint16_t index = INVALID_INFO_INDEX; + GraphicLockGuard guard(g_mutex); + while (!g_eventFinished) { + g_cond.Wait(g_mutex); + } + GetWatchInfo(uuid, index); + if (index == INVALID_INFO_INDEX) { + GRAPHIC_LOGE("uuid %u does not exist", uuid); return false; } - watch_dial_info info; - uint16_t index = 0; - bool isExists = false; - for (uint16_t i = 0; i < g_info.watchInfo.Size(); ++i) { - if (uuid == g_info.watchInfo[i].uuid) { - isExists = true; - info = g_info.watchInfo[i]; - index = i; - break; - } - } - if (!isExists) { - GRAPHIC_LOGE("uuid does not exist!"); - return false; + DialSetting setting = MainModel::GetInstance().GetDialSetting(); + setting.dialFlag = 1; + setting.dialFullName = g_info[index].fileName; + if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_SET_DIAL) { + GraphicService::GetInstance()->PostGraphicEvent([setting]() { + if (SetDialPresenter::GetCurrentInstance() != nullptr) { + SetDialPresenter::GetCurrentInstance()->SpecifyDialSetting(setting); + } + }); + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + return true; } - if (info.is_current_watch) { + if (g_info[index].watchInfo.is_current_watch) { return true; } - - DialSetting setting = MainModel::GetInstance().GetDialSetting(); - setting.dialFlag = 1; - setting.dialFullName = g_info.fileNames[index]; + g_eventFinished = false; GraphicService::GetInstance()->PostGraphicEvent([setting]() { + GraphicLockGuard guardGraphic(g_mutex); MainModel::GetInstance().GetDialSetting() = setting; - #ifdef fd230_650 MainModel::GetInstance().AddDialSetting(setting); - #endif - if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN) { - #ifdef fd230_650 + if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN_SAMPLE) { MainViewSample::GetInstance()->ReloadWatchFace(); - #endif } + g_eventFinished = true; + g_cond.Signal(); }); + TryToTurnOnScreen(); return true; } bool UninstallWatch(uint32_t uuid) { - if (!GetAllWatchInfo()) { - GRAPHIC_LOGE("failed to get all watch info."); - return false; - } - watch_dial_info info; - uint16_t index = 0; - bool isExists = false; - for (uint16_t i = 0; i < g_info.watchInfo.Size(); ++i) { - if (uuid == g_info.watchInfo[i].uuid) { - isExists = true; - info = g_info.watchInfo[i]; - index = i; - break; - } - } - if (!isExists) { - GRAPHIC_LOGE("uuid does not exist!"); + uint16_t index = INVALID_INFO_INDEX; + GraphicLockGuard guard(g_mutex); + while (!g_eventFinished) { + g_cond.Wait(g_mutex); + } + GetWatchInfo(uuid, index); + if (index == INVALID_INFO_INDEX) { + GRAPHIC_LOGE("uuid %u does not exist", uuid); return false; } - if (info.is_current_watch) { - DialSetting setting = MainModel::GetInstance().GetDialSetting(); + DialSetting setting = MainModel::GetInstance().GetDialSetting(); + if (g_info[index].watchInfo.is_current_watch) { setting.dialFlag = 0; setting.dialId = 0; - std::string fileName = g_info.fileNames[index]; - GraphicService::GetInstance()->PostGraphicEvent([setting, fileName]() { - MainModel::GetInstance().GetDialSetting() = setting; - #ifdef fd230_650 - MainModel::GetInstance().AddDialSetting(setting,0); - #endif - if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN) { - #ifdef fd230_650 - MainViewSample::GetInstance()->ReloadWatchFace(); - #endif - } - if (remove(fileName.c_str()) != 0) { - GRAPHIC_LOGE("failed to remove file %s", fileName.c_str()); + } + if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_SET_DIAL) { + if (g_info[index].watchInfo.is_current_watch) { + // If it is the current watch face, set it as the default watch face. Otherwise, the configuration remains + // unchanged. + GraphicService::GetInstance()->PostGraphicEvent([setting]() { + if (SetDialPresenter::GetCurrentInstance() != nullptr) { + SetDialPresenter::GetCurrentInstance()->SpecifyDialSetting(setting); + } + }); + } + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE); + g_eventFinished = false; + GraphicService::GetInstance()->PostGraphicEvent([index]() { + GraphicLockGuard guardGraphic(g_mutex); + ImageCacheManager::GetInstance().UnloadAllInMultiRes(g_info[index].fileName); + if (remove(g_info[index].fileName.c_str()) != 0) { + GRAPHIC_LOGE("failed to remove file %s", g_info[index].fileName.c_str()); + g_eventFinished = true; + g_cond.Signal(); + return; } + g_info.Erase(index); + g_eventFinished = true; + g_cond.Signal(); }); - } else { - if (remove(g_info.fileNames[index].c_str()) != 0) { - GRAPHIC_LOGE("failed to remove file %s", g_info.fileNames[index].c_str()); - return false; - } + return true; } + + g_eventFinished = false; + GraphicService::GetInstance()->PostGraphicEvent([index, setting]() { + GraphicLockGuard guardGraphic(g_mutex); + if (g_info[index].watchInfo.is_current_watch && + NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN_SAMPLE) { + MainModel::GetInstance().GetDialSetting() = setting; + MainModel::GetInstance().AddDialSetting(setting); + MainViewSample::GetInstance()->ReloadWatchFace(); + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(g_info[index].fileName); + if (remove(g_info[index].fileName.c_str()) != 0) { + GRAPHIC_LOGE("failed to remove file %s", g_info[index].fileName.c_str()); + g_eventFinished = true; + g_cond.Signal(); + return; + } + g_info.Erase(index); + g_eventFinished = true; + g_cond.Signal(); + }); + TryToTurnOnScreen(); return true; } -bool InstallWatch(const char *path, uint32_t *uuid) +bool GetUuidByPath(const char *path, uint32_t *uuid) { if (path == nullptr || uuid == nullptr) { GRAPHIC_LOGE("para error!"); @@ -337,49 +442,31 @@ bool InstallWatch(const char *path, uint32_t *uuid) } DialPreviewInfo preview; - if (!GetPreviewInfo(std::string(path), preview)) { + if (!GetPreviewInfo(std::string(path), preview, true)) { return false; } if (std::string(preview.protocolVersion) < std::string("3.0")) { return false; } - *uuid = preview.uuid; - if (!GetAllWatchInfo()) { - GRAPHIC_LOGE("failed to get all watchinfo!"); - return false; - } - for (uint16_t i = 0; i < g_info.watchInfo.Size(); ++i) { - const std::string &fileName = g_info.fileNames[i]; - const watch_dial_info &info = g_info.watchInfo[i]; - if (!(info.uuid == *uuid && std::string(path) != fileName)) { - continue; - } - - if (info.is_current_watch) { - DialSetting setting = MainModel::GetInstance().GetDialSetting(); - setting.dialFlag = 1; - setting.dialFullName = std::string(path); - GraphicService::GetInstance()->PostGraphicEvent([setting, fileName]() { - MainModel::GetInstance().GetDialSetting() = setting; - #ifdef fd230_650 - MainModel::GetInstance().AddDialSetting(setting); - #endif - if (NativeAbility::GetInstance().GetCurSliceId() == VIEW_MAIN) { - #ifdef fd230_650 - MainViewSample::GetInstance()->ReloadWatchFace(); - #endif - } - if (remove(fileName.c_str()) != 0) { - GRAPHIC_LOGE("failed to remove file %s", fileName.c_str()); - } - }); - } else { - if (remove(fileName.c_str()) != 0) { - return false; + watch_dial_info watchInfo; + if (ConvertPreview2WatchDialInfo(preview, watchInfo)) { + std::string activePath; + std::string appendPath(path); + bool isActiveExist = GetActiveWatchPath(activePath); + watchInfo.install_state = true; + watchInfo.is_current_watch = isActiveExist ? (activePath == appendPath) : false; + bool isExist = false; + for (uint16_t i = 0; i < g_info.Size(); ++i) { + if (g_info[i].fileName == appendPath) { + isExist = true; + break; } } + if (!isExist) { + g_info.PushBack({appendPath, watchInfo}); + } } - + *uuid = preview.uuid; return true; } \ No newline at end of file