adding a couple additional call screen related improvements

This commit is contained in:
tibbi
2018-11-20 22:50:42 +01:00
parent f5c645026f
commit 0b75543fda
2 changed files with 55 additions and 24 deletions

View File

@ -12,10 +12,7 @@ import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.os.PowerManager import android.os.PowerManager
import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.simplemobiletools.commons.extensions.beGone import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.extensions.beVisibleIf
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.contacts.pro.R import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.helpers.* import com.simplemobiletools.contacts.pro.helpers.*
import com.simplemobiletools.contacts.pro.models.Contact import com.simplemobiletools.contacts.pro.models.Contact
@ -26,6 +23,8 @@ import kotlinx.android.synthetic.main.activity_dialer.*
// incoming call handling inspired by https://github.com/mbarrben/android_dialer_replacement // incoming call handling inspired by https://github.com/mbarrben/android_dialer_replacement
class DialerActivity : SimpleActivity(), SensorEventListener { class DialerActivity : SimpleActivity(), SensorEventListener {
private val SENSOR_SENSITIVITY = 4 private val SENSOR_SENSITIVITY = 4
private val DISCONNECT_DELAY = 3000L
private var number = "" private var number = ""
private var isIncomingCall = false private var isIncomingCall = false
private var sensorManager: SensorManager? = null private var sensorManager: SensorManager? = null
@ -41,16 +40,13 @@ class DialerActivity : SimpleActivity(), SensorEventListener {
if (intent.action == Intent.ACTION_CALL && intent.data != null && intent.dataString?.contains("tel:") == true) { if (intent.action == Intent.ACTION_CALL && intent.data != null && intent.dataString?.contains("tel:") == true) {
number = Uri.decode(intent.dataString).substringAfter("tel:") number = Uri.decode(intent.dataString).substringAfter("tel:")
initViews() initViews()
ContactsHelper(this).getContactWithNumber(number) { tryFillingOtherEndsName()
runOnUiThread {
updateCallee(it)
}
}
} 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(CALLER_NUMBER) == true && intent.extras?.containsKey(CALL_STATUS) == true) {
isIncomingCall = true isIncomingCall = true
number = intent.getStringExtra(CALLER_NUMBER) number = intent.getStringExtra(CALLER_NUMBER)
initViews() initViews()
updateUI(intent.getSerializableExtra(CALL_STATUS) as GsmCall.Status) updateUI(intent.getSerializableExtra(CALL_STATUS) as GsmCall.Status)
tryFillingOtherEndsName()
} else { } else {
toast(R.string.unknown_error_occurred) toast(R.string.unknown_error_occurred)
finish() finish()
@ -88,28 +84,63 @@ class DialerActivity : SimpleActivity(), SensorEventListener {
} }
private fun initViews() { private fun initViews() {
dialer_hangup_button.setOnClickListener { CallManager.declineCall() } dialer_hangup_button.setOnClickListener {
dialer_incoming_accept.setOnClickListener { CallManager.acceptCall() } CallManager.declineCall()
dialer_incoming_decline.setOnClickListener { CallManager.declineCall() } finish()
}
dialer_incoming_accept.setOnClickListener {
CallManager.acceptCall()
}
dialer_incoming_decline.setOnClickListener {
CallManager.declineCall()
finish()
}
dialer_hangup_button.beVisibleIf(!isIncomingCall) dialer_hangup_button.beVisibleIf(!isIncomingCall)
dialer_incoming_decline.beVisibleIf(isIncomingCall) dialer_incoming_decline.beVisibleIf(isIncomingCall)
dialer_incoming_accept.beVisibleIf(isIncomingCall) dialer_incoming_accept.beVisibleIf(isIncomingCall)
calling_label.setText(if (isIncomingCall) R.string.incoming_call else R.string.calling) dialer_label.setText(if (isIncomingCall) R.string.incoming_call else R.string.calling)
}
private fun tryFillingOtherEndsName() {
ContactsHelper(this).getContactWithNumber(number) {
runOnUiThread {
updateOtherParticipant(it)
}
}
} }
private fun updateUI(status: GsmCall.Status) { private fun updateUI(status: GsmCall.Status) {
when (status) {
GsmCall.Status.ACTIVE -> statusActive()
GsmCall.Status.DISCONNECTED -> statusDisconnected()
}
} }
private fun updateCallee(contact: Contact?) { private fun statusActive() {
dialer_label.text = ""
dialer_hangup_button.beVisible()
dialer_incoming_accept.beGone()
dialer_incoming_decline.beGone()
}
private fun statusDisconnected() {
dialer_hangup_button.beGone()
dialer_hangup_button.postDelayed({
finish()
}, DISCONNECT_DELAY)
}
private fun updateOtherParticipant(contact: Contact?) {
if (contact != null) { if (contact != null) {
callee_big_name_number.text = contact.getNameToDisplay() dialer_big_name_number.text = contact.getNameToDisplay()
callee_number.text = number dialer_number.text = number
} else { } else {
callee_big_name_number.text = number dialer_big_name_number.text = number
callee_number.beGone() dialer_number.beGone()
} }
} }

View File

@ -8,7 +8,7 @@
android:layout_height="match_parent"> android:layout_height="match_parent">
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/calling_label" android:id="@+id/dialer_label"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dialer_top_margin" android:layout_marginTop="@dimen/dialer_top_margin"
@ -20,7 +20,7 @@
app:layout_constraintTop_toTopOf="parent"/> app:layout_constraintTop_toTopOf="parent"/>
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/callee_big_name_number" android:id="@+id/dialer_big_name_number"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin" android:layout_marginTop="@dimen/medium_margin"
@ -30,11 +30,11 @@
android:textSize="@dimen/dialpad_text_size" android:textSize="@dimen/dialpad_text_size"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/calling_label" app:layout_constraintTop_toBottomOf="@+id/dialer_label"
tools:text="John"/> tools:text="John"/>
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/callee_number" android:id="@+id/dialer_number"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin" android:layout_marginTop="@dimen/medium_margin"
@ -44,7 +44,7 @@
android:textSize="@dimen/big_text_size" android:textSize="@dimen/big_text_size"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/callee_big_name_number" app:layout_constraintTop_toBottomOf="@+id/dialer_big_name_number"
tools:text="123 456 789"/> tools:text="123 456 789"/>
<ImageView <ImageView