Example usage for com.facebook.react.bridge WritableArray pushString

List of usage examples for com.facebook.react.bridge WritableArray pushString

Introduction

In this page you can find the example usage for com.facebook.react.bridge WritableArray pushString.

Prototype

void pushString(@Nullable String value);

Source Link

Usage

From source file:co.rewen.statex.StateXModule.java

License:Open Source License

/**
 * Given an array of keys, this returns a map of (key, value) pairs for the keys found, and
 * (key, null) for the keys that haven't been found.
 *///from w w  w  . j a  va 2s. c  om
@ReactMethod
public void multiGet(final ReadableArray keys, final Callback callback) {
    if (keys == null) {
        callback.invoke(AsyncStorageErrorUtil.getInvalidKeyError(null), null);
        return;
    }

    new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
        @Override
        protected void doInBackgroundGuarded(Void... params) {
            if (!ensureDatabase()) {
                callback.invoke(AsyncStorageErrorUtil.getDBError(null), null);
                return;
            }

            String[] columns = { KEY_COLUMN, VALUE_COLUMN };
            HashSet<String> keysRemaining = SetBuilder.newHashSet();
            WritableArray data = Arguments.createArray();
            for (int keyStart = 0; keyStart < keys.size(); keyStart += MAX_SQL_KEYS) {
                int keyCount = Math.min(keys.size() - keyStart, MAX_SQL_KEYS);
                Cursor cursor = mStateXDatabaseSupplier.get().query(TABLE_STATE, columns,
                        AsyncLocalStorageUtil.buildKeySelection(keyCount),
                        AsyncLocalStorageUtil.buildKeySelectionArgs(keys, keyStart, keyCount), null, null,
                        null);
                keysRemaining.clear();
                try {
                    if (cursor.getCount() != keys.size()) {
                        // some keys have not been found - insert them with null into the final array
                        for (int keyIndex = keyStart; keyIndex < keyStart + keyCount; keyIndex++) {
                            keysRemaining.add(keys.getString(keyIndex));
                        }
                    }

                    if (cursor.moveToFirst()) {
                        do {
                            WritableArray row = Arguments.createArray();
                            row.pushString(cursor.getString(0));
                            row.pushString(cursor.getString(1));
                            data.pushArray(row);
                            keysRemaining.remove(cursor.getString(0));
                        } while (cursor.moveToNext());
                    }
                } catch (Exception e) {
                    FLog.w(ReactConstants.TAG, e.getMessage(), e);
                    callback.invoke(AsyncStorageErrorUtil.getError(null, e.getMessage()), null);
                    return;
                } finally {
                    cursor.close();
                }

                for (String key : keysRemaining) {
                    WritableArray row = Arguments.createArray();
                    row.pushString(key);
                    row.pushNull();
                    data.pushArray(row);
                }
                keysRemaining.clear();
            }

            callback.invoke(null, data);
        }
    }.execute();
}

From source file:co.rewen.statex.StateXModule.java

License:Open Source License

/**
 * Returns an array with all keys from the database.
 *///from w  ww  .j  a v  a 2 s. c  o  m
@ReactMethod
public void getAllKeys(final Callback callback) {
    new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
        @Override
        protected void doInBackgroundGuarded(Void... params) {
            if (!ensureDatabase()) {
                callback.invoke(AsyncStorageErrorUtil.getDBError(null), null);
                return;
            }
            WritableArray data = Arguments.createArray();
            String[] columns = { KEY_COLUMN };
            Cursor cursor = mStateXDatabaseSupplier.get().query(TABLE_STATE, columns, null, null, null, null,
                    null);
            try {
                if (cursor.moveToFirst()) {
                    do {
                        data.pushString(cursor.getString(0));
                    } while (cursor.moveToNext());
                }
            } catch (Exception e) {
                FLog.w(ReactConstants.TAG, e.getMessage(), e);
                callback.invoke(AsyncStorageErrorUtil.getError(null, e.getMessage()), null);
                return;
            } finally {
                cursor.close();
            }
            callback.invoke(null, data);
        }
    }.execute();
}

