com.googlecode.android_scripting.facade.ui
Class UiFacade

java.lang.Object
  extended by com.googlecode.android_scripting.jsonrpc.RpcReceiver
      extended by com.googlecode.android_scripting.facade.ui.UiFacade

public class UiFacade
extends RpcReceiver

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(java.lang.String, java.lang.Boolean) 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(java.lang.String).
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(java.lang.String, java.lang.String, java.lang.String) and dialogGetPassword(java.lang.String, java.lang.String) 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)

Constructor Summary
UiFacade(FacadeManager manager)
           
 
Method Summary
 void addContextMenuItem(java.lang.String label, java.lang.String event, java.lang.Object data)
          Context menus are used primarily with webViewShow(java.lang.String, java.lang.Boolean)
 void addOptionsMenuItem(java.lang.String label, java.lang.String event, java.lang.Object data, java.lang.String iconName)
          Example (python)
 void clearContextMenu()
           
 void clearOptionsMenu()
           
 void dialogCreateAlert(java.lang.String title, java.lang.String message)
          Example (python)
 void dialogCreateDatePicker(java.lang.Integer year, java.lang.Integer month, java.lang.Integer day)
           
 void dialogCreateHorizontalProgress(java.lang.String title, java.lang.String message, java.lang.Integer max)
           
 void dialogCreateInput(java.lang.String title, java.lang.String message, java.lang.String text, java.lang.String inputType)
          For inputType, see InputTypes.
 java.lang.String dialogCreateNFCBeamMaster(java.lang.String title, java.lang.String message, java.lang.String inputType)
           
 java.lang.String dialogCreateNFCBeamSlave(java.lang.String title, java.lang.String message)
           
 void dialogCreatePassword(java.lang.String title, java.lang.String message)
           
 void dialogCreateSeekBar(java.lang.Integer progress, java.lang.Integer max, java.lang.String title, java.lang.String message)
          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.
 void dialogCreateSpinnerProgress(java.lang.String title, java.lang.String message, java.lang.Integer max)
           
 void dialogCreateTimePicker(java.lang.Integer hour, java.lang.Integer minute, java.lang.Boolean is24hour)
           
 void dialogDismiss()
           
 java.lang.String dialogGetInput(java.lang.String title, java.lang.String message, java.lang.String text)
          The result is the user's input, or None (null) if cancel was hit.
 java.lang.String dialogGetPassword(java.lang.String title, java.lang.String message)
           
 java.lang.Object dialogGetResponse()
           
 java.util.Set<java.lang.Integer> dialogGetSelectedItems()
           
 void dialogSetCurrentProgress(java.lang.Integer current)
           
 void dialogSetItems(JSONArray items)
          This effectively creates list of options.
 void dialogSetMaxProgress(java.lang.Integer max)
           
 void dialogSetMultiChoiceItems(JSONArray items, JSONArray selected)
          This creates a list of check boxes.
 void dialogSetNegativeButtonText(java.lang.String text)
           
 void dialogSetNeutralButtonText(java.lang.String text)
           
 void dialogSetPositiveButtonText(java.lang.String text)
           
 void dialogSetSingleChoiceItems(JSONArray items, java.lang.Integer selected)
          This creates a list of radio buttons.
 void dialogShow()
           
 void fullDismiss()
           
 JSONArray fullKeyOverride(JSONArray keycodes, java.lang.Boolean enable)
          This will override the default behaviour of keys while in the fullscreen mode.
 java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> fullQuery()
           
 java.util.Map<java.lang.String,java.lang.String> fullQueryDetail(java.lang.String id)
           
 java.lang.String fullSetList(java.lang.String id, JSONArray items)
           
 java.lang.String fullSetProperty(java.lang.String id, java.lang.String property, java.lang.String value)
           
 java.util.List<java.lang.String> fullShow(java.lang.String layout)
          See wiki page for more detail.
 java.lang.String NFCBeamMessage(java.lang.String content, java.lang.String title, java.lang.String message)
           
 void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo)
           
 boolean onPrepareOptionsMenu(Menu menu)
           
 void shutdown()
          Invoked when the receiver is shut down.
 void webViewShow(java.lang.String url, java.lang.Boolean wait)
          See wiki page for more detail.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UiFacade

