Skip to content

Commit

Permalink
New custom launchers' package names added
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Chabanov committed Feb 4, 2015
1 parent aa2459e commit 4c4b364
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 20 deletions.
71 changes: 53 additions & 18 deletions src/main/java/com/shortcutBadger/ShortcutBadger.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Build;
import com.shortcutBadger.impl.*;

/**
Expand All @@ -15,11 +16,16 @@
* 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\"";
Expand All @@ -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() {
}

Expand All @@ -53,28 +61,55 @@ public static void setBadge(Context context, int badgeCount) throws ShortcutBadg
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
* 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);
}

Expand Down

0 comments on commit 4c4b364

Please sign in to comment.