use of com.getcapacitor.PluginMethod in project capacitor-calendar by Fir3st.
the class CapacitorCalendar method getAvailableCalendars.
@PluginMethod()
public void getAvailableCalendars(PluginCall call) {
if (!hasRequiredPermissions()) {
requestPermissionsCalendar(call);
} else {
List<Calendar> availableCalendars = getAvailableCalendarsList();
JSObject ret = new JSObject();
ret.put("availableCalendars", new Gson().toJson(availableCalendars));
call.success(ret);
}
}
use of com.getcapacitor.PluginMethod in project capacitor-radar by radarlabs.
the class RadarPlugin method startTrackingCustom.
@PluginMethod()
public void startTrackingCustom(PluginCall call) {
JSObject trackingOptionsObj = call.getObject("options");
JSONObject trackingOptionsJson = RadarPlugin.jsonObjectForJSObject(trackingOptionsObj);
RadarTrackingOptions trackingOptions = RadarTrackingOptions.fromJson(trackingOptionsJson);
Radar.startTracking(trackingOptions);
call.resolve();
}
use of com.getcapacitor.PluginMethod in project capacitor-radar by radarlabs.
the class RadarPlugin method searchGeofences.
@PluginMethod()
public void searchGeofences(final PluginCall call) throws JSONException {
Radar.RadarSearchGeofencesCallback callback = new Radar.RadarSearchGeofencesCallback() {
@Override
public void onComplete(@NotNull Radar.RadarStatus status, @Nullable Location location, @Nullable RadarGeofence[] geofences) {
if (status == Radar.RadarStatus.SUCCESS && location != null && geofences != null) {
JSObject ret = new JSObject();
ret.put("status", status.toString());
ret.put("location", RadarPlugin.jsObjectForJSONObject(Radar.jsonForLocation(location)));
ret.put("geofences", RadarPlugin.jsArrayForJSONArray(RadarGeofence.toJson(geofences)));
call.resolve(ret);
} else {
call.reject(status.toString());
}
}
};
int radius = call.getInt("radius", 1000);
String[] tags = RadarPlugin.stringArrayForJSArray(call.getArray("tags"));
int limit = call.getInt("limit", 10);
if (call.hasOption("near")) {
JSObject nearObj = call.getObject("near");
double latitude = nearObj.getDouble("latitude");
double longitude = nearObj.getDouble("longitude");
Location near = new Location("RadarSDK");
near.setLatitude(latitude);
near.setLongitude(longitude);
near.setAccuracy(5);
Radar.searchGeofences(near, radius, tags, null, limit, callback);
} else {
Radar.searchGeofences(radius, tags, null, limit, callback);
}
}
use of com.getcapacitor.PluginMethod in project capacitor-radar by radarlabs.
the class RadarPlugin method searchPlaces.
@PluginMethod()
public void searchPlaces(final PluginCall call) throws JSONException {
Radar.RadarSearchPlacesCallback callback = new Radar.RadarSearchPlacesCallback() {
@Override
public void onComplete(@NotNull Radar.RadarStatus status, @Nullable Location location, @Nullable RadarPlace[] places) {
if (status == Radar.RadarStatus.SUCCESS && location != null && places != null) {
JSObject ret = new JSObject();
ret.put("status", status.toString());
ret.put("location", RadarPlugin.jsObjectForJSONObject(Radar.jsonForLocation(location)));
ret.put("places", RadarPlugin.jsArrayForJSONArray(RadarPlace.toJson(places)));
call.resolve(ret);
} else {
call.reject(status.toString());
}
}
};
int radius = call.getInt("radius", 1000);
String[] chains = RadarPlugin.stringArrayForJSArray(call.getArray("chains"));
String[] categories = RadarPlugin.stringArrayForJSArray(call.getArray("categories"));
String[] groups = RadarPlugin.stringArrayForJSArray(call.getArray("groups"));
int limit = call.getInt("limit", 10);
if (call.hasOption("near")) {
JSObject nearObj = call.getObject("near");
double latitude = nearObj.getDouble("latitude");
double longitude = nearObj.getDouble("longitude");
Location near = new Location("RadarSDK");
near.setLatitude(latitude);
near.setLongitude(longitude);
near.setAccuracy(5);
Radar.searchPlaces(near, radius, chains, categories, groups, limit, callback);
} else {
Radar.searchPlaces(radius, chains, categories, groups, limit, callback);
}
}
use of com.getcapacitor.PluginMethod in project capacitor-radar by radarlabs.
the class RadarPlugin method autocomplete.
@PluginMethod()
public void autocomplete(final PluginCall call) throws JSONException {
if (!call.hasOption("query")) {
call.reject("query is required");
return;
}
String query = call.getString("query");
if (!call.hasOption("near")) {
call.reject("near is required");
return;
}
JSObject nearObj = call.getObject("near");
double latitude = nearObj.getDouble("latitude");
double longitude = nearObj.getDouble("longitude");
Location near = new Location("RadarSDK");
near.setLatitude(latitude);
near.setLongitude(longitude);
near.setAccuracy(5);
int limit = call.getInt("limit", 10);
Radar.autocomplete(query, near, limit, 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());
}
}
});
}
Aggregations