An open API service indexing awesome lists of open source software.

https://github.com/rasheedsulayman/animatedcounttextview

🚀 A library that helps you animate change in numeric values in a TextView
https://github.com/rasheedsulayman/animatedcounttextview

android animation count library number percentage rise textview

Last synced: 27 days ago
JSON representation

🚀 A library that helps you animate change in numeric values in a TextView

Awesome Lists containing this project

README

        

# AnimatedCountTextView

A library that helps you animate change in numeric values in a `TextView`.

[![Build Status](https://travis-ci.com/r4sh33d/AnimatedCountTextView.svg?token=8TPyvGS2YqpBT3ypdxNc&branch=master)](https://travis-ci.com/r4sh33d/AnimatedCountTextView)
[ ![Download](https://api.bintray.com/packages/r4sh33d/maven/AnimatedCountTextView/images/download.svg) ](https://bintray.com/r4sh33d/maven/AnimatedCountTextView/_latestVersion)

## Gradle Dependency

Add the dependency to your app's `build.gradle`:

```groovy
implementation 'com.r4sh33d:AnimatedCountTextView:0.0.1'
```

## Usage

Add the `AnimatedCountTextView` to your layout.

```xml

```

Then call the `start()` method to start the count:

```kotlin
countTextView.start()
```

You can optionally listen for the count end event by setting a `CountEndListener`

```kotlin
countTextView.countEndListener(object : CountEndListener {
override fun onCountFinish() {
// Do something
}
})
```

If required, you can also stop the count at any time by calling the `stop()` method:
```kotlin
countTextView.stop()
```

That's all for basic usage. Your `AnimatedCountTextView` should animate form your `startWith` value to `endWith` value within the given time `duration`.

## Customisation
`AnimatedCountTextView` attempts to use some default values to simplify the usage. The behaviour can be further
customized by setting the following attributes via `xml` or `code`.

### Start and End values
You can use the xml attributes `startWith` and the `endWith` values to specify the value to animate from, and value to animate to, respectively.

```xml

```
or programmatically:
```kotlin
countTextView.startWith(0)
countTextView.endWith(100)
```

### Duration
You can specify the duration(in milliseconds) for the count-up or count-down animation using the `duration` attribute in xml.

```xml

```
or programmatically:
```kotlin
countTextView.duration(4000)
```

### Number Type
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`.

```xml

```
Programmatically:
```kotlin
countTextView.numberType(NumberType.Decimal(twoDecimalPlacesFormat))
//or
countTextView.numberType(NumberType.Integer())
```
### Prefix and Suffix
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`.

```xml

```
or programmatically:
```kotlin
countTextView.prefix("$")
//or
countTextView.suffix("%")
```

### Interpolator
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:
```kotlin
countTextView.interpolator(AccelerateDecelerateInterpolator())
```

## License

Copyright (c) 2019 Rasheed Sulayman.

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.