Skip to content

Commit

Permalink
Set notification icon background color
Browse files Browse the repository at this point in the history
..to the background color of the launcher icon; see comment.
  • Loading branch information
oakkitten committed Dec 24, 2024
1 parent 5acaf7c commit 3cd36f3
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import androidx.core.app.Person
import androidx.core.app.RemoteInput
import androidx.core.content.ContextCompat
import androidx.core.content.LocusIdCompat
import androidx.core.content.edit
import androidx.fragment.app.DialogFragment
Expand Down Expand Up @@ -72,6 +73,13 @@ private var myself = Person.Builder().setName("Me").build()
private val manager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager


// In dark mode, the icon color might be of the same hue but lighter than the original color.
// Note that even though the documentation says that setColor sets the background color of the icon,
// in some cases the foreground will be colored instead,
// particularly on stock Android, when coloring the small icon attached to the conversation icon.
val notificationIconBackgroundColor = ContextCompat.getColor(applicationContext, R.color.launcherIconKittyBackgroundColor)


fun initializeNotificator(context: Context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return

Expand Down Expand Up @@ -122,12 +130,12 @@ private val disconnectActionPendingIntent = PendingIntent.getService(
PendingIntent.FLAG_IMMUTABLE
)


@AnyThread fun showMainNotification(relay: RelayService, content: String) {
val builder = NotificationCompat.Builder(
applicationContext, CHANNEL_CONNECTION_STATUS)
.setContentIntent(connectionStatusTapPendingIntent)
.setSmallIcon(R.drawable.ic_notification_main)
.setColor(notificationIconBackgroundColor)
.setCategory(NotificationCompat.CATEGORY_SERVICE)
.setWhen(System.currentTimeMillis())
.setPriority(Notification.PRIORITY_MIN)
Expand Down Expand Up @@ -353,6 +361,7 @@ private fun makeSummaryNotification(hotBuffers: Collection<HotlistBuffer>): Noti
val builder = NotificationCompat.Builder(applicationContext, CHANNEL_HOTLIST)
.setContentIntent(summaryNotificationIntent)
.setSmallIcon(R.drawable.ic_notification_hot)
.setColor(notificationIconBackgroundColor)
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setGroup(GROUP_KEY)
.setGroupSummary(true)
Expand Down Expand Up @@ -408,6 +417,7 @@ private fun makeBufferNotification(hotBuffer: HotlistBuffer, addReplyAction: Boo
.setContentIntent(makeActivityIntent<WeechatActivity>(hotBuffer.pointer))
.setDeleteIntent(makeBroadcastIntent<NotificationDismissedReceiver>(hotBuffer.pointer))
.setSmallIcon(R.drawable.ic_notification_hot)
.setColor(notificationIconBackgroundColor)
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setGroup(GROUP_KEY)
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN)
Expand Down Expand Up @@ -458,6 +468,7 @@ private fun makeEmptyBufferNotification(fullName: String): NotificationCompat.Bu

return NotificationCompat.Builder(applicationContext, CHANNEL_HOTLIST)
.setSmallIcon(R.drawable.ic_notification_hot)
.setColor(notificationIconBackgroundColor)
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setGroup(GROUP_KEY)
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN)
Expand Down

0 comments on commit 3cd36f3

Please sign in to comment.