SL4A API Help -UiFacade

index
User Interface Facade.

Usage Notes

The UI facade provides access to a selection of dialog boxes for general user interaction, and also hosts the webViewShow call which allows interactive use of html pages.
The general use of the dialog functions is as follows:
  1. Create a dialog using one of the following calls:
  2. Set additional features to your dialog
  3. Display the dialog using dialogShow
  4. Update dialog information if needed
  5. Get the results
  6. Once done, use dialogDismiss to remove the dialog.

You can also manipulate menu options. The menu options are available for both dialogShow and fullShow.
Some notes:
Not every dialogSet function is relevant to every dialog type, ie, dialogSetMaxProgress obviously only applies to dialogs created with a progress bar. Also, an Alert Dialog may have a message or items, not both. If you set both, items will take priority.
In addition to the above functions, dialogGetInput and dialogGetPassword are convenience functions that create, display and return the relevant dialogs in one call.
There is only ever one instance of a dialog. Any dialogCreate call will cause the existing dialog to be destroyed.
@author MeanEYE.rcf (meaneye.rcf@gmail.com)
addContextMenuItemAdds a new item to context menu.
label (String) label for this menu item
event (String) event that will be generated on menu item click
eventData (Object) (optional)
Context menus are used primarily with webViewShow
addOptionsMenuItemAdds a new item to options menu.
label (String) label for this menu item
event (String) event that will be generated on menu item click
eventData (Object) (optional)
iconName (String) Android system menu icon, see http://developer.android.com/reference/android/R.drawable.html (optional)
Example (python)
 import android
 droid=android.Android()
 
 droid.addOptionsMenuItem("Silly","silly",None,"star_on")
 droid.addOptionsMenuItem("Sensible","sensible","I bet.","star_off")
 droid.addOptionsMenuItem("Off","off",None,"ic_menu_revert")
 
 print "Hit menu to see extra options."
 print "Will timeout in 10 seconds if you hit nothing."
 
 while True: # Wait for events from the menu.
   response=droid.eventWait(10000).result
   if response==None:
     break
   print response
   if response["name"]=="off":
     break
 print "And done."
 
 
clearContextMenuRemoves all items previously added to context menu.
clearOptionsMenuRemoves all items previously added to options menu.
dialogCreateAlertCreate alert dialog.
title (String) (optional)
message (String) (optional)
Example (python)
   import android
   droid=android.Android()
   droid.dialogCreateAlert("I like swords.","Do you like swords?")
   droid.dialogSetPositiveButtonText("Yes")
   droid.dialogSetNegativeButtonText("No")
   droid.dialogShow()
   response=droid.dialogGetResponse().result
   droid.dialogDismiss()
   if response.has_key("which"):
     result=response["which"]
     if result=="positive":
       print "Yay! I like swords too!"
     elif result=="negative":
       print "Oh. How sad."
   elif response.has_key("canceled"): # Yes, I know it's mispelled.
     print "You can't even make up your mind?"
   else:
     print "Unknown response=",response
 
   print "Done"
 
dialogCreateDatePickerCreate date picker dialog.
year (Integer) (default=1970)
month (Integer) (default=1)
day (Integer) (default=1)
dialogCreateHorizontalProgressCreate a horizontal progress dialog.
title (String) (optional)
message (String) (optional)
maximum progress (Integer) (default=100)
dialogCreateInputCreate a text input dialog.
title (String) title of the input box (default=Value)
message (String) message to display above the input box (default=Please enter value:)
defaultText (String) text to insert into the input box (optional)
inputType (String) type of input data, ie number or text (optional)
For inputType, see InputTypes. Some useful ones are text, number, and textUri. Multiple flags can be supplied, seperated by "|", ie: "textUri|textAutoComplete"
dialogCreatePasswordCreate a password input dialog.
title (String) title of the input box (default=Password)
message (String) message to display above the input box (default=Please enter password:)
dialogCreateSeekBarCreate seek bar dialog.
starting value (Integer) (default=50)
maximum value (Integer) (default=100)
title (String)
message (String)
Will produce "dialog" events on change, containing:
  • "progress" - Position chosen, between 0 and max
  • "which" = "seekbar"
  • "fromuser" = true/false change is from user input