public UiFacade(FacadeManager manager)
Method Detail

dialogCreateInput

@Rpc(description="Create a text input dialog.")
public void dialogCreateInput(@RpcParameter(name="title",description="title of the input box")@RpcDefault(value="Value")
                                             java.lang.String title,
                                             @RpcParameter(name="message",description="message to display above the input box")@RpcDefault(value="Please enter value:")
                                             java.lang.String message,
                                             @RpcParameter(name="defaultText",description="text to insert into the input box")@RpcOptional
                                             java.lang.String text,
                                             @RpcParameter(name="inputType",description="type of input data, ie number or text")@RpcOptional
                                             java.lang.String inputType)
                       throws java.lang.InterruptedException
For inputType, see InputTypes. Some useful ones are text, number, and textUri. Multiple flags can be supplied, seperated by "|", ie: "textUri|textAutoComplete"

Throws:
java.lang.InterruptedException

dialogCreatePassword

@Rpc(description="Create a password input dialog.")
public void dialogCreatePassword(@RpcParameter(name="title",description="title of the input box")@RpcDefault(value="Password")
                                                java.lang.String title,
                                                @RpcParameter(name="message",description="message to display above the input box")@RpcDefault(value="Please enter password:")
                                                java.lang.String message)

dialogGetInput

@Rpc(description="Queries the user for a text input.")
public java.lang.String dialogGetInput(@RpcParameter(name="title",description="title of the input box")@RpcDefault(value="Value")
                                                      java.lang.String title,
                                                      @RpcParameter(name="message",description="message to display above the input box")@RpcDefault(value="Please enter value:")
                                                      java.lang.String message,
                                                      @RpcParameter(name="defaultText",description="text to insert into the input box")@RpcOptional
                                                      java.lang.String text)
                                throws java.lang.InterruptedException
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
 

Throws:
java.lang.InterruptedException

dialogGetPassword

@Rpc(description="Queries the user for a password.")
public java.lang.String dialogGetPassword(@RpcParameter(name="title",description="title of the password box")@RpcDefault(value="Password")
                                                         java.lang.String title,
                                                         @RpcParameter(name="message",description="message to display above the input box")@RpcDefault(value="Please enter password:")
                                                         java.lang.String message)
                                   throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

dialogCreateNFCBeamMaster

@Rpc(description="Create a qpython beam master.")
public java.lang.String dialogCreateNFCBeamMaster(@RpcParameter(name="title",description="title of the input box")@RpcDefault(value="QPython BEAM With NFC")
                                                                 java.lang.String title,
                                                                 @RpcParameter(name="message",description="message to display above the input box")@RpcDefault(value="Input message and Beam")
                                                                 java.lang.String message,
                                                                 @RpcParameter(name="inputType",description="type of input data, ie number or text")@RpcOptional
                                                                 java.lang.String inputType)
                                           throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

NFCBeamMessage

@Rpc(description="Create a qpython beam master to send directory message.")
public java.lang.String NFCBeamMessage(@RpcParameter(name="content",description="message you want to sent")@RpcDefault(value="Message you want to beam")
                                                      java.lang.String content,
                                                      @RpcParameter(name="title",description="title of the input box")@RpcDefault(value="QPython Beam With NFC")
                                                      java.lang.String title,
                                                      @RpcParameter(name="message",description="message to display above the input box")@RpcDefault(value="Beam Message")
                                                      java.lang.String message)
                                throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

dialogCreateNFCBeamSlave

@Rpc(description="Create a qpython beam slave.")
public java.lang.String dialogCreateNFCBeamSlave(@RpcParameter(name="title",description="title of the input box")@RpcDefault(value="QPython Beam With NFC")
                                                                java.lang.String title,
                                                                @RpcParameter(name="message",description="message to display above the input box")@RpcDefault(value="Wait for beam message")
                                                                java.lang.String message)
                                          throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

dialogCreateSpinnerProgress

@Rpc(description="Create a spinner progress dialog.")
public void dialogCreateSpinnerProgress(@RpcParameter(name="title")@RpcOptional
                                                       java.lang.String title,
                                                       @RpcParameter(name="message")@RpcOptional
                                                       java.lang.String message,
                                                       @RpcParameter(name="maximum progress")@RpcDefault(value="100")
                                                       java.lang.Integer max)

