Click here to Skip to main content
15,886,776 members
Articles / Mobile Apps / Android

Android Puzzles Solver

Rate me:
Please Sign up or sign in to vote.
4.87/5 (17 votes)
1 Oct 2012Apache13 min read 102.5K   7.1K   77  
Puzzles Solver is an Android application for playing and solving puzzles.
package gr.sullenart.time;

public class TimeCounter {

	private long startTime;

	private long totalTime = 0;

	private boolean isStarted = false;

	private boolean isPaused = false;

	private boolean stopTimerOnPause = true;

	public void setStopTimerOnPause(boolean value) {
		stopTimerOnPause = value;
	}

	public long getTime() {
		if (!isStarted || isPaused) {
			return totalTime;
		}
		return totalTime + (System.currentTimeMillis() - startTime);
	}

	public int getTimeSeconds() {
		return (int) (getTime() / 1000);
	}

	public void start() {
		if (!isStarted) {
			startTime = System.currentTimeMillis();
			isStarted = true;
		}
	}

	public void stop() {
		totalTime += (System.currentTimeMillis() - startTime);
		isStarted = false;
	}

	public void pause() {
		if (isStarted && stopTimerOnPause && !isPaused) {
			totalTime += (System.currentTimeMillis() - startTime);
			isPaused = true;
		}
	}

	public void resume() {
		if (isPaused && isStarted) {
			startTime = System.currentTimeMillis();
			isPaused = false;
		}
	}

	public void reset() {
		totalTime = 0;
		isStarted = isPaused = false;
		stopTimerOnPause = true;
	}

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Software Developer (Senior) Self employed
Greece Greece
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions