Skip to content

Commit

Permalink
merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
leolin310148 committed Mar 19, 2015
2 parents 27fa5b4 + 1842d65 commit 3815ce2
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
build
.gradle
local.properties
**/gradle.properties
**/gradle.properties
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ LICENSE
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
<br/>
<br/>
1 change: 1 addition & 0 deletions ShortcutBadger/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.library'

android {

compileSdkVersion 19
Expand Down
3 changes: 3 additions & 0 deletions ShortcutBadger/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@
<!--for apex-->
<uses-permission android:name="com.anddoes.launcher.permission.UPDATE_COUNT"/>

<!--for solid-->
<uses-permission android:name="com.majeur.launcher.permission.UPDATE_BADGE"/>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public abstract class ShortcutBadger {
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 HOME_PACKAGE_SOLID = "com.majeur.launcher";


private static final String MESSAGE_NOT_SUPPORT_BADGE_COUNT = "ShortBadger is currently not support the badgeCount \"%d\"";
Expand Down Expand Up @@ -78,7 +79,6 @@ public static void setBadge(Context context, int badgeCount) throws ShortcutBadg
} catch (Throwable e) {
throw new ShortcutBadgeException("Unable to execute badge:" + e.getMessage());
}
shortcutBadger.executeBadge(badgeCount);

}

Expand Down Expand Up @@ -117,6 +117,8 @@ private static ShortcutBadger getShortcutBadger(String currentHomePackage, Conte
sShortcutBadger = new AdwHomeBadger(context);
} else if (HOME_PACKAGE_NOVA.equals(currentHomePackage)) {
sShortcutBadger = new NovaHomeBadger(context);
} else if (HOME_PACKAGE_SOLID.equals(currentHomePackage)) {
sShortcutBadger = new SolidHomeBadger(context);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,27 @@ protected void executeBadge(int badgeCount) throws ShortcutBadgeException {
if (cursor != null) {
while (cursor.moveToNext()) {
int id = cursor.getInt(0);
ContentValues contentValues = getContentValues(badgeCount);
ContentValues contentValues = getContentValues(badgeCount, false);
contentResolver.update(mUri, contentValues, "_id=?", new String[]{String.valueOf(id)});
}
} else {
ContentValues contentValues = getContentValues(badgeCount);
ContentValues contentValues = getContentValues(badgeCount, true);
contentResolver.insert(mUri, contentValues);
}
} finally {
CloseHelper.close(cursor);
}
}

private ContentValues getContentValues(int badgeCount) {
private ContentValues getContentValues(int badgeCount, boolean isInsert) {
ContentValues contentValues = new ContentValues();
contentValues.put("package", getContextPackageName());
contentValues.put("class", getEntryActivityName());
if (isInsert) {
contentValues.put("package", getContextPackageName());
contentValues.put("class", getEntryActivityName());
}

contentValues.put("badgecount", badgeCount);

return contentValues;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package me.leolin.shortcutbadger.impl;

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

import me.leolin.shortcutbadger.ShortcutBadgeException;
import me.leolin.shortcutbadger.ShortcutBadger;

/**
* @author MajeurAndroid
*/
public class SolidHomeBadger extends ShortcutBadger {

private static final String INTENT_UPDATE_COUNTER = "com.majeur.launcher.intent.action.UPDATE_BADGE";
private static final String PACKAGENAME = "com.majeur.launcher.intent.extra.BADGE_PACKAGE";
private static final String COUNT = "com.majeur.launcher.intent.extra.BADGE_COUNT";
private static final String CLASS = "com.majeur.launcher.intent.extra.BADGE_CLASS";

public SolidHomeBadger(Context context) {
super(context);
}

@Override
protected void executeBadge(int badgeCount) throws ShortcutBadgeException {
Intent intent = new Intent(INTENT_UPDATE_COUNTER);
intent.putExtra(PACKAGENAME, getContextPackageName());
intent.putExtra(COUNT, badgeCount);
intent.putExtra(CLASS, getEntryActivityName());
mContext.sendBroadcast(intent);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package me.leolin.shortcutbadger.util;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.*;
import android.graphics.drawable.Drawable;
import me.leolin.shortcutbadger.ShortcutBadgeException;

import java.io.ByteArrayOutputStream;
import java.util.List;

/**
* Created with IntelliJ IDEA.
Expand Down Expand Up @@ -41,19 +40,18 @@ public static byte[] bitmapToByteArray(Bitmap bitmap) {

public static byte[] drawBadgeOnAppIcon(Context context, int badgeCount) throws ShortcutBadgeException {

Bitmap appIcon = null;
Bitmap appIcon;
String gText = String.valueOf(badgeCount);

List<PackageInfo> packages = context.getPackageManager().getInstalledPackages(0);
for (PackageInfo packageInfo : packages) {
if (context.getPackageName().equals(packageInfo.packageName)) {
Drawable drawable = packageInfo.applicationInfo.loadIcon(context.getPackageManager());
appIcon = drawableToBitmap(drawable);
}
try {
Drawable iconDrawable = context.getPackageManager().getApplicationIcon(context.getPackageName());
appIcon = drawableToBitmap(iconDrawable);
} catch (PackageManager.NameNotFoundException e) {
throw new ShortcutBadgeException("Could not load the app Icon");
}

if (appIcon == null) {
throw new ShortcutBadgeException("count not load the app Icon");
throw new ShortcutBadgeException("Could not load the app Icon");
}

if (badgeCount == 0) {
Expand All @@ -78,38 +76,31 @@ public static byte[] drawBadgeOnAppIcon(Context context, int badgeCount) throws
float cx = appIcon.getWidth() - radius;
float cy = radius;


Paint paint_red = new Paint();
paint_red.setColor(Color.RED);
Paint paint_white = new Paint();
paint_white.setColor(Color.WHITE);
Canvas canvas = new Canvas(appIcon);
canvas.drawCircle(cx, cy, radius, paint_white);


canvas.drawCircle(cx, cy, radius * 6 / 7, paint_red);


// new antialised Paint
Paint paint_text = new Paint(Paint.ANTI_ALIAS_FLAG);
// text color - #3D3D3D
paint_text.setColor(Color.WHITE);
//ANTI_ALIAS to avoid glitched circles
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.WHITE);
canvas.drawCircle(cx, cy, radius, paint);
paint.setColor(Color.RED);
canvas.drawCircle(cx, cy, radius * 6 / 7, paint);

paint.setColor(Color.WHITE);
// text size in pixels
int textSize = (int)(radius*0.7);
int textSize = (int) (radius * 0.7);
if (gText.length() > 1) {
textSize = (int)(radius*0.5);
textSize = (int) (radius * 0.5);
}
paint_text.setTextSize((int) (textSize * scale));
paint_text.setFakeBoldText(true);
paint.setTextSize((int) (textSize * scale));
paint.setFakeBoldText(true);
// draw text to the Canvas center
Rect bounds = new Rect();
paint_text.getTextBounds(gText, 0, gText.length(), bounds);
paint.getTextBounds(gText, 0, gText.length(), bounds);
float bw = bounds.width() / 2;
if (gText.endsWith("1")) {
bw *= 1.25;
}
float bh = bounds.height() / 2;
canvas.drawText(gText, cx - bw, cy + bh, paint_text);
canvas.drawText(gText, cx - bw, cy + bh, paint);

return bitmapToByteArray(appIcon);
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Wed Mar 04 10:08:25 CST 2015
#Thu Mar 12 21:22:24 CST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down

0 comments on commit 3815ce2

Please sign in to comment.