Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show milliseconds with Android Chronometer

I'm looking for a way to make the Chronometer in Android (preferably 1.6 and upwards) show 10ths of a second while counting up.

Is it possible to do this? If not, is there a free (and preferably open source) library that does the same? Failing that I'll write my own, but I'd rather use someone else's!

like image 915
Matthew Steeples Avatar asked Jun 05 '10 09:06

Matthew Steeples


3 Answers

Android's default chronometer widget does not support millisecond formatting.

I have modified the Chronometer widget source code in order to show milliseconds. Download it from github.

like image 98
antoniom Avatar answered Oct 15 '22 13:10

antoniom


Is it possible to do this?

Not really. You could pass a format string that shows tenths of a second, but the Chronometer itself only updates every second. The update frequency is baked into the code.

If not, is there a free (and preferably open source) library that does the same?

The Chronometer source is available under the Apache License 2.0, so you can modify it to suit. Find all occurrences of 1000 and change them to 100, and you're probably most of the way there.

Bear in mind that this Chronometer can be used in an activity but not an app widget, since customized View classes are not supported by the app widget framework.

like image 5
CommonsWare Avatar answered Oct 15 '22 12:10

CommonsWare


I created an instance of a class that I built inside the Activity. This new class was an extension of the Android CountDownTimer class(add the implemented methods)

Here in the constructor you can add the duration in milliseconds and the interval to be 1/10 of a second, that is 100 milliseconds. In the onTick method, the commands are executed every 1/100th of a second for the given duration. That should work.

like image 1
Bharat Ahuja Avatar answered Oct 15 '22 11:10

Bharat Ahuja