play notification sound pre notification categories

Daniel Gultsch created

Change summary

src/main/java/eu/siacs/conversations/services/NotificationService.java | 26 
src/main/java/eu/siacs/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(-)

Detailed changes

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()));

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<String> UNUESD_SETTINGS_PRE_TWENTYSIX = Collections.singletonList("more_notification_settings");
 
 

src/main/res/values/defaults.xml 🔗

@@ -14,6 +14,7 @@
     <bool name="led">true</bool>
     <bool name="enable_quiet_hours">false</bool>
     <string name="notification_ringtone">content://settings/system/notification_sound</string>
+    <string name="incoming_call_ringtone">content://settings/system/ringtone</string>
     <integer name="grace_period">144</integer>
     <integer name="auto_accept_filesize">524288</integer>
     <string name="picture_compression">auto</string>

src/main/res/values/strings.xml 🔗

@@ -116,8 +116,10 @@
     <string name="pref_vibrate_summary">Vibrate when a new message arrives</string>
     <string name="pref_led">LED Notification</string>
     <string name="pref_led_summary">Blink notification light when a new message arrives</string>
-    <string name="pref_sound">Ringtone</string>
-    <string name="pref_sound_summary">Play sound when a new message arrives</string>
+    <string name="pref_ringtone">Ringtone</string>
+    <string name="pref_notification_sound">Notification sound</string>
+    <string name="pref_notification_sound_summary">Notification sound for new messages</string>
+    <string name="pref_call_ringtone_summary">Ringtone for incoming call</string>
     <string name="pref_notification_grace_period">Grace Period</string>
     <string name="pref_notification_grace_period_summary">The length of time notifications are silenced after detecting activity on one of your other devices.</string>
     <string name="pref_advanced_options">Advanced</string>

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" />
+        <RingtonePreference
+            android:defaultValue="@string/notification_ringtone"
+            android:key="call_ringtone"
+            android:ringtoneType="ringtone"
+            android:summary="@string/pref_call_ringtone_summary"
+            android:title="@string/pref_ringtone" />
     </PreferenceCategory>
     <PreferenceCategory
         android:key="attachments"