From 0d97846d1ee3efb631cd3e6ce9b3c65c7047603f Mon Sep 17 00:00:00 2001 From: Pop Date: Tue, 29 Dec 2020 15:14:12 +0700 Subject: [PATCH 1/3] Upgrade dependency version --- build.gradle | 8 ++++---- demo/build.gradle | 6 +++--- gradle.properties | 1 - gradle/wrapper/gradle-wrapper.properties | 4 ++-- library/build.gradle | 6 +++--- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/build.gradle b/build.gradle index aa267f3..9db1906 100644 --- a/build.gradle +++ b/build.gradle @@ -1,19 +1,19 @@ buildscript { - ext.kotlin_version = '1.3.61' - ext.androidx_version = '1.1.0' + ext.kotlin_version = '1.4.21' + ext.androidx_version = '1.2.0' ext.android_annotation_version = '1.1.0' ext.test_runner_version = '1.2.0' ext.junit_version = '4.12' ext.mockk_version = '1.9.2' - ext.robolectric_version = '4.3.1' + ext.robolectric_version = '4.4' repositories { jcenter() google() } dependencies { - classpath 'com.android.tools.build:gradle:3.5.3' + classpath 'com.android.tools.build:gradle:4.1.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' diff --git a/demo/build.gradle b/demo/build.gradle index 4843780..b1dbaae 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -3,12 +3,12 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { - compileSdkVersion 29 - buildToolsVersion "29.0.2" + compileSdkVersion 30 + buildToolsVersion "30.0.3" defaultConfig { applicationId "com.minibugdev" minSdkVersion 15 - targetSdkVersion 29 + targetSdkVersion 30 versionCode 1 versionName "1.0" } diff --git a/gradle.properties b/gradle.properties index c2f1ff4..9e6fce1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,6 @@ # The setting is particularly useful for tweaking memory settings. android.enableJetifier=true android.useAndroidX=true -android.enableUnitTestBinaryResources=true org.gradle.jvmargs=-Xmx1536m # When configured, Gradle will run in incubating parallel mode. diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c8ed783..54de9d6 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Jun 24 11:14:39 ICT 2019 +#Tue Dec 29 15:08:23 ICT 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip diff --git a/library/build.gradle b/library/build.gradle index 5392b5e..2bcd02a 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -5,12 +5,12 @@ apply plugin: 'com.github.dcendents.android-maven' group = 'com.github.minibugdev' android { - compileSdkVersion 29 - buildToolsVersion "29.0.2" + compileSdkVersion 30 + buildToolsVersion "30.0.3" defaultConfig { minSdkVersion 14 - targetSdkVersion 29 + targetSdkVersion 30 versionCode 5 versionName "2.0.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" From 08e34f87980e64cc2818c62f3651629f059aa3bd Mon Sep 17 00:00:00 2001 From: Pop Date: Tue, 29 Dec 2020 15:23:44 +0700 Subject: [PATCH 2/3] Add feature `Builder.showCounter(Boolean)` --- .../drawablebadge/demo/DemoActivity.kt | 1 + .../minibugdev/drawablebadge/DrawableBadge.kt | 49 +++++++++++-------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/demo/src/main/java/com/minibugdev/drawablebadge/demo/DemoActivity.kt b/demo/src/main/java/com/minibugdev/drawablebadge/demo/DemoActivity.kt index bebc203..50cb46b 100644 --- a/demo/src/main/java/com/minibugdev/drawablebadge/demo/DemoActivity.kt +++ b/demo/src/main/java/com/minibugdev/drawablebadge/demo/DemoActivity.kt @@ -42,6 +42,7 @@ class DemoActivity : AppCompatActivity() { .badgeBorderSize(R.dimen.badge_border_size) .maximumCounter(99) .badgeMargin(10f) + .showCounter(true) .build() .get(number) .let { drawable -> imageViewBadge.setImageDrawable(drawable) } diff --git a/library/src/main/java/com/minibugdev/drawablebadge/DrawableBadge.kt b/library/src/main/java/com/minibugdev/drawablebadge/DrawableBadge.kt index a500155..0e3a2b2 100644 --- a/library/src/main/java/com/minibugdev/drawablebadge/DrawableBadge.kt +++ b/library/src/main/java/com/minibugdev/drawablebadge/DrawableBadge.kt @@ -21,7 +21,8 @@ class DrawableBadge private constructor(val context: Context, val badgeMargin: Float, val bitmap: Bitmap, val isShowBorder: Boolean, - val maximumCounter: Int) { + val maximumCounter: Int, + val isShowCounter: Boolean,){ class Builder(private val context: Context) { @@ -35,6 +36,7 @@ class DrawableBadge private constructor(val context: Context, private var bitmap: Bitmap? = null private var isShowBorder: Boolean? = null private var maximumCounter: Int? = null + private var isShowCounter: Boolean? = null private fun createBitmapFromDrawable(drawable: Drawable): Bitmap { val bitmap = Bitmap.createBitmap(drawable.intrinsicWidth, drawable.intrinsicHeight, Bitmap.Config.ARGB_8888) @@ -100,6 +102,8 @@ class DrawableBadge private constructor(val context: Context, fun maximumCounter(maximumCounter: Int) = apply { this.maximumCounter = maximumCounter } + fun showCounter(isShowCounter: Boolean) = apply { this.isShowCounter = isShowCounter } + fun build(): DrawableBadge { if (bitmap == null) throw IllegalArgumentException("Badge drawable/bitmap can not be null.") if (badgeSize == null) badgeSize(R.dimen.default_badge_size) @@ -110,6 +114,7 @@ class DrawableBadge private constructor(val context: Context, if (badgeGravity == null) badgeGravity(Gravity.TOP or Gravity.END) if (isShowBorder == null) showBorder(true) if (maximumCounter == null) maximumCounter(MAXIMUM_COUNT) + if (isShowCounter == null) showCounter(true) return DrawableBadge( context = context, @@ -122,7 +127,8 @@ class DrawableBadge private constructor(val context: Context, badgeGravity = badgeGravity!!, badgeMargin = badgeMargin ?: 0.0f, isShowBorder = isShowBorder!!, - maximumCounter = maximumCounter!!) + maximumCounter = maximumCounter!!, + isShowCounter = isShowCounter!!) } } @@ -162,27 +168,28 @@ class DrawableBadge private constructor(val context: Context, canvas.drawOval(badgeRect, paintBorder) } - val textSize: Float - val text: String - val max = if (maximumCounter > MAXIMUM_COUNT) MAXIMUM_COUNT else maximumCounter - if (counter > max) { - textSize = badgeRect.height() * 0.45f - text = "$max+" - } - else { - textSize = badgeRect.height() * 0.55f - text = counter.toString() - } + if(isShowCounter) { + val textSize: Float + val text: String + val max = if (maximumCounter > MAXIMUM_COUNT) MAXIMUM_COUNT else maximumCounter + if (counter > max) { + textSize = badgeRect.height() * 0.45f + text = "$max+" + } else { + textSize = badgeRect.height() * 0.55f + text = counter.toString() + } - val textPaint = TextPaint().apply { - this.isAntiAlias = true - this.color = textColor - this.textSize = textSize - } + val textPaint = TextPaint().apply { + this.isAntiAlias = true + this.color = textColor + this.textSize = textSize + } - val x = badgeRect.centerX() - (textPaint.measureText(text) / 2f) - val y = badgeRect.centerY() - (textPaint.ascent() + textPaint.descent()) * 0.5f - canvas.drawText(text, x, y, textPaint) + val x = badgeRect.centerX() - (textPaint.measureText(text) / 2f) + val y = badgeRect.centerY() - (textPaint.ascent() + textPaint.descent()) * 0.5f + canvas.drawText(text, x, y, textPaint) + } return BitmapDrawable(resources, output) } From 2f3ae63685a8f5fe8eebbb84b66c56c613d64dae Mon Sep 17 00:00:00 2001 From: Pop Date: Tue, 29 Dec 2020 15:26:10 +0700 Subject: [PATCH 3/3] Pump up version to 2.0.1 --- README.md | 6 ++++-- library/build.gradle | 4 ++-- .../minibugdev/drawablebadge/DrawableBadgeBuilderTest.kt | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 49f2e30..63f8692 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Drawable Badge [![CircleCI](https://circleci.com/gh/minibugdev/DrawableBadge.svg?style=shield)](https://circleci.com/gh/minibugdev/DrawableBadge) -[![Release](https://jitpack.io/v/minibugdev/DrawableBadge.svg)](https://jitpack.io/#minibugdev/DrawableBadge/2.0.0) +[![Release](https://jitpack.io/v/minibugdev/DrawableBadge.svg)](https://jitpack.io/#minibugdev/DrawableBadge/2.0.1) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/minibugdev/DrawableBadge/master/LICENSE) Drawable Badge is a android library for adding badges to drawables. @@ -21,6 +21,7 @@ val drawable = DrawableBadge.Builder(context) .badgeBorderColor(R.color.badgeBorderColor) .badgeBorderSize(R.dimen.badge_border_size) .maximumCounter(99) + .showCounter(true) .build() .get(99) ``` @@ -42,6 +43,7 @@ imageViewBadge.setImageDrawable(drawable) - `badgeBorderColor`: Badge border color resource id , default `#FFFFFF`. - `badgeBorderSize`: Badge border size supported `@DimenRes` or `@Px`, default `0.5dp`. - `maximumCounter`: Maximum counter text will append with `+`, default and not more than `99`. +- `showCounter`: Set visible of badge counter number, default `true`. #### Deprecated - `badgePosition`: Position of Badge which need to added. @@ -54,7 +56,7 @@ repositories { ``` ``` groovy -compile 'com.github.minibugdev:drawablebadge:2.0.0' +compile 'com.github.minibugdev:drawablebadge:2.0.1' ``` diff --git a/library/build.gradle b/library/build.gradle index 2bcd02a..54caf55 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -11,8 +11,8 @@ android { defaultConfig { minSdkVersion 14 targetSdkVersion 30 - versionCode 5 - versionName "2.0.0" + versionCode 6 + versionName "2.0.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { diff --git a/library/src/test/java/com/minibugdev/drawablebadge/DrawableBadgeBuilderTest.kt b/library/src/test/java/com/minibugdev/drawablebadge/DrawableBadgeBuilderTest.kt index c4e82b7..0e0f9a3 100644 --- a/library/src/test/java/com/minibugdev/drawablebadge/DrawableBadgeBuilderTest.kt +++ b/library/src/test/java/com/minibugdev/drawablebadge/DrawableBadgeBuilderTest.kt @@ -68,6 +68,7 @@ class DrawableBadgeBuilderTest { .badgeGravity(Gravity.CENTER_VERTICAL or Gravity.END) .showBorder(false) .maximumCounter(50) + .showCounter(false) .build() val expectedBadgeColor = ContextCompat.getColor(context, android.R.color.holo_red_dark) @@ -83,5 +84,6 @@ class DrawableBadgeBuilderTest { assertEquals(Gravity.CENTER_VERTICAL or Gravity.END, actual.badgeGravity) assertEquals(false, actual.isShowBorder) assertEquals(50, actual.maximumCounter) + assertEquals(false, actual.isShowCounter) } } \ No newline at end of file