Skip to content

Commit

Permalink
merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
leolin310148 committed Mar 4, 2015
2 parents 72c481e + 4c4b364 commit 9ab58da
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 135 deletions.
7 changes: 1 addition & 6 deletions SampleApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ android {
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

}


Expand Down
7 changes: 1 addition & 6 deletions ShortcutBadger/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@ android {
buildToolsVersion "20.0.0"

defaultConfig {
applicationId 'me.leolin.shortcutbadger'
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
}
}


}

Expand Down
2 changes: 2 additions & 0 deletions ShortcutBadger/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
<!--for android-->
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/>
<uses-permission android:name="com.android.launcher.permission.WRITE_SETTINGS"/>
<uses-permission android:name="com.android.launcher.action.INSTALL_SHORTCUT" />
<uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />

<!--for Samsung-->
<uses-permission android:name="com.sec.android.provider.badge.permission.READ"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Build;
import me.leolin.shortcutbadger.impl.*;


/**
* Created with IntelliJ IDEA.
* User: leolin
Expand All @@ -15,22 +17,30 @@
* 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_APEX = "com.anddoes.launcher";
private static final String HOME_PACKAGE_ADW = "org.adw.launcher";
private static final String HOME_PACKAGE_ADW_EX = "org.adwfreak.launcher";
private static final String HOME_PACKAGE_NOVA = "com.teslacoilsw.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\"";
private static final String MESSAGE_NOT_SUPPORT_THIS_HOME = "ShortcutBadger is currently not support the home launcher package \"%s\"";

private static final int MIN_BADGE_COUNT = 0;
private static final int MAX_BADGE_COUNT = 99;

private static ShortcutBadger sShortcutBadger;

private ShortcutBadger() {
}

Expand All @@ -55,39 +65,62 @@ public static void setBadge(Context context, int badgeCount) throws ShortcutBadg
ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY);
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);
mShortcutBadger = new NewHtcHomeBadger(context);
} else if (HOME_PACKAGE_ANDROID.equals(currentHomePackage)) {
mShortcutBadger = new AndroidHomeBadger(context);
} else if (HOME_PACKAGE_APEX.equals(currentHomePackage)) {
mShortcutBadger = new ApexHomeBadger(context);
} else if (HOME_PACKAGE_ADW.equals(currentHomePackage)
|| HOME_PACKAGE_ADW_EX.equals(currentHomePackage)) {
mShortcutBadger = new AdwHomeBadger(context);
} else if (HOME_PACKAGE_NOVA.equals(currentHomePackage)) {
mShortcutBadger = new NovaHomeBadger(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);
}
try {
mShortcutBadger.executeBadge(badgeCount);
shortcutBadger.executeBadge(badgeCount);
} catch (Throwable e) {
throw new ShortcutBadgeException("Unable to execute badge:" + e.getMessage());
}
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;
}


if (HOME_PACKAGE_SONY1.equals(currentHomePackage) ||
HOME_PACKAGE_SONY2.equals(currentHomePackage)) {
sShortcutBadger = new SonyHomeBadger(context);
} else if (HOME_PACKAGE_SAMSUNG1.equals(currentHomePackage) ||
HOME_PACKAGE_SAMSUNG2.equals(currentHomePackage)) {
sShortcutBadger = new SamsungHomeBadger(context);
} else if (HOME_PACKAGE_LG1.equals(currentHomePackage) ||
HOME_PACKAGE_LG2.equals(currentHomePackage)) {
sShortcutBadger = new LGHomeBadger(context);
} else if (HOME_PACKAGE_HTC.equals(currentHomePackage)) {
sShortcutBadger = new NewHtcHomeBadger(context);
} else if (HOME_PACKAGE_ANDROID1.equals(currentHomePackage) ||
HOME_PACKAGE_ANDROID2.equals(currentHomePackage) ||
HOME_PACKAGE_ANDROID3.equals(currentHomePackage)) {
sShortcutBadger = new AndroidHomeBadger(context);
} else if (HOME_PACKAGE_APEX.equals(currentHomePackage)) {
sShortcutBadger = new ApexHomeBadger(context);
} else if (HOME_PACKAGE_ADW.equals(currentHomePackage)
|| HOME_PACKAGE_ADW_EX.equals(currentHomePackage)) {
sShortcutBadger = new AdwHomeBadger(context);
} else if (HOME_PACKAGE_NOVA.equals(currentHomePackage)) {
sShortcutBadger = new NovaHomeBadger(context);
}


return sShortcutBadger;
}

protected String getEntryActivityName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
import me.leolin.shortcutbadger.ShortcutBadger;

/**
* Created with IntelliJ IDEA.
* User: leolin
* Date: 2013/11/14
* Time: 下午7:15
* To change this template use File | Settings | File Templates.
* @author Leo Lin
*/
public class AndroidHomeBadger extends ShortcutBadger {
private static final String CONTENT_URI = "content://com.android.launcher2.settings/favorites?notify=true";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
import me.leolin.shortcutbadger.ShortcutBadger;

/**
* Created with IntelliJ IDEA.
* User: leolin
* Date: 2013/11/14
* Time: 下午5:55
* To change this template use File | Settings | File Templates.
* @author Leo Lin
*/
public class LGHomeBadger extends ShortcutBadger {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import me.leolin.shortcutbadger.ShortcutBadger;

/**
* @author Leolin
* @author Leo Lin
*/
public class NewHtcHomeBadger extends ShortcutBadger {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@
import android.net.Uri;
import me.leolin.shortcutbadger.ShortcutBadgeException;
import me.leolin.shortcutbadger.ShortcutBadger;
import me.leolin.shortcutbadger.util.CloseHelper;

/**
* Created with IntelliJ IDEA.
* User: leolin
* Date: 2013/11/14
* Time: 下午7:15
* To change this template use File | Settings | File Templates.
* @author Leo Lin
*/
public class SamsungHomeBadger extends ShortcutBadger {
private static final String CONTENT_URI = "content://com.sec.badge/apps?notify=true";
private static final String[] CONTENT_PROJECTION = new String[]{"_id",};

public SamsungHomeBadger(Context context) {
super(context);
Expand All @@ -26,20 +24,29 @@ public SamsungHomeBadger(Context context) {
protected void executeBadge(int badgeCount) throws ShortcutBadgeException {
Uri mUri = Uri.parse(CONTENT_URI);
ContentResolver contentResolver = mContext.getContentResolver();
Cursor cursor = contentResolver.query(mUri, new String[]{"_id",}, "package=?", new String[]{getContextPackageName()}, null);
if (cursor.moveToNext()) {
int id = cursor.getInt(0);
ContentValues contentValues = new ContentValues();
contentValues.put("badgecount", badgeCount);
contentResolver.update(mUri, contentValues, "_id=?", new String[]{String.valueOf(id)});
} else {
ContentValues contentValues = new ContentValues();
contentValues.put("package", getContextPackageName());
contentValues.put("class", getEntryActivityName());
contentValues.put("badgecount", badgeCount);
contentResolver.insert(mUri, contentValues);
Cursor cursor = null;
try {
cursor = contentResolver.query(mUri, CONTENT_PROJECTION, "package=?", new String[]{getContextPackageName()}, null);
if (cursor != null) {
while (cursor.moveToNext()) {
int id = cursor.getInt(0);
ContentValues contentValues = getContentValues(badgeCount);
contentResolver.update(mUri, contentValues, "_id=?", new String[]{String.valueOf(id)});
}
} else {
ContentValues contentValues = getContentValues(badgeCount);
contentResolver.insert(mUri, contentValues);
}
} finally {
CloseHelper.close(cursor);
}
}


private ContentValues getContentValues(int badgeCount) {
ContentValues contentValues = new ContentValues();
contentValues.put("package", getContextPackageName());
contentValues.put("class", getEntryActivityName());
contentValues.put("badgecount", badgeCount);
return contentValues;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
import me.leolin.shortcutbadger.ShortcutBadger;

/**
* Created with IntelliJ IDEA.
* User: leolin
* Date: 2013/11/14
* Time: 下午5:55
* To change this template use File | Settings | File Templates.
* @author Leo Lin
*/
public class SonyHomeBadger extends ShortcutBadger {

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package me.leolin.shortcutbadger.util;

import android.database.Cursor;

/**
* @author leolin
*/
public class CloseHelper {
public static void close(Cursor cursor) {
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
}
}
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'
classpath 'com.android.tools.build:gradle:1.0.+'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
}
}
Expand All @@ -17,7 +17,7 @@ subprojects{
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'
classpath 'com.android.tools.build:gradle:1.0.+'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
}
}
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Fri Oct 10 21:55:32 CST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-bin.zip
Loading

0 comments on commit 9ab58da

Please sign in to comment.