Skip to content

Commit

Permalink
Add support-annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
nekocode committed Sep 26, 2016
1 parent c289581 commit 3e3a474
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib-badge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
minSdkVersion 15
targetSdkVersion 24
versionCode 2
versionName "1.6.1"
versionName "1.6.2"
}
buildTypes {
release {
Expand All @@ -23,4 +23,5 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-annotations:24.2.1'
}
14 changes: 10 additions & 4 deletions lib-badge/src/main/java/cn/nekocode/badge/BadgeDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.RoundRectShape;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ImageSpan;
Expand All @@ -21,6 +24,9 @@ public class BadgeDrawable extends Drawable {
public static final int TYPE_ONLY_ONE_TEXT = 1 << 1;
public static final int TYPE_WITH_TWO_TEXT = 1 << 2;
public static final int TYPE_WITH_TWO_TEXT_COMPLEMENTARY = 1 << 3;
@IntDef({TYPE_NUMBER, TYPE_ONLY_ONE_TEXT, TYPE_WITH_TWO_TEXT, TYPE_WITH_TWO_TEXT_COMPLEMENTARY})
public @interface BadgeType {}

private static final float DEFAULT_CORNER_RADIUS = dipToPixels(2);
private static final float DEFAULT_TEXT_SIZE = spToPixels(12);
private static final int DEFAULT_BADGE_COLOR = 0xffCC3333;
Expand Down Expand Up @@ -60,7 +66,7 @@ public Builder() {
config = new Config();
}

public Builder type(int type) {
public Builder type(@BadgeType int type) {
config.badgeType = type;
return this;
}
Expand Down Expand Up @@ -132,7 +138,7 @@ private BadgeDrawable(Config config) {
measureBadge();
}

public void setBadgeType(int type) {
public void setBadgeType(@BadgeType int type) {
_CONFIG.badgeType = type;

measureBadge();
Expand Down Expand Up @@ -286,7 +292,7 @@ public void setBounds(int left, int top, int right, int bottom) {
}

@Override
public void draw(Canvas canvas) {
public void draw(@NonNull Canvas canvas) {
Rect bounds = getBounds();

int marginTopAndBottom = (int) ((bounds.height() - badgeHeight) / 2f);
Expand Down Expand Up @@ -405,7 +411,7 @@ public void setColorFilter(ColorFilter colorFilter) {

@Override
public int getOpacity() {
return 0;
return PixelFormat.UNKNOWN;
}

private String cutNumber(int number, int width) {
Expand Down

0 comments on commit 3e3a474

Please sign in to comment.