change notifications led color

This commit is contained in:
kosyak 2024-01-10 00:17:46 +01:00
parent 6872b36f74
commit 9b748a7b4f

View file

@ -13,7 +13,6 @@ import android.content.SharedPreferences;
import android.content.pm.ShortcutManager; import android.content.pm.ShortcutManager;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.media.AudioAttributes; import android.media.AudioAttributes;
import android.media.Ringtone; import android.media.Ringtone;
@ -29,7 +28,6 @@ import android.text.style.StyleSpan;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import androidx.annotation.ColorInt;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationCompat.BigPictureStyle; import androidx.core.app.NotificationCompat.BigPictureStyle;
@ -95,6 +93,8 @@ public class NotificationService {
public static final Object CATCHUP_LOCK = new Object(); public static final Object CATCHUP_LOCK = new Object();
private static final int LED_COLOR = 0xffffffff;
private static final long[] CALL_PATTERN = {0, 500, 300, 600}; private static final long[] CALL_PATTERN = {0, 500, 300, 600};
private static final String MESSAGES_GROUP = "eu.siacs.conversations.messages"; private static final String MESSAGES_GROUP = "eu.siacs.conversations.messages";
@ -216,7 +216,7 @@ public class NotificationService {
NotificationManager.IMPORTANCE_HIGH); NotificationManager.IMPORTANCE_HIGH);
incomingCallsChannel.setSound(null, null); incomingCallsChannel.setSound(null, null);
incomingCallsChannel.setShowBadge(false); incomingCallsChannel.setShowBadge(false);
incomingCallsChannel.setLightColor(getPrimaryColor()); incomingCallsChannel.setLightColor(LED_COLOR);
incomingCallsChannel.enableLights(true); incomingCallsChannel.enableLights(true);
incomingCallsChannel.setGroup("calls"); incomingCallsChannel.setGroup("calls");
incomingCallsChannel.setBypassDnd(true); incomingCallsChannel.setBypassDnd(true);
@ -239,7 +239,7 @@ public class NotificationService {
NotificationManager.IMPORTANCE_HIGH); NotificationManager.IMPORTANCE_HIGH);
missedCallsChannel.setShowBadge(true); missedCallsChannel.setShowBadge(true);
missedCallsChannel.setSound(null, null); missedCallsChannel.setSound(null, null);
missedCallsChannel.setLightColor(getPrimaryColor()); missedCallsChannel.setLightColor(LED_COLOR);
missedCallsChannel.enableLights(true); missedCallsChannel.enableLights(true);
missedCallsChannel.setGroup("calls"); missedCallsChannel.setGroup("calls");
notificationManager.createNotificationChannel(missedCallsChannel); notificationManager.createNotificationChannel(missedCallsChannel);
@ -256,7 +256,7 @@ public class NotificationService {
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT) .setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT)
.build()); .build());
messagesChannel.setLightColor(getPrimaryColor()); messagesChannel.setLightColor(LED_COLOR);
final int dat = 70; final int dat = 70;
final long[] pattern = {0, 3 * dat, dat, dat}; final long[] pattern = {0, 3 * dat, dat, dat};
messagesChannel.setVibrationPattern(pattern); messagesChannel.setVibrationPattern(pattern);
@ -272,7 +272,7 @@ public class NotificationService {
silentMessagesChannel.setDescription( silentMessagesChannel.setDescription(
c.getString(R.string.silent_messages_channel_description)); c.getString(R.string.silent_messages_channel_description));
silentMessagesChannel.setShowBadge(true); silentMessagesChannel.setShowBadge(true);
silentMessagesChannel.setLightColor(getPrimaryColor()); silentMessagesChannel.setLightColor(LED_COLOR);
silentMessagesChannel.enableLights(true); silentMessagesChannel.enableLights(true);
silentMessagesChannel.setGroup("chats"); silentMessagesChannel.setGroup("chats");
notificationManager.createNotificationChannel(silentMessagesChannel); notificationManager.createNotificationChannel(silentMessagesChannel);
@ -283,7 +283,7 @@ public class NotificationService {
c.getString(R.string.title_pref_quiet_hours), c.getString(R.string.title_pref_quiet_hours),
NotificationManager.IMPORTANCE_LOW); NotificationManager.IMPORTANCE_LOW);
quietHoursChannel.setShowBadge(true); quietHoursChannel.setShowBadge(true);
quietHoursChannel.setLightColor(getPrimaryColor()); quietHoursChannel.setLightColor(LED_COLOR);
quietHoursChannel.enableLights(true); quietHoursChannel.enableLights(true);
quietHoursChannel.setGroup("chats"); quietHoursChannel.setGroup("chats");
quietHoursChannel.enableVibration(false); quietHoursChannel.enableVibration(false);
@ -831,13 +831,8 @@ public class NotificationService {
} }
private void setNotificationColor(final Builder mBuilder) { private void setNotificationColor(final Builder mBuilder) {
mBuilder.setColor(getPrimaryColor());
}
@ColorInt
private int getPrimaryColor() {
Integer primaryColorOverride = ThemeHelper.getOverriddenPrimaryColor(mXmppConnectionService); Integer primaryColorOverride = ThemeHelper.getOverriddenPrimaryColor(mXmppConnectionService);
return primaryColorOverride == null ? ContextCompat.getColor(mXmppConnectionService, R.color.green600) : primaryColorOverride; mBuilder.setColor(primaryColorOverride == null ? ContextCompat.getColor(mXmppConnectionService, R.color.green600) : primaryColorOverride);
} }
public void updateNotification() { public void updateNotification() {
@ -977,14 +972,14 @@ public class NotificationService {
setNotificationColor(mBuilder); setNotificationColor(mBuilder);
mBuilder.setDefaults(0); mBuilder.setDefaults(0);
if (led) { if (led) {
mBuilder.setLights(getPrimaryColor(), 2000, 3000); mBuilder.setLights(LED_COLOR, 2000, 3000);
} }
} }
private void modifyIncomingCall(final Builder mBuilder) { private void modifyIncomingCall(final Builder mBuilder) {
mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
setNotificationColor(mBuilder); setNotificationColor(mBuilder);
mBuilder.setLights(getPrimaryColor(), 2000, 3000); mBuilder.setLights(LED_COLOR, 2000, 3000);
} }
private Uri fixRingtoneUri(Uri uri) { private Uri fixRingtoneUri(Uri uri) {
@ -1109,7 +1104,7 @@ public class NotificationService {
final Resources resources = mXmppConnectionService.getResources(); final Resources resources = mXmppConnectionService.getResources();
final boolean led = preferences.getBoolean("led", resources.getBoolean(R.bool.led)); final boolean led = preferences.getBoolean("led", resources.getBoolean(R.bool.led));
if (led) { if (led) {
builder.setLights(getPrimaryColor(), 2000, 3000); builder.setLights(LED_COLOR, 2000, 3000);
} }
builder.setPriority(NotificationCompat.PRIORITY_HIGH); builder.setPriority(NotificationCompat.PRIORITY_HIGH);
builder.setSound(null); builder.setSound(null);