增加ota状态栏
authorxue <2144439972@qq.com>
Wed, 24 Sep 2025 07:52:54 +0000 (15:52 +0800)
committerxue <2144439972@qq.com>
Wed, 24 Sep 2025 07:52:54 +0000 (15:52 +0800)
code/sdk/application/wearable/ln/nativeapp/nativeui/ota/include/OtaModel.h
code/sdk/application/wearable/ln/nativeapp/nativeui/ota/include/OtaView.h
code/sdk/application/wearable/ln/nativeapp/nativeui/ota/src/OtaModel.cpp
code/sdk/application/wearable/ln/nativeapp/nativeui/ota/src/OtaView.cpp
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdMainView.cpp

index 8bc383d..ddef5bb 100644 (file)
@@ -35,6 +35,21 @@ namespace OHOS
         void StopCountdownTimer();
         void CountdownCallback();
         
+        // 状态栏更新定时器管理
+        void StartStatusBarTimer();
+        void StopStatusBarTimer();
+        void StatusBarTimerCallback();
+        static void StatusBarTimerCallbackWrapper(void* arg);
+        
+        // 状态栏信息更新方法
+        void UpdateStatusBarInfo();
+        std::string GetCurrentTimeString();
+        void UpdateBatteryInfo();
+        void UpdateSignalInfo();
+        int GetBatteryLevel();
+        bool IsBatteryCharging();
+        int GetSignalStrength();
+        
         // OTA操作
         int StartOtaUpdate();
         int StopOtaUpdate();
@@ -58,6 +73,10 @@ namespace OHOS
         bool m_countdownActive;    // 倒计时是否激活
         int m_countdownValue;      // 倒计时值
         void* m_countdownTimer;    // 倒计时定时器
+        
+        // 状态栏更新定时器
+        void* m_statusBarTimer;    // 状态栏更新定时器
+        bool m_statusBarTimerActive; // 定时器激活状态
     };
 }
 
index 821097f..9b99c53 100644 (file)
@@ -76,10 +76,17 @@ namespace OHOS
         bool ClickFunc(int16_t interface);
         void ChangeView(int16_t hideView, int16_t showView);
         int16_t GetCurrentView();
+        
+        // 状态栏显示更新方法
+        void UpdateStatusBarDisplay();
+        void UpdateBatteryDisplay();
+        void UpdateSignalDisplay();
 
     private:
         void InitUI();
         void ClearAll();
+        UIViewGroup* CreateIndependentStatusBar(); // 创建独立的状态栏
+        
 
 
         int16_t currentView_;
index 0baf195..b8add05 100644 (file)
@@ -28,12 +28,17 @@ namespace OHOS
         m_countdownActive = false;
         m_countdownValue = 0;
         m_countdownTimer = nullptr;
+        
+        // 初始化状态栏定时器
+        m_statusBarTimer = nullptr;
+        m_statusBarTimerActive = false;
     }
 
     OtaModel::~OtaModel()
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OtaModel::~OtaModel");
         StopCountdownTimer();
+        StopStatusBarTimer(); // 停止状态栏定时器
         g_pOtaModel = nullptr;
     }
 
@@ -257,5 +262,135 @@ namespace OHOS
     OtaUpdatingView::GetInstance()->UpdateProgress(progress);
   }
 
