From 9fad8363356ba6607f193c7fc12afab436f43bf8 Mon Sep 17 00:00:00 2001 From: yezhiqiu <983577727@qq.com> Date: Wed, 7 Jan 2026 17:41:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=85=B3=E9=97=AD=E5=A3=B0?= =?UTF-8?q?=E9=9F=B3=EF=BC=8C=E5=A3=B0=E9=9F=B3=E5=9B=BE=E6=A0=87=E6=8C=87?= =?UTF-8?q?=E7=A4=BA=E5=A3=B0=E9=9F=B3=E5=85=B3=E9=97=AD=EF=BC=8C=E4=BD=86?= =?UTF-8?q?=E8=B0=83=E6=89=8B=E6=9C=BA=E9=9F=B3=E9=87=8F=E9=94=AE=E5=BC=80?= =?UTF-8?q?=E5=90=AF=E5=A3=B0=E9=9F=B3=E5=90=8E=EF=BC=8C=E5=A3=B0=E9=9F=B3?= =?UTF-8?q?=E5=9B=BE=E6=A0=87=E4=BB=8D=E7=84=B6=E6=8C=87=E7=A4=BA=E5=A3=B0?= =?UTF-8?q?=E9=9F=B3=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/deploymentTargetSelector.xml | 3 ++ app/build.gradle | 6 ++-- .../tracker/ui/activity/map/LiveActivityV3.kt | 31 +++++++++++++++++++ .../tracker/vm/FindBleDeviceViewModel.kt | 15 ++++++++- 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml index 713138f..58cd886 100644 --- a/.idea/deploymentTargetSelector.xml +++ b/.idea/deploymentTargetSelector.xml @@ -13,6 +13,9 @@ + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 88768ff..d883191 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -28,9 +28,9 @@ android { applicationId "com.abbidot.tracker" minSdkVersion 23 targetSdkVersion 35 - versionCode 2101 -// versionName "2.1.1" - versionName "2.1.1-Beta15" + versionCode 2102 +// versionName "2.1.2" + versionName "2.1.2-Beta1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/java/com/abbidot/tracker/ui/activity/map/LiveActivityV3.kt b/app/src/main/java/com/abbidot/tracker/ui/activity/map/LiveActivityV3.kt index b7ed333..a3cd1b1 100644 --- a/app/src/main/java/com/abbidot/tracker/ui/activity/map/LiveActivityV3.kt +++ b/app/src/main/java/com/abbidot/tracker/ui/activity/map/LiveActivityV3.kt @@ -2,10 +2,12 @@ package com.abbidot.tracker.ui.activity.map import android.content.Intent import android.graphics.Typeface +import android.view.KeyEvent import android.view.View import android.widget.RelativeLayout import androidx.activity.viewModels import androidx.core.view.isGone +import androidx.core.view.isVisible import androidx.fragment.app.Fragment import androidx.fragment.app.commit import androidx.lifecycle.lifecycleScope @@ -1025,6 +1027,34 @@ class LiveActivityV3 : BaseActivity(ActivityLiveV3Binding isOpenSound = !isOpenSound } + override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean { + if (mViewBinding.ilLiveV2BluetoothFindDevice.root.isVisible) { + when (keyCode) { + KeyEvent.KEYCODE_VOLUME_DOWN -> { + val volume = mFindBleDeviceViewModel.getVolume() + if (volume == 1 && isOpenSound) { + isOpenSound = false + mViewBinding.ilLiveV2BluetoothFindDevice.ivLiveV2FindDeviceSound.setImageResource( + R.drawable.icon_sound_off_svg + ) + } + LogUtil.e("音量减小--,$volume") + } + + KeyEvent.KEYCODE_VOLUME_UP -> { + LogUtil.e("音量增加++") + if (!isOpenSound) { + isOpenSound = true + mViewBinding.ilLiveV2BluetoothFindDevice.ivLiveV2FindDeviceSound.setImageResource( + R.drawable.icon_sound_on_svg + ) + } + } + } + } + return super.onKeyDown(keyCode, event) + } + override fun onClick(v: View?) { mViewBinding.apply { when (v!!) { @@ -1048,6 +1078,7 @@ class LiveActivityV3 : BaseActivity(ActivityLiveV3Binding if (isLiveJump) { isOpenSound = true setSound() + mFindBleDeviceViewModel.stopPlay() showAndHideFindLayout() } else { mFindBleDeviceViewModel.stopFindDevice() diff --git a/app/src/main/java/com/abbidot/tracker/vm/FindBleDeviceViewModel.kt b/app/src/main/java/com/abbidot/tracker/vm/FindBleDeviceViewModel.kt index 5981909..808a5a0 100644 --- a/app/src/main/java/com/abbidot/tracker/vm/FindBleDeviceViewModel.kt +++ b/app/src/main/java/com/abbidot/tracker/vm/FindBleDeviceViewModel.kt @@ -80,7 +80,7 @@ class FindBleDeviceViewModel : ViewModel() { viewModelScope.launch(Dispatchers.IO) { mAudioManager = activity.getSystemService(Service.AUDIO_SERVICE) as AudioManager - mPhoneOriginalVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC) + mPhoneOriginalVolume = getVolume() mMaxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) setVolume(0) @@ -181,6 +181,13 @@ class FindBleDeviceViewModel : ViewModel() { mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0) } + /** + * 获取系统当前的音量 + */ + fun getVolume(): Int { + return mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC) + } + /** * 创建SoundPool ,注意 api 等级 */ @@ -198,6 +205,8 @@ class FindBleDeviceViewModel : ViewModel() { } val fd = activity.assets.openFd("find_device.mp3") mSoundID = mSoundPool?.load(fd, 1)!! + } else { + if (mStreamID != 0) mSoundPool?.resume(mStreamID) } } @@ -283,6 +292,10 @@ class FindBleDeviceViewModel : ViewModel() { setVolume(mPhoneOriginalVolume) } + fun stopPlay() { + mSoundPool?.pause(mStreamID) + } + override fun onCleared() { super.onCleared() LogUtil.e("FindBleDeviceViewModel onCleared")