Search in sources :

Example 11 with WritableNativeArray

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;
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) AddressComponent(com.google.android.libraries.places.api.model.AddressComponent) WritableArray(com.facebook.react.bridge.WritableArray) ArrayList(java.util.ArrayList) WritableNativeArray(com.facebook.react.bridge.WritableNativeArray) Place(com.google.android.libraries.places.api.model.Place)

Example 12 with WritableNativeArray

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;
}
Also used : BubbleEntry(com.github.mikephil.charting.data.BubbleEntry) RadarEntry(com.github.mikephil.charting.data.RadarEntry) WritableMap(com.facebook.react.bridge.WritableMap) CandleEntry(com.github.mikephil.charting.data.CandleEntry) PieEntry(com.github.mikephil.charting.data.PieEntry) WritableArray(com.facebook.react.bridge.WritableArray) WritableNativeMap(com.facebook.react.bridge.WritableNativeMap) WritableNativeMap(com.facebook.react.bridge.WritableNativeMap) Map(java.util.Map) WritableMap(com.facebook.react.bridge.WritableMap) BarEntry(com.github.mikephil.charting.data.BarEntry) WritableNativeArray(com.facebook.react.bridge.WritableNativeArray)

Example 13 with WritableNativeArray

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);
        }
    }
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) BluetoothDevice(android.bluetooth.BluetoothDevice) WritableArray(com.facebook.react.bridge.WritableArray) WritableNativeMap(com.facebook.react.bridge.WritableNativeMap) ArrayList(java.util.ArrayList) BluetoothClass(android.bluetooth.BluetoothClass) WritableNativeArray(com.facebook.react.bridge.WritableNativeArray) JSONException(org.json.JSONException) ConnectionException(com.zebra.sdk.comm.ConnectionException)

Example 14 with WritableNativeArray

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;
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) WritableNativeMap(com.facebook.react.bridge.WritableNativeMap) WebImage(com.google.android.gms.common.images.WebImage) WritableNativeArray(com.facebook.react.bridge.WritableNativeArray) Nullable(javax.annotation.Nullable)

Example 15 with WritableNativeArray

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());
        }
    });
}
Also used : McuMgrBleTransport(io.runtime.mcumgr.ble.McuMgrBleTransport) WritableMap(com.facebook.react.bridge.WritableMap) BluetoothDevice(android.bluetooth.BluetoothDevice) WritableArray(com.facebook.react.bridge.WritableArray) McuMgrImageStateResponse(io.runtime.mcumgr.response.img.McuMgrImageStateResponse) WritableNativeMap(com.facebook.react.bridge.WritableNativeMap) WritableNativeArray(com.facebook.react.bridge.WritableNativeArray) ImageManager(io.runtime.mcumgr.managers.ImageManager) McuMgrException(io.runtime.mcumgr.exception.McuMgrException) ReactMethod(com.facebook.react.bridge.ReactMethod)

Aggregations

WritableNativeArray (com.facebook.react.bridge.WritableNativeArray)19 WritableArray (com.facebook.react.bridge.WritableArray)18 WritableMap (com.facebook.react.bridge.WritableMap)17 WritableNativeMap (com.facebook.react.bridge.WritableNativeMap)14 ArrayList (java.util.ArrayList)10 Handler (android.os.Handler)7 ReactMethod (com.facebook.react.bridge.ReactMethod)7 AndroidCallbackEvent (com.mapbox.rctmgl.events.AndroidCallbackEvent)3 BluetoothDevice (android.bluetooth.BluetoothDevice)2 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)2 RequestPoint (com.yandex.mapkit.RequestPoint)2 Point (com.yandex.mapkit.geometry.Point)2 Polyline (com.yandex.mapkit.geometry.Polyline)2 VisitorChat (com.zoho.livechat.android.VisitorChat)2 ConversationListener (com.zoho.livechat.android.listeners.ConversationListener)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Activity (android.app.Activity)1 BluetoothClass (android.bluetooth.BluetoothClass)1 SharedPreferences (android.content.SharedPreferences)1