From source file:com.amazonaws.reactnative.core.AWSRNClientMarshaller.java

License:Open Source License

public static WritableArray jsonToReact(final JSONArray jsonArray) throws JSONException {
    final WritableArray writableArray = Arguments.createArray();
    for (int i = 0; i < jsonArray.length(); i++) {
        final Object value = jsonArray.get(i);
        if (value instanceof Float || value instanceof Double) {
            writableArray.pushDouble(jsonArray.getDouble(i));
        } else if (value instanceof Number) {
            writableArray.pushInt(jsonArray.getInt(i));
        } else if (value instanceof String) {
            writableArray.pushString(jsonArray.getString(i));
        } else if (value instanceof Boolean) {
            writableArray.pushBoolean(jsonArray.getBoolean(i));
        } else if (value instanceof JSONObject) {
            writableArray.pushMap(jsonToReact(jsonArray.getJSONObject(i)));
        } else if (value instanceof JSONArray) {
            writableArray.pushArray(jsonToReact(jsonArray.getJSONArray(i)));
        } else if (value == JSONObject.NULL) {
            writableArray.pushNull();/*  ww  w.  jav a  2 s .com*/
        }
    }
    return writableArray;
}

From source file:com.auth0.lock.react.bridge.UserProfileBridge.java

License:Open Source License

private void put(String key, List<?> list, WritableMap into) {
    if (list == null || list.isEmpty()) {
        return;/*from  w w  w .  ja  v  a  2s . co m*/
    }

    final WritableArray array = Arguments.createArray();
    for (Object item : list) {
        if (item instanceof String) {
            array.pushString((String) item);
        }
        if (item instanceof Integer) {
            array.pushInt((Integer) item);
        }
        if (item instanceof Boolean) {
            array.pushBoolean((Boolean) item);
        }
        if (item instanceof Double) {
            array.pushDouble((Double) item);
        }
        if (item instanceof Date) {
            array.pushString(formatter.format(item));
        }
    }
    into.putArray(key, array);
}

From source file:com.boundlessgeo.spatialconnect.jsbridge.RNSpatialConnect.java

License:Apache License

private WritableArray convertArrayToArrayList(List list) {
    WritableArray writableArray = Arguments.createArray();

    if (list.size() < 1) {
        return writableArray;
    }//w  ww  .  j a  v a2s  .c om

    Object firstObject = list.get(0);
    if (firstObject == null) {
        for (int i = 0; i < list.size(); i++) {
            writableArray.pushNull();
        }
    } else if (firstObject instanceof Boolean) {
        for (Object object : list) {
            writableArray.pushBoolean((boolean) object);
        }
    } else if (firstObject instanceof Double) {
        for (Object object : list) {
            writableArray.pushDouble((double) object);
        }
    } else if (firstObject instanceof Integer) {
        for (Object object : list) {
            writableArray.pushInt((int) object);
        }
    } else if (firstObject instanceof Long) {
        for (Object object : list) {
            writableArray.pushDouble((long) object);
        }
    } else if (firstObject instanceof String) {
        for (Object object : list) {
            writableArray.pushString((String) object);
        }
    } else if (firstObject instanceof Map) {
        for (Object object : list) {
            writableArray.pushMap(convertHashMapToMap((Map) object));
        }
    } else if (firstObject instanceof List) {
        for (Object object : list) {
            writableArray.pushArray(convertArrayToArrayList((List) object));
        }
    }

    return writableArray;
}

From source file:com.boundlessgeo.spatialconnect.jsbridge.SCBridge.java

License:Apache License

