增加充电监测
authorCaisking <3449750381@qq.com>
Sun, 18 Feb 2024 11:33:04 +0000 (19:33 +0800)
committerCaisking <3449750381@qq.com>
Sun, 18 Feb 2024 11:33:04 +0000 (19:33 +0800)
code/sdk/application/wearable/fd230app/nativeui/dial/include/Digital_clockView.h
code/sdk/application/wearable/fd230app/nativeui/dial/src/Digital_clockView.cpp
code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Battery/Battery_Charge.bin [new file with mode: 0644]
code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Battery/Charge_Icon.bin [moved from code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Battery/Icon.bin with 100% similarity]

index 2540a95..6963087 100644 (file)
@@ -152,11 +152,12 @@ namespace OHOS
     class myProgressCallback : public AnimatorCallback
     {
     private:
+        UIImageView *charge{nullptr};     // 充电闪电图标
         UIBoxProgress *progress{nullptr}; // 电池进度条控件指针
         UILabel *batterylabel{nullptr};   // 显示电池百分比的文本控件指针
 
     public:
-        explicit myProgressCallback(UIBoxProgress *progress, UILabel *batterylabel) : progress(progress), batterylabel(batterylabel) {}
+        explicit myProgressCallback(UIBoxProgress *progress, UILabel *batterylabel, UIImageView *charge) : progress(progress), batterylabel(batterylabel), charge(charge) {}
         ~myProgressCallback() {}
 
         // 电池进度更新的回调函数
@@ -166,6 +167,18 @@ namespace OHOS
             float voltage = 0.0F;
             uint8_t value = 0;
             value = battery_get_voltage(&voltage);
+            const char *progress1ForeImageSrc = nullptr;
+            const char *progress1BackImageSrc = nullptr;
+            if (get_charge_stat())
+            {
+                char *imageimagesPath = "/user/res/Battery/Charge_Icon.bin";
+                charge->SetSrc(imageimagesPath);
+                progress1ForeImageSrc = "/user/res/Battery/Battery_Charge.bin"; // 充电图片路径
+                charge->SetVisible(true);
+            }
+            else
+            {
+                charge->SetVisible(false);
 #if 0
             //设置种子
             srand(static_cast<unsigned int>(time(0)));
@@ -174,21 +187,19 @@ namespace OHOS
             //printf("value:%d\n", value);
             //根据电池电量值选择相应的进度条前景图片
 #endif
-            const char *progress1ForeImageSrc = nullptr;
-            const char *progress1BackImageSrc = nullptr;
-            if (value <= 10)
-            {
-                progress1ForeImageSrc = "/user/res/Battery/Battery_Limit.bin"; // 低电量图片路径
-            }
-            else if (value <= 20)
-            {
-                progress1ForeImageSrc = "/user/res/Battery/Battery_Save.bin"; // 中等电量图片路径
-            }
-            else
-            {
-                progress1ForeImageSrc = "/user/res/Battery/Battery_Nomoal.bin"; // 正常电量图片路径
+                if (value <= 10)
+                {
+                    progress1ForeImageSrc = "/user/res/Battery/Battery_Limit.bin"; // 低电量图片路径
+                }
+                else if (value <= 20)
+                {
+                    progress1ForeImageSrc = "/user/res/Battery/Battery_Save.bin"; // 中等电量图片路径
+                }
+                else
+                {
+                    progress1ForeImageSrc = "/user/res/Battery/Battery_Nomoal.bin"; // 正常电量图片路径
+                }
             }
-
             // 设置进度条的前景和背景图片,并更新进度值
             progress->SetImage(progress1ForeImageSrc, progress1BackImageSrc);
             progress->SetValue(value);                                    // 更新界面
@@ -344,6 +355,7 @@ namespace OHOS
         UIImageView *colon = nullptr;
         UIImageView *minute1 = nullptr;
         UIImageView *minute2 = nullptr;
+        UIImageView *charge = nullptr;
         UILabel *timeLable = nullptr;
         UILabel *dateLable = nullptr;
         UILabel *weekLable = nullptr;
index b323414..1b3cb24 100644 (file)
@@ -639,13 +639,22 @@ namespace OHOS
         batteryLable->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
         batteryLable->SetRollSpeed(0);
         batteryLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, fontsize);
-
         // Add to rootView
         Add(batteryLable);
         // batteryLable->SetVisible(true);
 
-        progress1callback_ = new myProgressCallback(progress, batteryLable);
-        progress1animator_ = new Animator(progress1callback_, progress, 10000, true);
+        // Add ImageView to App
+        if (charge == nullptr)
+        {
+            charge = new UIImageView();
+        }
+        charge->SetPosition(190, 27); // widget's left position and top position
+        charge->Resize(100, 100);     // widget's width and height
+        charge->SetViewId("image1");  // Set style
+        Add(charge);
+
+        progress1callback_ = new myProgressCallback(progress, batteryLable, charge);
+        progress1animator_ = new Animator(progress1callback_, progress, 1000, true);
         progress1animator_->Start();
         return true;
     };
@@ -755,6 +764,8 @@ namespace OHOS
         batteryLable = nullptr;
         delete progress;
         progress = nullptr;
+        delete charge;
+        charge = nullptr;
         /* -------------------------------------------------------------------------- */
         if (timeLableanimator_ != nullptr)
         {
diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Battery/Battery_Charge.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Battery/Battery_Charge.bin
new file mode 100644 (file)
index 0000000..467ba1f
Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Battery/Battery_Charge.bin differ