Android Open Source - RockFall-Android Stop Watch






From Project

Back to project page RockFall-Android.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project RockFall-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 eu.raffprta.rockfall.app;
// w  w w .j ava 2 s  . c om

/**
 * @author Neil Speirs
 * A stopwatch accumulates time when it is running. You can
 * repeatedly start and stop the stopwatch. You can use a
 * stopwatch to measure the running time of a program.
 *
 * This class was distributed for use (without restrictions) as
 * part of one of my coursework assignments.
 */
public class StopWatch {
    /**
     * Constructs a stopwatch that is in the stopped state
     * and has no time accumulated.
     */
    public StopWatch() {
        reset();
    }

    /**
     * Starts the stopwatch. Time starts accumulating now.
     */
    public void start() {
        if (isRunning) return;
        isRunning = true;
        startTime = System.nanoTime();
    }

    /**
     * Stops the stopwatch. Time stops accumulating and is
     * is added to the elapsed time.
     */
    public void stop() {
        if (!isRunning) return;
        isRunning = false;
        long endTime = System.nanoTime();
        elapsedTime = elapsedTime + endTime - startTime;
    }

    /**
     * Returns the total elapsed time.
     *
     * @return the total elapsed time
     */
    public long getElapsedTime() {
        if (isRunning) {
            long endTime = System.nanoTime();
            elapsedTime = elapsedTime + endTime - startTime;
            startTime = endTime;
        }
        return elapsedTime;
    }

    /**
     * Stops the watch and resets the elapsed time to 0.
     */
    public void reset() {
        elapsedTime = 0;
        isRunning = false;
    }

    private long elapsedTime;
    private long startTime;
    private boolean isRunning;

}




Java Source Code List

eu.raffprta.rockfall.app.GameCanvas.java
eu.raffprta.rockfall.app.GameIntent.java
eu.raffprta.rockfall.app.GameScreen.java
eu.raffprta.rockfall.app.MainGame.java
eu.raffprta.rockfall.app.MenuCanvas.java
eu.raffprta.rockfall.app.SpriteContainer.java
eu.raffprta.rockfall.app.StopWatch.java
eu.raffprta.rockfall.app.TouchHandler.java
eu.raffprta.rockfall.core.entity.AbstractEntity.java
eu.raffprta.rockfall.core.entity.EntityFactory.java
eu.raffprta.rockfall.core.entity.Entity.java
eu.raffprta.rockfall.core.entity.FallableType.java
eu.raffprta.rockfall.core.entity.Fallable.java
eu.raffprta.rockfall.core.entity.Powerup.java
eu.raffprta.rockfall.core.entity.Protagonist.java
eu.raffprta.rockfall.core.entity.Rock.java
eu.raffprta.rockfall.core.sprite.SpriteFactory.java
eu.raffprta.rockfall.core.sprite.SpriteSheet.java
eu.raffprta.rockfall.core.sprite.Sprite.java