Java Code Examples for com.facebook.react.bridge.ReadableArray#getString()
The following examples show how to use
com.facebook.react.bridge.ReadableArray#getString() .
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: ReactAztecManager.java From react-native-aztec with GNU General Public License v2.0 | 6 votes |
@Override public void receiveCommand(final ReactAztecText parent, int commandType, @Nullable ReadableArray args) { Assertions.assertNotNull(parent); if (commandType == COMMAND_NOTIFY_APPLY_FORMAT) { final String format = args.getString(0); Log.d(TAG, String.format("Apply format: %s", format)); parent.applyFormat(format); return; } else if (commandType == mFocusTextInputCommandCode) { parent.requestFocusFromJS(); return; } else if (commandType == mBlurTextInputCommandCode) { parent.clearFocusFromJS(); return; } super.receiveCommand(parent, commandType, args); }
Example 2
Source File: RNPushNotificationHelper.java From react-native-push-notification with MIT License | 5 votes |
public void clearDeliveredNotifications(ReadableArray identifiers) { NotificationManager notificationManager = notificationManager(); for (int index = 0; index < identifiers.size(); index++) { String id = identifiers.getString(index); Log.i(LOG_TAG, "Removing notification with id " + id); notificationManager.cancel(Integer.parseInt(id)); } }
Example 3
Source File: BridgeUtils.java From react-native-mp-android-chart with MIT License | 5 votes |
public static String[] convertToStringArray(ReadableArray readableArray) { String[] array = new String[readableArray.size()]; for (int i = 0; i < readableArray.size(); i++) { if (!ReadableType.String.equals(readableArray.getType(i))) { throw new IllegalArgumentException("Expecting array of strings"); } array[i] = readableArray.getString(i); } return array; }
Example 4
Source File: OptionsHelper.java From react-native-lock with MIT License | 5 votes |
public static ArrayList convertReadableArrayToArray(ReadableArray reactArray) { ArrayList<Object> array = new ArrayList<>(); for (int i=0, size = reactArray.size(); i<size; ++i) { Object object = null; switch (reactArray.getType(i)) { case Array: object = convertReadableArrayToArray(reactArray.getArray(i)); break; case Boolean: object = reactArray.getBoolean(i); break; case Map: object = convertReadableMapToMap(reactArray.getMap(i)); break; case Null: object = null; break; case Number: try { object = reactArray.getDouble(i); } catch (java.lang.ClassCastException e) { object = reactArray.getInt(i); } break; case String: object = reactArray.getString(i); break; default: Log.e(TAG, "Unknown type: " + reactArray.getType(i) + " for index: " + i); } array.add(object); } return array; }
Example 5
Source File: TabbedViewPagerManager.java From react-native-tabbed-view-pager-android with MIT License | 5 votes |
@ReactProp(name = "tabNames") public void setTabNames(TabbedViewPager viewPager, ReadableArray readableArray) { String[] names = new String[readableArray.size()]; for (int i = 0; i < readableArray.size(); i++) { names[i] = readableArray.getString(i); } viewPager.setTabNames(names); }
Example 6
Source File: ActionSheetModule.java From react-native-actionsheet-native with MIT License | 5 votes |
@ReactMethod public void showActionSheetWithOptions(ReadableMap params, Callback callback) { final Activity currentActivity = getCurrentActivity(); if (currentActivity == null || !(currentActivity instanceof ReactFragmentActivity)) { this.callback.invoke(RESULT_ERROR); return; } this.activity = (ReactFragmentActivity) currentActivity; this.callback = callback; int cancelButtonIndex = params.getInt("cancelButtonIndex"); ReadableArray options = params.getArray("options"); List<String> list = new ArrayList<>(options.size()); String cancelButtonName = options.getString(cancelButtonIndex); for (int i = 0; i < options.size(); ++i) { String value = options.getString(i); if (!value.equals(cancelButtonName)) { list.add(value); } } String[] args = new String[list.size()]; ActionSheet.createBuilder(context, activity.getSupportFragmentManager()) .setCancelButtonTitle(cancelButtonName) .setOtherButtonTitles(list.toArray(args)) .setCancelableOnTouchOutside(false) .setListener(this).show(); }
Example 7
Source File: SQLitePluginConverter.java From react-native-sqlite-storage with MIT License | 5 votes |
static Object get(ReadableArray array,int index,Object defaultValue){ if (array == null){ return defaultValue; } try { Object value = null; ReadableType type = array.getType(index); switch(type){ case Boolean: value = array.getBoolean(index); break; case Number: value = array.getDouble(index); break; case String: value = array.getString(index); break; case Map: value = array.getMap(index); break; case Array: value = array.getArray(index); break; case Null: break; } return value; } catch (NoSuchKeyException ex){ return defaultValue; } }
Example 8
Source File: ArrayUtil.java From react-native-background-geolocation with Apache License 2.0 | 5 votes |
public static Object[] toArray(ReadableArray readableArray) { Object[] array = new Object[readableArray.size()]; for (int i = 0; i < readableArray.size(); i++) { ReadableType type = readableArray.getType(i); switch (type) { case Null: array[i] = null; break; case Boolean: array[i] = readableArray.getBoolean(i); break; case Number: array[i] = readableArray.getDouble(i); break; case String: array[i] = readableArray.getString(i); break; case Map: array[i] = MapUtil.toMap(readableArray.getMap(i)); break; case Array: array[i] = ArrayUtil.toArray(readableArray.getArray(i)); break; } } return array; }
Example 9
Source File: SQLitePluginConverter.java From react-native-sqlite-storage with MIT License | 5 votes |
/** * Returns the value at {@code index} if it exists, coercing it if * necessary. */ static String getString(ReadableArray array, int index, String defaultValue) { if (array == null){ return defaultValue; } try { ReadableType type = array.getType(index); switch (type) { case Number: double value = array.getDouble(index); if (value == (long) value) { return String.valueOf((long) value); } else { return String.valueOf(value); } case Boolean: return String.valueOf(array.getBoolean(index)); case String: return array.getString(index); case Null: return null; default: return defaultValue; } } catch(NoSuchKeyException ex){ return defaultValue; } }
Example 10
Source File: SQLitePluginConverter.java From react-native-sqlite-storage with MIT License | 5 votes |
static Object get(ReadableArray array,int index,Object defaultValue){ if (array == null){ return defaultValue; } try { Object value = null; ReadableType type = array.getType(index); switch(type){ case Boolean: value = array.getBoolean(index); break; case Number: value = array.getDouble(index); break; case String: value = array.getString(index); break; case Map: value = array.getMap(index); break; case Array: value = array.getArray(index); break; case Null: break; } return value; } catch (NoSuchKeyException ex){ return defaultValue; } }
Example 11
Source File: NetworkingModule.java From react-native-GPay with MIT License | 5 votes |
/** * Extracts the headers from the Array. If the format is invalid, this method will return null. */ private @Nullable Headers extractHeaders( @Nullable ReadableArray headersArray, @Nullable ReadableMap requestData) { if (headersArray == null) { return null; } Headers.Builder headersBuilder = new Headers.Builder(); for (int headersIdx = 0, size = headersArray.size(); headersIdx < size; headersIdx++) { ReadableArray header = headersArray.getArray(headersIdx); if (header == null || header.size() != 2) { return null; } String headerName = header.getString(0); String headerValue = header.getString(1); if (headerName == null || headerValue == null) { return null; } headersBuilder.add(headerName, headerValue); } if (headersBuilder.get(USER_AGENT_HEADER_NAME) == null && mDefaultUserAgent != null) { headersBuilder.add(USER_AGENT_HEADER_NAME, mDefaultUserAgent); } // Sanitize content encoding header, supported only when request specify payload as string boolean isGzipSupported = requestData != null && requestData.hasKey(REQUEST_BODY_KEY_STRING); if (!isGzipSupported) { headersBuilder.removeAll(CONTENT_ENCODING_HEADER_NAME); } return headersBuilder.build(); }
Example 12
Source File: Utils.java From google-signin with MIT License | 5 votes |
@NonNull static Scope[] createScopesArray(ReadableArray scopes) { int size = scopes.size(); Scope[] _scopes = new Scope[size]; for (int i = 0; i < size; i++) { String scopeName = scopes.getString(i); _scopes[i] = new Scope(scopeName); } return _scopes; }
Example 13
Source File: SQLitePluginConverter.java From react-native-sqlite-storage with MIT License | 5 votes |
/** * Returns the value at {@code index} if it exists, coercing it if * necessary. */ static String getString(ReadableArray array, int index, String defaultValue) { if (array == null){ return defaultValue; } try { ReadableType type = array.getType(index); switch (type) { case Number: double value = array.getDouble(index); if (value == (long) value) { return String.valueOf((long) value); } else { return String.valueOf(value); } case Boolean: return String.valueOf(array.getBoolean(index)); case String: return array.getString(index); case Null: return null; default: return defaultValue; } } catch(NoSuchKeyException ex){ return defaultValue; } }
Example 14
Source File: ArrayUtil.java From Instabug-React-Native with MIT License | 5 votes |
public static Object[] toArray(ReadableArray readableArray) { Object[] array = new Object[readableArray.size()]; for (int i = 0; i < readableArray.size(); i++) { ReadableType type = readableArray.getType(i); switch (type) { case Null: array[i] = null; break; case Boolean: array[i] = readableArray.getBoolean(i); break; case Number: array[i] = readableArray.getDouble(i); break; case String: array[i] = readableArray.getString(i); break; case Map: array[i] = MapUtil.toMap(readableArray.getMap(i)); break; case Array: array[i] = ArrayUtil.toArray(readableArray.getArray(i)); break; } } return array; }
Example 15
Source File: ARTTextShadowNode.java From art with MIT License | 4 votes |
@Override public void draw(Canvas canvas, Paint paint, float opacity) { if (mFrame == null) { return; } opacity *= mOpacity; if (opacity <= MIN_OPACITY_FOR_DRAW) { return; } if (!mFrame.hasKey(PROP_LINES)) { return; } ReadableArray linesProp = mFrame.getArray(PROP_LINES); if (linesProp == null || linesProp.size() == 0) { return; } // only set up the canvas if we have something to draw saveAndSetupCanvas(canvas); String[] lines = new String[linesProp.size()]; for (int i = 0; i < lines.length; i++) { lines[i] = linesProp.getString(i); } String text = TextUtils.join("\n", lines); if (setupStrokePaint(paint, opacity)) { applyTextPropertiesToPaint(paint); if (mPath == null) { canvas.drawText(text, 0, -paint.ascent(), paint); } else { canvas.drawTextOnPath(text, mPath, 0, 0, paint); } } if (setupFillPaint(paint, opacity)) { applyTextPropertiesToPaint(paint); if (mPath == null) { canvas.drawText(text, 0, -paint.ascent(), paint); } else { canvas.drawTextOnPath(text, mPath, 0, 0, paint); } } if (mShadowOpacity > 0) { paint.setShadowLayer(mShadowRadius, mShadowOffsetX, mShadowOffsetY, mShadowColor); } restoreCanvas(canvas); markUpdateSeen(); }
Example 16
Source File: ShowOptions.java From react-native-lock with MIT License | 4 votes |
public ShowOptions(@Nullable ReadableMap options) { if (options == null) { return; } if (options.hasKey(CLOSABLE_KEY)) { closable = options.getBoolean(CLOSABLE_KEY); Log.d(TAG, CLOSABLE_KEY + closable); } if (options.hasKey(DISABLE_SIGNUP)) { disableSignUp = options.getBoolean(DISABLE_SIGNUP); Log.d(TAG, DISABLE_SIGNUP + disableSignUp); } if (options.hasKey(DISABLE_RESET_PASSWORD)) { disableResetPassword = options.getBoolean(DISABLE_RESET_PASSWORD); Log.d(TAG, DISABLE_RESET_PASSWORD + disableResetPassword); } if (options.hasKey(USE_MAGIC_LINK_KEY)) { useMagicLink = options.getBoolean(USE_MAGIC_LINK_KEY); Log.d(TAG, USE_MAGIC_LINK_KEY + useMagicLink); } if (options.hasKey(AUTH_PARAMS_KEY)) { ReadableMap reactMap = options.getMap(AUTH_PARAMS_KEY); authParams = OptionsHelper.convertReadableMapToMap(reactMap); Log.d(TAG, AUTH_PARAMS_KEY + authParams); } if (options.hasKey(CONNECTIONS_KEY)) { ReadableArray connections = options.getArray(CONNECTIONS_KEY); List<String> list = new ArrayList<>(connections.size()); for (int i = 0; i < connections.size(); i++) { String connectionName = connections.getString(i); switch (connectionName) { case LockReactModule.CONNECTION_EMAIL: connectionType = LockReactModule.CONNECTION_EMAIL; break; case LockReactModule.CONNECTION_SMS: connectionType = LockReactModule.CONNECTION_SMS; break; } list.add(connectionName); } this.connections = new String[list.size()]; this.connections = list.toArray(this.connections); Log.d(TAG, CONNECTIONS_KEY + list); } }
Example 17
Source File: ReactChatInputManager.java From aurora-imui with MIT License | 4 votes |
@ReactProp(name = "customLayoutItems") public void setCustomItems(ChatInputView chatInputView, ReadableMap map) { ReadableArray left = map.hasKey("left") ? map.getArray("left") : null; ReadableArray right = map.hasKey("right") ? map.getArray("right") : null; ReadableArray bottom = map.hasKey("bottom") ? map.getArray("bottom") : null; String[] bottomTags = new String[0]; if (bottom != null && bottom.size()>1) { bottomTags = new String[bottom.size()]; for (int i = 0; i < bottom.size(); i++) { bottomTags[i] = bottom.getString(i); } mInitialChatInputHeight = 100; }else { mInitialChatInputHeight = 56; } String[] leftTags = new String[0]; if (left != null) { leftTags = new String[left.size()]; for (int i = 0; i < left.size(); i++) { leftTags[i] = left.getString(i); } } String[] rightTags = new String[0]; if (right != null) { rightTags = new String[right.size()]; for (int i = 0; i < right.size(); i++) { rightTags[i] = right.getString(i); } } mChatInput.getMenuManager() .setMenu(Menu.newBuilder() .customize(true) .setLeft(leftTags) .setRight(rightTags) .setBottom(bottomTags) .build()); }
Example 18
Source File: RNPromptModule.java From react-native-prompt-android with MIT License | 4 votes |
@ReactMethod public void promptWithArgs(ReadableMap options, final Callback callback) { final FragmentManagerHelper fragmentManagerHelper = getFragmentManagerHelper(); if (fragmentManagerHelper == null) { FLog.w(RNPromptModule.class, "Tried to show an alert while not attached to an Activity"); return; } final Bundle args = new Bundle(); if (options.hasKey(KEY_TITLE)) { args.putString(RNPromptFragment.ARG_TITLE, options.getString(KEY_TITLE)); } if (options.hasKey(KEY_MESSAGE)) { String message = options.getString(KEY_MESSAGE); if (!message.isEmpty()) { args.putString(RNPromptFragment.ARG_MESSAGE, options.getString(KEY_MESSAGE)); } } if (options.hasKey(KEY_BUTTON_POSITIVE)) { args.putString(RNPromptFragment.ARG_BUTTON_POSITIVE, options.getString(KEY_BUTTON_POSITIVE)); } if (options.hasKey(KEY_BUTTON_NEGATIVE)) { args.putString(RNPromptFragment.ARG_BUTTON_NEGATIVE, options.getString(KEY_BUTTON_NEGATIVE)); } if (options.hasKey(KEY_BUTTON_NEUTRAL)) { args.putString(RNPromptFragment.ARG_BUTTON_NEUTRAL, options.getString(KEY_BUTTON_NEUTRAL)); } if (options.hasKey(KEY_ITEMS)) { ReadableArray items = options.getArray(KEY_ITEMS); CharSequence[] itemsArray = new CharSequence[items.size()]; for (int i = 0; i < items.size(); i++) { itemsArray[i] = items.getString(i); } args.putCharSequenceArray(RNPromptFragment.ARG_ITEMS, itemsArray); } if (options.hasKey(KEY_CANCELABLE)) { args.putBoolean(KEY_CANCELABLE, options.getBoolean(KEY_CANCELABLE)); } if (options.hasKey(KEY_TYPE)) { args.putString(KEY_TYPE, options.getString(KEY_TYPE)); } if (options.hasKey(KEY_STYLE)) { args.putString(KEY_STYLE, options.getString(KEY_STYLE)); } if (options.hasKey(KEY_DEFAULT_VALUE)) { args.putString(KEY_DEFAULT_VALUE, options.getString(KEY_DEFAULT_VALUE)); } if (options.hasKey(KEY_PLACEHOLDER)) { args.putString(KEY_PLACEHOLDER, options.getString(KEY_PLACEHOLDER)); } fragmentManagerHelper.showNewAlert(mIsInForeground, args, callback); }
Example 19
Source File: CustomTwilioVideoViewManager.java From react-native-twilio-video-webrtc with MIT License | 4 votes |
@Override public void receiveCommand(CustomTwilioVideoView view, int commandId, @Nullable ReadableArray args) { switch (commandId) { case CONNECT_TO_ROOM: String roomName = args.getString(0); String accessToken = args.getString(1); boolean enableAudio = args.getBoolean(2); boolean enableVideo = args.getBoolean(3); boolean enableRemoteAudio = args.getBoolean(4); view.connectToRoomWrapper(roomName, accessToken, enableAudio, enableVideo, enableRemoteAudio); break; case DISCONNECT: view.disconnect(); break; case SWITCH_CAMERA: view.switchCamera(); break; case TOGGLE_VIDEO: Boolean videoEnabled = args.getBoolean(0); view.toggleVideo(videoEnabled); break; case TOGGLE_SOUND: Boolean audioEnabled = args.getBoolean(0); view.toggleAudio(audioEnabled); break; case GET_STATS: view.getStats(); break; case DISABLE_OPENSL_ES: view.disableOpenSLES(); break; case TOGGLE_SOUND_SETUP: Boolean speaker = args.getBoolean(0); view.toggleSoundSetup(speaker); break; case TOGGLE_REMOTE_SOUND: Boolean remoteAudioEnabled = args.getBoolean(0); view.toggleRemoteAudio(remoteAudioEnabled); break; case RELEASE_RESOURCE: view.releaseResource(); break; case TOGGLE_BLUETOOTH_HEADSET: Boolean headsetEnabled = args.getBoolean(0); view.toggleBluetoothHeadset(headsetEnabled); break; case SEND_STRING: view.sendString(args.getString(0)); break; } }
Example 20
Source File: SQLiteManager.java From react-native-android-sqlite with MIT License | 4 votes |
public WritableArray query(final String sql, final ReadableArray values) { WritableArray data = Arguments.createArray(); // FLog.w(ReactConstants.TAG, "values.size()=%s", Integer.toString(values.size())); String[] args = new String[values.size()]; // FLog.w(ReactConstants.TAG, "sqlitemanager.query.args.length=%d", args.length); for ( int i=0; i < values.size(); i++) { if (values.getType(i) == ReadableType.Number) { args[i] = Integer.toString(values.getInt(i)); } else { args[i] = values.getString(i); } } Cursor cursor = db.rawQuery(sql, args); try { if (cursor.moveToFirst()) { do { WritableMap item = Arguments.createMap(); for (int i=0; i < cursor.getColumnCount(); i++) { switch( cursor.getType(i) ) { case Cursor.FIELD_TYPE_INTEGER: item.putInt(cursor.getColumnName(i), cursor.getInt(i)); break; default: item.putString(cursor.getColumnName(i), cursor.getString(i)); break; } } data.pushMap(item); } while (cursor.moveToNext()); } } catch (Exception e) { throw e; } finally { cursor.close(); } return data; }