Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nekocode committed Apr 20, 2017
1 parent ca1d660 commit fc2ceb4
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 61 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.2.0'
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
Expand Down
21 changes: 3 additions & 18 deletions gradle.properties
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
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
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
19 changes: 7 additions & 12 deletions lib-badge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
39 changes: 22 additions & 17 deletions lib-badge/src/main/java/cn/nekocode/badge/BadgeDrawable.java
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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 5 additions & 5 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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"
}
13 changes: 7 additions & 6 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>

<TextView
Expand All @@ -23,21 +23,22 @@
android:id="@+id/imageView"
android:layout_width="200dp"
android:layout_height="100dp"
android:background="@color/material_grey_300"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/textView"
android:background="@color/material_grey_300"
android:scaleType="fitXY"
/>

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ImageView:"
android:id="@+id/textView"
android:layout_below="@+id/tvHelloWorld"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/tvHelloWorld"
android:layout_marginTop="20dp"
android:text="ImageView:"
android:textStyle="bold"
/>
</RelativeLayout>

0 comments on commit fc2ceb4

Please sign in to comment.