Skip to content

Commit

Permalink
Update master to release v1.1.0 (#16)
Browse files Browse the repository at this point in the history
* fix #13 - icon is overlapped on fabSize mini

* Add change badge background color info in README file

* - Update compileSdkVersion and targetSdkVersion to 27
- Update support library version to 27.1.1

* - Add latest version tip in README file

* Bump to version 1.1.0 (5)

* Upgrade build gradle tools to 3.1.4
  • Loading branch information
andremion authored Sep 11, 2018
1 parent e5e5153 commit 82a2d19
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 31 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ It's also used by [Louvre](https://github.com/andremion/Louvre) library.

## Installation

Include the library in your `build.gradle`
Include the library in your `build.gradle` _(check badge at top for latest version)_

```groovy
dependencies{
compile 'com.github.andremion:counterfab:1.0.1'
compile 'com.github.andremion:counterfab:x.y.z'
}
```

Expand All @@ -34,7 +34,7 @@ or in your `pom.xml` if you are using Maven
<dependency>
<groupId>com.github.andremion</groupId>
<artifactId>counterfab</artifactId>
<version>1.0.1</version>
<version>x.y.z</version>
<type>pom</type>
</dependency>
```
Expand Down Expand Up @@ -73,6 +73,17 @@ The recommended way to customize the background color is by using the `app:backg
android:src="@drawable/ic_add_white_24dp" />
```

To change the badge background color you can use the `app:badgeBackgroundColor` attribute

```xml
<com.andremion.counterfab.CounterFab
android:id="@+id/counter_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:badgeBackgroundColor="#009688"
android:src="@drawable/ic_add_white_24dp" />
```

See more at the [sample](https://github.com/andremion/CounterFab/tree/master/sample)

## Libraries and tools used in the project
Expand Down
13 changes: 6 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
}
}
Expand All @@ -22,15 +22,14 @@ allprojects {
}
project.ext {

compileSdkVersion = 26
buildToolsVersion = '26.0.2'
compileSdkVersion = 27
minSdkVersion = 16
targetSdkVersion = 26
targetSdkVersion = 27

versionCode = 4
versionName = "1.0.3"
versionCode = 5
versionName = "1.1.0"

supportLibraryVersion = '26.1.0'
supportLibraryVersion = '27.1.1'

junitVersion = '4.12'
espressoVersion = '2.2.+'
Expand Down
1 change: 0 additions & 1 deletion counterfab/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ apply plugin: 'com.jfrog.bintray'

android {
compileSdkVersion project.ext.compileSdkVersion
buildToolsVersion project.ext.buildToolsVersion
defaultConfig {
minSdkVersion project.ext.minSdkVersion
targetSdkVersion project.ext.targetSdkVersion
Expand Down
39 changes: 31 additions & 8 deletions counterfab/src/main/java/com/andremion/counterfab/CounterFab.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,12 @@ public Float get(CounterFab object) {
}
};

private static final int MAX_COUNT = 99;
private static final String MAX_COUNT_TEXT = "99+";
private static final int NORMAL_MAX_COUNT = 99;
private static final String NORMAL_MAX_COUNT_TEXT = "99+";

private static final int MINI_MAX_COUNT = 9;
private static final String MINI_MAX_COUNT_TEXT = "9+";

private static final int TEXT_SIZE_DP = 11;
private static final int TEXT_PADDING_DP = 2;
private static final int MASK_COLOR = Color.parseColor("#33000000"); // Translucent black as mask color
Expand Down Expand Up @@ -135,17 +139,28 @@ public CounterFab(Context context, AttributeSet attrs, int defStyleAttr) {
mMaskPaint.setColor(MASK_COLOR);

Rect textBounds = new Rect();
mTextPaint.getTextBounds(MAX_COUNT_TEXT, 0, MAX_COUNT_TEXT.length(), textBounds);
mTextPaint.getTextBounds(NORMAL_MAX_COUNT_TEXT, 0, NORMAL_MAX_COUNT_TEXT.length(), textBounds);
mTextHeight = textBounds.height();

float textWidth = mTextPaint.measureText(MAX_COUNT_TEXT);
float textWidth = mTextPaint.measureText(NORMAL_MAX_COUNT_TEXT);
float circleRadius = Math.max(textWidth, mTextHeight) / 2f + textPadding;
mCircleBounds = new Rect(0, 0, (int) (circleRadius * 2), (int) (circleRadius * 2));
int circleEnd = (int) (circleRadius * 2);
if (isSizeMini()) {
int circleStart = (int) (circleRadius / 2);
mCircleBounds = new Rect(circleStart, circleStart, circleEnd, circleEnd);
} else {
int circleStart = 0;
mCircleBounds = new Rect(circleStart, circleStart, (int) (circleRadius * 2), (int) (circleRadius * 2));
}
mContentBounds = new Rect();

onCountChanged();
}

private boolean isSizeMini() {
return super.getSize() == android.support.design.widget.FloatingActionButton.SIZE_MINI;
}

/**
* @return The current count value
*/
Expand Down Expand Up @@ -182,10 +197,18 @@ public void decrease() {
}

private void onCountChanged() {
if (mCount > MAX_COUNT) {
mText = String.valueOf(MAX_COUNT_TEXT);
if (isSizeMini()) {
if (mCount > MINI_MAX_COUNT) {
mText = String.valueOf(MINI_MAX_COUNT_TEXT);
} else {
mText = String.valueOf(mCount);
}
} else {
mText = String.valueOf(mCount);
if (mCount > NORMAL_MAX_COUNT) {
mText = String.valueOf(NORMAL_MAX_COUNT_TEXT);
} else {
mText = String.valueOf(mCount);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
1 change: 0 additions & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion project.ext.compileSdkVersion
buildToolsVersion project.ext.buildToolsVersion
defaultConfig {
applicationId "com.andremion.counterfab.sample"
minSdkVersion project.ext.minSdkVersion
Expand Down
1 change: 0 additions & 1 deletion sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
app:layout_anchor="@id/toolbar"
app:badgeBackgroundColor="#03a9f4"
app:layout_anchorGravity="bottom|end"
app:srcCompat="@drawable/ic_add_white_24dp" />

Expand Down
9 changes: 0 additions & 9 deletions sample/src/main/res/values-v21/styles.xml

This file was deleted.

0 comments on commit 82a2d19

Please sign in to comment.