Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Update Android/ChildBrowser to new Cordova API #923

Closed
wants to merge 1 commit into from

2 participants

@mpeterka

...ChildBrowser.java

updated to new Cordova API (CordovaPlugin)

@mpeterka mpeterka Update Android/ChildBrowser/2.0.0/src/com/phonegap/plugins/childBrows…
…er/ChildBrowser.java

updated to new Cordova API (CordovaPlugin)
6671b5f
@shazron
Owner

This repo has been deprecated and will not be actively maintained - no pull requests nor any other issues will be worked on. The previous source currently exists in the DEPRECATED branch, and may be removed at a future date.
Migration path, see: https://github.com/phonegap/phonegap-plugins/blob/master/README.md

@shazron shazron closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 4, 2012
  1. @mpeterka

    Update Android/ChildBrowser/2.0.0/src/com/phonegap/plugins/childBrows…

    mpeterka authored
    …er/ChildBrowser.java
    
    updated to new Cordova API (CordovaPlugin)
This page is out of date. Refresh to see the latest.
View
40 Android/ChildBrowser/2.0.0/src/com/phonegap/plugins/childBrowser/ChildBrowser.java
@@ -10,7 +10,8 @@
import java.io.IOException;
import java.io.InputStream;
-import org.apache.cordova.api.Plugin;
+import org.apache.cordova.api.CallbackContext;
+import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
@@ -43,18 +44,23 @@
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
-public class ChildBrowser extends Plugin {
+/**
+ * https://github.com/phonegap/phonegap-plugins/tree/master/Android/ChildBrowser/2.0.0
+ * (extends CordovaPlugin)
+ *
+ */
+public class ChildBrowser extends CordovaPlugin {
protected static final String LOG_TAG = "ChildBrowser";
private static int CLOSE_EVENT = 0;
private static int LOCATION_CHANGED_EVENT = 1;
- private String browserCallbackId = null;
-
private Dialog dialog;
private WebView webview;
private EditText edittext;
private boolean showLocationBar = true;
+
+ private CallbackContext context;
/**
* Executes the request and returns PluginResult.
@@ -64,28 +70,31 @@
* @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) {
+ @Override
+ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
PluginResult.Status status = PluginResult.Status.OK;
+ this.context = callbackContext;
String result = "";
try {
if (action.equals("showWebPage")) {
- this.browserCallbackId = callbackId;
// If the ChildBrowser is already open then throw an error
if (dialog != null && dialog.isShowing()) {
- return new PluginResult(PluginResult.Status.ERROR, "ChildBrowser is already open");
+ this.context.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "ChildBrowser is already open"));
+ return true;
}
result = this.showWebPage(args.getString(0), args.optJSONObject(1));
if (result.length() > 0) {
status = PluginResult.Status.ERROR;
- return new PluginResult(status, result);
+ this.context.sendPluginResult(new PluginResult(status, result));
} else {
PluginResult pluginResult = new PluginResult(status, result);
pluginResult.setKeepCallback(true);
- return pluginResult;
+ this.context.sendPluginResult(pluginResult);
+ return true;
}
}
else if (action.equals("close")) {
@@ -96,7 +105,8 @@ else if (action.equals("close")) {
PluginResult pluginResult = new PluginResult(status, obj);
pluginResult.setKeepCallback(false);
- return pluginResult;
+ this.context.sendPluginResult(pluginResult);
+ return true;
}
else if (action.equals("openExternal")) {
result = this.openExternal(args.getString(0), args.optBoolean(1));
@@ -107,9 +117,11 @@ else if (action.equals("openExternal")) {
else {
status = PluginResult.Status.INVALID_ACTION;
}
- return new PluginResult(status, result);
+ this.context.sendPluginResult(new PluginResult(status, result));
+ return true;
} catch (JSONException e) {
- return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
+ this.context.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
+ return true;
}
}
@@ -405,10 +417,10 @@ private Bitmap loadDrawable(String filename) throws java.io.IOException {
* @param obj a JSONObject contain event payload information
*/
private void sendUpdate(JSONObject obj, boolean keepCallback) {
- if (this.browserCallbackId != null) {
+ if (this.context != null) {
PluginResult result = new PluginResult(PluginResult.Status.OK, obj);
result.setKeepCallback(keepCallback);
- this.success(result, this.browserCallbackId);
+ this.context.sendPluginResult(result);
}
}
Something went wrong with that request. Please try again.