Back to project page pong-android.
The source code is released under:
MIT License
If you think the Android project pong-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package me.zamecnik.android.pong; /*from w w w .ja v a 2s . c om*/ import android.widget.TextView; public class FpsCounter { private static final int MIN_FPS_DRAW_PERIOD_MILLIS = 200; private static final double SMOOTHING_COEFFICIENT = 0.1; private final TextView textView; private final ScalarExpSmoother fpsSmoother = new ScalarExpSmoother( SMOOTHING_COEFFICIENT); private long lastFpsDrawTime; public FpsCounter(TextView textView) { this.textView = textView; } public void updateFps(double fps) { final double smoothedFps = fpsSmoother.smooth(fps); long now = System.currentTimeMillis(); boolean canDrawFps = now - lastFpsDrawTime > MIN_FPS_DRAW_PERIOD_MILLIS; if (canDrawFps) { textView.post(new Runnable() { public void run() { textView.setText(String.format("FPS: %.2f", smoothedFps)); } }); lastFpsDrawTime = now; } } }