默认关闭声音,声音图标指示声音关闭,但调手机音量键开启声音后,声音图标仍然指示声音关闭
This commit is contained in:
@@ -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"
|
||||
|
||||
|
||||
@@ -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>(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>(ActivityLiveV3Binding
|
||||
if (isLiveJump) {
|
||||
isOpenSound = true
|
||||
setSound()
|
||||
mFindBleDeviceViewModel.stopPlay()
|
||||
showAndHideFindLayout()
|
||||
} else {
|
||||
mFindBleDeviceViewModel.stopFindDevice()
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user