net.rim.device.api.util
Class TimeSource

java.lang.Object
  extended by net.rim.device.api.util.TimeSource

public class TimeSource
extends Object

Defines a time-source for use by classes that take an application time as a reference point.

The time-source initial state is stopped. Once started, stopping the time-source will cause its recorded time to be reset. Pausing the time-source will cause the next call to start to begin the timesource's count from where it was when it was paused.

See Also:
Animator
Since:
BlackBerry API 6.0.0

Field Summary
static int STATE_PAUSED
          Represents the state when the time-source is paused.
static int STATE_STARTED
          Represents the state when the time-source is playing.
static int STATE_STOPPED
          Represents the state when the time-source is stopped.
 
Method Summary
 void addListener(TimeSourceListener listener)
          Adds a listener on the TimeSource.
 float getSpeed()
          Get the current speed factor of the time-source.
 int getState()
          Gets the time-source's current state: one of STATE_STARTED, STATE_PAUSED, or STATE_STOPPED.
 long getTime()
          Get the amount of time the time-source has been running for.
 void pause()
          Pause the time-source from STATE_STARTED.
 void removeListener(TimeSourceListener listener)
          Removes a listener from the TimeSource.
 void setSpeed(float speed)
          Set the time-source's speed factor.
 void start()
          Start the time-source from STATE_STOPPED or STATE_PAUSED.
 void stop()
          Stops the time-source.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 



Field Detail

STATE_STOPPED

public static final int STATE_STOPPED
Represents the state when the time-source is stopped.

See Also:
TimeSource.getState(), TimeSource.stop(), Constant Field Values
Since:
BlackBerry API 6.0.0

STATE_STARTED

public static final int STATE_STARTED
Represents the state when the time-source is playing.

See Also:
TimeSource.getState(), TimeSource.start(), Constant Field Values
Since:
BlackBerry API 6.0.0

STATE_PAUSED

public static final int STATE_PAUSED
Represents the state when the time-source is paused.

See Also:
TimeSource.getState(), TimeSource.pause(), Constant Field Values
Since:
BlackBerry API 6.0.0


Method Detail

getTime

public long getTime()
Get the amount of time the time-source has been running for.

Returns:
The amount of time the time-source has been running for.
Since:
BlackBerry API 6.0.0

start

public void start()
Start the time-source from STATE_STOPPED or STATE_PAUSED. Has no effect if already playing.

Since:
BlackBerry API 6.0.0

pause

public void pause()
Pause the time-source from STATE_STARTED. Has no effect if stopped or already paused.

Since:
BlackBerry API 6.0.0

stop

public void stop()
Stops the time-source. Has no effect if already stopped.

Since:
BlackBerry API 6.0.0

setSpeed

public void setSpeed(float speed)
Set the time-source's speed factor.

This value will be multiplied by time intervals before they are added to the running time.

Parameters:
speed - The speed factor.
Since:
BlackBerry API 6.0.0

getSpeed

public float getSpeed()
Get the current speed factor of the time-source.

Returns:
The current speed factor of the time-source.
Since:
BlackBerry API 6.0.0

getState

public int getState()
Gets the time-source's current state: one of STATE_STARTED, STATE_PAUSED, or STATE_STOPPED.

Returns:
The time-source's current state.
Since:
BlackBerry API 6.0.0

addListener

public void addListener(TimeSourceListener listener)
Adds a listener on the TimeSource.

Parameters:
listener - TimeSourceListener to listen on the TimeSource.
Throws:
IllegalArgumentException - if listener is null.
Since:
BlackBerry API 6.0.0

removeListener

public void removeListener(TimeSourceListener listener)
Removes a listener from the TimeSource.

Removes the first occurrence of listener from the set of TimeSourceListener's on the TimeSource.

Parameters:
listener - TimeSourceListener to remove from the TimeSource.
Since:
BlackBerry API 6.0.0





Copyright 1999-2010 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.