List of usage examples for org.apache.cordova PluginResult setKeepCallback
public void setKeepCallback(boolean b)
From source file:com.moodstocks.phonegap.plugin.MS4Plugin.java
License:Open Source License
public static void openFinished(Boolean bundleFlag) { PluginResult openResult = new PluginResult(PluginResult.Status.OK, bundleFlag); openResult.setKeepCallback(false); // final open callback -- doesn't need keeping openCallbackContext.sendPluginResult(openResult); }
From source file:com.movistar.tvsindesco.cordova.plugin.VideoPlugin.java
@Override public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException { if (action.equals("playIP")) { cordova.getActivity().runOnUiThread(new Runnable() { public void run() { currentPlay = PLAYING_LIVE; codecMpeg123 = true;/*from w ww .j ava 2 s . c om*/ String url = null; try { url = args.getString(0); } catch (JSONException e) { e.printStackTrace(); } urlPlaying = url; Log.i(LOGTAG, "url: " + url); player.init(url, MainActivity.getSurfaceView_live()); } }); return true; // } else if (action.equals("playRtsp")) { // cordova.getActivity().runOnUiThread(new Runnable() { // public void run() { // Log.i(LOGTAG, "playingrtsp: "); // currentPlay = PLAYING_RTSP; // codecMpeg123 = true; // String url = null; // try { // url = args.getString(0); // } catch (JSONException e) { // e.printStackTrace(); // } // urlPlaying = url; // if (player != null) { // if (player.getDvbSubsShown()) { // player.switchDvbSubs(false); // player.setSelectedTrack(DemoPlayer.TYPE_DVBSUBS, -1); // } // player.release(); // } // player = new DemoPlayer(new RtspRendererBuilder(context, userAgent, url)); // player.setSurface(surface_live); // // player.prepare(); // player.setPlayWhenReady(true); // // } // }); // // return true; } else if (action.equals("state")) { callbackContext.success(stateVideo); return true; } else if (action.equals("playVOD")) { cordova.getActivity().runOnUiThread(new Runnable() { public void run() { currentPlay = PLAYING_VOD; codecMpeg123 = false; String url = null; try { url = args.getString(0); } catch (JSONException e) { e.printStackTrace(); } urlPlaying = url; Log.i(LOGTAG, "url: " + url); if (player != null) { player.release(); } player.init(url, surfaceView_live); } }); return true; // } else if (action.equals("pauseVOD")) { // player.getPlayerControl().pause(); // // return true; // } else if (action.equals("ffRtsp")) { // player.rtspFastForward(Integer.parseInt(args.getString(0))); // // return true; // } else if (action.equals("rewindRtsp")) { // player.rtspRewind(Integer.parseInt(args.getString(0))); // // return true; // } else if (action.equals("resumeVOD")) { // player.getPlayerControl().start(); // // return true; // } else if (action.equals("playPositionVOD")) { // if (player.getPlaybackState() == player.STATE_READY || player.getPlaybackState() == player.STATE_BUFFERING) { // callbackContext.success(player.getPlayerControl().getCurrentPosition()); // } else { // callbackContext.success(0); // } // // return true; // } else if (action.equals("playTimeVOD")) { // if (player.getPlaybackState() == player.STATE_READY || player.getPlaybackState() == player.STATE_BUFFERING) { // callbackContext.success(player.getPlayerControl().getDuration()); // } else { // callbackContext.success(0); // } // // return true; // } else if (action.equals("playPositionAudio")) { // if (playerAudio != null) { // if (playerAudio.getPlaybackState() == playerAudio.STATE_READY) { // callbackContext.success(playerAudio.getPlayerControl().getCurrentPosition()); // } else { // callbackContext.success(0); // } // } else { // callbackContext.success(0); // } // return true; // } else if (action.equals("playTimeAudio")) { // // if (playerAudio != null) { // if (playerAudio.getPlaybackState() == playerAudio.STATE_READY) { // callbackContext.success(playerAudio.getPlayerControl().getDuration()); // } else { // callbackContext.success(0); // } // } else { // // callbackContext.success(0); // } // // return true; // } else if (action.equals("seekVOD")) { // player.seekTo(Integer.parseInt(args.getString(0))); // // return true; // } else if (action.equals("seekRtsp")) { // player.rtspPlay(Integer.parseInt(args.getString(0))); // // return true; } else if (action.equals("playAudio")) { currentPlay = PLAYING_AUDIO; codecMpeg123 = false; final String url = args.getString(0); urlPlaying = url; if (player != null) { player.release(); } player.init(url, surfaceView_live); return true; // } else if (action.equals("pauseAudio")) { // playerAudio.getPlayerControl().pause(); // // return true; // } else if (action.equals("resumeAudio")) { // playerAudio.getPlayerControl().start(); // // return true; } else if (action.equals("stopAudio")) { if (playerAudio != null) { playerAudio.stop(); } return true; // } else if (action.equals("seekAudio")) { // if (playerAudio != null) { // playerAudio.seekTo(Integer.parseInt(args.getString(0))); // } // // return true; } else if (action.equals("release")) { if (player != null) { player.stop(); } return true; } else if (action.equals("setToken")) { Log.i(LOGTAG, "setToken"); token = args.getString(0); Log.i(LOGTAG, "token: " + token); return true; } else if (action.equals("setLicense")) { Log.i(LOGTAG, "setLicense"); LA_URL = args.getString(0); Log.i(LOGTAG, "LA_URL: " + LA_URL); return true; // } else if (action.equals("playDrm")) { // cordova.getActivity().runOnUiThread(new Runnable() { // public void run() { // currentPlay = PLAYING_DRM; // codecMpeg123 = false; // // errorDRM = false; // String contentUri = null; // try { // contentUri = args.getString(0); // Log.i(LOGTAG, "url: " + contentUri); // urlPlaying = contentUri; // } catch (JSONException e) { // e.printStackTrace(); // } // // if (player != null) { // player.release(); // } // // player = new DemoPlayer(new SmoothStreamingRendererBuilder(context, userAgent, contentUri.toString(), // new SmoothStreamingTestMediaDrmCallback())); // player.setSurface(surface_live); // // eventLogger = new EventLogger(); // eventLogger.startSession(); // player.addListener(eventLogger); // player.setInfoListener(eventLogger); // // player.prepare(); // player.setPlayWhenReady(true); // } // }); // // return true; } else if (action.equals("changeAudio")) { if (player.changeAudio(Integer.parseInt(args.getString(0)))) { callbackContext.success("1"); } else { callbackContext.success("0"); } return true; } else if (action.equals("getAudios")) { String audioinfo = player.getAudios(); callbackContext.success(audioinfo.substring(1)); return true; } else if (action.equals("getSubtitles")) { callbackContext.success(player.getSubtitles()); return true; } else if (action.equals("changeSubtitle")) { if (player.changeSubtitle(Integer.parseInt(args.getString(0)))) { callbackContext.success("1"); } else { callbackContext.success("0"); } return true; } else if (action.equals("supportMulticast")) { File file = new File("/proc/net/igmp"); if (file.exists()) { callbackContext.success("1"); } else { callbackContext.success("0"); } return true; } else if (action.equals("setVideoSize")) { float APP_WIDTH = 1280; float appWidth = webView.getWidth(); float appHeight = webView.getHeight(); final android.view.ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) surfaceView_live .getLayoutParams(); if (args.getString(0).equals("1")) { float scale = APP_WIDTH / appWidth; Log.i(LOGTAG, "screenWidth: " + appWidth); Log.i(LOGTAG, "scale: " + scale); float width = Integer.parseInt(args.getString(1)) / scale; float height = Integer.parseInt(args.getString(2)) / scale; float bottomMargin = Integer.parseInt(args.getString(3)) / scale; float rightMargin = Integer.parseInt(args.getString(3)) / scale; lp.width = (int) width; lp.height = (int) height; lp.topMargin = (int) (appHeight - height - bottomMargin); lp.leftMargin = (int) (appWidth - width - rightMargin); cordova.getActivity().runOnUiThread(new Runnable() { public void run() { surfaceView_live.setLayoutParams(lp); // MainActivity.getVideoFrame().bringToFront(); } }); } else { lp.width = (int) appWidth; lp.height = (int) appHeight; lp.topMargin = 0; lp.leftMargin = 0; cordova.getActivity().runOnUiThread(new Runnable() { public void run() { surfaceView_live.setLayoutParams(lp); webView.bringToFront(); } }); } return true; } else if (action.equals("muteVideo")) { if (args.getString(0).equals("1")) { player.setVolume(0); } else { player.setVolume(0); } return true; } else if (action.equals("registerCallback")) { String event = args.getString(0); if (event.equals("OnStateChanged")) { onStateChangedCallbackContext = callbackContext; PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, "registered"); pluginResult.setKeepCallback(true); onStateChangedCallbackContext.sendPluginResult(pluginResult); } else if (event.equals("OnError")) { onErrorCallbackContext = callbackContext; PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, "registered"); pluginResult.setKeepCallback(true); onErrorCallbackContext.sendPluginResult(pluginResult); } else if (event.equals("OnTrackChanged")) { onTrackChangedCallbackContext = callbackContext; PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, "registered"); pluginResult.setKeepCallback(true); onTrackChangedCallbackContext.sendPluginResult(pluginResult); } else { callbackContext.error("unknown event"); } } else { return false; } return true; }
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); 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); 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); onTrackChangedCallbackContext.sendPluginResult(pluginResult); }
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 .ja va 2 s . c o m*/ 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();//from w ww .j a v a2s .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 {// www .j a va 2 s.co 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.nolgong.pedometer.Pedometer.java
License:Apache License
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { LOG.i(TAG, "execute()"); this.callbackContext = callbackContext; if (action.equals("isStepCountingAvailable")) { this.isStepCountingAvailable(); } else if (action.equals("startPedometerUpdates")) { if (!this.activityRunning) { this.startPedometerUpdates(); }//ww w. j a v a 2s .c o m } else if (action.equals("stopPedometerUpdates")) { if (this.activityRunning) { this.stopPedometerUpdates(); } } else { return false; } PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT, ""); result.setKeepCallback(true); callbackContext.sendPluginResult(result); return true; }
From source file:com.nolgong.pedometer.Pedometer.java
License:Apache License
public void isStepCountingAvailable() { this.activityRunning = true; countSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER); if (countSensor != null) { LOG.i(TAG, "isStepCountingAvailable() " + countSensor); sensorManager.registerListener(this, countSensor, SensorManager.SENSOR_DELAY_UI); PluginResult result = new PluginResult(PluginResult.Status.OK); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } else {/*from ww w.j a va2s .c o m*/ LOG.i(TAG, "isStepCountingAvailable() fail"); PluginResult err = new PluginResult(PluginResult.Status.ERROR); err.setKeepCallback(true); callbackContext.sendPluginResult(err); } }