custom-analog-clock-view icon indicating copy to clipboard operation
custom-analog-clock-view copied to clipboard

Sweeping second hand animation

Open ehausen opened this issue 6 years ago • 0 comments

Hello!

I tried modifying the code so that a sweeping second hand effect could be achieved, similar to expensive watches like Rolex have. I know that I should animate the second hand, but don't quite know how to implement it.

First I tried setting the delay in: public void setTime(Calendar calendar) { mCalendar = calendar; invalidate(); if (autoUpdate) { new Handler().postDelayed(new Runnable() { @Override public void run() { setTime(Calendar.getInstance()); } }, 1000); } }

to 250 instead of 1000 and modifying the updateHands() slightly so that second hand would update more often. Obviously 250ms was little bit too much and the second hand jumped weirdly.

I realized that animation is a better idea. I looked at this example: https://stackoverflow.com/questions/13719890/how-to-make-android-sweeping-second-hand-on-analog-clock but realized this widget is using canvas instead of ImageView and found out that a good way would be to use Matrix while animating. Something similar to this: https://stackoverflow.com/questions/27832881/animate-rotation-of-an-image-in-android

Unfortunately I can't quite get it to work. Any suggestions or pointers?

ehausen avatar Apr 29 '18 11:04 ehausen