* Create: 2021-10-18
*/
--#include "main/include/MainPresenterSample.h"
--#include "common/task_manager.h"
--#include "heartrate/include/HeartRateView.h"
--#include "player/include/PlayersModel.h"
--#include "player/include/PlayersPresenter.h"
--#include "compass/include/CompassPresenter.h"
--#include "NativeRegisterManager.h"
--#include "compass/include/CompassModel.h"
--#include "compass/include/CompassCalibrationView.h"
--#include "drag_event.h"
--#include "graphic_service.h"
--#include "wearable_log.h"
--#include "UiConfig.h"
--#include "ui_resource_image.h"
--#include <iostream>
--#include <map>
--#include "main/include/dial/ModelDialDataFactory.h"
--#include "main/include/dial/DialModelTime.h"
--#include "main/include/dial/DialModelPower.h"
--#include "heartrate/include/HeartModel.h"
--#include "gfx_utils/mem_check.h"
--#include "custom_utils.h"
--#include "traing/training_card/include/Training_CardView.h"
--#include "dnotdisturb/include/DnotDisturbModel.h"
--#include "weather/include/WeatherModel.h"
--#include "health/health_service/health_service.h"
--#include "sleep/include/SleepControlView.h"
--#include "sleep/include/SleepCardView.h"
--#include "sleep/include/SleepModel.h"
--#include "main/include/MainModel.h"
--#include "custom_runtime.h"
--#include "rebootandshutdown/include/RebootAndShutdownModelC.h"
--
--#if USE_OFFLINE_DIAL
--#include "main/include/MainModel.h"
--#endif
--#include "uiservice/include/ui_service.h"
--#include "time.h"
--#define TESTCHECK 0
--//心率弹窗
--#define HEART_RATE_CHECK_TIMEOUT 0
--
--#include "NativeRegisterManager.h"
--#ifdef SUPPORT_POWER_MANAGER
--#include "power_display_service.h"
--#endif
--
--#include "PageTransitionMgr.h"
--
--extern "C"
--{
--#ifdef SUPPORT_BATTERY_SERVICE
--#include "battery_hal.h"
--#endif
--}
--
--namespace OHOS
--{
--REGIST_SLICE(VIEW_MAIN, MainViewSample, MainPresenterSample);
--
-- std::map<std::string, AppViewId> g_jumpView = {
-- {MAIN_CLICK_BLOOD, VIEW_BLOOD_CHECK}, // 血氧检查
-- {MAIN_CLICK_SETCARD, VIEW_ADD_CARD}, // 卡片管理
-- };
--
-- static MainPresenterSample *g_pMainPresenterSample = nullptr;
--
-- static constexpr uint16_t DROP_X_MAX = 360;
-- static constexpr uint16_t PROGRESS_PERCENTAGE = 100;
-- static constexpr uint16_t HORIZONTAL_SWIPE = 1;
-- static constexpr uint16_t PLAYER_PERIOD = 500;
-- static constexpr uint16_t MAX_PERIOD = 1000;
--
-- MainPresenterSample::MainPresenterSample()
-- {
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample :%p", this);
-- g_pMainPresenterSample = this;
-- }
--
-- MainPresenterSample::~MainPresenterSample()
-- {
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~MainPresenterSample");
-- g_pMainPresenterSample = nullptr;
-- /*从主界面退出,关闭心率检测*/
-- HeartModel::GetInstance()->Heart_Stop();
-- HeartModel::GetInstance()->Heart_Control(HeartState::End,
-- HeartCheck::CARDCHECK);
-- }
--
-- MainPresenterSample *MainPresenterSample::GetInstance(void)
-- {
-- return g_pMainPresenterSample;
-- }
--
-- void MainPresenterSample::OnStart()
-- {
-- mainPresenterState_ = MainPresenterState::START;
-- }
--
-- void MainPresenterSample::OnPause()
-- {
-- // Save watchface content for slide back
-- UIView* watchFace = view_->GetViewById(WATCH_FACE)->GetParent();
-- uint8_t opaScale = watchFace->GetOpaScale();
-- watchFace->SetOpaScale(OPA_OPAQUE);
-- PageTransitionMgr::GetInstance().SaveSlideBackSnapShotIfNecessary(watchFace);
-- watchFace->SetOpaScale(opaScale);
--
-- uint8_t curCardId = view_->GetHorCurrentCard();
-- UICardPage *card = view_->GetViewById(curCardId);
-- if (card != nullptr) {
-- card->OnPause();
-- }
-- mainPresenterState_ = MainPresenterState::PAUSE;
--
-- //进行视频表盘的暂停
-- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "暂停视频") ;
-- // DialSetting &setting = GetDialSetting();
-- // if (setting.dialFlag) {
-- // DialModelTime::GetInstance()->UpdateTime();
-- // dynamic_cast<DialViewGroup *>(view_->GetViewById(WATCH_FACE))->StopDial();
-- // }
-- }
++ #include "main/include/MainPresenterSample.h"
++ #include "common/task_manager.h"
++ #include "heartrate/include/HeartRateView.h"
++ #include "player/include/PlayersModel.h"
++ #include "player/include/PlayersPresenter.h"
++ #include "compass/include/CompassPresenter.h"
++ #include "NativeRegisterManager.h"
++ #include "compass/include/CompassModel.h"
++ #include "compass/include/CompassCalibrationView.h"
++ #include "drag_event.h"
++ #include "graphic_service.h"
++ #include "wearable_log.h"
++ #include "UiConfig.h"
++ #include "ui_resource_image.h"
++ #include <iostream>
++ #include <map>
++ #include "main/include/dial/ModelDialDataFactory.h"
++ #include "main/include/dial/DialModelTime.h"
++ #include "main/include/dial/DialModelPower.h"
++ #include "heartrate/include/HeartModel.h"
++ #include "gfx_utils/mem_check.h"
++ #include "custom_utils.h"
++ #include "traing/training_card/include/Training_CardView.h"
++ #include "dnotdisturb/include/DnotDisturbModel.h"
++ #include "weather/include/WeatherModel.h"
++ #include "health/health_service/health_service.h"
++ #include "sleep/include/SleepControlView.h"
++ #include "sleep/include/SleepCardView.h"
++ #include "sleep/include/SleepModel.h"
++ #include "main/include/MainModel.h"
++ #include "custom_runtime.h"
++ #include "rebootandshutdown/include/RebootAndShutdownModelC.h"
++
++ #if USE_OFFLINE_DIAL
++ #include "main/include/MainModel.h"
++ #endif
++ #include "uiservice/include/ui_service.h"
++ #include "time.h"
++ #define TESTCHECK 0
++ //心率弹窗
++ #define HEART_RATE_CHECK_TIMEOUT 0
++
++ #include "NativeRegisterManager.h"
++ #ifdef SUPPORT_POWER_MANAGER
++ #include "power_display_service.h"
++ #endif
++
++ #include "PageTransitionMgr.h"
++
++ extern "C"
++ {
++ #ifdef SUPPORT_BATTERY_SERVICE
++ #include "battery_hal.h"
++ #endif
++ }
++
++ namespace OHOS
++ {
++ REGIST_SLICE(VIEW_MAIN, MainViewSample, MainPresenterSample);
++
++ std::map<std::string, AppViewId> g_jumpView = {
++ {MAIN_CLICK_BLOOD, VIEW_BLOOD_CHECK}, // 血氧检查
++ {MAIN_CLICK_SETCARD, VIEW_ADD_CARD}, // 卡片管理
++ };
++
++ static MainPresenterSample *g_pMainPresenterSample = nullptr;
++
++ static constexpr uint16_t DROP_X_MAX = 360;
++ static constexpr uint16_t PROGRESS_PERCENTAGE = 100;
++ static constexpr uint16_t HORIZONTAL_SWIPE = 1;
++ static constexpr uint16_t PLAYER_PERIOD = 500;
++ static constexpr uint16_t MAX_PERIOD = 1000;
++
++ MainPresenterSample::MainPresenterSample()
++ {
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample :%p", this);
++ g_pMainPresenterSample = this;
++ }
++
++ MainPresenterSample::~MainPresenterSample()
++ {
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~MainPresenterSample");
++ g_pMainPresenterSample = nullptr;
++ /*从主界面退出,关闭心率检测*/
++ HeartModel::GetInstance()->Heart_Stop();
++ HeartModel::GetInstance()->Heart_Control(HeartState::End,
++ HeartCheck::CARDCHECK);
++ }
++
++ MainPresenterSample *MainPresenterSample::GetInstance(void)
++ {
++ return g_pMainPresenterSample;
++ }
++
++ void MainPresenterSample::OnStart()
++ {
++ mainPresenterState_ = MainPresenterState::START;
++ }
++
++ void MainPresenterSample::OnPause()
++ {
++ // Save watchface content for slide back
++ UIView* watchFace = view_->GetViewById(WATCH_FACE)->GetParent();
++ uint8_t opaScale = watchFace->GetOpaScale();
++ watchFace->SetOpaScale(OPA_OPAQUE);
++ PageTransitionMgr::GetInstance().SaveSlideBackSnapShotIfNecessary(watchFace);
++ watchFace->SetOpaScale(opaScale);
++
++ uint8_t curCardId = view_->GetHorCurrentCard();
++ UICardPage *card = view_->GetViewById(curCardId);
++ if (card != nullptr) {
++ card->OnPause();
++ }
++ mainPresenterState_ = MainPresenterState::PAUSE;
++
++ //进行视频表盘的暂停
++ // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "暂停视频") ;
++ // DialSetting &setting = GetDialSetting();
++ // if (setting.dialFlag) {
++ // DialModelTime::GetInstance()->UpdateTime();
++ // dynamic_cast<DialViewGroup *>(view_->GetViewById(WATCH_FACE))->StopDial();
++ // }
++ }
++
++ void MainPresenterSample::OnResume(void)
++ {
++ mainPresenterState_ = MainPresenterState::RESUME;
++ // Set current page again to invoke OnActive method.
++ uint8_t curCardId = view_->GetHorCurrentCard();
++ view_->SwitchToCard(curCardId);
++ RootView::GetInstance()->SetOnKeyActListener(KeyInputListener::GetInstance());
++
++ #if IS_SUPPORT_BIND_VOTE
++ if (ConfigModel::GetInstance()->GetisFirstTimeStart() == true) {
++ uapi_remove_bind_vote(); //页面已经展示后的调用逻辑。取消绑定投票
++ ConfigModel::GetInstance()->SetisFirstTimeStart(false);
++ }
++ #endif
++ // //进行视频表盘的恢复
++ // DialSetting &setting = GetDialSetting();
++ // if (setting.dialFlag) {
++ // DialModelTime::GetInstance()->UpdateTime();
++ // dynamic_cast<DialViewGroup *>(view_->GetViewById(WATCH_FACE))->StartDial();
++ // }
++ }
++
++ void MainPresenterSample::OnStop(void)
++ {
++ mainPresenterState_ = MainPresenterState::STOP;
++ if (isCompassSensorOpened_) {
++ CompassModel::GetInstance()->CloseCompassSensor();
++ }
++
++ PullUpDown_StopTimer();
++ CloseCompassSensor(); //切换Slice时要关闭指南针传感器
++ }
++
++ MainPresenterState MainPresenterSample::GetMainPresenterState(void)
++ {
++ return mainPresenterState_;
++ }
++
++
-- void MainPresenterSample::OnResume(void)
-- {
-- mainPresenterState_ = MainPresenterState::RESUME;
-- // Set current page again to invoke OnActive method.
-- uint8_t curCardId = view_->GetHorCurrentCard();
-- view_->SwitchToCard(curCardId);
-- RootView::GetInstance()->SetOnKeyActListener(KeyInputListener::GetInstance());
--
-- #if IS_SUPPORT_BIND_VOTE
--if (ConfigModel::GetInstance()->GetisFirstTimeStart() == true) {
-- uapi_remove_bind_vote(); //页面已经展示后的调用逻辑。取消绑定投票
-- ConfigModel::GetInstance()->SetisFirstTimeStart(false);
-- }
--#endif
-- // //进行视频表盘的恢复
-- // DialSetting &setting = GetDialSetting();
-- // if (setting.dialFlag) {
-- // DialModelTime::GetInstance()->UpdateTime();
-- // dynamic_cast<DialViewGroup *>(view_->GetViewById(WATCH_FACE))->StartDial();
-- // }
-- }
--
-- void MainPresenterSample::OnStop(void)
-- {
-- mainPresenterState_ = MainPresenterState::STOP;
-- if (isCompassSensorOpened_) {
-- CompassModel::GetInstance()->CloseCompassSensor();
-- }
--
-- PullUpDown_StopTimer();
-- CloseCompassSensor(); //切换Slice时要关闭指南针传感器
-- }
--
-- MainPresenterState MainPresenterSample::GetMainPresenterState(void)
-- {
-- return mainPresenterState_;
-- }
--
--
--
-- bool MainPresenterSample::OnClick(UIView &view, const ClickEvent &event)
-- {
-- UNUSED(event);
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StatusButtonClickListener: %s", view.GetViewId());
-- std::string curViewId = view.GetViewId();
--
-- UIImageView *imgView = static_cast<UIImageView *>(&view);
-- if (HealthModel::GetInstance() == nullptr)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "health model nullptr");
-- return false;
-- }
--
-- /*发生点击进入密码锁*/
-- if (uapi_dev_runtime_get_lock_status())
-- {
-- /*进入密码锁*/
-- NativeAbility::GetInstance().ChangeSlice(VIEW_CODED_LOCK);
-- return true;
-- }
--
-- if (curViewId == CONNECTEDSTATUSBACKGROUNDBUTTON)
-- {
-- PullUpDownView::GetInstance()->ChangeView(DROPDOWNVIEW, CONNECTEDSTATUSVIEW);
-- PullUpDown_StopTimer(); // 切换到连接状态视图时停止定时器
-- return true;
-- }
-- else if (curViewId == CONNECTEDSTATUSVIEWCLOSEBUTTON)
-- {
-- PullUpDownView::GetInstance()->ChangeView(CONNECTEDSTATUSVIEW, DROPDOWNVIEW);
-- PullUpDown_StartTimer(1000); // 切回下拉控制中心视图开启定时器
-- return true;
-- }
-- // 设置血氧进入
-- else if (curViewId == MAIN_CLICK_BLOOD)
-- {
-- MainModel::GetInstance().SetFromSetCardView(true);
-- MainModel::GetInstance().SetFromCardId(BLOODOXGEN);
-- // 如果正在充电进入提醒界面
-- bool isCharging = false;
-- #ifdef SUPPORT_BATTERY_SERVICE
-- isCharging = get_charge_stat();
-- #endif
-- if (isCharging)
-- {
-- HealthState highHealthState;
-- highHealthState.checkType = CHARGE;
-- HealthService::GetInstance()->SetHealthCurrent(highHealthState);
-- NativeAbility::GetInstance().ChangeSlice(VIEW_CHECK_INVALID, TransitionType::TRANSITION_ZOOM);
-- }
-- }
-- // 设置卡片管理进入
-- if (curViewId == MAIN_CLICK_SETCARD)
-- {
-- MainModel::GetInstance().SetFromSetCardView(true);
-- MainModel::GetInstance().SetFromCardId(SETCARD);
-- }
-- if (g_jumpView.count(curViewId) != 0)
-- {
-- NativeAbility::GetInstance().EnterSlice(g_jumpView[curViewId]);
-- }
-- return true;
-- }
--
-- bool MainPresenterSample::OnLongPress(UIView &view, const LongPressEvent &event)
-- {
-- UNUSED(event);
-- UNUSED(view);
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample OnLongPress");
-- uint8_t cardId = view_->GetHorCurrentCard();
-- /*
-- 卡片进入管理卡片界面
-- if (cardId != WATCH_FACE)
-- {
-- SetCardModel::GetInstance().SetSelectedCard(cardId);
-- NativeAbility::GetInstance().ChangeSlice(VIEW_ADD_CARD);
-- }
-- */
-- if (cardId == WATCH_FACE)
-- {
-- if (uapi_dev_runtime_get_lock_status())
-- {
-- /*进入密码锁*/
-- NativeAbility::GetInstance().ChangeSlice(VIEW_CODED_LOCK);
-- }
-- else
-- {
-- /*进入表盘设置*/
-- NativeAbility::GetInstance().ChangeSlice(VIEW_SET_DIAL);
-- }
-- }
-- return true;
-- }
--
--
-- void MainPresenterSample::SetPage(int8_t id, bool loadAdjacent)
-- {
-- if (view_ != nullptr) {
-- view_->SetPage(id, loadAdjacent);
-- }
-- }
--
-- void MainPresenterSample::SetTaskPeroid(CardId cardId)
-- {
-- SetLastRun(0);
-- if (cardId == COMPASS) {
-- SetPeriod(DEFAULT_TASK_PERIOD);
-- } else if (cardId == WATCH_FACE) {
-- uint32_t time;
-- DialSetting &setting = GetDialSetting();
-- if (setting.dialFlag) {
-- time = dynamic_cast<DialViewGroup*>(view_->GetViewById(WATCH_FACE))->GetPeriod();
-- } else {
-- time = DEFAULT_TASK_PERIOD;
-- }
-- SetPeriod(time);
-- } else if (cardId == MUSIC_PLAYER) {
-- SetPeriod(PLAYER_PERIOD);
-- } else {
-- SetPeriod(MAX_PERIOD);
-- }
-- }
--
-- void MainPresenterSample::OnSwipe(UISwipeView &view)
-- {
-- // UNUSED(view);
-- /* -------------------------------------------------------------------------- */
-- /*
-- * @brief 如果当前是下拉界面,先更新一次下拉窗口的数据包括,电池电量,时间,信号强度等等数据,
-- * 然后开启一个每2秒更新数据的定时器。
-- * 如果不在下拉界面了停止定时器
++ bool MainPresenterSample::OnClick(UIView &view, const ClickEvent &event)
++ {
++ UNUSED(event);
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StatusButtonClickListener: %s", view.GetViewId());
++ std::string curViewId = view.GetViewId();
++
++ UIImageView *imgView = static_cast<UIImageView *>(&view);
++ if (HealthModel::GetInstance() == nullptr)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "health model nullptr");
++ return false;
++ }
++
++ /*发生点击进入密码锁*/
++ if (uapi_dev_runtime_get_lock_status())
++ {
++ /*进入密码锁*/
++ NativeAbility::GetInstance().ChangeSlice(VIEW_CODED_LOCK);
++ return true;
++ }
++
++ if (curViewId == CONNECTEDSTATUSBACKGROUNDBUTTON)
++ {
++ PullUpDownView::GetInstance()->ChangeView(DROPDOWNVIEW, CONNECTEDSTATUSVIEW);
++ PullUpDown_StopTimer(); // 切换到连接状态视图时停止定时器
++ return true;
++ }
++ else if (curViewId == CONNECTEDSTATUSVIEWCLOSEBUTTON)
++ {
++ PullUpDownView::GetInstance()->ChangeView(CONNECTEDSTATUSVIEW, DROPDOWNVIEW);
++ PullUpDown_StartTimer(1000); // 切回下拉控制中心视图开启定时器
++ return true;
++ }
++ // 设置血氧进入
++ else if (curViewId == MAIN_CLICK_BLOOD)
++ {
++ MainModel::GetInstance().SetFromSetCardView(true);
++ MainModel::GetInstance().SetFromCardId(BLOODOXGEN);
++ // 如果正在充电进入提醒界面
++ bool isCharging = false;
++ #ifdef SUPPORT_BATTERY_SERVICE
++ isCharging = get_charge_stat();
++ // 打印充电状态
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "isCharging: %d", isCharging);
++ #endif
++ if (isCharging)
++ {
++ HealthState highHealthState;
++ highHealthState.checkType = CHARGE;
++ HealthService::GetInstance()->SetHealthCurrent(highHealthState);
++ NativeAbility::GetInstance().ChangeSlice(VIEW_CHECK_INVALID, TransitionType::TRANSITION_ZOOM);
++ return true;
++ }
++ }
++ // 设置卡片管理进入
++ if (curViewId == MAIN_CLICK_SETCARD)
++ {
++ MainModel::GetInstance().SetFromSetCardView(true);
++ MainModel::GetInstance().SetFromCardId(SETCARD);
++ }
++ if (g_jumpView.count(curViewId) != 0)
++ {
++ NativeAbility::GetInstance().EnterSlice(g_jumpView[curViewId]);
++ }
++ return true;
++ }
++
++ bool MainPresenterSample::OnLongPress(UIView &view, const LongPressEvent &event)
++ {
++ UNUSED(event);
++ UNUSED(view);
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample OnLongPress");
++ uint8_t cardId = view_->GetHorCurrentCard();
++ /*
++ 卡片进入管理卡片界面
++ if (cardId != WATCH_FACE)
++ {
++ SetCardModel::GetInstance().SetSelectedCard(cardId);
++ NativeAbility::GetInstance().ChangeSlice(VIEW_ADD_CARD);
++ }
*/
-- if (MainViewSample::GetInstance()->IsPullUpViewPage() == PULLUP) {
-- if (!isPullDownPageView) {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开始下拉更新");
-- isPullDownPageView = true;
-- UpdataBaseData();
-- PullUpDownView::GetInstance()->UpdateSignalStrengthStatusAndBatteryPosition();
-- PullUpDown_StartTimer(2000);
-- }
-- } else if (MainViewSample::GetInstance()->IsPullUpViewPage() == DROPDOWN) {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开始上拉更新");
-- isPullDownPageView = false;
-- PullUpDown_StopTimer();
-- } else {
-- isPullDownPageView = false;
-- PullUpDown_StopTimer();
-- }
-- /* -------------------------------------------------------------------------- */
--
-- CardId cardId = view_->GetHorCurrentCard();
-- SetTaskPeroid(cardId);
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnSwipe OnSwipe");
-- return;
-- }
--
-- void MainPresenterSample::ProcessDataNotify(void)
-- {
-- HealthMsg healthMsg;
-- uint16_t len;
--
-- while ((HealthModel::GetInstance()->FetchedHealthData(&healthMsg) == true))
-- {
-- switch (healthMsg.type)
-- {
-- case BATTERY_LIFE:
-- break;
-- default:
-- break;
-- }
-- }
-- }
--
-- void MainPresenterSample::SetCircleProgress()
-- {
-- #if 1
-- PlayersView *playersView = dynamic_cast<PlayersView *>(view_->GetViewById(MUSIC_PLAYER));
-- if (playersView == nullptr)
-- {
-- return;
-- }
-- UICircleProgress *playbackProgress = playersView->GetPlaybackProgress();
-- if (playbackProgress == nullptr)
-- {
-- return;
-- }
-- if(PlayersModel::GetInstance()->GetMusicSource() == false) {
-- int32_t playerState;
-- PlayersModel::GetInstance()->GetPlayerCtr()->GetPlayerState(playerState);
-- state_ = playersView->GetPlayerButtonState();
-- if ((playerState != PLAYER_STARTED) && (state_ == UICheckBox::UICheckBoxState::SELECTED))
-- {
-- playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED);
-- }
-- else if ((playerState == PLAYER_STARTED) && (state_ == UICheckBox::UICheckBoxState::UNSELECTED))
-- {
-- playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED);
-- }
-- }
-- if (state_ == UICheckBox::UICheckBoxState::SELECTED)
-- {
-- PlayersModel::GetInstance()->GetPlayerCtr()->GetCurrentTime(playerCurrentTime_);
-- PlayersModel::GetInstance()->GetDuration(playerMusicDuration_);
-- if (playerMusicDuration_ != 0)
-- {
-- playerProgressValue_ = (playerCurrentTime_ * PROGRESS_PERCENTAGE) / playerMusicDuration_;
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerProgressValue_ %lld", playerProgressValue_);
-- }
-- else
-- {
-- playerProgressValue_ = 100; // 100: max progress value
-- }
-- PlayersModel::GetInstance()->SetCircleProgress(playerProgressValue_);
-- PlayersPresenter::GetInstance()->SetPlaybackProgress(playerProgressValue_);
-- }
-- #endif
-- }
--
-- void MainPresenterSample::SetCompassRotate()
-- {
-- bool status = CompassModel::GetInstance()->GetCalibrationStatus();
-- dynamic_cast<CompassControlView *>(view_->GetViewById(COMPASS))->SetCalibrationView(status);
-- if (!status)
-- {
-- DetermineToRotate();
-- }
-- }
--
-- // 滑动到指南针卡片开启指南针传感器
-- void MainPresenterSample::OpenCompassSensor(void)
-- {
-- if (!isCompassSensorOpened_)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OpenCompassSensor");
-- isCompassSensorOpened_ = true;
-- CompassModel::GetInstance()->OpenCompassSensor();
-- ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); //滑动到指南针页面时开启屏幕常亮
-- }
-- }
-- // 关闭指南针传感器
-- void MainPresenterSample::CloseCompassSensor(void)
-- {
-- if(isCompassSensorOpened_)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CloseCompassSensor");
-- isCompassSensorOpened_ = false;
-- CompassModel::GetInstance()->CloseCompassSensor();
-- ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); //滑动到指南针页面时取消屏幕常亮
-- }
-- }
-- /* --------------------------------- 主界面卡片功能 -------------------------------- */
-- void MainPresenterSample::Notify(void)
-- {
-- CardId currentCardId = view_->GetHorCurrentCard();
--
-- // 从心率卡片变为其他卡片时关闭心率检测
-- if (previousCardId == HEART_RATE && currentCardId != HEART_RATE)
-- {
-- LogCardTransition(previousCardId, currentCardId);
-- HeartModel::GetInstance()->Heart_Stop();
-- HeartModel::GetInstance()->Heart_Control(HeartState::End,HeartCheck::CARDCHECK); //主动检测心率
-- }
-- // 从指南针卡片跳转到其他卡片时切换到关闭长亮屏
-- if (previousCardId == COMPASS && currentCardId != COMPASS)
-- {
-- CloseCompassSensor();
-- }
--
-- // 从睡眠卡片跳转到其他卡片时切换到睡眠卡片主界面
-- if (previousCardId == SLEEP && currentCardId != SLEEP)
-- {
-- LogCardTransition(previousCardId, currentCardId);
-- ResetSleepCardView();
-- }
-- if (previousCardId == WEATHER && currentCardId != WEATHER)
-- {
-- LogCardTransition(previousCardId, currentCardId);
-- ResetWeatherCardView();
-- }
-- if (previousCardId == GOAL && currentCardId != GOAL)
-- {
-- LogCardTransition(previousCardId, currentCardId);
-- ResetgoalCardView();
-- }
--
--
-- // 更新上一个卡片的值
-- previousCardId = currentCardId;
--
-- switch (currentCardId)
-- {
-- case HEART_RATE:
-- StartHeartRateDetection();
-- break;
--
-- case COMPASS:
-- OpenCompassSensor();
-- SetCompassRotate();
-- break;
--
-- case MUSIC_PLAYER:
-- PlayersModel::GetInstance()->SetCircleProgress();
-- break;
--
-- case WATCH_FACE:
-- UpdateWatchFace();
-- break;
--
-- case WEATHER:
-- UpdateWeather();
-- break;
--
-- case GOAL:
-- // Updategoal();
-- break;
--
-- case SLEEP:
-- UpdateSleep();
-- break;
--
-- }
-- }
-- /*打印日志*/
-- void MainPresenterSample::LogCardTransition(CardId previous, CardId current)
-- {
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[MainCard slide]previousCardId:%d cardId:%d", previous, current);
-- }
-- /*睡眠卡片*/
-- void MainPresenterSample::ResetSleepCardView()
-- {
-- if (SleepCardView::GetInstance() != nullptr)
-- {
-- auto sleepCardView = SleepCardView::GetInstance()->GetSleepCardView();
-- if (sleepCardView->GetCurrentPage() != 0)
-- {
-- sleepCardView->SetCurrentPage(0);
-- }
-- }
--
-- // SleepModel::GetInstance().msg_save_sleep_data();
-- }
-- /*天气卡片*/
-- void MainPresenterSample::ResetWeatherCardView()
-- {
-- if(WeatherControlView::GetInstance())
-- {
-- auto weatherSwipView = WeatherControlView::GetInstance()->GetWeatherSwipView();
-- if (weatherSwipView->GetCurrentPage() != 0)
-- {
-- weatherSwipView->SetCurrentPage(0);
-- }
-- }
-- }
-- /*末日目标*/
-- void MainPresenterSample::ResetgoalCardView()
-- {
-- if(goalControlView::GetInstance())
-- {
-- auto goalSwipView = goalControlView::GetInstance()->GetGoalControlSwipView();
-- if (goalSwipView->GetCurrentPage() != 0)
-- {
-- goalSwipView->SetCurrentPage(0);
-- }
-- }
-- }
--
--
-- /*心率卡片*/
-- void MainPresenterSample::StartHeartRateDetection()
-- {
-- HeartModel::GetInstance()->Heart_Control(HeartState::End, HeartCheck::PASSIVITY);
--#if HEART_RATE_CHECK_TIMEOUT
-- HeartModel::GetInstance()->Heart_Control(HeartState::Start,HeartCheck::CARDCHECK);
--#else
-- HeartModel::GetInstance()->Heart_Start(HeartCheck::CARDCHECK);
-- // 更新显示值
-- GraphicService::GetInstance()->PostGraphicEvent(std::bind(&HeartModel::RefreshHeartRateScreen, HeartModel::GetInstance()));
--#endif
-- }
-- /*主表盘*/
-- void MainPresenterSample::UpdateWatchFace()
-- {
-- DialSetting &setting = GetDialSetting();
-- if (setting.dialFlag)
-- {
-- DialModelTime::GetInstance()->UpdateTime();
-- dynamic_cast<DialViewGroup *>(view_->GetViewById(WATCH_FACE))->UpdateViewsByPeriodicUpdateData();
-- }
-- else
-- {
-- dynamic_cast<MainClockView *>(view_->GetViewById(WATCH_FACE))->UpdateTime();
-- }
-- }
--
-- void MainPresenterSample::Updategoal()
-- {
-- if(GoalView::GetInstance())
-- {
-- GoalView::GetInstance()->GoalViewrefresh();
-- }
-- if(GoalotherView::GetInstance())
-- {
-- GoalotherView::GetInstance()->GoalViewrefresh();
-- }
-- }
--
-- /*睡眠*/
-- void MainPresenterSample::UpdateSleep()
-- {
-- GraphicService::GetInstance()->PostGraphicEvent(
-- std::bind(&OHOS::SleepModel::UpdateSleepView, &OHOS::SleepModel::GetInstance()));
-- }
--
-- /*天气*/
-- void MainPresenterSample::UpdateWeather()
-- {
-- if (WeatherModel::GetInstance().GetWeatherDataIsValid())
-- {
-- WeatherModel::GetInstance().UpdateWeatherCurTime();
-- }
-- }
-- /* -------------------------------------------------------------------------- */
-- void MainPresenterSample::InitCardSettings(void)
-- {
-- MainModel::GetInstance().InitCardSettings();
-- }
--
-- uint8_t MainPresenterSample::GetCardSettingCount(void)
-- {
-- return MainModel::GetInstance().GetCardSettingCount();
-- }
--
-- CardId *MainPresenterSample::GetCardSettings(void)
-- {
-- return MainModel::GetInstance().GetCardSettings();
-- }
--
-- void MainPresenterSample::InitDialSettings(void)
-- {
-- return MainModel::GetInstance().InitDialSettings();
-- }
-- DialSetting &MainPresenterSample::GetDialSetting()
-- {
-- return MainModel::GetInstance().GetDialSetting();
-- }
--
-- static const char *weekDays_ch[] = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
-- static const char *weekDays_other[] = {"Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat"};
-- uint32_t MainPresenterSample::GetWeekStr(char *p_week)
-- {
-- time_t currtime;
-- struct tm *timeinfo;
-- time(&currtime);
-- timeinfo = localtime(&currtime);
--
-- // 获取星期信息
-- int language = ConfigModel::GetInstance()->GetLanguage();
-- if (language == 0)
-- {
-- strcpy(p_week, weekDays_ch[timeinfo->tm_wday]);
-- }
-- else
-- {
-- strcpy(p_week, weekDays_other[timeinfo->tm_wday]);
-- }
--
-- return ERRCODE_SUCC; // 假设成功获取星期信息
-- }
--
--
--
-- void MainPresenterSample::UpdataBaseData()
-- {
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::UpdataBaseData");
-- // 解析日期信息
-- char *dateStr = (char *)malloc(9);
-- if (uapi_get_YYMMDD_Time(dateStr, '/') != ERRCODE_SUCC)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get start date");
-- free(dateStr);
-- return;
-- }
-- // 获取当前时间
-- char *timeStr = (char *)malloc(9);
-- if (uapi_get_HHMMSS_Time(timeStr, ':', false) != ERRCODE_SUCC)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get start time");
-- free(dateStr);
-- free(timeStr);
-- return;
-- }
-- // 解析星期信息
-- char *weekStr = (char *)malloc(10);
-- if (GetWeekStr(weekStr) != ERRCODE_SUCC)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get week information");
-- free(dateStr);
-- free(timeStr);
-- free(weekStr);
-- return;
-- }
--
-- // 获取电池电量信息
-- float voltage = 0.0F;
-- uint8_t value = 0;
-- #ifdef SUPPORT_BATTERY_SERVICE
-- value = battery_get_voltage(&voltage);
-- #endif
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "battery_get_voltage = %d", value);
-- std::string dateAndweek = std::string(dateStr) + " " + std::string(weekStr);
-- if (PullUpDownView::GetInstance() != nullptr)
-- {
-- PullUpDownView::GetInstance()->GetProgress()->SetValue(value);
-- PullUpDownView::GetInstance()->GetDateAndWeekLabel()->SetText(dateAndweek.c_str());
-- }
--
-- // 释放动态分配的内存
-- free(dateStr);
-- free(timeStr);
-- free(weekStr);
--
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ALLData are refresh!\n");
-- }
-- void MainPresenterSample::get_memcheck()
-- {
-- MemCheck::GetInstance()->DumpMemInfo();
-- }
-- /* -------------------------------------------------------------------------- */
-- // 声明定时器变量
-- static osTimerId_t g_timer = nullptr;
-- static uint8_t UPDATETIME = 20; // 20秒
-- uint8_t MainPresenterSample::g_PullUpDownTimes = UPDATETIME;
--
-- /*定时器到期时的处理*/
-- static void PullUpDown_TimerCallbackProc(int data)
-- {
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDown_TimerCallbackProc");
-- if (uapi_get_screen_state() == 1) // 息屏状态下若停留在下拉界面,20s后无操作停止更新数据
-- {
-- MainPresenterSample::g_PullUpDownTimes -= 2;
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "%d", MainPresenterSample::g_PullUpDownTimes);
-- if (MainPresenterSample::g_PullUpDownTimes <= 0) {
-- GraphicService::GetInstance()->PostGraphicEvent(std::bind(&MainPresenterSample::PullUpDown_StopTimer, MainPresenterSample::GetInstance()));
-- }
-- }
-- else //亮屏状态下每2s刷新一次下拉数据
-- {
-- if (PullUpDownView::GetInstance() != nullptr)
-- {
-- PullUpDownView::GetInstance()->UpdateSignalStrengthStatusAndBatteryPosition();
-- }
-- if (MainPresenterSample::g_PullUpDownTimes != UPDATETIME) // 如果是亮屏后息屏再亮屏(此时息屏时间没超过 UPDATETIME)则恢复
-- MainPresenterSample::g_PullUpDownTimes = UPDATETIME;
-- }
-- return;
-- }
--
-- /*
-- * @brief 回调函数
-- */
-- static void PullUpDown_TimerCallback(int data)
-- {
-- GraphicService::GetInstance()->PostGraphicEvent(std::bind(PullUpDown_TimerCallbackProc, data));
-- }
--
-- /*
-- * @brief 开启定时器函数
-- * @param interval 时间间隔,单位ms
-- */
-- void MainPresenterSample::PullUpDown_StartTimer(uint32_t interval)
-- {
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StartTimer");
-- /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */
-- if (g_timer != nullptr)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StartTimer Timer already exists!!");
-- return;
-- }
--
-- /* --------------------------------- 2.创建定时器 -------------------------------- */
-- g_timer = osTimerNew((osTimerFunc_t)PullUpDown_TimerCallback, osTimerPeriodic, nullptr, nullptr);
-- // 检查定时器创建是否成功
-- if (g_timer == nullptr)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StartTimer Timer create failed!!");
-- return;
-- }
--
-- /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */
-- int tick = osMs2Tick(interval);
-- /* --------------------------------- 4.启动定时器 -------------------------------- */
-- osStatus_t ret = osTimerStart(g_timer, tick);
-- /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */
-- if (ret != osOK)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[PullUpDown_StartTimer] osTimerDelete failed, ret = %lx!!", ret);
-- if (g_timer != nullptr)
-- {
-- ret = osTimerDelete(g_timer);
-- }
-- g_timer = nullptr;
-- return;
-- }
-- return;
-- }
--
-- /*
-- * @brief 停止定时器
-- */
-- void MainPresenterSample::PullUpDown_StopTimer(void)
-- {
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StopTimer");
-- // 检查定时器是否存在
-- if (g_timer != nullptr)
-- {
-- osTimerStop(g_timer);
-- // 删除定时器并置为 nullptr
-- osStatus_t ret = osTimerDelete(g_timer);
-- if (ret != osOK)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
-- }
-- g_timer = nullptr;
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "g_timer stop success");
-- }
-- }
--
-- bool MainPresenterSample::IsFromSetCardView(void) const
-- {
-- return MainModel::GetInstance().IsFromSetCardView();
-- }
--
-- void MainPresenterSample::SetFromSetCardView(bool isFrom)
-- {
-- MainModel::GetInstance().SetFromSetCardView(isFrom);
-- }
--
-- uint8_t MainPresenterSample::GetFromCardId(void)
-- {
-- return MainModel::GetInstance().GetFromCardId();
-- }
--
--}
++ if (cardId == WATCH_FACE)
++ {
++ if (uapi_dev_runtime_get_lock_status())
++ {
++ /*进入密码锁*/
++ NativeAbility::GetInstance().ChangeSlice(VIEW_CODED_LOCK);
++ }
++ else
++ {
++ /*进入表盘设置*/
++ NativeAbility::GetInstance().ChangeSlice(VIEW_SET_DIAL);
++ }
++ }
++ return true;
++ }
++
++
++ void MainPresenterSample::SetPage(int8_t id, bool loadAdjacent)
++ {
++ if (view_ != nullptr) {
++ view_->SetPage(id, loadAdjacent);
++ }
++ }
++
++ void MainPresenterSample::SetTaskPeroid(CardId cardId)
++ {
++ SetLastRun(0);
++ if (cardId == COMPASS) {
++ SetPeriod(DEFAULT_TASK_PERIOD);
++ } else if (cardId == WATCH_FACE) {
++ uint32_t time;
++ DialSetting &setting = GetDialSetting();
++ if (setting.dialFlag) {
++ time = dynamic_cast<DialViewGroup*>(view_->GetViewById(WATCH_FACE))->GetPeriod();
++ } else {
++ time = DEFAULT_TASK_PERIOD;
++ }
++ SetPeriod(time);
++ } else if (cardId == MUSIC_PLAYER) {
++ SetPeriod(PLAYER_PERIOD);
++ } else {
++ SetPeriod(MAX_PERIOD);
++ }
++ }
++
++ void MainPresenterSample::OnSwipe(UISwipeView &view)
++ {
++ // UNUSED(view);
++ /* -------------------------------------------------------------------------- */
++ /*
++ * @brief 如果当前是下拉界面,先更新一次下拉窗口的数据包括,电池电量,时间,信号强度等等数据,
++ * 然后开启一个每2秒更新数据的定时器。
++ * 如果不在下拉界面了停止定时器
++ */
++ if (MainViewSample::GetInstance()->IsPullUpViewPage() == PULLUP) {
++ if (!isPullDownPageView) {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开始下拉更新");
++ isPullDownPageView = true;
++ UpdataBaseData();
++ PullUpDownView::GetInstance()->UpdateSignalStrengthStatusAndBatteryPosition();
++ PullUpDown_StartTimer(2000);
++ }
++ } else if (MainViewSample::GetInstance()->IsPullUpViewPage() == DROPDOWN) {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开始上拉更新");
++ isPullDownPageView = false;
++ PullUpDown_StopTimer();
++ } else {
++ isPullDownPageView = false;
++ PullUpDown_StopTimer();
++ }
++ /* -------------------------------------------------------------------------- */
++
++ CardId cardId = view_->GetHorCurrentCard();
++ SetTaskPeroid(cardId);
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnSwipe OnSwipe");
++ return;
++ }
++
++ void MainPresenterSample::ProcessDataNotify(void)
++ {
++ HealthMsg healthMsg;
++ uint16_t len;
++
++ while ((HealthModel::GetInstance()->FetchedHealthData(&healthMsg) == true))
++ {
++ switch (healthMsg.type)
++ {
++ case BATTERY_LIFE:
++ break;
++ default:
++ break;
++ }
++ }
++ }
++
++ void MainPresenterSample::SetCircleProgress()
++ {
++ #if 1
++ PlayersView *playersView = dynamic_cast<PlayersView *>(view_->GetViewById(MUSIC_PLAYER));
++ if (playersView == nullptr)
++ {
++ return;
++ }
++ UICircleProgress *playbackProgress = playersView->GetPlaybackProgress();
++ if (playbackProgress == nullptr)
++ {
++ return;
++ }
++ if(PlayersModel::GetInstance()->GetMusicSource() == false) {
++ int32_t playerState;
++ PlayersModel::GetInstance()->GetPlayerCtr()->GetPlayerState(playerState);
++ state_ = playersView->GetPlayerButtonState();
++ if ((playerState != PLAYER_STARTED) && (state_ == UICheckBox::UICheckBoxState::SELECTED))
++ {
++ playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED);
++ }
++ else if ((playerState == PLAYER_STARTED) && (state_ == UICheckBox::UICheckBoxState::UNSELECTED))
++ {
++ playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED);
++ }
++ }
++ if (state_ == UICheckBox::UICheckBoxState::SELECTED)
++ {
++ PlayersModel::GetInstance()->GetPlayerCtr()->GetCurrentTime(playerCurrentTime_);
++ PlayersModel::GetInstance()->GetDuration(playerMusicDuration_);
++ if (playerMusicDuration_ != 0)
++ {
++ playerProgressValue_ = (playerCurrentTime_ * PROGRESS_PERCENTAGE) / playerMusicDuration_;
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerProgressValue_ %lld", playerProgressValue_);
++ }
++ else
++ {
++ playerProgressValue_ = 100; // 100: max progress value
++ }
++ PlayersModel::GetInstance()->SetCircleProgress(playerProgressValue_);
++ PlayersPresenter::GetInstance()->SetPlaybackProgress(playerProgressValue_);
++ }
++ #endif
++ }
++
++ void MainPresenterSample::SetCompassRotate()
++ {
++ bool status = CompassModel::GetInstance()->GetCalibrationStatus();
++ dynamic_cast<CompassControlView *>(view_->GetViewById(COMPASS))->SetCalibrationView(status);
++ if (!status)
++ {
++ DetermineToRotate();
++ }
++ }
++
++ // 滑动到指南针卡片开启指南针传感器
++ void MainPresenterSample::OpenCompassSensor(void)
++ {
++ if (!isCompassSensorOpened_)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OpenCompassSensor");
++ isCompassSensorOpened_ = true;
++ CompassModel::GetInstance()->OpenCompassSensor();
++ ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); //滑动到指南针页面时开启屏幕常亮
++ }
++ }
++ // 关闭指南针传感器
++ void MainPresenterSample::CloseCompassSensor(void)
++ {
++ if(isCompassSensorOpened_)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CloseCompassSensor");
++ isCompassSensorOpened_ = false;
++ CompassModel::GetInstance()->CloseCompassSensor();
++ ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); //滑动到指南针页面时取消屏幕常亮
++ }
++ }
++ /* --------------------------------- 主界面卡片功能 -------------------------------- */
++ void MainPresenterSample::Notify(void)
++ {
++ CardId currentCardId = view_->GetHorCurrentCard();
++
++ // 从心率卡片变为其他卡片时关闭心率检测
++ if (previousCardId == HEART_RATE && currentCardId != HEART_RATE)
++ {
++ LogCardTransition(previousCardId, currentCardId);
++ HeartModel::GetInstance()->Heart_Stop();
++ HeartModel::GetInstance()->Heart_Control(HeartState::End,HeartCheck::CARDCHECK); //主动检测心率
++ }
++ // 从指南针卡片跳转到其他卡片时切换到关闭长亮屏
++ if (previousCardId == COMPASS && currentCardId != COMPASS)
++ {
++ CloseCompassSensor();
++ }
++
++ // 从睡眠卡片跳转到其他卡片时切换到睡眠卡片主界面
++ if (previousCardId == SLEEP && currentCardId != SLEEP)
++ {
++ LogCardTransition(previousCardId, currentCardId);
++ ResetSleepCardView();
++ }
++ if (previousCardId == WEATHER && currentCardId != WEATHER)
++ {
++ LogCardTransition(previousCardId, currentCardId);
++ ResetWeatherCardView();
++ }
++ if (previousCardId == GOAL && currentCardId != GOAL)
++ {
++ LogCardTransition(previousCardId, currentCardId);
++ ResetgoalCardView();
++ }
++
++
++ // 更新上一个卡片的值
++ previousCardId = currentCardId;
++
++ switch (currentCardId)
++ {
++ case HEART_RATE:
++ StartHeartRateDetection();
++ break;
++
++ case COMPASS:
++ OpenCompassSensor();
++ SetCompassRotate();
++ break;
++
++ case MUSIC_PLAYER:
++ PlayersModel::GetInstance()->SetCircleProgress();
++ break;
++
++ case WATCH_FACE:
++ UpdateWatchFace();
++ break;
++
++ case WEATHER:
++ UpdateWeather();
++ break;
++
++ case GOAL:
++ // Updategoal();
++ break;
++
++ case SLEEP:
++ UpdateSleep();
++ break;
++
++ }
++ }
++ /*打印日志*/
++ void MainPresenterSample::LogCardTransition(CardId previous, CardId current)
++ {
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[MainCard slide]previousCardId:%d cardId:%d", previous, current);
++ }
++ /*睡眠卡片*/
++ void MainPresenterSample::ResetSleepCardView()
++ {
++ if (SleepCardView::GetInstance() != nullptr)
++ {
++ auto sleepCardView = SleepCardView::GetInstance()->GetSleepCardView();
++ if (sleepCardView->GetCurrentPage() != 0)
++ {
++ sleepCardView->SetCurrentPage(0);
++ }
++ }
++
++ // SleepModel::GetInstance().msg_save_sleep_data();
++ }
++ /*天气卡片*/
++ void MainPresenterSample::ResetWeatherCardView()
++ {
++ if(WeatherControlView::GetInstance())
++ {
++ auto weatherSwipView = WeatherControlView::GetInstance()->GetWeatherSwipView();
++ if (weatherSwipView->GetCurrentPage() != 0)
++ {
++ weatherSwipView->SetCurrentPage(0);
++ }
++ }
++ }
++ /*末日目标*/
++ void MainPresenterSample::ResetgoalCardView()
++ {
++ if(goalControlView::GetInstance())
++ {
++ auto goalSwipView = goalControlView::GetInstance()->GetGoalControlSwipView();
++ if (goalSwipView->GetCurrentPage() != 0)
++ {
++ goalSwipView->SetCurrentPage(0);
++ }
++ }
++ }
++
++
++ /*心率卡片*/
++ void MainPresenterSample::StartHeartRateDetection()
++ {
++ HeartModel::GetInstance()->Heart_Control(HeartState::End, HeartCheck::PASSIVITY);
++ #if HEART_RATE_CHECK_TIMEOUT
++ HeartModel::GetInstance()->Heart_Control(HeartState::Start,HeartCheck::CARDCHECK);
++ #else
++ HeartModel::GetInstance()->Heart_Start(HeartCheck::CARDCHECK);
++ // 更新显示值
++ GraphicService::GetInstance()->PostGraphicEvent(std::bind(&HeartModel::RefreshHeartRateScreen, HeartModel::GetInstance()));
++ #endif
++ }
++ /*主表盘*/
++ void MainPresenterSample::UpdateWatchFace()
++ {
++ DialSetting &setting = GetDialSetting();
++ if (setting.dialFlag)
++ {
++ DialModelTime::GetInstance()->UpdateTime();
++ dynamic_cast<DialViewGroup *>(view_->GetViewById(WATCH_FACE))->UpdateViewsByPeriodicUpdateData();
++ }
++ else
++ {
++ dynamic_cast<MainClockView *>(view_->GetViewById(WATCH_FACE))->UpdateTime();
++ }
++ }
++
++ void MainPresenterSample::Updategoal()
++ {
++ if(GoalView::GetInstance())
++ {
++ GoalView::GetInstance()->GoalViewrefresh();
++ }
++ if(GoalotherView::GetInstance())
++ {
++ GoalotherView::GetInstance()->GoalViewrefresh();
++ }
++ }
++
++ /*睡眠*/
++ void MainPresenterSample::UpdateSleep()
++ {
++ GraphicService::GetInstance()->PostGraphicEvent(
++ std::bind(&OHOS::SleepModel::UpdateSleepView, &OHOS::SleepModel::GetInstance()));
++ }
++
++ /*天气*/
++ void MainPresenterSample::UpdateWeather()
++ {
++ if (WeatherModel::GetInstance().GetWeatherDataIsValid())
++ {
++ WeatherModel::GetInstance().UpdateWeatherCurTime();
++ }
++ }
++ /* -------------------------------------------------------------------------- */
++ void MainPresenterSample::InitCardSettings(void)
++ {
++ MainModel::GetInstance().InitCardSettings();
++ }
++
++ uint8_t MainPresenterSample::GetCardSettingCount(void)
++ {
++ return MainModel::GetInstance().GetCardSettingCount();
++ }
++
++ CardId *MainPresenterSample::GetCardSettings(void)
++ {
++ return MainModel::GetInstance().GetCardSettings();
++ }
++
++ void MainPresenterSample::InitDialSettings(void)
++ {
++ return MainModel::GetInstance().InitDialSettings();
++ }
++ DialSetting &MainPresenterSample::GetDialSetting()
++ {
++ return MainModel::GetInstance().GetDialSetting();
++ }
++
++ static const char *weekDays_ch[] = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
++ static const char *weekDays_other[] = {"Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat"};
++ uint32_t MainPresenterSample::GetWeekStr(char *p_week)
++ {
++ time_t currtime;
++ struct tm *timeinfo;
++ time(&currtime);
++ timeinfo = localtime(&currtime);
++
++ // 获取星期信息
++ int language = ConfigModel::GetInstance()->GetLanguage();
++ if (language == 0)
++ {
++ strcpy(p_week, weekDays_ch[timeinfo->tm_wday]);
++ }
++ else
++ {
++ strcpy(p_week, weekDays_other[timeinfo->tm_wday]);
++ }
++
++ return ERRCODE_SUCC; // 假设成功获取星期信息
++ }
++
++
++
++ void MainPresenterSample::UpdataBaseData()
++ {
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::UpdataBaseData");
++ // 解析日期信息
++ char *dateStr = (char *)malloc(9);
++ if (uapi_get_YYMMDD_Time(dateStr, '/') != ERRCODE_SUCC)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get start date");
++ free(dateStr);
++ return;
++ }
++ // 获取当前时间
++ char *timeStr = (char *)malloc(9);
++ if (uapi_get_HHMMSS_Time(timeStr, ':', false) != ERRCODE_SUCC)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get start time");
++ free(dateStr);
++ free(timeStr);
++ return;
++ }
++ // 解析星期信息
++ char *weekStr = (char *)malloc(10);
++ if (GetWeekStr(weekStr) != ERRCODE_SUCC)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get week information");
++ free(dateStr);
++ free(timeStr);
++ free(weekStr);
++ return;
++ }
++
++ // 获取电池电量信息
++ float voltage = 0.0F;
++ uint8_t value = 0;
++ #ifdef SUPPORT_BATTERY_SERVICE
++ value = battery_get_voltage(&voltage);
++ #endif
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "battery_get_voltage = %d", value);
++ std::string dateAndweek = std::string(dateStr) + " " + std::string(weekStr);
++ if (PullUpDownView::GetInstance() != nullptr)
++ {
++ PullUpDownView::GetInstance()->GetProgress()->SetValue(value);
++ PullUpDownView::GetInstance()->GetDateAndWeekLabel()->SetText(dateAndweek.c_str());
++ }
++
++ // 释放动态分配的内存
++ free(dateStr);
++ free(timeStr);
++ free(weekStr);
++
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ALLData are refresh!\n");
++ }
++ void MainPresenterSample::get_memcheck()
++ {
++ MemCheck::GetInstance()->DumpMemInfo();
++ }
++ /* -------------------------------------------------------------------------- */
++ // 声明定时器变量
++ static osTimerId_t g_timer = nullptr;
++ static uint8_t UPDATETIME = 20; // 20秒
++ uint8_t MainPresenterSample::g_PullUpDownTimes = UPDATETIME;
++
++ /*定时器到期时的处理*/
++ static void PullUpDown_TimerCallbackProc(int data)
++ {
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDown_TimerCallbackProc");
++ if (uapi_get_screen_state() == 1) // 息屏状态下若停留在下拉界面,20s后无操作停止更新数据
++ {
++ MainPresenterSample::g_PullUpDownTimes -= 2;
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "%d", MainPresenterSample::g_PullUpDownTimes);
++ if (MainPresenterSample::g_PullUpDownTimes <= 0) {
++ GraphicService::GetInstance()->PostGraphicEvent(std::bind(&MainPresenterSample::PullUpDown_StopTimer, MainPresenterSample::GetInstance()));
++ }
++ }
++ else //亮屏状态下每2s刷新一次下拉数据
++ {
++ if (PullUpDownView::GetInstance() != nullptr)
++ {
++ PullUpDownView::GetInstance()->UpdateSignalStrengthStatusAndBatteryPosition();
++ }
++ if (MainPresenterSample::g_PullUpDownTimes != UPDATETIME) // 如果是亮屏后息屏再亮屏(此时息屏时间没超过 UPDATETIME)则恢复
++ MainPresenterSample::g_PullUpDownTimes = UPDATETIME;
++ }
++ return;
++ }
++
++ /*
++ * @brief 回调函数
++ */
++ static void PullUpDown_TimerCallback(int data)
++ {
++ GraphicService::GetInstance()->PostGraphicEvent(std::bind(PullUpDown_TimerCallbackProc, data));
++ }
++
++ /*
++ * @brief 开启定时器函数
++ * @param interval 时间间隔,单位ms
++ */
++ void MainPresenterSample::PullUpDown_StartTimer(uint32_t interval)
++ {
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StartTimer");
++ /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */
++ if (g_timer != nullptr)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StartTimer Timer already exists!!");
++ return;
++ }
++
++ /* --------------------------------- 2.创建定时器 -------------------------------- */
++ g_timer = osTimerNew((osTimerFunc_t)PullUpDown_TimerCallback, osTimerPeriodic, nullptr, nullptr);
++ // 检查定时器创建是否成功
++ if (g_timer == nullptr)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StartTimer Timer create failed!!");
++ return;
++ }
++
++ /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */
++ int tick = osMs2Tick(interval);
++ /* --------------------------------- 4.启动定时器 -------------------------------- */
++ osStatus_t ret = osTimerStart(g_timer, tick);
++ /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */
++ if (ret != osOK)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[PullUpDown_StartTimer] osTimerDelete failed, ret = %lx!!", ret);
++ if (g_timer != nullptr)
++ {
++ ret = osTimerDelete(g_timer);
++ }
++ g_timer = nullptr;
++ return;
++ }
++ return;
++ }
++
++ /*
++ * @brief 停止定时器
++ */
++ void MainPresenterSample::PullUpDown_StopTimer(void)
++ {
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StopTimer");
++ // 检查定时器是否存在
++ if (g_timer != nullptr)
++ {
++ osTimerStop(g_timer);
++ // 删除定时器并置为 nullptr
++ osStatus_t ret = osTimerDelete(g_timer);
++ if (ret != osOK)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
++ }
++ g_timer = nullptr;
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "g_timer stop success");
++ }
++ }
++
++ bool MainPresenterSample::IsFromSetCardView(void) const
++ {
++ return MainModel::GetInstance().IsFromSetCardView();
++ }
++
++ void MainPresenterSample::SetFromSetCardView(bool isFrom)
++ {
++ MainModel::GetInstance().SetFromSetCardView(isFrom);
++ }
++
++ uint8_t MainPresenterSample::GetFromCardId(void)
++ {
++ return MainModel::GetInstance().GetFromCardId();
++ }
++
++ }
++
* Create: 2021-10-18
*/
--#include "main/include/MainPresenterSample.h"
--#include "common/task_manager.h"
--#include "heartrate/include/HeartRateView.h"
--#include "player/include/PlayersModel.h"
--#include "player/include/PlayersPresenter.h"
--#include "compass/include/CompassPresenter.h"
--#include "NativeRegisterManager.h"
--#include "compass/include/CompassModel.h"
--#include "compass/include/CompassCalibrationView.h"
--#include "drag_event.h"
--#include "graphic_service.h"
--#include "wearable_log.h"
--#include "UiConfig.h"
--#include "ui_resource_image.h"
--#include <iostream>
--#include <map>
--#include "main/include/dial/ModelDialDataFactory.h"
--#include "main/include/dial/DialModelTime.h"
--#include "main/include/dial/DialModelPower.h"
--#include "heartrate/include/HeartModel.h"
--#include "gfx_utils/mem_check.h"
--#include "custom_utils.h"
--#include "traing/training_card/include/Training_CardView.h"
--#include "dnotdisturb/include/DnotDisturbModel.h"
--#include "weather/include/WeatherModel.h"
--#include "health/health_service/health_service.h"
--#include "sleep/include/SleepControlView.h"
--#include "sleep/include/SleepCardView.h"
--#include "sleep/include/SleepModel.h"
--#include "main/include/MainModel.h"
--#include "custom_runtime.h"
--#include "rebootandshutdown/include/RebootAndShutdownModelC.h"
--
--#if USE_OFFLINE_DIAL
--#include "main/include/MainModel.h"
--#endif
--#include "uiservice/include/ui_service.h"
--#include "time.h"
--#define TESTCHECK 0
--//心率弹窗
--#define HEART_RATE_CHECK_TIMEOUT 0
--
--#include "NativeRegisterManager.h"
--#ifdef SUPPORT_POWER_MANAGER
--#include "power_display_service.h"
--#endif
--
--#include "PageTransitionMgr.h"
--
--extern "C"
--{
--#ifdef SUPPORT_BATTERY_SERVICE
--#include "battery_hal.h"
--#endif
--}
--
--namespace OHOS
--{
--REGIST_SLICE(VIEW_MAIN, MainViewSample, MainPresenterSample);
--
-- std::map<std::string, AppViewId> g_jumpView = {
-- {MAIN_CLICK_BLOOD, VIEW_BLOOD_CHECK}, // 血氧检查
-- {MAIN_CLICK_SETCARD, VIEW_ADD_CARD}, // 卡片管理
-- };
--
-- static MainPresenterSample *g_pMainPresenterSample = nullptr;
--
-- static constexpr uint16_t DROP_X_MAX = 360;
-- static constexpr uint16_t PROGRESS_PERCENTAGE = 100;
-- static constexpr uint16_t HORIZONTAL_SWIPE = 1;
-- static constexpr uint16_t PLAYER_PERIOD = 500;
-- static constexpr uint16_t MAX_PERIOD = 1000;
--
-- MainPresenterSample::MainPresenterSample()
-- {
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample :%p", this);
-- g_pMainPresenterSample = this;
-- }
--
-- MainPresenterSample::~MainPresenterSample()
-- {
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~MainPresenterSample");
-- g_pMainPresenterSample = nullptr;
-- /*从主界面退出,关闭心率检测*/
-- HeartModel::GetInstance()->Heart_Stop();
-- HeartModel::GetInstance()->Heart_Control(HeartState::End,
-- HeartCheck::CARDCHECK);
-- }
--
-- MainPresenterSample *MainPresenterSample::GetInstance(void)
-- {
-- return g_pMainPresenterSample;
-- }
--
-- void MainPresenterSample::OnStart()
-- {
-- mainPresenterState_ = MainPresenterState::START;
-- }
--
-- void MainPresenterSample::OnPause()
-- {
-- // Save watchface content for slide back
-- UIView* watchFace = view_->GetViewById(WATCH_FACE)->GetParent();
-- uint8_t opaScale = watchFace->GetOpaScale();
-- watchFace->SetOpaScale(OPA_OPAQUE);
-- PageTransitionMgr::GetInstance().SaveSlideBackSnapShotIfNecessary(watchFace);
-- watchFace->SetOpaScale(opaScale);
--
-- uint8_t curCardId = view_->GetHorCurrentCard();
-- UICardPage *card = view_->GetViewById(curCardId);
-- if (card != nullptr) {
-- card->OnPause();
-- }
-- mainPresenterState_ = MainPresenterState::PAUSE;
--
-- //进行视频表盘的暂停
-- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "暂停视频") ;
-- // DialSetting &setting = GetDialSetting();
-- // if (setting.dialFlag) {
-- // DialModelTime::GetInstance()->UpdateTime();
-- // dynamic_cast<DialViewGroup *>(view_->GetViewById(WATCH_FACE))->StopDial();
-- // }
-- }
++ #include "main/include/MainPresenterSample.h"
++ #include "common/task_manager.h"
++ #include "heartrate/include/HeartRateView.h"
++ #include "player/include/PlayersModel.h"
++ #include "player/include/PlayersPresenter.h"
++ #include "compass/include/CompassPresenter.h"
++ #include "NativeRegisterManager.h"
++ #include "compass/include/CompassModel.h"
++ #include "compass/include/CompassCalibrationView.h"
++ #include "drag_event.h"
++ #include "graphic_service.h"
++ #include "wearable_log.h"
++ #include "UiConfig.h"
++ #include "ui_resource_image.h"
++ #include <iostream>
++ #include <map>
++ #include "main/include/dial/ModelDialDataFactory.h"
++ #include "main/include/dial/DialModelTime.h"
++ #include "main/include/dial/DialModelPower.h"
++ #include "heartrate/include/HeartModel.h"
++ #include "gfx_utils/mem_check.h"
++ #include "custom_utils.h"
++ #include "traing/training_card/include/Training_CardView.h"
++ #include "dnotdisturb/include/DnotDisturbModel.h"
++ #include "weather/include/WeatherModel.h"
++ #include "health/health_service/health_service.h"
++ #include "sleep/include/SleepControlView.h"
++ #include "sleep/include/SleepCardView.h"
++ #include "sleep/include/SleepModel.h"
++ #include "main/include/MainModel.h"
++ #include "custom_runtime.h"
++ #include "rebootandshutdown/include/RebootAndShutdownModelC.h"
++
++ #if USE_OFFLINE_DIAL
++ #include "main/include/MainModel.h"
++ #endif
++ #include "uiservice/include/ui_service.h"
++ #include "time.h"
++ #define TESTCHECK 0
++ //心率弹窗
++ #define HEART_RATE_CHECK_TIMEOUT 0
++
++ #include "NativeRegisterManager.h"
++ #ifdef SUPPORT_POWER_MANAGER
++ #include "power_display_service.h"
++ #endif
++
++ #include "PageTransitionMgr.h"
++
++ extern "C"
++ {
++ #ifdef SUPPORT_BATTERY_SERVICE
++ #include "battery_hal.h"
++ #endif
++ }
++
++ namespace OHOS
++ {
++ REGIST_SLICE(VIEW_MAIN, MainViewSample, MainPresenterSample);
++
++ std::map<std::string, AppViewId> g_jumpView = {
++ {MAIN_CLICK_BLOOD, VIEW_BLOOD_CHECK}, // 血氧检查
++ {MAIN_CLICK_SETCARD, VIEW_ADD_CARD}, // 卡片管理
++ };
++
++ static MainPresenterSample *g_pMainPresenterSample = nullptr;
++
++ static constexpr uint16_t DROP_X_MAX = 360;
++ static constexpr uint16_t PROGRESS_PERCENTAGE = 100;
++ static constexpr uint16_t HORIZONTAL_SWIPE = 1;
++ static constexpr uint16_t PLAYER_PERIOD = 500;
++ static constexpr uint16_t MAX_PERIOD = 1000;
++
++ MainPresenterSample::MainPresenterSample()
++ {
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample :%p", this);
++ g_pMainPresenterSample = this;
++ }
++
++ MainPresenterSample::~MainPresenterSample()
++ {
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~MainPresenterSample");
++ g_pMainPresenterSample = nullptr;
++ /*从主界面退出,关闭心率检测*/
++ HeartModel::GetInstance()->Heart_Stop();
++ HeartModel::GetInstance()->Heart_Control(HeartState::End,
++ HeartCheck::CARDCHECK);
++ }
++
++ MainPresenterSample *MainPresenterSample::GetInstance(void)
++ {
++ return g_pMainPresenterSample;
++ }
++
++ void MainPresenterSample::OnStart()
++ {
++ mainPresenterState_ = MainPresenterState::START;
++ }
++
++ void MainPresenterSample::OnPause()
++ {
++ // Save watchface content for slide back
++ UIView* watchFace = view_->GetViewById(WATCH_FACE)->GetParent();
++ uint8_t opaScale = watchFace->GetOpaScale();
++ watchFace->SetOpaScale(OPA_OPAQUE);
++ PageTransitionMgr::GetInstance().SaveSlideBackSnapShotIfNecessary(watchFace);
++ watchFace->SetOpaScale(opaScale);
++
++ uint8_t curCardId = view_->GetHorCurrentCard();
++ UICardPage *card = view_->GetViewById(curCardId);
++ if (card != nullptr) {
++ card->OnPause();
++ }
++ mainPresenterState_ = MainPresenterState::PAUSE;
++
++ //进行视频表盘的暂停
++ // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "暂停视频") ;
++ // DialSetting &setting = GetDialSetting();
++ // if (setting.dialFlag) {
++ // DialModelTime::GetInstance()->UpdateTime();
++ // dynamic_cast<DialViewGroup *>(view_->GetViewById(WATCH_FACE))->StopDial();
++ // }
++ }
++
++ void MainPresenterSample::OnResume(void)
++ {
++ mainPresenterState_ = MainPresenterState::RESUME;
++ // Set current page again to invoke OnActive method.
++ uint8_t curCardId = view_->GetHorCurrentCard();
++ view_->SwitchToCard(curCardId);
++ RootView::GetInstance()->SetOnKeyActListener(KeyInputListener::GetInstance());
++
++ #if IS_SUPPORT_BIND_VOTE
++ if (ConfigModel::GetInstance()->GetisFirstTimeStart() == true) {
++ uapi_remove_bind_vote(); //页面已经展示后的调用逻辑。取消绑定投票
++ ConfigModel::GetInstance()->SetisFirstTimeStart(false);
++ }
++ #endif
++ // //进行视频表盘的恢复
++ // DialSetting &setting = GetDialSetting();
++ // if (setting.dialFlag) {
++ // DialModelTime::GetInstance()->UpdateTime();
++ // dynamic_cast<DialViewGroup *>(view_->GetViewById(WATCH_FACE))->StartDial();
++ // }
++ }
++
++ void MainPresenterSample::OnStop(void)
++ {
++ mainPresenterState_ = MainPresenterState::STOP;
++ if (isCompassSensorOpened_) {
++ CompassModel::GetInstance()->CloseCompassSensor();
++ }
++
++ PullUpDown_StopTimer();
++ CloseCompassSensor(); //切换Slice时要关闭指南针传感器
++ }
++
++ MainPresenterState MainPresenterSample::GetMainPresenterState(void)
++ {
++ return mainPresenterState_;
++ }
++
++
-- void MainPresenterSample::OnResume(void)
-- {
-- mainPresenterState_ = MainPresenterState::RESUME;
-- // Set current page again to invoke OnActive method.
-- uint8_t curCardId = view_->GetHorCurrentCard();
-- view_->SwitchToCard(curCardId);
-- RootView::GetInstance()->SetOnKeyActListener(KeyInputListener::GetInstance());
--
-- #if IS_SUPPORT_BIND_VOTE
--if (ConfigModel::GetInstance()->GetisFirstTimeStart() == true) {
-- uapi_remove_bind_vote(); //页面已经展示后的调用逻辑。取消绑定投票
-- ConfigModel::GetInstance()->SetisFirstTimeStart(false);
-- }
--#endif
-- // //进行视频表盘的恢复
-- // DialSetting &setting = GetDialSetting();
-- // if (setting.dialFlag) {
-- // DialModelTime::GetInstance()->UpdateTime();
-- // dynamic_cast<DialViewGroup *>(view_->GetViewById(WATCH_FACE))->StartDial();
-- // }
-- }
--
-- void MainPresenterSample::OnStop(void)
-- {
-- mainPresenterState_ = MainPresenterState::STOP;
-- if (isCompassSensorOpened_) {
-- CompassModel::GetInstance()->CloseCompassSensor();
-- }
--
-- PullUpDown_StopTimer();
-- CloseCompassSensor(); //切换Slice时要关闭指南针传感器
-- }
--
-- MainPresenterState MainPresenterSample::GetMainPresenterState(void)
-- {
-- return mainPresenterState_;
-- }
--
--
--
-- bool MainPresenterSample::OnClick(UIView &view, const ClickEvent &event)
-- {
-- UNUSED(event);
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StatusButtonClickListener: %s", view.GetViewId());
-- std::string curViewId = view.GetViewId();
--
-- UIImageView *imgView = static_cast<UIImageView *>(&view);
-- if (HealthModel::GetInstance() == nullptr)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "health model nullptr");
-- return false;
-- }
--
-- /*发生点击进入密码锁*/
-- if (uapi_dev_runtime_get_lock_status())
-- {
-- /*进入密码锁*/
-- NativeAbility::GetInstance().ChangeSlice(VIEW_CODED_LOCK);
-- return true;
-- }
--
-- if (curViewId == CONNECTEDSTATUSBACKGROUNDBUTTON)
-- {
-- PullUpDownView::GetInstance()->ChangeView(DROPDOWNVIEW, CONNECTEDSTATUSVIEW);
-- PullUpDown_StopTimer(); // 切换到连接状态视图时停止定时器
-- return true;
-- }
-- else if (curViewId == CONNECTEDSTATUSVIEWCLOSEBUTTON)
-- {
-- PullUpDownView::GetInstance()->ChangeView(CONNECTEDSTATUSVIEW, DROPDOWNVIEW);
-- PullUpDown_StartTimer(1000); // 切回下拉控制中心视图开启定时器
-- return true;
-- }
-- // 设置血氧进入
-- else if (curViewId == MAIN_CLICK_BLOOD)
-- {
-- MainModel::GetInstance().SetFromSetCardView(true);
-- MainModel::GetInstance().SetFromCardId(BLOODOXGEN);
-- // 如果正在充电进入提醒界面
-- bool isCharging = false;
-- #ifdef SUPPORT_BATTERY_SERVICE
-- isCharging = get_charge_stat();
-- #endif
-- if (isCharging)
-- {
-- HealthState highHealthState;
-- highHealthState.checkType = CHARGE;
-- HealthService::GetInstance()->SetHealthCurrent(highHealthState);
-- NativeAbility::GetInstance().ChangeSlice(VIEW_CHECK_INVALID, TransitionType::TRANSITION_ZOOM);
-- }
-- }
-- // 设置卡片管理进入
-- if (curViewId == MAIN_CLICK_SETCARD)
-- {
-- MainModel::GetInstance().SetFromSetCardView(true);
-- MainModel::GetInstance().SetFromCardId(SETCARD);
-- }
-- if (g_jumpView.count(curViewId) != 0)
-- {
-- NativeAbility::GetInstance().EnterSlice(g_jumpView[curViewId]);
-- }
-- return true;
-- }
--
-- bool MainPresenterSample::OnLongPress(UIView &view, const LongPressEvent &event)
-- {
-- UNUSED(event);
-- UNUSED(view);
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample OnLongPress");
-- uint8_t cardId = view_->GetHorCurrentCard();
-- /*
-- 卡片进入管理卡片界面
-- if (cardId != WATCH_FACE)
-- {
-- SetCardModel::GetInstance().SetSelectedCard(cardId);
-- NativeAbility::GetInstance().ChangeSlice(VIEW_ADD_CARD);
-- }
-- */
-- if (cardId == WATCH_FACE)
-- {
-- if (uapi_dev_runtime_get_lock_status())
-- {
-- /*进入密码锁*/
-- NativeAbility::GetInstance().ChangeSlice(VIEW_CODED_LOCK);
-- }
-- else
-- {
-- /*进入表盘设置*/
-- NativeAbility::GetInstance().ChangeSlice(VIEW_SET_DIAL);
-- }
-- }
-- return true;
-- }
--
--
-- void MainPresenterSample::SetPage(int8_t id, bool loadAdjacent)
-- {
-- if (view_ != nullptr) {
-- view_->SetPage(id, loadAdjacent);
-- }
-- }
--
-- void MainPresenterSample::SetTaskPeroid(CardId cardId)
-- {
-- SetLastRun(0);
-- if (cardId == COMPASS) {
-- SetPeriod(DEFAULT_TASK_PERIOD);
-- } else if (cardId == WATCH_FACE) {
-- uint32_t time;
-- DialSetting &setting = GetDialSetting();
-- if (setting.dialFlag) {
-- time = dynamic_cast<DialViewGroup*>(view_->GetViewById(WATCH_FACE))->GetPeriod();
-- } else {
-- time = DEFAULT_TASK_PERIOD;
-- }
-- SetPeriod(time);
-- } else if (cardId == MUSIC_PLAYER) {
-- SetPeriod(PLAYER_PERIOD);
-- } else {
-- SetPeriod(MAX_PERIOD);
-- }
-- }
--
-- void MainPresenterSample::OnSwipe(UISwipeView &view)
-- {
-- // UNUSED(view);
-- /* -------------------------------------------------------------------------- */
-- /*
-- * @brief 如果当前是下拉界面,先更新一次下拉窗口的数据包括,电池电量,时间,信号强度等等数据,
-- * 然后开启一个每2秒更新数据的定时器。
-- * 如果不在下拉界面了停止定时器
++ bool MainPresenterSample::OnClick(UIView &view, const ClickEvent &event)
++ {
++ UNUSED(event);
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StatusButtonClickListener: %s", view.GetViewId());
++ std::string curViewId = view.GetViewId();
++
++ UIImageView *imgView = static_cast<UIImageView *>(&view);
++ if (HealthModel::GetInstance() == nullptr)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "health model nullptr");
++ return false;
++ }
++
++ /*发生点击进入密码锁*/
++ if (uapi_dev_runtime_get_lock_status())
++ {
++ /*进入密码锁*/
++ NativeAbility::GetInstance().ChangeSlice(VIEW_CODED_LOCK);
++ return true;
++ }
++
++ if (curViewId == CONNECTEDSTATUSBACKGROUNDBUTTON)
++ {
++ PullUpDownView::GetInstance()->ChangeView(DROPDOWNVIEW, CONNECTEDSTATUSVIEW);
++ PullUpDown_StopTimer(); // 切换到连接状态视图时停止定时器
++ return true;
++ }
++ else if (curViewId == CONNECTEDSTATUSVIEWCLOSEBUTTON)
++ {
++ PullUpDownView::GetInstance()->ChangeView(CONNECTEDSTATUSVIEW, DROPDOWNVIEW);
++ PullUpDown_StartTimer(1000); // 切回下拉控制中心视图开启定时器
++ return true;
++ }
++ // 设置血氧进入
++ else if (curViewId == MAIN_CLICK_BLOOD)
++ {
++ MainModel::GetInstance().SetFromSetCardView(true);
++ MainModel::GetInstance().SetFromCardId(BLOODOXGEN);
++ // 如果正在充电进入提醒界面
++ bool isCharging = false;
++ #ifdef SUPPORT_BATTERY_SERVICE
++ isCharging = get_charge_stat();
++ // 打印充电状态
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "isCharging: %d", isCharging);
++ #endif
++ if (isCharging)
++ {
++ HealthState highHealthState;
++ highHealthState.checkType = CHARGE;
++ HealthService::GetInstance()->SetHealthCurrent(highHealthState);
++ NativeAbility::GetInstance().ChangeSlice(VIEW_CHECK_INVALID, TransitionType::TRANSITION_ZOOM);
++ return true;
++ }
++ }
++ // 设置卡片管理进入
++ if (curViewId == MAIN_CLICK_SETCARD)
++ {
++ MainModel::GetInstance().SetFromSetCardView(true);
++ MainModel::GetInstance().SetFromCardId(SETCARD);
++ }
++ if (g_jumpView.count(curViewId) != 0)
++ {
++ NativeAbility::GetInstance().EnterSlice(g_jumpView[curViewId]);
++ }
++ return true;
++ }
++
++ bool MainPresenterSample::OnLongPress(UIView &view, const LongPressEvent &event)
++ {
++ UNUSED(event);
++ UNUSED(view);
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample OnLongPress");
++ uint8_t cardId = view_->GetHorCurrentCard();
++ /*
++ 卡片进入管理卡片界面
++ if (cardId != WATCH_FACE)
++ {
++ SetCardModel::GetInstance().SetSelectedCard(cardId);
++ NativeAbility::GetInstance().ChangeSlice(VIEW_ADD_CARD);
++ }
*/
-- if (MainViewSample::GetInstance()->IsPullUpViewPage() == PULLUP) {
-- if (!isPullDownPageView) {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开始下拉更新");
-- isPullDownPageView = true;
-- UpdataBaseData();
-- PullUpDownView::GetInstance()->UpdateSignalStrengthStatusAndBatteryPosition();
-- PullUpDown_StartTimer(2000);
-- }
-- } else if (MainViewSample::GetInstance()->IsPullUpViewPage() == DROPDOWN) {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开始上拉更新");
-- isPullDownPageView = false;
-- PullUpDown_StopTimer();
-- } else {
-- isPullDownPageView = false;
-- PullUpDown_StopTimer();
-- }
-- /* -------------------------------------------------------------------------- */
--
-- CardId cardId = view_->GetHorCurrentCard();
-- SetTaskPeroid(cardId);
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnSwipe OnSwipe");
-- return;
-- }
--
-- void MainPresenterSample::ProcessDataNotify(void)
-- {
-- HealthMsg healthMsg;
-- uint16_t len;
--
-- while ((HealthModel::GetInstance()->FetchedHealthData(&healthMsg) == true))
-- {
-- switch (healthMsg.type)
-- {
-- case BATTERY_LIFE:
-- break;
-- default:
-- break;
-- }
-- }
-- }
--
-- void MainPresenterSample::SetCircleProgress()
-- {
-- #if 1
-- PlayersView *playersView = dynamic_cast<PlayersView *>(view_->GetViewById(MUSIC_PLAYER));
-- if (playersView == nullptr)
-- {
-- return;
-- }
-- UICircleProgress *playbackProgress = playersView->GetPlaybackProgress();
-- if (playbackProgress == nullptr)
-- {
-- return;
-- }
-- if(PlayersModel::GetInstance()->GetMusicSource() == false) {
-- int32_t playerState;
-- PlayersModel::GetInstance()->GetPlayerCtr()->GetPlayerState(playerState);
-- state_ = playersView->GetPlayerButtonState();
-- if ((playerState != PLAYER_STARTED) && (state_ == UICheckBox::UICheckBoxState::SELECTED))
-- {
-- playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED);
-- }
-- else if ((playerState == PLAYER_STARTED) && (state_ == UICheckBox::UICheckBoxState::UNSELECTED))
-- {
-- playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED);
-- }
-- }
-- if (state_ == UICheckBox::UICheckBoxState::SELECTED)
-- {
-- PlayersModel::GetInstance()->GetPlayerCtr()->GetCurrentTime(playerCurrentTime_);
-- PlayersModel::GetInstance()->GetDuration(playerMusicDuration_);
-- if (playerMusicDuration_ != 0)
-- {
-- playerProgressValue_ = (playerCurrentTime_ * PROGRESS_PERCENTAGE) / playerMusicDuration_;
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerProgressValue_ %lld", playerProgressValue_);
-- }
-- else
-- {
-- playerProgressValue_ = 100; // 100: max progress value
-- }
-- PlayersModel::GetInstance()->SetCircleProgress(playerProgressValue_);
-- PlayersPresenter::GetInstance()->SetPlaybackProgress(playerProgressValue_);
-- }
-- #endif
-- }
--
-- void MainPresenterSample::SetCompassRotate()
-- {
-- bool status = CompassModel::GetInstance()->GetCalibrationStatus();
-- dynamic_cast<CompassControlView *>(view_->GetViewById(COMPASS))->SetCalibrationView(status);
-- if (!status)
-- {
-- DetermineToRotate();
-- }
-- }
--
-- // 滑动到指南针卡片开启指南针传感器
-- void MainPresenterSample::OpenCompassSensor(void)
-- {
-- if (!isCompassSensorOpened_)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OpenCompassSensor");
-- isCompassSensorOpened_ = true;
-- CompassModel::GetInstance()->OpenCompassSensor();
-- ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); //滑动到指南针页面时开启屏幕常亮
-- }
-- }
-- // 关闭指南针传感器
-- void MainPresenterSample::CloseCompassSensor(void)
-- {
-- if(isCompassSensorOpened_)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CloseCompassSensor");
-- isCompassSensorOpened_ = false;
-- CompassModel::GetInstance()->CloseCompassSensor();
-- ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); //滑动到指南针页面时取消屏幕常亮
-- }
-- }
-- /* --------------------------------- 主界面卡片功能 -------------------------------- */
-- void MainPresenterSample::Notify(void)
-- {
-- CardId currentCardId = view_->GetHorCurrentCard();
--
-- // 从心率卡片变为其他卡片时关闭心率检测
-- if (previousCardId == HEART_RATE && currentCardId != HEART_RATE)
-- {
-- LogCardTransition(previousCardId, currentCardId);
-- HeartModel::GetInstance()->Heart_Stop();
-- HeartModel::GetInstance()->Heart_Control(HeartState::End,HeartCheck::CARDCHECK); //主动检测心率
-- }
-- // 从指南针卡片跳转到其他卡片时切换到关闭长亮屏
-- if (previousCardId == COMPASS && currentCardId != COMPASS)
-- {
-- CloseCompassSensor();
-- }
--
-- // 从睡眠卡片跳转到其他卡片时切换到睡眠卡片主界面
-- if (previousCardId == SLEEP && currentCardId != SLEEP)
-- {
-- LogCardTransition(previousCardId, currentCardId);
-- ResetSleepCardView();
-- }
-- if (previousCardId == WEATHER && currentCardId != WEATHER)
-- {
-- LogCardTransition(previousCardId, currentCardId);
-- ResetWeatherCardView();
-- }
-- if (previousCardId == GOAL && currentCardId != GOAL)
-- {
-- LogCardTransition(previousCardId, currentCardId);
-- ResetgoalCardView();
-- }
--
--
-- // 更新上一个卡片的值
-- previousCardId = currentCardId;
--
-- switch (currentCardId)
-- {
-- case HEART_RATE:
-- StartHeartRateDetection();
-- break;
--
-- case COMPASS:
-- OpenCompassSensor();
-- SetCompassRotate();
-- break;
--
-- case MUSIC_PLAYER:
-- PlayersModel::GetInstance()->SetCircleProgress();
-- break;
--
-- case WATCH_FACE:
-- UpdateWatchFace();
-- break;
--
-- case WEATHER:
-- UpdateWeather();
-- break;
--
-- case GOAL:
-- // Updategoal();
-- break;
--
-- case SLEEP:
-- UpdateSleep();
-- break;
--
-- }
-- }
-- /*打印日志*/
-- void MainPresenterSample::LogCardTransition(CardId previous, CardId current)
-- {
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[MainCard slide]previousCardId:%d cardId:%d", previous, current);
-- }
-- /*睡眠卡片*/
-- void MainPresenterSample::ResetSleepCardView()
-- {
-- if (SleepCardView::GetInstance() != nullptr)
-- {
-- auto sleepCardView = SleepCardView::GetInstance()->GetSleepCardView();
-- if (sleepCardView->GetCurrentPage() != 0)
-- {
-- sleepCardView->SetCurrentPage(0);
-- }
-- }
--
-- // SleepModel::GetInstance().msg_save_sleep_data();
-- }
-- /*天气卡片*/
-- void MainPresenterSample::ResetWeatherCardView()
-- {
-- if(WeatherControlView::GetInstance())
-- {
-- auto weatherSwipView = WeatherControlView::GetInstance()->GetWeatherSwipView();
-- if (weatherSwipView->GetCurrentPage() != 0)
-- {
-- weatherSwipView->SetCurrentPage(0);
-- }
-- }
-- }
-- /*末日目标*/
-- void MainPresenterSample::ResetgoalCardView()
-- {
-- if(goalControlView::GetInstance())
-- {
-- auto goalSwipView = goalControlView::GetInstance()->GetGoalControlSwipView();
-- if (goalSwipView->GetCurrentPage() != 0)
-- {
-- goalSwipView->SetCurrentPage(0);
-- }
-- }
-- }
--
--
-- /*心率卡片*/
-- void MainPresenterSample::StartHeartRateDetection()
-- {
-- HeartModel::GetInstance()->Heart_Control(HeartState::End, HeartCheck::PASSIVITY);
--#if HEART_RATE_CHECK_TIMEOUT
-- HeartModel::GetInstance()->Heart_Control(HeartState::Start,HeartCheck::CARDCHECK);
--#else
-- HeartModel::GetInstance()->Heart_Start(HeartCheck::CARDCHECK);
-- // 更新显示值
-- GraphicService::GetInstance()->PostGraphicEvent(std::bind(&HeartModel::RefreshHeartRateScreen, HeartModel::GetInstance()));
--#endif
-- }
-- /*主表盘*/
-- void MainPresenterSample::UpdateWatchFace()
-- {
-- DialSetting &setting = GetDialSetting();
-- if (setting.dialFlag)
-- {
-- DialModelTime::GetInstance()->UpdateTime();
-- dynamic_cast<DialViewGroup *>(view_->GetViewById(WATCH_FACE))->UpdateViewsByPeriodicUpdateData();
-- }
-- else
-- {
-- dynamic_cast<MainClockView *>(view_->GetViewById(WATCH_FACE))->UpdateTime();
-- }
-- }
--
-- void MainPresenterSample::Updategoal()
-- {
-- if(GoalView::GetInstance())
-- {
-- GoalView::GetInstance()->GoalViewrefresh();
-- }
-- if(GoalotherView::GetInstance())
-- {
-- GoalotherView::GetInstance()->GoalViewrefresh();
-- }
-- }
--
-- /*睡眠*/
-- void MainPresenterSample::UpdateSleep()
-- {
-- GraphicService::GetInstance()->PostGraphicEvent(
-- std::bind(&OHOS::SleepModel::UpdateSleepView, &OHOS::SleepModel::GetInstance()));
-- }
--
-- /*天气*/
-- void MainPresenterSample::UpdateWeather()
-- {
-- if (WeatherModel::GetInstance().GetWeatherDataIsValid())
-- {
-- WeatherModel::GetInstance().UpdateWeatherCurTime();
-- }
-- }
-- /* -------------------------------------------------------------------------- */
-- void MainPresenterSample::InitCardSettings(void)
-- {
-- MainModel::GetInstance().InitCardSettings();
-- }
--
-- uint8_t MainPresenterSample::GetCardSettingCount(void)
-- {
-- return MainModel::GetInstance().GetCardSettingCount();
-- }
--
-- CardId *MainPresenterSample::GetCardSettings(void)
-- {
-- return MainModel::GetInstance().GetCardSettings();
-- }
--
-- void MainPresenterSample::InitDialSettings(void)
-- {
-- return MainModel::GetInstance().InitDialSettings();
-- }
-- DialSetting &MainPresenterSample::GetDialSetting()
-- {
-- return MainModel::GetInstance().GetDialSetting();
-- }
--
-- static const char *weekDays_ch[] = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
-- static const char *weekDays_other[] = {"Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat"};
-- uint32_t MainPresenterSample::GetWeekStr(char *p_week)
-- {
-- time_t currtime;
-- struct tm *timeinfo;
-- time(&currtime);
-- timeinfo = localtime(&currtime);
--
-- // 获取星期信息
-- int language = ConfigModel::GetInstance()->GetLanguage();
-- if (language == 0)
-- {
-- strcpy(p_week, weekDays_ch[timeinfo->tm_wday]);
-- }
-- else
-- {
-- strcpy(p_week, weekDays_other[timeinfo->tm_wday]);
-- }
--
-- return ERRCODE_SUCC; // 假设成功获取星期信息
-- }
--
--
--
-- void MainPresenterSample::UpdataBaseData()
-- {
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::UpdataBaseData");
-- // 解析日期信息
-- char *dateStr = (char *)malloc(9);
-- if (uapi_get_YYMMDD_Time(dateStr, '/') != ERRCODE_SUCC)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get start date");
-- free(dateStr);
-- return;
-- }
-- // 获取当前时间
-- char *timeStr = (char *)malloc(9);
-- if (uapi_get_HHMMSS_Time(timeStr, ':', false) != ERRCODE_SUCC)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get start time");
-- free(dateStr);
-- free(timeStr);
-- return;
-- }
-- // 解析星期信息
-- char *weekStr = (char *)malloc(10);
-- if (GetWeekStr(weekStr) != ERRCODE_SUCC)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get week information");
-- free(dateStr);
-- free(timeStr);
-- free(weekStr);
-- return;
-- }
--
-- // 获取电池电量信息
-- float voltage = 0.0F;
-- uint8_t value = 0;
-- #ifdef SUPPORT_BATTERY_SERVICE
-- value = battery_get_voltage(&voltage);
-- #endif
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "battery_get_voltage = %d", value);
-- std::string dateAndweek = std::string(dateStr) + " " + std::string(weekStr);
-- if (PullUpDownView::GetInstance() != nullptr)
-- {
-- PullUpDownView::GetInstance()->GetProgress()->SetValue(value);
-- PullUpDownView::GetInstance()->GetDateAndWeekLabel()->SetText(dateAndweek.c_str());
-- }
--
-- // 释放动态分配的内存
-- free(dateStr);
-- free(timeStr);
-- free(weekStr);
--
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ALLData are refresh!\n");
-- }
-- void MainPresenterSample::get_memcheck()
-- {
-- MemCheck::GetInstance()->DumpMemInfo();
-- }
-- /* -------------------------------------------------------------------------- */
-- // 声明定时器变量
-- static osTimerId_t g_timer = nullptr;
-- static uint8_t UPDATETIME = 20; // 20秒
-- uint8_t MainPresenterSample::g_PullUpDownTimes = UPDATETIME;
--
-- /*定时器到期时的处理*/
-- static void PullUpDown_TimerCallbackProc(int data)
-- {
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDown_TimerCallbackProc");
-- if (uapi_get_screen_state() == 1) // 息屏状态下若停留在下拉界面,20s后无操作停止更新数据
-- {
-- MainPresenterSample::g_PullUpDownTimes -= 2;
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "%d", MainPresenterSample::g_PullUpDownTimes);
-- if (MainPresenterSample::g_PullUpDownTimes <= 0) {
-- GraphicService::GetInstance()->PostGraphicEvent(std::bind(&MainPresenterSample::PullUpDown_StopTimer, MainPresenterSample::GetInstance()));
-- }
-- }
-- else //亮屏状态下每2s刷新一次下拉数据
-- {
-- if (PullUpDownView::GetInstance() != nullptr)
-- {
-- PullUpDownView::GetInstance()->UpdateSignalStrengthStatusAndBatteryPosition();
-- }
-- if (MainPresenterSample::g_PullUpDownTimes != UPDATETIME) // 如果是亮屏后息屏再亮屏(此时息屏时间没超过 UPDATETIME)则恢复
-- MainPresenterSample::g_PullUpDownTimes = UPDATETIME;
-- }
-- return;
-- }
--
-- /*
-- * @brief 回调函数
-- */
-- static void PullUpDown_TimerCallback(int data)
-- {
-- GraphicService::GetInstance()->PostGraphicEvent(std::bind(PullUpDown_TimerCallbackProc, data));
-- }
--
-- /*
-- * @brief 开启定时器函数
-- * @param interval 时间间隔,单位ms
-- */
-- void MainPresenterSample::PullUpDown_StartTimer(uint32_t interval)
-- {
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StartTimer");
-- /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */
-- if (g_timer != nullptr)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StartTimer Timer already exists!!");
-- return;
-- }
--
-- /* --------------------------------- 2.创建定时器 -------------------------------- */
-- g_timer = osTimerNew((osTimerFunc_t)PullUpDown_TimerCallback, osTimerPeriodic, nullptr, nullptr);
-- // 检查定时器创建是否成功
-- if (g_timer == nullptr)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StartTimer Timer create failed!!");
-- return;
-- }
--
-- /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */
-- int tick = osMs2Tick(interval);
-- /* --------------------------------- 4.启动定时器 -------------------------------- */
-- osStatus_t ret = osTimerStart(g_timer, tick);
-- /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */
-- if (ret != osOK)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[PullUpDown_StartTimer] osTimerDelete failed, ret = %lx!!", ret);
-- if (g_timer != nullptr)
-- {
-- ret = osTimerDelete(g_timer);
-- }
-- g_timer = nullptr;
-- return;
-- }
-- return;
-- }
--
-- /*
-- * @brief 停止定时器
-- */
-- void MainPresenterSample::PullUpDown_StopTimer(void)
-- {
-- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StopTimer");
-- // 检查定时器是否存在
-- if (g_timer != nullptr)
-- {
-- osTimerStop(g_timer);
-- // 删除定时器并置为 nullptr
-- osStatus_t ret = osTimerDelete(g_timer);
-- if (ret != osOK)
-- {
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
-- }
-- g_timer = nullptr;
-- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "g_timer stop success");
-- }
-- }
--
-- bool MainPresenterSample::IsFromSetCardView(void) const
-- {
-- return MainModel::GetInstance().IsFromSetCardView();
-- }
--
-- void MainPresenterSample::SetFromSetCardView(bool isFrom)
-- {
-- MainModel::GetInstance().SetFromSetCardView(isFrom);
-- }
--
-- uint8_t MainPresenterSample::GetFromCardId(void)
-- {
-- return MainModel::GetInstance().GetFromCardId();
-- }
--
--}
++ if (cardId == WATCH_FACE)
++ {
++ if (uapi_dev_runtime_get_lock_status())
++ {
++ /*进入密码锁*/
++ NativeAbility::GetInstance().ChangeSlice(VIEW_CODED_LOCK);
++ }
++ else
++ {
++ /*进入表盘设置*/
++ NativeAbility::GetInstance().ChangeSlice(VIEW_SET_DIAL);
++ }
++ }
++ return true;
++ }
++
++
++ void MainPresenterSample::SetPage(int8_t id, bool loadAdjacent)
++ {
++ if (view_ != nullptr) {
++ view_->SetPage(id, loadAdjacent);
++ }
++ }
++
++ void MainPresenterSample::SetTaskPeroid(CardId cardId)
++ {
++ SetLastRun(0);
++ if (cardId == COMPASS) {
++ SetPeriod(DEFAULT_TASK_PERIOD);
++ } else if (cardId == WATCH_FACE) {
++ uint32_t time;
++ DialSetting &setting = GetDialSetting();
++ if (setting.dialFlag) {
++ time = dynamic_cast<DialViewGroup*>(view_->GetViewById(WATCH_FACE))->GetPeriod();
++ } else {
++ time = DEFAULT_TASK_PERIOD;
++ }
++ SetPeriod(time);
++ } else if (cardId == MUSIC_PLAYER) {
++ SetPeriod(PLAYER_PERIOD);
++ } else {
++ SetPeriod(MAX_PERIOD);
++ }
++ }
++
++ void MainPresenterSample::OnSwipe(UISwipeView &view)
++ {
++ // UNUSED(view);
++ /* -------------------------------------------------------------------------- */
++ /*
++ * @brief 如果当前是下拉界面,先更新一次下拉窗口的数据包括,电池电量,时间,信号强度等等数据,
++ * 然后开启一个每2秒更新数据的定时器。
++ * 如果不在下拉界面了停止定时器
++ */
++ if (MainViewSample::GetInstance()->IsPullUpViewPage() == PULLUP) {
++ if (!isPullDownPageView) {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开始下拉更新");
++ isPullDownPageView = true;
++ UpdataBaseData();
++ PullUpDownView::GetInstance()->UpdateSignalStrengthStatusAndBatteryPosition();
++ PullUpDown_StartTimer(2000);
++ }
++ } else if (MainViewSample::GetInstance()->IsPullUpViewPage() == DROPDOWN) {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开始上拉更新");
++ isPullDownPageView = false;
++ PullUpDown_StopTimer();
++ } else {
++ isPullDownPageView = false;
++ PullUpDown_StopTimer();
++ }
++ /* -------------------------------------------------------------------------- */
++
++ CardId cardId = view_->GetHorCurrentCard();
++ SetTaskPeroid(cardId);
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnSwipe OnSwipe");
++ return;
++ }
++
++ void MainPresenterSample::ProcessDataNotify(void)
++ {
++ HealthMsg healthMsg;
++ uint16_t len;
++
++ while ((HealthModel::GetInstance()->FetchedHealthData(&healthMsg) == true))
++ {
++ switch (healthMsg.type)
++ {
++ case BATTERY_LIFE:
++ break;
++ default:
++ break;
++ }
++ }
++ }
++
++ void MainPresenterSample::SetCircleProgress()
++ {
++ #if 1
++ PlayersView *playersView = dynamic_cast<PlayersView *>(view_->GetViewById(MUSIC_PLAYER));
++ if (playersView == nullptr)
++ {
++ return;
++ }
++ UICircleProgress *playbackProgress = playersView->GetPlaybackProgress();
++ if (playbackProgress == nullptr)
++ {
++ return;
++ }
++ if(PlayersModel::GetInstance()->GetMusicSource() == false) {
++ int32_t playerState;
++ PlayersModel::GetInstance()->GetPlayerCtr()->GetPlayerState(playerState);
++ state_ = playersView->GetPlayerButtonState();
++ if ((playerState != PLAYER_STARTED) && (state_ == UICheckBox::UICheckBoxState::SELECTED))
++ {
++ playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::UNSELECTED);
++ }
++ else if ((playerState == PLAYER_STARTED) && (state_ == UICheckBox::UICheckBoxState::UNSELECTED))
++ {
++ playersView->SetPlayerButtonState(UICheckBox::UICheckBoxState::SELECTED);
++ }
++ }
++ if (state_ == UICheckBox::UICheckBoxState::SELECTED)
++ {
++ PlayersModel::GetInstance()->GetPlayerCtr()->GetCurrentTime(playerCurrentTime_);
++ PlayersModel::GetInstance()->GetDuration(playerMusicDuration_);
++ if (playerMusicDuration_ != 0)
++ {
++ playerProgressValue_ = (playerCurrentTime_ * PROGRESS_PERCENTAGE) / playerMusicDuration_;
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "playerProgressValue_ %lld", playerProgressValue_);
++ }
++ else
++ {
++ playerProgressValue_ = 100; // 100: max progress value
++ }
++ PlayersModel::GetInstance()->SetCircleProgress(playerProgressValue_);
++ PlayersPresenter::GetInstance()->SetPlaybackProgress(playerProgressValue_);
++ }
++ #endif
++ }
++
++ void MainPresenterSample::SetCompassRotate()
++ {
++ bool status = CompassModel::GetInstance()->GetCalibrationStatus();
++ dynamic_cast<CompassControlView *>(view_->GetViewById(COMPASS))->SetCalibrationView(status);
++ if (!status)
++ {
++ DetermineToRotate();
++ }
++ }
++
++ // 滑动到指南针卡片开启指南针传感器
++ void MainPresenterSample::OpenCompassSensor(void)
++ {
++ if (!isCompassSensorOpened_)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OpenCompassSensor");
++ isCompassSensorOpened_ = true;
++ CompassModel::GetInstance()->OpenCompassSensor();
++ ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); //滑动到指南针页面时开启屏幕常亮
++ }
++ }
++ // 关闭指南针传感器
++ void MainPresenterSample::CloseCompassSensor(void)
++ {
++ if(isCompassSensorOpened_)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CloseCompassSensor");
++ isCompassSensorOpened_ = false;
++ CompassModel::GetInstance()->CloseCompassSensor();
++ ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); //滑动到指南针页面时取消屏幕常亮
++ }
++ }
++ /* --------------------------------- 主界面卡片功能 -------------------------------- */
++ void MainPresenterSample::Notify(void)
++ {
++ CardId currentCardId = view_->GetHorCurrentCard();
++
++ // 从心率卡片变为其他卡片时关闭心率检测
++ if (previousCardId == HEART_RATE && currentCardId != HEART_RATE)
++ {
++ LogCardTransition(previousCardId, currentCardId);
++ HeartModel::GetInstance()->Heart_Stop();
++ HeartModel::GetInstance()->Heart_Control(HeartState::End,HeartCheck::CARDCHECK); //主动检测心率
++ }
++ // 从指南针卡片跳转到其他卡片时切换到关闭长亮屏
++ if (previousCardId == COMPASS && currentCardId != COMPASS)
++ {
++ CloseCompassSensor();
++ }
++
++ // 从睡眠卡片跳转到其他卡片时切换到睡眠卡片主界面
++ if (previousCardId == SLEEP && currentCardId != SLEEP)
++ {
++ LogCardTransition(previousCardId, currentCardId);
++ ResetSleepCardView();
++ }
++ if (previousCardId == WEATHER && currentCardId != WEATHER)
++ {
++ LogCardTransition(previousCardId, currentCardId);
++ ResetWeatherCardView();
++ }
++ if (previousCardId == GOAL && currentCardId != GOAL)
++ {
++ LogCardTransition(previousCardId, currentCardId);
++ ResetgoalCardView();
++ }
++
++
++ // 更新上一个卡片的值
++ previousCardId = currentCardId;
++
++ switch (currentCardId)
++ {
++ case HEART_RATE:
++ StartHeartRateDetection();
++ break;
++
++ case COMPASS:
++ OpenCompassSensor();
++ SetCompassRotate();
++ break;
++
++ case MUSIC_PLAYER:
++ PlayersModel::GetInstance()->SetCircleProgress();
++ break;
++
++ case WATCH_FACE:
++ UpdateWatchFace();
++ break;
++
++ case WEATHER:
++ UpdateWeather();
++ break;
++
++ case GOAL:
++ // Updategoal();
++ break;
++
++ case SLEEP:
++ UpdateSleep();
++ break;
++
++ }
++ }
++ /*打印日志*/
++ void MainPresenterSample::LogCardTransition(CardId previous, CardId current)
++ {
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[MainCard slide]previousCardId:%d cardId:%d", previous, current);
++ }
++ /*睡眠卡片*/
++ void MainPresenterSample::ResetSleepCardView()
++ {
++ if (SleepCardView::GetInstance() != nullptr)
++ {
++ auto sleepCardView = SleepCardView::GetInstance()->GetSleepCardView();
++ if (sleepCardView->GetCurrentPage() != 0)
++ {
++ sleepCardView->SetCurrentPage(0);
++ }
++ }
++
++ // SleepModel::GetInstance().msg_save_sleep_data();
++ }
++ /*天气卡片*/
++ void MainPresenterSample::ResetWeatherCardView()
++ {
++ if(WeatherControlView::GetInstance())
++ {
++ auto weatherSwipView = WeatherControlView::GetInstance()->GetWeatherSwipView();
++ if (weatherSwipView->GetCurrentPage() != 0)
++ {
++ weatherSwipView->SetCurrentPage(0);
++ }
++ }
++ }
++ /*末日目标*/
++ void MainPresenterSample::ResetgoalCardView()
++ {
++ if(goalControlView::GetInstance())
++ {
++ auto goalSwipView = goalControlView::GetInstance()->GetGoalControlSwipView();
++ if (goalSwipView->GetCurrentPage() != 0)
++ {
++ goalSwipView->SetCurrentPage(0);
++ }
++ }
++ }
++
++
++ /*心率卡片*/
++ void MainPresenterSample::StartHeartRateDetection()
++ {
++ HeartModel::GetInstance()->Heart_Control(HeartState::End, HeartCheck::PASSIVITY);
++ #if HEART_RATE_CHECK_TIMEOUT
++ HeartModel::GetInstance()->Heart_Control(HeartState::Start,HeartCheck::CARDCHECK);
++ #else
++ HeartModel::GetInstance()->Heart_Start(HeartCheck::CARDCHECK);
++ // 更新显示值
++ GraphicService::GetInstance()->PostGraphicEvent(std::bind(&HeartModel::RefreshHeartRateScreen, HeartModel::GetInstance()));
++ #endif
++ }
++ /*主表盘*/
++ void MainPresenterSample::UpdateWatchFace()
++ {
++ DialSetting &setting = GetDialSetting();
++ if (setting.dialFlag)
++ {
++ DialModelTime::GetInstance()->UpdateTime();
++ dynamic_cast<DialViewGroup *>(view_->GetViewById(WATCH_FACE))->UpdateViewsByPeriodicUpdateData();
++ }
++ else
++ {
++ dynamic_cast<MainClockView *>(view_->GetViewById(WATCH_FACE))->UpdateTime();
++ }
++ }
++
++ void MainPresenterSample::Updategoal()
++ {
++ if(GoalView::GetInstance())
++ {
++ GoalView::GetInstance()->GoalViewrefresh();
++ }
++ if(GoalotherView::GetInstance())
++ {
++ GoalotherView::GetInstance()->GoalViewrefresh();
++ }
++ }
++
++ /*睡眠*/
++ void MainPresenterSample::UpdateSleep()
++ {
++ GraphicService::GetInstance()->PostGraphicEvent(
++ std::bind(&OHOS::SleepModel::UpdateSleepView, &OHOS::SleepModel::GetInstance()));
++ }
++
++ /*天气*/
++ void MainPresenterSample::UpdateWeather()
++ {
++ if (WeatherModel::GetInstance().GetWeatherDataIsValid())
++ {
++ WeatherModel::GetInstance().UpdateWeatherCurTime();
++ }
++ }
++ /* -------------------------------------------------------------------------- */
++ void MainPresenterSample::InitCardSettings(void)
++ {
++ MainModel::GetInstance().InitCardSettings();
++ }
++
++ uint8_t MainPresenterSample::GetCardSettingCount(void)
++ {
++ return MainModel::GetInstance().GetCardSettingCount();
++ }
++
++ CardId *MainPresenterSample::GetCardSettings(void)
++ {
++ return MainModel::GetInstance().GetCardSettings();
++ }
++
++ void MainPresenterSample::InitDialSettings(void)
++ {
++ return MainModel::GetInstance().InitDialSettings();
++ }
++ DialSetting &MainPresenterSample::GetDialSetting()
++ {
++ return MainModel::GetInstance().GetDialSetting();
++ }
++
++ static const char *weekDays_ch[] = {"星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
++ static const char *weekDays_other[] = {"Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat"};
++ uint32_t MainPresenterSample::GetWeekStr(char *p_week)
++ {
++ time_t currtime;
++ struct tm *timeinfo;
++ time(&currtime);
++ timeinfo = localtime(&currtime);
++
++ // 获取星期信息
++ int language = ConfigModel::GetInstance()->GetLanguage();
++ if (language == 0)
++ {
++ strcpy(p_week, weekDays_ch[timeinfo->tm_wday]);
++ }
++ else
++ {
++ strcpy(p_week, weekDays_other[timeinfo->tm_wday]);
++ }
++
++ return ERRCODE_SUCC; // 假设成功获取星期信息
++ }
++
++
++
++ void MainPresenterSample::UpdataBaseData()
++ {
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDownView::UpdataBaseData");
++ // 解析日期信息
++ char *dateStr = (char *)malloc(9);
++ if (uapi_get_YYMMDD_Time(dateStr, '/') != ERRCODE_SUCC)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get start date");
++ free(dateStr);
++ return;
++ }
++ // 获取当前时间
++ char *timeStr = (char *)malloc(9);
++ if (uapi_get_HHMMSS_Time(timeStr, ':', false) != ERRCODE_SUCC)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get start time");
++ free(dateStr);
++ free(timeStr);
++ return;
++ }
++ // 解析星期信息
++ char *weekStr = (char *)malloc(10);
++ if (GetWeekStr(weekStr) != ERRCODE_SUCC)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get week information");
++ free(dateStr);
++ free(timeStr);
++ free(weekStr);
++ return;
++ }
++
++ // 获取电池电量信息
++ float voltage = 0.0F;
++ uint8_t value = 0;
++ #ifdef SUPPORT_BATTERY_SERVICE
++ value = battery_get_voltage(&voltage);
++ #endif
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "battery_get_voltage = %d", value);
++ std::string dateAndweek = std::string(dateStr) + " " + std::string(weekStr);
++ if (PullUpDownView::GetInstance() != nullptr)
++ {
++ PullUpDownView::GetInstance()->GetProgress()->SetValue(value);
++ PullUpDownView::GetInstance()->GetDateAndWeekLabel()->SetText(dateAndweek.c_str());
++ }
++
++ // 释放动态分配的内存
++ free(dateStr);
++ free(timeStr);
++ free(weekStr);
++
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ALLData are refresh!\n");
++ }
++ void MainPresenterSample::get_memcheck()
++ {
++ MemCheck::GetInstance()->DumpMemInfo();
++ }
++ /* -------------------------------------------------------------------------- */
++ // 声明定时器变量
++ static osTimerId_t g_timer = nullptr;
++ static uint8_t UPDATETIME = 20; // 20秒
++ uint8_t MainPresenterSample::g_PullUpDownTimes = UPDATETIME;
++
++ /*定时器到期时的处理*/
++ static void PullUpDown_TimerCallbackProc(int data)
++ {
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "PullUpDown_TimerCallbackProc");
++ if (uapi_get_screen_state() == 1) // 息屏状态下若停留在下拉界面,20s后无操作停止更新数据
++ {
++ MainPresenterSample::g_PullUpDownTimes -= 2;
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "%d", MainPresenterSample::g_PullUpDownTimes);
++ if (MainPresenterSample::g_PullUpDownTimes <= 0) {
++ GraphicService::GetInstance()->PostGraphicEvent(std::bind(&MainPresenterSample::PullUpDown_StopTimer, MainPresenterSample::GetInstance()));
++ }
++ }
++ else //亮屏状态下每2s刷新一次下拉数据
++ {
++ if (PullUpDownView::GetInstance() != nullptr)
++ {
++ PullUpDownView::GetInstance()->UpdateSignalStrengthStatusAndBatteryPosition();
++ }
++ if (MainPresenterSample::g_PullUpDownTimes != UPDATETIME) // 如果是亮屏后息屏再亮屏(此时息屏时间没超过 UPDATETIME)则恢复
++ MainPresenterSample::g_PullUpDownTimes = UPDATETIME;
++ }
++ return;
++ }
++
++ /*
++ * @brief 回调函数
++ */
++ static void PullUpDown_TimerCallback(int data)
++ {
++ GraphicService::GetInstance()->PostGraphicEvent(std::bind(PullUpDown_TimerCallbackProc, data));
++ }
++
++ /*
++ * @brief 开启定时器函数
++ * @param interval 时间间隔,单位ms
++ */
++ void MainPresenterSample::PullUpDown_StartTimer(uint32_t interval)
++ {
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StartTimer");
++ /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */
++ if (g_timer != nullptr)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StartTimer Timer already exists!!");
++ return;
++ }
++
++ /* --------------------------------- 2.创建定时器 -------------------------------- */
++ g_timer = osTimerNew((osTimerFunc_t)PullUpDown_TimerCallback, osTimerPeriodic, nullptr, nullptr);
++ // 检查定时器创建是否成功
++ if (g_timer == nullptr)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StartTimer Timer create failed!!");
++ return;
++ }
++
++ /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */
++ int tick = osMs2Tick(interval);
++ /* --------------------------------- 4.启动定时器 -------------------------------- */
++ osStatus_t ret = osTimerStart(g_timer, tick);
++ /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */
++ if (ret != osOK)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[PullUpDown_StartTimer] osTimerDelete failed, ret = %lx!!", ret);
++ if (g_timer != nullptr)
++ {
++ ret = osTimerDelete(g_timer);
++ }
++ g_timer = nullptr;
++ return;
++ }
++ return;
++ }
++
++ /*
++ * @brief 停止定时器
++ */
++ void MainPresenterSample::PullUpDown_StopTimer(void)
++ {
++ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainPresenterSample::PullUpDown_StopTimer");
++ // 检查定时器是否存在
++ if (g_timer != nullptr)
++ {
++ osTimerStop(g_timer);
++ // 删除定时器并置为 nullptr
++ osStatus_t ret = osTimerDelete(g_timer);
++ if (ret != osOK)
++ {
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
++ }
++ g_timer = nullptr;
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "g_timer stop success");
++ }
++ }
++
++ bool MainPresenterSample::IsFromSetCardView(void) const
++ {
++ return MainModel::GetInstance().IsFromSetCardView();
++ }
++
++ void MainPresenterSample::SetFromSetCardView(bool isFrom)
++ {
++ MainModel::GetInstance().SetFromSetCardView(isFrom);
++ }
++
++ uint8_t MainPresenterSample::GetFromCardId(void)
++ {
++ return MainModel::GetInstance().GetFromCardId();
++ }
++
++ }
++
MainModel::GetInstance().SetFromCardId(BLOODOXGEN);
// 如果正在充电进入提醒界面
bool isCharging = false;
-- #ifdef SUPPORT_BATTERY_SERVICE
++ #ifdef SUPPORT_BATTERY_SERVICE
isCharging = get_charge_stat();
-- #endif
++ // 打印充电状态
++ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "isCharging: %d", isCharging);
++ #endif
if (isCharging)
{
HealthState highHealthState;
highHealthState.checkType = CHARGE;
HealthService::GetInstance()->SetHealthCurrent(highHealthState);
NativeAbility::GetInstance().ChangeSlice(VIEW_CHECK_INVALID, TransitionType::TRANSITION_ZOOM);
++ return true;
}
}
// 设置卡片管理进入