copying some Call screen related things from Simple Contacts

This commit is contained in:
tibbi
2020-05-09 23:25:04 +02:00
parent d6fc7bbcbd
commit a34307ef18
21 changed files with 918 additions and 1 deletions

View File

@ -0,0 +1,70 @@
package com.simplemobiletools.dialer.helpers
import android.annotation.SuppressLint
import android.content.Context
import android.net.Uri
import android.telecom.Call
import android.telecom.VideoProfile
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
import com.simplemobiletools.dialer.models.CallContact
// inspired by https://github.com/Chooloo/call_manage
@SuppressLint("NewApi")
class CallManager {
companion object {
var call: Call? = null
fun accept() {
call?.answer(VideoProfile.STATE_AUDIO_ONLY)
}
fun reject() {
if (call != null) {
if (call!!.state == Call.STATE_RINGING) {
call!!.reject(false, null)
} else {
call!!.disconnect()
}
}
}
fun registerCallback(callback: Call.Callback) {
if (call != null) {
call!!.registerCallback(callback)
}
}
fun unregisterCallback(callback: Call.Callback) {
call?.unregisterCallback(callback)
}
fun getState() = if (call == null) {
Call.STATE_DISCONNECTED
} else {
call!!.state
}
fun keypad(c: Char) {
call?.playDtmfTone(c)
call?.stopDtmfTone()
}
fun getCallContact(context: Context, callback: (CallContact?) -> Unit) {
val callContact = CallContact("", "", "")
if (call == null || call!!.details == null || call!!.details!!.handle == null) {
callback(callContact)
return
}
val uri = Uri.decode(call!!.details.handle.toString())
if (uri.startsWith("tel:")) {
val number = uri.substringAfter("tel:")
callContact.number = number
callContact.name = SimpleContactsHelper(context).getNameFromPhoneNumber(number)
callContact.photoUri = SimpleContactsHelper(context).getPhotoUriFromPhoneNumber(number)
callback(callContact)
}
}
}
}