aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-11-15 15:51:27 +0100
committeriNPUTmice <daniel@gultsch.de>2014-11-15 15:51:27 +0100
commit07b07115d684b27ebc0c3ee4f70ef2e33a3b2dbb (patch)
tree3b19be17a403cfbb2a695e50da9a1b277376ac45 /src/main/java
parent5b9c690c47cbb6fd352d7ddce3b13e6bf119fc22 (diff)
parentbdc86bb8e3667acb4d3f59ece718dc763d59374f (diff)
Merge branch 'feature/foreground_service' into development
Conflicts: src/main/res/values/strings.xml
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/eu/siacs/conversations/services/NotificationService.java29
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java19
-rw-r--r--src/main/java/eu/siacs/conversations/ui/SettingsActivity.java2
3 files changed, 41 insertions, 9 deletions
diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java
index 4cb28145..11b88538 100644
--- a/src/main/java/eu/siacs/conversations/services/NotificationService.java
+++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java
@@ -38,6 +38,7 @@ public class NotificationService {
private LinkedHashMap<String, ArrayList<Message>> notifications = new LinkedHashMap<String, ArrayList<Message>>();
public static int NOTIFICATION_ID = 0x2342;
+ public static int FOREGROUND_NOTIFICATION_ID = 0x8899;
private Conversation mOpenConversation;
private boolean mIsInForeground;
private long mLastNotification;
@@ -290,9 +291,11 @@ public class NotificationService {
Intent viewConversationIntent = new Intent(mXmppConnectionService,
ConversationActivity.class);
viewConversationIntent.setAction(Intent.ACTION_VIEW);
- viewConversationIntent.putExtra(ConversationActivity.CONVERSATION,
- conversationUuid);
- viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
+ if (conversationUuid!=null) {
+ viewConversationIntent.putExtra(ConversationActivity.CONVERSATION,
+ conversationUuid);
+ viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
+ }
stackBuilder.addNextIntent(viewConversationIntent);
@@ -304,7 +307,14 @@ public class NotificationService {
private PendingIntent createDeleteIntent() {
Intent intent = new Intent(mXmppConnectionService,
XmppConnectionService.class);
- intent.setAction("clear_notification");
+ intent.setAction(XmppConnectionService.ACTION_CLEAR_NOTIFICATION);
+ return PendingIntent.getService(mXmppConnectionService, 0, intent, 0);
+ }
+
+ private PendingIntent createDisableForeground() {
+ Intent intent = new Intent(mXmppConnectionService,
+ XmppConnectionService.class);
+ intent.setAction(XmppConnectionService.ACTION_DISABLE_FOREGROUND);
return PendingIntent.getService(mXmppConnectionService, 0, intent, 0);
}
@@ -351,4 +361,15 @@ public class NotificationService {
: Config.MINI_GRACE_PERIOD * 2;
return SystemClock.elapsedRealtime() < (this.mLastNotification + miniGrace);
}
+
+ public Notification createForegroundNotification() {
+ NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
+ mBuilder.setSmallIcon(R.drawable.ic_stat_communication_import_export);
+ mBuilder.setContentTitle(mXmppConnectionService.getString(R.string.conversations_foreground_service));
+ mBuilder.setContentText(mXmppConnectionService.getString(R.string.touch_to_disable));
+ mBuilder.setContentIntent(createDisableForeground());
+ mBuilder.setWhen(0);
+ mBuilder.setPriority(NotificationCompat.PRIORITY_MIN);
+ return mBuilder.build();
+ }
}
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 831a54e1..97aba64f 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -97,6 +97,7 @@ public class XmppConnectionService extends Service {
public static String ACTION_CLEAR_NOTIFICATION = "clear_notification";
private static String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts";
+ public static String ACTION_DISABLE_FOREGROUND = "disable_foreground";
private ContentObserver contactObserver = new ContentObserver(null) {
@Override
public void onChange(boolean selfChange) {
@@ -345,6 +346,9 @@ public class XmppConnectionService extends Service {
return START_NOT_STICKY;
} else if (intent.getAction().equals(ACTION_CLEAR_NOTIFICATION)) {
mNotificationService.clear();
+ } else if (intent.getAction().equals(ACTION_DISABLE_FOREGROUND)) {
+ getPreferences().edit().putBoolean("keep_foreground_service",false).commit();
+ toggleForegroundService();
}
}
this.wakeLock.acquire();
@@ -459,18 +463,23 @@ public class XmppConnectionService extends Service {
this.pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
this.wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"XmppConnectionService");
+ toggleForegroundService();
}
- @Override
- public void onDestroy() {
- super.onDestroy();
- this.logoutAndSave();
+ public void toggleForegroundService() {
+ if (getPreferences().getBoolean("keep_foreground_service",false)) {
+ startForeground(NotificationService.FOREGROUND_NOTIFICATION_ID, this.mNotificationService.createForegroundNotification());
+ } else {
+ stopForeground(true);
+ }
}
@Override
public void onTaskRemoved(Intent rootIntent) {
super.onTaskRemoved(rootIntent);
- this.logoutAndSave();
+ if (!getPreferences().getBoolean("keep_foreground_service",false)) {
+ this.logoutAndSave();
+ }
}
private void logoutAndSave() {
diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
index aba60175..b6f3a077 100644
--- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java
@@ -70,6 +70,8 @@ public class SettingsActivity extends XmppActivity implements
}
}
}
+ } else if (name.equals("keep_foreground_service")) {
+ xmppConnectionService.toggleForegroundService();
}
}