danger.app
Class Alarm

java.lang.Object
  extended by danger.app.Alarm


public class Alarm
extends Object

Application interface to alarms. You can use Alarm to get notified based on time. Similar to the Timer class, Alarm uses the event system to send notifications. One can setup a new Alarm, activate it, and handle the alarm event callback by handling EventType.EVENT_ALARM in the receiveEvent() method. The requirement is that one has to be a listener to be able to receive alarm events. Unlike the Timer, Alarm's granularity is in seconds. From the Alarm user's perspective, Alarm also runs when the system is in the sleep mode. For example, when you set up an alarm to fire in 10 minutes, the alarm will fire in 10 minutes, whether or not the system goes into sleep mode in between.


Constructor Summary
Alarm(int wake)
          Class constructor specifying wake time.
Alarm(int wake, Listener target)
          Class constructor specifying wake time and listener.
Alarm(int wake, Listener target, int data, Object context)
          Class constructor specifying wake time, listener and context.
Alarm(int wake, Listener target, Object context)
          Class constructor specifying wake time, listener and context.
 
Method Summary
 void activate()
          Activate the alarm.
 void deactivate()
          Deactivate the alarm.
static void forceProcessAlarms()
          Force the alarm dispatcher to process the alarms.
static int getNextAlarmTime()
          Returns the next alarm wake time.
 void resetWake(int inWake)
          Reset the alarm's wake time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Alarm

public Alarm(int wake)
Class constructor specifying wake time. Constructs an alarm with the specified wake time. The alarm events are sent to the application that creates the alarm.

Parameters:
wake - time to wake specified in seconds from the time the Alarm is activated.

Alarm

public Alarm(int wake,
             Listener target)
Class constructor specifying wake time and listener. Constructs an alarm with the specified wake time. The alarm events are sent to the object passed in the listener parameter rather than the application creating the alarm.

Parameters:
wake - time to wake specified in seconds from the time the Alarm is activated.
target - Listener.
See Also:
Listener

Alarm

public Alarm(int wake,
             Listener target,
             Object context)
Class constructor specifying wake time, listener and context. Constructs an alarm with the specified wake time. Alarm events are sent to the specified listener, and the context can be retrieved from the argument field of the alarm event.

Parameters:
wake - time to wake specified in seconds from the time the Alarm is activated.
target - Listener.
context - argument to be passed back in the Alarm event.
See Also:
Listener

Alarm

public Alarm(int wake,
             Listener target,
             int data,
             Object context)
Class constructor specifying wake time, listener and context. Constructs an alarm with the specified wake time. Alarm events are sent to the specified listener, and the context can be retrieved from the argument field of the alarm event.

Parameters:
wake - time to wake specified in seconds from the time the Alarm is activated.
target - Listener.
data - optional data to be passed back to the Alarm event.
context - argument to be passed back in the Alarm event.
See Also:
Listener
Method Detail

activate

public void activate()
Activate the alarm. Starts the alarm. Alarm events will be sent to the listener when the alarm fires.


deactivate

public void deactivate()
Deactivate the alarm. Stops the alarm. This prevents the alarm events from being sent to the listener.


resetWake

public void resetWake(int inWake)
Reset the alarm's wake time. Resets the alarm's wake time. This stops the current alarm, if one has been started; resets the wake time, and starts up a new alarm.

Parameters:
inWake - time to wake specified in seconds from now.

getNextAlarmTime

public static int getNextAlarmTime()
Returns the next alarm wake time. Returns the time the next alarm is scheduled to occur. The time is absolute time in seconds.

Returns:
An int containing the absolute alarm time in seconds.

forceProcessAlarms

public static void forceProcessAlarms()
Force the alarm dispatcher to process the alarms. Normally you shouldn't have to call this method. The alarm dispatcher should be up and running already. This is used by the system when it comes out of the sleep mode.