From 2284b762a8a4f0843d073343fd63ff32dedb36c2 Mon Sep 17 00:00:00 2001 From: domi04151309 <36272047+Domi04151309@users.noreply.github.com> Date: Sun, 9 Feb 2025 20:04:40 +0100 Subject: [PATCH] Force brighter colours Co-Authored-By: Rich <21251286+rlees85@users.noreply.github.com> --- .../alwayson/helpers/ColorHelper.kt | 24 +++++++++++++++++++ .../alwayson/services/NotificationService.kt | 3 ++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/io/github/domi04151309/alwayson/helpers/ColorHelper.kt diff --git a/app/src/main/java/io/github/domi04151309/alwayson/helpers/ColorHelper.kt b/app/src/main/java/io/github/domi04151309/alwayson/helpers/ColorHelper.kt new file mode 100644 index 00000000..25f5e578 --- /dev/null +++ b/app/src/main/java/io/github/domi04151309/alwayson/helpers/ColorHelper.kt @@ -0,0 +1,24 @@ +package io.github.domi04151309.alwayson.helpers; + +import android.graphics.Color +import kotlin.math.roundToInt + +object ColorHelper { + fun boostColor(color: Int): Int { + val colorRed: Int = Color.red(color) + val colorGreen: Int = Color.green(color) + val colorBlue: Int = Color.blue(color) + + return if (colorRed < 1 && colorGreen < 1 && colorBlue < 1) { + Color.WHITE + } else { + val rgbMax: Int = maxOf(colorRed, colorGreen, colorBlue) + val rgbFactor: Float = 255 / rgbMax.toFloat() + val boostedRed: Int = minOf(255, (colorRed * rgbFactor).roundToInt()) + val boostedGreen: Int = minOf(255, (colorGreen * rgbFactor).roundToInt()) + val boostedBlue: Int = minOf(255, (colorBlue * rgbFactor).roundToInt()) + Color.rgb(boostedRed, boostedGreen, boostedBlue) + } + } +} + diff --git a/app/src/main/java/io/github/domi04151309/alwayson/services/NotificationService.kt b/app/src/main/java/io/github/domi04151309/alwayson/services/NotificationService.kt index bb57205d..2e02bef7 100644 --- a/app/src/main/java/io/github/domi04151309/alwayson/services/NotificationService.kt +++ b/app/src/main/java/io/github/domi04151309/alwayson/services/NotificationService.kt @@ -10,6 +10,7 @@ import android.service.notification.StatusBarNotification import android.util.Log import androidx.preference.PreferenceManager import io.github.domi04151309.alwayson.actions.alwayson.AlwaysOn +import io.github.domi04151309.alwayson.helpers.ColorHelper import io.github.domi04151309.alwayson.helpers.Global import io.github.domi04151309.alwayson.helpers.JSON import io.github.domi04151309.alwayson.helpers.Rules @@ -84,7 +85,7 @@ class NotificationService : NotificationListenerService() { icons.add( Pair( notification.notification.smallIcon, - notification.notification.color, + ColorHelper.boostColor(notification.notification.color), ), ) }