use of com.facebook.react.bridge.WritableNativeArray in project react-native-google-places by tolu360.
the class RNGooglePlacesModule method propertiesMapForPlace.
private WritableMap propertiesMapForPlace(Place place, List<Place.Field> selectedFields) {
// Display attributions if required.
// CharSequence attributions = place.getAttributions();
WritableMap map = Arguments.createMap();
if (selectedFields.contains(Place.Field.LAT_LNG)) {
WritableMap locationMap = Arguments.createMap();
locationMap.putDouble("latitude", place.getLatLng().latitude);
locationMap.putDouble("longitude", place.getLatLng().longitude);
map.putMap("location", locationMap);
}
if (selectedFields.contains(Place.Field.NAME)) {
map.putString("name", place.getName());
}
if (selectedFields.contains(Place.Field.ADDRESS)) {
if (!TextUtils.isEmpty(place.getAddress())) {
map.putString("address", place.getAddress());
} else {
map.putString("address", "");
}
}
if (selectedFields.contains(Place.Field.ADDRESS_COMPONENTS)) {
if (place.getAddressComponents() != null) {
List<AddressComponent> items = place.getAddressComponents().asList();
WritableNativeArray addressComponents = new WritableNativeArray();
for (AddressComponent item : items) {
WritableMap addressComponentMap = Arguments.createMap();
addressComponentMap.putArray("types", Arguments.fromList(item.getTypes()));
addressComponentMap.putString("name", item.getName());
addressComponentMap.putString("shortName", item.getShortName());
addressComponents.pushMap(addressComponentMap);
}
map.putArray("addressComponents", addressComponents);
} else {
WritableArray emptyResult = Arguments.createArray();
map.putArray("addressComponents", emptyResult);
}
}
if (selectedFields.contains(Place.Field.PHONE_NUMBER)) {
if (!TextUtils.isEmpty(place.getPhoneNumber())) {
map.putString("phoneNumber", place.getPhoneNumber());
} else {
map.putString("phoneNumber", "");
}
}
if (selectedFields.contains(Place.Field.WEBSITE_URI)) {
if (null != place.getWebsiteUri()) {
map.putString("website", place.getWebsiteUri().toString());
} else {
map.putString("website", "");
}
}
if (selectedFields.contains(Place.Field.ID)) {
map.putString("placeID", place.getId());
}
if (place.getAttributions() != null) {
List<String> attributions = new ArrayList<>(place.getAttributions());
map.putArray("attributions", Arguments.fromArray(attributions.toArray(new String[0])));
} else {
WritableArray emptyResult = Arguments.createArray();
map.putArray("attributions", emptyResult);
}
if (selectedFields.contains(Place.Field.TYPES)) {
if (place.getTypes() != null) {
List<String> types = new ArrayList<>();
for (Place.Type placeType : place.getTypes()) {
types.add(RNGooglePlacesPlaceTypeMapper.getTypeSlug(placeType));
}
map.putArray("types", Arguments.fromArray(types.toArray(new String[0])));
} else {
WritableArray emptyResult = Arguments.createArray();
map.putArray("types", emptyResult);
}
}
if (selectedFields.contains(Place.Field.VIEWPORT)) {
if (place.getViewport() != null) {
WritableMap viewportMap = Arguments.createMap();
viewportMap.putDouble("latitudeNE", place.getViewport().northeast.latitude);
viewportMap.putDouble("longitudeNE", place.getViewport().northeast.longitude);
viewportMap.putDouble("latitudeSW", place.getViewport().southwest.latitude);
viewportMap.putDouble("longitudeSW", place.getViewport().southwest.longitude);
map.putMap("viewport", viewportMap);
} else {
WritableMap emptyResult = Arguments.createMap();
map.putMap("viewport", emptyResult);
}
}
if (selectedFields.contains(Place.Field.PRICE_LEVEL)) {
if (place.getPriceLevel() != null) {
map.putInt("priceLevel", place.getPriceLevel());
} else {
map.putInt("priceLevel", 0);
}
}
if (selectedFields.contains(Place.Field.RATING)) {
if (place.getRating() != null) {
map.putDouble("rating", place.getRating());
} else {
map.putDouble("rating", 0);
}
}
if (selectedFields.contains(Place.Field.OPENING_HOURS)) {
if (place.getOpeningHours() != null) {
List<String> openingHours = new ArrayList<>(place.getOpeningHours().getWeekdayText());
map.putArray("openingHours", Arguments.fromArray(openingHours.toArray(new String[0])));
} else {
WritableArray emptyResult = Arguments.createArray();
map.putArray("openingHours", emptyResult);
}
}
if (selectedFields.contains(Place.Field.PLUS_CODE)) {
if (place.getPlusCode() != null) {
WritableMap plusCodeMap = Arguments.createMap();
plusCodeMap.putString("compoundCode", place.getPlusCode().getCompoundCode());
plusCodeMap.putString("globalCode", place.getPlusCode().getGlobalCode());
map.putMap("plusCode", plusCodeMap);
} else {
WritableMap emptyResult = Arguments.createMap();
map.putMap("plusCode", emptyResult);
}
}
if (selectedFields.contains(Place.Field.USER_RATINGS_TOTAL)) {
if (place.getUserRatingsTotal() != null) {
map.putInt("userRatingsTotal", place.getUserRatingsTotal());
} else {
map.putInt("userRatingsTotal", 0);
}
}
return map;
}
use of com.facebook.react.bridge.WritableNativeArray in project react-native-charts-wrapper by wuxudong.
the class EntryToWritableMapUtils method convertEntryToWritableMap.
public static WritableMap convertEntryToWritableMap(Entry entry) {
if (entry == null) {
return null;
}
WritableMap map = new WritableNativeMap();
if (entry.getData() instanceof Map) {
map.putMap("data", convertMapToWritableMap((Map) entry.getData()));
}
if (entry instanceof BarEntry) {
BarEntry barEntry = (BarEntry) entry;
map.putDouble("x", entry.getX());
if (barEntry.getYVals() != null) {
WritableArray array = new WritableNativeArray();
for (float f : barEntry.getYVals()) {
array.pushDouble(f);
}
map.putArray("yValues", array);
} else {
map.putDouble("y", entry.getY());
}
} else if (entry instanceof BubbleEntry) {
BubbleEntry bubbleEntry = (BubbleEntry) entry;
map.putDouble("x", entry.getX());
map.putDouble("y", entry.getY());
map.putDouble("size", bubbleEntry.getSize());
} else if (entry instanceof CandleEntry) {
CandleEntry candleEntry = (CandleEntry) entry;
map.putDouble("x", entry.getX());
map.putDouble("open", candleEntry.getOpen());
map.putDouble("close", candleEntry.getClose());
map.putDouble("low", candleEntry.getLow());
map.putDouble("high", candleEntry.getHigh());
} else if (entry instanceof PieEntry) {
PieEntry pieEntry = (PieEntry) entry;
map.putDouble("value", pieEntry.getValue());
map.putString("label", pieEntry.getLabel());
} else if (entry instanceof RadarEntry) {
RadarEntry radarEntry = (RadarEntry) entry;
map.putDouble("value", radarEntry.getValue());
} else {
map.putDouble("x", entry.getX());
map.putDouble("y", entry.getY());
}
return map;
}
use of com.facebook.react.bridge.WritableNativeArray in project react-native-zebra-bluetooth-printer by anmoljain10.
the class RNZebraBluetoothPrinterModule method pairedDevices.
@ReactMethod
public void pairedDevices(final Promise promise) {
this.context = getCurrentActivity();
if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
promise.reject("BT NOT ENABLED");
} else {
Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
List<String> deviceName = new ArrayList<String>();
List<String> deviceAddress = new ArrayList<String>();
List<Integer> ble = new ArrayList<Integer>();
try {
WritableArray app_list = new WritableNativeArray();
for (BluetoothDevice bt : pairedDevices) {
// get class of bluetooth device
BluetoothClass bluetoothClass = bt.getBluetoothClass();
WritableMap info = new WritableNativeMap();
info.putString("address", bt.getAddress());
// 1664
info.putDouble("class", bluetoothClass.getDeviceClass());
info.putString("name", bt.getName());
info.putString("type", "paired");
app_list.pushMap(info);
}
promise.resolve(app_list);
} catch (Exception e) {
promise.reject(E_LAYOUT_ERROR, e);
}
}
}
use of com.facebook.react.bridge.WritableNativeArray in project react-native-google-cast by react-native-google-cast.
the class RNGCDevice method toJson.
@Nullable
public static WritableMap toJson(@Nullable final CastDevice device) {
if (device == null)
return null;
final WritableMap json = new WritableNativeMap();
final WritableArray capabilities = new WritableNativeArray();
if (device.hasCapability(CastDevice.CAPABILITY_AUDIO_IN)) {
capabilities.pushString("AudioIn");
}
if (device.hasCapability(CastDevice.CAPABILITY_AUDIO_OUT)) {
capabilities.pushString("AudioOut");
}
if (device.hasCapability(CastDevice.CAPABILITY_VIDEO_IN)) {
capabilities.pushString("VideoIn");
}
if (device.hasCapability(CastDevice.CAPABILITY_VIDEO_OUT)) {
capabilities.pushString("VideoOut");
}
if (device.hasCapability(CastDevice.CAPABILITY_MULTIZONE_GROUP)) {
capabilities.pushString("MultizoneGroup");
}
json.putArray("capabilities", capabilities);
json.putString("deviceId", device.getDeviceId());
json.putString("deviceVersion", device.getDeviceVersion());
json.putString("friendlyName", device.getFriendlyName());
WritableArray icons = Arguments.createArray();
if (device.getIcons() != null) {
for (WebImage image : device.getIcons()) {
icons.pushMap(RNGCWebImage.toJson(image));
}
}
json.putArray("icons", icons);
json.putString("ipAddress", device.getInetAddress().toString());
json.putBoolean("isOnLocalNetwork", device.isOnLocalNetwork());
json.putString("modelName", device.getModelName());
return json;
}
use of com.facebook.react.bridge.WritableNativeArray in project react-native-mcuboot by brandbrandnew.
the class McubootModule method list.
@ReactMethod
public void list(String id, Callback failureCallback, Callback successCallback) throws McuMgrException {
BluetoothDevice device = bluetoothAdapter.getRemoteDevice(id);
transport = new McuMgrBleTransport(this.reactContext, device);
imageManager = new ImageManager(transport);
imageManager.list(new McuMgrCallback<McuMgrImageStateResponse>() {
@Override
public void onResponse(@NotNull McuMgrImageStateResponse response) {
WritableArray images = new WritableNativeArray();
if (response.images != null) {
for (McuMgrImageStateResponse.ImageSlot slot : response.images) {
WritableMap map = new WritableNativeMap();
map.putString("image", String.valueOf(slot.image));
byte[] hash = Base64.encode(slot.hash, Base64.DEFAULT);
map.putString("hash", new String(hash));
map.putString("version", slot.version);
WritableArray flags = new WritableNativeArray();
if (slot.active)
flags.pushString("active");
if (slot.confirmed)
flags.pushString("confirmed");
if (slot.pending)
flags.pushString("pending");
if (slot.permanent)
flags.pushString("permanent");
map.putArray("flags", flags);
images.pushMap(map);
}
successCallback.invoke(images);
}
}
@Override
public void onError(@NotNull McuMgrException error) {
failureCallback.invoke(error.toString());
}
});
}
Aggregations