Search in sources :

Example 61 with PluginMethod

use of com.getcapacitor.PluginMethod in project capacitor-radar by radarlabs.

the class RadarPlugin method updateTrip.

@PluginMethod
public void updateTrip(PluginCall call) {
    JSObject optionsObj = call.getObject("options");
    JSONObject optionsJson = RadarPlugin.jsonObjectForJSObject(optionsObj);
    if (optionsJson == null) {
        call.reject("options is required");
        return;
    }
    RadarTripOptions options = RadarTripOptions.fromJson(optionsJson);
    RadarTrip.RadarTripStatus status = RadarTrip.RadarTripStatus.UNKNOWN;
    if (call.hasOption("status")) {
        String statusStr = call.getString("status");
        if (statusStr.equals("STARTED") || statusStr.equals("started")) {
            status = RadarTrip.RadarTripStatus.STARTED;
        } else if (statusStr.equals("APPROACHING") || statusStr.equals("approaching")) {
            status = RadarTrip.RadarTripStatus.APPROACHING;
        } else if (statusStr.equals("ARRIVED") || statusStr.equals("arrived")) {
            status = RadarTrip.RadarTripStatus.ARRIVED;
        } else if (statusStr.equals("COMPLETED") || statusStr.equals("completed")) {
            status = RadarTrip.RadarTripStatus.COMPLETED;
        } else if (statusStr.equals("CANCELED") || statusStr.equals("canceled")) {
            status = RadarTrip.RadarTripStatus.CANCELED;
        }
    }
    Radar.updateTrip(options, status, new Radar.RadarTripCallback() {

        @Override
        public void onComplete(@NonNull Radar.RadarStatus status, @Nullable RadarTrip trip, @Nullable RadarEvent[] events) {
            JSObject ret = new JSObject();
            ret.put("status", status.toString());
            if (trip != null) {
                ret.put("trip", RadarPlugin.jsObjectForJSONObject(trip.toJson()));
            }
            if (events != null) {
                ret.put("events", RadarPlugin.jsArrayForArray(events));
            }
            call.resolve(ret);
        }
    });
}
Also used : RadarTripOptions(io.radar.sdk.RadarTripOptions) JSONObject(org.json.JSONObject) RadarEvent(io.radar.sdk.model.RadarEvent) Radar(io.radar.sdk.Radar) JSObject(com.getcapacitor.JSObject) RadarTrip(io.radar.sdk.model.RadarTrip) PluginMethod(com.getcapacitor.PluginMethod)

Example 62 with PluginMethod

use of com.getcapacitor.PluginMethod in project capacitor-radar by radarlabs.

the class RadarPlugin method geocode.

@PluginMethod()
public void geocode(final PluginCall call) throws JSONException {
    if (!call.hasOption("query")) {
        call.reject("query is required");
        return;
    }
    String query = call.getString("query");
    Radar.geocode(query, new Radar.RadarGeocodeCallback() {

        @Override
        public void onComplete(@NotNull Radar.RadarStatus status, @Nullable RadarAddress[] addresses) {
            if (status == Radar.RadarStatus.SUCCESS && addresses != null) {
                JSObject ret = new JSObject();
                ret.put("status", status.toString());
                ret.put("addresses", RadarPlugin.jsArrayForJSONArray(RadarAddress.toJson(addresses)));
                call.resolve(ret);
            } else {
                call.reject(status.toString());
            }
        }
    });
}
Also used : Radar(io.radar.sdk.Radar) JSObject(com.getcapacitor.JSObject) RadarAddress(io.radar.sdk.model.RadarAddress) PluginMethod(com.getcapacitor.PluginMethod)

Example 63 with PluginMethod

use of com.getcapacitor.PluginMethod in project capacitor-radar by radarlabs.

the class RadarPlugin method getDistance.

