aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2015-03-02 12:42:04 +0100
committerDaniel Gultsch <daniel@gultsch.de>2015-05-19 15:21:00 +0200
commit8c3aab3c422ad263a1502889fbf477cc2965679b (patch)
treed18c14aae8f30ccf8151ef3dce4bca8f2017801c
parentbb603644880f0b32d8a7b54d5158f6fac678aa12 (diff)
ground work for various unread count badges
-rw-r--r--src/main/AndroidManifest.xml1
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java4
-rw-r--r--src/main/java/eu/siacs/conversations/utils/UnreadCountBadgeHelper.java64
3 files changed, 68 insertions, 1 deletions
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index 9fe37017..abe427ba 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -14,6 +14,7 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.NFC" />
+ <uses-permission android:name="com.anddoes.launcher.permission.UPDATE_COUNT" />
<application
android:allowBackup="true"
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 63d9ba7a..81f7c136 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -77,6 +77,7 @@ import eu.siacs.conversations.utils.ExceptionHelper;
import eu.siacs.conversations.utils.OnPhoneContactsLoadedListener;
import eu.siacs.conversations.utils.PRNGFixes;
import eu.siacs.conversations.utils.PhoneHelper;
+import eu.siacs.conversations.utils.UnreadCountBadgeHelper;
import eu.siacs.conversations.utils.Xmlns;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.OnBindListener;
@@ -1033,7 +1034,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public void loadMoreMessages(final Conversation conversation, final long timestamp, final OnMoreMessagesLoaded callback) {
- Log.d(Config.LOGTAG,"load more messages for "+conversation.getName() + " prior to "+MessageGenerator.getTimestamp(timestamp));
+ Log.d(Config.LOGTAG, "load more messages for " + conversation.getName() + " prior to " + MessageGenerator.getTimestamp(timestamp));
if (XmppConnectionService.this.getMessageArchiveService().queryInProgress(conversation,callback)) {
return;
}
@@ -2205,6 +2206,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public void updateConversationUi() {
+ UnreadCountBadgeHelper.update(this,unreadCount());
if (mOnConversationUpdate != null) {
mOnConversationUpdate.onConversationUpdate();
}
diff --git a/src/main/java/eu/siacs/conversations/utils/UnreadCountBadgeHelper.java b/src/main/java/eu/siacs/conversations/utils/UnreadCountBadgeHelper.java
new file mode 100644
index 00000000..3e194c05
--- /dev/null
+++ b/src/main/java/eu/siacs/conversations/utils/UnreadCountBadgeHelper.java
@@ -0,0 +1,64 @@
+package eu.siacs.conversations.utils;
+
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.util.Log;
+
+import eu.siacs.conversations.Config;
+
+public class UnreadCountBadgeHelper {
+
+ private static int count = 0;
+
+ public static void update(final Context context,
+ final int count) {
+ if (UnreadCountBadgeHelper.count != count) {
+ UnreadCountBadgeHelper.count = count;
+ Log.d(Config.LOGTAG, "updating read count to: " + count);
+ final String packageName = context.getPackageName();
+ final String activity = context.getPackageManager().getLaunchIntentForPackage(packageName).getComponent().getClassName();
+ updateTeslaUnreadApi(context, packageName, activity, count);
+ updateApexNotificationApi(context, packageName, activity, count);
+ }
+ }
+
+ /*
+ TeslaUnread API primarily used by Nova Launcher
+ documented here: http://novalauncher.com/teslaunread-api/
+ */
+ private static void updateTeslaUnreadApi(final Context context,
+ final String packageName,
+ final String activity,
+ final int count) {
+ try {
+ ContentValues contentValues = new ContentValues();
+ contentValues.put("tag",packageName+"/"+activity);
+ contentValues.put("count",count);
+ context.getContentResolver().insert(
+ Uri.parse("content://com.teslacoilsw.notifier/unread_count"),
+ contentValues
+ );
+ } catch (IllegalArgumentException e) {
+ return;
+ } catch (Exception e) {
+ return;
+ }
+ }
+
+ /*
+ Apex Launcher Notifications API used by Apex Launcher Pro and others (Smart Launcher 2)
+ */
+ private static void updateApexNotificationApi(final Context context,
+ final String packageName,
+ final String activity,
+ final int count) {
+ Intent intent = new Intent("com.anddoes.launcher.COUNTER_CHANGED");
+ intent.putExtra("package",packageName);
+ //intent.putExtra("class",packageName+"."+activity);
+ intent.putExtra("class",activity);
+ intent.putExtra("count",count);
+ context.sendBroadcast(intent);
+ }
+}