Merge branch 'feature/foreground_service' into development
Conflicts: src/main/res/values/strings.xml
This commit is contained in:
commit
07b07115d6
|
@ -38,6 +38,7 @@ public class NotificationService {
|
||||||
private LinkedHashMap<String, ArrayList<Message>> notifications = new LinkedHashMap<String, ArrayList<Message>>();
|
private LinkedHashMap<String, ArrayList<Message>> notifications = new LinkedHashMap<String, ArrayList<Message>>();
|
||||||
|
|
||||||
public static int NOTIFICATION_ID = 0x2342;
|
public static int NOTIFICATION_ID = 0x2342;
|
||||||
|
public static int FOREGROUND_NOTIFICATION_ID = 0x8899;
|
||||||
private Conversation mOpenConversation;
|
private Conversation mOpenConversation;
|
||||||
private boolean mIsInForeground;
|
private boolean mIsInForeground;
|
||||||
private long mLastNotification;
|
private long mLastNotification;
|
||||||
|
@ -290,9 +291,11 @@ public class NotificationService {
|
||||||
Intent viewConversationIntent = new Intent(mXmppConnectionService,
|
Intent viewConversationIntent = new Intent(mXmppConnectionService,
|
||||||
ConversationActivity.class);
|
ConversationActivity.class);
|
||||||
viewConversationIntent.setAction(Intent.ACTION_VIEW);
|
viewConversationIntent.setAction(Intent.ACTION_VIEW);
|
||||||
|
if (conversationUuid!=null) {
|
||||||
viewConversationIntent.putExtra(ConversationActivity.CONVERSATION,
|
viewConversationIntent.putExtra(ConversationActivity.CONVERSATION,
|
||||||
conversationUuid);
|
conversationUuid);
|
||||||
viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
|
viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
|
||||||
|
}
|
||||||
|
|
||||||
stackBuilder.addNextIntent(viewConversationIntent);
|
stackBuilder.addNextIntent(viewConversationIntent);
|
||||||
|
|
||||||
|
@ -304,7 +307,14 @@ public class NotificationService {
|
||||||
private PendingIntent createDeleteIntent() {
|
private PendingIntent createDeleteIntent() {
|
||||||
Intent intent = new Intent(mXmppConnectionService,
|
Intent intent = new Intent(mXmppConnectionService,
|
||||||
XmppConnectionService.class);
|
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);
|
return PendingIntent.getService(mXmppConnectionService, 0, intent, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,4 +361,15 @@ public class NotificationService {
|
||||||
: Config.MINI_GRACE_PERIOD * 2;
|
: Config.MINI_GRACE_PERIOD * 2;
|
||||||
return SystemClock.elapsedRealtime() < (this.mLastNotification + miniGrace);
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,7 @@ public class XmppConnectionService extends Service {
|
||||||
|
|
||||||
public static String ACTION_CLEAR_NOTIFICATION = "clear_notification";
|
public static String ACTION_CLEAR_NOTIFICATION = "clear_notification";
|
||||||
private static String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts";
|
private static String ACTION_MERGE_PHONE_CONTACTS = "merge_phone_contacts";
|
||||||
|
public static String ACTION_DISABLE_FOREGROUND = "disable_foreground";
|
||||||
private ContentObserver contactObserver = new ContentObserver(null) {
|
private ContentObserver contactObserver = new ContentObserver(null) {
|
||||||
@Override
|
@Override
|
||||||
public void onChange(boolean selfChange) {
|
public void onChange(boolean selfChange) {
|
||||||
|
@ -345,6 +346,9 @@ public class XmppConnectionService extends Service {
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
} else if (intent.getAction().equals(ACTION_CLEAR_NOTIFICATION)) {
|
} else if (intent.getAction().equals(ACTION_CLEAR_NOTIFICATION)) {
|
||||||
mNotificationService.clear();
|
mNotificationService.clear();
|
||||||
|
} else if (intent.getAction().equals(ACTION_DISABLE_FOREGROUND)) {
|
||||||
|
getPreferences().edit().putBoolean("keep_foreground_service",false).commit();
|
||||||
|
toggleForegroundService();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.wakeLock.acquire();
|
this.wakeLock.acquire();
|
||||||
|
@ -459,19 +463,24 @@ public class XmppConnectionService extends Service {
|
||||||
this.pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
this.pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
||||||
this.wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
this.wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
|
||||||
"XmppConnectionService");
|
"XmppConnectionService");
|
||||||
|
toggleForegroundService();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void toggleForegroundService() {
|
||||||
public void onDestroy() {
|
if (getPreferences().getBoolean("keep_foreground_service",false)) {
|
||||||
super.onDestroy();
|
startForeground(NotificationService.FOREGROUND_NOTIFICATION_ID, this.mNotificationService.createForegroundNotification());
|
||||||
this.logoutAndSave();
|
} else {
|
||||||
|
stopForeground(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTaskRemoved(Intent rootIntent) {
|
public void onTaskRemoved(Intent rootIntent) {
|
||||||
super.onTaskRemoved(rootIntent);
|
super.onTaskRemoved(rootIntent);
|
||||||
|
if (!getPreferences().getBoolean("keep_foreground_service",false)) {
|
||||||
this.logoutAndSave();
|
this.logoutAndSave();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void logoutAndSave() {
|
private void logoutAndSave() {
|
||||||
for (Account account : accounts) {
|
for (Account account : accounts) {
|
||||||
|
|
|
@ -70,6 +70,8 @@ public class SettingsActivity extends XmppActivity implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (name.equals("keep_foreground_service")) {
|
||||||
|
xmppConnectionService.toggleForegroundService();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 620 B |
Binary file not shown.
After Width: | Height: | Size: 392 B |
Binary file not shown.
After Width: | Height: | Size: 972 B |
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
|
@ -328,4 +328,8 @@
|
||||||
<string name="verified">Verified!</string>
|
<string name="verified">Verified!</string>
|
||||||
<string name="smp_requested">Contact requested SMP verification</string>
|
<string name="smp_requested">Contact requested SMP verification</string>
|
||||||
<string name="no_otr_session_found">No valid OTR session has been found!</string>
|
<string name="no_otr_session_found">No valid OTR session has been found!</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>
|
</resources>
|
||||||
|
|
|
@ -101,6 +101,11 @@
|
||||||
android:key="indicate_received"
|
android:key="indicate_received"
|
||||||
android:summary="@string/pref_use_indicate_received_summary"
|
android:summary="@string/pref_use_indicate_received_summary"
|
||||||
android:title="@string/pref_use_indicate_received" />
|
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>
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue