mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
toggle proximity sensor with the external speaker
This commit is contained in:
@ -77,9 +77,7 @@ class CallActivity : SimpleActivity() {
|
|||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
CallManager.unregisterCallback(callCallback)
|
CallManager.unregisterCallback(callCallback)
|
||||||
if (proximityWakeLock?.isHeld == true) {
|
disableProximitySensor()
|
||||||
proximityWakeLock!!.release()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
@ -280,6 +278,12 @@ class CallActivity : SimpleActivity() {
|
|||||||
val newRoute = if (isSpeakerOn) CallAudioState.ROUTE_SPEAKER else CallAudioState.ROUTE_EARPIECE
|
val newRoute = if (isSpeakerOn) CallAudioState.ROUTE_SPEAKER else CallAudioState.ROUTE_EARPIECE
|
||||||
CallManager.inCallService?.setAudioRoute(newRoute)
|
CallManager.inCallService?.setAudioRoute(newRoute)
|
||||||
call_toggle_speaker.contentDescription = getString(if (isSpeakerOn) R.string.turn_speaker_off else R.string.turn_speaker_on)
|
call_toggle_speaker.contentDescription = getString(if (isSpeakerOn) R.string.turn_speaker_off else R.string.turn_speaker_on)
|
||||||
|
|
||||||
|
if (isSpeakerOn) {
|
||||||
|
disableProximitySensor()
|
||||||
|
} else {
|
||||||
|
enableProximitySensor()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleMicrophone() {
|
private fun toggleMicrophone() {
|
||||||
@ -373,7 +377,7 @@ class CallActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initOutgoingCallUI() {
|
private fun initOutgoingCallUI() {
|
||||||
initProximitySensor()
|
enableProximitySensor()
|
||||||
incoming_call_holder.beGone()
|
incoming_call_holder.beGone()
|
||||||
ongoing_call_holder.beVisible()
|
ongoing_call_holder.beVisible()
|
||||||
}
|
}
|
||||||
@ -383,7 +387,7 @@ class CallActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun callStarted() {
|
private fun callStarted() {
|
||||||
initProximitySensor()
|
enableProximitySensor()
|
||||||
incoming_call_holder.beGone()
|
incoming_call_holder.beGone()
|
||||||
ongoing_call_holder.beVisible()
|
ongoing_call_holder.beVisible()
|
||||||
callDurationHelper.onDurationChange {
|
callDurationHelper.onDurationChange {
|
||||||
@ -406,9 +410,7 @@ class CallActivity : SimpleActivity() {
|
|||||||
|
|
||||||
private fun endCall() {
|
private fun endCall() {
|
||||||
CallManager.reject()
|
CallManager.reject()
|
||||||
if (proximityWakeLock?.isHeld == true) {
|
disableProximitySensor()
|
||||||
proximityWakeLock!!.release()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isCallEnded) {
|
if (isCallEnded) {
|
||||||
finishAndRemoveTask()
|
finishAndRemoveTask()
|
||||||
@ -462,12 +464,17 @@ class CallActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initProximitySensor() {
|
private fun enableProximitySensor() {
|
||||||
if (!audioManager.hasExternalSpeaker() && !config.disableProximitySensor &&
|
if (!config.disableProximitySensor && (proximityWakeLock == null || proximityWakeLock?.isHeld == false)) {
|
||||||
(proximityWakeLock == null || proximityWakeLock?.isHeld == false)) {
|
|
||||||
val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
|
val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||||
proximityWakeLock = powerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "com.simplemobiletools.dialer.pro:wake_lock")
|
proximityWakeLock = powerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "com.simplemobiletools.dialer.pro:wake_lock")
|
||||||
proximityWakeLock!!.acquire(60 * MINUTE_SECONDS * 1000L)
|
proximityWakeLock!!.acquire(60 * MINUTE_SECONDS * 1000L)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun disableProximitySensor() {
|
||||||
|
if (proximityWakeLock?.isHeld == true) {
|
||||||
|
proximityWakeLock!!.release()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
package com.simplemobiletools.dialer.extensions
|
|
||||||
|
|
||||||
import android.media.AudioDeviceInfo
|
|
||||||
import android.media.AudioManager
|
|
||||||
import com.simplemobiletools.commons.helpers.isOreoPlus
|
|
||||||
import com.simplemobiletools.commons.helpers.isSPlus
|
|
||||||
|
|
||||||
fun AudioManager.hasExternalSpeaker(): Boolean {
|
|
||||||
val audioDevices = getDevices(AudioManager.GET_DEVICES_INPUTS)
|
|
||||||
if (isSPlus()) {
|
|
||||||
if (audioDevices.find {
|
|
||||||
it.type == AudioDeviceInfo.TYPE_BLE_HEADSET ||
|
|
||||||
it.type == AudioDeviceInfo.TYPE_BLE_SPEAKER
|
|
||||||
} != null) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isOreoPlus()) {
|
|
||||||
if (audioDevices.find {
|
|
||||||
it.type == AudioDeviceInfo.TYPE_USB_HEADSET
|
|
||||||
} != null) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (audioDevices.find {
|
|
||||||
it.type == AudioDeviceInfo.TYPE_WIRED_HEADSET ||
|
|
||||||
it.type == AudioDeviceInfo.TYPE_BLUETOOTH_SCO ||
|
|
||||||
it.type == AudioDeviceInfo.TYPE_BLUETOOTH_A2DP
|
|
||||||
} != null) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
Reference in New Issue
Block a user