List of usage examples for org.apache.cordova PluginResult PluginResult
public PluginResult(Status status)
From source file:com.inbeacon.cordova.CordovaInbeaconManager.java
License:Apache License
/** * The final call you receive before your activity is destroyed. *///from ww w.j a v a2 s . com public void onDestroy() { if (broadcastReceiver != null) { // unRegister our receiver that was registered on localbroadcastmanager // wrong: cordova.getActivity().unregisterReceiver(broadcastReceiver); LocalBroadcastManager.getInstance(cordova.getActivity().getApplicationContext()) .unregisterReceiver(broadcastReceiver); broadcastReceiver = null; } // release events in JS side if (eventCallbackContext != null) { PluginResult result = new PluginResult(PluginResult.Status.OK); result.setKeepCallback(false); eventCallbackContext.sendPluginResult(result); eventCallbackContext = null; } super.onDestroy(); }
From source file:com.inbeacon.cordova.CordovaInbeaconManager.java
License:Apache License
/** * Send a new plugin result with no result. Use to keep callback channel open for events *//*from ww w.j ava 2 s.c o m*/ private void sendNoResult() { if (this.eventCallbackContext != null) { PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(true); this.eventCallbackContext.sendPluginResult(pluginResult); } }
From source file:com.ironsmile.cordova.mediaevents.MediaEventListener.java
License:Apache License
/** * Executes the request./*from w w w .j a v a 2 s. co m*/ * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackContext The callback context used when calling back into js * @return True if the action was valid, false if not. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { if (action.equals("start")) { if (this.eventCallbackContext != null) { callbackContext.error("Media event listener already running."); return true; } this.eventCallbackContext = callbackContext; // We need to listen to audio events IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(AudioManager.ACTION_AUDIO_BECOMING_NOISY); if (this.receiver == null) { this.receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { sendMediaEvent(intent); } }; cordova.getActivity().registerReceiver(this.receiver, intentFilter); } if (this.focusListener == null) { Context ctx = cordova.getActivity().getBaseContext(); this.focusListener = this.new FocusListener(ctx); } // Don't return any result now, since status results will be sent when // events come in from broadcast receiver PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); return true; } else if (action.equals("stop")) { removeMediaEventListener(); // release status callback in JS side this.sendUpdate(new JSONObject(), false); this.eventCallbackContext = null; callbackContext.success(); return true; } return false; }
From source file:com.jcesarmobile.plusonebutton.PlusOneButtonPlugin.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 callbackContext The callback context from which we were invoked. *//*w ww . j av a2 s .c o m*/ @SuppressLint("NewApi") public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException { if (action.equals("show")) { if (args.optJSONObject(0) != null) { JSONObject obj = args.getJSONObject(0); URL = obj.optString("url", null); if (URL == null) { callbackContext.error("you have to provide an url"); } x = obj.optJSONObject("position").optLong("x", 0); y = obj.optJSONObject("position").optLong("y", 0); size = obj.optInt("size", 3); annotation = obj.optInt("annotation", 1); } else if (args.optString(0) != null) { URL = args.optString(0); } else { callbackContext.error("you have to provide an url"); } if (mPlusOneButton == null) { mPlusOneButton = new PlusOneButton(cordova.getActivity()); } cordova.getActivity().runOnUiThread(new Runnable() { public void run() { mPlusOneButton.initialize(URL, null); mPlusOneButton.setVisibility(View.VISIBLE); if (!created) { cordova.getActivity().addContentView(mPlusOneButton, new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)); created = true; } mPlusOneButton.setX(x); mPlusOneButton.setY(y); mPlusOneButton.setSize(size); mPlusOneButton.setAnnotation(annotation); } }); } else if (action.equals("hide")) { if (mPlusOneButton != null) { cordova.getActivity().runOnUiThread(new Runnable() { public void run() { mPlusOneButton.setVisibility(View.GONE); } }); } } else if (action.equals("onClick")) { if (mPlusOneButton != null) { callback = callbackContext; mPlusOneButton.setOnPlusOneClickListener(new PlusOneButton.OnPlusOneClickListener() { @Override public void onPlusOneClick(Intent intent) { System.out.println("1 Click!"); PluginResult result = new PluginResult(PluginResult.Status.OK); result.setKeepCallback(true); callback.sendPluginResult(result); cordova.startActivityForResult(PObtn, intent, 0); } }); } } else { return false; } return true; }
From source file:com.jcesarmobile.plusonebutton.PlusOneButtonPlugin.java
License:Apache License
@Override public void onResume(boolean multitasking) { super.onResume(multitasking); if (mPlusOneButton != null) { mPlusOneButton.initialize(URL, null); mPlusOneButton.setOnPlusOneClickListener(new PlusOneButton.OnPlusOneClickListener() { @Override/*from w w w . j a v a2 s . c om*/ public void onPlusOneClick(Intent intent) { System.out.println("2 Click!"); PluginResult result = new PluginResult(PluginResult.Status.OK); result.setKeepCallback(true); callback.sendPluginResult(result); cordova.startActivityForResult(PObtn, intent, 0); } }); } }
From source file:com.KA.Geolocation.java
License:Apache License
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { LOG.d(TAG, "We are entering execute"); context = callbackContext;// w w w. jav a 2 s . c om if (action.equals("getPermission")) { if (hasPermisssion()) { PluginResult r = new PluginResult(PluginResult.Status.OK); context.sendPluginResult(r); return true; } else { PermissionHelper.requestPermissions(this, 0, permissions); } return true; } return false; }
From source file:com.KA.Geolocation.java
License:Apache License
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) throws JSONException { PluginResult result;/*from w w w . j ava2 s .c o m*/ //This is important if we're using Cordova without using Cordova, but we have the geolocation plugin installed if (context != null) { for (int r : grantResults) { if (r == PackageManager.PERMISSION_DENIED) { LOG.d(TAG, "Permission Denied!"); result = new PluginResult(PluginResult.Status.ILLEGAL_ACCESS_EXCEPTION); context.sendPluginResult(result); return; } } result = new PluginResult(PluginResult.Status.OK); context.sendPluginResult(result); } }
From source file:com.keepe.plugins.cardio.CardIO.java
License:Open Source License
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { // TODO Auto-generated method stub this.callbackContext = callbackContext; try {//from w ww.j ava2 s.com // set configurations if (action.equals("scan")) { JSONObject config = args.getJSONObject(0); expiry = config.getBoolean("expiry"); cvv = config.getBoolean("cvv"); zip = config.getBoolean("zip"); confirm = config.getBoolean("suppressConfirm"); hideLogo = config.getBoolean("hideLogo"); suppressManual = config.getBoolean("suppressManual"); guideColor = Color.parseColor(config.getString("guideColor")); Intent scanIntent = new Intent(cordova.getActivity(), CardIOMain.class); cordova.getActivity().startActivity(scanIntent); PluginResult cardData = new PluginResult(PluginResult.Status.NO_RESULT); cardData.setKeepCallback(true); callbackContext.sendPluginResult(cardData); return true; } else if (action.equals("canScan")) { if (CardIOActivity.canReadCardWithCamera()) { callbackContext.success("PASS"); return true; } else { callbackContext.error("FAIL"); return false; } } return false; } catch (JSONException e) { e.printStackTrace(); PluginResult res = new PluginResult(PluginResult.Status.JSON_EXCEPTION); callbackContext.sendPluginResult(res); return false; } }
From source file:com.knowledgecode.cordova.websocket.ConnectionTask.java
License:Apache License
@Override public void execute(JSONArray args, CallbackContext ctx) { try {/*from ww w .j a v a 2 s . c o m*/ WebSocketClient client = _factory.newWebSocketClient(); int id = args.getInt(0); URI uri = new URI(args.getString(1)); String protocol = args.getString(2); JSONObject options = args.getJSONObject(5); String origin = options.optString("origin", args.getString(3)); String agent = options.optString("agent", args.getString(4)); long maxConnectTime = options.optLong("maxConnectTime", MAX_CONNECT_TIME); client.setMaxTextMessageSize(options.optInt("maxTextMessageSize", MAX_TEXT_MESSAGE_SIZE)); client.setMaxBinaryMessageSize(options.optInt("maxBinaryMessageSize", MAX_BINARY_MESSAGE_SIZE)); if (protocol.length() > 0) { client.setProtocol(protocol); } if (origin.length() > 0) { client.setOrigin(origin); } if (agent.length() > 0) { client.setAgent(agent); } setCookie(client.getCookies(), uri.getHost()); WebSocketGenerator gen = new WebSocketGenerator(id, ctx); gen.setOnOpenListener(new OnOpenListener() { @Override public void onOpen(int id, Connection conn) { _map.put(id, conn); } }); gen.setOnCloseListener(new OnCloseListener() { @Override public void onClose(int id) { if (_map.indexOfKey(id) >= 0) { _map.remove(id); } } }); client.open(uri, gen, maxConnectTime, TimeUnit.MILLISECONDS); } catch (Exception e) { if (!ctx.isFinished()) { PluginResult result = new PluginResult(Status.ERROR); result.setKeepCallback(true); ctx.sendPluginResult(result); } } }
From source file:com.manueldeveloper.VolumeButtonsListener.java
License:Apache License
/** * Method which executes the Javascript request * * @param action: String object with the action to execute * @param args: JSONArray object with the arguments of the request * @param callbackContext: CallbackContext object for call back into Javascript * * @return "boolean" which indicates if the action is valid (true) or not (false) * * @date 10/12/2016//ww w . j a v a 2 s . co m * @version 0.0.3 * @author ManuelDeveloper(manueldeveloper@gmail.com) */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { // Check the action if (action.equals("start")) { // Check if the plugin is listening the volume button events if (this.volumeCallbackContext != null) { callbackContext.error("Volume buttons listener already running"); return true; } // Get the reference to the callbacks and start the listening process this.volumeCallbackContext = callbackContext; this.webView.getView().setOnKeyListener(this); // Don't return any result now PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); pluginResult.setKeepCallback(true); this.volumeCallbackContext.sendPluginResult(pluginResult); return true; } else if (action.equals("stop")) { // Erase the callbacks reference and stop the listening process sendSignal(new JSONObject(), false); // release status callback in Javascript side this.volumeCallbackContext = null; this.webView.getView().setOnKeyListener(null); callbackContext.success(); return true; } return false; }