mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
copying some Call screen related things from Simple Contacts
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user