From bef39f7e0c86d545d22aaa8c7caf7e460c539dd0 Mon Sep 17 00:00:00 2001 From: kosyak Date: Wed, 27 Dec 2023 01:08:35 +0100 Subject: [PATCH] led color follows current app primary colort --- .../services/NotificationService.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index dc265755d..d5289f367 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -13,6 +13,7 @@ import android.content.SharedPreferences; import android.content.pm.ShortcutManager; import android.content.res.Resources; import android.graphics.Bitmap; +import android.graphics.Color; import android.graphics.Typeface; import android.media.AudioAttributes; import android.media.Ringtone; @@ -28,6 +29,7 @@ import android.text.style.StyleSpan; import android.util.DisplayMetrics; import android.util.Log; +import androidx.annotation.ColorInt; import androidx.annotation.RequiresApi; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat.BigPictureStyle; @@ -93,8 +95,6 @@ public class NotificationService { public static final Object CATCHUP_LOCK = new Object(); - private static final int LED_COLOR = 0xff00ff00; - private static final long[] CALL_PATTERN = {0, 500, 300, 600}; private static final String MESSAGES_GROUP = "eu.siacs.conversations.messages"; @@ -216,7 +216,7 @@ public class NotificationService { NotificationManager.IMPORTANCE_HIGH); incomingCallsChannel.setSound(null, null); incomingCallsChannel.setShowBadge(false); - incomingCallsChannel.setLightColor(LED_COLOR); + incomingCallsChannel.setLightColor(getPrimaryColor()); incomingCallsChannel.enableLights(true); incomingCallsChannel.setGroup("calls"); incomingCallsChannel.setBypassDnd(true); @@ -239,7 +239,7 @@ public class NotificationService { NotificationManager.IMPORTANCE_HIGH); missedCallsChannel.setShowBadge(true); missedCallsChannel.setSound(null, null); - missedCallsChannel.setLightColor(LED_COLOR); + missedCallsChannel.setLightColor(getPrimaryColor()); missedCallsChannel.enableLights(true); missedCallsChannel.setGroup("calls"); notificationManager.createNotificationChannel(missedCallsChannel); @@ -256,7 +256,7 @@ public class NotificationService { .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT) .build()); - messagesChannel.setLightColor(LED_COLOR); + messagesChannel.setLightColor(getPrimaryColor()); final int dat = 70; final long[] pattern = {0, 3 * dat, dat, dat}; messagesChannel.setVibrationPattern(pattern); @@ -272,7 +272,7 @@ public class NotificationService { silentMessagesChannel.setDescription( c.getString(R.string.silent_messages_channel_description)); silentMessagesChannel.setShowBadge(true); - silentMessagesChannel.setLightColor(LED_COLOR); + silentMessagesChannel.setLightColor(getPrimaryColor()); silentMessagesChannel.enableLights(true); silentMessagesChannel.setGroup("chats"); notificationManager.createNotificationChannel(silentMessagesChannel); @@ -283,7 +283,7 @@ public class NotificationService { c.getString(R.string.title_pref_quiet_hours), NotificationManager.IMPORTANCE_LOW); quietHoursChannel.setShowBadge(true); - quietHoursChannel.setLightColor(LED_COLOR); + quietHoursChannel.setLightColor(getPrimaryColor()); quietHoursChannel.enableLights(true); quietHoursChannel.setGroup("chats"); quietHoursChannel.enableVibration(false); @@ -831,8 +831,13 @@ public class NotificationService { } private void setNotificationColor(final Builder mBuilder) { + mBuilder.setColor(getPrimaryColor()); + } + + @ColorInt + private int getPrimaryColor() { Integer primaryColorOverride = ThemeHelper.getOverriddenPrimaryColor(mXmppConnectionService); - mBuilder.setColor(primaryColorOverride == null ? ContextCompat.getColor(mXmppConnectionService, R.color.green600) : primaryColorOverride); + return primaryColorOverride == null ? ContextCompat.getColor(mXmppConnectionService, R.color.green600) : primaryColorOverride; } public void updateNotification() { @@ -972,14 +977,14 @@ public class NotificationService { setNotificationColor(mBuilder); mBuilder.setDefaults(0); if (led) { - mBuilder.setLights(LED_COLOR, 2000, 3000); + mBuilder.setLights(getPrimaryColor(), 2000, 3000); } } private void modifyIncomingCall(final Builder mBuilder) { mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); setNotificationColor(mBuilder); - mBuilder.setLights(LED_COLOR, 2000, 3000); + mBuilder.setLights(getPrimaryColor(), 2000, 3000); } private Uri fixRingtoneUri(Uri uri) { @@ -1104,7 +1109,7 @@ public class NotificationService { final Resources resources = mXmppConnectionService.getResources(); final boolean led = preferences.getBoolean("led", resources.getBoolean(R.bool.led)); if (led) { - builder.setLights(LED_COLOR, 2000, 3000); + builder.setLights(getPrimaryColor(), 2000, 3000); } builder.setPriority(NotificationCompat.PRIORITY_HIGH); builder.setSound(null);