adding a few more call notification related improvements

This commit is contained in:
tibbi 2018-11-21 17:54:08 +01:00
parent 59119f274e
commit a392759ae0
21 changed files with 83 additions and 23 deletions

View File

@ -27,7 +27,8 @@ class DialerActivity : SimpleActivity(), SensorEventListener {
private val SENSOR_SENSITIVITY = 4
private val DISCONNECT_DELAY = 3000L
private var number = ""
private var callNumber = ""
private var callStatus = Call.STATE_NEW
private var isIncomingCall = false
private var isCallActive = false
private var callDuration = 0
@ -43,17 +44,15 @@ class DialerActivity : SimpleActivity(), SensorEventListener {
LocalBroadcastManager.getInstance(applicationContext).registerReceiver(messageReceiver, IntentFilter(DIALER_INTENT_FILTER))
if (intent.action == Intent.ACTION_CALL && intent.data != null && intent.dataString?.contains("tel:") == true) {
number = Uri.decode(intent.dataString).substringAfter("tel:")
callNumber = Uri.decode(intent.dataString).substringAfter("tel:")
initViews()
tryFillingOtherEndsName()
startNotificationService()
} else if (intent.action == INCOMING_CALL && intent.extras?.containsKey(CALLER_NUMBER) == true && intent.extras?.containsKey(CALL_STATUS) == true) {
} else if (intent.action == INCOMING_CALL && intent.extras?.containsKey(CALL_NUMBER) == true && intent.extras?.containsKey(CALL_STATUS) == true) {
isIncomingCall = true
number = intent.getStringExtra(CALLER_NUMBER)
callNumber = intent.getStringExtra(CALL_NUMBER)
initViews()
updateUI(intent.getIntExtra(CALL_STATUS, 0))
updateUI(intent.getIntExtra(CALL_STATUS, Call.STATE_NEW))
tryFillingOtherEndsName()
startNotificationService()
} else {
toast(R.string.unknown_error_occurred)
finish()
@ -69,6 +68,9 @@ class DialerActivity : SimpleActivity(), SensorEventListener {
override fun onPause() {
super.onPause()
sensorManager!!.unregisterListener(this)
if (!isCallActive && callStatus != Call.STATE_DISCONNECTED) {
startNotificationService()
}
}
override fun onDestroy() {
@ -79,7 +81,7 @@ class DialerActivity : SimpleActivity(), SensorEventListener {
private val messageReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.extras?.containsKey(CALL_STATUS) == true) {
updateUI(intent.getIntExtra(CALL_STATUS, 0))
updateUI(intent.getIntExtra(CALL_STATUS, Call.STATE_NEW))
}
}
}
@ -109,7 +111,9 @@ class DialerActivity : SimpleActivity(), SensorEventListener {
private fun startNotificationService() {
Intent(this, DialerCallService::class.java).apply {
putExtra(CALLER_NUMBER, number)
putExtra(CALL_NUMBER, callNumber)
putExtra(CALL_STATUS, callStatus)
putExtra(IS_INCOMING_CALL, isIncomingCall)
startService(this)
}
}
@ -121,13 +125,14 @@ class DialerActivity : SimpleActivity(), SensorEventListener {
}
private fun hangUp() {
callStatus = Call.STATE_DISCONNECTED
stopNotificationService()
CallManager.declineCall()
finish()
}
private fun tryFillingOtherEndsName() {
ContactsHelper(this).getContactWithNumber(number) {
ContactsHelper(this).getContactWithNumber(callNumber) {
runOnUiThread {
updateOtherParticipant(it)
}
@ -135,6 +140,7 @@ class DialerActivity : SimpleActivity(), SensorEventListener {
}
private fun updateUI(status: Int) {
callStatus = status
when (status) {
Call.STATE_ACTIVE -> statusActive()
Call.STATE_DISCONNECTED -> statusDisconnected()
@ -142,11 +148,12 @@ class DialerActivity : SimpleActivity(), SensorEventListener {
}
private fun statusActive() {
startNotificationService()
isCallActive = true
dialer_call_duration.beVisible()
updateCallDuration()
dialer_label.text = ""
dialer_label.setText(R.string.ongoing_call)
dialer_hangup_button.beVisible()
dialer_incoming_accept.beGone()
dialer_incoming_decline.beGone()
@ -166,6 +173,7 @@ class DialerActivity : SimpleActivity(), SensorEventListener {
stopNotificationService()
timerHandler.removeCallbacksAndMessages(null)
dialer_hangup_button.beGone()
dialer_label.setText(R.string.disconnected)
if (isCallActive) {
dialer_hangup_button.postDelayed({
finish()
@ -179,9 +187,9 @@ class DialerActivity : SimpleActivity(), SensorEventListener {
private fun updateOtherParticipant(contact: Contact?) {
if (contact != null) {
dialer_big_name_number.text = contact.getNameToDisplay()
dialer_number.text = number
dialer_number.text = callNumber
} else {
dialer_big_name_number.text = number
dialer_big_name_number.text = callNumber
dialer_number.beGone()
}
}

View File

@ -34,8 +34,9 @@ const val KEY_NAME = "name"
// Dialer
const val INCOMING_CALL = "incoming_call"
const val CALLER_NUMBER = "caller_number"
const val CALL_NUMBER = "call_number"
const val CALL_STATUS = "call_status"
const val IS_INCOMING_CALL = "is_incoming_call"
const val DIALER_INTENT_FILTER = "dialer_intent_filter"
const val LOCATION_CONTACTS_TAB = 0

View File

@ -8,21 +8,29 @@ import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.Build
import android.telecom.Call
import androidx.core.app.NotificationCompat
import com.simplemobiletools.commons.helpers.isOreoPlus
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.DialerActivity
import com.simplemobiletools.contacts.pro.helpers.CALLER_NUMBER
import com.simplemobiletools.contacts.pro.helpers.CALL_NUMBER
import com.simplemobiletools.contacts.pro.helpers.CALL_STATUS
import com.simplemobiletools.contacts.pro.helpers.IS_INCOMING_CALL
class DialerCallService : Service() {
private val CALL_NOTIFICATION_ID = 1
private var number = ""
private var callNumber = ""
private var callStatus = Call.STATE_NEW
private var isIncomingCall = false
override fun onBind(intent: Intent?) = null
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
super.onStartCommand(intent, flags, startId)
number = intent.getStringExtra(CALLER_NUMBER)
callNumber = intent.getStringExtra(CALL_NUMBER)
callStatus = intent.getIntExtra(CALL_STATUS, Call.STATE_NEW)
isIncomingCall = intent.getBooleanExtra(IS_INCOMING_CALL, false)
setupNotification()
return START_STICKY
}
@ -38,7 +46,7 @@ class DialerCallService : Service() {
if (isOreoPlus()) {
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val name = resources.getString(R.string.app_name)
val importance = NotificationManager.IMPORTANCE_HIGH
val importance = NotificationManager.IMPORTANCE_DEFAULT
NotificationChannel(channelId, name, importance).apply {
enableLights(false)
enableVibration(false)
@ -47,14 +55,15 @@ class DialerCallService : Service() {
}
val notification = NotificationCompat.Builder(applicationContext, channelId)
.setSmallIcon(R.drawable.ic_person)
.setContentTitle(number)
.setContentText(getString(R.string.calling))
.setSmallIcon(R.drawable.ic_phone)
.setContentTitle(callNumber)
.setContentText(getCallStatusString())
.setContentIntent(getLaunchDialerIntent())
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setOngoing(true)
.setChannelId(channelId)
.setUsesChronometer(callStatus == Call.STATE_ACTIVE)
startForeground(CALL_NOTIFICATION_ID, notification.build())
}
@ -65,4 +74,12 @@ class DialerCallService : Service() {
intent.addCategory(Intent.CATEGORY_LAUNCHER)
return PendingIntent.getActivity(this, 0, intent, 0)
}
private fun getCallStatusString(): String {
return when (callStatus) {
Call.STATE_NEW -> applicationContext.getString(if (isIncomingCall) R.string.incoming_call else R.string.calling)
Call.STATE_ACTIVE -> applicationContext.getString(R.string.ongoing_call)
else -> ""
}
}
}

View File

@ -7,7 +7,7 @@ import android.telecom.Call
import android.telecom.InCallService
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.simplemobiletools.contacts.pro.activities.DialerActivity
import com.simplemobiletools.contacts.pro.helpers.CALLER_NUMBER
import com.simplemobiletools.contacts.pro.helpers.CALL_NUMBER
import com.simplemobiletools.contacts.pro.helpers.CALL_STATUS
import com.simplemobiletools.contacts.pro.helpers.DIALER_INTENT_FILTER
import com.simplemobiletools.contacts.pro.helpers.INCOMING_CALL
@ -30,7 +30,7 @@ class MyCallService : InCallService() {
Intent(this, DialerActivity::class.java).apply {
action = INCOMING_CALL
putExtra(CALL_STATUS, call.state)
putExtra(CALLER_NUMBER, callerNumber)
putExtra(CALL_NUMBER, callerNumber)
startActivity(this)
}
CallManager.updateCall(call)

View File

@ -113,6 +113,8 @@
<string name="dialer">Dialer</string>
<string name="calling">Calling…</string>
<string name="incoming_call">Incoming call from…</string>
<string name="ongoing_call">Ongoing call</string>
<string name="disconnected">Disconnected</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Göstərmək üçün sahəni seç</string>

View File

@ -113,6 +113,8 @@
<string name="dialer">Dialer</string>
<string name="calling">Calling…</string>
<string name="incoming_call">Incoming call from…</string>
<string name="ongoing_call">Ongoing call</string>
<string name="disconnected">Disconnected</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Sichtbare Felder auswählen</string>

View File

@ -113,6 +113,8 @@
<string name="dialer">Dialer</string>
<string name="calling">Calling…</string>
<string name="incoming_call">Incoming call from…</string>
<string name="ongoing_call">Ongoing call</string>
<string name="disconnected">Disconnected</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Επιλογή εμφάνισης πεδίων</string>

View File

@ -113,6 +113,8 @@
<string name="dialer">Dialer</string>
<string name="calling">Calling…</string>
<string name="incoming_call">Incoming call from…</string>
<string name="ongoing_call">Ongoing call</string>
<string name="disconnected">Disconnected</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Hautatu erakusteko eremuak</string>

View File

@ -113,6 +113,8 @@
<string name="dialer">Dialer</string>
<string name="calling">Calling…</string>
<string name="incoming_call">Incoming call from…</string>
<string name="ongoing_call">Ongoing call</string>
<string name="disconnected">Disconnected</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Sélectionner les champs à afficher</string>

View File

@ -113,6 +113,8 @@
<string name="dialer">Dialer</string>
<string name="calling">Calling…</string>
<string name="incoming_call">Incoming call from…</string>
<string name="ongoing_call">Ongoing call</string>
<string name="disconnected">Disconnected</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Odaberi polja za prikaz</string>

View File

@ -113,6 +113,8 @@
<string name="dialer">Compositore</string>
<string name="calling">Chiamata in corso…</string>
<string name="incoming_call">Incoming call from…</string>
<string name="ongoing_call">Ongoing call</string>
<string name="disconnected">Disconnected</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Seleziona i campi da mostrare</string>

View File

@ -113,6 +113,8 @@
<string name="dialer">Dialer</string>
<string name="calling">Calling…</string>
<string name="incoming_call">Incoming call from…</string>
<string name="ongoing_call">Ongoing call</string>
<string name="disconnected">Disconnected</string>
<!-- Visible fields -->
<string name="select_fields_to_show">表示する項目を選択</string>

View File

@ -113,6 +113,8 @@
<string name="dialer">Dialer</string>
<string name="calling">Calling…</string>
<string name="incoming_call">Incoming call from…</string>
<string name="ongoing_call">Ongoing call</string>
<string name="disconnected">Disconnected</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Select fields to show</string>

View File

@ -113,6 +113,8 @@
<string name="dialer">Dialer</string>
<string name="calling">Calling…</string>
<string name="incoming_call">Incoming call from…</string>
<string name="ongoing_call">Ongoing call</string>
<string name="disconnected">Disconnected</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Pasirinkti rodomus laukelius</string>

View File

@ -113,6 +113,8 @@
<string name="dialer">Dialer</string>
<string name="calling">Calling…</string>
<string name="incoming_call">Incoming call from…</string>
<string name="ongoing_call">Ongoing call</string>
<string name="disconnected">Disconnected</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Selecione os campos a mostrar</string>

View File

@ -113,6 +113,8 @@
<string name="dialer">Dialer</string>
<string name="calling">Calling…</string>
<string name="incoming_call">Incoming call from…</string>
<string name="ongoing_call">Ongoing call</string>
<string name="disconnected">Disconnected</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Выберите отображаемые поля</string>

View File

@ -113,6 +113,8 @@
<string name="dialer">Telefón</string>
<string name="calling">Vytáča sa…</string>
<string name="incoming_call">Prichádzajúci hovor od…</string>
<string name="ongoing_call">Prebiehajúci hovor</string>
<string name="disconnected">Ukončený hovor</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Zvoľte polia na zobrazenie</string>

View File

@ -113,6 +113,8 @@
<string name="dialer">Dialer</string>
<string name="calling">Calling…</string>
<string name="incoming_call">Incoming call from…</string>
<string name="ongoing_call">Ongoing call</string>
<string name="disconnected">Disconnected</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Välj vilka fält som ska visas</string>

View File

@ -113,6 +113,8 @@
<string name="dialer">Dialer</string>
<string name="calling">Calling…</string>
<string name="incoming_call">Incoming call from…</string>
<string name="ongoing_call">Ongoing call</string>
<string name="disconnected">Disconnected</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Görüntülenecek alanları seç</string>

View File

@ -113,6 +113,8 @@
<string name="dialer">Dialer</string>
<string name="calling">Calling…</string>
<string name="incoming_call">Incoming call from…</string>
<string name="ongoing_call">Ongoing call</string>
<string name="disconnected">Disconnected</string>
<!-- Visible fields -->
<string name="select_fields_to_show">選擇要顯示的欄位</string>

View File

@ -113,6 +113,8 @@
<string name="dialer">Dialer</string>
<string name="calling">Calling…</string>
<string name="incoming_call">Incoming call from…</string>
<string name="ongoing_call">Ongoing call</string>
<string name="disconnected">Disconnected</string>
<!-- Visible fields -->
<string name="select_fields_to_show">Select fields to show</string>