Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -16,6 +18,11 @@ class CallActionReceiver : BroadcastReceiver() {
CallManager.accept()
}

ANSWER_SPEAKER_CALL -> {
CallManager.accept()
CallManager.setAudioRoute(CallAudioState.ROUTE_SPEAKER)
}

DECLINE_CALL -> CallManager.reject()
}
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/drawable/bg_notification_answer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#258428" /> <corners android:radius="16dp" /> </shape>
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/bg_notification_decline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#b63229" /> <corners android:radius="16dp" />
</shape>
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/bg_notification_speaker.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#455365" /> <corners android:radius="16dp" />
</shape>
26 changes: 20 additions & 6 deletions app/src/main/res/layout/call_notification.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,35 @@

<ImageView
android:id="@+id/notification_decline_call"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="@dimen/call_notification_button_size"
android:layout_weight="1"
android:background="@drawable/ripple_background"
android:layout_marginEnd="8dp"
android:background="@drawable/bg_notification_decline"
android:padding="@dimen/small_margin"
android:src="@drawable/ic_phone_down_red_vector" />
android:src="@drawable/ic_phone_down_red_vector"
android:tint="@android:color/white" />

<ImageView
android:id="@+id/notification_answer_speaker"
android:layout_width="0dp"
android:layout_height="@dimen/call_notification_button_size"
android:layout_weight="1"
android:layout_marginEnd="8dp"
android:background="@drawable/bg_notification_speaker"
android:padding="@dimen/small_margin"
android:src="@drawable/ic_volume_up_vector"
android:tint="@android:color/white" />

<ImageView
android:id="@+id/notification_accept_call"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="@dimen/call_notification_button_size"
android:layout_weight="1"
android:background="@drawable/ripple_background"
android:background="@drawable/bg_notification_answer"
android:padding="@dimen/small_margin"
android:src="@drawable/ic_phone_green_vector" />
android:src="@drawable/ic_phone_green_vector"
android:tint="@android:color/white" />

</LinearLayout>
</RelativeLayout>
Loading