merge conflict
This commit is contained in:
commit
9ab58da4cd
|
|
@ -18,12 +18,7 @@ android {
|
|||
versionCode 1
|
||||
versionName "1.0"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
runProguard false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"/>
|
||||
|
|
|
|||
|
|
@ -5,8 +5,10 @@ import android.content.Context;
|
|||
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
|
||||
|
|
@ -15,15 +17,21 @@ import me.leolin.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_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\"";
|
||||
|
|
@ -31,6 +39,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() {
|
||||
}
|
||||
|
||||
|
|
@ -55,41 +65,64 @@ public abstract class ShortcutBadger {
|
|||
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() {
|
||||
ComponentName componentName = mContext.getPackageManager().getLaunchIntentForPackage(mContext.getPackageName()).getComponent();
|
||||
return componentName.getClassName();
|
||||
|
|
|
|||
|
|
@ -9,11 +9,7 @@ import me.leolin.shortcutbadger.ShortcutBadgeException;
|
|||
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";
|
||||
|
|
|
|||
|
|
@ -5,11 +5,7 @@ import android.content.Intent;
|
|||
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 {
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import me.leolin.shortcutbadger.ShortcutBadgeException;
|
|||
import me.leolin.shortcutbadger.ShortcutBadger;
|
||||
|
||||
/**
|
||||
* @author Leolin
|
||||
* @author Leo Lin
|
||||
*/
|
||||
public class NewHtcHomeBadger extends ShortcutBadger {
|
||||
|
||||
|
|
|
|||
|
|
@ -7,16 +7,14 @@ import android.database.Cursor;
|
|||
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);
|
||||
|
|
@ -26,20 +24,29 @@ public class SamsungHomeBadger extends ShortcutBadger {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,11 +5,7 @@ import android.content.Intent;
|
|||
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 {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,58 +0,0 @@
|
|||
package me.leolin.shortcutbadger.impl;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import me.leolin.shortcutbadger.ShortcutBadgeException;
|
||||
import me.leolin.shortcutbadger.ShortcutBadger;
|
||||
import me.leolin.shortcutbadger.util.ImageUtil;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
* User: leolin
|
||||
* Date: 2013/11/14
|
||||
* Time: 下午7:15
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
@Deprecated
|
||||
public class hTCHomeBadger extends ShortcutBadger {
|
||||
private static final String CONTENT_URI = "content://com.htc.launcher.settings/favorites?notify=true";
|
||||
|
||||
public hTCHomeBadger(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void executeBadge(int badgeCount) throws ShortcutBadgeException {
|
||||
ContentResolver contentResolver = mContext.getContentResolver();
|
||||
Uri mUri = Uri.parse(CONTENT_URI);
|
||||
String appName = mContext.getResources().getText(mContext.getResources().getIdentifier("app_name",
|
||||
"string", getContextPackageName())).toString();
|
||||
|
||||
boolean supportNotifyCount = true;
|
||||
try {
|
||||
Cursor cursor = contentResolver.query(mUri, new String[]{"notifyCount"}, "title=?", new String[]{appName}, null);
|
||||
} catch (Throwable e) {
|
||||
supportNotifyCount = false;
|
||||
}
|
||||
|
||||
if (supportNotifyCount) {
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put("notifyCount", badgeCount);
|
||||
contentResolver.update(mUri, contentValues, "title=?", new String[]{appName});
|
||||
} else {
|
||||
byte[] bytes = ImageUtil.drawBadgeOnAppIcon(mContext, badgeCount);
|
||||
|
||||
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put("iconType", 1);
|
||||
contentValues.put("itemType", 1);
|
||||
contentValues.put("icon", bytes);
|
||||
contentResolver.update(mUri, contentValues, "title=?", new String[]{appName});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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,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.+'
|
||||
}
|
||||
}
|
||||
|
|
@ -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.+'
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in /home/mik/sdk/android-sdk-linux/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the proguardFiles
|
||||
# directive in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
-dontshrink
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.shortcutBadger.impl;
|
||||
|
||||
import android.database.Cursor;
|
||||
|
||||
public class CloseHelper {
|
||||
public static void close(Cursor cursor) {
|
||||
if (cursor != null && !cursor.isClosed()) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue