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()
          Deprecated. For internal use only.
static int getNextAlarmTime()
          Deprecated. For internal use only.
 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 created.

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 created.
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 created.
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 created.
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.

An alarm will not fire unless activate() or resetWake(int) is called.

Alarm events will be sent to the listener when the alarm fires. Calling this method does not affect the timing of the alarm; the alarm will fire the specified number of seconds after the alarm is created. Note that this behavior is different than Timers, which fire a specified time after Timer.start() is called.


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()
Deprecated. For internal use only.


forceProcessAlarms

public static void forceProcessAlarms()
Deprecated. For internal use only.