danger.app
Class Application

java.lang.Object
  extended by danger.app.Listener
      extended by danger.app.Application


public class Application
extends Listener

Application interface to the Application class This class is extended by all applications.


Constructor Summary
Application()
          Constructs a new Application object.
 
Method Summary
protected  void addQuickAccessItem(Bitmap bitmap, CharSequence text, Object data)
          Add a pending item to the QuickAccess window list.
 boolean allowEntryInSystemLock()
          Override to allow this app to be active in system lock.
 void bringToForeground()
          Bring yourself to the foreground.
 Event event()
          Return an event initialized with the given parameters.
 Event event(Event orig)
          Return an event initialized with the given parameters.
 Event event(int type)
          Return an event initialized with the given parameters.
 Event event(int type, int what)
          Return an event initialized with the given parameters.
 Event event(int type, int what, int data)
          Return an event initialized with the given parameters.
 Event event(int type, int what, int data, Object argument)
          Return an event initialized with the given parameters.
 Event event(Listener target, int type)
          Return an event initialized with the given parameters.
 Event event(Listener target, int type, int what)
          Return an event initialized with the given parameters.
 Event event(Listener target, int type, int what, int data)
          Return an event initialized with the given parameters.
 Event event(Listener target, int type, int what, int data, int modifiers)
          Return an event initialized with the given parameters.
 Event event(Listener target, int type, int what, int data, int modifiers, int timestamp, Object argument)
          Return an event initialized with the given parameters.
 Event event(Listener target, int type, int what, int data, Object argument)
          Return an event initialized with the given parameters.
 AlertWindow getAlert(int id, Listener listener)
          Get the alert (but don't show it yet) with the specified resource id.
 Bitmap getBitmap(int id)
          Get a bitmap from the resource database.
 Bundle getBundle()
          Get the application information.
 CharSequence getChooserFolderLabel()
          Access the label that appears next to the application's icon in a chooser folder splash screen.
static Application getCurrentApp()
          Get the current application.
 DialogWindow getDialog(int id, Listener listener)
          Get the dialog (but don't show it yet) with the specified resource id.
 ScreenWindow getFrontScreenWindow()
          Get the frontmost, visible screen window that belongs to this application.
 Window getFrontWindow()
          Get the frontmost, visible window that belongs to this application.
 String getLocaleString(String locale, int id)
          Get a localized string resource from the resource database.
 Listener getNetworkListener()
          Get the current listener for network events.
 Resource getResource(int type, int id)
          Get a resource from the resource database.
 ResourceDatabase getResources()
          Get the resource database associated with this application.
 Shadow getShadow()
          Deprecated. For internal use only.
 String getString(int id)
          Get a string resource from the resource database.
 String[] getStringArray(int id)
          Get a string array resource from the resource database.
 TextInputAlertWindow getTextInputAlert(int id, Listener listener)
          Get the text input alert (but don't show it yet) with the specified resource id.
 boolean handleLauncherMenuShortcut(char inChar)
          Handle a menu shortcut from the launcher application This method is called when the user types a menu shortcut in the launcher application.
 void hideActiveMenu()
          Hide the currently active menu, if one is visible.
 void launch()
          The application was launched.
static void launchApp(Bundle ai)
          Launch the specified application.
 void networkEvent(Object obj)
          Receive a network event from the system.
protected  void onQuickAccessItemSelected(Object argument)
          Respond to a pending item for this application being selected.
 void openURL(URL url)
          Receive and handle a URL based request.
 void openURLInBackground(URL url)
          Receive and handle a URL based request.
 void paintSplashScreen()
          Deprecated. Override renderSplashScreen(danger.ui.View, danger.ui.Pen) if using a splash screen resource is insufficient.
 void quit()
          Quit the application.
 boolean receiveEvent(Event e)
          Receive a new event.
 void receiveMessage(int inMessage, int inData, Object inArgument)
          Receive a message from the system.
static boolean registerForEvent(Listener inListener, int event)
          Register to receive events of a certain type.
static boolean registerForLeftShoulderHeld(String recipient, IPCMessage msg, int priority)
          Register to handle the case of the left shoulder button being held in the Jump screen.
 void removeAllQuickAccessItems()
          Remove all pending items for this application that are currently visible in the QuickAccess window.
 void removeQuickAccessItem(Object data)
          Remove a pending item for this application that is currently visible in the QuickAccess window.
 void renderSplashScreen(View inView, Pen inPen)
          Display the application's splash screen.
 void resume()
          Resume the application.
 void returnToLauncher()
          Return to the Chooser.
static void setAppImpl(danger.app.AppImpl ai)
          Set the application implementation for the system.
 void setChooserFolderLabel(CharSequence label)
          Change the label that appears next to the application's icon in a chooser folder splash screen.
 void setLargeIcon(Bitmap inIcon)
          Set the large icon for this application.
protected  void setName(String appName)
          Change the name of an application.
protected  void setNetworkListener(Listener networkListener)
          Set the current listener for network events.
protected  void setReceiveConnectivityEvents(boolean receiveConnectivityEvents)
          Register this application as being interested in network connectivity events.
protected  void setShowInChooserMenu(boolean showInChooserMenu)
          Control whether the application appears in the chooser menu.
 void setSmallIcon(Bitmap inIcon)
          Set the small icon for this application.
 AlertWindow showAlert(int id)
          Show the alert with the specified resource id.
 AlertWindow showAlert(int id, Listener listener)
          Show the alert with the specified resource id.
 DialogWindow showDialog(int id, Listener listener)
          Show the dialog with the specified resource id.
 TextInputAlertWindow showTextInputAlert(int id, Listener listener)
          Show the text input alert with the specified resource id.
 void suspend()
          Suspend the application.
protected  void unload()
          Should be the last thing called as a response to quit() - this will abort() the app's dispatcher and finalize unloading
static boolean unregisterForEvent(Listener inListener, int event)
          Unregister for events of a certain type, as registered using registerForEvent(danger.app.Listener, int).
static void unregisterForLeftShoulderHeld(String recipient)
          Unregister the specified recipient as the handler of the left shoulder button being held in the Jump screen.
 void updateIcons()
          Notify the system that the application's icons have changed.
 void updatePreviewScreen()
          Request that the system redisplay the application's splash screen.
 
Methods inherited from class danger.app.Listener
cancelEvents, childEventPump, childEventPumpDone, eventProblem, isDispatchingThread, receiveEventInternal, sendEvent, sendEvent, sendEvent, sendEvent, sendEvent, sendLowPriorityEvent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Application

public Application()
Constructs a new Application object. This method creates and registers a new application with the system. It also attaches the new object to the window manager.

Method Detail

receiveEvent

public boolean receiveEvent(Event e)
Receive a new event. This is the main method for receiving events from the system. If the method returns true, the system assumes the event has been handled and does not further processing. If the method returns false, the system does its default processing on the event.

Overrides:
receiveEvent in class Listener
Parameters:
e - An Event object containing the event type and data.
Returns:
A boolean that is true if the method handled the event.

launch

public void launch()
The application was launched. This method is called immediately after the application has been launched. Use this to perform any initialization work that cannot be done in constructors. If you override this method, be sure to call the super method. launch() is guaranteed to be called only once. launch() is guaranteed to be called before resume() or suspend()


allowEntryInSystemLock

public boolean allowEntryInSystemLock()
Override to allow this app to be active in system lock. The phone uses this to allow access to the emergency screen. The system lock app uses this to allow entry to system lock. Unless system lock uses you, you needn't worry about this method and should just leave the default, as it's the most secure thing to do.


handleLauncherMenuShortcut

public boolean handleLauncherMenuShortcut(char inChar)
Handle a menu shortcut from the launcher application This method is called when the user types a menu shortcut in the launcher application. This method is called only for the application whose splash screen is currently showing. Over-ride this method in your application. If you handle the shortcut, return true, otherwise return false.

Parameters:
inChar - The character held down with the menu key.

receiveMessage

public void receiveMessage(int inMessage,
                           int inData,
                           Object inArgument)
Receive a message from the system. This method is used to receive messages from the system. The inMessage parameter contains the type of the message being received. The contents of the inData and inArgument parameters are dependent on the type of message being received.

Parameters:
inMessage - An int containing the type of message being received.
inData - An int containing data associated with the message.
inArgument - An Object containing an object associated with the message.

networkEvent

public void networkEvent(Object obj)

Receive a network event from the system.

This method is used to receive network-related events from the system. To use this method, an application must first define a new unique EventType for the event. It must then define a new class that implements the Storable interface. One of the methods in the Storable interface is GetClassID. The ID returned from this method must be the EventType the application has defined. This is used by the system to map the EventType to a specific object. Finally, the application must use the RegisterHandler to register their new EventType with the system. When the network receives a network object, it calls the GetClassID method to determine which application to send the object to. It then calls the networkEvent method of the application with the object that had been received. Currently there can only be one registered receiver for the event.

Note: this method will be marked protected in a future release.

Parameters:
obj - The object received over the network.
See Also:
EventType

resume

public void resume()
Resume the application. Called whenever the application is selected from the Chooser.


suspend

public void suspend()
Suspend the application. Called whenever the user returns to the Chooser from an application.


quit

public void quit()
Quit the application. Called whenever the application needs to quit. This happens when the system software is being update, when a low-power condition has occured, or when the device is being rebooted.


unload

protected final void unload()
Should be the last thing called as a response to quit() - this will abort() the app's dispatcher and finalize unloading


renderSplashScreen

public void renderSplashScreen(View inView,
                               Pen inPen)

Display the application's splash screen.

This method is called when the application's icon is selected in the Chooser. Application's store their splash screen in the appropriate resource with the ID ID_SPLASH_SCREEN. Because of this the default method of renderSplashScreen can be used for all applications.

Note that in builds prior to the 2.3 release, each call to renderSplashScreen() would receive the same Pen to draw with. You were supposed to redraw the entire Bitmap with it, but if you didn't, whatever you drew last time would still be there. If your drawing routine took a long time, you had to be careful to avoid flicker because the launcher might examine the Bitmap while you were in the middle of drawing into it.

Beginning in the 2.3 release, the Pen provided is a RecordingPen, which has a new and different set of performance concerns. You no longer need worry about flicker, because the Pen will not be redrawn until your method returns. Overall system memory consumption should be lower in general because there is no more need for a huge backing bitmap for each application. However, if your drawing routine does a huge number of individual operations, each of those takes up a certain amount of storage and time, and if you draw any Bitmaps you are urged to draw them from resources (or from ImageView resources) if possible. See the javadoc for RecordingPen for the details.

In the 2.3 release and later, any area of the splash screen where you do not draw anything will be filled with the generic background chiclets. If your splash screen design is suited to it and your application is only going to run on 2.3 or later devices, you are encouraged to draw only the foreground and to let the system draw the background for you.

Note: this method will be marked protected in a future release. You should override, not call this method. To update your splash screen, call updatePreviewScreen() instead.

Parameters:
inView - a view with the bounds corresponding to the splash screen. Generally, you will only use the view to obtain the dimensions of the splash screen.
inPen - the pen to use to draw the splash screen.

updatePreviewScreen

public void updatePreviewScreen()

Request that the system redisplay the application's splash screen.

This method sends an event to the system letting it know that the splash screen has been changed, which will result in a call to renderSplashScreen(danger.ui.View, danger.ui.Pen).

You should call, not override, this method.


updateIcons

public void updateIcons()

Notify the system that the application's icons have changed.

You should call, not override, this method.


setLargeIcon

public void setLargeIcon(Bitmap inIcon)
Set the large icon for this application. This is the bitmap displayed in the Jump screen.

Generally, you will not need to use this method, as the large icon is automatically set to the ID_LARGE_ICON bitmap from your .rsrc file.


setSmallIcon

public void setSmallIcon(Bitmap inIcon)
Set the small icon for this application. This is the bitmap displayed in the Jump screen.

Generally, you will not need to use this method, as the small icon is automatically set to the ID_LARGE_ICON bitmap from your .rsrc file.


paintSplashScreen

public void paintSplashScreen()
Deprecated. Override renderSplashScreen(danger.ui.View, danger.ui.Pen) if using a splash screen resource is insufficient.


setChooserFolderLabel

public void setChooserFolderLabel(CharSequence label)
Change the label that appears next to the application's icon in a chooser folder splash screen. Setting the label to null or "" will clear out the label and the Chooser will simply show the application title in its place.

Parameters:
label - The label to show for the application when it is in a Chooser folder.

getChooserFolderLabel

public CharSequence getChooserFolderLabel()
Access the label that appears next to the application's icon in a chooser folder splash screen.

Returns:
null-ok; the label.

addQuickAccessItem

protected void addQuickAccessItem(Bitmap bitmap,
                                  CharSequence text,
                                  Object data)
Add a pending item to the QuickAccess window list. Pending items appear in the QuickAccess Window. The QuickAccess window gets shown by the user by holding down JUMP. Applications can register arbitrary items to be shown in this list. This method is called as a result of the user selecting the item in the list.

Parameters:
data - Arbitrary data that uniquely identifies a pending item. Its entirely up to the application to decide how they want to interpet this data. When the user selects the item, the onQuickAccessItemSelected(java.lang.Object) method will be invoked for the application.
bitmap - null-ok; An icon for the item. The dimesnions of the icon should not exceed those of the "small" application icon.
text - non-null; Text for the item.

removeQuickAccessItem

public void removeQuickAccessItem(Object data)
Remove a pending item for this application that is currently visible in the QuickAccess window. Pending items are automatically removed right before onQuickAccessItemSelected(java.lang.Object) is invoked. However, you will probably require to manually remove it as the pending state of your application changes. For example, if the user visits your app (independent of QuickAccess) and manipulates data.

Parameters:
data - non-null; Arbitrary data used in addQuickAccessItem(danger.ui.Bitmap, java.lang.CharSequence, java.lang.Object)

removeAllQuickAccessItems

public void removeAllQuickAccessItems()
Remove all pending items for this application that are currently visible in the QuickAccess window. Pending items are automatically removed right before onQuickAccessItemSelected(java.lang.Object) is invoked. However, you will probably require to manually remove it as the pending state of your application changes. For example, if the user visits your app (independent of QuickAccess) and manipulates data.


onQuickAccessItemSelected

protected void onQuickAccessItemSelected(Object argument)
Respond to a pending item for this application being selected. Pending items appear in the QuickAccess Window. The QuickAccess window gets shown by the user by holding down JUMP. Applications can register arbitrary items to be shown in this list. This method is called as a result of the user selecting the item in the list. Note that bringToForeground() is automatically called right after this method executes.

Parameters:
argument - Arbitrary data given by the application when the item was registered with addQuickAccessItem(danger.ui.Bitmap, java.lang.CharSequence, java.lang.Object)

openURL

public void openURL(URL url)
Receive and handle a URL based request. Works as an IPC mechanism between applications. An application can use the RegisterURLSchemeHandler method to register a URL type that it handles (i.e. "date:", "phone:", etc), and the system will then call this method when another application trys to open a URL of this type. This is how the Calendar can dial a phone number stored in an appointment.

Parameters:
url - The URL to be opened/handled.
See Also:
Registrar

openURLInBackground

public void openURLInBackground(URL url)
Receive and handle a URL based request. Works as an IPC mechanism between applications. An application can use the RegisterURLSchemeHandler method to register a URL type that it handles (i.e. "date:", "phone:", etc), and the system will then call this method when another application trys to open a URL of this type. This is how the Calendar can dial a phone number stored in an appointment.

Parameters:
url - The URL to be opened/handled.
See Also:
Registrar

bringToForeground

public void bringToForeground()
Bring yourself to the foreground. Causes your application's Resume method to be called as if it were being run from the Chooser.


returnToLauncher

public final void returnToLauncher()
Return to the Chooser. Causes your application's Suspend method to be called and then returns the user to the Chooser.


getCurrentApp

public static Application getCurrentApp()
Get the current application. Gets a reference to the currently running application. Applications may use this method to reference their application object from methods where it is not readily available through member variables. Though this method may return null when called in some system threads, this should never return null from any user-created thread.

Returns:
null-ok; the instance representing the currently running application.

launchApp

public static void launchApp(Bundle ai)
Launch the specified application. Launch the application specified in the parameter.

Parameters:
ai - An Bundle that contains reference information for the application.
See Also:
Bundle

setAppImpl

public static void setAppImpl(danger.app.AppImpl ai)
Set the application implementation for the system. The AppImpl is an abstract class containing the implementation-specific methods for an application. These are the methods that are different on the simulator versus the actual device. You should not need to call this method because it will have been called during system startup and will have no effect thereafter.

Parameters:
ai - An ApplImpl specifying the type of implementation (i.e. sim or dev).

getBundle

public Bundle getBundle()
Get the application information. Returns the Bundle associated with this application. The Bundle contains the application name, class name, hotkey, and other information related to the application.

Returns:
An Bundle object containing the application information.

getFrontWindow

public Window getFrontWindow()
Get the frontmost, visible window that belongs to this application. Returns the frontmost window that is visible and belongs to this application. Returns null if no windows are visible.

Returns:
A Window containing the frontmost window.

getFrontScreenWindow

public ScreenWindow getFrontScreenWindow()
Get the frontmost, visible screen window that belongs to this application. Returns the frontmost screen window that is visible and belongs to this application. Returns null if no windows are visible. Note that the front most screen window for this application may not be the front most screen window in the system.

Returns:
A Window containing the frontmost window.

getResources

public ResourceDatabase getResources()
Get the resource database associated with this application. Returns the resource database that belongs to this application.

Returns:
A ResourceDatabase containing the resource database.

showAlert

public AlertWindow showAlert(int id)
Show the alert with the specified resource id. Alert events will be passed to the alert itself.

Returns:
The alert that was shown, or null if it could not be found.

showAlert

public AlertWindow showAlert(int id,
                             Listener listener)
Show the alert with the specified resource id. Alert events will be passed to the specified listener.

Returns:
The alert that was shown, or null if it could not be found.

getAlert

public AlertWindow getAlert(int id,
                            Listener listener)
Get the alert (but don't show it yet) with the specified resource id. Alert events will be passed to the specified listener.


showTextInputAlert

public TextInputAlertWindow showTextInputAlert(int id,
                                               Listener listener)
Show the text input alert with the specified resource id. Alert events will be passed to the specified listener.

Returns:
The alert that was shown, or null if it could not be found.

getTextInputAlert

public TextInputAlertWindow getTextInputAlert(int id,
                                              Listener listener)
Get the text input alert (but don't show it yet) with the specified resource id. Alert events will be passed to the specified listener.


showDialog

public DialogWindow showDialog(int id,
                               Listener listener)
Show the dialog with the specified resource id. Dialog events will be passed to the specified listener.

Returns:
The dialog that was shown, or null if it could not be found.

getDialog

public DialogWindow getDialog(int id,
                              Listener listener)
Get the dialog (but don't show it yet) with the specified resource id. Dialog events will be passed to the specified listener.


getString

public String getString(int id)
Get a string resource from the resource database. Returns a string from the resource database for the application. The string to return is specified by the id parameter. If no string with the given id is found, the method returns null.

Parameters:
id - An int specifying the string to be returned.
Returns:
A String containing the specified string or null.

getLocaleString

public String getLocaleString(String locale,
                              int id)
Get a localized string resource from the resource database. Returns a string from the resource database for the application. The string to return is specified by the id parameter. If no resource database for the given locale is available the method returns null. If no string with the given id is found in the database the method returns null.

Parameters:
locale - A String specifying the locale (ie. en_US, fr_CH, etc.)
id - An int specifying the string to be returned.
Returns:
A String containing the specified string or null.

getStringArray

public String[] getStringArray(int id)
Get a string array resource from the resource database. Returns a string array from the resource database for the application. The string array to return is specified by the id parameter. If no string array with the given id is found, the method returns null.

Parameters:
id - an index specifying the string array to be returned.
Returns:
A String[] containing the specified string array or null.

getBitmap

public Bitmap getBitmap(int id)
Get a bitmap from the resource database. Returns a bitmap from the resource database for the application. The bitmap to return is specified by the id parameter. If no bitmap with the given id is found, the method returns null.

Parameters:
id - An int specifying the bitmap to be returned.
Returns:
A Bitmap containing the specified bitmap or null.

getResource

public Resource getResource(int type,
                            int id)
Get a resource from the resource database. Returns a resource from the resource database for the application. The type and id of the resource to get are specified in the type and id parameters. If no resource of the specified type with the given id is found, the method returns null.

Parameters:
type - An int specifying the type of resource to be returned.
id - An int specifying the id of the resource to be returned.
Returns:
A Resource containing the specified resource or null.

getShadow

public final Shadow getShadow()
Deprecated. For internal use only.


hideActiveMenu

public void hideActiveMenu()
Hide the currently active menu, if one is visible.


event

public Event event(Listener target,
                   int type,
                   int what,
                   int data,
                   int modifiers,
                   int timestamp,
                   Object argument)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(Listener target,
                   int type,
                   int what,
                   int data,
                   Object argument)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(Listener target,
                   int type,
                   int what,
                   int data,
                   int modifiers)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(int type,
                   int what,
                   int data,
                   Object argument)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(int type,
                   int what,
                   int data)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(int type,
                   int what)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(int type)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event()
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(Listener target,
                   int type,
                   int what,
                   int data)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(Listener target,
                   int type,
                   int what)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(Listener target,
                   int type)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


event

public Event event(Event orig)
Return an event initialized with the given parameters. This is equivalent to the Event constructor with the same arguments, except that the actual instance may have been recycled rather than constructed afresh.


getNetworkListener

public final Listener getNetworkListener()
Get the current listener for network events. Returns the Listener associated with this application. The Listener is the object that receives network events for the application. The Listener object can be executed in a different thread than the application. If no listener is specified, events are sent to the Application object.

Returns:
A Listener object.

setNetworkListener

protected void setNetworkListener(Listener networkListener)
Set the current listener for network events. Sets the Listener associated with this application. The Listener is the object that receives network events for the application. The Listener object can be executed in a different thread than the application. If no listener is specified, events are sent to the Application object.

Parameters:
networkListener - A Listener object that will receive application events.

setName

protected void setName(String appName)
Change the name of an application. The name of an app should be suitable for display in the Launcher, and other human-readable places.

Parameters:
appName - The new app name.

setShowInChooserMenu

protected void setShowInChooserMenu(boolean showInChooserMenu)
Control whether the application appears in the chooser menu. Note that this only works for apps also marked Invisible ('I') in the ID_APP_FLAGS section of their resources.

Parameters:
showInChooserMenu - Whether to show this app in the chooser menu or not.

setReceiveConnectivityEvents

protected void setReceiveConnectivityEvents(boolean receiveConnectivityEvents)
Register this application as being interested in network connectivity events. By default, an application does not receive EVENT_CONNECTION_UP and EVENT_CONNECTION_DOWN events unless it has registered itself as a handler for a network object. This function allows you to override that setting.

Parameters:
receiveConnectivityEvents - true if you wish to receive connectivity events; false if you do not.

registerForEvent

public static boolean registerForEvent(Listener inListener,
                                       int event)
Register to receive events of a certain type. Registering for an event does not result in a strong reference to the listener. Therefore, if you don't want the listener to be garbage collected, you should maintain a strong reference to it. You can call unregisterForEvent(danger.app.Listener, int) when you no longer want to receive the event. Returns false if the event type is not supported by this method. Note that the active window always gets the following events, even if it is not registered for the events using this method: EventType.EVENT_HEADSET_STATUS, EventType.EVENT_HINGE_CHANGED, EventType.EVENT_NUM_ACTIVE_VOICE_CALLS_CHANGED. Thus, for the above events, you only need to use this method if you want to know about the events when you're not the active window.

Parameters:
inListener - the listener to receive the events
event - the type of event to listen to. Valid values are: EventType.EVENT_POWER, EventType.EVENT_TIME_CHANGED, EventType.EVENT_TIME_FORMAT_CHANGED, EventType.EVENT_PROFILE_CHANGED, EventType.EVENT_ENTERING_KEY_GUARD, EventType.EVENT_LEAVING_KEY_GUARD, EventType.EVENT_PREFERENCES_CHANGED, EventType.EVENT_SIM_PRESENCE, EventType.EVENT_HEADSET_STATUS, EventType.EVENT_CAMERA_STATUS, EventType.EVENT_HINGE_CHANGED, EventType.EVENT_NUM_ACTIVE_VOICE_CALLS_CHANGED, EventType.EVENT_BACKLIGHT_CHANGED, EventType.EVENT_ACTIVE_SPEAKER_CHANGED, EventType.DEVICE_EXT_HOOK_UP, EventType.DEVICE_EXT_HOOK_DOWN, EventType.EVENT_AUDIO_MEDIA_VOLUME_CHANGED, EventType.EVENT_AUDIO_MEDIA_VOLUME_CHANGE_REQUESTED, EventType.EVENT_STORAGE_DEVICE_STATE_CHANGED. Note that if you register for either EventType.DEVICE_EXT_HOOK_UP or EventType.DEVICE_EXT_HOOK_DOWN, you will receive both events.

unregisterForEvent

public static boolean unregisterForEvent(Listener inListener,
                                         int event)
Unregister for events of a certain type, as registered using registerForEvent(danger.app.Listener, int). You do not need to call this simply to allow garbage collection. registerForEvent(danger.app.Listener, int) uses a WeakReference, so as soon as you no longer have a strong reference to the listener, it can be garbage collected. After it is garbage collected, it will automatically be unregistered for any events it was registered for. Thus, you only need to make this call if you want to unregister immediately. Returns false if the event type is not supported by this method. See registerForEvent(danger.app.Listener, int) for a list of valid event values.


registerForLeftShoulderHeld

public static boolean registerForLeftShoulderHeld(String recipient,
                                                  IPCMessage msg,
                                                  int priority)
Register to handle the case of the left shoulder button being held in the Jump screen. Only one application will be able to handle this event. The priority value is used to determine the handler. Danger applications take precedence over third party applications. Returns whether registration was successful.

Parameters:
recipient - IPC service name
msg - the IPC message to send to the service
priority - value used to settle conflicts. If two apps both register for this left shoulder held case, then the one with the higher priority wins. Third party apps calling this method should use priorities less than 100.
Since:
3.0

unregisterForLeftShoulderHeld

public static void unregisterForLeftShoulderHeld(String recipient)
Unregister the specified recipient as the handler of the left shoulder button being held in the Jump screen.

Parameters:
recipient - IPC service name
Since:
3.0
See Also:
registerForLeftShoulderHeld(java.lang.String, danger.app.IPCMessage, int)