List of usage examples for com.facebook.react.bridge ReadableMap getDouble
double getDouble(@NonNull String name);
From source file:com.adjust.nativemodule.Adjust.java
License:Open Source License
@ReactMethod public void create(ReadableMap mapConfig) { String environment = null;/* w w w. j a v a 2s.c om*/ String appToken = null; String defaultTracker = null; String processName = null; String sdkPrefix = null; String logLevel = null; boolean eventBufferingEnabled = false; String userAgent = null; boolean sendInBackground = false; boolean shouldLaunchDeeplink = false; double delayStart = 0.0; boolean isLogLevelSuppress = false; // Check for isLogLevelSuppress. if (!mapConfig.isNull("logLevel")) { logLevel = mapConfig.getString("logLevel"); if (logLevel.equals("SUPPRESS")) { isLogLevelSuppress = true; } } // Check for appToken and environment. appToken = mapConfig.getString("appToken"); environment = mapConfig.getString("environment"); final AdjustConfig adjustConfig = new AdjustConfig(getReactApplicationContext(), appToken, environment, isLogLevelSuppress); if (!adjustConfig.isValid()) { return; } // Log level if (!mapConfig.isNull("logLevel")) { logLevel = mapConfig.getString("logLevel"); if (logLevel.equals("VERBOSE")) { adjustConfig.setLogLevel(LogLevel.VERBOSE); } else if (logLevel.equals("DEBUG")) { adjustConfig.setLogLevel(LogLevel.DEBUG); } else if (logLevel.equals("INFO")) { adjustConfig.setLogLevel(LogLevel.INFO); } else if (logLevel.equals("WARN")) { adjustConfig.setLogLevel(LogLevel.WARN); } else if (logLevel.equals("ERROR")) { adjustConfig.setLogLevel(LogLevel.ERROR); } else if (logLevel.equals("ASSERT")) { adjustConfig.setLogLevel(LogLevel.ASSERT); } else if (logLevel.equals("SUPPRESS")) { adjustConfig.setLogLevel(LogLevel.SUPRESS); } else { adjustConfig.setLogLevel(LogLevel.INFO); } } // Event buffering if (!mapConfig.isNull("eventBufferingEnabled")) { eventBufferingEnabled = mapConfig.getBoolean("eventBufferingEnabled"); adjustConfig.setEventBufferingEnabled(eventBufferingEnabled); } // SDK prefix if (!mapConfig.isNull("sdkPrefix")) { sdkPrefix = mapConfig.getString("sdkPrefix"); adjustConfig.setSdkPrefix(sdkPrefix); } // Main process name if (!mapConfig.isNull("processName")) { processName = mapConfig.getString("processName"); adjustConfig.setProcessName(processName); } // Default tracker if (!mapConfig.isNull("defaultTracker")) { defaultTracker = mapConfig.getString("defaultTracker"); adjustConfig.setDefaultTracker(defaultTracker); } // User agent if (!mapConfig.isNull("userAgent")) { userAgent = mapConfig.getString("userAgent"); adjustConfig.setUserAgent(userAgent); } // Background tracking if (!mapConfig.isNull("sendInBackground")) { sendInBackground = mapConfig.getBoolean("sendInBackground"); adjustConfig.setSendInBackground(sendInBackground); } // Launching deferred deep link if (!mapConfig.isNull("shouldLaunchDeeplink")) { shouldLaunchDeeplink = mapConfig.getBoolean("shouldLaunchDeeplink"); this.shouldLaunchDeeplink = shouldLaunchDeeplink; } // Delayed start if (!mapConfig.isNull("delayStart")) { delayStart = mapConfig.getDouble("delayStart"); adjustConfig.setDelayStart(delayStart); } // Attribution callback if (attributionCallback) { adjustConfig.setOnAttributionChangedListener(this); } // Event tracking succeeded callback if (eventTrackingSucceededCallback) { adjustConfig.setOnEventTrackingSucceededListener(this); } // Event tracking failed callback if (eventTrackingFailedCallback) { adjustConfig.setOnEventTrackingFailedListener(this); } // Session tracking succeeded callback if (sessionTrackingSucceededCallback) { adjustConfig.setOnSessionTrackingSucceededListener(this); } // Session tracking failed callback if (sessionTrackingFailedCallback) { adjustConfig.setOnSessionTrackingFailedListener(this); } // Deferred deeplink callback listener if (deferredDeeplinkCallback) { adjustConfig.setOnDeeplinkResponseListener(this); } com.adjust.sdk.Adjust.onCreate(adjustConfig); com.adjust.sdk.Adjust.onResume(); }
From source file:com.adjust.nativemodule.Adjust.java
License:Open Source License
@ReactMethod public void trackEvent(ReadableMap mapEvent) { final String eventToken = mapEvent.getString("eventToken"); final String currency = mapEvent.getString("currency"); final String transactionId = mapEvent.getString("transactionId"); final Map<String, Object> callbackParameters = AdjustUtil.toMap(mapEvent.getMap("callbackParameters")); final Map<String, Object> partnerParameters = AdjustUtil.toMap(mapEvent.getMap("partnerParameters")); AdjustEvent event = new AdjustEvent(eventToken); if (event.isValid()) { if (!mapEvent.isNull("revenue")) { event.setRevenue(mapEvent.getDouble("revenue"), currency); }/*from ww w. j a v a 2s . co m*/ if (null != callbackParameters) { for (Map.Entry<String, Object> entry : callbackParameters.entrySet()) { event.addCallbackParameter(entry.getKey(), entry.getValue().toString()); } } if (null != partnerParameters) { for (Map.Entry<String, Object> entry : partnerParameters.entrySet()) { event.addPartnerParameter(entry.getKey(), entry.getValue().toString()); } } if (null != transactionId) { event.setOrderId(transactionId); } com.adjust.sdk.Adjust.trackEvent(event); } }
From source file:com.adjust.nativemodule.AdjustUtil.java
License:Open Source License
/** * toObject extracts a value from a {@link ReadableMap} by its key, * and returns a POJO representing that object. * //from w w w . j av a 2 s .c o m * @param readableMap The Map to containing the value to be converted * @param key The key for the value to be converted * @return The converted POJO */ private static Object toObject(@Nullable ReadableMap readableMap, String key) { if (readableMap == null) { return null; } Object result = null; ReadableType readableType = readableMap.getType(key); switch (readableType) { case Null: result = null; break; case Boolean: result = readableMap.getBoolean(key); break; case Number: // Can be int or double. double tmp = readableMap.getDouble(key); if (tmp == (int) tmp) { result = (int) tmp; } else { result = tmp; } break; case String: result = readableMap.getString(key); break; case Map: result = toMap(readableMap.getMap(key)); break; case Array: result = toList(readableMap.getArray(key)); break; default: AdjustFactory.getLogger().error("Could not convert object with key: " + key + "."); } return result; }
From source file:com.amazonaws.reactnative.core.AWSRNClientMarshaller.java
License:Open Source License
public static Object toObject(@Nullable ReadableMap readableMap, String key) { if (readableMap == null) { return null; }//from w w w . ja va2 s . c o m Object result; final ReadableType readableType = readableMap.getType(key); switch (readableType) { case Null: result = key; break; case Boolean: result = readableMap.getBoolean(key); break; case Number: // Can be int or double. double tmp = readableMap.getDouble(key); if (tmp == (int) tmp) { result = (int) tmp; } else { result = tmp; } break; case String: result = readableMap.getString(key); break; case Map: result = readableMapToMap(readableMap.getMap(key)); break; case Array: result = readableArrayToList(readableMap.getArray(key)); break; default: throw new IllegalArgumentException("Could not convert object with key: " + key + "."); } return result; }
From source file:com.boundlessgeo.spatialconnect.jsbridge.RNSpatialConnect.java
License:Apache License
private HashMap<String, Object> convertMapToHashMap(ReadableMap readableMap) { HashMap<String, Object> json = new HashMap<>(); ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); while (iterator.hasNextKey()) { String key = iterator.nextKey(); switch (readableMap.getType(key)) { case Null: json.put(key, null);// ww w . ja v a 2 s . c om break; case Boolean: json.put(key, readableMap.getBoolean(key)); break; case Number: json.put(key, readableMap.getDouble(key)); break; case String: json.put(key, readableMap.getString(key)); break; case Map: json.put(key, convertMapToHashMap(readableMap.getMap(key))); break; case Array: json.put(key, convertArrayToArrayList(readableMap.getArray(key))); break; } } return json; }
From source file:com.boundlessgeo.spatialconnect.jsbridge.SCBridge.java
License:Apache License
private static JSONObject convertMapToJson(ReadableMap readableMap) { JSONObject object = new JSONObject(); ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); try {/*ww w . j av a 2 s.c o m*/ while (iterator.hasNextKey()) { String key = iterator.nextKey(); switch (readableMap.getType(key)) { case Null: object.put(key, JSONObject.NULL); break; case Boolean: object.put(key, readableMap.getBoolean(key)); break; case Number: object.put(key, readableMap.getDouble(key)); break; case String: object.put(key, readableMap.getString(key)); break; case Map: object.put(key, convertMapToJson(readableMap.getMap(key))); break; case Array: object.put(key, convertArrayToJson(readableMap.getArray(key))); break; } } } catch (JSONException e) { Log.e(LOG_TAG, "Could not convert to json"); e.printStackTrace(); } return object; }
From source file:com.dylanvann.cameraroll.ImageEditingManager.java
License:Open Source License
/** * Crop an image. If all goes well, the success callback will be called with the file:// URI of * the new image as the only argument. This is a temporary file - consider using * CameraRollManager.saveImageWithTag to save it in the gallery. * * @param uri the MediaStore URI of the image to crop * @param options crop parameters specified as {@code {offset: {x, y}, size: {width, height}}}. * Optionally this also contains {@code {targetSize: {width, height}}}. If this is * specified, the cropped image will be resized to that size. * All units are in pixels (not DPs). * @param success callback to be invoked when the image has been cropped; the only argument that * is passed to this callback is the file:// URI of the new image * @param error callback to be invoked when an error occurs (e.g. can't create file etc.) *//*from ww w .ja v a2 s . c o m*/ @ReactMethod public void cropImage(String uri, ReadableMap options, final Callback success, final Callback error) { ReadableMap offset = options.hasKey("offset") ? options.getMap("offset") : null; ReadableMap size = options.hasKey("size") ? options.getMap("size") : null; if (offset == null || size == null || !offset.hasKey("x") || !offset.hasKey("y") || !size.hasKey("width") || !size.hasKey("height")) { throw new JSApplicationIllegalArgumentException("Please specify offset and size"); } if (uri == null || uri.isEmpty()) { throw new JSApplicationIllegalArgumentException("Please specify a URI"); } CropTask cropTask = new CropTask(getReactApplicationContext(), uri, (int) offset.getDouble("x"), (int) offset.getDouble("y"), (int) size.getDouble("width"), (int) size.getDouble("height"), success, error); if (options.hasKey("displaySize")) { ReadableMap targetSize = options.getMap("displaySize"); cropTask.setTargetSize(targetSize.getInt("width"), targetSize.getInt("height")); } cropTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }
From source file:com.hijridatepicker.HijriDatePickerAndroidModule.java
License:Open Source License
private boolean parseOptionsWithKey(String ARG_KEY, ReadableMap options, Bundle args, Promise promise) { ReadableType argDateType = options.getType(ARG_KEY); if (ReadableType.String.equals(argDateType)) { try {//w ww . j av a 2 s. c om long milliSeconds = 0; milliSeconds = (long) convertHijriDateToGregorianMilliseconds(options.getString(ARG_KEY)); args.putLong(ARG_KEY, milliSeconds); return true; } catch (PatternSyntaxException | IndexOutOfBoundsException | NumberFormatException e) { promise.reject(ERROR_PARSING_OPTIONS, "Exception happened while parsing " + ARG_KEY + " we only accept object of Date or String with the format \"dd-MM-yyyy\" in Hijri"); return false; } } else if (ReadableType.Number.equals(argDateType)) { args.putLong(ARG_KEY, (long) options.getDouble(ARG_KEY)); return true; } else { promise.reject(ERROR_PARSING_OPTIONS, "Exception happened while parsing " + ARG_KEY + " we only accept object of Date or String with the format \"dd-MM-yyyy\" in Hijri"); return false; } }
From source file:com.horcrux.svg.BezierTransformer.java
License:Open Source License
private PointF getPointFromMap(ReadableMap map) { return new PointF((float) map.getDouble("x"), (float) map.getDouble("y")); }
From source file:com.horcrux.svg.GlyphContext.java
License:Open Source License
public ReadableMap getGlyphFont() { String fontFamily = null;//from ww w .j av a 2 s . com 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; }