Skip to content

Commit

Permalink
v 1.1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
leolin310148 committed Feb 3, 2017
1 parent ca9e457 commit a56ebde
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 10 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ The ShortcutBadger makes your Android App show the count of unread messages as a
<td width="130">
<h3>Xiaomi</h3>
<br>
(Not Fully Support)
<br>
<img src="https://raw.github.com/leolin310148/ShortcutBadger/master/screenshots/ss_xiaomi.png"/>
</td>
<td width="130">
Expand All @@ -58,6 +60,8 @@ The ShortcutBadger makes your Android App show the count of unread messages as a
<td width="130">
<h3>Huawei</h3>
<br>
(Not Fully Support)
<br>
<img src="https://raw.github.com/leolin310148/ShortcutBadger/master/screenshots/ss_huawei.png"/>
<br>
(1.1.7+)
Expand All @@ -72,6 +76,8 @@ The ShortcutBadger makes your Android App show the count of unread messages as a
<td width="130">
<h3>OPPO</h3>
<br>
(Not Fully Support)
<br>
<img src="screenshots/ss_oppo.png?raw=true"/>
<br>
(1.1.10+)
Expand Down Expand Up @@ -103,7 +109,7 @@ USAGE
<br/>2. Add dependencies for ShortcutBadger, it's available from maven now.

dependencies {
compile "me.leolin:ShortcutBadger:1.1.10@aar"
compile "me.leolin:ShortcutBadger:1.1.12@aar"
}

<br/>3. Add the codes below:
Expand Down Expand Up @@ -143,6 +149,16 @@ Please use version 1.1.0+

CHANGE LOG
===================================
1.1.12:<br/>
Handling Samsung badger for old devices and new devices.
<br/>
Try to support newer Xiaomi (Not tested.)
<br/>
Try to support Vivo (Not tested.)

1.1.11:<br/>
Add OPPO Launcher Support

1.1.10:<br/>
Add ZUK Launcher Support

