From 8e0daa69cc63d02b35b3b4c12725619b110ca25f Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Wed, 17 Sep 2014 16:05:54 +0200 Subject: [PATCH] Added preference to disable incoming file notification sound. --- .../Plugins/SharePlugin/SharePlugin.java | 25 +++++++++++++------ src/main/res/values/strings.xml | 3 +++ src/main/res/xml/plugin_share_preferences.xml | 13 ++++++++++ 3 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 src/main/res/xml/plugin_share_preferences.xml diff --git a/src/main/java/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java b/src/main/java/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java index 23fa7bc5..f277f9f0 100644 --- a/src/main/java/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java +++ b/src/main/java/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java @@ -8,10 +8,12 @@ import android.app.PendingIntent; import android.content.ClipboardManager; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Environment; +import android.preference.PreferenceManager; import android.support.v4.app.NotificationCompat; import android.support.v4.app.TaskStackBuilder; import android.util.Log; @@ -33,7 +35,7 @@ public class SharePlugin extends Plugin { @Override public String getPluginName() { - return "share_ping"; + return "plugin_share"; } @Override @@ -53,7 +55,7 @@ public class SharePlugin extends Plugin { @Override public boolean hasSettings() { - return false; + return true; } @Override @@ -110,6 +112,7 @@ public class SharePlugin extends Plugin { .setSmallIcon(android.R.drawable.ic_dialog_alert) .setAutoCancel(true) .build(); + NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(notificationId, noti); @@ -155,15 +158,23 @@ public class SharePlugin extends Plugin { ); Resources res = context.getResources(); - Notification noti = new NotificationCompat.Builder(context) + + NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setContentTitle(res.getString(R.string.received_file_title, device.getName())) .setContentText(res.getString(R.string.received_file_text, filename)) .setContentIntent(resultPendingIntent) .setTicker(res.getString(R.string.received_file_title, device.getName())) .setSmallIcon(android.R.drawable.ic_dialog_alert) - .setAutoCancel(true) - .setDefaults(Notification.DEFAULT_SOUND) - .build(); + .setAutoCancel(true); + + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + if (prefs.getBoolean("share_notification_preference", true)) { + builder.setDefaults(Notification.DEFAULT_ALL); + } + + Notification noti = builder.build(); + NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(notificationId, noti); @@ -214,7 +225,7 @@ public class SharePlugin extends Plugin { .setTicker(res.getString(R.string.received_url_title, device.getName())) .setSmallIcon(android.R.drawable.ic_dialog_alert) .setAutoCancel(true) - .setDefaults(Notification.DEFAULT_SOUND) + .setDefaults(Notification.DEFAULT_ALL) .build(); NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 55394654..3bed60aa 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -87,4 +87,7 @@ %s Invalid device name Received text, saved to clipboard + Noisy notifications + Vibrate and play a sound when receiving a file + diff --git a/src/main/res/xml/plugin_share_preferences.xml b/src/main/res/xml/plugin_share_preferences.xml new file mode 100644 index 00000000..f84b140e --- /dev/null +++ b/src/main/res/xml/plugin_share_preferences.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file