aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-11-12 14:41:43 +0100
committeriNPUTmice <daniel@gultsch.de>2014-11-12 14:41:43 +0100
commitc8bc075cbc75ed50b6f4bca35d4aad67c89c4e40 (patch)
tree8884d1416ce6c5aaff6167391719d8f6b8d48129
parente555fe4b033d2ad342d757217bb59704ad8207f9 (diff)
turn on foreground service in expert settings
-rw-r--r--src/main/java/eu/siacs/conversations/services/NotificationService.java27
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java19
-rw-r--r--src/main/java/eu/siacs/conversations/ui/SettingsActivity.java2
-rw-r--r--src/main/res/drawable-hdpi/ic_stat_communication_import_export.pngbin0 -> 620 bytes
-rw-r--r--src/main/res/drawable-mdpi/ic_stat_communication_import_export.pngbin0 -> 392 bytes
-rw-r--r--src/main/res/drawable-xhdpi/ic_stat_communication_import_export.pngbin0 -> 972 bytes
-rw-r--r--src/main/res/drawable-xxhdpi/ic_stat_communication_import_export.pngbin0 -> 1860 bytes
-rw-r--r--src/main/res/values/strings.xml4
-rw-r--r--src/main/res/xml/preferences.xml5
9 files changed, 48 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..ec1ffc15 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,13 @@ 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());
+ 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();
}
}
diff --git a/src/main/res/drawable-hdpi/ic_stat_communication_import_export.png b/src/main/res/drawable-hdpi/ic_stat_communication_import_export.png
new file mode 100644
index 00000000..f929996e
--- /dev/null
+++ b/src/main/res/drawable-hdpi/ic_stat_communication_import_export.png
Binary files differ
diff --git a/src/main/res/drawable-mdpi/ic_stat_communication_import_export.png b/src/main/res/drawable-mdpi/ic_stat_communication_import_export.png
new file mode 100644
index 00000000..b581e174
--- /dev/null
+++ b/src/main/res/drawable-mdpi/ic_stat_communication_import_export.png
Binary files differ
diff --git a/src/main/res/drawable-xhdpi/ic_stat_communication_import_export.png b/src/main/res/drawable-xhdpi/ic_stat_communication_import_export.png
new file mode 100644
index 00000000..a1d62d41
--- /dev/null
+++ b/src/main/res/drawable-xhdpi/ic_stat_communication_import_export.png
Binary files differ
diff --git a/src/main/res/drawable-xxhdpi/ic_stat_communication_import_export.png b/src/main/res/drawable-xxhdpi/ic_stat_communication_import_export.png
new file mode 100644
index 00000000..3539cd91
--- /dev/null
+++ b/src/main/res/drawable-xxhdpi/ic_stat_communication_import_export.png
Binary files differ
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 4d379429..856ee551 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -311,4 +311,8 @@
<string name="scan_qr_code">Scan QR code</string>
<string name="show_qr_code">Show QR code</string>
<string name="account_details">Account details</string>
+ <string name="conversations_foreground_service">Conversations</string>
+ <string name="touch_to_disable">Touch to disable foreground service</string>
+ <string name="pref_keep_foreground_service">Keep service in foreground</string>
+ <string name="pref_keep_foreground_service_summary">Prevents the operating system from killing your connection</string>
</resources>
diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml
index 15a61e87..3be65b7a 100644
--- a/src/main/res/xml/preferences.xml
+++ b/src/main/res/xml/preferences.xml
@@ -101,6 +101,11 @@
android:key="indicate_received"
android:summary="@string/pref_use_indicate_received_summary"
android:title="@string/pref_use_indicate_received" />
+ <CheckBoxPreference
+ android:defaultValue="false"
+ android:key="keep_foreground_service"
+ android:title="@string/pref_keep_foreground_service"
+ android:summary="@string/pref_keep_foreground_service_summary" />
</PreferenceCategory>
</PreferenceScreen>