├── .gitignore
├── .travis.yml
├── LICENSE.md
├── README.md
├── bintrayconfig.gradle
├── build.gradle
├── dependencies.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── library.iml
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── r4sh33d
│ │ └── animatedcounttextview
│ │ ├── AnimatedCountTextView.kt
│ │ └── Utils.kt
│ ├── res-public
│ └── values
│ │ ├── attrs.xml
│ │ └── public.xml
│ └── res
│ └── values
│ └── strings.xml
├── sample
├── .gitignore
├── build.gradle
├── sample.iml
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── r4sh33d
│ │ └── animatedcounttextview
│ │ └── MainActivity.kt
│ └── res
│ ├── drawable-v24
│ └── ic_launcher_foreground.xml
│ ├── drawable
│ └── ic_launcher_background.xml
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-anydpi-v26
│ ├── ic_launcher.xml
│ └── ic_launcher_round.xml
│ ├── mipmap-hdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-mdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ ├── values-large
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── settings.gradle
├── spotless.gradle
└── spotless.license.kt
/.gitignore:
--------------------------------------------------------------------------------
1 | # Project exclude paths
2 | /.gradle/
3 | /local.properties
4 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | jdk: oraclejdk8
3 | android:
4 | components:
5 | - tools
6 | - platform-tools
7 | - build-tools-29.0.0
8 | - android-29
9 | - extra-android-support
10 | - extra-android-m2repository
11 | - extra-google-m2repository
12 |
13 | licenses:
14 | - '.+'
15 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | ###### Apache License, Version 2.0 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/
2 |
3 | ### TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
4 |
5 | ###### 1. Definitions.
6 |
7 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
8 |
9 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
10 |
11 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
12 |
13 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
14 |
15 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
16 |
17 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
18 |
19 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
20 |
21 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
22 |
23 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
24 |
25 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
26 |
27 | ###### 2. Grant of Copyright License.
28 |
29 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
30 |
31 | ###### 3. Grant of Patent License.
32 |
33 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
34 |
35 | ###### 4. Redistribution.
36 |
37 | You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
38 |
39 | You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
40 |
41 | ###### 5. Submission of Contributions.
42 |
43 | Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
44 |
45 | 6. Trademarks.
46 |
47 | This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48 |
49 | ###### 7. Disclaimer of Warranty.
50 |
51 | Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
52 |
53 | ###### 8. Limitation of Liability.
54 |
55 | In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
56 |
57 | ###### 9. Accepting Warranty or Additional Liability.
58 |
59 | While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
60 |
61 | ### END OF TERMS AND CONDITIONS
62 |
63 | ### APPENDIX: How to apply the Apache License to your work
64 |
65 | To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
66 |
67 | ### Copyright 2019 Cotta & Cush Limited
68 |
69 | 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
70 |
71 | http://www.apache.org/licenses/LICENSE-2.0
72 |
73 | 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.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AnimatedCountTextView
2 |
3 | A library that helps you animate change in numeric values in a `TextView`.
4 |
5 | [](https://travis-ci.com/r4sh33d/AnimatedCountTextView)
6 | [  ](https://bintray.com/r4sh33d/maven/AnimatedCountTextView/_latestVersion)
7 |
8 | ## Gradle Dependency
9 |
10 | Add the dependency to your app's `build.gradle`:
11 |
12 | ```groovy
13 | implementation 'com.r4sh33d:AnimatedCountTextView:0.0.1'
14 | ```
15 |
16 | ## Usage
17 |
18 | Add the `AnimatedCountTextView` to your layout.
19 |
20 | ```xml
21 |
32 | ```
33 |
34 | Then call the `start()` method to start the count:
35 |
36 | ```kotlin
37 | countTextView.start()
38 | ```
39 |
40 | You can optionally listen for the count end event by setting a `CountEndListener`
41 |
42 | ```kotlin
43 | countTextView.countEndListener(object : CountEndListener {
44 | override fun onCountFinish() {
45 | // Do something
46 | }
47 | })
48 | ```
49 |
50 | If required, you can also stop the count at any time by calling the `stop()` method:
51 | ```kotlin
52 | countTextView.stop()
53 | ```
54 |
55 | That's all for basic usage. Your `AnimatedCountTextView` should animate form your `startWith` value to `endWith` value within the given time `duration`.
56 |
57 | ## Customisation
58 | `AnimatedCountTextView` attempts to use some default values to simplify the usage. The behaviour can be further
59 | customized by setting the following attributes via `xml` or `code`.
60 |
61 | ### Start and End values
62 | You can use the xml attributes `startWith` and the `endWith` values to specify the value to animate from, and value to animate to, respectively.
63 |
64 | ```xml
65 |
69 | ```
70 | or programmatically:
71 | ```kotlin
72 | countTextView.startWith(0)
73 | countTextView.endWith(100)
74 | ```
75 |
76 | ### Duration
77 | You can specify the duration(in milliseconds) for the count-up or count-down animation using the `duration` attribute in xml.
78 |
79 | ```xml
80 |
83 | ```
84 | or programmatically:
85 | ```kotlin
86 | countTextView.duration(4000)
87 | ```
88 |
89 | ### Number Type
90 | You can use `NumberType` to specify the type of number you want to animate. You can either specify `NumberType.Integer()` or `NumberType.Decimal()`. You can also apply custom formatting to display the animated values. Custom formats can be specified by passing a `DecimalFormat` to `NumberType.Integer()` or `NumberType.Decimal()` constructor. The default `NumberType` is `Integer`.
91 |
92 | ```xml
93 |
96 | ```
97 | Programmatically:
98 | ```kotlin
99 | countTextView.numberType(NumberType.Decimal(twoDecimalPlacesFormat))
100 | //or
101 | countTextView.numberType(NumberType.Integer())
102 | ```
103 | ### Prefix and Suffix
104 | You can specify `prefix` and/or `suffix` to the animated values. This is useful if you want to specify a currency symbol as a `prefix` or the percentage sign as the `suffix`.
105 |
106 | ```xml
107 |
111 | ```
112 | or programmatically:
113 | ```kotlin
114 | countTextView.prefix("$")
115 | //or
116 | countTextView.suffix("%")
117 | ```
118 |
119 | ### Interpolator
120 | You can specify the [Interpolator](https://developer.android.com/reference/android/view/animation/Interpolator) to use when animating the values. This can only be done programmatically:
121 | ```kotlin
122 | countTextView.interpolator(AccelerateDecelerateInterpolator())
123 | ```
124 |
125 | ## License
126 |
127 | Copyright (c) 2019 Rasheed Sulayman.
128 |
129 | Licensed under the Apache License, Version 2.0 (the "License");
130 | you may not use this file except in compliance with the License.
131 | You may obtain a copy of the License at
132 |
133 | http://www.apache.org/licenses/LICENSE-2.0
134 |
135 | Unless required by applicable law or agreed to in writing, software
136 | distributed under the License is distributed on an "AS IS" BASIS,
137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138 | See the License for the specific language governing permissions and
139 | limitations under the License.
140 |
--------------------------------------------------------------------------------
/bintrayconfig.gradle:
--------------------------------------------------------------------------------
1 | // Set default
2 | ext.modulePackageId = ""
3 |
4 | if (!project.rootProject.file('local.properties').exists()) {
5 | println "Not applying bintrayconfig.gradle"
6 | return
7 | }
8 | apply plugin: 'com.novoda.bintray-release'
9 |
10 | def getBintrayUserAndKey() {
11 | Properties properties = new Properties()
12 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
13 | return [
14 | properties.getProperty("bintray.user"),
15 | properties.getProperty("bintray.apikey")
16 | ]
17 | }
18 |
19 | if (versions == null || versions.publishVersion == null) {
20 | throw new IllegalStateException("Unable to reference publishVersion")
21 | }
22 |
23 | task checkBintrayConfig {
24 | doLast {
25 | def (user, key) = getBintrayUserAndKey()
26 | if (user == null || user.isEmpty() ||
27 | key == null || key.isEmpty()) {
28 | throw new IllegalStateException("Must specify Bintray user/API key in your local.properties.")
29 | }
30 | }
31 | }
32 |
33 | afterEvaluate {
34 | bintrayUpload.dependsOn checkBintrayConfig
35 | }
36 |
37 | def (user, key) = getBintrayUserAndKey()
38 | publish {
39 | bintrayUser = user
40 | bintrayKey = key
41 | userOrg = 'r4sh33d'
42 | groupId = 'com.r4sh33d'
43 | artifactId = 'AnimatedCountTextView'
44 | publishVersion = versions.publishVersion
45 | desc = 'A library that helps you animate change in numeric values in a TextView'
46 | website = 'https://github.com/r4sh33d/AnimatedCountTextView'
47 | dryRun = false
48 | }
49 |
50 | ext.modulePackageId = publish.groupId + '.' + publish.artifactId
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | apply from: './dependencies.gradle'
2 |
3 | buildscript {
4 | apply from: './dependencies.gradle'
5 |
6 | repositories {
7 | google()
8 | jcenter()
9 | }
10 |
11 | dependencies {
12 | classpath 'com.android.tools.build:gradle:' + versions.gradlePlugin
13 | classpath "com.diffplug.spotless:spotless-plugin-gradle:" + versions.spotlessPlugin
14 | classpath 'com.novoda:bintray-release:' + versions.bintrayRelease
15 | classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:' + versions.kotlin
16 | }
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | google()
22 | jcenter()
23 | }
24 |
25 | tasks.withType(Javadoc).all {
26 | enabled = false
27 | }
28 | }
29 |
30 | task clean(type: Delete) {
31 | delete rootProject.buildDir
32 | }
33 |
--------------------------------------------------------------------------------
/dependencies.gradle:
--------------------------------------------------------------------------------
1 | ext.versions = [
2 | minSdk : 19,
3 | compileSdk : 29,
4 | buildTools : '29.0.0',
5 | publishVersion : '0.0.1',
6 | publishVersionCode: 1,
7 |
8 | gradlePlugin : '3.4.1',
9 | spotlessPlugin : '3.23.1',
10 | versionsPlugin : '0.21.0',
11 | bintrayRelease : '0.9.1',
12 |
13 | kotlin : '1.3.40',
14 | ktx : '1.0.2',
15 | androidx : '1.0.2',
16 |
17 | material : '1.1.0-alpha07',
18 | ]
19 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rasheedsulayman/AnimatedCountTextView/134c07ce20ff2eb3422e5fa2f7422bcf9def1a6b/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Jun 30 19:33:56 WAT 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply from: '../dependencies.gradle'
4 |
5 | apply from: '../bintrayconfig.gradle'
6 |
7 | android {
8 | compileSdkVersion versions.compileSdk
9 | buildToolsVersion versions.buildTools
10 |
11 | compileOptions {
12 | sourceCompatibility 1.8
13 | targetCompatibility 1.8
14 |
15 | if (modulePackageId != null && modulePackageId != '') {
16 | logger.warn('Package for current module: ' + modulePackageId)
17 | kotlinOptions.freeCompilerArgs += ['-module-name', modulePackageId]
18 | } else {
19 | logger.warn('Skipping setting compiler module name, no package to use.')
20 | }
21 | }
22 |
23 | defaultConfig {
24 | minSdkVersion versions.minSdk
25 | targetSdkVersion versions.compileSdk
26 | versionCode versions.publishVersionCode
27 | versionName versions.publishVersion
28 | }
29 |
30 | sourceSets {
31 | main.res.srcDirs = [
32 | 'src/main/res',
33 | 'src/main/res-public'
34 | ]
35 | }
36 | }
37 |
38 | dependencies {
39 | implementation 'androidx.appcompat:appcompat:' + versions.androidx
40 | implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:' + versions.kotlin
41 | api 'com.google.android.material:material:' + versions.material
42 | }
43 |
44 | apply from: '../spotless.gradle'
--------------------------------------------------------------------------------
/library/library.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | generateDebugSources
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
43 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/library/src/main/java/com/r4sh33d/animatedcounttextview/AnimatedCountTextView.kt:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rasheed Sulayman.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.r4sh33d.animatedcounttextview
17 |
18 | import android.animation.Animator
19 | import android.animation.AnimatorListenerAdapter
20 | import android.animation.ValueAnimator
21 | import android.annotation.SuppressLint
22 | import android.content.Context
23 | import android.util.AttributeSet
24 | import android.view.animation.AccelerateDecelerateInterpolator
25 | import android.view.animation.Interpolator
26 | import androidx.appcompat.widget.AppCompatTextView
27 | import com.r4sh33d.animatedcounttextview.NumberType.*
28 |
29 | class AnimatedCountTextView(context: Context, attrs: AttributeSet?) :
30 | AppCompatTextView(context, attrs) {
31 | private lateinit var valueAnimator: ValueAnimator
32 | private var numberType: NumberType = Integer()
33 | private var startValue: Number = 0f
34 | private var endValue: Number = 0f
35 | private var animationDuration: Long
36 | private var animationEndListener: CountEndListener? = null
37 | private var animationinterpolator: Interpolator = AccelerateDecelerateInterpolator()
38 | private var prefix = ""
39 | private var suffix = ""
40 |
41 | init {
42 | context.theme.obtainStyledAttributes(
43 | attrs,
44 | R.styleable.AnimatedCountTextView,
45 | 0, 0
46 | ).run {
47 | try {
48 | getString(R.styleable.AnimatedCountTextView_prefix)?.let {
49 | prefix = it
50 | }
51 | getString(R.styleable.AnimatedCountTextView_suffix)?.let {
52 | suffix = it
53 | }
54 | getString(R.styleable.AnimatedCountTextView_startWith)?.run {
55 | startValue = toFloat()
56 | }
57 | getString(R.styleable.AnimatedCountTextView_endWith)?.run {
58 | endValue = toFloat()
59 | }
60 | getInt(R.styleable.AnimatedCountTextView_numberType, 1).let {
61 | numberType = if (it == 1) Integer() else Decimal()
62 | }
63 | animationDuration = getInt(R.styleable.AnimatedCountTextView_duration, 4000).toLong()
64 | } finally {
65 | recycle()
66 | }
67 | }
68 | }
69 |
70 | @SuppressLint("SetTextI18n")
71 | fun start() {
72 | if (::valueAnimator.isInitialized && valueAnimator.isRunning) {
73 | valueAnimator.end()
74 | }
75 | valueAnimator = if (numberType is Integer) {
76 | ValueAnimator.ofInt(startValue.toInt(), endValue.toInt())
77 | } else {
78 | ValueAnimator.ofFloat(startValue.toFloat(), endValue.toFloat())
79 | }.apply {
80 | duration = animationDuration
81 | interpolator = animationinterpolator
82 | addUpdateListener {
83 | text = "$prefix${numberType.formatter.format(it.animatedValue.toString().toFloat())}$suffix"
84 | }
85 | addListener(object : AnimatorListenerAdapter() {
86 | override fun onAnimationEnd(animation: Animator?) {
87 | animationEndListener?.onCountFinish()
88 | }
89 | })
90 | start()
91 | }
92 | }
93 |
94 | // ---> Begin Public APIs
95 |
96 | fun startWith(value: Number) {
97 | startValue = value
98 | }
99 |
100 | fun duration(duration: Long) {
101 | animationDuration = duration
102 | }
103 |
104 | fun endWith(value: Number) {
105 | endValue = value
106 | }
107 |
108 | fun numberType(numberType: NumberType) {
109 | this.numberType = numberType
110 | }
111 |
112 | fun interpolator(interpolator: Interpolator) {
113 | animationinterpolator = interpolator
114 | }
115 |
116 | fun countEndListener(countEndListener: CountEndListener) {
117 | this.animationEndListener = countEndListener
118 | }
119 |
120 | fun prefix(prefix: String) {
121 | this.prefix = prefix
122 | }
123 |
124 | fun suffix(suffix: String) {
125 | this.suffix = suffix
126 | }
127 |
128 | fun stop() {
129 | if (::valueAnimator.isInitialized) valueAnimator.end()
130 | }
131 |
132 | // ---> End Public APIs
133 | }
134 |
--------------------------------------------------------------------------------
/library/src/main/java/com/r4sh33d/animatedcounttextview/Utils.kt:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Rasheed Sulayman.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.r4sh33d.animatedcounttextview
17 |
18 | import java.text.DecimalFormat
19 | import java.text.NumberFormat
20 |
21 | interface CountEndListener {
22 | fun onCountFinish()
23 | }
24 |
25 | sealed class NumberType(val formatter: DecimalFormat) {
26 | class Integer(format: DecimalFormat = wholeNumberDecimalFormat) : NumberType(format)
27 | class Decimal(format: DecimalFormat = twoDecimalPlacesFormat) : NumberType(format)
28 | }
29 |
30 | internal val wholeNumberDecimalFormat =
31 | (NumberFormat.getNumberInstance() as DecimalFormat).apply {
32 | applyPattern("#0")
33 | }
34 |
35 | internal val twoDecimalPlacesFormat =
36 | (NumberFormat.getNumberInstance() as DecimalFormat).apply {
37 | applyPattern("#0.00")
38 | }
39 |
--------------------------------------------------------------------------------
/library/src/main/res-public/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/library/src/main/res-public/values/public.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply from: '../dependencies.gradle'
2 |
3 | apply plugin: 'com.android.application'
4 | apply plugin: 'kotlin-android'
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 |
8 | android {
9 | compileSdkVersion versions.compileSdk
10 | buildToolsVersion versions.buildTools
11 |
12 | compileOptions {
13 | sourceCompatibility 1.8
14 | targetCompatibility 1.8
15 | }
16 |
17 | defaultConfig {
18 | applicationId "com.r4sh33d.AnimatedCountTextView"
19 | minSdkVersion versions.minSdk
20 | targetSdkVersion versions.compileSdk
21 | versionCode versions.publishVersionCode
22 | versionName versions.publishVersion
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation project(':library')
28 | implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:' + versions.kotlin
29 | implementation 'androidx.core:core-ktx:' + versions.ktx
30 | implementation 'com.google.android.material:material:' + versions.material
31 | implementation 'androidx.appcompat:appcompat:' + versions.androidx
32 | implementation 'com.android.support.constraint:constraint-layout:' + versions.constraintLayout
33 | implementation 'androidx.appcompat:appcompat:1.1.0'
34 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
35 | }
36 |
37 | apply from: '../spotless.gradle'
38 |
--------------------------------------------------------------------------------
/sample/sample.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | generateDebugSources
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
47 |