adding an initial implementation of the incoming call notification
This commit is contained in:
parent
d835c5d80b
commit
c7f5f454ef
10 changed files with 188 additions and 1 deletions
|
@ -57,7 +57,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:5.26.27'
|
||||
implementation 'com.simplemobiletools:commons:5.26.28'
|
||||
implementation 'joda-time:joda-time:2.10.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
|
||||
implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5'
|
||||
|
|
|
@ -265,6 +265,25 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name=".services.CallService"
|
||||
android:permission="android.permission.BIND_INCALL_SERVICE">
|
||||
<meta-data
|
||||
android:name="android.telecom.IN_CALL_SERVICE_UI"
|
||||
android:value="true" />
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.telecom.InCallService"/>
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<receiver android:name=".receivers.CallActionReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="com.simplemobiletools.contacts.action.ACCEPT_CALL"/>
|
||||
<action android:name="com.simplemobiletools.contacts.action.DECLINE_CALL"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.provider"
|
||||
|
|
|
@ -1,11 +1,26 @@
|
|||
package com.simplemobiletools.contacts.pro.activities
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Notification
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.RemoteViews
|
||||
import androidx.core.app.NotificationCompat
|
||||
import com.simplemobiletools.commons.extensions.notificationManager
|
||||
import com.simplemobiletools.commons.extensions.setText
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import com.simplemobiletools.commons.helpers.isOreoPlus
|
||||
import com.simplemobiletools.contacts.pro.R
|
||||
import com.simplemobiletools.contacts.pro.helpers.ACCEPT_CALL
|
||||
import com.simplemobiletools.contacts.pro.helpers.DECLINE_CALL
|
||||
import com.simplemobiletools.contacts.pro.receivers.CallActionReceiver
|
||||
import kotlinx.android.synthetic.main.activity_call.*
|
||||
|
||||
class CallActivity : SimpleActivity() {
|
||||
private val CALL_NOTIFICATION_ID = 1
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
supportActionBar?.hide()
|
||||
|
@ -14,6 +29,12 @@ class CallActivity : SimpleActivity() {
|
|||
|
||||
updateTextColors(call_holder)
|
||||
initButtons()
|
||||
showNotification()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
notificationManager.cancel(CALL_NOTIFICATION_ID)
|
||||
}
|
||||
|
||||
private fun initButtons() {
|
||||
|
@ -24,4 +45,55 @@ class CallActivity : SimpleActivity() {
|
|||
call_toggle_speaker.setOnClickListener { }
|
||||
call_dialpad.setOnClickListener { }
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private fun showNotification() {
|
||||
val channelId = "simple_contacts_call"
|
||||
if (isOreoPlus()) {
|
||||
val importance = NotificationManager.IMPORTANCE_HIGH
|
||||
val name = "call_notification_channel"
|
||||
|
||||
NotificationChannel(channelId, name, importance).apply {
|
||||
notificationManager.createNotificationChannel(this)
|
||||
}
|
||||
}
|
||||
|
||||
val openAppIntent = Intent(this, CallActivity::class.java)
|
||||
openAppIntent.flags = Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT
|
||||
val openAppPendingIntent = PendingIntent.getActivity(this, 0, openAppIntent, 0)
|
||||
|
||||
val acceptCallIntent = Intent(this, CallActionReceiver::class.java)
|
||||
acceptCallIntent.action = ACCEPT_CALL
|
||||
val acceptPendingIntent = PendingIntent.getBroadcast(this, 0, acceptCallIntent, PendingIntent.FLAG_CANCEL_CURRENT)
|
||||
|
||||
val declineCallIntent = Intent(this, CallActionReceiver::class.java)
|
||||
declineCallIntent.action = DECLINE_CALL
|
||||
val declinePendingIntent = PendingIntent.getBroadcast(this, 1, declineCallIntent, PendingIntent.FLAG_CANCEL_CURRENT)
|
||||
|
||||
val callerName = "Caller name"
|
||||
val contentText = getString(R.string.incoming_call)
|
||||
|
||||
val collapsedView = RemoteViews(packageName, R.layout.call_notification).apply {
|
||||
setText(R.id.notification_caller_name, callerName)
|
||||
setText(R.id.notification_caller_number, contentText)
|
||||
|
||||
setOnClickPendingIntent(R.id.notification_decline_call, declinePendingIntent)
|
||||
setOnClickPendingIntent(R.id.notification_accept_call, acceptPendingIntent)
|
||||
}
|
||||
|
||||
val builder = NotificationCompat.Builder(this, channelId)
|
||||
.setSmallIcon(R.drawable.ic_phone_vector)
|
||||
.setContentIntent(openAppPendingIntent)
|
||||
.setPriority(NotificationCompat.PRIORITY_MAX)
|
||||
.setDefaults(Notification.DEFAULT_LIGHTS)
|
||||
.setCategory(Notification.CATEGORY_EVENT)
|
||||
.setCustomContentView(collapsedView)
|
||||
.setOngoing(true)
|
||||
.setAutoCancel(true)
|
||||
.setChannelId(channelId)
|
||||
.setStyle(NotificationCompat.DecoratedCustomViewStyle())
|
||||
|
||||
val notification = builder.build()
|
||||
notificationManager.notify(CALL_NOTIFICATION_ID, notification)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,10 @@ const val ADD_NEW_CONTACT_NUMBER = "add_new_contact_number"
|
|||
const val FIRST_CONTACT_ID = 1000000
|
||||
const val FIRST_GROUP_ID = 10000L
|
||||
|
||||
private const val PATH = "com.simplemobiletools.contacts.action."
|
||||
const val ACCEPT_CALL = PATH + "accept_call"
|
||||
const val DECLINE_CALL = PATH + "decline_call"
|
||||
|
||||
// extras used at third party intents
|
||||
const val KEY_PHONE = "phone"
|
||||
const val KEY_NAME = "name"
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package com.simplemobiletools.contacts.pro.receivers
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
|
||||
class CallActionReceiver : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.simplemobiletools.contacts.pro.services
|
||||
|
||||
import android.os.Build
|
||||
import android.telecom.Call
|
||||
import android.telecom.InCallService
|
||||
import androidx.annotation.RequiresApi
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.M)
|
||||
class CallService : InCallService() {
|
||||
override fun onCallAdded(call: Call) {
|
||||
super.onCallAdded(call)
|
||||
}
|
||||
}
|
9
app/src/main/res/drawable/ic_phone_down_red_vector.xml
Normal file
9
app/src/main/res/drawable/ic_phone_down_red_vector.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@color/md_red_700"
|
||||
android:pathData="M23.4267,12.2343C20.4492,9.413 16.4272,7.6753 11.9951,7.6753c-4.4321,0 -8.4541,1.7377 -11.4316,4.559 -0.1757,0.1757 -0.2831,0.4198 -0.2831,0.6931 0,0.2733 0.1074,0.5174 0.2831,0.6931l2.421,2.421c0.1757,0.1757 0.4198,0.2831 0.6931,0.2831 0.2636,0 0.5076,-0.1074 0.6834,-0.2733 0.7712,-0.7224 1.6498,-1.3277 2.5968,-1.806 0.3222,-0.1562 0.5467,-0.4881 0.5467,-0.8786l0,-3.0263C8.92,9.8718 10.4332,9.6278 11.9951,9.6278c1.562,0 3.0751,0.2441 4.4906,0.7029l0,3.0263c0,0.3807 0.2245,0.7224 0.5467,0.8786 0.9567,0.4783 1.8255,1.0934 2.6065,1.806 0.1757,0.1757 0.4198,0.2733 0.6834,0.2733 0.2733,0 0.5174,-0.1074 0.6931,-0.2831l2.421,-2.421c0.1757,-0.1757 0.2831,-0.4198 0.2831,-0.6931 0,-0.2733 -0.1171,-0.5076 -0.2929,-0.6834z" />
|
||||
</vector>
|
9
app/src/main/res/drawable/ic_phone_green_vector.xml
Normal file
9
app/src/main/res/drawable/ic_phone_green_vector.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@color/md_green_700"
|
||||
android:pathData="M6.62,10.79c1.44,2.83 3.76,5.14 6.59,6.59l2.2,-2.2c0.27,-0.27 0.67,-0.36 1.02,-0.24 1.12,0.37 2.33,0.57 3.57,0.57 0.55,0 1,0.45 1,1V20c0,0.55 -0.45,1 -1,1 -9.39,0 -17,-7.61 -17,-17 0,-0.55 0.45,-1 1,-1h3.5c0.55,0 1,0.45 1,1 0,1.25 0.2,2.45 0.57,3.57 0.11,0.35 0.03,0.74 -0.25,1.02l-2.2,2.2z" />
|
||||
</vector>
|
49
app/src/main/res/layout/call_notification.xml
Normal file
49
app/src/main/res/layout/call_notification.xml
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/notification_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/notification_caller_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/md_grey_black"
|
||||
android:textSize="@dimen/bigger_text_size"
|
||||
android:textStyle="bold"
|
||||
tools:text="Caller name" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/notification_caller_number"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/notification_caller_name"
|
||||
android:alpha="0.8"
|
||||
android:textColor="@color/md_grey_black"
|
||||
tools:text="123 456 789" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/notification_actions_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/notification_caller_number"
|
||||
android:layout_marginTop="@dimen/medium_margin"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/notification_decline_call"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/call_notification_button_size"
|
||||
android:layout_weight="1"
|
||||
android:src="@drawable/ic_phone_down_red_vector" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/notification_accept_call"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/call_notification_button_size"
|
||||
android:layout_weight="1"
|
||||
android:src="@drawable/ic_phone_green_vector" />
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
|
@ -6,6 +6,7 @@
|
|||
<dimen name="min_row_height">60dp</dimen>
|
||||
<dimen name="dialpad_button_size">60dp</dimen>
|
||||
<dimen name="incoming_call_button_size">72dp</dimen>
|
||||
<dimen name="call_notification_button_size">30dp</dimen>
|
||||
|
||||
<dimen name="caller_name_text_size">26sp</dimen>
|
||||
<dimen name="caller_number_text_size">20sp</dimen>
|
||||
|
|
Loading…
Reference in a new issue