更正进度条不同步bug
authorCaisking <3449750381@qq.com>
Thu, 22 Feb 2024 09:06:54 +0000 (17:06 +0800)
committerCaisking <3449750381@qq.com>
Thu, 22 Feb 2024 09:06:54 +0000 (17:06 +0800)
code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialBoxProgressView.h
code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp
code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialBoxProgressView.cpp
code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialModelPower.cpp
code/sdk/application/wearable/service/msg_center/include/notify/charge_notification.h [new file with mode: 0644]
code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp [new file with mode: 0644]

index ad1f1d5..e4aca93 100644 (file)
@@ -13,9 +13,14 @@ class DialBoxProgressView : public UIBoxProgress, public DialView {
 public:
     DialBoxProgressView();
     virtual ~DialBoxProgressView();
+    static DialBoxProgressView* GetInstance()
+    {
+        static DialBoxProgressView instance;
+        return &instance;
+    }
     void HandleFloatData(float data) override;
 private:
-    int32_t value_ = 50;
+    int32_t value_ = -1;
 };
 }
 #endif
\ No newline at end of file
index af86ed7..9a82988 100644 (file)
@@ -23,6 +23,7 @@
 #include "ModelDialDataFactory.h"
 #include "PresenterTask.h"
 #include "DialModelTime.h"
+#include "DialModelPower.h"
 #if USE_OFFLINE_DIAL
 #include "DialViewGroup.h"
 #endif
@@ -32,7 +33,7 @@ namespace OHOS
 {
 
     map<string, AppViewId> g_jumpView = {
-        {DROPDOWN_CLICK_SETTING, VIEW_SETTING},              // 设置
+        {DROPDOWN_CLICK_SETTING, VIEW_SETTING},             // 设置
         {DROPDOWN_CLICK_BLUETOOTH, VIEW_CLASSIC_BLUETOOTH}, // 蓝牙
     };
 
@@ -139,7 +140,7 @@ namespace OHOS
                 SendMsgToUIService(SCREEN_OFF_ENABLE_TO_UI, 0, &enable, sizeof(int32_t));
             }
         }
-        #endif
+#endif
         if (g_jumpView.count(curViewId) != 0)
         {
             NativeAbility::GetInstance().ChangeSlice(g_jumpView[curViewId]);
@@ -290,6 +291,7 @@ namespace OHOS
         {
 #if USE_OFFLINE_DIAL
             DialModelTime::GetInstance()->UpdateTime();
+            DialModelPower::GetInstance()->UpdatePower();
             dynamic_cast<DialViewGroup *>(view_->GetViewById(WATCH_FACE))->UpdateViewsByPeriodicUpdateData();
 #else
             dynamic_cast<MainClockView *>(view_->GetViewById(WATCH_FACE))->UpdateTime();
index 8084dfb..6a5088f 100644 (file)
@@ -3,29 +3,41 @@
  */
 
 #include "DialBoxProgressView.h"
+#include "wearable_log.h"
+#include "battery_hal.h"
+extern uint8_t battery_get_voltage(float *voltage);
 
-namespace OHOS {
-DialBoxProgressView::DialBoxProgressView(void)
+namespace OHOS
 {
-}
-
-DialBoxProgressView::~DialBoxProgressView(void)
-{
-}
+    DialBoxProgressView::DialBoxProgressView(void)
+    {
+    }
 
-void DialBoxProgressView::HandleFloatData(float data)
-{
-    float ratio = data;
-    if (ratio > 1.0f) {
-        ratio = 1.0f;
-    } else if (ratio < 0.0f) {
-        ratio = 0.0f;
+    DialBoxProgressView::~DialBoxProgressView(void)
+    {
     }
-    int32_t value = ratio * (GetRangeMax() - GetRangeMin());
-    if (value_ == value) {
-        return;
+
+    void DialBoxProgressView::HandleFloatData(float data)
+    {
+        float ratio = data;
+        if (ratio > 1.0f)
+        {
+            ratio = 1.0f;
+        }
+        else if (ratio < 0.0f)
+        {
+            ratio = 0.0f;
+        }
+        int32_t value = ratio * (GetRangeMax() - GetRangeMin());
+        if (value_ == value)
+        {
+            return;
+        }
+        // 获取电池电压值
+        float voltage = 0.0F;
+        value = battery_get_voltage(&voltage);
+        value_ = value;
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"battery_get_value:%d", value_);
+        SetValue(value_);
     }
-    value_ = value;
-    SetValue(value_);
 }
-}
\ No newline at end of file
index 55d6a94..1e5f086 100644 (file)
@@ -7,6 +7,7 @@
 
 #include "RegisterDialModel.h"
 #include "DialModelPower.h"
+#include "DialBoxProgressView.h"
 #include <string>
 #include "battery_hal.h"
 extern uint8_t battery_get_voltage(float *voltage);
@@ -17,12 +18,11 @@ namespace OHOS
 {
     bool DialModelPower::GetDialFloatData(DialDataType &type, float &out)
     {
-        if (power_ == 0)
-        {
-            UpdatePower();
-        }
         (void)type;
-        out = power_;
+        // 获取电池电压值
+        float voltage = 0.0F;
+        power_ = battery_get_voltage(&voltage);
+        out = static_cast<float>(power_);
         return true;
     }
     void DialModelPower::UpdatePower()
@@ -30,9 +30,12 @@ namespace OHOS
         // 获取电池电压值
         float voltage = 0.0F;
         power_ = battery_get_voltage(&voltage);
+#if 1
         if (onChangeListener_ != nullptr)
         {
             onChangeListener_->OnDialFloatDataUpdate(DialDataType::DATA_TYPE_POWER, power_);
         }
+#endif
     }
+
 }
diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/charge_notification.h b/code/sdk/application/wearable/service/msg_center/include/notify/charge_notification.h
new file mode 100644 (file)
index 0000000..7cbcade
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef CHARGE_NOTIFICATION_H
+#define CHARGE_NOTIFICATION_H
+
+namespace OHOS
+{
+    UIViewGroup *ChargingStatuShow(void);
+    UIView *view_ = nullptr;
+};
+#endif /* CHARGE_NOTIFICATION_H */
\ No newline at end of file
diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp
new file mode 100644 (file)
index 0000000..661f390
--- /dev/null
@@ -0,0 +1,35 @@
+#include "notification_manager.h"
+#include "wearable_log.h"
+#include "UiConfig.h"
+#include "AlarmPopUpPresenter.h"
+#include "components/ui_image_view.h"
+#include "components/ui_label.h"
+namespace OHOS
+{
+    UIImageView *imageCharge = nullptr;
+
+    // 展示充电图标
+    UIViewGroup *ChargingStatuShow()
+    {
+        // Add ImageView to App
+        if (imageCharge == nullptr)
+        {
+            imageCharge = new UIImageView();
+        }
+        imageCharge->SetPosition(186, 55); // widget's left position and top position
+        imageCharge->Resize(100, 100);     // widget's width and height
+        imageCharge->SetViewId("image1");  // Set style
+
+        // Set additional property
+        char *image1imagesPath = "/user/res/Battery/Charge_Icon.bin";
+        imageCharge->SetSrc(image1imagesPath);
+
+        // Add to rootView
+        RootView::GetInstance()->Add(imageCharge);
+
+        if (view_->GetHorCurrentPage() == WATCH_FACE)
+        {
+            imageCharge->SetVisible(true);
+        }
+    }
+}