Skip to content

Commit

Permalink
Merge branch 'master' of github.com:callback/callback-android
Browse files Browse the repository at this point in the history
  • Loading branch information
brycecurtis committed Oct 21, 2011
2 parents 64b770b + cdeddf1 commit 191e1bf
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 145 deletions.
11 changes: 4 additions & 7 deletions framework/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,18 @@ App.prototype.clearCache = function() {
};

/**
* Load the url into the webview.
* Load the url into the webview or into new browser instance.
*
* @param url The URL to load
* @param props Properties that can be passed in to the activity:
* wait: int => wait msec before loading URL
* loadingDialog: "Title,Message" => display a native loading dialog
* hideLoadingDialogOnPage: boolean => hide loadingDialog when page loaded instead of when deviceready event occurs.
* loadInWebView: boolean => cause all links on web page to be loaded into existing web view, instead of being loaded into new browser.
* loadUrlTimeoutValue: int => time in msec to wait before triggering a timeout error
* errorUrl: URL => URL to load if there's an error loading specified URL with loadUrl(). Should be a local URL such as file:///android_asset/www/error.html");
* keepRunning: boolean => enable app to keep running in background
* clearHistory: boolean => clear webview history (default=false)
* openExternal: boolean => open in a new browser (default=false)
*
* Example:
* App app = new App();
* app.loadUrl("http://server/myapp/index.html", {wait:2000, loadingDialog:"Wait,Loading App", loadUrlTimeoutValue: 60000});
* navigator.app.loadUrl("http://server/myapp/index.html", {wait:2000, loadingDialog:"Wait,Loading App", loadUrlTimeoutValue: 60000});
*/
App.prototype.loadUrl = function(url, props) {
PhoneGap.exec(null, null, "App", "loadUrl", [url, props]);
Expand Down
9 changes: 7 additions & 2 deletions framework/assets/js/phonegap.js.base
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ if (typeof PhoneGap === "undefined") {
* onDestroy Internal event fired when app is being destroyed (User should use window.onunload event, not this one).
*
* The only PhoneGap events that user code should register for are:
* onDeviceReady
* onResume
* deviceready PhoneGap native code is initialized and PhoneGap APIs can be called from JavaScript
* pause App has moved to background
* resume App has returned to foreground
*
* Listeners can be registered as:
* document.addEventListener("deviceready", myDeviceReadyListener, false);
* document.addEventListener("resume", myResumeListener, false);
* document.addEventListener("pause", myPauseListener, false);
*
* The DOM lifecycle events should be used for saving and restoring state
* window.onload
* window.onunload
*/

if (typeof(DeviceInfo) !== 'object') {
Expand Down
35 changes: 16 additions & 19 deletions framework/src/com/phonegap/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ public void clearCache() {
((DroidGap)this.ctx).clearCache();
}

/**
* Load the url into the webview.
*
* @param url
* @param props Properties that can be passed in to the DroidGap activity (i.e. loadingDialog, wait, ...)
* @throws JSONException
*/
/**
* Load the url into the webview.
*
* @param url
* @param props Properties that can be passed in to the DroidGap activity (i.e. loadingDialog, wait, ...)
* @throws JSONException
*/
public void loadUrl(String url, JSONObject props) throws JSONException {
System.out.println("App.loadUrl("+url+","+props+")");
int wait = 0;
boolean usePhoneGap = true;
boolean clearPrev = false;
boolean openExternal = false;
boolean clearHistory = false;

// If there are properties, then set them on the Activity
HashMap<String, Object> params = new HashMap<String, Object>();
Expand All @@ -100,11 +100,11 @@ public void loadUrl(String url, JSONObject props) throws JSONException {
if (key.equals("wait")) {
wait = props.getInt(key);
}
else if (key.equalsIgnoreCase("usephonegap")) {
usePhoneGap = props.getBoolean(key);
else if (key.equalsIgnoreCase("openexternal")) {
openExternal = props.getBoolean(key);
}
else if (key.equalsIgnoreCase("clearprev")) {
clearPrev = props.getBoolean(key);
else if (key.equalsIgnoreCase("clearhistory")) {
clearHistory = props.getBoolean(key);
}
else {
Object value = props.get(key);
Expand Down Expand Up @@ -135,7 +135,7 @@ else if (value.getClass().equals(Integer.class)) {
e.printStackTrace();
}
}
((DroidGap)this.ctx).showWebPage(url, usePhoneGap, clearPrev, params);
((DroidGap)this.ctx).showWebPage(url, openExternal, clearHistory, params);
}

/**
Expand All @@ -146,20 +146,18 @@ public void cancelLoadUrl() {
}

/**
* Clear web history in this web view.
* This does not have any effect since each page has its own activity.
* Clear page history for the app.
*/
public void clearHistory() {
((DroidGap)this.ctx).clearHistory();
// TODO: Kill previous activities?
}

/**
* Go to previous page displayed.
* This is the same as pressing the backbutton on Android device.
*/
public void backHistory() {
((DroidGap)this.ctx).endActivity();
((DroidGap)this.ctx).backHistory();
}

/**
Expand All @@ -186,7 +184,6 @@ public boolean isBackbuttonOverridden() {
* Exit the Android application.
*/
public void exitApp() {
((DroidGap)this.ctx).setResult(Activity.RESULT_OK);
((DroidGap)this.ctx).endActivity();
}

Expand Down
14 changes: 14 additions & 0 deletions framework/src/com/phonegap/CallbackServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ public CallbackServer() {
*/
public void init(String url) {
//System.out.println("CallbackServer.start("+url+")");
this.active = false;
this.empty = true;
this.port = 0;
this.javascript = new LinkedList<String>();

// Determine if XHR or polling is to be used
if ((url != null) && !url.startsWith("file://")) {
Expand All @@ -119,6 +123,16 @@ else if (android.net.Proxy.getDefaultHost() != null) {
}
}

/**
* Re-init when loading a new HTML page into webview.
*
* @param url The URL of the PhoneGap app being loaded
*/
public void reinit(String url) {
this.stopServer();
this.init(url);
}

/**
* Return if polling is being used instead of XHR.
*
Expand Down
Loading

0 comments on commit 191e1bf

Please sign in to comment.