-    
+    // 状态栏定时器回调函数
+    void OtaModel::StatusBarTimerCallbackWrapper(void* arg)
+    {
+        OtaModel* otaModel = static_cast<OtaModel*>(arg);
+        if (otaModel) {
+            otaModel->StatusBarTimerCallback();
+        }
+    }
+
+    void OtaModel::StatusBarTimerCallback()
+    {
+        if (!m_statusBarTimerActive) {
+            return;
+        }
+
+        // 更新状态栏信息
+        UpdateStatusBarInfo();
+    }
+
+    void OtaModel::StartStatusBarTimer()
+    {
+        if (m_statusBarTimer != nullptr) {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StatusBar timer already exists");
+            return;
+        }
+
+        // 创建定时器,每秒更新一次
+        m_statusBarTimer = osTimerNew(StatusBarTimerCallbackWrapper, osTimerPeriodic, this, nullptr);
+        if (m_statusBarTimer == nullptr) {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to create status bar timer");
+            return;
+        }
+
+        // 启动定时器,每1000ms执行一次
+        osStatus_t status = osTimerStart(m_statusBarTimer, 1000);
+        if (status != osOK) {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to start status bar timer: %d", status);
+            osTimerDelete(m_statusBarTimer);
+            m_statusBarTimer = nullptr;
+            return;
+        }
+
+        m_statusBarTimerActive = true;
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Status bar timer started successfully");
+    }
+
+    void OtaModel::StopStatusBarTimer()
+    {
+        if (m_statusBarTimer == nullptr) {
+            return;
+        }
+
+        m_statusBarTimerActive = false;
+        osTimerStop(m_statusBarTimer);
+        osTimerDelete(m_statusBarTimer);
+        m_statusBarTimer = nullptr;
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Status bar timer stopped");
+    }
+
+    void OtaModel::UpdateStatusBarInfo()
+    {
+        // 通过图形服务更新UI
+        GraphicService::GetInstance()->PostGraphicEvent([]() {
+            if (OtaView::GetInstance()) {
+                OtaView::GetInstance()->UpdateStatusBarDisplay();
+            }
+        });
+    }
+
+    std::string OtaModel::GetCurrentTimeString()
+    {
+        // 获取当前时间并格式化为 HH:MM
+        time_t now = time(nullptr);
+        struct tm* timeinfo = localtime(&now);
+        
+        char timeStr[6]; // HH:MM + null terminator
+        strftime(timeStr, sizeof(timeStr), "%H:%M", timeinfo);
+        
+        return std::string(timeStr);
+    }
+
+    void OtaModel::UpdateBatteryInfo()
+    {
+        // 通过图形服务更新UI
+        GraphicService::GetInstance()->PostGraphicEvent([]() {
+            if (OtaView::GetInstance()) {
+                OtaView::GetInstance()->UpdateBatteryDisplay();
+            }
+        });
+    }
+
+    void OtaModel::UpdateSignalInfo()
+    {
+        // 通过图形服务更新UI
+        GraphicService::GetInstance()->PostGraphicEvent([]() {
+            if (OtaView::GetInstance()) {
+                OtaView::GetInstance()->UpdateSignalDisplay();
+            }
+        });
+    }
+
+    int OtaModel::GetBatteryLevel()
+    {
+        // 使用电池服务API获取电池电量
+        float voltage = 0.0F;
+        int batteryLevel = 0;
+        
+#ifdef SUPPORT_BATTERY_SERVICE
+        batteryLevel = battery_get_voltage(&voltage);
+#endif
+        
+        return batteryLevel;
+    }
+
+    bool OtaModel::IsBatteryCharging()
+    {
+        // 使用电池服务API获取充电状态
+        bool isCharging = false;
+        
+#ifdef SUPPORT_BATTERY_SERVICE
+        isCharging = get_charge_stat();
+#endif
+        
+        return isCharging;
+    }
+
+    int OtaModel::GetSignalStrength()
+    {
+        
+        return  uapi_dev_runtime_get_cat1_signal(); 
+    }
 }
index 9081678..4272320 100644 (file)
@@ -17,6 +17,7 @@
 #include "ota/include/OtaUpdateNowView.h"
 #include "ota/include/OtaNightUpdateView.h"
 #include "ota/include/OtaNightUpdateSuccessView.h"
+#include "ota/include/OtaModel.h"
 #include "wearable_log.h"
 #include "custom_utils.h"
 #include "thunderbird/include/ThunderBirdModel.h"
@@ -77,12 +78,18 @@ namespace OHOS
             ChangeView(MAX_OTA_VIEW, OTA_VIEW_UPDATE_NOW);
         }
 
-        // ScrollView_->Add(ThunderBirdMainView::GetInstance()->InitBaseData()); // 最上面状态栏
+        // 添加状态栏(如果ThunderBirdMainView存在则复用,否则创建独立的状态栏)
+
+        ScrollView_->Add(CreateIndependentStatusBar()); // 创建独立的状态栏
+        
+        // 启动状态栏更新定时器
+        OtaModel::GetInstance()->StartStatusBarTimer();
     }
 
     void OtaView::OnStop()
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OtaView::OnStop");
+        OtaModel::GetInstance()->StopStatusBarTimer(); // 停止状态栏定时器
         View<OtaPresenter>::OnStop();
     }
 
@@ -428,4 +435,226 @@ namespace OHOS
     //     //     VolumeProgress->SetValue(value);
     //     // }
     // }
