New custom launchers' package names added

This commit is contained in:
Mikhail Chabanov 2015-02-04 18:04:13 +03:00
parent aa2459ed17
commit 4c4b3648b4
2 changed files with 55 additions and 20 deletions

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Build;
import com.shortcutBadger.impl.*;
/**
@ -15,11 +16,16 @@ import com.shortcutBadger.impl.*;
* To change this template use File | Settings | File Templates.
*/
public abstract class ShortcutBadger {
private static final String HOME_PACKAGE_SONY = "com.sonyericsson.home";
private static final String HOME_PACKAGE_SAMSUNG = "com.sec.android.app.launcher";
private static final String HOME_PACKAGE_LG = "com.lge.launcher2";
private static final String HOME_PACKAGE_SONY1 = "com.sonyericsson.home";
private static final String HOME_PACKAGE_SONY2 = "com.anddoes.launcher";
private static final String HOME_PACKAGE_SAMSUNG1 = "com.sec.android.app.launcher";
private static final String HOME_PACKAGE_SAMSUNG2 = "com.sec.android.app.twlauncher";
private static final String HOME_PACKAGE_LG1 = "com.lge.launcher";
private static final String HOME_PACKAGE_LG2 = "com.lge.launcher2";
private static final String HOME_PACKAGE_HTC = "com.htc.launcher";
private static final String HOME_PACKAGE_ANDROID = "com.android.launcher";
private static final String HOME_PACKAGE_ANDROID1 = "com.android.launcher";
private static final String HOME_PACKAGE_ANDROID2 = "com.android.launcher2";
private static final String HOME_PACKAGE_ANDROID3 = "com.google.android.googlequicksearchbox";
private static final String MESSAGE_NOT_SUPPORT_BADGE_COUNT = "ShortBadger is currently not support the badgeCount \"%d\"";
@ -28,6 +34,8 @@ public abstract class ShortcutBadger {
private static final int MIN_BADGE_COUNT = 0;
private static final int MAX_BADGE_COUNT = 99;
private static ShortcutBadger sShortcutBadger;
private ShortcutBadger() {
}
@ -53,28 +61,55 @@ public abstract class ShortcutBadger {
String currentHomePackage = resolveInfo.activityInfo.packageName;
//different home launcher packages use different way adding badges
ShortcutBadger mShortcutBadger = null;
if (HOME_PACKAGE_SONY.equals(currentHomePackage)) {
mShortcutBadger = new SonyHomeBadger(context);
} else if (HOME_PACKAGE_SAMSUNG.equals(currentHomePackage)) {
mShortcutBadger = new SamsungHomeBadger(context);
} else if (HOME_PACKAGE_LG.equals(currentHomePackage)) {
mShortcutBadger = new LGHomeBadger(context);
} else if (HOME_PACKAGE_HTC.equals(currentHomePackage)) {
mShortcutBadger = new hTCHomeBadger(context);
} else if (HOME_PACKAGE_ANDROID.equals(currentHomePackage)) {
mShortcutBadger = new AndroidHomeBadger(context);
}
ShortcutBadger shortcutBadger = getShortcutBadger(currentHomePackage, context);
//not support this home launcher package
if (mShortcutBadger == null) {
if (shortcutBadger == null) {
String exceptionMessage = String.format(MESSAGE_NOT_SUPPORT_THIS_HOME, currentHomePackage);
throw new ShortcutBadgeException(exceptionMessage);
}
mShortcutBadger.executeBadge(badgeCount);
shortcutBadger.executeBadge(badgeCount);
}
private static ShortcutBadger getShortcutBadger(String currentHomePackage, Context context){
if(sShortcutBadger != null) {
return sShortcutBadger;
}
// Workaround for Meizu:
// Meizu declare 'com.android.launcher', but hold something else
// Icons get duplicated on restart after badge change
if(Build.MANUFACTURER.toLowerCase().contains("meizu"))
{
return null;
}
switch (currentHomePackage){
case HOME_PACKAGE_SONY1:
case HOME_PACKAGE_SONY2:
sShortcutBadger = new SonyHomeBadger(context);
break;
case HOME_PACKAGE_SAMSUNG1:
case HOME_PACKAGE_SAMSUNG2:
sShortcutBadger = new SamsungHomeBadger(context);
break;
case HOME_PACKAGE_LG1:
case HOME_PACKAGE_LG2:
sShortcutBadger = new LGHomeBadger(context);
break;
case HOME_PACKAGE_HTC:
sShortcutBadger = new HTCHomeBadger(context);
break;
case HOME_PACKAGE_ANDROID1:
case HOME_PACKAGE_ANDROID2:
case HOME_PACKAGE_ANDROID3:
sShortcutBadger = new AndroidHomeBadger(context);
break;
}
return sShortcutBadger;
}
protected String getEntryActivityName() {
ComponentName componentName = mContext.getPackageManager().getLaunchIntentForPackage(mContext.getPackageName()).getComponent();
return componentName.getClassName();

View File

@ -16,10 +16,10 @@ import com.shortcutBadger.util.ImageUtil;
* Time: 下午7:15
* To change this template use File | Settings | File Templates.
*/
public class hTCHomeBadger extends ShortcutBadger {
public class HTCHomeBadger extends ShortcutBadger {
private static final String CONTENT_URI = "content://com.htc.launcher.settings/favorites?notify=true";
public hTCHomeBadger(Context context) {
public HTCHomeBadger(Context context) {
super(context);
}