Response will contain a "progress" element.
dialogCreateSpinnerProgressCreate a spinner progress dialog.
title (String) (optional)
message (String) (optional)
maximum progress (Integer) (default=100)
dialogCreateTimePickerCreate time picker dialog.
hour (Integer) (default=0)
minute (Integer) (default=0)
is24hour (Boolean) Use 24 hour clock (default=false)
dialogDismissDismiss dialog.
dialogGetInputQueries the user for a text input.
title (String) title of the input box (default=Value)
message (String) message to display above the input box (default=Please enter value:)
defaultText (String) text to insert into the input box (optional)
The result is the user's input, or None (null) if cancel was hit.
Example (python)
 import android
 droid=android.Android()
 
 print droid.dialogGetInput("Title","Message","Default").result
 
dialogGetPasswordQueries the user for a password.
title (String) title of the password box (default=Password)
message (String) message to display above the input box (default=Please enter password:)
dialogGetResponseReturns dialog response.
dialogGetSelectedItemsThis method provides list of items user selected.
returns: (Set) Selected items
dialogSetCurrentProgressSet progress dialog current value.
current (Integer)
dialogSetItemsSet alert dialog list items.
items (JSONArray)
This effectively creates list of options. Clicking on an item will immediately return an "item" element, which is the index of the selected item.
dialogSetMaxProgressSet progress dialog maximum value.
max (Integer)
dialogSetMultiChoiceItemsSet dialog multiple choice items and selection.
items (JSONArray)
selected (JSONArray) list of selected items (optional)
This creates a list of check boxes. You can select multiple items out of the list. A response will not be returned until the dialog is closed, either with the Cancel key or a button (positive/negative/neutral). Use dialogGetSelectedItems() to find out what was selected.
dialogSetNegativeButtonTextSet alert dialog button text.
text (String)
dialogSetNeutralButtonTextSet alert dialog button text.
text (String)
dialogSetPositiveButtonTextSet alert dialog positive button text.
text (String)
dialogSetSingleChoiceItemsSet dialog single choice items and selected item.
items (JSONArray)
selected (Integer) selected item index (default=0)
This creates a list of radio buttons. You can select one item out of the list. A response will not be returned until the dialog is closed, either with the Cancel key or a button (positive/negative/neutral). Use dialogGetSelectedItems() to find out what was selected.
dialogShowShow dialog.
fullDismissDismiss Full Screen.
fullKeyOverrideOverride default key actions
keycodes (JSONArray) List of keycodes to override
enable (Boolean) Turn overriding or off (default=true)
This will override the default behaviour of keys while in the fullscreen mode. ie:
   droid.fullKeyOverride([24,25],True)
 
This will override the default behaviour of the volume keys (codes 24 and 25) so that they do not actually adjust the volume.
Returns a list of currently overridden keycodes.
fullQueryGet Fullscreen Properties
fullQueryDetailGet fullscreen properties for a specific widget
id (String) id of layout widget
fullSetListAttach a list to a fullscreen widget
id (String) id of layout widget
list (JSONArray) List to set
fullSetPropertySet fullscreen widget property
id (String) id of layout widget
property (String) name of property to set
value (String) value to set property to
fullSetTitleSet the Full Screen Activity Title
title (String) Activity Title
fullShowShow Full Screen.
layout (String) String containing View layout
title (String) Activity Title (optional)
See wiki page for more detail.
webViewShowDisplay a WebView with the given URL.
url (String)
wait (Boolean) block until the user exits the WebView (optional)
See wiki page for more detail.

index