+
+    UIViewGroup* OtaView::CreateIndependentStatusBar()
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OtaView::CreateIndependentStatusBar");
+        
+        if (group1 == nullptr)
+        {
+            group1 = new UIViewGroup();
+            if (group1 == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group1 new fail");
+                return nullptr;
+            }
+        }
+        group1->SetPosition(90, 14, 175, 40);
+        group1->SetStyle(STYLE_BACKGROUND_OPA, 0);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group1 init success");
+
+        // 创建时间标签
+        timeLabel = new UILabelExt();
+        if (timeLabel == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timeLabel new fail");
+            return nullptr;
+        }
+        timeLabel->SetPosition(0, 4, 60, 33);
+        timeLabel->SetViewId("timeLabel");
+        timeLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24);
+        timeLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+        timeLabel->SetVisible(true);
+        timeLabel->SetText("12:00"); // 默认时间
+        group1->Add(timeLabel);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timeLabel add success");
+
+        // 创建无信号图标
+        if (NoSignal == nullptr)
+        {
+            NoSignal = new UIImageView();
+            if (NoSignal == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NoSignal new fail");
+                return nullptr;
+            }
+        }
+        NoSignal->SetAutoEnable(false);
+        NoSignal->SetPosition(80, (group1->GetHeight() - 25) / 2, 25, 25);     
+        NoSignal->SetResizeMode(UIImageView::COVER);
+        NoSignal->SetSrc(DROPDOWN_NOSIGNAL_IMAGE);
+        NoSignal->SetVisible(false);
+        group1->Add(NoSignal);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NoSignal add success");
+
+        // 创建信号强度指示器
+        struct ImageViewInfo
+        {
+            int posX;
+            int posY;
+            int width;
+            int height;
+        };
+        std::vector<ImageViewInfo> imageViewList = {
+            {65, 28, 6, 6},
+            {75, 20, 6, 14},
+            {85, 12, 6, 22},
+            {95, 4, 6, 30},
+        };
+
+        for (int i = 0; i < 4; i++)
+        {
+            if (showSignalStrength[i] == nullptr)
+            {
+                showSignalStrength[i] = new UIImageView();
+                if (showSignalStrength[i] == nullptr)
+                {
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showSignalStrength[%d] new fail", i);
+                    return nullptr;
+                }
+            }
+            showSignalStrength[i]->SetPosition(imageViewList[i].posX, imageViewList[i].posY, imageViewList[i].width, imageViewList[i].height);
+            showSignalStrength[i]->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);
+            showSignalStrength[i]->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+            showSignalStrength[i]->SetStyle(STYLE_BORDER_RADIUS, 10);
+            group1->Add(showSignalStrength[i]);
+            showSignalStrength[i]->SetVisible(true);
+        }
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showSignalStrength add success");
+
+        // 创建电池图标
+        batteryimage = new UIImageView();
+        if (batteryimage == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryimage new fail");
+            return nullptr;
+        }
+        batteryimage->SetAutoEnable(false);
+        batteryimage->SetPosition(95 + 20, (group1->GetHeight() - 20) / 2, 32, 20);
+        batteryimage->SetResizeMode(UIImageView::COVER);
+        std::string batteryimagesPath = "/user/res/Battery_White.bin";
+        batteryimage->SetSrc(batteryimagesPath.c_str());
+        group1->Add(batteryimage);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryimage add success");
+
+        // 创建电池进度条
+        progress = new UIBoxProgress();
+        if (progress == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "progress new fail");
+            return nullptr;
+        }
+        progress->SetPosition(batteryimage->GetX() + 5, batteryimage->GetY() + 4, 18, 12);
+        progress->SetValidWidth(18);
+        progress->SetValidHeight(12);
+        progress->SetRange(100, 0);
+        progress->SetStyle(STYLE_BORDER_RADIUS, 3);
+        progress->SetBackgroundStyle(STYLE_BACKGROUND_OPA, 0x00);
+        progress->SetBackgroundStyle(STYLE_TEXT_COLOR, 0xff000000);
+        progress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);
+        progress->SetForegroundStyle(STYLE_TEXT_COLOR, 0xff000000);
+        progress->SetForegroundStyle(STYLE_LINE_COLOR, 0xff45A5FF);
+        group1->Add(progress);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "progress add success");
+
+        // 创建电池电量标签
+        batteryLabel = new UILabel();
+        if (batteryLabel == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryLabel new fail");
+            return nullptr;
+        }
+        batteryLabel->SetPosition(batteryimage->GetX() + 38, (group1->GetHeight() - 14) / 2, 30, 30);
+        batteryLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 15);
+        batteryLabel->SetText("100");
+        batteryLabel->SetStyle(STYLE_TEXT_COLOR, Color::White().full);
+        batteryLabel->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_LEFT);
+        group1->Add(batteryLabel);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryLabel add success");
+
+        // 创建充电图标
+        chargeBatteryicon = new UIImageView();
+        if (!chargeBatteryicon)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "chargeBatteryicon creation failed");
+            return nullptr;
+        }
+        chargeBatteryicon->SetAutoEnable(false);
+        chargeBatteryicon->SetPosition(progress->GetX() + 5, batteryimage->GetY() + 3, 9, 13);
+        chargeBatteryicon->SetSrc("/user/res/Icon.bin");
+        chargeBatteryicon->SetResizeMode(UIImageView::CONTAIN);
+        chargeBatteryicon->SetVisible(false);
+        group1->Add(chargeBatteryicon);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "chargeBatteryicon add success");
+
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateIndependentStatusBar add success");
+        return group1;
+    }
+
+    void OtaView::UpdateStatusBarDisplay()
+    {
+        if (group1 == nullptr) {
+            return;
+        }
+
+        // 更新时间
+        if (timeLabel != nullptr) {
+            // 获取当前时间
+            std::string currentTime = OtaModel::GetInstance()->GetCurrentTimeString();
+            timeLabel->SetText(currentTime.c_str());
+        }
+
+        // 更新电池信息
+        UpdateBatteryDisplay();
+
+        // 更新信号信息
+        UpdateSignalDisplay();
+    }
+
+    void OtaView::UpdateBatteryDisplay()
+    {
+        if (batteryLabel == nullptr || progress == nullptr || chargeBatteryicon == nullptr) {
+            return;
+        }
+
+        // 获取电池信息
+        int batteryLevel = OtaModel::GetInstance()->GetBatteryLevel();
+        bool isCharging = OtaModel::GetInstance()->IsBatteryCharging();
+
+        // 更新电池电量显示
+        char batteryText[8];
+        snprintf(batteryText, sizeof(batteryText), "%d", batteryLevel);
+        batteryLabel->SetText(batteryText);
+
+        // 更新电池进度条
+        progress->SetValue(batteryLevel);
+
+        // 更新充电图标显示
+        chargeBatteryicon->SetVisible(isCharging);
+    }
+
+    void OtaView::UpdateSignalDisplay()
+    {
+        if (NoSignal == nullptr) {
+            return;
+        }
+
+        // 获取信号强度(范围通常是0-31)
+        int signalStrength = OtaModel::GetInstance()->GetSignalStrength();
+        bool hasSignal = (signalStrength > 0);
+
+        // 更新无信号图标显示
+        NoSignal->SetVisible(!hasSignal);
+
+        // 更新信号强度指示器
+        for (int i = 0; i < 4; i++) {
+            if (showSignalStrength[i] != nullptr) {
+                // 根据信号强度显示对应的信号条
+                // 信号强度范围0-31,分为4个等级:0-7, 8-15, 16-23, 24-31
+                bool showBar = (signalStrength >= (i + 1) * 8);
+                showSignalStrength[i]->SetVisible(hasSignal && showBar);
+            }
+        }
+    }
+
 }
index 4905c89..583351d 100644 (file)
@@ -832,9 +832,9 @@ namespace OHOS
         /* -------------------------------------------------------------------------- */
         // ScrollView_->Add(group1);
         /* -------------------------------------------------------------------------- */
-        //updateSignalDisplay();
+        updateSignalDisplay();
         /* -------------------------------------------------------------------------- */
-        //UpdateBatteryProcess();
+        UpdateBatteryProcess();
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitBaseData add success");
         return group1;
     }
@@ -848,7 +848,7 @@ namespace OHOS
         // 更新网络状态
         ThunderBirdModel::GetInstance()->UpdateNetworkStatus();
         
-        // 从Model获取网络状态信息
+        // 从Model获取网络状态信息  
         int sim = ThunderBirdModel::GetInstance()->GetSimStatus();
         int cat1_powerOn = ThunderBirdModel::GetInstance()->GetCat1PowerStatus();
         int signal = ThunderBirdModel::GetInstance()->GetSignalStrength();