Skip to content
michael edited this page Nov 9, 2015 · 2 revisions

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
    • Using dialogGetResponse, which will wait until the user performs an action to close the dialog box, or
    • Use eventPoll to wait for a "dialog" event.
    • You can find out which list items were selected using dialogGetSelectedItems, which returns an array of numeric indices to your list. For a single choice list, there will only ever be one of these.
  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.
addContextMenuItem Adds 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
addOptionsMenuItem Adds 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."
 
 
clearContextMenu Removes all items previously added to context menu.
clearOptionsMenu Removes all items previously added to options menu.
dialogCreateAlert Create 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"
 
dialogCreateDatePicker Create date picker dialog.
year (Integer) (default=1970)
month (Integer) (default=1)
day (Integer) (default=1)
dialogCreateHorizontalProgress Create a horizontal progress dialog.
title (String) (optional)
message (String) (optional)
maximum progress (Integer) (default=100)
dialogCreateInput Create 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"
dialogCreatePassword Create 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:)
dialogCreateSeekBar Create 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.
dialogCreateSpinnerProgress Create a spinner progress dialog.
title (String) (optional)
message (String) (optional)
maximum progress (Integer) (default=100)
dialogCreateTimePicker Create time picker dialog.
hour (Integer) (default=0)
minute (Integer) (default=0)
is24hour (Boolean) Use 24 hour clock (default=false)
dialogDismiss Dismiss dialog.
dialogGetInput Queries 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
 
dialogGetPassword Queries 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:)
dialogGetResponse Returns dialog response.
dialogGetSelectedItems This method provides list of items user selected.
returns: (Set) Selected items
dialogSetCurrentProgress Set progress dialog current value.
current (Integer)
dialogSetItems Set 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.
dialogSetMaxProgress Set progress dialog maximum value.
max (Integer)
dialogSetMultiChoiceItems Set 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.
dialogSetNegativeButtonText Set alert dialog button text.
text (String)
dialogSetNeutralButtonText Set alert dialog button text.
text (String)
dialogSetPositiveButtonText Set alert dialog positive button text.
text (String)
dialogSetSingleChoiceItems Set 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.
dialogShow Show dialog.
fullDismiss Dismiss Full Screen.
fullKeyOverride Override 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.

fullQuery Get Fullscreen Properties
fullQueryDetail Get fullscreen properties for a specific widget
id (String) id of layout widget
fullSetList Attach a list to a fullscreen widget
id (String) id of layout widget
list (JSONArray) List to set
fullSetProperty Set fullscreen widget property
id (String) id of layout widget
property (String) name of property to set
value (String) value to set property to
fullSetTitle Set the Full Screen Activity Title
title (String) Activity Title
fullShow Show Full Screen.
layout (String) String containing View layout
title (String) Activity Title (optional)
See wiki page for more detail.
webViewShow Display a WebView with the given URL.
url (String)
wait (Boolean) block until the user exits the WebView (optional)
See wiki page for more detail.

Clone this wiki locally