com.phonegap
Class DroidGap

java.lang.Object
  extended by Activity
      extended by com.phonegap.api.PhonegapActivity
          extended by com.phonegap.DroidGap
Direct Known Subclasses:
StandAlone

public class DroidGap
extends com.phonegap.api.PhonegapActivity

This class is the main Android activity that represents the PhoneGap application. It should be extended by the user to load the specific html file that contains the application. As an example: package com.phonegap.examples; import android.app.Activity; import android.os.Bundle; import com.phonegap.*; public class Examples extends DroidGap {


Nested Class Summary
 class DroidGap.GapClient
          Set the chrome handler.
 class DroidGap.GapViewClient
          The webview client receives notifications about appView
 
Field Summary
protected  com.phonegap.api.IPlugin activityResultCallback
           
protected  boolean activityResultKeepRunning
           
protected  WebView appView
           
 boolean bound
           
 CallbackServer callbackServer
           
protected  boolean cancelLoadUrl
           
protected  boolean clearHistory
           
protected  boolean keepRunning
           
protected  boolean loadInWebView
           
protected  int loadUrlTimeoutValue
           
protected  com.phonegap.api.PluginManager pluginManager
           
protected  LinearLayout root
           
protected  ProgressDialog spinnerDialog
           
protected  int splashscreen
           
static java.lang.String TAG
           
protected  WebViewClient webViewClient
           
 
Constructor Summary
DroidGap()
           
 
Method Summary
 void addService(java.lang.String serviceType, java.lang.String className)
          Add a class that implements a service.
 void addWhiteListEntry(java.lang.String origin, boolean subdomains)
          Add entry to approved list of URLs (whitelist)
 void cancelLoadUrl()
          Cancel loadUrl before it has been loaded.
 void clearCache()
          Clear the resource cache.
 void clearHistory()
          Clear web history in this web view.
 void displayError(java.lang.String title, java.lang.String message, java.lang.String button, boolean exit)
          Display an error dialog and optionally exit application.
 void endActivity()
          End this activity by simulating backbutton keypress
 boolean getBooleanProperty(java.lang.String name, boolean defaultValue)
          Get boolean property for activity.
 double getDoubleProperty(java.lang.String name, double defaultValue)
          Get double property for activity.
 int getIntegerProperty(java.lang.String name, int defaultValue)
          Get int property for activity.
 java.lang.String getStringProperty(java.lang.String name, java.lang.String defaultValue)
          Get string property for activity.
 void init()
          Create and initialize web container.
 void loadUrl(java.lang.String url)
          Load the url into the webview.
 void loadUrl(java.lang.String url, int time)
          Load the url into the webview after waiting for period of time.
protected  void onActivityResult(int requestCode, int resultCode, Intent intent)
           
 void onConfigurationChanged(Configuration newConfig)
           
 void onCreate(Bundle savedInstanceState)
          Called when the activity is first created.
 void onDestroy()
           
 boolean onKeyDown(int keyCode, KeyEvent event)
          Called when a key is pressed.
protected  void onNewIntent(Intent intent)
           
protected  void onPause()
           
 void onReceivedError(int errorCode, java.lang.String description, java.lang.String failingUrl)
          Report an error to the host application.
protected  void onResume()
           
 void sendJavascript(java.lang.String statement)
          Send JavaScript statement back to JavaScript.
 void setActivityResultCallback(com.phonegap.api.IPlugin plugin)
          Set the plugin to be called when a sub-activity exits.
 void setBooleanProperty(java.lang.String name, boolean value)
          Set boolean property on activity.
 void setDoubleProperty(java.lang.String name, double value)
          Set double property on activity.
 void setIntegerProperty(java.lang.String name, int value)
          Set int property on activity.
 void setStringProperty(java.lang.String name, java.lang.String value)
          Set string property on activity.
protected  void setWebViewClient(WebView appView, WebViewClient client)
          Set the WebViewClient.
 void showWebPage(java.lang.String url, boolean usePhoneGap, boolean clearPrev, java.util.HashMap<java.lang.String,java.lang.Object> params)
          Display a new browser with the specified URL.
 void spinnerStart(java.lang.String title, java.lang.String message)
          Show the spinner.
 void spinnerStop()
          Stop spinner.
 void startActivityForResult(Intent intent, int requestCode)
          Any calls to Activity.startActivityForResult must use method below, so the result can be routed to them correctly.
 void startActivityForResult(com.phonegap.api.IPlugin command, Intent intent, int requestCode)
          Launch an activity for which you would like a result when it finished.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TAG

public static java.lang.String TAG

appView

protected WebView appView

webViewClient

protected WebViewClient webViewClient

root

protected LinearLayout root

bound

public boolean bound

callbackServer

public CallbackServer callbackServer

pluginManager

protected com.phonegap.api.PluginManager pluginManager

cancelLoadUrl

protected boolean cancelLoadUrl

clearHistory

protected boolean clearHistory

spinnerDialog

protected ProgressDialog spinnerDialog

activityResultCallback

protected com.phonegap.api.IPlugin activityResultCallback

activityResultKeepRunning

protected boolean activityResultKeepRunning

loadInWebView

protected boolean loadInWebView

splashscreen

protected int splashscreen

loadUrlTimeoutValue

protected int loadUrlTimeoutValue

keepRunning

protected boolean keepRunning
Constructor Detail

DroidGap

public DroidGap()
Method Detail

onCreate

public void onCreate(Bundle savedInstanceState)
Called when the activity is first created.

Parameters:
savedInstanceState -

init

public void init()
Create and initialize web container.


setWebViewClient

protected void setWebViewClient(WebView appView,
                                WebViewClient client)
Set the WebViewClient.

Parameters:
appView -
client -

loadUrl

public void loadUrl(java.lang.String url)
Load the url into the webview.

Specified by:
loadUrl in class com.phonegap.api.PhonegapActivity
Parameters:
url -

loadUrl

public void loadUrl(java.lang.String url,
                    int time)
Load the url into the webview after waiting for period of time. This is used to display the splashscreen for certain amount of time.

Parameters:
url -
time - The number of ms to wait before loading webview

cancelLoadUrl

public void cancelLoadUrl()
Cancel loadUrl before it has been loaded.


clearCache

public void clearCache()
Clear the resource cache.


clearHistory

public void clearHistory()
Clear web history in this web view.


onConfigurationChanged

public void onConfigurationChanged(Configuration newConfig)

getBooleanProperty

public boolean getBooleanProperty(java.lang.String name,
                                  boolean defaultValue)
Get boolean property for activity.

Parameters:
name -
defaultValue -
Returns:

getIntegerProperty

public int getIntegerProperty(java.lang.String name,
                              int defaultValue)
Get int property for activity.

Parameters:
name -
defaultValue -
Returns:

getStringProperty

public java.lang.String getStringProperty(java.lang.String name,
                                          java.lang.String defaultValue)
Get string property for activity.

Parameters:
name -
defaultValue -
Returns:

getDoubleProperty

public double getDoubleProperty(java.lang.String name,
                                double defaultValue)
Get double property for activity.

Parameters:
name -
defaultValue -
Returns:

setBooleanProperty

public void setBooleanProperty(java.lang.String name,
                               boolean value)
Set boolean property on activity.

Parameters:
name -
value -

setIntegerProperty

public void setIntegerProperty(java.lang.String name,
                               int value)
Set int property on activity.

Parameters:
name -
value -

setStringProperty

public void setStringProperty(java.lang.String name,
                              java.lang.String value)
Set string property on activity.

Parameters:
name -
value -

setDoubleProperty

public void setDoubleProperty(java.lang.String name,
                              double value)
Set double property on activity.

Parameters:
name -
value -

onPause

protected void onPause()

onNewIntent

protected void onNewIntent(Intent intent)

onResume

protected void onResume()

onDestroy

public void onDestroy()

addService

public void addService(java.lang.String serviceType,
                       java.lang.String className)
Add a class that implements a service.

Specified by:
addService in class com.phonegap.api.PhonegapActivity
Parameters:
serviceType -
className -

sendJavascript

public void sendJavascript(java.lang.String statement)
Send JavaScript statement back to JavaScript. (This is a convenience method)

Specified by:
sendJavascript in class com.phonegap.api.PhonegapActivity
Parameters:
message -

showWebPage

public void showWebPage(java.lang.String url,
                        boolean usePhoneGap,
                        boolean clearPrev,
                        java.util.HashMap<java.lang.String,java.lang.Object> params)
                 throws android.content.ActivityNotFoundException
Display a new browser with the specified URL. NOTE: If usePhoneGap is set, only trusted PhoneGap URLs should be loaded, since any PhoneGap API can be called by the loaded HTML page.

Parameters:
url - The url to load.
usePhoneGap - Load url in PhoneGap webview.
clearPrev - Clear the activity stack, so new app becomes top of stack
params - DroidGap parameters for new app
Throws:
android.content.ActivityNotFoundException

spinnerStart

public void spinnerStart(java.lang.String title,
                         java.lang.String message)
Show the spinner. Must be called from the UI thread.

Parameters:
title - Title of the dialog
message - The message of the dialog

spinnerStop

public void spinnerStop()
Stop spinner.


endActivity

public void endActivity()
End this activity by simulating backbutton keypress


onKeyDown

public boolean onKeyDown(int keyCode,
                         KeyEvent event)
Called when a key is pressed.

Parameters:
keyCode -
event -

startActivityForResult

public void startActivityForResult(Intent intent,
                                   int requestCode)
                            throws java.lang.RuntimeException
Any calls to Activity.startActivityForResult must use method below, so the result can be routed to them correctly. This is done to eliminate the need to modify DroidGap.java to receive activity results.

Parameters:
intent - The intent to start
requestCode - Identifies who to send the result to
Throws:
java.lang.RuntimeException

startActivityForResult

public void startActivityForResult(com.phonegap.api.IPlugin command,
                                   Intent intent,
                                   int requestCode)
Launch an activity for which you would like a result when it finished. When this activity exits, your onActivityResult() method will be called.

Specified by:
startActivityForResult in class com.phonegap.api.PhonegapActivity
Parameters:
command - The command object
intent - The intent to start
requestCode - The request code that is passed to callback to identify the activity

onActivityResult

protected void onActivityResult(int requestCode,
                                int resultCode,
                                Intent intent)

setActivityResultCallback

public void setActivityResultCallback(com.phonegap.api.IPlugin plugin)
Description copied from class: com.phonegap.api.PhonegapActivity
Set the plugin to be called when a sub-activity exits.

Specified by:
setActivityResultCallback in class com.phonegap.api.PhonegapActivity
Parameters:
plugin - The plugin on which onActivityResult is to be called

onReceivedError

public void onReceivedError(int errorCode,
                            java.lang.String description,
                            java.lang.String failingUrl)
Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable). The errorCode parameter corresponds to one of the ERROR_* constants.

Parameters:
errorCode - The error code corresponding to an ERROR_* value.
description - A String describing the error.
failingUrl - The url that failed to load.

displayError

public void displayError(java.lang.String title,
                         java.lang.String message,
                         java.lang.String button,
                         boolean exit)
Display an error dialog and optionally exit application.

Parameters:
title -
message -
button -
exit -

addWhiteListEntry

public void addWhiteListEntry(java.lang.String origin,
                              boolean subdomains)
Add entry to approved list of URLs (whitelist)

Parameters:
origin - URL regular expression to allow
subdomains - T=include all subdomains under origin