List of usage examples for org.apache.cordova CordovaArgs getInt
public int getInt(int index) throws JSONException
From source file:br.com.hotforms.StatusBarManager.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 id used when calling back into JavaScript. * @return True if the action was valid, false otherwise. *//*from www .ja va2s . c o m*/ @Override public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException { Log.v(TAG, "Executing action: " + action); final Activity activity = this.cordova.getActivity(); final Window window = activity.getWindow(); if ("_ready".equals(action)) { boolean statusBarVisible = (window.getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0; callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, statusBarVisible)); } else if ("show".equals(action)) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); } }); return true; } else if ("hide".equals(action)) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) { window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); } } }); return true; } else if ("setTranslucent".equals(action)) { if (currentapiVersion >= android.os.Build.VERSION_CODES.KITKAT) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) { window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); } window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } }); return true; } else { return false; } } else if ("setTransparent".equals(action)) { if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) { this.cordova.getActivity().runOnUiThread(new Runnable() { @Override public void run() { window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); } }); return true; } else { return false; } } else if ("setColor".equals(action)) { if (currentapiVersion >= android.os.Build.VERSION_CODES.LOLLIPOP) { this.setColor(args.getInt(0), args.getInt(1), args.getInt(2)); return true; } else { return false; } } return false; }
From source file:com.boox.booxfile.BooxFile.java
License:Apache License
private void getDirectoryForPurpose(final CordovaArgs args, final CallbackContext callbackContext) throws JSONException { int purpose = args.getInt(0); boolean sandboxed = args.getBoolean(1); // boolean syncable = args.getInt(2); String path = null;// w w w .ja va2 s . c o m switch (purpose) { case PURPOSE_DATA: if (sandboxed) { path = cordova.getActivity().getApplicationContext().getFilesDir().getAbsolutePath(); } else { path = cordova.getActivity().getApplicationContext().getExternalFilesDir(null).getAbsolutePath(); } break; case PURPOSE_DOCUMENTS: if (sandboxed) { path = new File(cordova.getActivity().getApplicationContext().getFilesDir(), "Documents") .getAbsolutePath(); } else { path = Environment.getExternalStorageDirectory().getAbsolutePath(); } break; case PURPOSE_CACHE: case PURPOSE_TEMP: if (sandboxed) { path = cordova.getActivity().getApplicationContext().getCacheDir().getAbsolutePath(); } else { path = cordova.getActivity().getApplicationContext().getExternalCacheDir().getAbsolutePath(); } break; } if (path == null) { callbackContext.error("No path found."); return; } callbackContext.success(path); }
From source file:com.emeth.cordova.ble.central.BLECentralPlugin.java
License:Apache License
@Override public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException { LOG.d(TAG, "action = " + action); if (bluetoothAdapter == null) { Activity activity = cordova.getActivity(); BluetoothManager bluetoothManager = (BluetoothManager) activity .getSystemService(Context.BLUETOOTH_SERVICE); bluetoothAdapter = bluetoothManager.getAdapter(); }/*from w w w.ja v a 2s .com*/ boolean validAction = true; if (action.equals(SCAN)) { UUID[] serviceUUIDs = parseServiceUUIDList(args.getJSONArray(0)); int scanSeconds = args.getInt(1); findLowEnergyDevices(callbackContext, serviceUUIDs, scanSeconds); } else if (action.equals(START_SCAN)) { UUID[] serviceUUIDs = parseServiceUUIDList(args.getJSONArray(0)); findLowEnergyDevices(callbackContext, serviceUUIDs, -1); } else if (action.equals(STOP_SCAN)) { bluetoothAdapter.stopLeScan(this); callbackContext.success(); } else if (action.equals(LIST)) { listKnownDevices(callbackContext); } else if (action.equals(CONNECT)) { String macAddress = args.getString(0); connect(callbackContext, macAddress); } else if (action.equals(DISCONNECT)) { String macAddress = args.getString(0); disconnect(callbackContext, macAddress); } else if (action.equals(READ)) { String macAddress = args.getString(0); UUID serviceUUID = uuidFromString(args.getString(1)); UUID characteristicUUID = uuidFromString(args.getString(2)); read(callbackContext, macAddress, serviceUUID, characteristicUUID); } else if (action.equals(WRITE)) { String macAddress = args.getString(0); UUID serviceUUID = uuidFromString(args.getString(1)); UUID characteristicUUID = uuidFromString(args.getString(2)); byte[] data = args.getArrayBuffer(3); int type = BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT; write(callbackContext, macAddress, serviceUUID, characteristicUUID, data, type); } else if (action.equals(WRITE_WITHOUT_RESPONSE)) { String macAddress = args.getString(0); UUID serviceUUID = uuidFromString(args.getString(1)); UUID characteristicUUID = uuidFromString(args.getString(2)); byte[] data = args.getArrayBuffer(3); int type = BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE; write(callbackContext, macAddress, serviceUUID, characteristicUUID, data, type); } else if (action.equals(NOTIFY)) { String macAddress = args.getString(0); UUID serviceUUID = uuidFromString(args.getString(1)); UUID characteristicUUID = uuidFromString(args.getString(2)); registerNotifyCallback(callbackContext, macAddress, serviceUUID, characteristicUUID); } else if (action.equals(IS_ENABLED)) { if (bluetoothAdapter.isEnabled()) { callbackContext.success(); } else { callbackContext.error("Bluetooth is disabled."); } } else if (action.equals(IS_CONNECTED)) { String macAddress = args.getString(0); if (peripherals.containsKey(macAddress) && peripherals.get(macAddress).isConnected()) { callbackContext.success(); } else { callbackContext.error("Not connected."); } } else if (action.equals(SETTINGS)) { Intent intent = new Intent(Settings.ACTION_BLUETOOTH_SETTINGS); cordova.getActivity().startActivity(intent); callbackContext.success(); } else if (action.equals(ENABLE)) { enableBluetoothCallback = callbackContext; Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); cordova.startActivityForResult(this, intent, REQUEST_ENABLE_BLUETOOTH); } else { validAction = false; } return validAction; }
From source file:com.google.cordova.ChromeSocket.java
License:Open Source License
private void connect(CordovaArgs args, final CallbackContext callbackContext) throws JSONException { int socketId = args.getInt(0); String address = args.getString(1); int port = args.getInt(2); SocketData sd = sockets.get(Integer.valueOf(socketId)); if (sd == null) { Log.e(LOG_TAG, "No socket with socketId " + socketId); return;// w w w . jav a 2s . c om } boolean success = sd.connect(address, port); if (success) callbackContext.success(); else callbackContext.error("Failed to connect"); }
From source file:com.google.cordova.ChromeSocket.java
License:Open Source License
private void bind(CordovaArgs args, final CallbackContext context) throws JSONException { int socketId = args.getInt(0); String address = args.getString(1); int port = args.getInt(2); SocketData sd = sockets.get(Integer.valueOf(socketId)); if (sd == null) { Log.e(LOG_TAG, "No socket with socketId " + socketId); return;//from w w w . j a v a 2 s.c om } boolean success = sd.bind(address, port); if (success) context.success(); else context.error("Failed to bind."); }
From source file:com.google.cordova.ChromeSocket.java
License:Open Source License
private void write(CordovaArgs args, final CallbackContext callbackContext) throws JSONException { int socketId = args.getInt(0); byte[] data = args.getArrayBuffer(1); SocketData sd = sockets.get(Integer.valueOf(socketId)); if (sd == null) { Log.e(LOG_TAG, "No socket with socketId " + socketId); return;//from w w w.j a v a 2 s.c o m } int result = sd.write(data); if (result <= 0) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, result)); } else { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }
From source file:com.google.cordova.ChromeSocket.java
License:Open Source License
private void read(CordovaArgs args, final CallbackContext callbackContext) throws JSONException { int socketId = args.getInt(0); int bufferSize = args.getInt(1); SocketData sd = sockets.get(Integer.valueOf(socketId)); if (sd == null) { Log.e(LOG_TAG, "No socket with socketId " + socketId); return;/*from w ww.j ava 2s.c om*/ } // Will call the callback once it has some data. sd.read(bufferSize, callbackContext); }
From source file:com.google.cordova.ChromeSocket.java
License:Open Source License
private void recvFrom(CordovaArgs args, final CallbackContext context) throws JSONException { int socketId = args.getInt(0); int bufferSize = args.getInt(1); SocketData sd = sockets.get(Integer.valueOf(socketId)); if (sd == null) { Log.e(LOG_TAG, "No socket with socketId " + socketId); return;/*from ww w.j av a2 s . c o m*/ } sd.recvFrom(bufferSize, context); }
From source file:com.google.cordova.ChromeSocket.java
License:Open Source License
private void disconnect(CordovaArgs args, final CallbackContext callbackContext) throws JSONException { int socketId = args.getInt(0); SocketData sd = sockets.get(Integer.valueOf(socketId)); if (sd == null) { Log.e(LOG_TAG, "No socket with socketId " + socketId); return;/*from w w w . j a v a2 s . c om*/ } sd.disconnect(); callbackContext.success(); }
From source file:com.google.cordova.ChromeSocket.java
License:Open Source License
private void destroy(CordovaArgs args, final CallbackContext callbackContext) throws JSONException { int socketId = args.getInt(0); SocketData sd = sockets.get(Integer.valueOf(socketId)); if (sd == null) { Log.e(LOG_TAG, "No socket with socketId " + socketId); return;//from w ww. j a v a 2s.c om } sd.destroy(); sockets.remove(Integer.valueOf(socketId)); callbackContext.success(); }