Created
March 11, 2016 11:57
-
-
Save kmansoft/b5c81d4703ac76e66672 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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