show the call screen for a moment after the call ends, with visible duration

This commit is contained in:
tibbi 2020-05-01 18:18:29 +02:00
parent 1c45efd986
commit ae42a735e7
2 changed files with 28 additions and 9 deletions

View File

@ -8,6 +8,7 @@ import android.graphics.*
import android.media.AudioManager import android.media.AudioManager
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.os.Handler
import android.os.PowerManager import android.os.PowerManager
import android.provider.MediaStore import android.provider.MediaStore
import android.telecom.Call import android.telecom.Call
@ -35,6 +36,7 @@ class CallActivity : SimpleActivity() {
private var isSpeakerOn = false private var isSpeakerOn = false
private var isMicrophoneOn = true private var isMicrophoneOn = true
private var isCallEnded = false
private var callDuration = 0 private var callDuration = 0
private var callContact: CallContact? = null private var callContact: CallContact? = null
private var callContactAvatar: Bitmap? = null private var callContactAvatar: Bitmap? = null
@ -65,6 +67,9 @@ class CallActivity : SimpleActivity() {
notificationManager.cancel(CALL_NOTIFICATION_ID) notificationManager.cancel(CALL_NOTIFICATION_ID)
CallManager.unregisterCallback(callCallback) CallManager.unregisterCallback(callCallback)
callTimer.cancel() callTimer.cancel()
if (proximityWakeLock?.isHeld == true) {
proximityWakeLock!!.release()
}
} }
private fun initButtons() { private fun initButtons() {
@ -123,17 +128,18 @@ class CallActivity : SimpleActivity() {
Call.STATE_DISCONNECTED -> endCall() Call.STATE_DISCONNECTED -> endCall()
} }
if (state == Call.STATE_DISCONNECTED || state == Call.STATE_DISCONNECTING) {
callTimer.cancel()
}
val statusTextId = when (state) { val statusTextId = when (state) {
Call.STATE_RINGING -> R.string.is_calling Call.STATE_RINGING -> R.string.is_calling
Call.STATE_DIALING -> R.string.is_called Call.STATE_DIALING -> R.string.is_called
Call.STATE_DISCONNECTED -> R.string.call_ended else -> 0
Call.STATE_DISCONNECTING -> R.string.call_ending
else -> R.string.empty
} }
call_status_label.text = getString(statusTextId) if (statusTextId != 0) {
if (state == Call.STATE_DISCONNECTED || state == Call.STATE_DISCONNECTING) { call_status_label.text = getString(statusTextId)
callTimer.cancel()
} }
} }
@ -150,19 +156,33 @@ class CallActivity : SimpleActivity() {
} }
private fun endCall() { private fun endCall() {
isCallEnded = true
CallManager.reject() CallManager.reject()
if (proximityWakeLock?.isHeld == true) { if (proximityWakeLock?.isHeld == true) {
proximityWakeLock!!.release() proximityWakeLock!!.release()
} }
audioManager.mode = AudioManager.MODE_NORMAL audioManager.mode = AudioManager.MODE_NORMAL
finish() if (callDuration > 0) {
runOnUiThread {
call_status_label.text = "${callDuration.getFormattedDuration()} (${getString(R.string.call_ended)})"
Handler().postDelayed({
finish()
}, 3000)
}
} else {
call_status_label.text = getString(R.string.call_ended)
finish()
}
} }
private fun getCallTimerUpdateTask() = object : TimerTask() { private fun getCallTimerUpdateTask() = object : TimerTask() {
override fun run() { override fun run() {
callDuration++ callDuration++
runOnUiThread { runOnUiThread {
call_status_label.text = callDuration.getFormattedDuration() if (!isCallEnded) {
call_status_label.text = callDuration.getFormattedDuration()
}
} }
} }
} }

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="package_name">com.simplemobiletools.contacts.pro</string> <string name="package_name">com.simplemobiletools.contacts.pro</string>
<string name="empty"></string>
<string name="im">IM</string> <string name="im">IM</string>
<string name="aim">AIM</string> <string name="aim">AIM</string>