From 2d4252cee199f26b8d633b1015292ccb239ed740 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Wed, 24 Jul 2024 18:01:26 +0800 Subject: [PATCH] =?utf8?q?#18=20=E6=98=BE=E7=A4=BA=E4=B8=AD=E6=96=87?= =?utf8?q?=E8=A1=A8=E7=9B=98=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/set_dial/src/SetDialView.cpp | 357 +++++++++++------- 1 file changed, 213 insertions(+), 144 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialView.cpp b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialView.cpp index 82a55d015..619c335cd 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialView.cpp @@ -10,171 +10,240 @@ #include "SetDialPresenter.h" #include "SetDialStyleModel.h" -namespace OHOS { -SetDialView::SetDialView() +namespace OHOS { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::SetDialView"); -} - -SetDialView::~SetDialView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::~SetDialView"); -} - -void SetDialView::OnStart() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::OnStart"); - View::OnStart(); - SetContainerView(new UIViewGroup()); - container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - if (SetDialStyleModel::GetInstance().GetStyle() == DialStyle::COVERFLOW) { - SetUpCoverflowView(); - } else { - SetUpRollerView(); + SetDialView::SetDialView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::SetDialView"); } -} -void SetDialView::SetUpCoverflowView(void) -{ - coverflow_.SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - coverflow_.SetIntercept(true); - coverflow_.SetOnCoverflowListener(presenter_); - coverflow_.SetOnClickListener(presenter_); - coverflow_.SetThrowDrag(true); - std::vector &dialInfo = presenter_->GetDialInfo(); - for (auto iter : dialInfo) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::SetUpCoverflowView %s", - iter.dialName.c_str()); - coverflow_.Add(iter.dialName.c_str(), iter.preImageInfo); + SetDialView::~SetDialView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::~SetDialView"); } - lastIndex_ = presenter_->GetPageIndex(); - coverflow_.SetCurrentPage(lastIndex_); - label_.SetPosition(127, 50, 200, 50); - label_.SetTextColor(Color::White()); - label_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label_.SetText(dialInfo[lastIndex_].dialName.c_str()); - label_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + void SetDialView::OnStart() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::OnStart"); + View::OnStart(); + SetContainerView(new UIViewGroup()); + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + if (SetDialStyleModel::GetInstance().GetStyle() == DialStyle::COVERFLOW) + { + SetUpCoverflowView(); + } + else + { + SetUpRollerView(); + } + } - container_->Add(&coverflow_); - container_->Add(&label_); -} + void SetDialView::SetUpCoverflowView(void) + { + coverflow_.SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + coverflow_.SetIntercept(true); + coverflow_.SetOnCoverflowListener(presenter_); + coverflow_.SetOnClickListener(presenter_); + coverflow_.SetThrowDrag(true); + std::vector &dialInfo = presenter_->GetDialInfo(); + for (auto iter : dialInfo) + { + if (iter.dialFlag) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::SetUpCoverflowView description %s", + iter.description.c_str()); + coverflow_.Add(iter.description.c_str(), iter.preImageInfo); + } + else + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::SetUpCoverflowView dialName %s", + iter.dialName.c_str()); + coverflow_.Add(iter.dialName.c_str(), iter.preImageInfo); + } + } + lastIndex_ = presenter_->GetPageIndex(); + coverflow_.SetCurrentPage(lastIndex_); + + label_.SetPosition(127, 50, 200, 50); + label_.SetTextColor(Color::White()); + label_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + + if (dialInfo[lastIndex_].dialFlag) + { + // 切换表盘[表盘名称设置{多国语言需要配置xml里面的表盘描述}] + label_.SetText(dialInfo[lastIndex_].description.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetText dialName %s", + dialInfo[lastIndex_].description.c_str()); + } + else + { + label_.SetText(dialInfo[lastIndex_].dialName.c_str()); + } -void SetDialView::SetUpRollerView(void) -{ - rollerView_.SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - rollerView_.SetItemSize(150, 150); // 150: item size - rollerView_.SetThrowDrag(true); - rollerView_.SetItemPadding(80); // 80: item padding - container_->Add(&rollerView_); - - std::vector &dialInfo = presenter_->GetDialInfo(); - for (auto iter : dialInfo) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::SetUpRollerView %s", - iter.dialName.c_str()); - bool succ = rollerView_.AddItem(iter.dialName, iter.preImageInfo); - rollerItemNum_ += succ ? 1 : 0; + label_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + container_->Add(&coverflow_); + container_->Add(&label_); } - float scalerCoef = 0.55; - uint16_t w = Screen::GetInstance().GetWidth(); - uint16_t h = Screen::GetInstance().GetHeight(); - rollerView_.SetItemSize(w * scalerCoef, h * scalerCoef); - lastIndex_ = presenter_->GetPageIndex(); - rollerView_.SetCurrentItem(dialInfo[lastIndex_].dialName); - rollerView_.SetOnClickListener(presenter_); - rollerView_.SetOnScrollListener(presenter_); - - label_.SetPosition(127, 50, 200, 50); - label_.SetTextColor(Color::White()); - label_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label_.SetText(dialInfo[lastIndex_].dialName.c_str()); - label_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - container_->Add(&label_); -} -void SetDialView::OnSetUpView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::OnSetUpView"); - View::OnSetUpView(); -} + void SetDialView::SetUpRollerView(void) + { + rollerView_.SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + rollerView_.SetItemSize(150, 150); // 150: item size + rollerView_.SetThrowDrag(true); + rollerView_.SetItemPadding(80); // 80: item padding + container_->Add(&rollerView_); -void SetDialView::OnTearDownView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::OnTearDownView"); - View::OnTearDownView(); -} + std::vector &dialInfo = presenter_->GetDialInfo(); + for (auto iter : dialInfo) + { + bool succ = false; + if (iter.dialFlag) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::SetUpCoverflowView description %s", + iter.description.c_str()); + succ = rollerView_.AddItem(iter.description.c_str(), iter.preImageInfo); + } + else + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::SetUpCoverflowView dialName %s", + iter.dialName.c_str()); + succ = rollerView_.AddItem(iter.dialName.c_str(), iter.preImageInfo); + } + rollerItemNum_ += succ ? 1 : 0; + } + float scalerCoef = 0.55; + uint16_t w = Screen::GetInstance().GetWidth(); + uint16_t h = Screen::GetInstance().GetHeight(); + rollerView_.SetItemSize(w * scalerCoef, h * scalerCoef); + lastIndex_ = presenter_->GetPageIndex(); + rollerView_.SetCurrentItem(dialInfo[lastIndex_].dialName); + rollerView_.SetOnClickListener(presenter_); + rollerView_.SetOnScrollListener(presenter_); + + label_.SetPosition(127, 50, 200, 50); + label_.SetTextColor(Color::White()); + label_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + + if (dialInfo[lastIndex_].dialFlag) + { + // 切换表盘[表盘名称设置{多国语言需要配置xml里面的表盘描述}] + label_.SetText(dialInfo[lastIndex_].description.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetText dialName %s", + dialInfo[lastIndex_].description.c_str()); + } + else + { + label_.SetText(dialInfo[lastIndex_].dialName.c_str()); + } -void SetDialView::OnStop() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::OnStop"); - View::OnStop(); - if (container_ != nullptr) { - container_->RemoveAll(); - delete container_; - container_ = nullptr; + label_.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + container_->Add(&label_); } -} -void SetDialView::CoverflowViewScroll(void) -{ - int16_t contMidX = static_cast(Screen::GetInstance().GetWidth() / DIVISOR_TWO); - int16_t minOffset = contMidX; - uint8_t newCenterIndex = lastIndex_; - for (uint8_t i = 0; i < coverflow_.GetChildrenNumber(); i++) { - Rect rect = coverflow_.GetViewByIndex(i)->GetOrigRect(); - int16_t x = rect.GetLeft(); - int16_t x1 = rect.GetRight(); - int16_t xMid = static_cast(x + (x1 - x + 1) / DIVISOR_TWO); - int16_t distance = MATH_ABS(xMid - contMidX); - if (distance < minOffset) { - newCenterIndex = i; - minOffset = distance; - } - } - if (newCenterIndex != lastIndex_) { - lastIndex_ = newCenterIndex; - std::vector &dialInfo = presenter_->GetDialInfo(); - label_.SetText(dialInfo[lastIndex_].dialName.c_str()); + void SetDialView::OnSetUpView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::OnSetUpView"); + View::OnSetUpView(); } - Rect curViewRect = coverflow_.GetViewByIndex(lastIndex_)->GetOrigRect(); - int16_t centerMid = curViewRect.GetLeft() + curViewRect.GetWidth() / DIVISOR_TWO; - int16_t offset = MATH_ABS(contMidX - centerMid); - if (offset > curViewRect.GetWidth() / DIVISOR_TWO) { - label_.SetStyle(STYLE_TEXT_OPA, 0); - } else { - uint8_t alpha = (uint8_t)((1.0f - ((float)offset / (curViewRect.GetWidth() / DIVISOR_TWO))) * OPA_OPAQUE); - label_.SetStyle(STYLE_TEXT_OPA, alpha); + void SetDialView::OnTearDownView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::OnTearDownView"); + View::OnTearDownView(); } - presenter_->ResetTickTimer(); -} -void SetDialView::RollerViewScroll(std::string currentItemName, float currentItemAngle) -{ - const float baseAngle = 360.0; - const float halfBaseAngle = 180.0; - if (FloatMoreEqual(currentItemAngle, halfBaseAngle)) { - currentItemAngle -= baseAngle; + void SetDialView::OnStop() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::OnStop"); + View::OnStop(); + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } } - if (currentItemAngle < 0) { - currentItemAngle = -currentItemAngle; + + void SetDialView::CoverflowViewScroll(void) + { + int16_t contMidX = static_cast(Screen::GetInstance().GetWidth() / DIVISOR_TWO); + int16_t minOffset = contMidX; + uint8_t newCenterIndex = lastIndex_; + for (uint8_t i = 0; i < coverflow_.GetChildrenNumber(); i++) + { + Rect rect = coverflow_.GetViewByIndex(i)->GetOrigRect(); + int16_t x = rect.GetLeft(); + int16_t x1 = rect.GetRight(); + int16_t xMid = static_cast(x + (x1 - x + 1) / DIVISOR_TWO); + int16_t distance = MATH_ABS(xMid - contMidX); + if (distance < minOffset) + { + newCenterIndex = i; + minOffset = distance; + } + } + if (newCenterIndex != lastIndex_) + { + lastIndex_ = newCenterIndex; + std::vector &dialInfo = presenter_->GetDialInfo(); + if (dialInfo[lastIndex_].dialFlag) + { + // 切换表盘[表盘名称设置{多国语言需要配置xml里面的表盘描述}] + label_.SetText(dialInfo[lastIndex_].description.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetText dialName %s", + dialInfo[lastIndex_].description.c_str()); + } + else + { + label_.SetText(dialInfo[lastIndex_].dialName.c_str()); + } + } + + Rect curViewRect = coverflow_.GetViewByIndex(lastIndex_)->GetOrigRect(); + int16_t centerMid = curViewRect.GetLeft() + curViewRect.GetWidth() / DIVISOR_TWO; + int16_t offset = MATH_ABS(contMidX - centerMid); + if (offset > curViewRect.GetWidth() / DIVISOR_TWO) + { + label_.SetStyle(STYLE_TEXT_OPA, 0); + } + else + { + uint8_t alpha = (uint8_t)((1.0f - ((float)offset / (curViewRect.GetWidth() / DIVISOR_TWO))) * OPA_OPAQUE); + label_.SetStyle(STYLE_TEXT_OPA, alpha); + } + presenter_->ResetTickTimer(); } - float maxAngle = baseAngle / rollerItemNum_; - float coef = 1.0 - 1.0 / (maxAngle) * currentItemAngle; - label_.SetStyle(STYLE_TEXT_OPA, coef * OPA_OPAQUE); - label_.SetText(currentItemName.c_str()); - std::vector &dialInfo = presenter_->GetDialInfo(); - for (uint8_t i = 0; i < dialInfo.size(); ++i) { - if (dialInfo[i].dialName == currentItemName) { - lastIndex_ = i; + + void SetDialView::RollerViewScroll(std::string currentItemName, float currentItemAngle) + { + const float baseAngle = 360.0; + const float halfBaseAngle = 180.0; + if (FloatMoreEqual(currentItemAngle, halfBaseAngle)) + { + currentItemAngle -= baseAngle; + } + if (currentItemAngle < 0) + { + currentItemAngle = -currentItemAngle; } + float maxAngle = baseAngle / rollerItemNum_; + float coef = 1.0 - 1.0 / (maxAngle)*currentItemAngle; + label_.SetStyle(STYLE_TEXT_OPA, coef * OPA_OPAQUE); + label_.SetText(currentItemName.c_str()); + std::vector &dialInfo = presenter_->GetDialInfo(); + for (uint8_t i = 0; i < dialInfo.size(); ++i) + { + if (dialInfo[i].dialName == currentItemName) + { + lastIndex_ = i; + } + } + presenter_->ResetTickTimer(); } - presenter_->ResetTickTimer(); -} -uint8_t SetDialView::GetCoverflowPage(void) -{ - return lastIndex_; -} + uint8_t SetDialView::GetCoverflowPage(void) + { + return lastIndex_; + } } -- 2.17.1