Fresh from being used to demo Android Studio at Google I/O, the Ultimate Stopwatch version 6.0.4 is rolling out with a couple more tweaks and bug fixes. This has also given me the opportunity to try the Google Play staged rollout feature.
First up, overdraw has been reduced again, this time by removing the background drawable for the window.
UltimateStopwatchActivity.onCreate(){
getWindow().setBackgroundDrawable(null);
}
Resulting in an almost totally green/blue layout, the only remaining red section is in the overlap of the minute and second hands. The screen was already drawing in a fraction of the time needed to maintain 60fps, so at this point it is really just optimizing for the sake of optimizing. Removing the window background had the side effect of a lap time screen without a background at all, leaving a hole in the UI and some freaky results. That was quickly resolved by setting a background color on that view.
I've gone one step further in an experimental version, which results in 0 overdraw for most of the app, but there are still a few margins left with no background color, so it needs a little more work and testing.
Another minor change in 6.0.4 was in the animation timing code. The animation runnable was already using postInvalidateOnAnimation() for JB+ devices, an optimization to cause redraws to happen on the next display frame:
if(JELLYBEAN_OR_ABOVE) postInvalidateOnAnimation();
else invalidate();
However, +ChrisBanes pointed out that there is a version of this in ViewCompat. ViewCompat is a backwards compatible helper provided in the Support Library for accessing View features introduced after API level 4. So, the custom view animation runnable now looks like this:
//Stopwatch animation runnable
private final Runnable animator = new Runnable() {
@Override
public void run() {
updateWatchState(false);
if(mIsRunning)
{
invalidate();
removeCallbacks(this);
ViewCompat.postOnAnimation(StopwatchCustomView.this, this);
}
}
};
private final Runnable animator = new Runnable() {
@Override
public void run() {
updateWatchState(false);
if(mIsRunning)
{
invalidate();
removeCallbacks(this);
ViewCompat.postOnAnimation(StopwatchCustomView.this, this);
}
}
};
Which is more pleasing to the eye, easier to understand for devs reading the code and would benefit from any future advances in ViewCompat.
There are also a couple of other bug fixes in this release:
Issue #42: Fixed - Hands don't reset on Stopwatch when hand animations turned off.
Issue #47: Fixed - Ticking sounds go wrong during onPause onResume cycle.
As always the full source code to Ultimate Stopwatch is available at https://code.google.com/p/android-ultimatestopwatch