List of usage examples for com.facebook.react.bridge ReadableMap getInt
int getInt(@NonNull String name);
From source file:com.reactlibrary.SGScanditPicker.java
License:Apache License
@Override public void receiveCommand(BarcodePicker view, int commandType, @Nullable final ReadableArray args) { int argCount = args == null ? 0 : args.size(); final WritableMap promiseResponse = Arguments.createMap(); if (argCount > 0) { if (args.getType(args.size() - 1) == ReadableType.Map) { ReadableMap map = args.getMap(args.size() - 1); if (map.hasKey("commandid")) { int commandid = map.getInt("commandid"); promiseResponse.putInt("commandid", commandid); argCount--;// w ww .j a va2s .c om } } } switch (commandType) { case COMMAND_STOP_SCANNING: { picker.stopScanning(); return; } case COMMAND_START_SCANNING: { picker.startScanning(false, new Runnable() { @Override public void run() { new PromiseSender(promiseResponse) { @Override public Object getResponse() { return "Scan started"; } }; } }); return; } case COMMAND_START_SCANNING_IN_PAUSED_STATE: { picker.startScanning(true); return; } case COMMAND_PAUSE_SCANNING: { picker.pauseScanning(); return; } case COMMAND_SET_SETTINGS: { if (argCount > 0) { ReadableMap map = args.getMap(0); setSettings(null, map); new PromiseSender(promiseResponse) { @Override public Object getResponse() { return ScanditBarcodeHelpers.scanSettingsToWritableMap(scanSettings); } }; } else { final int c = argCount; new PromiseSender(promiseResponse) { @Override public Object getResponse() { promiseFailed = true; return "Cannot set null settings" + c; } }; } return; } case COMMAND_GET_SETTINGS: { new PromiseSender(promiseResponse) { @Override public Object getResponse() { return ScanditBarcodeHelpers.scanSettingsToWritableMap(scanSettings); } }; emitSettings(); return; } default: throw new IllegalArgumentException(String.format(Locale.ENGLISH, "Unsupported command %d received by %s.", commandType, getClass().getSimpleName())); } }
From source file:com.shahenlibrary.Trimmer.Trimmer.java
License:Open Source License
public static void compress(String source, ReadableMap options, final Promise promise, final OnCompressVideoListener cb, ThemedReactContext tctx, ReactApplicationContext rctx) { Log.d(LOG_TAG, "OPTIONS: " + options.toString()); Context ctx = tctx != null ? tctx : rctx; ReadableMap videoMetadata = getVideoRequiredMetadata(source, ctx); int videoWidth = videoMetadata.getInt("width"); int videoHeight = videoMetadata.getInt("height"); int videoBitrate = videoMetadata.getInt("bitrate"); int width = options.hasKey("width") ? (int) (options.getDouble("width")) : 0; int height = options.hasKey("height") ? (int) (options.getDouble("height")) : 0; if (width != 0 && height != 0 && videoWidth != 0 && videoHeight != 0) { ReadableMap sizes = formatWidthAndHeightForFfmpeg(width, height, videoWidth, videoHeight); width = sizes.getInt("width"); height = sizes.getInt("height"); }/*from w ww. ja v a2 s .co m*/ Double minimumBitrate = options.hasKey("minimumBitrate") ? options.getDouble("minimumBitrate") : null; Double bitrateMultiplier = options.hasKey("bitrateMultiplier") ? options.getDouble("bitrateMultiplier") : 1.0; Boolean removeAudio = options.hasKey("removeAudio") ? options.getBoolean("removeAudio") : false; Double averageBitrate = videoBitrate / bitrateMultiplier; if (minimumBitrate != null) { if (averageBitrate < minimumBitrate) { averageBitrate = minimumBitrate; } if (videoBitrate < minimumBitrate) { averageBitrate = videoBitrate * 1.0; } } Log.d(LOG_TAG, "getVideoRequiredMetadata: averageBitrate - " + Double.toString(averageBitrate)); final File tempFile = createTempFile("mp4", promise, ctx); ArrayList<String> cmd = new ArrayList<String>(); cmd.add("-y"); cmd.add("-i"); cmd.add(source); cmd.add("-c:v"); cmd.add("libx264"); cmd.add("-b:v"); cmd.add(Double.toString(averageBitrate / 1000) + "K"); cmd.add("-bufsize"); cmd.add(Double.toString(averageBitrate / 2000) + "K"); if (width != 0 && height != 0) { cmd.add("-vf"); cmd.add("scale=" + Integer.toString(width) + ":" + Integer.toString(height)); } cmd.add("-preset"); cmd.add("ultrafast"); cmd.add("-pix_fmt"); cmd.add("yuv420p"); if (removeAudio) { cmd.add("-an"); } cmd.add(tempFile.getPath()); executeFfmpegCommand(cmd, tempFile.getPath(), rctx, promise, "compress error", cb); }
From source file:com.shahenlibrary.Trimmer.Trimmer.java
License:Open Source License
static void crop(String source, ReadableMap options, final Promise promise, ReactApplicationContext ctx) { int cropWidth = (int) (options.getDouble("cropWidth")); int cropHeight = (int) (options.getDouble("cropHeight")); int cropOffsetX = (int) (options.getDouble("cropOffsetX")); int cropOffsetY = (int) (options.getDouble("cropOffsetY")); ReadableMap videoSizes = getVideoRequiredMetadata(source, ctx); int videoWidth = videoSizes.getInt("width"); int videoHeight = videoSizes.getInt("height"); ReadableMap sizes = formatWidthAndHeightForFfmpeg(cropWidth, cropHeight, // NOTE: MUST CHECK AGAINST "CROPPABLE" WIDTH/HEIGHT. NOT FULL WIDTH/HEIGHT videoWidth - cropOffsetX, videoHeight - cropOffsetY); cropWidth = sizes.getInt("width"); cropHeight = sizes.getInt("height"); // TODO: 1) ADD METHOD TO CHECK "IS FFMPEG LOADED". // 2) CHECK IT HERE // 3) EXPORT THAT METHOD TO "JS" final File tempFile = createTempFile("mp4", promise, ctx); ArrayList<String> cmd = new ArrayList<String>(); cmd.add("-y"); // NOTE: OVERWRITE OUTPUT FILE // NOTE: INPUT FILE cmd.add("-i"); cmd.add(source);// www . j a v a 2s . c o m // NOTE: PLACE ARGUMENTS FOR FFMPEG IN THIS ORDER: // 1. "-i" (INPUT FILE) // 2. "-ss" (START TIME) // 3. "-to" (END TIME) or "-t" (TRIM TIME) // OTHERWISE WE WILL LOSE ACCURACY AND WILL GET WRONG CLIPPED VIDEO String startTime = options.getString("startTime"); if (!startTime.equals(null) && !startTime.equals("")) { cmd.add("-ss"); cmd.add(startTime); } String endTime = options.getString("endTime"); if (!endTime.equals(null) && !endTime.equals("")) { cmd.add("-to"); cmd.add(endTime); } cmd.add("-vf"); cmd.add("crop=" + Integer.toString(cropWidth) + ":" + Integer.toString(cropHeight) + ":" + Integer.toString(cropOffsetX) + ":" + Integer.toString(cropOffsetY)); cmd.add("-preset"); cmd.add("ultrafast"); // NOTE: DO NOT CONVERT AUDIO TO SAVE TIME cmd.add("-c:a"); cmd.add("copy"); // NOTE: FLAG TO CONVER "AAC" AUDIO CODEC cmd.add("-strict"); cmd.add("-2"); // NOTE: OUTPUT FILE cmd.add(tempFile.getPath()); executeFfmpegCommand(cmd, tempFile.getPath(), ctx, promise, "Crop error", null); }
From source file:com.silklabs.react.blobs.WebSocketModule.java
License:Open Source License
@ReactMethod public void sendBlob(ReadableMap blob, int id) { WebSocket client = mWebSocketConnections.get(id); if (client == null) { // This is a programmer error throw new RuntimeException("Cannot send a message. Unknown WebSocket id " + id); }// www . ja v a 2 s . c o m byte[] data = BlobModule.resolve(blob.getString("blobId"), blob.getInt("offset"), blob.getInt("size")); try { client.sendMessage(RequestBody.create(WebSocket.BINARY, data)); } catch (IOException | IllegalStateException e) { notifyWebSocketFailed(id, e.getMessage()); } }
From source file:io.github.douglasjunior.ReactNativeEasyBluetooth.core.CoreModule.java
License:Open Source License
public void init(ReadableMap config, Promise promise) { Log.d(TAG, "config: " + config); try {/* ww w .j av a 2 s . com*/ if (!validateBluetoothAdapter(promise)) return; BluetoothConfiguration bluetoothConfig = new BluetoothConfiguration(); bluetoothConfig.context = getReactApplicationContext(); bluetoothConfig.bluetoothServiceClass = mBluetoothServiceClass; bluetoothConfig.deviceName = config.getString("deviceName"); bluetoothConfig.characterDelimiter = config.getString("characterDelimiter").charAt(0); bluetoothConfig.bufferSize = config.getInt("bufferSize"); if (config.hasKey("uuid")) bluetoothConfig.uuid = UUID.fromString(config.getString("uuid")); if (config.hasKey("uuidService")) bluetoothConfig.uuidService = UUID.fromString(config.getString("uuidService")); if (config.hasKey("uuidCharacteristic")) bluetoothConfig.uuidCharacteristic = UUID.fromString(config.getString("uuidCharacteristic")); if (config.hasKey("transport")) bluetoothConfig.transport = config.getInt("transport"); bluetoothConfig.callListenersInMainThread = false; BluetoothService.init(bluetoothConfig); mService = BluetoothService.getDefaultInstance(); mService.setOnScanCallback(this); mService.setOnEventCallback(this); mWriter = new BluetoothWriter(mService); WritableNativeMap returnConfig = new WritableNativeMap(); returnConfig.merge(config); promise.resolve(returnConfig); } catch (Exception ex) { ex.printStackTrace(); promise.reject(ex); } }
From source file:io.tradle.RNBlinkIDModule.java
@ReactMethod public void scan(ReadableMap opts, final Promise promise) { String licenseKey = getString(opts, "licenseKey"); if (licenseKey == null) { licenseKey = this.licenseKey; }//from ww w .j a va 2 s. co m resetForNextScan(); this.scanPromise = promise; this.opts = opts; Activity currentActivity = getCurrentActivity(); Intent intent = new Intent(currentActivity, ScanCard.class); intent.putExtra(ScanCard.EXTRAS_LICENSE_KEY, licenseKey); intent.putExtra(ScanCard.EXTRAS_CAMERA_TYPE, (Parcelable) CameraType.CAMERA_BACKFACE); RecognitionSettings settings = new RecognitionSettings(); RecognizerSettings[] recognizerSettings = getRecognitionSettings(opts); if (!RecognizerCompatibility.cameraHasAutofocus(CameraType.CAMERA_BACKFACE, reactContext)) { int length = recognizerSettings.length; recognizerSettings = RecognizerSettingsUtils .filterOutRecognizersThatRequireAutofocus(recognizerSettings); if (recognizerSettings.length != length) { reject(E_FAILED_NO_AUTOFOCUS); return; } } settings.setRecognizerSettingsArray(recognizerSettings); if (opts.hasKey("timeout")) { settings.setNumMsBeforeTimeout(opts.getInt("timeout")); } intent.putExtra(ScanCard.EXTRAS_RECOGNITION_SETTINGS, settings); // pass implementation of image listener that will obtain document images intent.putExtra(ScanCard.EXTRAS_IMAGE_LISTENER, new MyImageListener()); // pass image metadata settings that specifies which images will be obtained intent.putExtra(ScanCard.EXTRAS_IMAGE_METADATA_SETTINGS, getImageMetadataSettings(opts)); // Starting Activity currentActivity.startActivityForResult(intent, SCAN_REQUEST_CODE); }