Merge branch 'xts_origin' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230...
authorCaisking <3449750381@qq.com>
Wed, 28 Feb 2024 11:01:40 +0000 (19:01 +0800)
committerCaisking <3449750381@qq.com>
Wed, 28 Feb 2024 11:01:40 +0000 (19:01 +0800)
1  2 
code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenPresenter.cpp

  #include "components/ui_label.h"
  #include "BloodBandoffView.h"
  #include "ChangeSliceListener.h"
 -
 -namespace OHOS {
 -static BloodOxygenPresenter *g_pMainView = nullptr;
 -static constexpr uint16_t PROGRESS_VALUE_MIN = 0;
 -static constexpr uint16_t PROGRESS_VALUE_MAX = 100;
 -
 -BloodOxygenPresenter::BloodOxygenPresenter()
 +#include "broadcast_service.h"
 +#include <fstream>
 +#include "iostream"
 +#include <sstream>
 +#include <string>
 +#include <cstdlib>
 +#include <ctime>
 +#include "wearable_log.h"
 +#include "cmsis_os.h"
 +#include "securec.h"
 +#include "broadcast_service.h"
 +#include "graphic_service.h"
 +#include <chrono>
 +#include <thread>
 +#include "ppg_service.h"
 +
 +namespace OHOS
  {
 -    count = PROGRESS_VALUE_MAX;
 -    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodOxygenPresenter::new BloodOxygenPresenter");
 -    g_pMainView = this;
 -}
 +    static BloodOxygenPresenter *g_pMainView = nullptr;
 +    static constexpr uint16_t PROGRESS_VALUE_MIN = 0;
 +    static constexpr uint16_t PROGRESS_VALUE_MAX = 100;
  
 -BloodOxygenPresenter::~BloodOxygenPresenter()
 -{
 -    if (keyActListenr != nullptr) 
 +    BloodOxygenPresenter::BloodOxygenPresenter()
      {
 -        delete keyActListenr;
 -        keyActListenr = nullptr;
 +        count = PROGRESS_VALUE_MAX;
 +        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodOxygenPresenter::new BloodOxygenPresenter");
 +        g_pMainView = this;
      }
 -    g_pMainView = nullptr;
 -}
  
 -BloodOxygenPresenter* BloodOxygenPresenter::GetInstance()
 -{
 -    return g_pMainView;
 -}
 +    BloodOxygenPresenter::~BloodOxygenPresenter()
 +    {
 +        g_pMainView = nullptr;
 +    }
  
-     BloodOxygenPresenter *BloodOxygenPresenter::GetInstance()
 -void BloodOxygenPresenter::OnStart()
 -{
 -    Presenter<BloodOxygenView>::OnStart();
 -    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodOxygenPresenter::On Start ");
++    BloodOxygenPresenter::~BloodOxygenPresenter()
 +    {
-         return g_pMainView;
++        if (keyActListenr != nullptr)
++        {
++            delete keyActListenr;
++            keyActListenr = nullptr;
++        }
++        g_pMainView = nullptr;
 +    }
  
 -    if (keyActListenr == nullptr) 
 +    void BloodOxygenPresenter::OnStart()
      {
 -        keyActListenr = new KeyInputListener();
 -        if (keyActListenr != nullptr) {
 +        Presenter<BloodOxygenView>::OnStart();
 +        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodOxygenPresenter::On Start ");
++
++        if (keyActListenr == nullptr)
++        {
++            keyActListenr = new KeyInputListener();
++            if (keyActListenr != nullptr)
++            {
+                 RootView::GetInstance()->SetOnKeyActListener(keyActListenr);
 -        } else {
++            }
++            else
++            {
+                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodOxygenPresenter::OnStart: new KeyInputListener fail");
++            }
+         }
      }
 -}
  
 -void BloodOxygenPresenter::OnPause(void) {}
 +    void BloodOxygenPresenter::OnPause(void) {}
  
 -void BloodOxygenPresenter::OnResume(void) {}
 +    void BloodOxygenPresenter::OnResume(void) {}
  
 -void BloodOxygenPresenter::OnStop(void) {}
 +    void BloodOxygenPresenter::OnStop(void) {}
  
 -bool BloodOxygenPresenter::CheckPointersValue()
 -{
 -    if (BloodOxygenView::GetInstance() == nullptr) {
 -        return false;
 -    }
 +    bool BloodOxygenPresenter::CheckPointersValue()
 +    {
 +        if (BloodOxygenView::GetInstance() == nullptr)
 +        {
 +            return false;
 +        }
  
 -    if (BloodBandoffView::GetInstance() == nullptr) {
 -        return false;
 +        if (BloodBandoffView::GetInstance() == nullptr)
 +        {
 +            return false;
 +        }
 +
 +        if (BloodOxygenModel::GetInstance() == nullptr)
 +        {
 +            return false;
 +        }
 +        return true;
      }
  
 -    if (BloodOxygenModel::GetInstance() == nullptr) {
 +    bool BloodOxygenPresenter::OnDrag(UIView &view, const DragEvent &event)
 +    {
 +        UNUSED(view);
 +        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
 +        {
 +            BloodOxygenModel::GetInstance()->SetBloodOxygenViewStatus(false);
 +            BloodOxygenView::GetInstance()->GetTestButton()->SetTouchable(true);
 +            NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST);
 +        }
          return false;
      }
 -    return true;
 -}
  
 -
 -bool BloodOxygenPresenter::OnDrag(UIView& view, const DragEvent& event)
 -{
 -    UNUSED(view);
 -    if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) {
 -        BloodOxygenModel::GetInstance()->SetBloodOxygenViewStatus(false);
 -        BloodOxygenView::GetInstance()->GetTestButton()->SetTouchable(true);
 -        NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST);
 +    bool BloodOxygenPresenter::OnClick(UIView &view, const ClickEvent &event)
 +    {
 +        UNUSED(view);
 +        UNUSED(event);
 +        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodOxygenPresenter::OnClick");
 +        if (CheckPointersValue() == false)
 +        {
 +            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodOxygenPresenter::Pointers is empty");
 +            return false;
 +        }
 +        BloodOxygenView::GetInstance()->GetPercent()->SetText("");
 +        BloodOxygenView::GetInstance()->GetBloodOxygenGroup()->SetVisible(false);
 +        BloodBandoffView::GetInstance()->GetBandoffViewGroup()->SetVisible(true);
 +        BloodBandoffView::GetInstance()->GetImageAnimator()->Stop();
 +#ifdef SUPPORT_SPO2_NOTIFICATION
 +        uint32_t md = PPG_SERVICE_CMD_TYPE_DO_SPO2_TEST;
 +        send_ppg_cmd_msg(md);
 +        // 增加测试时间,大概20秒,测试期间,循环播放
 +        BloodBandoffView::GetInstance()->GetImageAnimator()->SetRepeatTimes(20);
 +#else
 +        BloodBandoffView::GetInstance()->GetImageAnimator()->SetRepeatTimes(1);
 +#endif
 +        BloodBandoffView::GetInstance()->GetImageAnimator()->Start();
 +        BloodOxygenModel::GetInstance()->SetBloodBandoffViewStatus(true);
 +        BloodOxygenView::GetInstance()->GetTestButton()->SetTouchable(false);
 +        return true;
      }
 -    return false;
 -}
 -
  
 -bool BloodOxygenPresenter::OnClick(UIView& view, const ClickEvent& event)
 -{
 -    UNUSED(view);
 -    UNUSED(event);
 -    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodOxygenPresenter::OnClick");
 -    if (CheckPointersValue() == false) {
 -        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodOxygenPresenter::Pointers is empty");
 -        return false;
 -    }
 -    BloodOxygenView::GetInstance()->GetPercent()->SetText("");
 -    BloodOxygenView::GetInstance()->GetBloodOxygenGroup()->SetVisible(false);
 -    BloodBandoffView::GetInstance()->GetBandoffViewGroup()->SetVisible(true);
 -    BloodBandoffView::GetInstance()->GetImageAnimator()->Stop();
 -    BloodBandoffView::GetInstance()->GetImageAnimator()->SetRepeat(false);
 -    BloodBandoffView::GetInstance()->GetImageAnimator()->Start();
 -    BloodOxygenModel::GetInstance()->SetBloodBandoffViewStatus(true);
 -    BloodOxygenView::GetInstance()->GetTestButton()->SetTouchable(false);
 -    return true;
 -}
 -
 -//增加按键事件
 -bool BloodOxygenPresenter::OnKeyAct(UIView& view, const KeyEvent& event)
 -{
 -    WEARABLE_LOGD("","into the view is: %s\n", typeid(view).name());
 -    uint16 keyID = event.GetKeyId();
 -    WEARABLE_LOGD("","into key! keyID %u\n",keyID);
 -    //如果是power键就返回上一级
 -    if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER))
 +    // 增加按键事件
 +    bool BloodOxygenPresenter::OnKeyAct(UIView &view, const KeyEvent &event)
      {
 -        //uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();
 -        NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST);
 -    }
 -    return true;
 -}
 -void BloodOxygenPresenter::ProgressNotify(void)
 -{
 -    if (CheckPointersValue() == false) {
 -        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodOxygenPresenter::Pointers is empty");
 -        return;
 +        WEARABLE_LOGD("", "into the view is: %s\n", typeid(view).name());
 +        uint16 keyID = event.GetKeyId();
 +        WEARABLE_LOGD("", "into key! keyID %u\n", keyID);
 +        // 如果是power键就返回上一级
 +        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER))
 +        {
 +            // uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();
 +            NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST);
 +        }
 +        return true;
      }
 -
 -    if (BloodOxygenModel::GetInstance()->GetBloodOxygenViewStatus() == true) {
 -        count--;
 -        BloodOxygenView::GetInstance()->GetCircleProgress()->SetValue(count);
 -        if (count == PROGRESS_VALUE_MIN) {
 -            BloodOxygenView::GetInstance()->GetPercent()->SetText("98%");
 -            BloodOxygenModel::GetInstance()->SetBloodOxygenViewStatus(false);
 -            count = PROGRESS_VALUE_MAX;
 +    void BloodOxygenPresenter::ProgressNotify(void)
 +    {
 +        if (CheckPointersValue() == false)
 +        {
 +            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodOxygenPresenter::Pointers is empty");
 +            return;
 +        }
 +        if (BloodOxygenModel::GetInstance()->GetBloodOxygenViewStatus() == true)
 +        {
 +            count--;
              BloodOxygenView::GetInstance()->GetCircleProgress()->SetValue(count);
 -            BloodOxygenView::GetInstance()->GetTestButton()->SetTouchable(true);
 +            if (count == PROGRESS_VALUE_MIN)
 +            {
 +                BloodOxygenView::GetInstance()->GetPercent()->SetText("98%");
 +                BloodOxygenModel::GetInstance()->SetBloodOxygenViewStatus(false);
 +                count = PROGRESS_VALUE_MAX;
 +                BloodOxygenView::GetInstance()->GetCircleProgress()->SetValue(count);
 +                BloodOxygenView::GetInstance()->GetTestButton()->SetTouchable(true);
 +            }
          }
      }
 -}
  
 -void BloodOxygenPresenter::ReturnInterface()
 -{
 -    if (BloodOxygenModel::GetInstance()->GetBloodBandoffViewStatus() == true) {
 -        if (BloodBandoffView::GetInstance()->GetImageAnimator()->GetState() == false) {
 -            BloodOxygenModel::GetInstance()->SetBloodBandoffViewStatus(false);
 -            BloodOxygenModel::GetInstance()->SetBloodOxygenViewStatus(true);
 -
 -            BloodBandoffView::GetInstance()->GetBandoffViewGroup()->SetVisible(false);
 -            BloodOxygenView::GetInstance()->GetBloodOxygenGroup()->SetVisible(true);
 +    void BloodOxygenPresenter::ReturnInterface()
 +    {
 +        if (BloodOxygenModel::GetInstance()->GetBloodBandoffViewStatus() == true)
 +        {
 +            if (BloodBandoffView::GetInstance()->GetImageAnimator()->GetState() == false)
 +            {
 +                BloodOxygenModel::GetInstance()->SetBloodBandoffViewStatus(false);
 +                BloodOxygenModel::GetInstance()->SetBloodOxygenViewStatus(true);
 +
 +                BloodBandoffView::GetInstance()->GetBandoffViewGroup()->SetVisible(false);
 +                BloodOxygenView::GetInstance()->GetBloodOxygenGroup()->SetVisible(true);
 +#ifdef SUPPORT_SPO2_NOTIFICATION
 +                uint32_t md = PPG_SERVICE_CMD_TYPE_STOP_SPO2_TEST;
 +                send_ppg_cmd_msg(md);
 +#endif
 +            }
          }
      }
 -}
  
 -void BloodOxygenPresenter::Notify(void)
 -{
 -    ProgressNotify();
 -    ReturnInterface();
 -}
 +    void BloodOxygenPresenter::Notify(void)
 +    {
 +        ProgressNotify();
 +        ReturnInterface();
 +    }
  }