Expand Down
2 changes: 1 addition & 1 deletion SampleApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {

defaultConfig {
applicationId "me.leolin.shortcutbadger.example"
minSdkVersion 10
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import me.leolin.shortcutbadger.ShortcutBadger;
import me.leolin.shortcutbadger.impl.ApexHomeBadger;


public class MainActivity extends Activity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@

import me.leolin.shortcutbadger.impl.AdwHomeBadger;
import me.leolin.shortcutbadger.impl.ApexHomeBadger;
import me.leolin.shortcutbadger.impl.AsusHomeLauncher;
import me.leolin.shortcutbadger.impl.AsusHomeBadger;
import me.leolin.shortcutbadger.impl.DefaultBadger;
import me.leolin.shortcutbadger.impl.HuaweiHomeBadger;
import me.leolin.shortcutbadger.impl.NewHtcHomeBadger;
import me.leolin.shortcutbadger.impl.NovaHomeBadger;
import me.leolin.shortcutbadger.impl.OPPOHomeBader;
import me.leolin.shortcutbadger.impl.SamsungHomeBadger;
import me.leolin.shortcutbadger.impl.SonyHomeBadger;
import me.leolin.shortcutbadger.impl.VivoHomeBadger;
import me.leolin.shortcutbadger.impl.XiaomiHomeBadger;
import me.leolin.shortcutbadger.impl.ZukHomeBadger;

Expand All @@ -41,12 +42,12 @@ public final class ShortcutBadger {
BADGERS.add(NovaHomeBadger.class);
BADGERS.add(SonyHomeBadger.class);
BADGERS.add(XiaomiHomeBadger.class);
BADGERS.add(AsusHomeLauncher.class);
BADGERS.add(AsusHomeBadger.class);
BADGERS.add(HuaweiHomeBadger.class);
// BADGERS.add(LGHomeBadger.class);
BADGERS.add(OPPOHomeBader.class);
BADGERS.add(SamsungHomeBadger.class);
BADGERS.add(ZukHomeBadger.class);
BADGERS.add(VivoHomeBadger.class);
}

private static Badger sShortcutBadger;
Expand Down Expand Up @@ -150,6 +151,8 @@ else if (Build.MANUFACTURER.equalsIgnoreCase("ZUK"))
sShortcutBadger = new ZukHomeBadger();
else if (Build.MANUFACTURER.equalsIgnoreCase("OPPO"))
sShortcutBadger = new OPPOHomeBader();
else if (Build.MANUFACTURER.equalsIgnoreCase("VIVO"))
sShortcutBadger = new VivoHomeBadger();
else
sShortcutBadger = new DefaultBadger();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* @author leolin
*/
public class AsusHomeLauncher implements Badger {
public class AsusHomeBadger implements Badger {

private static final String INTENT_ACTION = "android.intent.action.BADGE_COUNT_UPDATE";
private static final String INTENT_EXTRA_BADGE_COUNT = "badge_count";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package me.leolin.shortcutbadger.impl;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

import java.util.Arrays;
import java.util.List;

import me.leolin.shortcutbadger.Badger;
import me.leolin.shortcutbadger.ShortcutBadgeException;

/**
* @author leolin
*/
public class VivoHomeBadger implements Badger {

@Override
public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException {
Intent intent = new Intent("launcher.action.CHANGE_APPLICATION_NOTIFICATION_NUM");
intent.putExtra("packageName", context.getPackageName());
intent.putExtra("className", componentName.getClassName());
intent.putExtra("notificationNum", badgeCount);
context.sendBroadcast(intent);
}

@Override
public List<String> getSupportLaunchers() {
return Arrays.asList("com.vivo.launcher");
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
package me.leolin.shortcutbadger.impl;

import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Build;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;

import me.leolin.shortcutbadger.Badger;
import me.leolin.shortcutbadger.ShortcutBadgeException;
import me.leolin.shortcutbadger.util.BroadcastHelper;


/**
* @author leolin
*/
Expand All @@ -20,6 +28,7 @@ public class XiaomiHomeBadger implements Badger {
public static final String INTENT_ACTION = "android.intent.action.APPLICATION_MESSAGE_UPDATE";
public static final String EXTRA_UPDATE_APP_COMPONENT_NAME = "android.intent.extra.update_application_component_name";
public static final String EXTRA_UPDATE_APP_MSG_TEXT = "android.intent.extra.update_application_message_text";
private ResolveInfo resolveInfo;

@Override
public void executeBadge(Context context, ComponentName componentName, int badgeCount) throws ShortcutBadgeException {
Expand All @@ -28,7 +37,11 @@ public void executeBadge(Context context, ComponentName componentName, int badge
Object miuiNotification = miuiNotificationClass.newInstance();
Field field = miuiNotification.getClass().getDeclaredField("messageCount");
field.setAccessible(true);
field.set(miuiNotification, String.valueOf(badgeCount == 0 ? "" : badgeCount));
try {
field.set(miuiNotification, String.valueOf(badgeCount == 0 ? "" : badgeCount));
} catch (Exception e) {
field.set(miuiNotification, badgeCount);
}
} catch (Exception e) {
Intent localIntent = new Intent(
INTENT_ACTION);
Expand All @@ -37,8 +50,36 @@ public void executeBadge(Context context, ComponentName componentName, int badge
if (BroadcastHelper.canResolveBroadcast(context, localIntent)) {
context.sendBroadcast(localIntent);
} else {
throw new ShortcutBadgeException("unable to resolve intent: " + localIntent.toString());
if (Build.MANUFACTURER.equalsIgnoreCase("Xiaomi")) {
tryNewMiuiBadge(context, badgeCount);
}
}
}
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void tryNewMiuiBadge(Context context, int badgeCount) {
if (resolveInfo == null) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
}

if (resolveInfo != null) {
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(context)
.setContentTitle(context.getString(resolveInfo.labelRes)).setContentText(context.getString(resolveInfo.labelRes)).setSmallIcon(resolveInfo.getIconResource());
Notification notification = builder.build();
try {
Field field = notification.getClass().getDeclaredField("extraNotification");
Object extraNotification = field.get(notification);
Method method = extraNotification.getClass().getDeclaredMethod("setMessageCount", int.class);
method.invoke(extraNotification, badgeCount);
} catch (Exception e) {
e.printStackTrace();
}
mNotificationManager.notify(0, notification);
}
}

Expand All @@ -50,7 +91,8 @@ public List<String> getSupportLaunchers() {
"com.miui.miuihome",
"com.miui.miuihome2",
"com.miui.mihome",
"com.miui.mihome2"
"com.miui.mihome2",
"com.i.miui.launcher"
);
}
}

0 comments on commit a56ebde

Please sign in to comment.