aboutsummaryrefslogtreecommitdiff
path: root/notification
diff options
context:
space:
mode:
authorYuichi Araki <yaraki@google.com>2019-04-03 12:13:29 +0900
committerYuichi Araki <yaraki@google.com>2019-04-04 09:31:03 +0900
commit50c369645a56e7d356f86fcd35c95b9b9aae8e24 (patch)
tree81bb0902041b9ac6e3b6d087fcd29d641375adf1 /notification
parent7eeb89a225ccbe55a7703a4604dcd5d3e12bfcd6 (diff)
downloadandroid-50c369645a56e7d356f86fcd35c95b9b9aae8e24.tar.gz
Bubbles: Fix icon
Change-Id: I53097417c77970493da9d68cc66e83d9eb311a7f
Diffstat (limited to 'notification')
-rw-r--r--notification/Bubbles/app/src/main/java/com/example/android/bubbles/data/NotificationHelper.kt34
1 files changed, 6 insertions, 28 deletions
diff --git a/notification/Bubbles/app/src/main/java/com/example/android/bubbles/data/NotificationHelper.kt b/notification/Bubbles/app/src/main/java/com/example/android/bubbles/data/NotificationHelper.kt
index 825489c3..be81e9c8 100644
--- a/notification/Bubbles/app/src/main/java/com/example/android/bubbles/data/NotificationHelper.kt
+++ b/notification/Bubbles/app/src/main/java/com/example/android/bubbles/data/NotificationHelper.kt
@@ -22,17 +22,10 @@ import android.app.PendingIntent
import android.app.Person
import android.content.Context
import android.content.Intent
-import android.graphics.Bitmap
import android.graphics.BitmapFactory
-import android.graphics.BlendMode
-import android.graphics.Color
-import android.graphics.Paint
-import android.graphics.Rect
import android.graphics.drawable.Icon
import android.net.Uri
-import androidx.annotation.DrawableRes
import androidx.annotation.WorkerThread
-import androidx.core.graphics.applyCanvas
import com.example.android.bubbles.BubbleActivity
import com.example.android.bubbles.MainActivity
import com.example.android.bubbles.R
@@ -71,7 +64,12 @@ class NotificationHelper(private val context: Context) {
@WorkerThread
fun showNotification(chat: Chat, fromUser: Boolean) {
- val icon = Icon.createWithBitmap(roundIcon(context, chat.contact.icon))
+ val icon = Icon.createWithAdaptiveBitmap(
+ BitmapFactory.decodeResource(
+ context.resources,
+ chat.contact.icon
+ )
+ )
val person = Person.Builder()
.setName(chat.contact.name)
.setIcon(icon)
@@ -173,23 +171,3 @@ class NotificationHelper(private val context: Context) {
return notificationManager.areBubblesAllowed() && channel.canBubble()
}
}
-
-@WorkerThread
-private fun roundIcon(context: Context, @DrawableRes id: Int): Bitmap {
- val original = BitmapFactory.decodeResource(context.resources, id)
- val width = original.width
- val height = original.height
- val rect = Rect(0, 0, width, height)
- val icon = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888)
- val paint = Paint().apply {
- isAntiAlias = true
- color = Color.BLACK
- }
- icon.applyCanvas {
- drawARGB(0, 0, 0, 0)
- drawOval(0f, 0f, width.toFloat(), height.toFloat(), paint)
- paint.blendMode = BlendMode.SRC_IN
- drawBitmap(original, rect, rect, paint)
- }
- return icon
-}