Android Open Source - CalWatch Timer






From Project

Back to project page CalWatch.

License

The source code is released under:

GNU General Public License

If you think the Android project CalWatch 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

// $Id: Timer.java,v 1.7 1999/11/13 19:44:12 gjb Exp $
////from w  ww.  ja  v  a 2s  .  c om
// Cassowary Incremental Constraint Solver
// Original Smalltalk Implementation by Alan Borning
// This Java Implementation by Greg J. Badros, <gjb@cs.washington.edu>
// http://www.cs.washington.edu/homes/gjb
// (C) 1998, 1999 Greg J. Badros and Alan Borning
// See ../LICENSE for legal details regarding this software
//
// Timer, adapted from John P. Russo's C++ Timer class

package EDU.Washington.grad.gjb.cassowary;

public class Timer
{
  public Timer() {
    TimerIsRunning = false;         // Start not yet called.
    ElapsedMs   = 0;             // No time on timer object yet.
  }
  

  public void Start() {
    //  Stopwatch is now running
    TimerIsRunning = true;
    //  Look at internal clock and remember reading
    StartReading   = System.currentTimeMillis();
  }

  public void Stop() {
    TimerIsRunning = false;                       //  Stop timer object.
    ElapsedMs += System.currentTimeMillis() - StartReading;
  }

  //  Clears a Timer of previous elapsed times, so that a new event
  //  can be timed.
  public void Reset() {
    TimerIsRunning = false;             // Start not yet called.
    ElapsedMs   = 0;             // No time on timer object yet.
  }

  // The data member, "TimerIsRunning" is used to keep track of
  // whether a timer is active, i.e. whether an event is being
  // timed. While we want those using the timer class to know when a
  // timer is active, we do NOT want them to directly access the
  // TimerIsRunning variable. We solve this problem, by making
  // TimerIsRunning private and providing the public "access function"
  // below.

  public boolean IsRunning() {
    return TimerIsRunning;
  }
  
  // This function allows a client to determine the amount of time that has
  // elapsed on a timer object. Note that there are two possibilities:

  // 1)  A timer object has been started and stopped. We can detect this
  //     case, because the variable "TimerIsRunning" is false.

  // 2)  A timer object is "running", i.e. is still in the process of timing
  //     an event. It is not expected that this case will occur as frequently
  //     as case 1).

  // In either case, this function converts ticks to seconds. Note that
  // since the function TicksPerSecond() returns a value of type double,
  // an implicit type conversion takes place before doing the division
  // required in either case.

  public double ElapsedTime() {
    if ( !TimerIsRunning )                            // Normal case
      return (double) ElapsedMs/1000;
    else
      return (double) (ElapsedMs + System.currentTimeMillis() - StartReading)/1000;
  }

  private boolean TimerIsRunning;
  private long ElapsedMs;
  private long StartReading;
}




Java Source Code List

EDU.Washington.grad.gjb.cassowary.CL.java
EDU.Washington.grad.gjb.cassowary.ClAbstractVariable.java
EDU.Washington.grad.gjb.cassowary.ClConstraint.java
EDU.Washington.grad.gjb.cassowary.ClDouble.java
EDU.Washington.grad.gjb.cassowary.ClDummyVariable.java
EDU.Washington.grad.gjb.cassowary.ClEditConstraint.java
EDU.Washington.grad.gjb.cassowary.ClEditInfo.java
EDU.Washington.grad.gjb.cassowary.ClEditOrStayConstraint.java
EDU.Washington.grad.gjb.cassowary.ClLinearConstraint.java
EDU.Washington.grad.gjb.cassowary.ClLinearEquation.java
EDU.Washington.grad.gjb.cassowary.ClLinearExpression.java
EDU.Washington.grad.gjb.cassowary.ClLinearInequality.java
EDU.Washington.grad.gjb.cassowary.ClObjectiveVariable.java
EDU.Washington.grad.gjb.cassowary.ClPoint.java
EDU.Washington.grad.gjb.cassowary.ClSimplexSolver.java
EDU.Washington.grad.gjb.cassowary.ClSlackVariable.java
EDU.Washington.grad.gjb.cassowary.ClStayConstraint.java
EDU.Washington.grad.gjb.cassowary.ClStrength.java
EDU.Washington.grad.gjb.cassowary.ClSymbolicWeight.java
EDU.Washington.grad.gjb.cassowary.ClTableau.java
EDU.Washington.grad.gjb.cassowary.ClTestColumns.java
EDU.Washington.grad.gjb.cassowary.ClTests.java
EDU.Washington.grad.gjb.cassowary.ClVariable.java
EDU.Washington.grad.gjb.cassowary.ExCLConstraintNotFound.java
EDU.Washington.grad.gjb.cassowary.ExCLError.java
EDU.Washington.grad.gjb.cassowary.ExCLInternalError.java
EDU.Washington.grad.gjb.cassowary.ExCLNonlinearExpression.java
EDU.Washington.grad.gjb.cassowary.ExCLNotEnoughStays.java
EDU.Washington.grad.gjb.cassowary.ExCLRequiredFailure.java
EDU.Washington.grad.gjb.cassowary.ExCLTooDifficult.java
EDU.Washington.grad.gjb.cassowary.Set.java
EDU.Washington.grad.gjb.cassowary.Timer.java
EDU.Washington.grad.gjb.cassowary.sym.java
EDU.Washington.grad.gjb.cassowary.testClLinearExpression.java
EDU.Washington.grad.gjb.cassowary.testClStrength.java
org.dwallach.calwatch.ApplicationTest.java
org.dwallach.calwatch.BatteryWrapper.java
org.dwallach.calwatch.CalWatchFaceService.java
org.dwallach.calwatch.CalendarFetcher.java
org.dwallach.calwatch.ClockFace.java
org.dwallach.calwatch.ClockState.java
org.dwallach.calwatch.Constants.java
org.dwallach.calwatch.EventLayoutTest.java
org.dwallach.calwatch.EventLayoutUniformTest.java
org.dwallach.calwatch.EventLayoutUniform.java
org.dwallach.calwatch.EventLayout.java
org.dwallach.calwatch.EventWrapper.java
org.dwallach.calwatch.MyViewAnim.java
org.dwallach.calwatch.PaintCan.java
org.dwallach.calwatch.PathCache.java
org.dwallach.calwatch.PhoneActivity.java
org.dwallach.calwatch.PreferencesHelper.java
org.dwallach.calwatch.TimeWrapper.java
org.dwallach.calwatch.VersionWrapper.java
org.dwallach.calwatch.WatchCalendarService.java
org.dwallach.calwatch.WearReceiverService.java
org.dwallach.calwatch.WearSender.java
org.dwallach.calwatch.WireEvent.java
org.dwallach.calwatch.WireUpdate.java
org.dwallach.calwatch.XWatchfaceReceiver.java