com.googlecode.android_scripting.facade
Class AndroidFacade

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

public class AndroidFacade
extends RpcReceiver

Some general purpose Android routines.

Intents

Intents are returned as a map, in the following form:

An intent can be built using the makeIntent(java.lang.String, java.lang.String, java.lang.String, JSONObject, JSONArray, java.lang.String, java.lang.String, java.lang.Integer) call, but can also be constructed exterally.


Nested Class Summary
static interface AndroidFacade.Resources
          An instance of this interface is passed to the facade.
 
Constructor Summary
AndroidFacade(FacadeManager manager)
           
 
Method Summary
 java.util.Map<java.lang.String,java.lang.Object> environment()
          
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AndroidFacade

public AndroidFacade(FacadeManager manager)
Method Detail

shutdown

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

Specified by:
shutdown in class RpcReceiver

setClipboard

@Rpc(description="Put text in the clipboard.")
public void setClipboard(@RpcParameter(name="text")
                                        java.lang.String text)
Creates a new AndroidFacade that simplifies the interface to various Android APIs.

Parameters:
service - is the Context the APIs will run under

getClipboard

@Rpc(description="Read text from the clipboard.",
     returns="The text in the clipboard.")
public java.lang.String getClipboard()

putExtrasFromJsonObject

public static void putExtrasFromJsonObject(JSONObject extras,
                                           Intent intent)
                                    throws JSONException
Throws:
JSONException

startActivityForResult

@Rpc(description="Starts an activity and returns the result.",
     returns="A Map representation of the result Intent.")
public Intent startActivityForResult(@RpcParameter(name="action")
                                                           java.lang.String action,
                                                           @RpcParameter(name="uri")@RpcOptional
                                                           java.lang.String uri,
                                                           @RpcParameter(name="type",description="MIME type/subtype of the URI")@RpcOptional
                                                           java.lang.String type,
                                                           @RpcParameter(name="extras",description="a Map of extras to add to the Intent")@RpcOptional
                                                           JSONObject extras,
                                                           @RpcParameter(name="packagename",description="name of package. If used, requires classname to be useful")@RpcOptional
                                                           java.lang.String packagename,
                                                           @RpcParameter(name="classname",description="name of class. If used, requires packagename to be useful")@RpcOptional
                                                           java.lang.String classname)
                              throws JSONException
Throws:
JSONException

startActivityForResultIntent

@Rpc(description="Starts an activity and returns the result.",
     returns="A Map representation of the result Intent.")
public Intent startActivityForResultIntent(@RpcParameter(name="intent",description="Intent in the format as returned from makeIntent")
                                                                 Intent intent)

startActivity

@Rpc(description="Starts an activity.")
public void startActivity(@RpcParameter(name="action")
                                         java.lang.String action,
                                         @RpcParameter(name="uri")@RpcOptional
                                         java.lang.String uri,
                                         @RpcParameter(name="type",description="MIME type/subtype of the URI")@RpcOptional
                                         java.lang.String type,
                                         @RpcParameter(name="extras",description="a Map of extras to add to the Intent")@RpcOptional
                                         JSONObject extras,
                                         @RpcParameter(name="wait",description="block until the user exits the started activity")@RpcOptional
                                         java.lang.Boolean wait,
                                         @RpcParameter(name="packagename",description="name of package. If used, requires classname to be useful")@RpcOptional
                                         java.lang.String packagename,
                                         @RpcParameter(name="classname",description="name of class. If used, requires packagename to be useful")@RpcOptional
                                         java.lang.String classname)
                   throws java.lang.Exception
packagename and classname, if provided, are used in a 'setComponent' call.

Throws:
java.lang.Exception

sendBroadcast

@Rpc(description="Send a broadcast.")
public void sendBroadcast(@RpcParameter(name="action")
                                         java.lang.String action,
                                         @RpcParameter(name="uri")@RpcOptional
                                         java.lang.String uri,
                                         @RpcParameter(name="type",description="MIME type/subtype of the URI")@RpcOptional
                                         java.lang.String type,
                                         @RpcParameter(name="extras",description="a Map of extras to add to the Intent")@RpcOptional
                                         JSONObject extras,
                                         @RpcParameter(name="packagename",description="name of package. If used, requires classname to be useful")@RpcOptional
                                         java.lang.String packagename,
                                         @RpcParameter(name="classname",description="name of class. If used, requires packagename to be useful")@RpcOptional
                                         java.lang.String classname)
                   throws JSONException
Throws:
JSONException

makeIntent

@Rpc(description="Create an Intent.",
     returns="An object representing an Intent")
