use of com.getcapacitor.JSObject 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);
}
}
use of com.getcapacitor.JSObject 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();
}
use of com.getcapacitor.JSObject in project capacitor-calendar by Fir3st.
the class CapacitorCalendar method deleteCalendarEventById.
protected void deleteCalendarEventById(PluginCall call) {
JSObject data = call.getData();
JSObject ret = new JSObject();
String id = data.getString("id", null);
if (id == null)
throw new IllegalArgumentException("Event id not specified.");
long evDtStart = -1;
{
Cursor cur = queryEvents(new String[] { Events.DTSTART }, Events._ID + " = ?", new String[] { id }, Events.DTSTART);
if (cur.moveToNext()) {
evDtStart = cur.getLong(0);
}
cur.close();
}
if (evDtStart == -1)
throw new RuntimeException("Could not find event.");
int deleted = this.getActivity().getContentResolver().delete(ContentUris.withAppendedId(Events.CONTENT_URI, Long.valueOf(id)), null, null);
ret.put("result", deleted > 0);
call.resolve(ret);
}
use of com.getcapacitor.JSObject in project capacitor-calendar by Fir3st.
the class CapacitorCalendar method createCalendarEvent.
protected void createCalendarEvent(PluginCall call) {
ContentResolver cr = this.getActivity().getContentResolver();
ContentValues values = new ContentValues();
JSObject data = call.getData();
try {
Long startTime = data.has("startDate") ? data.getLong("startDate") : new Date().getTime();
Long endTime = data.has("endDate") ? data.getLong("endDate") : new Date().getTime();
final boolean hasAllDayEventConfig = data.has("allDay");
if (hasAllDayEventConfig != false) {
final boolean allDayEventConfig = data.getBoolean("allDay");
values.put(Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
values.put(Events.ALL_DAY, allDayEventConfig);
values.put(Events.DTSTART, startTime);
values.put(Events.DTEND, endTime);
} else {
final boolean allDayEvent = isAllDayEvent(new Date(startTime), new Date(endTime));
if (allDayEvent) {
values.put(Events.EVENT_TIMEZONE, "UTC");
values.put(Events.ALL_DAY, true);
values.put(Events.DTSTART, startTime + TimeZone.getDefault().getOffset(startTime));
values.put(Events.DTEND, endTime + TimeZone.getDefault().getOffset(endTime));
} else {
values.put(Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
values.put(Events.ALL_DAY, false);
values.put(Events.DTSTART, startTime);
values.put(Events.DTEND, endTime);
}
}
String selectedCalendarId = data.has("calendarId") ? data.getString("calendarId").replaceAll("\"", "") : "";
List<String> activeCalendars = Arrays.asList(getActiveCalendarIds());
int calendarId = data.has("calendarId") && activeCalendars.contains(selectedCalendarId) ? Integer.parseInt(selectedCalendarId) : getDefaultCalendarId();
values.put(Events.TITLE, call.getString("title", ""));
values.put(Events.DESCRIPTION, call.getString("notes", ""));
values.put(Events.EVENT_LOCATION, call.getString("location", ""));
values.put(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);
values.put(CalendarContract.Events.CALENDAR_ID, calendarId);
} catch (Exception e) {
Log.e(LOG_TAG, "Fail to parse data", e);
call.reject(e.getMessage());
}
try {
Uri uri = cr.insert(Events.CONTENT_URI, values);
String createdEventID = uri.getLastPathSegment();
Log.d(LOG_TAG, "Created event with ID " + createdEventID);
JSObject ret = new JSObject();
ret.put("id", createdEventID);
call.resolve(ret);
} catch (SecurityException e) {
Log.e(LOG_TAG, "Permission denied", e);
call.error(e.getMessage());
} catch (Exception e) {
Log.e(LOG_TAG, "Fail to create an event", e);
call.error(e.getMessage());
}
}
use of com.getcapacitor.JSObject 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);
}
}
Aggregations