private static WritableArray convertJsonToArray(JSONArray jsonArray) throws JSONException {
    WritableArray array = new WritableNativeArray();

    for (int i = 0; i < jsonArray.length(); i++) {
        Object value = jsonArray.get(i);
        if (value instanceof JSONObject) {
            array.pushMap(convertJsonToMap((JSONObject) value));
        } else if (value instanceof JSONArray) {
            array.pushArray(convertJsonToArray((JSONArray) value));
        } else if (value instanceof Boolean) {
            array.pushBoolean((Boolean) value);
        } else if (value instanceof Integer) {
            array.pushInt((Integer) value);
        } else if (value instanceof Double) {
            array.pushDouble((Double) value);
        } else if (value instanceof String) {
            array.pushString((String) value);
        } else {/*  w ww .j av a2s  .  co m*/
            array.pushString(value.toString());
        }
    }
    return array;
}

From source file:com.geniem.rnble.RNBLEModule.java

License:Open Source License

@ReactMethod
public void discoverServices(final String peripheralUuid, ReadableArray uuids) {
    Log.d(TAG, "discoverServices");
    WritableArray filteredServiceUuids = Arguments.createArray();

    if (bluetoothGatt != null && this.discoveredServices != null && uuids != null && uuids.size() > 0) {
        //filter discovered services
        for (BluetoothGattService service : this.discoveredServices) {
            String uuid = service.getUuid().toString();
            for (int i = 0; i < uuids.size(); i++) {
                if (uuid.equalsIgnoreCase(uuids.getString(i))) {
                    filteredServiceUuids.pushString(toNobleUuid(uuid));
                }/*from   www.  j  av  a  2  s .  co m*/
            }
        }
    } else if (uuids == null || uuids.size() == 0) {
        //if no uuids are requested return all discovered service uuids
        for (BluetoothGattService service : this.discoveredServices) {
            String uuid = service.getUuid().toString();
            filteredServiceUuids.pushString(toNobleUuid(uuid));
        }
    }

    WritableMap params = Arguments.createMap();
    params.putString("peripheralUuid", peripheralUuid);
    params.putArray("serviceUuids", filteredServiceUuids);

    this.sendEvent("ble.servicesDiscover", params);
}

From source file:com.geniem.rnble.RNBLEModule.java

License:Open Source License

