mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-14 22:19:29 +01:00
Pebble: add experimental and incomplete support for dismissing 2.x notifications
Currently this dismisses all notifications on the Phone-
This commit is contained in:
parent
0f6491a11d
commit
74e1598bf7
@ -22,10 +22,12 @@ import nodomain.freeyourgadget.gadgetbridge.activities.AbstractChartFragment;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventAppInfo;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventCallControl;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventDismissNotification;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventMusicControl;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventScreenshot;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSleepMonitorResult;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventVersionInfo;
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.NotificationListener;
|
||||
|
||||
// TODO: support option for a single reminder notification when notifications could not be delivered?
|
||||
// conditions: app was running and received notifications, but device was not connected.
|
||||
@ -89,6 +91,9 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
||||
case SCREENSHOT:
|
||||
handleGBDeviceEvent((GBDeviceEventScreenshot) deviceEvent);
|
||||
break;
|
||||
case DISMISS_NOTIFICATION:
|
||||
handleGBDeviceEvent((GBDeviceEventDismissNotification) deviceEvent);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -189,4 +194,12 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
||||
nm.notify(NOTIFICATION_ID_SCREENSHOT, notif);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleGBDeviceEvent(GBDeviceEventDismissNotification deviceEvent) {
|
||||
Context context = getContext();
|
||||
LOG.info("Got DISMISS_NOTIFICATION device event");
|
||||
Intent notificationListenerIntent = new Intent(NotificationListener.ACTION_DISMISS);
|
||||
notificationListenerIntent.putExtra("id", deviceEvent.notificationID);
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(notificationListenerIntent);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ public abstract class GBDeviceEvent {
|
||||
SEND_BYTES,
|
||||
SLEEP_MONITOR_RES,
|
||||
SCREENSHOT,
|
||||
DISMISS_NOTIFICATION,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.deviceevents;
|
||||
|
||||
public class GBDeviceEventDismissNotification extends GBDeviceEvent {
|
||||
public int notificationID;
|
||||
|
||||
public GBDeviceEventDismissNotification() {
|
||||
eventClass = EventClass.DISMISS_NOTIFICATION;
|
||||
}
|
||||
}
|
@ -2,13 +2,17 @@ package nodomain.freeyourgadget.gadgetbridge.externalevents;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.Notification;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -19,13 +23,30 @@ public class NotificationListener extends NotificationListenerService {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(NotificationListener.class);
|
||||
|
||||
public static final String ACTION_DISMISS
|
||||
= "nodomain.freeyourgadget.gadgetbridge.notificationlistener.action.dismiss";
|
||||
|
||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action.equals(ACTION_DISMISS)) {
|
||||
NotificationListener.this.cancelAllNotifications();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
IntentFilter filterLocal = new IntentFilter();
|
||||
filterLocal.addAction(ACTION_DISMISS);
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@ -50,7 +71,6 @@ public class NotificationListener extends NotificationListenerService {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
if (!sharedPrefs.getBoolean("notifications_generic_whenscreenon", false)) {
|
||||
PowerManager powermanager = (PowerManager) getSystemService(POWER_SERVICE);
|
||||
|
Loading…
Reference in New Issue
Block a user