Java Code Examples for com.facebook.react.bridge.ReadableType#Map
The following examples show how to use
com.facebook.react.bridge.ReadableType#Map .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StackTraceHelper.java From react-native-GPay with MIT License | 6 votes |
/** * Convert a JavaScript stack trace (see {@code parseErrorStack} JS module) to an array of * {@link StackFrame}s. */ public static StackFrame[] convertJsStackTrace(@Nullable ReadableArray stack) { int size = stack != null ? stack.size() : 0; StackFrame[] result = new StackFrame[size]; for (int i = 0; i < size; i++) { ReadableType type = stack.getType(i); if (type == ReadableType.Map) { ReadableMap frame = stack.getMap(i); String methodName = frame.getString("methodName"); String fileName = frame.getString("file"); int lineNumber = -1; if (frame.hasKey(LINE_NUMBER_KEY) && !frame.isNull(LINE_NUMBER_KEY)) { lineNumber = frame.getInt(LINE_NUMBER_KEY); } int columnNumber = -1; if (frame.hasKey(COLUMN_KEY) && !frame.isNull(COLUMN_KEY)) { columnNumber = frame.getInt(COLUMN_KEY); } result[i] = new StackFrameImpl(fileName, methodName, lineNumber, columnNumber); } else if (type == ReadableType.String) { result[i] = new StackFrameImpl(null, stack.getString(i), -1, -1); } } return result; }
Example 2
Source File: RNAppAuthModule.java From react-native-app-auth with MIT License | 5 votes |
private void parseHeaderMap (ReadableMap headerMap) { if (headerMap == null) { return; } if (headerMap.hasKey("register") && headerMap.getType("register") == ReadableType.Map) { this.registrationRequestHeaders = MapUtil.readableMapToHashMap(headerMap.getMap("register")); } if (headerMap.hasKey("authorize") && headerMap.getType("authorize") == ReadableType.Map) { this.authorizationRequestHeaders = MapUtil.readableMapToHashMap(headerMap.getMap("authorize")); } if (headerMap.hasKey("token") && headerMap.getType("token") == ReadableType.Map) { this.tokenRequestHeaders = MapUtil.readableMapToHashMap(headerMap.getMap("token")); } }
Example 3
Source File: RNMailComposeModule.java From react-native-mail-compose with MIT License | 5 votes |
private void addAttachments(Intent intent, ReadableArray attachments) { if (attachments == null) return; ArrayList<Uri> uris = new ArrayList<>(); for (int i = 0; i < attachments.size(); i++) { if (attachments.getType(i) == ReadableType.Map) { ReadableMap attachment = attachments.getMap(i); if (attachment != null) { byte[] blob = getBlob(attachment, "data"); String text = getString(attachment, "text"); // String mimeType = getString(attachment, "mimeType"); String filename = getString(attachment, "filename"); if (filename == null) { filename = UUID.randomUUID().toString(); } String ext = getString(attachment, "ext"); File tempFile = createTempFile(filename, ext); if (blob != null) { tempFile = writeBlob(tempFile, blob); } else if (text != null) { tempFile = writeText(tempFile, text); } if (tempFile != null) { uris.add(Uri.fromFile(tempFile)); } } } } if (uris.size() > 0) { intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); } }
Example 4
Source File: CheckoutModule.java From react-native-square-reader-sdk with Apache License 2.0 | 4 votes |
static private boolean validateJSCheckoutParams(ReadableMap jsCheckoutParams, StringBuilder paramError) { // check types of all parameters if (!jsCheckoutParams.hasKey("amountMoney") || jsCheckoutParams.getType("amountMoney") != ReadableType.Map) { paramError.append("'amountMoney' is missing or not an object"); return false; } else if (jsCheckoutParams.hasKey("skipReceipt") && jsCheckoutParams.getType("skipReceipt") != ReadableType.Boolean) { paramError.append("'skipReceipt' is not a boolean"); return false; } else if (jsCheckoutParams.hasKey("collectSignature") && jsCheckoutParams.getType("collectSignature") != ReadableType.Boolean) { paramError.append("'collectSignature' is not a boolean"); return false; } else if (jsCheckoutParams.hasKey("allowSplitTender") && jsCheckoutParams.getType("allowSplitTender") != ReadableType.Boolean) { paramError.append("'allowSplitTender' is not a boolean"); return false; } else if (jsCheckoutParams.hasKey("delayCapture") && jsCheckoutParams.getType("delayCapture") != ReadableType.Boolean) { paramError.append("'delayCapture' is not a boolean"); return false; } else if (jsCheckoutParams.hasKey("note") && jsCheckoutParams.getType("note") != ReadableType.String) { paramError.append("'note' is not a string"); return false; } else if (jsCheckoutParams.hasKey("tipSettings") && jsCheckoutParams.getType("tipSettings") != ReadableType.Map) { paramError.append("'tipSettings' is not an object"); return false; } else if (jsCheckoutParams.hasKey("additionalPaymentTypes") && jsCheckoutParams.getType("additionalPaymentTypes") != ReadableType.Array) { paramError.append("'additionalPaymentTypes' is not an array"); return false; } // check amountMoney ReadableMap amountMoney = jsCheckoutParams.getMap("amountMoney"); if (!amountMoney.hasKey("amount") || amountMoney.getType("amount") != ReadableType.Number) { paramError.append("'amount' is not an integer"); return false; } if (amountMoney.hasKey("currencyCode") && amountMoney.getType("currencyCode") != ReadableType.String) { paramError.append("'currencyCode' is not a String"); return false; } if (amountMoney.hasKey("currencyCode")) { try { CurrencyCode.valueOf(amountMoney.getString("currencyCode")); } catch (IllegalArgumentException ex) { paramError.append("failed to parse 'currencyCode'"); return false; } } if (jsCheckoutParams.hasKey("tipSettings")) { // check tipSettings ReadableMap tipSettings = jsCheckoutParams.getMap("tipSettings"); if (tipSettings.hasKey("showCustomTipField") && tipSettings.getType("showCustomTipField") != ReadableType.Boolean) { paramError.append("'showCustomTipField' is not a boolean"); return false; } else if (tipSettings.hasKey("showSeparateTipScreen") && tipSettings.getType("showSeparateTipScreen") != ReadableType.Boolean) { paramError.append("'showSeparateTipScreen' is not a boolean"); return false; } else if (tipSettings.hasKey("tipPercentages") && tipSettings.getType("tipPercentages") != ReadableType.Array) { paramError.append("'tipPercentages' is not an array"); return false; } } return true; }
Example 5
Source File: RNMessageComposeModule.java From react-native-message-compose with MIT License | 4 votes |
private ReadableMap getMap(ReadableMap map, String key) { if (map.hasKey(key) && map.getType(key) == ReadableType.Map) { return map.getMap(key); } return null; }
Example 6
Source File: RNMailComposeModule.java From react-native-mail-compose with MIT License | 4 votes |
private ReadableMap getMap(ReadableMap map, String key) { if (map.hasKey(key) && map.getType(key) == ReadableType.Map) { return map.getMap(key); } return null; }
Example 7
Source File: MusicControlModule.java From react-native-music-control with MIT License | 4 votes |
@ReactMethod synchronized public void setNowPlaying(ReadableMap metadata) { init(); if(artworkThread != null && artworkThread.isAlive()) artworkThread.interrupt(); String title = metadata.hasKey("title") ? metadata.getString("title") : null; String artist = metadata.hasKey("artist") ? metadata.getString("artist") : null; String album = metadata.hasKey("album") ? metadata.getString("album") : null; String genre = metadata.hasKey("genre") ? metadata.getString("genre") : null; String description = metadata.hasKey("description") ? metadata.getString("description") : null; String date = metadata.hasKey("date") ? metadata.getString("date") : null; long duration = metadata.hasKey("duration") ? (long)(metadata.getDouble("duration") * 1000) : 0; int notificationColor = metadata.hasKey("color") ? metadata.getInt("color") : NotificationCompat.COLOR_DEFAULT; String notificationIcon = metadata.hasKey("notificationIcon") ? metadata.getString("notificationIcon") : null; // If a color is supplied, we need to clear the MediaStyle set during init(). // Otherwise, the color will not be used for the notification's background. boolean removeFade = metadata.hasKey("color"); if(removeFade) { nb.setStyle(new MediaStyle()); } RatingCompat rating; if(metadata.hasKey("rating")) { if(ratingType == RatingCompat.RATING_PERCENTAGE) { rating = RatingCompat.newPercentageRating((float)metadata.getDouble("rating")); } else if(ratingType == RatingCompat.RATING_HEART) { rating = RatingCompat.newHeartRating(metadata.getBoolean("rating")); } else if(ratingType == RatingCompat.RATING_THUMB_UP_DOWN) { rating = RatingCompat.newThumbRating(metadata.getBoolean("rating")); } else { rating = RatingCompat.newStarRating(ratingType, (float)metadata.getDouble("rating")); } } else { rating = RatingCompat.newUnratedRating(ratingType); } md.putText(MediaMetadataCompat.METADATA_KEY_TITLE, title); md.putText(MediaMetadataCompat.METADATA_KEY_ARTIST, artist); md.putText(MediaMetadataCompat.METADATA_KEY_ALBUM, album); md.putText(MediaMetadataCompat.METADATA_KEY_GENRE, genre); md.putText(MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION, description); md.putText(MediaMetadataCompat.METADATA_KEY_DATE, date); md.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration); if (android.os.Build.VERSION.SDK_INT > 19) { md.putRating(MediaMetadataCompat.METADATA_KEY_RATING, rating); } nb.setContentTitle(title); nb.setContentText(artist); nb.setContentInfo(album); nb.setColor(notificationColor); notification.setCustomNotificationIcon(notificationIcon); if(metadata.hasKey("artwork")) { String artwork = null; boolean localArtwork = false; if(metadata.getType("artwork") == ReadableType.Map) { artwork = metadata.getMap("artwork").getString("uri"); localArtwork = true; } else { artwork = metadata.getString("artwork"); } final String artworkUrl = artwork; final boolean artworkLocal = localArtwork; artworkThread = new Thread(new Runnable() { @Override public void run() { Bitmap bitmap = loadArtwork(artworkUrl, artworkLocal); if(md != null) { md.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, bitmap); session.setMetadata(md.build()); } if(nb != null) { nb.setLargeIcon(bitmap); notification.show(nb, isPlaying); } artworkThread = null; } }); artworkThread.start(); } else { md.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, null); nb.setLargeIcon(null); } session.setMetadata(md.build()); session.setActive(true); notification.show(nb, isPlaying); }