Android Open Source - pong-android Fps Counter






From Project

Back to project page pong-android.

License

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.

Java Source Code

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;
    }
  }
}




Java Source Code List

me.zamecnik.android.pong.FpsCounter.java
me.zamecnik.android.pong.GameActivity.java
me.zamecnik.android.pong.GameView.java
me.zamecnik.android.pong.PongGameView.java
me.zamecnik.android.pong.ScalarExpSmoother.java