Update to work with changes in DroidGap initialization parameters.

This commit is contained in:
Bryce Curtis
2010-11-13 00:24:15 -06:00
parent 0aaab4a323
commit b62fecf5df
2 changed files with 76 additions and 55 deletions

View File

@@ -1,7 +1,7 @@
/*
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
*
*
* Copyright (c) 2005-2010, Nitobi Software Inc.
* Copyright (c) 2010, IBM Corporation
*/
@@ -18,75 +18,84 @@ import com.phonegap.api.PluginResult;
public class ChildBrowser extends Plugin {
/**
* Executes the request and returns PluginResult.
*
* @param action The action to execute.
* @param args JSONArry of arguments for the plugin.
* @param callbackId The callback id used when calling back into JavaScript.
* @return A PluginResult object with a status and message.
*/
public PluginResult execute(String action, JSONArray args, String callbackId) {
PluginResult.Status status = PluginResult.Status.OK;
String result = "";
try {
if (action.equals("showWebPage")) {
result = this.showWebPage(args.getString(0), args.optBoolean(1));
if (result.length() > 0) {
status = PluginResult.Status.ERROR;
}
}
return new PluginResult(status, result);
} catch (JSONException e) {
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
}
}
/**
* Executes the request and returns PluginResult.
*
* @param action The action to execute.
* @param args JSONArry of arguments for the plugin.
* @param callbackId The callback id used when calling back into JavaScript.
* @return A PluginResult object with a status and message.
*/
public PluginResult execute(String action, JSONArray args, String callbackId) {
PluginResult.Status status = PluginResult.Status.OK;
String result = "";
try {
if (action.equals("showWebPage")) {
result = this.showWebPage(args.getString(0), args.optBoolean(1));
if (result.length() > 0) {
status = PluginResult.Status.ERROR;
}
}
return new PluginResult(status, result);
} catch (JSONException e) {
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
}
}
/**
* Identifies if action to be executed returns a value and should be run synchronously.
*
* @param action The action to execute
* @return T=returns value
*/
public boolean isSynch(String action) {
return false;
}
/**
* Identifies if action to be executed returns a value and should be run synchronously.
*
* @param action The action to execute
* @return T=returns value
*/
public boolean isSynch(String action) {
return false;
}
/**
* Called by AccelBroker when listener is to be shut down.
* Stop listener.
*/
public void onDestroy() {
public void onDestroy() {
}
//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------
/**
* Display a new browser with the specified URL.
*
* @param url The url to load.
* @param usePhoneGap Load url in PhoneGap webview
* @return "" if ok, or error message.
*
* @param url The url to load.
* @param usePhoneGap Load url in PhoneGap webview
* @return "" if ok, or error message.
*/
public String showWebPage(String url, boolean usePhoneGap) {
try {
Intent intent = null;
if (usePhoneGap) {
intent = new Intent().setClass(this.ctx, com.phonegap.DroidGap.class);
}
else {
intent = new Intent(Intent.ACTION_VIEW);
}
intent.setData(Uri.parse(url));
this.ctx.startActivity(intent);
return "";
try {
Intent intent = null;
if (usePhoneGap) {
intent = new Intent().setClass(this.ctx, com.phonegap.DroidGap.class);
intent.setData(Uri.parse(url)); // This line will be removed in future.
intent.putExtra("url", url);
// Timeout parameter: 60 sec max - May be less if http device timeout is less.
intent.putExtra("loadUrlTimeoutValue", 60000);
// These parameters can be configured if you want to show the loading dialog
intent.putExtra("loadingDialog", "Wait,Loading web page..."); // show loading dialog
intent.putExtra("hideLoadingDialogOnPageLoad", true); // hide it once page has completely loaded
}
else {
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
}
this.ctx.startActivity(intent);
return "";
} catch (android.content.ActivityNotFoundException e) {
System.out.println("ChildBrowser: Error loading url "+url+":"+ e.toString());
return e.toString();
System.out.println("ChildBrowser: Error loading url "+url+":"+ e.toString());
return e.toString();
}
}
}

View File

@@ -19,6 +19,14 @@ Using this plugin requires [Android PhoneGap](http://github.com/phonegap/phonega
2. Create a directory within your project called "src/com/phonegap/plugins/childBrowser" and move ChildBrowser.java into it.
3. Add the following activity to your AndroidManifest.xml file. It should be added inside the <application> tag.
&lt;activity android:name="com.phonegap.DroidGap" android:label="@string/app_name"&gt;<br/>
&lt;intent-filter&gt;<br/>
&lt;/intent-filter&gt;<br/>
&lt;/activity&gt;
## Using the plugin ##
The plugin creates the object `window.plugins.childBrowser`. To use, call one of the following, available methods:
@@ -43,6 +51,10 @@ Sample use:
* Initial release
### Nov 12, 2010 ###
* Changed how URL is passed when usePhoneGap=true. Instead of using Data, it is now passed as Extra. This will work with latest edge version with the same date.
* Added "Loading" dialog that is shown when usePhoneGap=true.
## BUGS AND CONTRIBUTIONS ##