-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
47 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
COMPILE_SDK_VERSION=25 | ||
BUILD_TOOLS_VERSION=25.0.2 | ||
SUPPORT_LIBS_VERSION=25.3.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
/* | ||
* Copyright 2017. nekocode ([email protected]) | ||
* | ||
* 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 ([email protected]) | ||
*/ | ||
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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters