The Chronometer Library is designed to make it easy to use a stopwatch, has features that help count turns, and a custom Widget to display the milliseconds.
- Add it in your
build.gradle
(root) at the end of repositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
- Add the dependency in your
build.gradle
project
dependencies {
implementation 'com.github.gbzarelli:chronometer-library:2.0.0'
}
- Put in your layout xml
<br.com.helpdev.chronometerlib.widget.ChronometerWidget
android:id="@+id/chronometer_widget"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"/>
- The code
fun start(){
chronometer_widget.start()
}
fun reset(){
chronometer_widget.base = SystemClock.elapsedRealtime()
stop()
}
fun stop(){
chronometer_widget.stop()
}
- See
ChronometerManager.kt
andChronometer.kt
val manager = ChronometerManager { SystemClock.elapsedRealtime() }
manager.start()
Thread.sleep(1000) // +1s
manager.lap()
manager.pause()
Thread.sleep(1000) // 1s paused
manager.start()
Thread.sleep(1000) // +1s
manager.stop()
print(ChronometerUtils.getFormattedTime(manager.getChronometerTime()))
val obChronometer = manager.chronometer
println(obChronometer)
manager.reset()
- Play Store: Swimming Stopwatch (Lap counter)
- Github: LapsCounter