dialogCreateHorizontalProgress

@Rpc(description="Create a horizontal progress dialog.")
public void dialogCreateHorizontalProgress(@RpcParameter(name="title")@RpcOptional
                                                          java.lang.String title,
                                                          @RpcParameter(name="message")@RpcOptional
                                                          java.lang.String message,
                                                          @RpcParameter(name="maximum progress")@RpcDefault(value="100")
                                                          java.lang.Integer max)

dialogCreateAlert

@Rpc(description="Create alert dialog.")
public void dialogCreateAlert(@RpcParameter(name="title")@RpcOptional
                                             java.lang.String title,
                                             @RpcParameter(name="message")@RpcOptional
                                             java.lang.String message)
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"
 


dialogCreateSeekBar

@Rpc(description="Create seek bar dialog.")
public void dialogCreateSeekBar(@RpcParameter(name="starting value")@RpcDefault(value="50")
                                               java.lang.Integer progress,
                                               @RpcParameter(name="maximum value")@RpcDefault(value="100")
                                               java.lang.Integer max,
                                               @RpcParameter(name="title")
                                               java.lang.String title,
                                               @RpcParameter(name="message")
                                               java.lang.String message)
Will produce "dialog" events on change, containing: Response will contain a "progress" element.


dialogCreateTimePicker

@Rpc(description="Create time picker dialog.")
public void dialogCreateTimePicker(@RpcParameter(name="hour")@RpcDefault(value="0")
                                                  java.lang.Integer hour,
                                                  @RpcParameter(name="minute")@RpcDefault(value="0")
                                                  java.lang.Integer minute,
                                                  @RpcParameter(name="is24hour",description="Use 24 hour clock")@RpcDefault(value="false")
                                                  java.lang.Boolean is24hour)

dialogCreateDatePicker

@Rpc(description="Create date picker dialog.")
public void dialogCreateDatePicker(@RpcParameter(name="year")@RpcDefault(value="1970")
                                                  java.lang.Integer year,
                                                  @RpcParameter(name="month")@RpcDefault(value="1")
                                                  java.lang.Integer month,
                                                  @RpcParameter(name="day")@RpcDefault(value="1")
                                                  java.lang.Integer day)

dialogDismiss

@Rpc(description="Dismiss dialog.")
public void dialogDismiss()

dialogShow

@Rpc(description="Show dialog.")
public void dialogShow()
                throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

dialogSetCurrentProgress

@Rpc(description="Set progress dialog current value.")
public void dialogSetCurrentProgress(@RpcParameter(name="current")
                                                    java.lang.Integer current)

dialogSetMaxProgress

@Rpc(description="Set progress dialog maximum value.")
public void dialogSetMaxProgress(@RpcParameter(name="max")
                                                java.lang.Integer max)

dialogSetPositiveButtonText

@Rpc(description="Set alert dialog positive button text.")
public void dialogSetPositiveButtonText(@RpcParameter(name="text")
                                                       java.lang.String text)

dialogSetNegativeButtonText

@Rpc(description="Set alert dialog button text.")
public void dialogSetNegativeButtonText(@RpcParameter(name="text")
                                                       java.lang.String text)

dialogSetNeutralButtonText

@Rpc(description="Set alert dialog button text.")
public void dialogSetNeutralButtonText(@RpcParameter(name="text")
                                                      java.lang.String text)

dialogSetItems

@Rpc(description="Set alert dialog list items.")
public void dialogSetItems(@RpcParameter(name="items")
                                          JSONArray items)
This effectively creates list of options. Clicking on an item will immediately return an "item" element, which is the index of the selected item.


dialogSetSingleChoiceItems

@Rpc(description="Set dialog single choice items and selected item.")
public void dialogSetSingleChoiceItems(@RpcParameter(name="items")
                                                      JSONArray items,
                                                      @RpcParameter(name="selected",description="selected item index")@RpcDefault(value="0")
                                                      java.lang.Integer selected)
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.


dialogSetMultiChoiceItems

@Rpc(description="Set dialog multiple choice items and selection.")
public void dialogSetMultiChoiceItems(@RpcParameter(name="items")
                                                     JSONArray items,
                                                     @RpcParameter(name="selected",description="list of selected items")@RpcOptional
                                                     JSONArray selected)
                               throws JSONException
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.

