List of usage examples for org.apache.cordova.api PluginResult setKeepCallback
public void setKeepCallback(boolean b)
From source file:com.android.adcnx.adlib.plugin.AdConnectLibrary.java
License:Open Source License
private PluginResult createAdBlock(JSONObject params, final String callbackID) { final String action = "create"; if (_lib != null) { return createResultWithJSONMessage(Status.ERROR, "There is already an instance of the library" + "currently running."); }/*from w w w . j a va2 s . c om*/ if (params == null) { return createResultWithJSONMessage(Status.ERROR, "No params passed for action " + action); } //_createCallbackID = callbackID; log("Creating a new AdBlock"); final String publisherID = params.optString("id"); if (publisherID.equalsIgnoreCase("")) { return createResultWithJSONMessage(Status.ERROR, "Missing publisher id"); } log("have publisher id."); JSONObject size = params.optJSONObject("size"); if (size == null) { return createResultWithJSONMessage(Status.ERROR, "Missing AdSize"); } final int width = size.optInt("width"); final int height = size.optInt("height"); if (width < 1 || height < 1) { return createResultWithJSONMessage(Status.ERROR, "AdSize is too small"); } final JSONObject layout = params.optJSONObject("layout"); log("have AdSize"); Handler h = new Handler(ctx.getContext().getMainLooper()); final AdConnectLibrary self = this; h.post(new Runnable() { public void run() { _lib = new AdBlock(ctx.getContext(), new AdSize(width, height), publisherID); _lib.setAdListener(self); LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); if (layout != null) { log("setting the layout"); String gravity = layout.optString("gravity"); if (!gravity.equalsIgnoreCase("")) { log("Have gravity: " + gravity); layoutParams.gravity = getGravity(gravity); } } log("have a new lib"); ((LinearLayout) webView.getParent()).addView(_lib, layoutParams); log("successfully added adblock to webview"); updateAdBlockCreation(callbackID); } }); PluginResult result = createResultWithJSONMessage(Status.NO_RESULT, "Awaiting AdBlockCreation"); result.setKeepCallback(true); return result; }
From source file:com.android.adcnx.adlib.plugin.AdConnectLibrary.java
License:Open Source License
private void updateAdBlockCreation(String callbackID) { PluginResult result = createResultWithJSONMessage(Status.OK, "Successfully created AdBlock"); result.setKeepCallback(false); this.success(result, callbackID); }
From source file:com.android.adcnx.adlib.plugin.AdConnectLibrary.java
License:Open Source License
private PluginResult hide(final String callbackID) { log("Hide function called."); if (_lib == null) { return createResultWithJSONMessage(Status.ERROR, "AdConnect Library not created."); }/*from w w w . ja v a2s . c om*/ Handler h = new Handler(ctx.getContext().getMainLooper()); h.post(new Runnable() { public void run() { _lib.stopLoading(); _lib.setVisibility(View.GONE); updateHideStatus(callbackID); } }); PluginResult result = createResultWithJSONMessage(Status.NO_RESULT, "Hiding..."); result.setKeepCallback(true); return result; }
From source file:com.android.adcnx.adlib.plugin.AdConnectLibrary.java
License:Open Source License
private void updateHideStatus(String callbackID) { PluginResult result = createResultWithJSONMessage(Status.OK, "Successfully hidden view."); result.setKeepCallback(false); this.success(result, callbackID); }
From source file:com.android.adcnx.adlib.plugin.AdConnectLibrary.java
License:Open Source License
private PluginResult show(final String callbackID) { log("Show function called."); if (_lib == null) { return createResultWithJSONMessage(Status.ERROR, "AdConnect Library not created."); }/*from w w w .j a v a 2 s .c o m*/ Handler h = new Handler(ctx.getContext().getMainLooper()); h.post(new Runnable() { public void run() { _lib.setVisibility(View.VISIBLE); if (_currAdRequest != null) { _lib.loadAd(_currAdRequest); } updateShowStatus(callbackID); } }); PluginResult result = createResultWithJSONMessage(Status.NO_RESULT, "Showing..."); result.setKeepCallback(true); return result; }
From source file:com.android.adcnx.adlib.plugin.AdConnectLibrary.java
License:Open Source License
private void updateShowStatus(String callbackID) { PluginResult result = createResultWithJSONMessage(Status.OK, "Shown"); result.setKeepCallback(false); this.success(result, callbackID); }
From source file:com.android.adcnx.adlib.plugin.AdConnectLibrary.java
License:Open Source License
private synchronized PluginResult addListener(JSONObject params, String callbackID) { log("Adding listener"); if (_lib == null) { return createResultWithJSONMessage(Status.ERROR, "Library not created."); }//from ww w . j ava 2 s .c om log("Lib is not null."); if (params == null) { return createResultWithJSONMessage(Status.ERROR, "No params have been passed"); } log("params are not null"); String listener = params.optString("listener"); log("listener is:" + listener); if (listener.equalsIgnoreCase("")) { return createResultWithJSONMessage(Status.ERROR, "No listener has been passed."); } String oldCallbackID = _listeners.remove(listener); log("current callbackID for listener: " + oldCallbackID); if (oldCallbackID == null) { _listeners.put(listener, callbackID); PluginResult result = createResultWithJSONMessage(Status.NO_RESULT, listener + " added successfully."); result.setKeepCallback(true); return result; } else { if (params.optBoolean("doForce")) { _listeners.put(listener, callbackID); PluginResult result = createResultWithJSONMessage(Status.NO_RESULT, listener + "added successfully."); result.setKeepCallback(true); return result; } return createResultWithJSONMessage(Status.ERROR, listener + " previously added. Cannot add again unless sent the doForce param"); } }
From source file:com.android.adcnx.adlib.plugin.AdConnectLibrary.java
License:Open Source License
public void OnFailedToReceiveAd(Ad ad, ErrorCode code) { String callbackID = _listeners.get("failedToReceiveAdListener"); if (callbackID != null) { JSONObject message = new JSONObject(); try {//from ww w . j ava 2s . co m message.put("msg", "Failed to receive ad: " + ad.toString()); message.put("error", code.name()); this.success(message, callbackID); } catch (JSONException e) { //e.printStackTrace(); PluginResult result = new PluginResult(Status.OK, message); result.setKeepCallback(true); this.success("Failed to receive ad: " + ad.toString() + "\n" + "error: " + code.name(), callbackID); } } }
From source file:com.android.adcnx.adlib.plugin.AdConnectLibrary.java
License:Open Source License
public void defaultListenerUpdate(String msg, String callbackID) { if (callbackID != null) { PluginResult result = createResultWithJSONMessage(Status.OK, msg); result.setKeepCallback(true); this.success(result, callbackID); }// w w w . j av a 2s .co m }
From source file:com.app.plugins.childBrowser.ChildBrowser.java
License:BSD License
/** * 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. *//*from ww w . ja v a 2 s . c o m*/ public PluginResult execute(String action, JSONArray args, String callbackId) { PluginResult.Status status = PluginResult.Status.OK; 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"); } result = this.showWebPage(args.getString(0), args.optJSONObject(1)); if (result.length() > 0) { status = PluginResult.Status.ERROR; return new PluginResult(status, result); } else { PluginResult pluginResult = new PluginResult(status, result); pluginResult.setKeepCallback(true); return pluginResult; } } else if (action.equals("close")) { closeDialog(); JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); this.onClose(); PluginResult pluginResult = new PluginResult(status, obj); pluginResult.setKeepCallback(false); return pluginResult; } else if (action.equals("openExternal")) { result = this.openExternal(args.getString(0), args.optBoolean(1)); if (result.length() > 0) { status = PluginResult.Status.ERROR; } } else { status = PluginResult.Status.INVALID_ACTION; } return new PluginResult(status, result); } catch (JSONException e) { return new PluginResult(PluginResult.Status.JSON_EXCEPTION); } }