properly dismiss notifications

This commit is contained in:
iNPUTmice 2014-10-02 17:36:02 +02:00
parent fd6f5b0e84
commit 4b09f0e9d3
2 changed files with 25 additions and 10 deletions

View file

@ -120,10 +120,11 @@ public class NotificationService {
+ mXmppConnectionService + mXmppConnectionService
.getString(R.string.unread_conversations)); .getString(R.string.unread_conversations));
StringBuilder names = new StringBuilder(); StringBuilder names = new StringBuilder();
Conversation conversation = null;
for (ArrayList<Message> messages : notifications.values()) { for (ArrayList<Message> messages : notifications.values()) {
if (messages.size() > 0) { if (messages.size() > 0) {
String name = messages.get(0).getConversation() conversation = messages.get(0).getConversation();
.getName(); String name = conversation.getName();
style.addLine(Html.fromHtml("<b>" style.addLine(Html.fromHtml("<b>"
+ name + name
+ "</b> " + "</b> "
@ -142,6 +143,10 @@ public class NotificationService {
.getString(R.string.unread_conversations)); .getString(R.string.unread_conversations));
mBuilder.setContentText(names.toString()); mBuilder.setContentText(names.toString());
mBuilder.setStyle(style); mBuilder.setStyle(style);
if (conversation!=null) {
mBuilder.setContentIntent(createContentIntent(conversation
.getUuid()));
}
} }
if (notify) { if (notify) {
if (vibrate) { if (vibrate) {
@ -153,6 +158,7 @@ public class NotificationService {
mBuilder.setSound(Uri.parse(ringtone)); mBuilder.setSound(Uri.parse(ringtone));
} }
} }
mBuilder.setDeleteIntent(createDeleteIntent());
mBuilder.setLights(0xffffffff, 2000, 4000); mBuilder.setLights(0xffffffff, 2000, 4000);
Notification notification = mBuilder.build(); Notification notification = mBuilder.build();
mNotificationManager.notify(NOTIFICATION_ID, notification); mNotificationManager.notify(NOTIFICATION_ID, notification);
@ -177,6 +183,12 @@ public class NotificationService {
PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent.FLAG_UPDATE_CURRENT);
return resultPendingIntent; return resultPendingIntent;
} }
private PendingIntent createDeleteIntent() {
Intent intent = new Intent(mXmppConnectionService, XmppConnectionService.class);
intent.setAction("clear_notification");
return PendingIntent.getService(mXmppConnectionService, 0, intent, 0);
}
public static boolean wasHighlightedOrPrivate(Message message) { public static boolean wasHighlightedOrPrivate(Message message) {
String nick = message.getConversation().getMucOptions().getActualNick(); String nick = message.getConversation().getMucOptions().getActualNick();

View file

@ -90,6 +90,7 @@ public class XmppConnectionService extends Service {
public long startDate; public long startDate;
private static String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts"; private static String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts";
public static String ACTION_CLEAR_NOTIFICATION = "clear_notification";
private MemorizingTrustManager mMemorizingTrustManager; private MemorizingTrustManager mMemorizingTrustManager;
@ -318,14 +319,16 @@ public class XmppConnectionService extends Service {
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
if ((intent != null) if (intent != null && intent.getAction() != null) {
&& (ACTION_MERGE_PHONE_CONTACTS.equals(intent.getAction()))) { if (intent.getAction().equals(ACTION_MERGE_PHONE_CONTACTS)) {
mergePhoneContactsWithRoster(); mergePhoneContactsWithRoster();
return START_STICKY; return START_STICKY;
} else if ((intent != null) } else if (intent.getAction().equals(Intent.ACTION_SHUTDOWN)) {
&& (Intent.ACTION_SHUTDOWN.equals(intent.getAction()))) { logoutAndSave();
logoutAndSave(); return START_NOT_STICKY;
return START_NOT_STICKY; } else if (intent.getAction().equals(ACTION_CLEAR_NOTIFICATION)) {
mNotificationService.clear();
}
} }
this.wakeLock.acquire(); this.wakeLock.acquire();
ConnectivityManager cm = (ConnectivityManager) getApplicationContext() ConnectivityManager cm = (ConnectivityManager) getApplicationContext()