List of usage examples for org.apache.cordova PluginResult setKeepCallback
public void setKeepCallback(boolean b)
From source file:com.vidinoti.pixlive.PixLive.java
@Override public void onSyncProgress(VDARRemoteController controller, float progress, boolean isReady, String folder) { if (this.eventHandler != null) { JSONObject o = new JSONObject(); try {//from w ww . j ava 2 s. c om o.put("type", "syncProgress"); o.put("progress", progress / 100.0f); } catch (JSONException e) { } PluginResult p = new PluginResult(PluginResult.Status.OK, o); p.setKeepCallback(true); try { PixLive.this.eventHandler.sendPluginResult(p); } catch (Exception e) { //To avoid webview crashes } } }
From source file:com.vp9.plugin.WebSocket.java
License:Open Source License
/** * Connect a server./*from w w w .jav a 2 s . c om*/ * @param callbackContext * @param callbackId * @param uri * @param protocol * @param origin */ private void create(final CallbackContext callbackContext, final int callbackId, String uri, String protocol, String origin) { WebSocketClient client = _factory.newWebSocketClient(); client.setMaxTextMessageSize(10240000); if (protocol.length() > 0) { client.setProtocol(protocol); } if (origin.length() > 0) { client.setOrigin(origin); } try { client.open(createURI(uri), new org.eclipse.jetty.websocket.WebSocket.OnTextMessage() { @Override public void onOpen(Connection conn) { _conn.put(callbackId, conn); JSONObject json = createCallbackJSON("onopen", null); PluginResult result = new PluginResult(Status.OK, json); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } @Override public void onMessage(String data) { JSONObject json = createCallbackJSON("onmessage", data); PluginResult result = new PluginResult(Status.OK, json); result.setKeepCallback(true); callbackContext.sendPluginResult(result); } @Override public void onClose(int code, String message) { _conn.remove(callbackId); JSONObject json = createCallbackJSON("onclose", code); PluginResult result = new PluginResult(Status.OK, json); if (code != 1000) { result.setKeepCallback(true); } callbackContext.sendPluginResult(result); } }, CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS); } catch (Exception e) { callbackContext.error(e.toString()); } }
From source file:com.vuforia.VuforiaPlugin.java
public void initVuforia(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { // If we are starting Vuforia, set the public variable referencing our start callback for later use // VuforiaPlugin.persistantVuforiaStartCallback = callbackContext; initVuforiaCallback = callbackContext; ACTION = action;/*from w w w . java 2 s . c om*/ ARGS = args; // Get all of our ARGS out and into local variables // String targetFile = args.getString(0); // String targets = args.getJSONArray(1).toString(); // String overlayText = (args.isNull(2)) ? null : args.getString(2); // String vuforiaLicense = args.getString(3); // Boolean closeButton = args.getBoolean(4); // Boolean showDevicesIcon = args.getBoolean(5); // autostopOnImageFound = args.getBoolean(6); vuforia_key = args.get(0).toString(); vuforia_access_key = args.get(1).toString(); vuforia_secret_key = args.get(2).toString(); command_id = callbackContext.getCallbackId(); Boolean closeButton = true; Boolean showDevicesIcon = false; autostopOnImageFound = true; String overlayText = "Scan the pattern image"; Context context = cordova.getActivity().getApplicationContext(); // Create a new intent to pass data to Vuforia // Intent intent = new Intent(context, CloudReco.class); // // // if(overlayText != null) // intent.putExtra("OVERLAY_TEXT", overlayText); // // intent.putExtra("LICENSE_KEY", vuforia_key); // intent.putExtra("DISPLAY_CLOSE_BUTTON", closeButton); // intent.putExtra("DISPLAY_DEVICES_ICON", showDevicesIcon); // intent.putExtra("STOP_AFTER_IMAGE_FOUND", autostopOnImageFound); JSONObject json = new JSONObject(); if (vuforiaStarted) { sendAction(DISMISS_ACTION); json.put("success", "true"); json.put("message", "success"); } else { json.put("success", "false"); json.put("message", "No Vuforia session running"); } PluginResult result = new PluginResult(PluginResult.Status.OK, " "); result.setKeepCallback(true); callback.sendPluginResult(result); // Check to see if we have permission to access the camera // if(cordova.hasPermission(CAMERA)) { // // Launch a new activity with Vuforia in it. Expect it to return a result. // cordova.startActivityForResult(this, intent, IMAGE_REC_REQUEST); // vuforiaStarted = true; // } // else { // // Request the camera permission and handle the outcome. // cordova.requestPermission(this, CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE, CAMERA); // } }
From source file:com.wezka.nativecamera.NativeCameraLauncher.java
License:Apache License
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { PluginResult.Status status = PluginResult.Status.OK; String result = ""; this.callbackContext = callbackContext; try {/*from w ww . j a v a 2s. c om*/ if (action.equals("takePicture")) { this.targetHeight = 0; this.targetWidth = 0; this.mQuality = 80; this.targetHeight = args.getInt(4); this.targetWidth = args.getInt(3); this.mQuality = args.getInt(0); this.takePicture(); PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT); r.setKeepCallback(true); callbackContext.sendPluginResult(r); return true; } return false; } catch (JSONException e) { e.printStackTrace(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); return true; } }
From source file:com.whamads.nativecamera.NativeCameraLauncher.java
License:Apache License
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { PluginResult.Status status = PluginResult.Status.OK; String result = ""; this.callbackContext = callbackContext; try {// w w w . j av a2 s . co m if (action.equals("takePicture")) { if (!PermissionHelper.hasPermission(this, Manifest.permission.CAMERA)) { PermissionHelper.requestPermission(this, 1, Manifest.permission.CAMERA); } else { this.targetHeight = 0; this.targetWidth = 0; this.mQuality = 80; this.targetHeight = args.getInt(4); this.targetWidth = args.getInt(3); this.mQuality = args.getInt(0); this.takePicture(); PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT); r.setKeepCallback(true); callbackContext.sendPluginResult(r); } return true; } return false; } catch (JSONException e) { e.printStackTrace(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); return true; } }
From source file:com.wikitude.phonegap.WikitudePlugin.java
License:Apache License
@Override public boolean execute(final String action, final JSONArray args, final CallbackContext callContext) { /* hide architect-view -> destroy and remove from activity */ if (WikitudePlugin.ACTION_CLOSE.equals(action)) { if (this.architectView != null) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override/*from w ww . j av a 2 s .co m*/ public void run() { removeArchitectView(); } }); callContext.success(action + ": architectView is present"); } else { callContext.error(action + ": architectView is not present"); } return true; } /* return success only if view is opened (no matter if visible or not) */ if (WikitudePlugin.ACTION_STATE_ISOPEN.equals(action)) { if (this.architectView != null) { callContext.success(action + ": architectView is present"); } else { callContext.error(action + ": architectView is not present"); } return true; } /* return success only if view is opened (no matter if visible or not) */ if (WikitudePlugin.ACTION_IS_DEVICE_SUPPORTED.equals(action)) { if (ArchitectView.isDeviceSupported(this.cordova.getActivity()) && hasNeonSupport()) { callContext.success(action + ": this device is ARchitect-ready"); } else { callContext.error(action + action + ":Sorry, this device is NOT ARchitect-ready"); } return true; } if (WikitudePlugin.ACTION_CAPTURE_SCREEN.equals(action)) { if (architectView != null) { int captureMode = ArchitectView.CaptureScreenCallback.CAPTURE_MODE_CAM_AND_WEBVIEW; try { captureMode = (args.getBoolean(0)) ? ArchitectView.CaptureScreenCallback.CAPTURE_MODE_CAM_AND_WEBVIEW : ArchitectView.CaptureScreenCallback.CAPTURE_MODE_CAM; } catch (Exception e) { // unexpected error; } architectView.captureScreen(captureMode, new CaptureScreenCallback() { @Override public void onScreenCaptured(Bitmap screenCapture) { try { // final File imageDirectory = cordova.getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES); final File imageDirectory = Environment.getExternalStorageDirectory(); if (imageDirectory == null) { callContext.error("External storage not available"); } final File screenCaptureFile = new File(imageDirectory, System.currentTimeMillis() + ".jpg"); if (screenCaptureFile.exists()) { screenCaptureFile.delete(); } final FileOutputStream out = new FileOutputStream(screenCaptureFile); screenCapture.compress(Bitmap.CompressFormat.JPEG, 90, out); out.flush(); out.close(); cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { final String absoluteCaptureImagePath = screenCaptureFile.getAbsolutePath(); callContext.success(absoluteCaptureImagePath); // in case you want to sent the pic to other applications, uncomment these lines (for future use) // final Intent share = new Intent(Intent.ACTION_SEND); // share.setType("image/jpg"); // share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(screenCaptureFile)); // final String chooserTitle = "Share Snaphot"; // cordova.getActivity().startActivity(Intent.createChooser(share, chooserTitle)); } }); } catch (Exception e) { callContext.error(e.getMessage()); } } }); return true; } } /* life-cycle's RESUME */ if (WikitudePlugin.ACTION_ON_RESUME.equals(action)) { if (this.architectView != null) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { WikitudePlugin.this.architectView.onResume(); callContext.success(action + ": architectView is present"); locationProvider.onResume(); } }); // callContext.success( action + ": architectView is present" ); } else { callContext.error(action + ": architectView is not present"); } return true; } /* life-cycle's PAUSE */ if (WikitudePlugin.ACTION_ON_PAUSE.equals(action)) { if (architectView != null) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { WikitudePlugin.this.architectView.onPause(); locationProvider.onPause(); } }); callContext.success(action + ": architectView is present"); } else { callContext.error(action + ": architectView is not present"); } return true; } /* set visibility to "visible", return error if view is null */ if (WikitudePlugin.ACTION_SHOW.equals(action)) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { if (architectView != null) { architectView.setVisibility(View.VISIBLE); callContext.success(action + ": architectView is present"); } else { callContext.error(action + ": architectView is not present"); } } }); return true; } /* set visibility to "invisible", return error if view is null */ if (WikitudePlugin.ACTION_HIDE.equals(action)) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { if (architectView != null) { architectView.setVisibility(View.INVISIBLE); callContext.success(action + ": architectView is present"); } else { callContext.error(action + ": architectView is not present"); } } }); return true; } /* define call-back for url-invocations */ if (WikitudePlugin.ACTION_ON_URLINVOKE.equals(action)) { this.urlInvokeCallback = callContext; final PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT, action + ": registered callback"); result.setKeepCallback(true); callContext.sendPluginResult(result); return true; } /* location update */ if (WikitudePlugin.ACTION_SET_LOCATION.equals(action)) { if (this.architectView != null) { try { final double lat = args.getDouble(0); final double lon = args.getDouble(1); float alt = Float.MIN_VALUE; try { alt = (float) args.getDouble(2); } catch (Exception e) { // invalid altitude -> ignore it } final float altitude = alt; Double acc = null; try { acc = args.getDouble(3); } catch (Exception e) { // invalid accuracy -> ignore it } final Double accuracy = acc; if (this.cordova != null && this.cordova.getActivity() != null) { this.useCustomLocation = true; cordova.getActivity().runOnUiThread( // this.cordova.getThreadPool().execute( new Runnable() { @Override public void run() { if (accuracy != null) { WikitudePlugin.this.architectView.setLocation(lat, lon, altitude, accuracy.floatValue()); } else { WikitudePlugin.this.architectView.setLocation(lat, lon, altitude); } } }); } } catch (Exception e) { callContext.error( action + ": exception thrown, " + e != null ? e.getMessage() : "(exception is NULL)"); return true; } callContext.success(action + ": updated location"); return true; } else { /* return error if there is no architect-view active*/ callContext.error(action + ": architectView is not present"); } return true; } if (WikitudePlugin.ACTION_CALL_JAVASCRIPT.equals(action)) { String logMsg = null; try { final String callJS = args.getString(0); logMsg = callJS; this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { if (architectView != null) { WikitudePlugin.this.architectView.callJavascript(callJS); } else { callContext.error(action + ": architectView is not present"); } } }); } catch (JSONException je) { callContext.error( action + ": exception thrown, " + je != null ? je.getMessage() : "(exception is NULL)"); return true; } callContext.success(action + ": called js, '" + logMsg + "'"); return true; } /* initial set-up, show ArchitectView full-screen in current screen/activity */ if (WikitudePlugin.ACTION_OPEN.equals(action)) { this.openCallback = callContext; PluginResult result = null; try { final JSONObject params = args.getJSONObject(0); final String apiKey = params.getString("SDKKey"); final String filePath = params.getString("ARchitectWorldPath"); final String arMode = params.getString("AugmentedRealityMode"); this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { try { WikitudePlugin.this.addArchitectView(apiKey, filePath); /* call success method once architectView was added successfully */ if (openCallback != null) { PluginResult result = new PluginResult(PluginResult.Status.OK); result.setKeepCallback(false); openCallback.sendPluginResult(result); } } catch (Exception e) { /* in case "addArchitectView" threw an exception -> notify callback method asynchronously */ openCallback.error(e != null ? e.getMessage() : "Exception is 'null'"); } } }); } catch (Exception e) { result = new PluginResult(PluginResult.Status.ERROR, action + ": exception thown, " + e != null ? e.getMessage() : "(exception is NULL)"); result.setKeepCallback(false); callContext.sendPluginResult(result); return true; } /* adding architect-view is done in separate thread, ensure to setKeepCallback so one can call success-method properly later on */ result = new PluginResult(PluginResult.Status.NO_RESULT, action + ": no result required, just registered callback-method"); result.setKeepCallback(true); callContext.sendPluginResult(result); return true; } /* fall-back return value */ callContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "no such action: " + action)); return false; }
From source file:com.wikitude.phonegap.WikitudePlugin.java
License:Apache License
/** * called when url was invoked in architectView (by e.g. calling document.location = "myprotocoll://foo"; * @param url the invoked url (e.g. "architectsdk://foo") * @return true if call was handled properly *//*from w w w .ja v a 2s . c om*/ @Override public boolean urlWasInvoked(final String url) { /* call callback-method if set*/ if (this.urlInvokeCallback != null) { try { /* pass called url as String to callback-method */ final PluginResult res = new PluginResult(PluginResult.Status.OK, url); res.setKeepCallback(true); this.urlInvokeCallback.sendPluginResult(res); } catch (Exception e) { this.urlInvokeCallback.error("invalid url invoked: " + url); } return true; } return false; }
From source file:com.wodify.cordova.plugin.filepicker.FilePicker.java
License:Apache License
/** * Executes the request sent from JavaScript. * * @param action/*from www .j a v a 2 s . c om*/ * The action to execute. * @param args * The exec() arguments in JSON form. * @param command * The callback context used when calling back into JavaScript. * @return * Whether the action was valid. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { this.callbackContext = callbackContext; if (action.equals("pickFile")) { if (args.length() > 1) { returnFileWithDetails = args.getBoolean(1); } this.pickFile(); PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT); r.setKeepCallback(true); callbackContext.sendPluginResult(r); return true; } else if (action.equals("deviceSupported")) { callbackContext.success("true"); } return false; }
From source file:com.wx.iseeweather.GetPressurePlugin.GetPressure.java
License:Apache License
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { this.callbackContext = callbackContext; mSensorManager = (SensorManager) this.cordova.getActivity().getSystemService(Context.SENSOR_SERVICE); mPressure = mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE); if (mPressure != null) { currentNumberOfReadings = 0;/* www .j a v a 2 s .c o m*/ mSensorManager.registerListener(this, mPressure, SensorManager.SENSOR_DELAY_NORMAL); PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT); result.setKeepCallback(true); callbackContext.sendPluginResult(result); return true; } else { callbackContext.error("No pressure sensor found."); return false; } }
From source file:com.wx.iseeweather.GetPressurePlugin.GetPressure.java
License:Apache License
private void sendFinalResult() { mSensorManager.unregisterListener(this); Arrays.sort(pressures);//w w w . java 2 s . co m PluginResult result = new PluginResult(PluginResult.Status.OK, pressures[(NUMBER_OF_READINGS - 1) / 2]); result.setKeepCallback(false); callbackContext.sendPluginResult(result); }