List of usage examples for com.facebook.react.bridge WritableMap putMap
void putMap(@NonNull String key, @Nullable ReadableMap value);
From source file:com.amazonaws.reactnative.core.AWSRNClientMarshaller.java
License:Open Source License
public static WritableMap jsonToReact(final JSONObject jsonObject) throws JSONException { final WritableMap writableMap = Arguments.createMap(); final Iterator iterator = jsonObject.keys(); while (iterator.hasNext()) { final String key = (String) iterator.next(); final Object value = jsonObject.get(key); if (value instanceof Float || value instanceof Double) { writableMap.putDouble(key, jsonObject.getDouble(key)); } else if (value instanceof Number) { writableMap.putInt(key, jsonObject.getInt(key)); } else if (value instanceof String) { writableMap.putString(key, jsonObject.getString(key)); } else if (value instanceof JSONObject) { writableMap.putMap(key, jsonToReact(jsonObject.getJSONObject(key))); } else if (value instanceof JSONArray) { writableMap.putArray(key, jsonToReact(jsonObject.getJSONArray(key))); } else if (value instanceof Boolean) { writableMap.putBoolean(key, jsonObject.getBoolean(key)); } else if (value == JSONObject.NULL) { writableMap.putNull(key);/* www . j a v a 2s . c o m*/ } } return writableMap; }
From source file:com.amazonaws.reactnative.s3.AWSRNS3TransferUtility.java
License:Open Source License
private void subscribe(TransferObserver observer) { observer.setTransferListener(new TransferListener() { @Override//from ww w . j a v a 2s . co m public void onStateChanged(final int id, final TransferState state) { final WritableMap map = Arguments.createMap(); final String uuid = transferIDMap.get(id); final Map<String, Object> req = requestMap.get(uuid); if (!(boolean) req.get(COMPLETIONHANDLER)) { return; } map.putString(REQUESTID, uuid); if (state == TransferState.CANCELED) { map.putString(ERROR, "canceled"); } else if (state == TransferState.FAILED) { map.putString(ERROR, "failed"); } else if (state == TransferState.COMPLETED) { final WritableMap request = Arguments.createMap(); TransferObserver observer = null; try { observer = transferUtility.getTransferById(id); } catch (final AmazonClientException e) { throw e; } request.putString(BUCKET, observer.getBucket()); request.putString(KEY, observer.getKey()); request.putString(LOCATION, observer.getAbsoluteFilePath()); map.putMap(REQUEST, request); removeTransferFromMap(uuid, id); } if ((state.equals(TransferState.CANCELED) || state.equals(TransferState.FAILED) || state.equals(TransferState.COMPLETED)) && (map.hasKey(ERROR) || map.hasKey(REQUEST))) { sendEvent(getReactApplicationContext(), "CompletionHandlerEvent", map); } } @Override public void onProgressChanged(final int id, final long bytesCurrent, final long bytesTotal) { final WritableMap map = Arguments.createMap(); final String uuid = transferIDMap.get(id); final Map<String, Object> req = requestMap.get(uuid); map.putString(TYPE, (String) req.get(TYPE)); map.putString(REQUESTID, uuid); map.putDouble(COMPLETEDUNITCOUNT, (double) bytesCurrent); map.putDouble(TOTALUNITCOUNT, (double) bytesTotal); if (bytesTotal == 0) { map.putDouble(FRACTIONCOMPLETED, 0); } else { map.putDouble(FRACTIONCOMPLETED, ((double) bytesCurrent / (double) bytesTotal)); } sendEvent(getReactApplicationContext(), "ProgressEventUtility", map); } @Override public void onError(final int id, final Exception ex) { final WritableMap map = Arguments.createMap(); final WritableMap errorMap = Arguments.createMap(); final String uuid = transferIDMap.get(id); map.putString(REQUESTID, uuid); errorMap.putString(ERROR, ex.toString()); errorMap.putString(DESCRIPTION, ex.getLocalizedMessage()); errorMap.putInt(CODE, ex.hashCode()); map.putMap(ERROR, errorMap); sendEvent(getReactApplicationContext(), "ProgressEventUtility", map); } }); }
From source file:com.auth0.lock.react.bridge.UserProfileBridge.java
License:Open Source License
private void put(String key, Map<String, Object> map, WritableMap into) { if (map == null || map.isEmpty()) { return;// ww w . j a v a 2 s.co m } final WritableMap writableMap = Arguments.createMap(); for (Map.Entry<String, Object> entry : map.entrySet()) { put(entry.getKey(), entry.getValue(), writableMap); } into.putMap(key, writableMap); }
From source file:com.boundlessgeo.spatialconnect.jsbridge.RNSpatialConnect.java
License:Apache License
private WritableMap writePayloadToMap(WritableMap response, Object value) { if (value instanceof Boolean) { response.putBoolean("payload", (Boolean) value); } else if (value instanceof Integer) { response.putInt("payload", (Integer) value); } else if (value instanceof String) { response.putString("payload", (String) value); } else if (value instanceof HashMap) { // if we upgrade react, we can just `writeMap` instead of having to convert it response.putMap("payload", convertHashMapToMap((Map<String, Object>) value)); }/* w ww . ja va 2 s . c o m*/ return response; }
From source file:com.boundlessgeo.spatialconnect.jsbridge.RNSpatialConnect.java
License:Apache License
private WritableMap convertHashMapToMap(Map<String, Object> hashMap) { WritableMap writableMap = Arguments.createMap(); for (Map.Entry<String, Object> entry : hashMap.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (value == null) { writableMap.putNull(key);// w w w .jav a 2 s .c o m } else if (value instanceof Boolean) { writableMap.putBoolean(key, (Boolean) value); } else if (value instanceof Double) { writableMap.putDouble(key, (Double) value); } else if (value instanceof Integer) { writableMap.putInt(key, (Integer) value); } else if (value instanceof Long) { writableMap.putDouble(key, (Long) value); } else if (value instanceof String) { writableMap.putString(key, (String) value); } else if (value instanceof Map) { writableMap.putMap(key, convertHashMapToMap((Map) value)); } else if (value instanceof List) { writableMap.putArray(key, convertArrayToArrayList((List) value)); } } return writableMap; }
From source file:com.boundlessgeo.spatialconnect.jsbridge.SCBridge.java
License:Apache License
private static WritableMap convertJsonToMap(JSONObject jsonObject) throws JSONException { WritableMap map = new WritableNativeMap(); Iterator<String> iterator = jsonObject.keys(); while (iterator.hasNext()) { String key = iterator.next(); Object value = jsonObject.get(key); if (value instanceof JSONObject) { map.putMap(key, convertJsonToMap((JSONObject) value)); } else if (value instanceof JSONArray) { map.putArray(key, convertJsonToArray((JSONArray) value)); } else if (value instanceof Boolean) { map.putBoolean(key, (Boolean) value); } else if (value instanceof Integer) { map.putInt(key, (Integer) value); } else if (value instanceof Double) { map.putDouble(key, (Double) value); } else if (value instanceof String) { map.putString(key, (String) value); } else {// w ww. ja va 2 s . c om map.putString(key, value.toString()); } } return map; }
From source file:com.dylanvann.cameraroll.CameraRollManager.java
License:Open Source License
private static void putPageInfo(Cursor photos, WritableMap response, int limit) { WritableMap pageInfo = new WritableNativeMap(); pageInfo.putBoolean("has_next_page", limit < photos.getCount()); if (limit < photos.getCount()) { photos.moveToPosition(limit - 1); pageInfo.putString("end_cursor", photos.getString(photos.getColumnIndex(FileColumns.DATE_MODIFIED))); }//from w w w . j av a 2s . co m response.putMap("page_info", pageInfo); }
From source file:com.geniem.rnble.RNBLEModule.java
License:Open Source License
@ReactMethod public void disconnect(final String peripheralUuid) { Log.d(TAG, "disconnect"); WritableMap params = Arguments.createMap(); params.putString("peripheralUuid", peripheralUuid); stopReadWriteThread();//w w w . j a va 2s .c om if (bluetoothGatt == null) { Log.w(TAG, "Bluetoothgatt already closed"); WritableMap error = Arguments.createMap(); error.putInt("erroCode", -1); error.putString("errorMessage", "BluetoothGatt closed."); params.putMap("error", error); } else { Log.d(TAG, "BluetoothGatt disconnect"); bluetoothGatt.disconnect(); } connectionState = STATE_DISCONNECTED; this.sendEvent("ble.disconnect.", params); }
From source file:com.geniem.rnble.RNBLEModule.java
License:Open Source License
@ReactMethod public void connect(final String peripheralUuid) { //in android peripheralUuid is the mac address of the BLE device Log.d(TAG, "RNBLE Connect called"); if (bluetoothAdapter == null || peripheralUuid == null) { Log.w(TAG, "BluetoothAdapter not initialized or unspecified peripheralUuid."); WritableMap error = Arguments.createMap(); error.putInt("erroCode", -1); error.putString("errorMessage", "BluetoothAdapter not initialized or unspecified peripheralUuid."); WritableMap params = Arguments.createMap(); params.putString("peripheralUuid", peripheralUuid); params.putMap("error", error); this.sendEvent("ble.connect", params); return;// w w w .jav a 2 s . c o m } // Previously connected device. Try to reconnect. /* if (bluetoothDeviceAddress != null && peripheralUuid.equalsIgnoreCase(bluetoothDeviceAddress) && bluetoothGatt != null) { Log.d(TAG, "Trying to use an existing bluetoothGatt for connection."); if (bluetoothGatt.connect()) { connectionState = STATE_CONNECTING; return; } } */ final BluetoothDevice device = bluetoothAdapter.getRemoteDevice(peripheralUuid); if (device == null) { Log.w(TAG, "Device not found. Unable to connect."); connectionState = STATE_DISCONNECTED; WritableMap error = Arguments.createMap(); error.putInt("erroCode", -2); error.putString("errorMessage", "Device not found. Unable to connect."); WritableMap params = Arguments.createMap(); params.putString("peripheralUuid", peripheralUuid); params.putMap("error", error); this.sendEvent("ble.connect", params); return; } bluetoothGatt = device.connectGatt(context, false, gattCallback); Log.d(TAG, "Trying to create a new connection."); bluetoothDeviceAddress = peripheralUuid; connectionState = STATE_CONNECTING; }
From source file:com.ibatimesheet.RNJSONUtils.java
License:Apache License
public static WritableMap convertJsonToMap(JSONObject jsonObject) throws JSONException { WritableMap map = new WritableNativeMap(); Iterator<String> iterator = jsonObject.keys(); while (iterator.hasNext()) { String key = iterator.next(); Object value = jsonObject.get(key); if (value instanceof JSONObject) { map.putMap(key, convertJsonToMap((JSONObject) value)); } else if (value instanceof JSONArray) { map.putArray(key, convertJsonToArray((JSONArray) value)); } else if (value instanceof Boolean) { map.putBoolean(key, (Boolean) value); } else if (value instanceof Integer) { map.putInt(key, (Integer) value); } else if (value instanceof Double) { map.putDouble(key, (Double) value); } else if (value instanceof String) { map.putString(key, (String) value); } else {/*from w w w .j a v a 2s. co m*/ map.putString(key, value.toString()); } } return map; }