redesigning the Incoming Call notification, add colored icons

This commit is contained in:
tibbi 2018-11-27 12:19:05 +01:00
parent 7cdefe43d5
commit 012442a057
4 changed files with 87 additions and 5 deletions

View File

@ -10,7 +10,10 @@ import android.content.Intent
import android.os.Build
import android.os.Handler
import android.telecom.Call
import android.widget.RemoteViews
import androidx.core.app.NotificationCompat
import com.simplemobiletools.commons.extensions.getColoredBitmap
import com.simplemobiletools.commons.extensions.setText
import com.simplemobiletools.commons.helpers.isOreoPlus
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.DialerActivity
@ -67,19 +70,32 @@ class DialerCallService : Service() {
}
}
val notificationLayout = RemoteViews(packageName, R.layout.incoming_call_notification).apply {
setText(R.id.incoming_call_caller, callNumber)
setText(R.id.incoming_call_status, getCallStatusString())
val resources = applicationContext.resources
setImageViewBitmap(R.id.call_decline, resources.getColoredBitmap(R.drawable.ic_phone_down, resources.getColor(R.color.theme_dark_red_primary_color)))
setImageViewBitmap(R.id.call_answer, resources.getColoredBitmap(R.drawable.ic_phone, resources.getColor(R.color.md_green_700)))
setOnClickPendingIntent(R.id.call_decline, getDeclineCallIntent())
setOnClickPendingIntent(R.id.call_answer, getAnswerCallIntent())
}
val notification = NotificationCompat.Builder(applicationContext, channelId)
.setSmallIcon(R.drawable.ic_phone)
.setContentTitle(callNumber)
.setContentText(getCallStatusString())
.setContentIntent(getLaunchDialerIntent())
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setCustomContentView(notificationLayout)
.setCustomHeadsUpContentView(notificationLayout)
.setCustomBigContentView(notificationLayout)
.setOngoing(true)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setChannelId(channelId)
.setSound(null)
.setOnlyAlertOnce(true)
.setUsesChronometer(callStatus == Call.STATE_ACTIVE)
.addAction(0, getString(R.string.decline_call), getDeclineCallIntent())
.addAction(0, getString(R.string.answer_call), getAnswerCallIntent())
startForeground(CALL_NOTIFICATION_ID, notification.build())

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple
xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/ripple_grey">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="@color/ripple_grey"/>
</shape>
</item>
</ripple>

View File

@ -0,0 +1,55 @@
<?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/call_notification_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/incoming_call_caller"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/normal_margin"
android:paddingLeft="@dimen/activity_margin"
android:textSize="@dimen/bigger_text_size"
android:textStyle="bold"
tools:text="John"/>
<TextView
android:id="@+id/incoming_call_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/incoming_call_caller"
android:layout_marginBottom="@dimen/small_margin"
android:paddingLeft="@dimen/activity_margin"
android:textSize="@dimen/normal_text_size"
tools:text="Incoming call"/>
<LinearLayout
android:id="@+id/call_notification_actions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/incoming_call_status"
android:orientation="horizontal">
<ImageView
android:id="@+id/call_decline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/ripple"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_phone_down"/>
<ImageView
android:id="@+id/call_answer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/ripple"
android:padding="@dimen/medium_margin"
android:src="@drawable/ic_phone"/>
</LinearLayout>
</RelativeLayout>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ripple_grey">#55000000</color>
</resources>