Throws:
JSONException

dialogGetResponse

@Rpc(description="Returns dialog response.")
public java.lang.Object dialogGetResponse()

dialogGetSelectedItems

@Rpc(description="This method provides list of items user selected.",
     returns="Selected items")
public java.util.Set<java.lang.Integer> dialogGetSelectedItems()

webViewShow

@Rpc(description="Display a WebView with the given URL.")
public void webViewShow(@RpcParameter(name="url")
                                       java.lang.String url,
                                       @RpcParameter(name="wait",description="block until the user exits the WebView")@RpcOptional
                                       java.lang.Boolean wait)
                 throws java.io.IOException
See wiki page for more detail.

Throws:
java.io.IOException

addContextMenuItem

@Rpc(description="Adds a new item to context menu.")
public void addContextMenuItem(@RpcParameter(name="label",description="label for this menu item")
                                              java.lang.String label,
                                              @RpcParameter(name="event",description="event that will be generated on menu item click")
                                              java.lang.String event,
                                              @RpcParameter(name="eventData")@RpcOptional
                                              java.lang.Object data)
Context menus are used primarily with webViewShow(java.lang.String, java.lang.Boolean)


addOptionsMenuItem

@Rpc(description="Adds a new item to options menu.")
public void addOptionsMenuItem(@RpcParameter(name="label",description="label for this menu item")
                                              java.lang.String label,
                                              @RpcParameter(name="event",description="event that will be generated on menu item click")
                                              java.lang.String event,
                                              @RpcParameter(name="eventData")@RpcOptional
                                              java.lang.Object data,
                                              @RpcParameter(name="iconName",description="Android system menu icon, see http://developer.android.com/reference/android/R.drawable.html")@RpcOptional
                                              java.lang.String iconName)
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

@Rpc(description="Removes all items previously added to context menu.")
public void clearContextMenu()

clearOptionsMenu

@Rpc(description="Removes all items previously added to options menu.")
public void clearOptionsMenu()

onCreateContextMenu

public void onCreateContextMenu(ContextMenu menu,
                                View v,
                                ContextMenuInfo menuInfo)

onPrepareOptionsMenu

public boolean onPrepareOptionsMenu(Menu menu)

fullShow

@Rpc(description="Show Full Screen.")
public java.util.List<java.lang.String> fullShow(@RpcParameter(name="layout",description="String containing View layout")
                                                                java.lang.String layout)
                                          throws java.lang.InterruptedException
See wiki page for more detail.

Throws:
java.lang.InterruptedException

fullDismiss

@Rpc(description="Dismiss Full Screen.")
public void fullDismiss()

fullQuery

@Rpc(description="Get Fullscreen Properties")
public java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> fullQuery()

fullQueryDetail

@Rpc(description="Get fullscreen properties for a specific widget")
public java.util.Map<java.lang.String,java.lang.String> fullQueryDetail(@RpcParameter(name="id",description="id of layout widget")
                                                                                       java.lang.String id)

fullSetProperty

@Rpc(description="Set fullscreen widget property")
public java.lang.String fullSetProperty(@RpcParameter(name="id",description="id of layout widget")
                                                       java.lang.String id,
                                                       @RpcParameter(name="property",description="name of property to set")
                                                       java.lang.String property,
                                                       @RpcParameter(name="value",description="value to set property to")
                                                       java.lang.String value)

fullSetList

@Rpc(description="Attach a list to a fullscreen widget")
public java.lang.String fullSetList(@RpcParameter(name="id",description="id of layout widget")
                                                   java.lang.String id,
                                                   @RpcParameter(name="list",description="List to set")
                                                   JSONArray items)

fullKeyOverride

@Rpc(description="Override default key actions")
public JSONArray fullKeyOverride(@RpcParameter(name="keycodes",description="List of keycodes to override")
                                                JSONArray keycodes,
                                                @RpcParameter(name="enable",description="Turn overriding or off")@RpcDefault(value="true")
                                                java.lang.Boolean enable)
                          throws JSONException
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.

Throws:
JSONException

shutdown

public void shutdown()
Description copied from class: RpcReceiver
Invoked when the receiver is shut down.

Specified by:
shutdown in class RpcReceiver