FR #200 Remove dialer from recent apps after hanging up a call

This commit is contained in:
fl0w3r
2021-08-15 23:11:02 +05:45
parent bbc61c34eb
commit 8ef4422a7a
3 changed files with 68 additions and 27 deletions

View File

@ -89,6 +89,7 @@
<activity <activity
android:name=".activities.CallActivity" android:name=".activities.CallActivity"
android:label="@string/ongoing_call" android:label="@string/ongoing_call"
android:excludeFromRecents="true"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:showOnLockScreen="true" /> android:showOnLockScreen="true" />

View File

@ -9,6 +9,7 @@ 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.Handler
import android.os.Looper
import android.os.PowerManager import android.os.PowerManager
import android.provider.MediaStore import android.provider.MediaStore
import android.telecom.Call import android.telecom.Call
@ -87,7 +88,8 @@ class CallActivity : SimpleActivity() {
if (dialpad_wrapper.isVisible()) { if (dialpad_wrapper.isVisible()) {
dialpad_wrapper.beGone() dialpad_wrapper.beGone()
return return
} else { }
else {
super.onBackPressed() super.onBackPressed()
} }
@ -141,7 +143,13 @@ class CallActivity : SimpleActivity() {
dialpad_hashtag_holder.setOnClickListener { dialpadPressed('#') } dialpad_hashtag_holder.setOnClickListener { dialpadPressed('#') }
dialpad_wrapper.setBackgroundColor(config.backgroundColor) dialpad_wrapper.setBackgroundColor(config.backgroundColor)
arrayOf(call_toggle_microphone, call_toggle_speaker, call_dialpad, dialpad_close, call_sim_image).forEach { arrayOf(
call_toggle_microphone,
call_toggle_speaker,
call_dialpad,
dialpad_close,
call_sim_image
).forEach {
it.applyColorFilter(config.textColor) it.applyColorFilter(config.textColor)
} }
@ -155,17 +163,20 @@ class CallActivity : SimpleActivity() {
private fun toggleSpeaker() { private fun toggleSpeaker() {
isSpeakerOn = !isSpeakerOn isSpeakerOn = !isSpeakerOn
val drawable = if (isSpeakerOn) R.drawable.ic_speaker_on_vector else R.drawable.ic_speaker_off_vector val drawable =
if (isSpeakerOn) R.drawable.ic_speaker_on_vector else R.drawable.ic_speaker_off_vector
call_toggle_speaker.setImageDrawable(getDrawable(drawable)) call_toggle_speaker.setImageDrawable(getDrawable(drawable))
audioManager.isSpeakerphoneOn = isSpeakerOn audioManager.isSpeakerphoneOn = isSpeakerOn
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)
} }
private fun toggleMicrophone() { private fun toggleMicrophone() {
isMicrophoneOn = !isMicrophoneOn isMicrophoneOn = !isMicrophoneOn
val drawable = if (isMicrophoneOn) R.drawable.ic_microphone_vector else R.drawable.ic_microphone_off_vector val drawable =
if (isMicrophoneOn) R.drawable.ic_microphone_vector else R.drawable.ic_microphone_off_vector
call_toggle_microphone.setImageDrawable(getDrawable(drawable)) call_toggle_microphone.setImageDrawable(getDrawable(drawable))
audioManager.isMicrophoneMute = !isMicrophoneOn audioManager.isMicrophoneMute = !isMicrophoneOn
CallManager.inCallService?.setMuted(!isMicrophoneOn) CallManager.inCallService?.setMuted(!isMicrophoneOn)
@ -174,7 +185,8 @@ class CallActivity : SimpleActivity() {
private fun toggleDialpadVisibility() { private fun toggleDialpadVisibility() {
if (dialpad_wrapper.isVisible()) { if (dialpad_wrapper.isVisible()) {
dialpad_wrapper.beGone() dialpad_wrapper.beGone()
} else { }
else {
dialpad_wrapper.beVisible() dialpad_wrapper.beVisible()
} }
} }
@ -184,10 +196,12 @@ class CallActivity : SimpleActivity() {
return return
} }
caller_name_label.text = if (callContact!!.name.isNotEmpty()) callContact!!.name else getString(R.string.unknown_caller) caller_name_label.text =
if (callContact!!.name.isNotEmpty()) callContact!!.name else getString(R.string.unknown_caller)
if (callContact!!.number.isNotEmpty() && callContact!!.number != callContact!!.name) { if (callContact!!.number.isNotEmpty() && callContact!!.number != callContact!!.name) {
caller_number_label.text = callContact!!.number caller_number_label.text = callContact!!.number
} else { }
else {
caller_number_label.beGone() caller_number_label.beGone()
} }
@ -209,7 +223,8 @@ class CallActivity : SimpleActivity() {
} }
} }
} }
} catch (ignored: Exception) { }
catch (ignored: Exception) {
} }
} }
@ -259,7 +274,8 @@ class CallActivity : SimpleActivity() {
ongoing_call_holder.beVisible() ongoing_call_holder.beVisible()
try { try {
callTimer.scheduleAtFixedRate(getCallTimerUpdateTask(), 1000, 1000) callTimer.scheduleAtFixedRate(getCallTimerUpdateTask(), 1000, 1000)
} catch (ignored: Exception) { }
catch (ignored: Exception) {
} }
} }
@ -278,24 +294,27 @@ class CallActivity : SimpleActivity() {
} }
if (isCallEnded) { if (isCallEnded) {
finish() finishAndRemoveTask()
return return
} }
try { try {
audioManager.mode = AudioManager.MODE_NORMAL audioManager.mode = AudioManager.MODE_NORMAL
} catch (ignored: Exception) { }
catch (ignored: Exception) {
} }
isCallEnded = true isCallEnded = true
if (callDuration > 0) { if (callDuration > 0) {
runOnUiThread { runOnUiThread {
call_status_label.text = "${callDuration.getFormattedDuration()} (${getString(R.string.call_ended)})" call_status_label.text =
Handler().postDelayed({ "${callDuration.getFormattedDuration()} (${getString(R.string.call_ended)})"
finish() Handler(Looper.getMainLooper()).postDelayed({
finishAndRemoveTask()
}, 3000) }, 3000)
} }
} else { }
else {
call_status_label.text = getString(R.string.call_ended) call_status_label.text = getString(R.string.call_ended)
finish() finish()
} }
@ -324,13 +343,18 @@ class CallActivity : SimpleActivity() {
if (isOreoMr1Plus()) { if (isOreoMr1Plus()) {
setShowWhenLocked(true) setShowWhenLocked(true)
setTurnScreenOn(true) setTurnScreenOn(true)
} else { }
else {
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON) window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON)
} }
if (isOreoPlus()) { if (isOreoPlus()) {
(getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).requestDismissKeyguard(this, null) (getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).requestDismissKeyguard(
} else { this,
null
)
}
else {
window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD) window.addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD)
} }
} }
@ -338,7 +362,10 @@ class CallActivity : SimpleActivity() {
private fun initProximitySensor() { private fun initProximitySensor() {
if (proximityWakeLock == null || proximityWakeLock?.isHeld == false) { if (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(10 * MINUTE_SECONDS * 1000L) proximityWakeLock!!.acquire(10 * MINUTE_SECONDS * 1000L)
} }
} }
@ -363,13 +390,21 @@ class CallActivity : SimpleActivity() {
val acceptCallIntent = Intent(this, CallActionReceiver::class.java) val acceptCallIntent = Intent(this, CallActionReceiver::class.java)
acceptCallIntent.action = ACCEPT_CALL acceptCallIntent.action = ACCEPT_CALL
val acceptPendingIntent = PendingIntent.getBroadcast(this, 0, acceptCallIntent, PendingIntent.FLAG_CANCEL_CURRENT) val acceptPendingIntent =
PendingIntent.getBroadcast(this, 0, acceptCallIntent, PendingIntent.FLAG_CANCEL_CURRENT)
val declineCallIntent = Intent(this, CallActionReceiver::class.java) val declineCallIntent = Intent(this, CallActionReceiver::class.java)
declineCallIntent.action = DECLINE_CALL declineCallIntent.action = DECLINE_CALL
val declinePendingIntent = PendingIntent.getBroadcast(this, 1, declineCallIntent, PendingIntent.FLAG_CANCEL_CURRENT) val declinePendingIntent = PendingIntent.getBroadcast(
this,
1,
declineCallIntent,
PendingIntent.FLAG_CANCEL_CURRENT
)
val callerName = if (callContact != null && callContact!!.name.isNotEmpty()) callContact!!.name else getString(R.string.unknown_caller) val callerName =
if (callContact != null && callContact!!.name.isNotEmpty()) callContact!!.name
else getString(R.string.unknown_caller)
val contentTextId = when (callState) { val contentTextId = when (callState) {
Call.STATE_RINGING -> R.string.is_calling Call.STATE_RINGING -> R.string.is_calling
Call.STATE_DIALING -> R.string.dialing Call.STATE_DIALING -> R.string.dialing
@ -387,7 +422,10 @@ class CallActivity : SimpleActivity() {
setOnClickPendingIntent(R.id.notification_accept_call, acceptPendingIntent) setOnClickPendingIntent(R.id.notification_accept_call, acceptPendingIntent)
if (callContactAvatar != null) { if (callContactAvatar != null) {
setImageViewBitmap(R.id.notification_thumbnail, getCircularBitmap(callContactAvatar!!)) setImageViewBitmap(
R.id.notification_thumbnail,
getCircularBitmap(callContactAvatar!!)
)
} }
} }
@ -416,13 +454,15 @@ class CallActivity : SimpleActivity() {
bitmap = if (isQPlus()) { bitmap = if (isQPlus()) {
val tmbSize = resources.getDimension(R.dimen.list_avatar_size).toInt() val tmbSize = resources.getDimension(R.dimen.list_avatar_size).toInt()
contentResolver.loadThumbnail(photoUri, Size(tmbSize, tmbSize), null) contentResolver.loadThumbnail(photoUri, Size(tmbSize, tmbSize), null)
} else { }
else {
MediaStore.Images.Media.getBitmap(contentResolver, photoUri) MediaStore.Images.Media.getBitmap(contentResolver, photoUri)
} }
bitmap = getCircularBitmap(bitmap!!) bitmap = getCircularBitmap(bitmap!!)
} catch (ignored: Exception) { }
catch (ignored: Exception) {
return null return null
} }
} }

View File

@ -1,7 +1,7 @@
<resources> <resources>
<string name="app_name">Simple Dialer</string> <string name="app_name">Simple Dialer</string>
<string name="app_launcher_name">Telefono</string> <string name="app_launcher_name">Telefono</string>
<string name="default_phone_app_prompt">Per favore, rendi l'app la predefinita per le chiamate</string> <string name="default_phone_app_prompt">Per favore, rendi l\'app la predefinita per le chiamate</string>
<!-- Contacts --> <!-- Contacts -->
<string name="could_not_access_contacts">Impossibile accedere ai contatti</string> <string name="could_not_access_contacts">Impossibile accedere ai contatti</string>