diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index d5289f367..ad2ac2f67 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -13,7 +13,6 @@ 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; @@ -29,7 +28,6 @@ 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; @@ -95,6 +93,8 @@ public class NotificationService { 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 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(getPrimaryColor()); + incomingCallsChannel.setLightColor(LED_COLOR); 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(getPrimaryColor()); + missedCallsChannel.setLightColor(LED_COLOR); 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(getPrimaryColor()); + messagesChannel.setLightColor(LED_COLOR); 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(getPrimaryColor()); + silentMessagesChannel.setLightColor(LED_COLOR); 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(getPrimaryColor()); + quietHoursChannel.setLightColor(LED_COLOR); quietHoursChannel.enableLights(true); quietHoursChannel.setGroup("chats"); quietHoursChannel.enableVibration(false); @@ -411,8 +411,8 @@ public class NotificationService { private int getBacklogMessageCount(Account account) { int count = 0; for (Iterator> it = - mBacklogMessageCounter.entrySet().iterator(); - it.hasNext(); ) { + mBacklogMessageCounter.entrySet().iterator(); + it.hasNext(); ) { Map.Entry entry = it.next(); if (entry.getKey().getAccount() == account) { count += entry.getValue().get(); @@ -590,19 +590,19 @@ public class NotificationService { builder.setOngoing(true); builder.addAction( new NotificationCompat.Action.Builder( - R.drawable.ic_call_end_white_48dp, - mXmppConnectionService.getString(R.string.dismiss_call), - createCallAction( - id.sessionId, - XmppConnectionService.ACTION_DISMISS_CALL, - 102)) + R.drawable.ic_call_end_white_48dp, + mXmppConnectionService.getString(R.string.dismiss_call), + createCallAction( + id.sessionId, + XmppConnectionService.ACTION_DISMISS_CALL, + 102)) .build()); builder.addAction( new NotificationCompat.Action.Builder( - R.drawable.ic_call_white_24dp, - mXmppConnectionService.getString(R.string.answer_call), - createPendingRtpSession( - id, RtpSessionActivity.ACTION_ACCEPT_CALL, 103)) + R.drawable.ic_call_white_24dp, + mXmppConnectionService.getString(R.string.answer_call), + createPendingRtpSession( + id, RtpSessionActivity.ACTION_ACCEPT_CALL, 103)) .build()); modifyIncomingCall(builder); final Notification notification = builder.build(); @@ -641,10 +641,10 @@ public class NotificationService { builder.setOngoing(true); builder.addAction( new NotificationCompat.Action.Builder( - R.drawable.ic_call_end_white_48dp, - mXmppConnectionService.getString(R.string.hang_up), - createCallAction( - id.sessionId, XmppConnectionService.ACTION_END_CALL, 104)) + R.drawable.ic_call_end_white_48dp, + mXmppConnectionService.getString(R.string.hang_up), + createCallAction( + id.sessionId, XmppConnectionService.ACTION_END_CALL, 104)) .build()); builder.setLocalOnly(true); return builder.build(); @@ -831,13 +831,8 @@ public class NotificationService { } private void setNotificationColor(final Builder mBuilder) { - mBuilder.setColor(getPrimaryColor()); - } - - @ColorInt - private int getPrimaryColor() { 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() { @@ -865,7 +860,7 @@ public class NotificationService { notify && conversations != null && conversations.size() - == 1; // if this check is changed to > 0 catchup messages will + == 1; // if this check is changed to > 0 catchup messages will // create one notification per conversation if (notifications.size() == 0) { @@ -971,20 +966,20 @@ public class NotificationService { mBuilder.setPriority( notify ? (headsup - ? NotificationCompat.PRIORITY_HIGH - : NotificationCompat.PRIORITY_DEFAULT) + ? NotificationCompat.PRIORITY_HIGH + : NotificationCompat.PRIORITY_DEFAULT) : NotificationCompat.PRIORITY_LOW); setNotificationColor(mBuilder); mBuilder.setDefaults(0); if (led) { - mBuilder.setLights(getPrimaryColor(), 2000, 3000); + mBuilder.setLights(LED_COLOR, 2000, 3000); } } private void modifyIncomingCall(final Builder mBuilder) { mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); setNotificationColor(mBuilder); - mBuilder.setLights(getPrimaryColor(), 2000, 3000); + mBuilder.setLights(LED_COLOR, 2000, 3000); } private Uri fixRingtoneUri(Uri uri) { @@ -1019,17 +1014,17 @@ public class NotificationService { (totalCalls == 1) ? mXmppConnectionService.getString(R.string.missed_call) : (mMissedCalls.size() == 1) - ? mXmppConnectionService - .getResources() - .getQuantityString( - R.plurals.n_missed_calls, totalCalls, totalCalls) - : mXmppConnectionService - .getResources() - .getQuantityString( - R.plurals.n_missed_calls_from_m_contacts, - mMissedCalls.size(), - totalCalls, - mMissedCalls.size()); + ? mXmppConnectionService + .getResources() + .getQuantityString( + R.plurals.n_missed_calls, totalCalls, totalCalls) + : mXmppConnectionService + .getResources() + .getQuantityString( + R.plurals.n_missed_calls_from_m_contacts, + mMissedCalls.size(), + totalCalls, + mMissedCalls.size()); builder.setContentTitle(title); builder.setTicker(title); if (!publicVersion) { @@ -1065,11 +1060,11 @@ public class NotificationService { (info.getNumberOfCalls() == 1) ? mXmppConnectionService.getString(R.string.missed_call) : mXmppConnectionService - .getResources() - .getQuantityString( - R.plurals.n_missed_calls, - info.getNumberOfCalls(), - info.getNumberOfCalls()); + .getResources() + .getQuantityString( + R.plurals.n_missed_calls, + info.getNumberOfCalls(), + info.getNumberOfCalls()); builder.setContentTitle(title); final String name = conversation.getContact().getDisplayName(); if (publicVersion) { @@ -1109,7 +1104,7 @@ public class NotificationService { final Resources resources = mXmppConnectionService.getResources(); final boolean led = preferences.getBoolean("led", resources.getBoolean(R.bool.led)); if (led) { - builder.setLights(getPrimaryColor(), 2000, 3000); + builder.setLights(LED_COLOR, 2000, 3000); } builder.setPriority(NotificationCompat.PRIORITY_HIGH); builder.setSound(null); @@ -1145,9 +1140,9 @@ public class NotificationService { name + ": " + mXmppConnectionService - .getResources() - .getQuantityString( - R.plurals.x_messages, count, count)); + .getResources() + .getQuantityString( + R.plurals.x_messages, count, count)); styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0); style.addLine(styledString); } else { @@ -1156,8 +1151,8 @@ public class NotificationService { name + ": " + UIHelper.getMessagePreview( - mXmppConnectionService, messages.get(0)) - .first); + mXmppConnectionService, messages.get(0)) + .first); styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0); style.addLine(styledString); } @@ -1223,9 +1218,9 @@ public class NotificationService { PendingIntent markAsReadPendingIntent = createReadPendingIntent(conversation); NotificationCompat.Action markReadAction = new NotificationCompat.Action.Builder( - R.drawable.ic_drafts_white_24dp, - mXmppConnectionService.getString(R.string.mark_as_read), - markAsReadPendingIntent) + R.drawable.ic_drafts_white_24dp, + mXmppConnectionService.getString(R.string.mark_as_read), + markAsReadPendingIntent) .setSemanticAction( NotificationCompat.Action.SEMANTIC_ACTION_MARK_AS_READ) .setShowsUserInterface(false) @@ -1234,18 +1229,18 @@ public class NotificationService { final String lastMessageUuid = Iterables.getLast(messages).getUuid(); final NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder( - R.drawable.ic_send_text_offline, - replyLabel, - createReplyIntent(conversation, lastMessageUuid, false)) + R.drawable.ic_send_text_offline, + replyLabel, + createReplyIntent(conversation, lastMessageUuid, false)) .setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_REPLY) .setShowsUserInterface(false) .addRemoteInput(remoteInput) .build(); final NotificationCompat.Action wearReplyAction = new NotificationCompat.Action.Builder( - R.drawable.ic_wear_reply, - replyLabel, - createReplyIntent(conversation, lastMessageUuid, true)) + R.drawable.ic_wear_reply, + replyLabel, + createReplyIntent(conversation, lastMessageUuid, true)) .addRemoteInput(remoteInput) .build(); mBuilder.extend( @@ -1262,9 +1257,9 @@ public class NotificationService { PendingIntent pendingSnoozeIntent = createSnoozeIntent(conversation); NotificationCompat.Action snoozeAction = new NotificationCompat.Action.Builder( - R.drawable.ic_notifications_paused_white_24dp, - label, - pendingSnoozeIntent) + R.drawable.ic_notifications_paused_white_24dp, + label, + pendingSnoozeIntent) .build(); mBuilder.addAction(snoozeAction); ++addedActionsCount; @@ -1281,9 +1276,9 @@ public class NotificationService { .getString(R.string.show_location); NotificationCompat.Action locationAction = new NotificationCompat.Action.Builder( - R.drawable.ic_room_white_24dp, - label, - pendingShowLocationIntent) + R.drawable.ic_room_white_24dp, + label, + pendingShowLocationIntent) .build(); mBuilder.addAction(locationAction); ++addedActionsCount; @@ -1305,9 +1300,9 @@ public class NotificationService { createDownloadIntent(firstDownloadableMessage); NotificationCompat.Action downloadAction = new NotificationCompat.Action.Builder( - R.drawable.ic_file_download_white_24dp, - label, - pendingDownloadIntent) + R.drawable.ic_file_download_white_24dp, + label, + pendingDownloadIntent) .build(); mBuilder.addAction(downloadAction); ++addedActionsCount; @@ -1455,7 +1450,7 @@ public class NotificationService { new NotificationCompat.BigTextStyle().bigText(getMergedBodies(messages))); final CharSequence preview = UIHelper.getMessagePreview( - mXmppConnectionService, messages.get(messages.size() - 1)) + mXmppConnectionService, messages.get(messages.size() - 1)) .first; builder.setContentText(preview); builder.setTicker(preview); @@ -1823,7 +1818,7 @@ public class NotificationService { if (account.hasErrorStatus() && account.showErrorNotification() && (showAllErrors - || account.getLastErrorStatus() == Account.State.UNAUTHORIZED)) { + || account.getLastErrorStatus() == Account.State.UNAUTHORIZED)) { errors.add(account); torNotAvailable |= account.getStatus() == Account.State.TOR_NOT_AVAILABLE; } @@ -1859,7 +1854,7 @@ public class NotificationService { TorServiceUtils.LAUNCH_INTENT, s() ? PendingIntent.FLAG_IMMUTABLE - | PendingIntent.FLAG_UPDATE_CURRENT + | PendingIntent.FLAG_UPDATE_CURRENT : PendingIntent.FLAG_UPDATE_CURRENT)); } else { mBuilder.addAction( @@ -1871,7 +1866,7 @@ public class NotificationService { TorServiceUtils.INSTALL_INTENT, s() ? PendingIntent.FLAG_IMMUTABLE - | PendingIntent.FLAG_UPDATE_CURRENT + | PendingIntent.FLAG_UPDATE_CURRENT : PendingIntent.FLAG_UPDATE_CURRENT)); } }