@PluginMethod()
public void getDistance(final PluginCall call) throws JSONException {
    Radar.RadarRouteCallback callback = new Radar.RadarRouteCallback() {

        @Override
        public void onComplete(@NotNull Radar.RadarStatus status, @Nullable RadarRoutes routes) {
            if (status == Radar.RadarStatus.SUCCESS && routes != null) {
                JSObject ret = new JSObject();
                ret.put("status", status.toString());
                ret.put("points", RadarPlugin.jsObjectForJSONObject(routes.toJson()));
                call.resolve(ret);
            } else {
                call.reject(status.toString());
            }
        }
    };
    if (!call.hasOption("destination")) {
        call.reject("destination is required");
        return;
    }
    JSObject destinationObj = call.getObject("destination");
    double destinationLatitude = destinationObj.getDouble("latitude");
    double destinationLongitude = destinationObj.getDouble("longitude");
    Location destination = new Location("RadarSDK");
    destination.setLatitude(destinationLatitude);
    destination.setLongitude(destinationLongitude);
    destination.setAccuracy(5);
    if (!call.hasOption("modes")) {
        call.reject("modes is required");
        return;
    }
    EnumSet<Radar.RadarRouteMode> modes = EnumSet.noneOf(Radar.RadarRouteMode.class);
    List<String> modesList = call.getArray("modes").toList();
    if (modesList.contains("FOOT") || modesList.contains("foot")) {
        modes.add(Radar.RadarRouteMode.FOOT);
    }
    if (modesList.contains("BIKE") || modesList.contains("bike")) {
        modes.add(Radar.RadarRouteMode.BIKE);
    }
    if (modesList.contains("CAR") || modesList.contains("car")) {
        modes.add(Radar.RadarRouteMode.CAR);
    }
    if (!call.hasOption("units")) {
        call.reject("units is required");
        return;
    }
    String unitsStr = call.getString("units");
    Radar.RadarRouteUnits units = unitsStr.equals("METRIC") || unitsStr.equals("metric") ? Radar.RadarRouteUnits.METRIC : Radar.RadarRouteUnits.IMPERIAL;
    if (call.hasOption("origin")) {
        JSObject originObj = call.getObject("origin");
        double originLatitude = originObj.getDouble("latitude");
        double originLongitude = originObj.getDouble("longitude");
        Location origin = new Location("RadarSDK");
        origin.setLatitude(originLatitude);
        origin.setLongitude(originLongitude);
        Radar.getDistance(origin, destination, modes, units, callback);
    } else {
        Radar.getDistance(destination, modes, units, callback);
    }
}
Also used : JSObject(com.getcapacitor.JSObject) NotNull(org.jetbrains.annotations.NotNull) Radar(io.radar.sdk.Radar) RadarRoutes(io.radar.sdk.model.RadarRoutes) Nullable(org.jetbrains.annotations.Nullable) Location(android.location.Location) PluginMethod(com.getcapacitor.PluginMethod)

Example 64 with PluginMethod

use of com.getcapacitor.PluginMethod in project capacitor-radar by radarlabs.

the class RadarPlugin method getContext.

@PluginMethod()
public void getContext(final PluginCall call) {
    Radar.RadarContextCallback callback = new Radar.RadarContextCallback() {

        @Override
        public void onComplete(@NotNull Radar.RadarStatus status, @Nullable Location location, @Nullable RadarContext context) {
            if (status == Radar.RadarStatus.SUCCESS && location != null && context != null) {
                JSObject ret = new JSObject();
                ret.put("status", status.toString());
                ret.put("location", RadarPlugin.jsObjectForJSONObject(Radar.jsonForLocation(location)));
                ret.put("context", RadarPlugin.jsObjectForJSONObject(context.toJson()));
                call.resolve(ret);
            } else {
                call.reject(status.toString());
            }
        }
    };
    if (call.hasOption("latitude") && call.hasOption("longitude")) {
        double latitude = call.getDouble("latitude");
        double longitude = call.getDouble("longitude");
        Location location = new Location("RadarSDK");
        location.setLatitude(latitude);
        location.setLongitude(longitude);
        location.setAccuracy(5);
        Radar.getContext(location, callback);
    } else {
        Radar.getContext(callback);
    }
}
Also used : Radar(io.radar.sdk.Radar) JSObject(com.getcapacitor.JSObject) RadarContext(io.radar.sdk.model.RadarContext) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable) Location(android.location.Location) PluginMethod(com.getcapacitor.PluginMethod)

Example 65 with PluginMethod

use of com.getcapacitor.PluginMethod in project capacitor-radar by radarlabs.

the class RadarPlugin method setForegroundServiceOptions.

@PluginMethod()
public void setForegroundServiceOptions(PluginCall call) {
    JSObject optionsObj = call.getObject("options");
    JSONObject optionsJson = RadarPlugin.jsonObjectForJSObject(optionsObj);
    RadarTrackingOptionsForegroundService options = RadarTrackingOptionsForegroundService.fromJson(optionsJson);
    Radar.setForegroundServiceOptions(options);
    call.resolve();
}
Also used : JSONObject(org.json.JSONObject) RadarTrackingOptionsForegroundService(io.radar.sdk.RadarTrackingOptions.RadarTrackingOptionsForegroundService) JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Aggregations

PluginMethod (com.getcapacitor.PluginMethod)120 JSObject (com.getcapacitor.JSObject)93 JSONException (org.json.JSONException)18 MyRunnable (com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable)13 JSONObject (org.json.JSONObject)13 JSArray (com.getcapacitor.JSArray)12 Radar (io.radar.sdk.Radar)11 Location (android.location.Location)8 Intent (android.content.Intent)7 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)6 Uri (android.net.Uri)5 LatLng (com.google.android.libraries.maps.model.LatLng)5 GenericAd (admob.plus.core.GenericAd)4 GoogleSignInAccount (com.google.android.gms.auth.api.signin.GoogleSignInAccount)4 Gson (com.google.gson.Gson)4 PackageManager (android.content.pm.PackageManager)3 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)3 User (io.ionic.demo.ecommerce.data.model.User)3 Context (android.content.Context)2