@ReactMethod
public void discoverCharacteristics(final String peripheralUuid, final String serviceUuid,
        ReadableArray characteristicUuids) {
    Log.d(TAG, "discoverCharacteristics");
    WritableArray requestedCharacteristics = Arguments.createArray();
    List<BluetoothGattCharacteristic> filteredCharacteristics = new ArrayList<BluetoothGattCharacteristic>();

    for (BluetoothGattService service : this.discoveredServices) {
        String uuid = service.getUuid().toString();
        //filter requested service
        if (uuid != null && uuid.equalsIgnoreCase(serviceUuid)) {
            List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics();

            //remove characteristics from the characteristics list based on requested characteristicUuids
            if (characteristicUuids != null && characteristicUuids.size() > 0) {
                for (int i = 0; i < characteristicUuids.size(); i++) {
                    Iterator<BluetoothGattCharacteristic> iterator = characteristics.iterator();
                    while (iterator.hasNext()) {
                        BluetoothGattCharacteristic characteristic = iterator.next();
                        if (characteristicUuids.getString(i)
                                .equalsIgnoreCase(characteristic.getUuid().toString())) {
                            filteredCharacteristics.add(characteristic);
                            break;
                        }/*from  w ww .j a  va 2s  .c o  m*/
                    }
                }
            }
            // if no filter uuids given, just pass all
            else {
                Iterator<BluetoothGattCharacteristic> iterator = characteristics.iterator();
                while (iterator.hasNext()) {
                    BluetoothGattCharacteristic characteristic = iterator.next();
                    filteredCharacteristics.add(characteristic);
                }
            }

            //process characteristics
            for (BluetoothGattCharacteristic c : filteredCharacteristics) {
                WritableArray properties = Arguments.createArray();
                int propertyBitmask = c.getProperties();

                if ((propertyBitmask & BluetoothGattCharacteristic.PROPERTY_BROADCAST) != 0) {
                    properties.pushString("boradcast");
                }

                if ((propertyBitmask & BluetoothGattCharacteristic.PROPERTY_READ) != 0) {
                    properties.pushString("read");
                }

                if ((propertyBitmask & BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE) != 0) {
                    properties.pushString("writeWithoutResponse");
                }

                if ((propertyBitmask & BluetoothGattCharacteristic.PROPERTY_WRITE) != 0) {
                    properties.pushString("write");
                }

                if ((propertyBitmask & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0) {
                    properties.pushString("notify");
                }

                if ((propertyBitmask & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0) {
                    properties.pushString("indicaste");
                }

                if ((propertyBitmask & BluetoothGattCharacteristic.PROPERTY_SIGNED_WRITE) != 0) {
                    properties.pushString("authenticatedSignedWrites");
                }

                if ((propertyBitmask & BluetoothGattCharacteristic.PROPERTY_EXTENDED_PROPS) != 0) {
                    properties.pushString("extendedProperties");
                }

                WritableMap characteristicObject = Arguments.createMap();
                characteristicObject.putArray("properties", properties);
                characteristicObject.putString("uuid", toNobleUuid(c.getUuid().toString()));

                requestedCharacteristics.pushMap(characteristicObject);
            }
            break;
        }
    }

    WritableMap params = Arguments.createMap();
    params.putString("peripheralUuid", peripheralUuid);
    params.putString("serviceUuid", toNobleUuid(serviceUuid));
    params.putArray("characteristics", requestedCharacteristics);
    this.sendEvent("ble.characteristicsDiscover", params);
}

From source file:com.geniem.rnble.RNBLEModule.java

License:Open Source License

@ReactMethod
public void discoverDescriptors(final String peripheralUuid, final String serviceUuid,
        final String characteristicUuid) {
    Log.d(TAG, "discover descriptors");
    WritableArray descriptors = Arguments.createArray();

    for (BluetoothGattService service : this.discoveredServices) {
        String uuid = service.getUuid().toString();
        //filter requested service
        if (uuid != null && uuid.equalsIgnoreCase(serviceUuid)) {
            List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics();
            for (BluetoothGattCharacteristic characteristic : characteristics) {
                String cUuid = characteristic.getUuid().toString();
                if (cUuid != null && cUuid.equalsIgnoreCase(characteristicUuid)) {
                    List<BluetoothGattDescriptor> descriptorList = characteristic.getDescriptors();
                    for (BluetoothGattDescriptor descriptor : descriptorList) {
                        descriptors.pushString(descriptor.getUuid().toString());
                    }//from w  w w  .ja  v a2 s. c om
                    break;
                }
            }
            break;
        }
    }

    WritableMap params = Arguments.createMap();
    params.putString("peripheralUuid", peripheralUuid);
    params.putString("serviceUuid", toNobleUuid(serviceUuid));
    params.putString("characteristicUuid", toNobleUuid(characteristicUuid));
    params.putArray("descriptors", descriptors);
    this.sendEvent("ble.descriptorsDiscover", params);
}

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

License:Open Source License

@Override
protected void saveDefinition() {
    if (mName != null) {
        WritableArray points = Arguments.createArray();
        points.pushString(mX1);
        points.pushString(mY1);/* w ww  . j a va  2  s  .c  o  m*/
        points.pushString(mX2);
        points.pushString(mY2);

        Brush brush = new Brush(Brush.BrushType.LINEAR_GRADIENT, points, mGradientUnits);
        brush.setGradientColors(mGradient);

        SvgViewShadowNode svg = getSvgShadowNode();
        if (mGradientUnits == Brush.BrushUnits.USER_SPACE_ON_USE) {
            brush.setUserSpaceBoundingBox(svg.getCanvasBounds());
        }

        svg.defineBrush(brush, mName);
    }
}