Example usage for com.facebook.react.bridge WritableMap putDouble

List of usage examples for com.facebook.react.bridge WritableMap putDouble

Introduction

In this page you can find the example usage for com.facebook.react.bridge WritableMap putDouble.

Prototype

void putDouble(@NonNull String key, double value);

Source Link

Usage

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);//from 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  w w  w .j av  a 2s  .c  om*/
        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, Object value, WritableMap map) {
    if (value instanceof String) {
        map.putString(key, (String) value);
    }//  w  w w.  j ava  2s.  c  om
    if (value instanceof Integer) {
        map.putInt(key, (Integer) value);
    }
    if (value instanceof Boolean) {
        map.putBoolean(key, (Boolean) value);
    }
    if (value instanceof Double) {
        map.putDouble(key, (Double) value);
    }
    if (value instanceof Date) {
        map.putString(key, formatter.format(value));
    }
    if (value instanceof Map) {
        //noinspection unchecked
        put(key, (Map) value, map);
    }
    if (value instanceof List) {
        put(key, (List) value, map);
    }
}

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  .j av  a2s .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 WritableMap getFormMap(SCFormConfig formConfig) {
    WritableMap params = Arguments.createMap();
    params.putString("id", formConfig.getId());
    params.putString("name", formConfig.getName());
    params.putString("display_name", formConfig.getDisplayName());
    params.putString("layer_name", formConfig.getLayerName());
    WritableArray fields = Arguments.createArray();
    // for each field, create a WriteableMap with all the SCFormField params
    for (SCFormField field : formConfig.getFields()) {
        WritableMap fieldMap = Arguments.createMap();
        fieldMap.putString("id", field.getId());
        fieldMap.putString("key", field.getKey());
        fieldMap.putString("label", field.getLabel());
        if (field.isRequired() != null) {
            fieldMap.putBoolean("is_required", field.isRequired());
        }/*ww w  .  j  a va2 s. co m*/
        if (field.getPosition() != null) {
            fieldMap.putInt("order", field.getPosition());
        }
        if (field.getType() != null) {
            fieldMap.putString("type", field.getType());
        }
        if (field.getInitialValue() != null) {
            fieldMap.putString("initial_value", String.valueOf(field.getInitialValue()));
        }
        if (field.getMaximum() != null) {
            fieldMap.putDouble("minimum", Double.valueOf(String.valueOf(field.getMinimum())));
        }
        if (field.getMaximum() != null) {
            fieldMap.putDouble("maximum", Double.valueOf(String.valueOf(field.getMaximum())));
        }
        if (field.isExclusiveMaximum() != null) {
            fieldMap.putBoolean("exclusive_maximum", field.isExclusiveMaximum());
        }
        if (field.isExclusiveMinimum() != null) {
            fieldMap.putBoolean("exclusive_minimum", field.isExclusiveMinimum());
        }
        if (field.isInteger() != null) {
            fieldMap.putBoolean("is_integer", field.isInteger());
        }
        if (field.getMaximumLength() != null) {
            fieldMap.putInt("maximum_length", field.getMaximumLength());
        }
        if (field.getMinimumLength() != null) {
            fieldMap.putInt("minimum_length", field.getMinimumLength());
        }
        if (field.getPattern() != null) {
            fieldMap.putString("pattern", field.getPattern());
        }
        fields.pushMap(fieldMap);
    }
    params.putArray("fields", fields);
    return params;
}

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 {/*from  w  ww.  j  a v  a  2 s.  c  o  m*/
            map.putString(key, value.toString());
        }
    }
    return map;
}

From source file:com.dylanvann.cameraroll.CameraRollManager.java

License:Open Source License

