From: luozheng <1732036298@qq.com> Date: Sun, 20 Oct 2024 07:56:30 +0000 (+0800) Subject: 1.倒计时界面,UI刷新改用Notify,减少误差 X-Git-Tag: fd230_release_V1.3.102~188^2~37 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=c2a6ed26173e3ff2f86c1309d6489bd6b169a56f;p=mirrors%2FFD230.git 1.倒计时界面,UI刷新改用Notify,减少误差 2.倒计时响铃流类型改为:AUDIO_STREAM_NOTIFICATION_SYSTEM 支持a2dp播放时混音 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/countdown/include/MainCountDownPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/countdown/include/MainCountDownPresenter.h index c87e4a417..e16f7feef 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/countdown/include/MainCountDownPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/countdown/include/MainCountDownPresenter.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-07 18:15:53 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-20 10:17:35 + * @LastEditTime: 2024-10-19 17:07:09 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/countdown/include/MainCountDownPresenter.h */ #ifndef MAIN_COUNTDOWN_PRESENTER_H @@ -12,6 +12,7 @@ #include "Presenter.h" #include "MainCountDownView.h" #include "ui_resource_string.h" +#include "ModelListenerSample.h" /*倒计时的主界面*/ namespace OHOS { @@ -31,7 +32,8 @@ namespace OHOS public UIView::OnDragListener, UITimePicker::SelectedListener, public UICheckBox::OnChangeListener, - public RootView::OnKeyActListener + public RootView::OnKeyActListener, + public ModelListenerSample { public: MainCountDownPresenter(); @@ -52,6 +54,7 @@ namespace OHOS bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 bool OnChange(UICheckBox::UICheckBoxState state) override; void OnTimePickerStoped(UITimePicker &picker) override; + void Notify() override; std::string countdowntime{0}; std::string ringtime{0}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp index 7518ec048..c15993234 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-07 18:15:53 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-10-11 16:17:52 + * @LastEditTime: 2024-10-20 11:49:21 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp */ #include "countdown/include/CountDownModel.h" @@ -174,7 +174,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDownModel] Player url:%s", uri.c_str()); playerCtr->SetSource(*source); /* --------------------------------- 4.配置播放器 -------------------------------- */ - playerCtr->SetAudioStreamType(AUDIO_STREAM_MUSIC); // 设置播放器的音频流类型 + playerCtr->SetAudioStreamType(AUDIO_STREAM_NOTIFICATION_SYSTEM); // 设置播放器的音频流类型 playerCtr->Prepare(); // 准备播放器对象以播放音频。 /* -------------------------------- 5.请求音频焦点 -------------------------------- */ AudioManager &amIntance = AudioManager::GetInstance(); @@ -192,7 +192,7 @@ namespace OHOS return OHOS_FAILURE; } playerInterruptListener->SetOwner(playerCtr); - interrupt = {AUDIO_STREAM_MUSIC, sessionId, playerInterruptListener}; + interrupt = {AUDIO_STREAM_NOTIFICATION_SYSTEM, sessionId, playerInterruptListener}; // 激活音频中断 5s超时 if (amIntance.ActivateAudioInterrupt(interrupt) == INTERRUPT_FAILED) { @@ -203,6 +203,7 @@ namespace OHOS playerCtr->SetAudioSessionId(sessionId); // 播放 playerCtr->Play(); + playerCtr->EnableSingleLooping(true); // 设置是否循环播放 return OHOS_SUCCESS; } @@ -436,14 +437,14 @@ namespace OHOS } } } - else - { - if (p_StartCountDownView) - { - // 更新显示 - p_StartCountDownView->GetShowCountDownTimelabel()->SetText(CountDownModel::GetInstance()->DisplayCountDownDuration()); - } - } + // else + // { + // if (p_StartCountDownView) + // { + // // 更新显示 + // p_StartCountDownView->GetShowCountDownTimelabel()->SetText(CountDownModel::GetInstance()->DisplayCountDownDuration()); + // } + // } return; } @@ -646,8 +647,8 @@ namespace OHOS void CountDownRingPlayerCallbackImpl::OnPlaybackComplete(void) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnPlaybackComplete"); - CountDownModel::GetInstance()->RequestStopRingtone(); - CountDownModel::GetInstance()->RequestStartRingtone(); + // CountDownModel::GetInstance()->RequestStopRingtone(); + // CountDownModel::GetInstance()->RequestStartRingtone(); } void CountDownRingPlayerCallbackImpl::OnError(int32_t errorType, int32_t errorCode) diff --git a/code/sdk/application/wearable/fd230app/nativeui/countdown/src/MainCountDownPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/countdown/src/MainCountDownPresenter.cpp index 134887383..da464782c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/countdown/src/MainCountDownPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/countdown/src/MainCountDownPresenter.cpp @@ -295,4 +295,18 @@ namespace OHOS CountDownModel::GetInstance()->SetCountDownTime(picker.GetSelectValue()); // 设置倒计时时间 CountDownModel::GetInstance()->SetRingTime(picker.GetSelectValue()); // 设置响铃时间 } + void MainCountDownPresenter::Notify() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCountDownPresenter::Notify"); + if(CountDownModel::GetInstance()->CountDownTimerIsEnd()) // 倒计时timer已经停止直接退出不刷新 + { + return; + } + StartCountDownView *p_StartCountDownView = StartCountDownView::GetInstance(); + if (p_StartCountDownView && p_StartCountDownView->GetShowCountDownTimelabel()) + { + // 更新显示 + p_StartCountDownView->GetShowCountDownTimelabel()->SetText(CountDownModel::GetInstance()->DisplayCountDownDuration()); + } + } } \ No newline at end of file