From: xue <2144439972@qq.com> Date: Thu, 4 Dec 2025 07:25:02 +0000 (+0800) Subject: 优化音量加减按键操作 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=68ebc7e30ae0fe42aae07034013517b939237296;p=mirrors%2FFD230.git 优化音量加减按键操作 --- diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdReminderView.h b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdReminderView.h index c6d801bac..0473a8adf 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdReminderView.h +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdReminderView.h @@ -22,8 +22,10 @@ namespace OHOS void Show(int16_t showView); void HideAll(); // 音量/进度调节接口(用于 THUNDERBIRD_REMINDERVIEW_VOLUME) - void AdjustRemindProgress(int16_t delta); // 正数增加,负数减少 - void SetRemindProgress(int16_t value); + void AdjustRemindProgress(int16_t delta); // 正数增加,负数减少(只更新UI,延迟应用真实音量) + void SetRemindProgress(int16_t value); // 立即设置真实音量 + void ApplyPendingVolume(); // 应用待设置的音量值(在界面隐藏时调用) + bool IsVolumeViewVisible() const; // 检查音量界面是否正在显示 // 任务提醒文本更新接口(用于 THUNDERBIRD_REMINDERVIEW_TASK_REMINDER) void UpdateTaskReminderText(const char* title, const char* content); @@ -64,6 +66,9 @@ namespace OHOS // 进度当前值(用于音量界面),0~100 int16_t remindProgressValue_{50}; + + // 待应用的真实音量值(延迟应用音量时使用) + int16_t pendingVolumeValue_{-1}; // -1表示没有待应用的值 }; } diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp index b17b31b69..3c006fd1d 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp @@ -211,16 +211,29 @@ extern "C" { { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StartReminderHideTimer: intervalMs=%u", intervalMs); - // 如果已经有倒计时在进行,先停止并隐藏上一次的提醒 + auto *reminder = ThunderBirdReminderView::GetInstance(); + bool isVolumeViewVisible = (reminder != nullptr && reminder->IsVolumeViewVisible()); + + // 如果已经有倒计时在进行 if (m_reminderHideActive) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StartReminderHideTimer: Previous timer active, hiding previous reminder"); - auto *reminder = ThunderBirdReminderView::GetInstance(); - if (reminder != nullptr) { - reminder->HideAll(); + // 如果音量界面正在显示,只重新启动定时器(再延时),不隐藏界面 + if (isVolumeViewVisible) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StartReminderHideTimer: Volume view visible, restarting timer only (extend by %u ms)", intervalMs); + m_reminderHideTime = intervalMs / 1000; // 重新设置倒计时时间 + // 确保时间显示定时器正在运行 + if (m_timeDisplayTimer == nullptr) { + StartTimeDisplayTimer(1000); // 1秒间隔 + } + return; // 直接返回,不隐藏界面 + } else { + // 音量界面未显示,隐藏上一次的提醒 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StartReminderHideTimer: Previous timer active, hiding previous reminder"); + if (reminder != nullptr) { + reminder->HideAll(); + } + // 重置之前的倒计时状态 + m_reminderHideActive = false; } - // 重置之前的倒计时状态 - m_reminderHideActive = false; - //close_battery_flag = false; } // 设置提醒隐藏定时器状态 @@ -229,10 +242,11 @@ extern "C" { if(m_reminderHideTime == 5)//电量过低即将关机提醒 close_battery_flag = true; - // 隐藏全部提醒界面,准备显示新的 - auto *reminder = ThunderBirdReminderView::GetInstance(); - if (reminder != nullptr) { - reminder->HideAll(); + // 如果音量界面未显示,隐藏全部提醒界面,准备显示新的 + if (!isVolumeViewVisible) { + if (reminder != nullptr) { + reminder->HideAll(); + } } // 确保时间显示定时器正在运行 @@ -240,7 +254,8 @@ extern "C" { StartTimeDisplayTimer(1000); // 1秒间隔 } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reminder hide timer started: %d seconds, close_battery_flag=%d", m_reminderHideTime, close_battery_flag); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Reminder hide timer started: %d seconds, close_battery_flag=%d, isVolumeViewVisible=%d", + m_reminderHideTime, close_battery_flag, isVolumeViewVisible); } // ---------------------- OTA 倒计时定时器(已整合到新定时器系统) ---------------------- @@ -2699,6 +2714,8 @@ extern "C" { // 没有已绑定设备,跳转到配对准备页面 ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_BLUEVIEW, ThunderBirdBlueView::THUNDERBIRD_BULEVIEW_ENTER); + //不管跳到什么界面都要先停止视频 + ThunderBirdMainView::GetInstance()->videoPlay_->PauseVideoPlay(); } } diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp index 6686451da..eacebdd19 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp @@ -598,13 +598,36 @@ namespace OHOS */ void ThunderBirdPresenter::ShowVolumeAdjustment(int volumeDelta) { - ThunderBirdMainView::GetInstance()->ChangeThunderBirdReminderView(THUNDERBIRD_REMINDERVIEW); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "音量调节"); - if (ThunderBirdReminderView::GetInstance()) { - ThunderBirdModel::GetInstance()->StartReminderHideTimer(1000); - ThunderBirdReminderView::GetInstance()->Show(ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_VOLUME); - ThunderBirdReminderView::GetInstance()->AdjustRemindProgress(volumeDelta); + // struct timespec startTime; + // clock_gettime(CLOCK_MONOTONIC, &startTime); + + ThunderBirdReminderView *reminderView = ThunderBirdReminderView::GetInstance(); + if (!reminderView) { + ThunderBirdMainView::GetInstance()->ChangeThunderBirdReminderView(THUNDERBIRD_REMINDERVIEW); + reminderView = ThunderBirdReminderView::GetInstance(); } + + if (reminderView) { + // 检查音量界面是否已经显示 + if (reminderView->IsVolumeViewVisible()) { + // 界面已经显示,只更新音量并重新启动定时器(再延时1秒) + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "音量界面已显示,只更新音量并重新启动定时器"); + reminderView->AdjustRemindProgress(volumeDelta); + ThunderBirdModel::GetInstance()->StartReminderHideTimer(1000); + } else { + // 界面未显示,显示界面并启动定时器 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "音量调节:显示界面"); + ThunderBirdMainView::GetInstance()->ChangeThunderBirdReminderView(THUNDERBIRD_REMINDERVIEW); + ThunderBirdModel::GetInstance()->StartReminderHideTimer(1000); + reminderView->Show(ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_VOLUME); + reminderView->AdjustRemindProgress(volumeDelta); + } + } + + // struct timespec endTime; + // clock_gettime(CLOCK_MONOTONIC, &endTime); + // long long timeCost = (endTime.tv_sec - startTime.tv_sec) * 1000000000 + endTime.tv_nsec - startTime.tv_nsec; + // printf("timeCost = %u ns\n", timeCost); } /** diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdReminderView.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdReminderView.cpp index e70e9f530..b4b4902ea 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdReminderView.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdReminderView.cpp @@ -140,6 +140,11 @@ namespace OHOS } if (VolumeProgress) { + // 显示音量界面时,初始化显示值为当前真实音量 + int16_t currentVolume = AudioManager::GetInstance().GetVolume(AUDIO_STREAM_VOICE_ASSISTANT); + remindProgressValue_ = currentVolume; + pendingVolumeValue_ = -1; // 重置待应用的值 + VolumeProgress->SetValue(remindProgressValue_); VolumeProgress->SetVisible(true); } break; @@ -449,6 +454,12 @@ namespace OHOS void ThunderBirdReminderView::HideAll() { if (group == nullptr) { return; } + + // 如果音量界面正在显示,在隐藏前应用待设置的音量值 + if (VolumeProgress && VolumeProgress->IsVisible()) { + ApplyPendingVolume(); + } + if (RemindButton) { RemindButton->SetVisible(false); } if (TextLabel) { TextLabel->SetVisible(false); } if (RemindLabel) { RemindLabel->SetVisible(false); } @@ -479,10 +490,49 @@ namespace OHOS { return; } - int16_t newVal = AudioManager::GetInstance().GetVolume(AUDIO_STREAM_VOICE_ASSISTANT) + delta; - SetRemindProgress(newVal); - // 若当前处于音量界面,确保控件可见 - if (RemindButton) { RemindButton->SetVisible(true); } + + // 获取当前显示的音量值(如果有待应用的值,使用待应用的值;否则使用真实音量) + int16_t currentDisplayValue; + if (pendingVolumeValue_ >= 0) { + // 有待应用的值,使用待应用的值作为基准 + currentDisplayValue = pendingVolumeValue_; + } else { + // 没有待应用的值,使用真实音量作为基准 + currentDisplayValue = AudioManager::GetInstance().GetVolume(AUDIO_STREAM_VOICE_ASSISTANT); + } + + // 计算新的音量值 + int16_t newVal = currentDisplayValue + delta; + if (newVal < 0) { newVal = 0; } + if (newVal > 100) { newVal = 100; } + + // 只更新UI显示,不设置真实音量 + remindProgressValue_ = newVal; + pendingVolumeValue_ = newVal; // 保存待应用的值 + VolumeProgress->SetValue(remindProgressValue_); + VolumeProgress->Invalidate(); + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AdjustRemindProgress: delta=%d, newVal=%d (UI only, pending apply)", delta, newVal); + } + + /** + * @brief 应用待设置的音量值(在界面隐藏时调用) + */ + void ThunderBirdReminderView::ApplyPendingVolume() + { + if (pendingVolumeValue_ >= 0) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplyPendingVolume: applying volume=%d", pendingVolumeValue_); + // 应用真实音量 + AudioManager::GetInstance().SetVolume(AUDIO_STREAM_VOICE_ASSISTANT, pendingVolumeValue_); + ln_bt_earphone_set_volume(pendingVolumeValue_); + remindProgressValue_ = pendingVolumeValue_; + pendingVolumeValue_ = -1; // 清除待应用的值 + } + } + + bool ThunderBirdReminderView::IsVolumeViewVisible() const + { + return (VolumeProgress != nullptr && VolumeProgress->IsVisible()); } void ThunderBirdReminderView::UpdateTaskReminderText(const char* title, const char* content)