As a part of development of Minitris there was a need for a score display that would indicate to the user that the score is increasing and would provide a visual feedback.
It is a standard TextView
subclass driven by RxJava
Observable.interval
towards defined numerical target,
which you can specify either by standard setTarget(long target)
or you can tie it to your Rx stream
via public Action1<Long> targetAction()
(RxJava1) or Consumer<Long> targetConsumer()
(RxJava2)
respectively.
You can see usage examples in sample-rxjava1
and sample-rxjava2
modules.
Add Jetpack.io repository to your project level build.gradle
:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
and add one of these dependencies:
RxJava1 based:
dependencies {
implementation 'com.github.ursimon.CounterTextView:library-rxjava1:1.0.0'
implementation 'com.github.ursimon.CounterTextView:library-common:1.0.0'
}
RxJava2 based:
dependencies {
implementation 'com.github.ursimon.CounterTextView:library-rxjava2:1.0.0'
implementation 'com.github.ursimon.CounterTextView:library-common:1.0.0'
}
Then you can declare it in your XML layout similar to standard TextView
:
<cz.ursiny.countertextview.library.CounterTextView
android:id="@+id/counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:numberFormat="true"
app:speed="100"
/>
It can take up two optional xml parameters:
param | value | description |
---|---|---|
numberFormat | true/false | whether you to be number formatted by default NumberFormat.getInstance().format |
speed | int | speed of Observable.interval ticking to animate towards target, default 25 milliseconds |
You can use base method:
setTarget(long target)
and that will trigger animation towards it or will retarget currently running one
or you can tie it to your rx stream directly using Action1<Long>
, Consumer<Long>
depending on RxJava1/RxJava2 implementation you choose to use