List of usage examples for org.apache.cordova PluginResult PluginResult
public PluginResult(Status status, List<PluginResult> multipartMessages)
From source file:com.movistar.tvsindesco.cordova.plugin.VideoPlugin.java
@Override public void onPlayerStateChanged(String state) { PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, state); pluginResult.setKeepCallback(true);//from ww w .j a va 2 s. co m onStateChangedCallbackContext.sendPluginResult(pluginResult); }
From source file:com.movistar.tvsindesco.cordova.plugin.VideoPlugin.java
@Override public void onPlayerError() { PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, "Error"); pluginResult.setKeepCallback(true);// www . j a v a2 s . c om onErrorCallbackContext.sendPluginResult(pluginResult); }
From source file:com.movistar.tvsindesco.cordova.plugin.VideoPlugin.java
@Override public void onTrackChanged() { PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, "Track Changed"); pluginResult.setKeepCallback(true);//from w w w . j av a 2s .com onTrackChangedCallbackContext.sendPluginResult(pluginResult); }
From source file:com.mrboss.tianbosdk.tianbosdk.java
License:Apache License
public void TianBoSdkOpenMoneyBox(CallbackContext callbackContext) { if (MoneyBox.open() == TelpoErrorCode.ERR_LOW_POWER) { //the battery is low,Please connect the charger callbackContext.error("??"); return;/*from w ww. ja va 2s . c om*/ } try { Thread.sleep(500); MoneyBox.close(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, "OK")); callbackContext.success(); } catch (InterruptedException e) { e.printStackTrace(); callbackContext.error(e.toString()); } }
From source file:com.msopentech.o365.outlookServices.OutlookServicesMethodsImpl.java
License:Open Source License
/** * Adds default callback that send future's result back to plugin * * @param future Future to add callback to * @param context Plugin context used to send future result back to plugin * @param resolver Dependency resolver, that used to serialize future results *//*ww w. ja v a 2 s.com*/ static <T> void addCordovaCallback(final ListenableFuture<T> future, final CallbackContext context, final DependencyResolver resolver) { Futures.addCallback(future, new FutureCallback<T>() { @Override public void onSuccess(T t) { if (t != null) { String result = resolver.getJsonSerializer().serialize(t); context.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } else { context.sendPluginResult(new PluginResult(PluginResult.Status.OK)); } } @Override public void onFailure(Throwable throwable) { context.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, throwable.getMessage())); } }); }
From source file:com.msopentech.o365.outlookServices.OutlookServicesProxy.java
License:Open Source License
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { Method handler;// ww w . j a va 2 s .com try { // Get appropriate method for handling provided action handler = OutlookServicesMethodsImpl.class.getDeclaredMethod(action, CallbackContext.class, OutlookClient.class, DefaultDependencyResolver.class, ODataMethodArgs.class); } catch (NoSuchMethodException e) { // If no appropriate method found, send return false to indicate this return false; } // parse arguments passed from JS layer to ArrayList objects ODataMethodArgs methodArgs = ODataMethodArgs.parseInvocationArgs(args); //Get common parameters necessary for creating OutlookClient object //and create a new one or use an existing if token and serviceRoot are unchanged from previous call final String token = methodArgs.getToken(); final String serviceRoot = methodArgs.getServiceRoot(); OutlookClient client = getClient(serviceRoot, token); try { // If appropriate method found, invoke it with arguments parsed from action args handler.invoke(null, callbackContext, client, this.resolver, methodArgs); } catch (InvocationTargetException e) { // Catch inner method's exception and send back an error result String message = "Method " + action + " failed with error: " + e.getMessage(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, message)); } catch (IllegalAccessException e) { // Catch method invocation exception and send back an error result String message = "Failed to call native method " + action + ": " + e.getMessage(); callbackContext .sendPluginResult(new PluginResult(PluginResult.Status.ILLEGAL_ACCESS_EXCEPTION, message)); } // Return true here to indicate that action is handled by plugin return true; }
From source file:com.neka.cordova.inappbrowser.InAppBrowser.java
License:Apache 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 w w w . jav a2 s. c om*/ public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException { if (action.equals("open")) { this.callbackContext = callbackContext; final String url = args.getString(0); String t = args.optString(1); if (t == null || t.equals("") || t.equals(NULL)) { t = SELF; } final String target = t; final HashMap<String, Boolean> features = parseFeature(args.optString(2)); Log.d(LOG_TAG, "target = " + target); this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { String result = ""; // SELF if (SELF.equals(target)) { Log.d(LOG_TAG, "in self"); // load in webview if (url.startsWith("file://") || url.startsWith("javascript:") || Config.isUrlWhiteListed(url)) { Log.d(LOG_TAG, "loading in webview"); webView.loadUrl(url); } //Load the dialer else if (url.startsWith(WebView.SCHEME_TEL)) { try { Log.d(LOG_TAG, "loading in dialer"); Intent intent = new Intent(Intent.ACTION_DIAL); intent.setData(Uri.parse(url)); cordova.getActivity().startActivity(intent); } catch (android.content.ActivityNotFoundException e) { LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString()); } } // load in InAppBrowser else { Log.d(LOG_TAG, "loading in InAppBrowser"); result = showWebPage(url, features); } } // SYSTEM else if (SYSTEM.equals(target)) { Log.d(LOG_TAG, "in system"); result = openExternal(url); } // BLANK - or anything else else { Log.d(LOG_TAG, "in blank"); result = showWebPage(url, features); } PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, result); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); } }); } else if (action.equals("close")) { closeDialog(); } else if (action.equals("injectScriptCode")) { String jsWrapper = null; if (args.getBoolean(1)) { jsWrapper = String.format("prompt(JSON.stringify([eval(%%s)]), 'gap-iab://%s')", callbackContext.getCallbackId()); } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("injectScriptFile")) { String jsWrapper; if (args.getBoolean(1)) { jsWrapper = String.format( "(function(d) { var c = d.createElement('script'); c.src = %%s; c.onload = function() { prompt('', 'gap-iab://%s'); }; d.body.appendChild(c); })(document)", callbackContext.getCallbackId()); } else { jsWrapper = "(function(d) { var c = d.createElement('script'); c.src = %s; d.body.appendChild(c); })(document)"; } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("injectStyleCode")) { String jsWrapper; if (args.getBoolean(1)) { jsWrapper = String.format( "(function(d) { var c = d.createElement('style'); c.innerHTML = %%s; d.body.appendChild(c); prompt('', 'gap-iab://%s');})(document)", callbackContext.getCallbackId()); } else { jsWrapper = "(function(d) { var c = d.createElement('style'); c.innerHTML = %s; d.body.appendChild(c); })(document)"; } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("injectStyleFile")) { String jsWrapper; if (args.getBoolean(1)) { jsWrapper = String.format( "(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %%s; d.head.appendChild(c); prompt('', 'gap-iab://%s');})(document)", callbackContext.getCallbackId()); } else { jsWrapper = "(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %s; d.head.appendChild(c); })(document)"; } injectDeferredObject(args.getString(0), jsWrapper); } else if (action.equals("show")) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { dialog.show(); } }); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK); pluginResult.setKeepCallback(true); this.callbackContext.sendPluginResult(pluginResult); } else { return false; } return true; }
From source file:com.netcompss.ffmpeg4android_client.BaseVideo.java
public boolean execute(String actiosaveImagen, JSONArray args, CallbackContext callbackContext) throws JSONException { this.callbackContext = callbackContext; context = this.cordova.getActivity().getApplicationContext(); contexts = this.cordova.getActivity().getApplicationContext(); _prefs = new Prefs(); _prefs.setContext(this.cordova.getActivity().getApplicationContext()); jsondata = args.toString();/* ww w . j av a2 s . c o m*/ Log.e("json", args.toString() + " ddddd " + args.length()); cd = new ConnectionDetector(context); isInternetPresent = cd.isConnectingToInternet(); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); // pd = new // ProgressDialog(this.cordova.getActivity().getApplicationContext()); // pd.setCancelable(true); // pd.setMessage("Please Wait..."); if (isInternetPresent) { if (args != null && args.length() > 0) { JSONArray arry = new JSONArray(jsondata); JSONObject obj = arry.getJSONObject(2); sgn = obj.getString("video"); if (obj.has("video_thumbnail")) { String image = obj.getString("video_thumbnail"); if (image != null) { Log.d("image", image); if (image.contains("content") || image.contains("file")) { Log.d("content", "content"); String getString = getFileNameByUri(context, Uri.parse(image)); String thumb = reporteds(getString); video(thumb, true); } else { Log.d("image", "image"); String thumb = reporteds(image); video(thumb, true); } } else { Log.d("one", "videopath1"); Log.d("two-2", video_thumbpath.getAbsolutePath()); String thumb = reporteds(video_thumbpath.getAbsolutePath()); if (thumb != null) { Log.d("thumb", thumb); video(thumb, true); Log.d("image path32", video_thumbpath.getAbsolutePath()); } } } else { Log.d("one", "videopath2"); Log.d("two-2", video_thumbpath.getAbsolutePath()); String thumb = reporteds(video_thumbpath.getAbsolutePath()); if (thumb != null) { Log.d("thumb", thumb); video(thumb, true); Log.d("image path32", video_thumbpath.getAbsolutePath()); } } } else { PluginResult progressResult = new PluginResult(PluginResult.Status.ERROR, "parameter required or incorrect"); progressResult.setKeepCallback(true); callbackContext.sendPluginResult(progressResult); } } else { toastsettext("No Internet Connection"); } return true;// super.execute(action, args, callbackContext); }
From source file:com.netcompss.ffmpeg4android_client.BaseVideo.java
private void video_posted() { LicenseCheckJNI lic = new LicenseCheckJNI(); int licenseCheckRC = lic.licenseCheck(Prefs.getWorkingFolderForNative(), context); String licenseText = ""; if (licenseCheckRC == 4) { licenseText = " Personal"; } else if (licenseCheckRC == 1) { licenseText = " OEM"; } else if (licenseCheckRC == 0 || licenseCheckRC == 2) { licenseText = " Trial"; } else if (licenseCheckRC == -1) { licenseText = " Trial Expired"; } else if (licenseCheckRC == -3) { licenseText = " Trial (not validated) "; Log.w(Prefs.TAG, "License file not created, possible first time"); } else {//from www .j a v a 2 s.c o m licenseText = "Not Valid"; } Log.d("license", licenseText); File files = new File(sgn); // JSONObject obj = args.getJSONObject(2).getJSONObject("video"); String[] temp = null;// args.getString(0).split("/"); temp = getVideoPath(files.getName()); if (temp[0].equalsIgnoreCase("success")) { File file = new File(temp[1]); String hrSize = ""; long size = file.length(); double m = size / 1048576; if (m < 75) { Intent intent = new Intent(context, NewAct.class); Log.d(Prefs.TAG, "Starting demo act"); int currentapiVersion = android.os.Build.VERSION.SDK_INT; if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) { Constant.command = temp[1]; Constant.commandStr = "ffmpeg -y -i /sdcard/videokit/in.mp4 -strict experimental -s 160x120 -r 25 -aspect 4:3 -vcodec mpeg4 -b 97152 -ab 48000 -ac 2 -ar 22050 /sdcard/videokit/final.mp4"; } else { Constant.command = temp[1]; Constant.commandStr = "ffmpeg -y -i " + temp[1] + " -strict experimental -s 160x120 -r 25 -aspect 4:3 -vcodec mpeg4 -b 97152 -ab 48000 -ac 2 -ar 22050 /sdcard/videokit/final.mp4"; } Log.d("command", Constant.commandStr); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } else { JSONObject object = new JSONObject(); try { object.put("statues", "Error"); object.put("message", "file size should not greater than 75MB...."); } catch (JSONException e) { e.printStackTrace(); } PluginResult progressResult = new PluginResult(PluginResult.Status.ERROR, object); progressResult.setKeepCallback(true); callbackContext.sendPluginResult(progressResult); } } else { PluginResult progressResult = new PluginResult(PluginResult.Status.ERROR, temp[0]); progressResult.setKeepCallback(true); callbackContext.sendPluginResult(progressResult); } }
From source file:com.netcompss.ffmpeg4android_client.BaseWizard.java
public void handleServiceFinished() { Log.i(Prefs.TAG, "FFMPEG finished."); //Toast.makeText(this, getString(R.string.notif_message_ok), Toast.LENGTH_LONG).show(); //remove the sticky notification // fix 4.4.2 bug, should not effect other versions. releaseService();// w ww . j a va 2 s. c om stopService(); appView.sendPluginResult(new PluginResult(PluginResult.Status.OK, this.getResults()), this.getCallbackId()); }