From 8472712b3e2009f47cea6bc2f1e3f585747c19a6 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 16 Apr 2020 20:26:46 +0200 Subject: [PATCH] play notification sound pre notification categories --- .../services/NotificationService.java | 26 ++++++++++++++++++- .../conversations/utils/Compatibility.java | 4 ++- src/main/res/values/defaults.xml | 1 + src/main/res/values/strings.xml | 6 +++-- src/main/res/xml/preferences.xml | 10 +++++-- 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index b6257cf92..ee35e00a8 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -355,7 +355,9 @@ public class NotificationService { builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); builder.setPriority(NotificationCompat.PRIORITY_HIGH); builder.setCategory(NotificationCompat.CATEGORY_CALL); - builder.setFullScreenIntent(createPendingRtpSession(id, Intent.ACTION_VIEW, 101), true); + PendingIntent pendingIntent = createPendingRtpSession(id, Intent.ACTION_VIEW, 101); + builder.setFullScreenIntent(pendingIntent, true); + builder.setContentIntent(pendingIntent); //old androids need this? builder.setOngoing(true); builder.addAction(new NotificationCompat.Action.Builder( R.drawable.ic_call_end_white_48dp, @@ -367,6 +369,7 @@ public class NotificationService { mXmppConnectionService.getString(R.string.answer_call), createPendingRtpSession(id, RtpSessionActivity.ACTION_ACCEPT_CALL, 103)) .build()); + modifyIncomingCall(builder); final Notification notification = builder.build(); notification.flags = notification.flags | Notification.FLAG_INSISTENT; notify(INCOMING_CALL_NOTIFICATION_ID, notification); @@ -570,6 +573,27 @@ public class NotificationService { } } + private void modifyIncomingCall(Builder mBuilder) { + final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mXmppConnectionService); + final Resources resources = mXmppConnectionService.getResources(); + final String ringtone = preferences.getString("call_ringtone", resources.getString(R.string.incoming_call_ringtone)); + final int dat = 70; + final long[] pattern = {0, 3 * dat, dat, dat, 3 * dat, dat, dat}; + mBuilder.setVibrate(pattern); + Uri uri = Uri.parse(ringtone); + try { + mBuilder.setSound(fixRingtoneUri(uri)); + } catch (SecurityException e) { + Log.d(Config.LOGTAG, "unable to use custom notification sound " + uri.toString()); + } + if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + mBuilder.setCategory(Notification.CATEGORY_MESSAGE); + } + mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); + setNotificationColor(mBuilder); + mBuilder.setLights(LED_COLOR, 2000, 3000); + } + private Uri fixRingtoneUri(Uri uri) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && "file".equals(uri.getScheme())) { return FileBackend.getUriForFile(mXmppConnectionService, new File(uri.getPath())); diff --git a/src/main/java/eu/siacs/conversations/utils/Compatibility.java b/src/main/java/eu/siacs/conversations/utils/Compatibility.java index 9f7b9c997..3389d7519 100644 --- a/src/main/java/eu/siacs/conversations/utils/Compatibility.java +++ b/src/main/java/eu/siacs/conversations/utils/Compatibility.java @@ -30,7 +30,9 @@ public class Compatibility { "led", "notification_ringtone", "notification_headsup", - "vibrate_on_notification"); + "vibrate_on_notification", + "call_ringtone" + ); private static final List UNUESD_SETTINGS_PRE_TWENTYSIX = Collections.singletonList("more_notification_settings"); diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml index 3c1de4ebc..ebfdf5672 100644 --- a/src/main/res/values/defaults.xml +++ b/src/main/res/values/defaults.xml @@ -14,6 +14,7 @@ true false content://settings/system/notification_sound + content://settings/system/ringtone 144 524288 auto diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 6cdab665b..1ac409fdc 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -116,8 +116,10 @@ Vibrate when a new message arrives LED Notification Blink notification light when a new message arrives - Ringtone - Play sound when a new message arrives + Ringtone + Notification sound + Notification sound for new messages + Ringtone for incoming call Grace Period The length of time notifications are silenced after detecting activity on one of your other devices. Advanced diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index 31c2f8b08..3ef7b10b2 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -117,8 +117,14 @@ android:defaultValue="@string/notification_ringtone" android:key="notification_ringtone" android:ringtoneType="notification" - android:summary="@string/pref_sound_summary" - android:title="@string/pref_sound" /> + android:summary="@string/pref_notification_sound_summary" + android:title="@string/pref_notification_sound" /> +