1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-20 12:00:51 +02:00

Pebble message intent notifications default to "never" now

If these get turned on, Conversations notifications will be handled through Pebble message intents and get filtered out from generic notifcation handling.
This commit is contained in:
Andreas Shimokawa 2015-05-08 12:50:42 +02:00
parent c999c52501
commit 6f162c593b
3 changed files with 20 additions and 11 deletions

View File

@ -48,8 +48,6 @@ public class NotificationListener extends NotificationListenerService {
return; return;
} }
String source = sbn.getPackageName();
Log.i(TAG, source);
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
if (!sharedPrefs.getBoolean("notifications_generic_whenscreenon", false)) { if (!sharedPrefs.getBoolean("notifications_generic_whenscreenon", false)) {
@ -59,8 +57,13 @@ public class NotificationListener extends NotificationListenerService {
} }
} }
String source = sbn.getPackageName();
Notification notification = sbn.getNotification(); Notification notification = sbn.getNotification();
if ((notification.flags & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT) {
return;
}
/* do not display messages from "android" /* do not display messages from "android"
* This includes keyboard selection message, usb connection messages, etc * This includes keyboard selection message, usb connection messages, etc
* Hope it does not filter out too much, we will see... * Hope it does not filter out too much, we will see...
@ -70,13 +73,14 @@ public class NotificationListener extends NotificationListenerService {
source.equals("com.android.systemui") || source.equals("com.android.systemui") ||
source.equals("com.android.dialer") || source.equals("com.android.dialer") ||
source.equals("com.android.mms") || source.equals("com.android.mms") ||
source.equals("com.fsck.k9") || source.equals("com.fsck.k9")) {
source.equals("eu.siacs.conversations")) {
return; return;
} }
if ((notification.flags & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT) { if (source.equals("eu.siacs.conversations")) {
return; if (!"never".equals(sharedPrefs.getString("notification_mode_pebblemsg", "never"))) {
return;
}
} }
Log.i(TAG, "Processing notification from source " + source); Log.i(TAG, "Processing notification from source " + source);
@ -84,20 +88,25 @@ public class NotificationListener extends NotificationListenerService {
Bundle extras = notification.extras; Bundle extras = notification.extras;
String title = extras.getCharSequence(Notification.EXTRA_TITLE).toString(); String title = extras.getCharSequence(Notification.EXTRA_TITLE).toString();
String content = null; String content = null;
if (extras.containsKey(Notification.EXTRA_TEXT)) { if (extras.containsKey(Notification.EXTRA_TEXT))
{
CharSequence contentCS = extras.getCharSequence(Notification.EXTRA_TEXT); CharSequence contentCS = extras.getCharSequence(Notification.EXTRA_TEXT);
if (contentCS != null) { if (contentCS != null) {
content = contentCS.toString(); content = contentCS.toString();
} }
} }
if (content != null) { if (content != null)
{
Intent startIntent = new Intent(NotificationListener.this, BluetoothCommunicationService.class); Intent startIntent = new Intent(NotificationListener.this, BluetoothCommunicationService.class);
startIntent.setAction(BluetoothCommunicationService.ACTION_NOTIFICATION_GENERIC); startIntent.setAction(BluetoothCommunicationService.ACTION_NOTIFICATION_GENERIC);
startIntent.putExtra("notification_title", title); startIntent.putExtra("notification_title", title);
startIntent.putExtra("notification_body", content); startIntent.putExtra("notification_body", content);
startService(startIntent); startService(startIntent);
} }
} }
@Override @Override

View File

@ -21,10 +21,10 @@ public class PebbleReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
if ("never".equals(sharedPrefs.getString("notification_mode_pebblemsg", "when_screen_off"))) { if ("never".equals(sharedPrefs.getString("notification_mode_pebblemsg", "never"))) {
return; return;
} }
if ("when_screen_off".equals(sharedPrefs.getString("notification_mode_pebblemsg", "when_screen_off"))) { if ("when_screen_off".equals(sharedPrefs.getString("notification_mode_pebblemsg", "never"))) {
PowerManager powermanager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager powermanager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (powermanager.isScreenOn()) { if (powermanager.isScreenOn()) {
return; return;

View File

@ -35,7 +35,7 @@
android:title="@string/pref_title_notifications_k9mail" /> android:title="@string/pref_title_notifications_k9mail" />
<ListPreference <ListPreference
android:defaultValue="when_screen_off" android:defaultValue="never"
android:entries="@array/notification_mode" android:entries="@array/notification_mode"
android:entryValues="@array/notification_mode_values" android:entryValues="@array/notification_mode_values"
android:key="notification_mode_pebblemsg" android:key="notification_mode_pebblemsg"