#18 显示中文表盘名称
authorCaisking <3449750381@qq.com>
Wed, 24 Jul 2024 10:01:26 +0000 (18:01 +0800)
committerCaisking <3449750381@qq.com>
Wed, 24 Jul 2024 10:01:26 +0000 (18:01 +0800)
code/sdk/application/wearable/fd230app/nativeui/set_dial/src/SetDialView.cpp

index 82a55d0..619c335 100644 (file)
 #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<SetDialPresenter>::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<SetDialInfo> &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<SetDialPresenter>::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<SetDialInfo> &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<SetDialInfo> &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<SetDialPresenter>::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<SetDialPresenter>::OnTearDownView();
-}
+        std::vector<SetDialInfo> &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<SetDialPresenter>::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<int16_t>(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<int16_t>(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<SetDialInfo> &dialInfo = presenter_->GetDialInfo();
-        label_.SetText(dialInfo[lastIndex_].dialName.c_str());
+    void SetDialView::OnSetUpView()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetDialView::OnSetUpView");
+        View<SetDialPresenter>::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<SetDialPresenter>::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<SetDialPresenter>::OnStop();
+        if (container_ != nullptr)
+        {
+            container_->RemoveAll();
+            delete container_;
+            container_ = nullptr;
+        }
     }
-    if (currentItemAngle < 0) {
-        currentItemAngle = -currentItemAngle;
+
+    void SetDialView::CoverflowViewScroll(void)
+    {
+        int16_t contMidX = static_cast<int16_t>(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<int16_t>(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<SetDialInfo> &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<SetDialInfo> &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<SetDialInfo> &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_;
+    }
 
 }