private static boolean putAssetInfo(ContentResolver resolver, Cursor photos, WritableMap asset,
        int mediaTypeIndex, int idIndex, int widthIndex, int heightIndex, int mimeTypeIndex,
        int dateAddedIndex) {
    boolean isVideo = photos.getInt(mediaTypeIndex) == FileColumns.MEDIA_TYPE_VIDEO;
    if (isVideo) {
        // Add the actual source of the video as a property.
        Uri sourceUri = Uri.withAppendedPath(Video.Media.EXTERNAL_CONTENT_URI, photos.getString(idIndex));
        asset.putString("source", sourceUri.toString());
        asset.putString("duration", photos.getString(photos.getColumnIndex(Video.VideoColumns.DURATION)));

        long videoId = photos.getLong(idIndex);
        // Attempt to trigger the MediaScanner to generate the thumbnail before
        // we try to get its uri.
        MediaStore.Video.Thumbnails.getThumbnail(resolver, videoId, Video.Thumbnails.MINI_KIND, null);
        String[] projection = { Video.Thumbnails.DATA, };
        // Get the thumbnail info for this video id.
        Cursor videoThumbnailCursor = resolver.query(Video.Thumbnails.EXTERNAL_CONTENT_URI, projection,
                Video.Thumbnails.VIDEO_ID + "=?", new String[] { String.valueOf(videoId) }, null);
        boolean hasThumb = videoThumbnailCursor != null && videoThumbnailCursor.moveToFirst();
        // If there is no thumbnail then the media will be returned, but with no uri.
        if (hasThumb) {
            int pathIndex = videoThumbnailCursor.getColumnIndex(Video.Thumbnails.DATA);
            String uri = videoThumbnailCursor.getString(pathIndex);
            // Return a url with file:///storage for React Native to use.
            asset.putString("uri", "file://" + uri);
            videoThumbnailCursor.close();
        }//from   ww  w . j a  v  a 2  s  .co m
    } else {
        Uri photoUri = Uri.withAppendedPath(Images.Media.EXTERNAL_CONTENT_URI, photos.getString(idIndex));
        asset.putString("uri", photoUri.toString());
        asset.putString("source", photoUri.toString());
    }

    float width = photos.getInt(widthIndex);
    float height = photos.getInt(heightIndex);
    String mediaType = isVideo ? "video" : "photo";
    asset.putDouble("width", width);
    asset.putDouble("height", height);
    asset.putString("fileName", photos.getString(photos.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME)));
    asset.putString("mimeType", photos.getString(mimeTypeIndex));
    asset.putString("mediaType", mediaType);
    asset.putDouble("creationDate", photos.getLong(dateAddedIndex));
    asset.putString("id", photos.getString(idIndex));
    return true;
}

From source file:com.horcrux.svg.GlyphContext.java

License:Open Source License

public ReadableMap getGlyphFont() {
    String fontFamily = null;//  www.j  a  va2s .c  o m
    float fontSize = DEFAULT_FONT_SIZE;
    boolean fontSizeSet = false;
    String fontWeight = null;
    String fontStyle = null;

    int index = mContextLength - 1;

    for (; index >= 0; index--) {
        ReadableMap font = mFontContext.get(index);

        if (fontFamily == null && font.hasKey("fontFamily")) {
            fontFamily = font.getString("fontFamily");
        }

        if (!fontSizeSet && font.hasKey("fontSize")) {
            fontSize = (float) font.getDouble("fontSize");
            fontSizeSet = true;
        }

        if (fontWeight == null && font.hasKey("fontWeight")) {
            fontWeight = font.getString("fontWeight");
        }
        if (fontStyle == null && font.hasKey("fontStyle")) {
            fontStyle = font.getString("fontStyle");
        }

        if (fontFamily != null && fontSizeSet && fontWeight != null && fontStyle != null) {
            break;
        }
    }

    WritableMap map = Arguments.createMap();
    map.putString("fontFamily", fontFamily);
    map.putDouble("fontSize", fontSize);
    map.putString("fontWeight", fontWeight);
    map.putString("fontStyle", fontStyle);

    return map;
}

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  ava  2 s  .c  o m*/
            map.putString(key, value.toString());
        }
    }
    return map;
}

From source file:com.idehub.Billing.InAppBillingBridge.java

@ReactMethod
public void getProductDetails(final ReadableArray productIds, final Promise promise) {
    if (bp != null) {
        try {/* ww w  . jav a 2s.  c o m*/
            ArrayList<String> productIdList = new ArrayList<>();
            for (int i = 0; i < productIds.size(); i++) {
                productIdList.add(productIds.getString(i));
            }

            List<SkuDetails> details = bp.getPurchaseListingDetails(productIdList);

            if (details != null) {
                WritableArray arr = Arguments.createArray();
                for (SkuDetails detail : details) {
                    if (detail != null) {
                        WritableMap map = Arguments.createMap();

                        map.putString("productId", detail.productId);
                        map.putString("title", detail.title);
                        map.putString("description", detail.description);
                        map.putBoolean("isSubscription", detail.isSubscription);
                        map.putString("currency", detail.currency);
                        map.putDouble("priceValue", detail.priceValue);
                        map.putString("priceText", detail.priceText);
                        arr.pushMap(map);
                    }
                }

                promise.resolve(arr);
            } else {
                promise.reject("Details was not found.");
            }
        } catch (Exception ex) {
            promise.reject("Failure on getting product details: " + ex.getMessage());
        }
    } else {
        promise.reject("Channel is not opened. Call open() on InAppBilling.");
    }
}