diff --git a/build.gradle b/build.gradle
index f4b30d0..de3efa6 100644
--- a/build.gradle
+++ b/build.gradle
@@ -3,7 +3,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.2.0'
+ classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
diff --git a/gradle.properties b/gradle.properties
index 1d3591c..43386c3 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,18 +1,3 @@
-# Project-wide Gradle settings.
-
-# IDE (e.g. Android Studio) users:
-# Gradle settings configured through the IDE *will override*
-# any settings specified in this file.
-
-# For more details on how to configure your build environment visit
-# http://www.gradle.org/docs/current/userguide/build_environment.html
-
-# Specifies the JVM arguments used for the daemon process.
-# The setting is particularly useful for tweaking memory settings.
-# Default value: -Xmx10248m -XX:MaxPermSize=256m
-# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
-
-# When configured, Gradle will run in incubating parallel mode.
-# This option should only be used with decoupled projects. More details, visit
-# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
-# org.gradle.parallel=true
\ No newline at end of file
+COMPILE_SDK_VERSION=25
+BUILD_TOOLS_VERSION=25.0.2
+SUPPORT_LIBS_VERSION=25.3.1
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 5fd35a9..f203c2b 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Thu Aug 25 10:49:21 IST 2016
+#Wed Apr 19 17:53:27 CST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
diff --git a/lib-badge/build.gradle b/lib-badge/build.gradle
index 0d2b3b9..0391f3e 100644
--- a/lib-badge/build.gradle
+++ b/lib-badge/build.gradle
@@ -4,24 +4,19 @@ apply plugin: 'com.github.dcendents.android-maven'
group='com.github.nekocode'
android {
- compileSdkVersion 24
- buildToolsVersion "24.0.2"
+ compileSdkVersion COMPILE_SDK_VERSION.toInteger()
+ buildToolsVersion BUILD_TOOLS_VERSION
defaultConfig {
- minSdkVersion 15
- targetSdkVersion 24
- versionCode 2
- versionName "1.6.2"
+ minSdkVersion 11
+ targetSdkVersion 25
}
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
+ lintOptions {
+ abortOnError false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
- compile 'com.android.support:support-annotations:24.2.1'
+ provided "com.android.support:support-annotations:$SUPPORT_LIBS_VERSION"
}
diff --git a/lib-badge/src/main/java/cn/nekocode/badge/BadgeDrawable.java b/lib-badge/src/main/java/cn/nekocode/badge/BadgeDrawable.java
index e6d1182..5e0262c 100644
--- a/lib-badge/src/main/java/cn/nekocode/badge/BadgeDrawable.java
+++ b/lib-badge/src/main/java/cn/nekocode/badge/BadgeDrawable.java
@@ -1,3 +1,19 @@
+/*
+ * Copyright 2017. nekocode (nekocode.cn@gmail.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * 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.
+ */
+
package cn.nekocode.badge;
import android.content.res.Resources;
@@ -17,7 +33,7 @@
import android.text.style.ImageSpan;
/**
- * Created by nekocode on 16/5/28.
+ * @author nekocode (nekocode.cn@gmail.com)
*/
public class BadgeDrawable extends Drawable {
public static final int TYPE_NUMBER = 1;
@@ -57,7 +73,6 @@ private static class Config {
private Paint paint;
private Paint.FontMetrics fontMetrics;
private int text1Width, text2Width;
- private boolean isNeedAutoSetBounds = false;
public static class Builder {
private Config config;
@@ -212,10 +227,6 @@ public String getText2() {
return _CONFIG.text2;
}
- public void setNeedAutoSetBounds(boolean needAutoSetBounds) {
- this.isNeedAutoSetBounds = needAutoSetBounds;
- }
-
private void measureBadge() {
switch (_CONFIG.badgeType) {
case TYPE_ONLY_ONE_TEXT:
@@ -248,16 +259,11 @@ private void measureBadge() {
badgeWidth = badgeHeight = (int) (_CONFIG.textSize * 1.4f);
setCornerRadius(badgeHeight);
}
-
- if (isNeedAutoSetBounds)
- setBounds(0, 0, badgeWidth, badgeHeight);
}
@Override
public void setBounds(int left, int top, int right, int bottom) {
super.setBounds(left, top, right, bottom);
- if (isNeedAutoSetBounds)
- return;
// If any view set the bounds of this drawable
int boundsWidth = right - left;
@@ -308,7 +314,7 @@ public void draw(@NonNull Canvas canvas) {
float textCx = bounds.centerX();
float textCy = bounds.centerY();
- float textCyOffset = (-fontMetrics.ascent) / 2f - dipToPixels(1);
+ float textCyOffset = - (fontMetrics.ascent + fontMetrics.descent / 2f) / 2f;
switch (_CONFIG.badgeType) {
case TYPE_ONLY_ONE_TEXT:
@@ -391,12 +397,12 @@ public void draw(@NonNull Canvas canvas) {
@Override
public int getIntrinsicWidth() {
- return isNeedAutoSetBounds ? badgeWidth : -1;
+ return badgeWidth;
}
@Override
public int getIntrinsicHeight() {
- return isNeedAutoSetBounds ? badgeHeight : -1;
+ return badgeHeight;
}
@Override
@@ -411,7 +417,7 @@ public void setColorFilter(ColorFilter colorFilter) {
@Override
public int getOpacity() {
- return PixelFormat.UNKNOWN;
+ return PixelFormat.TRANSLUCENT;
}
private String cutNumber(int number, int width) {
@@ -444,8 +450,7 @@ private String cutText(String text, int width) {
public SpannableString toSpannable() {
final SpannableString spanStr = new SpannableString(" ");
spanStr.setSpan(new ImageSpan(this, ImageSpan.ALIGN_BOTTOM), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- isNeedAutoSetBounds = true;
- setBounds(0, 0, badgeWidth, badgeHeight);
+ setBounds(0, 0, getIntrinsicWidth(), getIntrinsicHeight());
return spanStr;
}
diff --git a/sample/build.gradle b/sample/build.gradle
index 66b3b5c..59a104b 100644
--- a/sample/build.gradle
+++ b/sample/build.gradle
@@ -1,15 +1,15 @@
apply plugin: 'com.android.application'
android {
- compileSdkVersion 24
- buildToolsVersion "24.0.2"
+ compileSdkVersion COMPILE_SDK_VERSION.toInteger()
+ buildToolsVersion BUILD_TOOLS_VERSION
defaultConfig {
applicationId "cn.nekocode.badge.sample"
minSdkVersion 15
- targetSdkVersion 24
+ targetSdkVersion 25
versionCode 1
- versionName "1.6.1"
+ versionName "1.0"
}
buildTypes {
release {
@@ -22,5 +22,5 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(":lib-badge")
- compile 'com.android.support:appcompat-v7:24.2.1'
+ compile "com.android.support:appcompat-v7:$SUPPORT_LIBS_VERSION"
}
diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml
index db106c5..8a182b3 100644
--- a/sample/src/main/res/layout/activity_main.xml
+++ b/sample/src/main/res/layout/activity_main.xml
@@ -8,7 +8,7 @@
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
- tools:context=".sample.MainActivity"
+ tools:context=".MainActivity"
>