private PluginResult registerTagListener() throws NFCException, JSONException { ReaderWriterManager nfc = ReaderWriterManager.getInstance(); tagListener = new DetectionListener() { public void onTargetDetected(Target target) { Hashtable props = Util.getTagProperties(target); NDEFMessage message = null; try { NDEFTagConnection tagConnection = (NDEFTagConnection) Connector.open(target.getUri(Target.NDEF_TAG)); message = tagConnection.read(); // might want to handle NFCException different } catch (IOException e) { Logger.error("Failed reading tag " + e.toString()); } fireNdefEvent(TAG_DEFAULT, message, props); } }; nfc.addDetectionListener(tagListener); return new PluginResult(Status.OK); }
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback id used when calling back into JavaScript. * @return A PluginResult object with a status and message. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { this.callbackContext = callbackContext; this.targetHeight = 0; this.targetWidth = 0; this.mQuality = 80; JSONObject options = args.optJSONObject(0); if (options != null) { this.targetHeight = options.getInt("targetHeight"); this.targetWidth = options.getInt("targetWidth"); this.mQuality = options.getInt("quality"); } this.getImage(); PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT); r.setKeepCallback(true); callbackContext.sendPluginResult(r); return true; }
public void processPicture(Bitmap bitmap) { ByteArrayOutputStream jpeg_data = new ByteArrayOutputStream(); try { if (bitmap.compress(CompressFormat.JPEG, mQuality, jpeg_data)) { byte[] code = jpeg_data.toByteArray(); byte[] output = Base64.encodeBase64(code); String js_out = new String(output); this.success(new PluginResult(PluginResult.Status.OK, "data:image/jpeg;base64," + js_out), this.callbackId); js_out = null; output = null; code = null; } } catch (Exception e) { this.failPicture("Error compressing image."); } jpeg_data = null; }
private void fail(int paramInt, String paramString) { JSONObject localJSONObject = new JSONObject(); try { localJSONObject.put("code", paramInt); localJSONObject.put("message", paramString); PluginResult localPluginResult = new PluginResult(PluginResult.Status.ERROR, localJSONObject); localPluginResult.setKeepCallback(true); this.callbackContext.sendPluginResult(localPluginResult); return; } catch (JSONException localJSONException) { while (true) localJSONException.printStackTrace(); } }
public boolean execute(String paramString, JSONArray paramJSONArray, CallbackContext paramCallbackContext) { if (paramString.equals("start")) { this.callbackContext = paramCallbackContext; if (this.status != RUNNING) start(); } while (true) { PluginResult localPluginResult = new PluginResult(PluginResult.Status.NO_RESULT, ""); localPluginResult.setKeepCallback(true); paramCallbackContext.sendPluginResult(localPluginResult); return true; if (!paramString.equals("stop")) break; if (this.status != RUNNING) continue; stop(); } return false; }
public void addPluginResult(PluginResult paramPluginResult, String paramString) { if (paramString == null) { Log.e("JsMessageQueue", "Got plugin result with no callbackId", new Throwable()); return; } if (paramPluginResult.getStatus() == PluginResult.Status.NO_RESULT.ordinal()); for (int i = 1; ; i = 0) { boolean bool = paramPluginResult.getKeepCallback(); if ((i != 0) && (bool)) break; enqueueMessage(new JsMessage(paramPluginResult, paramString)); return; } }
public void onReceivedError(WebView paramWebView, int paramInt, String paramString1, String paramString2) { super.onReceivedError(paramWebView, paramInt, paramString1, paramString2); try { JSONObject localJSONObject = new JSONObject(); localJSONObject.put("type", "loaderror"); localJSONObject.put("url", paramString2); localJSONObject.put("code", paramInt); localJSONObject.put("message", paramString1); InAppBrowser.this.sendUpdate(localJSONObject, true, PluginResult.Status.ERROR); return; } catch (JSONException localJSONException) { Log.d("InAppBrowser", "Should never happen"); } }
public PluginResult dispatch(BaseActionDispatcher.Context paramContext) throws Throwable { DatabaseManager localDatabaseManager = DatabaseManager.getInstance(); try { localDatabaseManager.clearDbPath(); localDatabaseManager.clearDatabaseKey(); if (localDatabaseManager.isDatabaseOpen()) localDatabaseManager.closeDatabase(); PluginResult localPluginResult = new PluginResult(PluginResult.Status.OK, 0); return localPluginResult; } catch (Throwable localThrowable) { } return new PluginResult(PluginResult.Status.ERROR, 23); }
public PluginResult dispatch(DatabaseActionDispatcher.Context paramContext) throws Throwable { JSONArray localJSONArray1 = getIds(paramContext); try { JSONArray localJSONArray2 = (JSONArray)paramContext.performReadableDatabaseAction(new FindByIdAction(localJSONArray1, null)); if (localJSONArray2 == null) return new PluginResult(PluginResult.Status.ERROR, 22); JacksonSerializedPluginResult localJacksonSerializedPluginResult = new JacksonSerializedPluginResult(PluginResult.Status.OK, localJSONArray2); return localJacksonSerializedPluginResult; } catch (Throwable localThrowable) { if (this.logger.isLoggable(6)) this.logger.logError("error while executing find by ID query on database \"" + paramContext.getDatabaseName() + "\"", localThrowable); } return new PluginResult(PluginResult.Status.ERROR, 22); }
public PluginResult dispatch(BaseActionDispatcher.Context paramContext) throws Throwable { if (!DatabaseManager.getInstance().isDatabaseOpen()) return new PluginResult(PluginResult.Status.ERROR, -50); String str1 = getNewPW(paramContext); String str2 = getOldPW(paramContext); String str3 = getUserName(paramContext); SecurityManager localSecurityManager = SecurityManager.getInstance(paramContext.getCordovaContext().getActivity()); try { String str4 = localSecurityManager.getDPK(str2, str3); String str5 = localSecurityManager.getSalt(str3); localSecurityManager.storeDPK(str1, str3, str4, str5, true, false); return new PluginResult(PluginResult.Status.OK, 0); } catch (Throwable localThrowable) { } return new PluginResult(PluginResult.Status.ERROR, 24); }
public PluginResult dispatch(DatabaseActionDispatcher.Context paramContext) throws Throwable { JSONArray localJSONArray = getDocs(paramContext); for (int i = 0; i < localJSONArray.length(); i++) { JSONObject localJSONObject = localJSONArray.getJSONObject(i); MarkCleanAction localMarkCleanAction = new MarkCleanAction(localJSONObject.getInt("_id"), localJSONObject.getString("_operation"), null); try { if (((Integer)paramContext.performWritableDatabaseAction(localMarkCleanAction)).intValue() > 0) continue; PluginResult localPluginResult = new PluginResult(PluginResult.Status.ERROR, 15); return localPluginResult; } catch (Throwable localThrowable) { Exception localException = new Exception("Failed trying to mark document clean"); this.logger.logError("Failed trying to mark document clean", localException); return new PluginResult(PluginResult.Status.ERROR, 15); } } return new PluginResult(PluginResult.Status.OK, 0); }
public PluginResult dispatch(DatabaseActionDispatcher.Context paramContext) throws Throwable { int i = -1; try { int k = ((Integer)paramContext.performReadableDatabaseAction(new SimpleQueryAction(paramContext, null))).intValue(); i = k; int j = getModifiedResultValue(i); logResult(paramContext, j); return new PluginResult(PluginResult.Status.OK, j); } catch (Throwable localThrowable) { while (true) { if (!this.logger.isLoggable(6)) continue; this.logger.logError("error occurred while performing query:"); this.logger.logError(" " + getFormattedQuery(paramContext), localThrowable); } } }
public PluginResult dispatch(CordovaInterface paramCordovaInterface, JSONArray paramJSONArray) throws Throwable { Context localContext = new Context(paramCordovaInterface); collectParameters(localContext, paramJSONArray); if (this.logger.isLoggable(3)) { this.logger.logDebug("invoking action dispatcher \"" + this.name + "\" with parameters:"); Iterator localIterator = this.parameters.iterator(); while (localIterator.hasNext()) { Parameter localParameter = (Parameter)localIterator.next(); String str = localParameter.getName(); if (localParameter.isLoggable()) { this.logger.logDebug(" " + str + "=" + localContext.getUntypedParameter(str)); continue; } this.logger.logDebug(" " + str + "=[value not logged]"); } } return dispatch(localContext); }
private PluginResult openFile(String fileUrl){ Log.d("FileViewerPlugin", "View file"+fileUrl); Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); File file = new File(fileUrl); String extension = fileUrl.substring(fileUrl.lastIndexOf(".")+1); String type = ""; if (extension.toLowerCase().equals("pdf")) { type = "application/pdf"; } else if (extension.toLowerCase().equals("flv")) { type = "video/flv"; } else if (extension.toLowerCase().equals("mp4")) { type = "video/mp4"; } else if (extension.toLowerCase().equals("jpg")) { type = "image/jpg"; } intent.setDataAndType(Uri.fromFile(file), type); cordova.getActivity().startActivity(intent); Log.d("FileViewerPlugin", "View complete in" + fileUrl); return new PluginResult(PluginResult.Status.OK, fileUrl); }
/** * Add a JavaScript statement to the list. */ public void addPluginResult(PluginResult result, String callbackId) { if (callbackId == null) { Log.e(LOG_TAG, "Got plugin result with no callbackId", new Throwable()); return; } // Don't send anything if there is no result and there is no need to // clear the callbacks. boolean noResult = result.getStatus() == PluginResult.Status.NO_RESULT.ordinal(); boolean keepCallback = result.getKeepCallback(); if (noResult && keepCallback) { return; } JsMessage message = new JsMessage(result, callbackId); if (FORCE_ENCODE_USING_EVAL) { StringBuilder sb = new StringBuilder(message.calculateEncodedLength() + 50); message.encodeAsJsMessage(sb); message = new JsMessage(sb.toString()); } enqueueMessage(message); }
void encodeAsJsMessage(StringBuilder sb) { if (pluginResult == null) { sb.append(jsPayloadOrCallbackId); } else { int status = pluginResult.getStatus(); boolean success = (status == PluginResult.Status.OK.ordinal()) || (status == PluginResult.Status.NO_RESULT.ordinal()); sb.append("cordova.callbackFromNative('") .append(jsPayloadOrCallbackId) .append("',") .append(success) .append(",") .append(status) .append(",[") .append(pluginResult.getMessage()) .append("],") .append(pluginResult.getKeepCallback()) .append(");"); } }
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { super.onReceivedError(view, errorCode, description, failingUrl); try { JSONObject obj = new JSONObject(); obj.put("type", LOAD_ERROR_EVENT); obj.put("url", failingUrl); obj.put("code", errorCode); obj.put("message", description); sendUpdate(obj, true, PluginResult.Status.ERROR); } catch (JSONException ex) { Log.d(LOG_TAG, "Should never happen"); } }
private void initializeJREngage(String appId, String tokenUrl) { if (appId == null || appId.equals("")) { postResultAndResetState(buildFailureResult(ConfigurationError.MISSING_APP_ID_ERROR, "Missing appId in call to initialize")); return; } try { mJREngage = JREngage.initInstance(cordova.getActivity(), appId, tokenUrl, null); } catch (IllegalArgumentException e) { postResultAndResetState(buildFailureResult(ConfigurationError.GENERIC_CONFIGURATION_ERROR, e.getLocalizedMessage())); return; } postResultAndResetState(new PluginResult(Status.OK, "{'stat':'ok','message':'Initializing JREngage...'}")); }
@Override public void onSignInFailed(String reason){ JSONObject json = new JSONObject(); try{ json.put("type", GMS_SIGNIN); json.put("signin", false); json.put("message", reason); }catch(JSONException ex){ Log.e(TAG, "signin failed exception: "+ex.getMessage()); return; } Log.d(TAG, "signin failed"); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, json); pluginResult.setKeepCallback(true); connectionCB.sendPluginResult(pluginResult); }
@Override public void onStateConflict(int stateKey, String resolvedVersion, byte[] localData, byte[] serverData) { // Need to resolve conflict between the two states. // We do that by taking the union of the two sets of cleared levels, // which means preserving the maximum star rating of each cleared // level: JSONObject json = new JSONObject(); try{ json.put("type", STATE_CONFLICTED); json.put("stateKey", stateKey); json.put("version", resolvedVersion); json.put("localData", new JSONObject(new String(localData))); json.put("serverData", new JSONObject(new String(serverData))); }catch(JSONException ex){ Log.e(TAG, "STATE_CONFLICTED ["+stateKey+"] ["+resolvedVersion+"] exception: "+ex.getMessage()); return; } PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, json); pluginResult.setKeepCallback(true); connectionCB.sendPluginResult(pluginResult); }
@Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { if (action.equals("upload") || action.equals("download")) { String source = args.getString(0); String target = args.getString(1); if (action.equals("upload")) { try { source = URLDecoder.decode(source, "UTF-8"); upload(source, target, args, callbackContext); } catch (UnsupportedEncodingException e) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.MALFORMED_URL_EXCEPTION, "UTF-8 error.")); } } else { download(source, target, args, callbackContext); } return true; } else if (action.equals("abort")) { String objectId = args.getString(0); abort(objectId); callbackContext.success(); return true; } return false; }
/** * Executes the request. * * @param action The action to execute. * @param args The exec() arguments. * @param callbackId The callback id used when calling back into JavaScript. * @return Whether the action was valid. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { if (action.equals("start")) { this.callbackContext = callbackContext; if (this.status != AccelListener.RUNNING) { // If not running, then this is an async call, so don't worry about waiting // We drop the callback onto our stack, call start, and let start and the sensor callback fire off the callback down the road this.start(); } } else if (action.equals("stop")) { if (this.status == AccelListener.RUNNING) { this.stop(); } } else { // Unsupported action return false; } PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT, ""); result.setKeepCallback(true); callbackContext.sendPluginResult(result); return true; }
/** * Parses the create banner view input parameters and runs the create banner * view action on the UI thread. If this request is successful, the developer * should make the requestAd call to request an ad for the banner. * * @param inputs The JSONArray representing input parameters. This function * expects the first object in the array to be a JSONObject with the * input parameters. * @return A PluginResult representing whether or not the banner was created * successfully. */ private PluginResult executeCreateBannerView(JSONArray inputs) { String publisherId; String size; // Get the input data. try { JSONObject data = inputs.getJSONObject(0); publisherId = data.getString("publisherId"); size = data.getString("adSize"); this.positionAtTop = data.getBoolean("positionAtTop"); } catch (JSONException exception) { Log.w(LOGTAG, String.format("Got JSON Exception: %s", exception.getMessage())); return new PluginResult(Status.JSON_EXCEPTION); } // Create the AdView on the UI thread. return executeRunnable(new CreateBannerViewRunnable( publisherId, adSizeFromSize(size))); }
@Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { if (action.equals(ACTION_SEND_SMS)) { try { String phoneNumber = args.getString(0); String message = args.getString(1); String method = args.getString(2); if(method.equalsIgnoreCase("INTENT")){ invokeSMSIntent(phoneNumber, message); callbackContext.sendPluginResult(new PluginResult( PluginResult.Status.NO_RESULT)); } else{ sendSMS(phoneNumber, message); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); return true; } catch (JSONException ex) { callbackContext.sendPluginResult(new PluginResult( PluginResult.Status.JSON_EXCEPTION)); } } return false; }
@Override public void onopen() { cordova.getActivity().runOnUiThread(new Runnable() { public void run() { try { JSONObject json = new JSONObject(); json.put("event", "open"); json.put("value", ""); PluginResult result = new PluginResult(PluginResult.Status.OK, json); result.setKeepCallback(true); Log.e("BrowserPush", "Sending on open"); callbackContext.sendPluginResult(result); } catch (JSONException exception) { callbackContext.error(exception.getMessage()); } } }); }
@Override public void onmessage(final String message) { cordova.getActivity().runOnUiThread(new Runnable() { public void run() { try { JSONObject json = new JSONObject(); json.put("value", message); PluginResult result = new PluginResult(PluginResult.Status.OK, json); result.setKeepCallback(true); Log.e("BrowserPush", "Sending on message " + message); callbackContext.sendPluginResult(result); } catch (JSONException exception) { callbackContext.error(exception.getMessage()); } } }); }
@Override public void onclose() { cordova.getActivity().runOnUiThread(new Runnable() { public void run() { try { JSONObject json = new JSONObject(); json.put("value", ""); PluginResult result = new PluginResult(PluginResult.Status.OK, json); result.setKeepCallback(true); Log.e("BrowserPush", "Sending on close"); callbackContext.sendPluginResult(result); } catch (JSONException exception) { callbackContext.error(exception.getMessage()); } } }); }
private PluginResult registerMimeListener(JSONArray args) throws NFCException, JSONException { ReaderWriterManager nfc = ReaderWriterManager.getInstance(); String mimeType = args.getString(0); NDEFMessageListener listener = new NDEFMessageListener() { public void onNDEFMessageDetected(final NDEFMessage msg) { NfcPlugin.this.fireNdefEvent(NDEF_MIME, msg, null); } }; nfc.addNDEFMessageListener(listener, NDEFRecord.TNF_MEDIA, mimeType, true); return new PluginResult(Status.OK); }
private PluginResult shareTag(JSONArray args) throws NFCException, JSONException { NDEFMessage message = Util.jsonToNdefMessage(args.getString(0)); virtualTag = new VirtualNDEFTag(message); virtualTag.startEmulation(); return new PluginResult(Status.OK); }
/** * 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. */ public PluginResult execute(String action, JSONArray args, String callbackId) { this.callbackId = callbackId; try { this.targetHeight = 0; this.targetWidth = 0; this.mQuality = 80; JSONObject options = args.optJSONObject(0); if (options != null) { this.targetHeight = options.getInt("targetHeight"); this.targetWidth = options.getInt("targetWidth"); this.mQuality = options.getInt("quality"); } this.getImage(); PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT); r.setKeepCallback(true); return r; } catch (JSONException e) { e.printStackTrace(); return new PluginResult(PluginResult.Status.JSON_EXCEPTION); } }