public Intent makeIntent(@RpcParameter(name="action")
                                               java.lang.String action,
                                               @RpcParameter(name="uri")@RpcOptional
                                               java.lang.String uri,
                                               @RpcParameter(name="type",description="MIME type/subtype of the URI")@RpcOptional
                                               java.lang.String type,
                                               @RpcParameter(name="extras",description="a Map of extras to add to the Intent")@RpcOptional
                                               JSONObject extras,
                                               @RpcParameter(name="categories",description="a List of categories to add to the Intent")@RpcOptional
                                               JSONArray categories,
                                               @RpcParameter(name="packagename",description="name of package. If used, requires classname to be useful")@RpcOptional
                                               java.lang.String packagename,
                                               @RpcParameter(name="classname",description="name of class. If used, requires packagename to be useful")@RpcOptional
                                               java.lang.String classname,
                                               @RpcParameter(name="flags",description="Intent flags")@RpcOptional
                                               java.lang.Integer flags)
                  throws JSONException
Throws:
JSONException

startActivityIntent

@Rpc(description="Start Activity using Intent")
public void startActivityIntent(@RpcParameter(name="intent",description="Intent in the format as returned from makeIntent")
                                               Intent intent,
                                               @RpcParameter(name="wait",description="block until the user exits the started activity")@RpcOptional
                                               java.lang.Boolean wait)
                         throws java.lang.Exception
Throws:
java.lang.Exception

sendBroadcastIntent

@Rpc(description="Send Broadcast Intent")
public void sendBroadcastIntent(@RpcParameter(name="intent",description="Intent in the format as returned from makeIntent")
                                               Intent intent)
                         throws java.lang.Exception
Throws:
java.lang.Exception

vibrate

@Rpc(description="Vibrates the phone or a specified duration in milliseconds.")
public void vibrate(@RpcParameter(name="duration",description="duration in milliseconds")@RpcDefault(value="300")
                                   java.lang.Integer duration)

makeToast

@Rpc(description="Displays a short-duration Toast notification.")
public void makeToast(@RpcParameter(name="message")
                                     java.lang.String message)

getInput

@Rpc(description="Queries the user for a text input.")
@RpcDeprecated(value="dialogGetInput",
               release="r3")
public java.lang.String getInput(@RpcParameter(name="title",description="title of the input box")@RpcDefault(value="SL4A Input")
                                                                          java.lang.String title,
                                                                          @RpcParameter(name="message",description="message to display above the input box")@RpcDefault(value="Please enter value:")
                                                                          java.lang.String message)

getPassword

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

notify

@Rpc(description="Displays a notification that will be canceled when the user clicks on it.")
public void notify(@RpcParameter(name="title",description="title")
                                  java.lang.String title,
                                  @RpcParameter(name="message")
                                  java.lang.String message)

getIntent

@Rpc(description="Returns the intent that launched the script.")
public java.lang.Object getIntent()

sendEmail

@Rpc(description="Launches an activity that sends an e-mail message to a given recipient.")
public void sendEmail(@RpcParameter(name="to",description="A comma separated list of recipients.")
                                     java.lang.String to,
                                     @RpcParameter(name="subject")
                                     java.lang.String subject,
                                     @RpcParameter(name="body")
                                     java.lang.String body,
                                     @RpcParameter(name="attachmentUri")@RpcOptional
                                     java.lang.String attachmentUri)

getPackageVersionCode

@Rpc(description="Returns package version code.")
public int getPackageVersionCode(@RpcParameter(name="packageName")
                                                java.lang.String packageName)

getPackageVersion

@Rpc(description="Returns package version name.")
public java.lang.String getPackageVersion(@RpcParameter(name="packageName")
                                                         java.lang.String packageName)

requiredVersion

@Rpc(description="Checks if version of SL4A is greater than or equal to the specified version.")
public boolean requiredVersion(@RpcParameter(name="requiredVersion")
                                              java.lang.Integer version)

log

@Rpc(description="Writes message to logcat.")
public void log(@RpcParameter(name="message")
                               java.lang.String message)

environment

Map returned:
   TZ = Timezone
     id = Timezone ID
     display = Timezone display name
     offset = Offset from UTC (in ms)
   SDK = SDK Version
   download = default download path
   appcache = Location of application cache 
   sdcard = Space on sdcard
     availblocks = Available blocks
     blockcount = Total Blocks
     blocksize = size of block.
 


getConstants

@Rpc(description="Get list of constants (static final fields) for a class")
public Bundle getConstants(@RpcParameter(name="classname",description="Class to get constants from")
                                          java.lang.String classname)
                    throws java.lang.Exception
Throws:
java.lang.Exception