Skip to content

Instantly share code, notes, and snippets.

@kmansoft
Created March 11, 2016 11:57
Show Gist options
  • Save kmansoft/b5c81d4703ac76e66672 to your computer and use it in GitHub Desktop.
Save kmansoft/b5c81d4703ac76e66672 to your computer and use it in GitHub Desktop.
/* Performance logging for animations.
final DebugAnimationListener debug = new DebugAnimationListener();
animator.addUpdateListener(debug);
animator.addListener(debug);
*/
class DebugAnimationListener implements ValueAnimator.AnimatorUpdateListener, Animator.AnimatorListener {
private static final String TAG = "DebugAnimationListener";
long mFrameCount;
long mStart;
@Override
public void onAnimationStart(Animator animation) {
mFrameCount = 0;
mStart = AnimationUtils.currentAnimationTimeMillis();
}
@Override
public void onAnimationEnd(Animator animation) {
if (mStart != 0) {
final long elapsed = AnimationUtils.currentAnimationTimeMillis() - mStart;
final float fps = (mFrameCount * 1000.0f) / elapsed;
MyLog.i(TAG, "%d frames over %d ms, %.02f fps", mFrameCount, elapsed, fps);
}
}
@Override
public void onAnimationCancel(Animator animation) {
mStart = 0;
}
@Override
public void onAnimationRepeat(Animator animation) {
onAnimationStart(animation);
}
@Override
public void onAnimationUpdate(ValueAnimator animation) {
++mFrameCount;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment