diff --git a/app/src/main/kotlin/org/fossify/phone/helpers/CallNotificationManager.kt b/app/src/main/kotlin/org/fossify/phone/helpers/CallNotificationManager.kt index 90b527e9e..fb5a335c9 100644 --- a/app/src/main/kotlin/org/fossify/phone/helpers/CallNotificationManager.kt +++ b/app/src/main/kotlin/org/fossify/phone/helpers/CallNotificationManager.kt @@ -22,6 +22,7 @@ class CallNotificationManager(private val context: Context) { private const val CALL_NOTIFICATION_ID = 42 private const val ACCEPT_CALL_CODE = 0 private const val DECLINE_CALL_CODE = 1 + private const val ANSWER_SPEAKER_CALL_CODE = 2 } private val notificationManager = context.notificationManager @@ -61,6 +62,16 @@ class CallNotificationManager(private val context: Context) { PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_MUTABLE ) + val answerSpeakerIntent = Intent(context, CallActionReceiver::class.java) + answerSpeakerIntent.action = ANSWER_SPEAKER_CALL + val answerSpeakerPendingIntent = + PendingIntent.getBroadcast( + context, + ANSWER_SPEAKER_CALL_CODE, + answerSpeakerIntent, + PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_MUTABLE + ) + var callerName = callContact.name.ifEmpty { context.getString(R.string.unknown_caller) } if (callContact.numberLabel.isNotEmpty()) { callerName += " - ${callContact.numberLabel}" @@ -78,9 +89,11 @@ class CallNotificationManager(private val context: Context) { setText(R.id.notification_caller_name, callerName) setText(R.id.notification_call_status, context.getString(contentTextId)) setVisibleIf(R.id.notification_accept_call, callState == Call.STATE_RINGING) + setVisibleIf(R.id.notification_answer_speaker, callState == Call.STATE_RINGING) setOnClickPendingIntent(R.id.notification_decline_call, declinePendingIntent) setOnClickPendingIntent(R.id.notification_accept_call, acceptPendingIntent) + setOnClickPendingIntent(R.id.notification_answer_speaker, answerSpeakerPendingIntent) if (callContactAvatar != null) { setImageViewBitmap( diff --git a/app/src/main/kotlin/org/fossify/phone/helpers/Constants.kt b/app/src/main/kotlin/org/fossify/phone/helpers/Constants.kt index 754151c80..e92355ba6 100644 --- a/app/src/main/kotlin/org/fossify/phone/helpers/Constants.kt +++ b/app/src/main/kotlin/org/fossify/phone/helpers/Constants.kt @@ -27,5 +27,6 @@ val tabsList = arrayListOf(TAB_CONTACTS, TAB_FAVORITES, TAB_CALL_HISTORY) private const val PATH = "org.fossify.phone.action." const val ACCEPT_CALL = PATH + "ACCEPT_CALL" const val DECLINE_CALL = PATH + "DECLINE_CALL" +const val ANSWER_SPEAKER_CALL = PATH + "ANSWER_SPEAKER_CALL" const val DIALPAD_TONE_LENGTH_MS = 150L // The length of DTMF tones in milliseconds diff --git a/app/src/main/kotlin/org/fossify/phone/receivers/CallActionReceiver.kt b/app/src/main/kotlin/org/fossify/phone/receivers/CallActionReceiver.kt index a826b7856..9cea888f6 100644 --- a/app/src/main/kotlin/org/fossify/phone/receivers/CallActionReceiver.kt +++ b/app/src/main/kotlin/org/fossify/phone/receivers/CallActionReceiver.kt @@ -3,8 +3,10 @@ package org.fossify.phone.receivers import android.content.BroadcastReceiver import android.content.Context import android.content.Intent +import android.telecom.CallAudioState import org.fossify.phone.activities.CallActivity import org.fossify.phone.helpers.ACCEPT_CALL +import org.fossify.phone.helpers.ANSWER_SPEAKER_CALL import org.fossify.phone.helpers.CallManager import org.fossify.phone.helpers.DECLINE_CALL @@ -16,6 +18,11 @@ class CallActionReceiver : BroadcastReceiver() { CallManager.accept() } + ANSWER_SPEAKER_CALL -> { + CallManager.accept() + CallManager.setAudioRoute(CallAudioState.ROUTE_SPEAKER) + } + DECLINE_CALL -> CallManager.reject() } } diff --git a/app/src/main/res/drawable/bg_notification_answer.xml b/app/src/main/res/drawable/bg_notification_answer.xml new file mode 100644 index 000000000..b1b73fb33 --- /dev/null +++ b/app/src/main/res/drawable/bg_notification_answer.xml @@ -0,0 +1,3 @@ + + + diff --git a/app/src/main/res/drawable/bg_notification_decline.xml b/app/src/main/res/drawable/bg_notification_decline.xml new file mode 100644 index 000000000..da518082c --- /dev/null +++ b/app/src/main/res/drawable/bg_notification_decline.xml @@ -0,0 +1,4 @@ + + + + diff --git a/app/src/main/res/drawable/bg_notification_speaker.xml b/app/src/main/res/drawable/bg_notification_speaker.xml new file mode 100644 index 000000000..f46da781e --- /dev/null +++ b/app/src/main/res/drawable/bg_notification_speaker.xml @@ -0,0 +1,4 @@ + + + + diff --git a/app/src/main/res/layout/call_notification.xml b/app/src/main/res/layout/call_notification.xml index b75682142..ef7ed053b 100644 --- a/app/src/main/res/layout/call_notification.xml +++ b/app/src/main/res/layout/call_notification.xml @@ -42,21 +42,35 @@ + android:src="@drawable/ic_phone_down_red_vector" + android:tint="@android:color/white" /> + + + android:src="@drawable/ic_phone_green_vector" + android:tint="@android:color/white" />