handle accepting call
This commit is contained in:
parent
0ac58a0a57
commit
824a385b11
|
@ -10,9 +10,7 @@ import android.os.Bundle
|
||||||
import android.telecom.Call
|
import android.telecom.Call
|
||||||
import android.widget.RemoteViews
|
import android.widget.RemoteViews
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import com.simplemobiletools.commons.extensions.notificationManager
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.extensions.setText
|
|
||||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
|
||||||
import com.simplemobiletools.commons.helpers.isOreoPlus
|
import com.simplemobiletools.commons.helpers.isOreoPlus
|
||||||
import com.simplemobiletools.contacts.pro.R
|
import com.simplemobiletools.contacts.pro.R
|
||||||
import com.simplemobiletools.contacts.pro.helpers.ACCEPT_CALL
|
import com.simplemobiletools.contacts.pro.helpers.ACCEPT_CALL
|
||||||
|
@ -49,7 +47,9 @@ class CallActivity : SimpleActivity() {
|
||||||
endCall()
|
endCall()
|
||||||
}
|
}
|
||||||
|
|
||||||
call_accept.setOnClickListener { }
|
call_accept.setOnClickListener {
|
||||||
|
acceptCall()
|
||||||
|
}
|
||||||
|
|
||||||
call_toggle_microphone.setOnClickListener {
|
call_toggle_microphone.setOnClickListener {
|
||||||
toggleMicrophone()
|
toggleMicrophone()
|
||||||
|
@ -60,7 +60,9 @@ class CallActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
call_dialpad.setOnClickListener { }
|
call_dialpad.setOnClickListener { }
|
||||||
call_end.setOnClickListener { }
|
call_end.setOnClickListener {
|
||||||
|
endCall()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleSpeaker() {
|
private fun toggleSpeaker() {
|
||||||
|
@ -77,10 +79,20 @@ class CallActivity : SimpleActivity() {
|
||||||
|
|
||||||
private fun updateCallState(state: Int) {
|
private fun updateCallState(state: Int) {
|
||||||
when (state) {
|
when (state) {
|
||||||
|
Call.STATE_ACTIVE -> callStarted()
|
||||||
Call.STATE_DISCONNECTED -> endCall()
|
Call.STATE_DISCONNECTED -> endCall()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun acceptCall() {
|
||||||
|
CallManager.accept()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun callStarted() {
|
||||||
|
incoming_call_holder.beGone()
|
||||||
|
ongoing_call_holder.beVisible()
|
||||||
|
}
|
||||||
|
|
||||||
private fun endCall() {
|
private fun endCall() {
|
||||||
CallManager.reject()
|
CallManager.reject()
|
||||||
finish()
|
finish()
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.simplemobiletools.contacts.pro.helpers
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.telecom.Call
|
import android.telecom.Call
|
||||||
|
import android.telecom.VideoProfile
|
||||||
|
|
||||||
// inspired by https://github.com/Chooloo/call_manage
|
// inspired by https://github.com/Chooloo/call_manage
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
|
@ -9,6 +10,10 @@ class CallManager {
|
||||||
companion object {
|
companion object {
|
||||||
var call: Call? = null
|
var call: Call? = null
|
||||||
|
|
||||||
|
fun accept() {
|
||||||
|
call?.answer(VideoProfile.STATE_AUDIO_ONLY)
|
||||||
|
}
|
||||||
|
|
||||||
fun reject() {
|
fun reject() {
|
||||||
if (call != null) {
|
if (call != null) {
|
||||||
if (call!!.state == Call.STATE_RINGING) {
|
if (call!!.state == Call.STATE_RINGING) {
|
||||||
|
|
|
@ -3,12 +3,14 @@ package com.simplemobiletools.contacts.pro.receivers
|
||||||
import android.content.BroadcastReceiver
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import com.simplemobiletools.contacts.pro.helpers.ACCEPT_CALL
|
||||||
import com.simplemobiletools.contacts.pro.helpers.CallManager
|
import com.simplemobiletools.contacts.pro.helpers.CallManager
|
||||||
import com.simplemobiletools.contacts.pro.helpers.DECLINE_CALL
|
import com.simplemobiletools.contacts.pro.helpers.DECLINE_CALL
|
||||||
|
|
||||||
class CallActionReceiver : BroadcastReceiver() {
|
class CallActionReceiver : BroadcastReceiver() {
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
when (intent.action) {
|
when (intent.action) {
|
||||||
|
ACCEPT_CALL -> CallManager.accept()
|
||||||
DECLINE_CALL -> CallManager.reject()
|
DECLINE_CALL -> CallManager.reject()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue