Search in sources :

Example 71 with PluginMethod

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

the class RadarPlugin method startTrip.

@PluginMethod()
public void startTrip(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);
    Radar.startTrip(options, 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 72 with PluginMethod

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

the class RadarPlugin method reverseGeocode.

@PluginMethod()
public void reverseGeocode(final PluginCall call) throws JSONException {
    Radar.RadarGeocodeCallback callback = 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());
            }
        }
    };
    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.reverseGeocode(location, callback);
    } else {
        Radar.reverseGeocode(callback);
    }
}
Also used : Radar(io.radar.sdk.Radar) JSObject(com.getcapacitor.JSObject) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable) Location(android.location.Location) PluginMethod(com.getcapacitor.PluginMethod)

Example 73 with PluginMethod

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

the class RadarPlugin method getLocationPermissionsStatus.

@PluginMethod()
public void getLocationPermissionsStatus(PluginCall call) {
    boolean foreground = hasPermission(Manifest.permission.ACCESS_FINE_LOCATION);
    String status;
    if (Build.VERSION.SDK_INT >= 29) {
        if (foreground) {
            boolean background = hasPermission(Manifest.permission.ACCESS_BACKGROUND_LOCATION);
            status = background ? "GRANTED_BACKGROUND" : "GRANTED_FOREGROUND";
        } else {
            status = "DENIED";
        }
    } else {
        status = foreground ? "GRANTED_FOREGROUND" : "DENIED";
    }
    JSObject ret = new JSObject();
    ret.put("status", status);
    call.resolve(ret);
}
Also used : JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 74 with PluginMethod

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

the class RadarPlugin method mockTracking.

@PluginMethod()
public void mockTracking(final PluginCall call) throws JSONException {
    if (!call.hasOption("origin")) {
        call.reject("origin is required");
        return;
    }
    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);
    origin.setAccuracy(5);
    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("mode")) {
        call.reject("mode is required");
        return;
    }
    String modeStr = call.getString("mode");
    Radar.RadarRouteMode mode = Radar.RadarRouteMode.CAR;
    if (modeStr.equals("FOOT") || modeStr.equals("foot")) {
        mode = Radar.RadarRouteMode.FOOT;
    } else if (modeStr.equals("BIKE") || modeStr.equals("bike")) {
        mode = Radar.RadarRouteMode.BIKE;
    } else if (modeStr.equals("CAR") || modeStr.equals("car")) {
        mode = Radar.RadarRouteMode.CAR;
    }
    int steps = call.getInt("steps", 10);
    int interval = call.getInt("interval", 1);
    Radar.mockTracking(origin, destination, mode, steps, interval, new Radar.RadarTrackCallback() {

        @Override
        public void onComplete(@NotNull Radar.RadarStatus radarStatus, @Nullable Location location, @Nullable RadarEvent[] radarEvents, @Nullable RadarUser radarUser) {
        }
    });
    call.resolve();
}
Also used : RadarEvent(io.radar.sdk.model.RadarEvent) JSObject(com.getcapacitor.JSObject) RadarUser(io.radar.sdk.model.RadarUser) Radar(io.radar.sdk.Radar) Location(android.location.Location) PluginMethod(com.getcapacitor.PluginMethod)

Example 75 with PluginMethod

use of com.getcapacitor.PluginMethod in project capacitor-plugins by ionic-team.

the class DevicePlugin method getLanguageCode.

@PluginMethod
public void getLanguageCode(PluginCall call) {
    JSObject ret = new JSObject();
    ret.put("value", Locale.getDefault().getLanguage());
    call.resolve(ret);
}
Also used : 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