Search in sources :

Example 11 with JSObject

use of com.getcapacitor.JSObject in project capacitor-app-update by robingenz.

the class AppUpdatePlugin method handleOnActivityResult.

@Override
protected void handleOnActivityResult(int requestCode, int resultCode, Intent data) {
    super.handleOnActivityResult(requestCode, resultCode, data);
    if (resultCode != RESULT_OK && requestCode == REQUEST_FLEXIBLE_UPDATE) {
        this.unregisterListener();
    }
    this.appUpdateInfo = null;
    if (savedPluginCall == null) {
        return;
    }
    JSObject ret = new JSObject();
    if (resultCode == RESULT_OK) {
        ret.put("code", UPDATE_OK);
    } else if (resultCode == RESULT_CANCELED) {
        ret.put("code", UPDATE_CANCELED);
    } else if (resultCode == RESULT_IN_APP_UPDATE_FAILED) {
        ret.put("code", UPDATE_FAILED);
    }
    savedPluginCall.resolve(ret);
}
Also used : JSObject(com.getcapacitor.JSObject)

Example 12 with JSObject

use of com.getcapacitor.JSObject in project capacitor-google-fit by perfood.

the class GoogleFitPlugin method getHistoryActivity.

@PluginMethod
public Task<DataReadResponse> getHistoryActivity(final PluginCall call) throws ParseException {
    final GoogleSignInAccount account = getAccount();
    if (account == null) {
        call.reject("No access");
        return null;
    }
    long startTime = dateToTimestamp(call.getString("startTime"));
    long endTime = dateToTimestamp(call.getString("endTime"));
    if (startTime == -1 || endTime == -1) {
        call.reject("Must provide a start time and end time");
        return null;
    }
    DataReadRequest readRequest = new DataReadRequest.Builder().aggregate(DataType.TYPE_STEP_COUNT_DELTA).aggregate(DataType.AGGREGATE_STEP_COUNT_DELTA).aggregate(DataType.TYPE_DISTANCE_DELTA).aggregate(DataType.AGGREGATE_DISTANCE_DELTA).aggregate(DataType.TYPE_SPEED).aggregate(DataType.TYPE_CALORIES_EXPENDED).aggregate(DataType.AGGREGATE_CALORIES_EXPENDED).aggregate(DataType.TYPE_WEIGHT).setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS).bucketByActivitySegment(1, TimeUnit.MINUTES).enableServerQueries().build();
    return Fitness.getHistoryClient(getActivity(), account).readData(readRequest).addOnSuccessListener(new OnSuccessListener<DataReadResponse>() {

        @Override
        public void onSuccess(DataReadResponse dataReadResponse) {
            List<Bucket> buckets = dataReadResponse.getBuckets();
            JSONArray activities = new JSONArray();
            for (Bucket bucket : buckets) {
                JSONObject summary = new JSONObject();
                try {
                    summary.put("start", timestampToDate(bucket.getStartTime(TimeUnit.MILLISECONDS)));
                    summary.put("end", timestampToDate(bucket.getEndTime(TimeUnit.MILLISECONDS)));
                    List<DataSet> dataSets = bucket.getDataSets();
                    for (DataSet dataSet : dataSets) {
                        if (dataSet.getDataPoints().size() > 0) {
                            switch(dataSet.getDataType().getName()) {
                                case "com.google.distance.delta":
                                    summary.put("distance", dataSet.getDataPoints().get(0).getValue(Field.FIELD_DISTANCE));
                                    break;
                                case "com.google.speed.summary":
                                    summary.put("speed", dataSet.getDataPoints().get(0).getValue(Field.FIELD_AVERAGE));
                                    break;
                                case "com.google.calories.expended":
                                    summary.put("calories", dataSet.getDataPoints().get(0).getValue(Field.FIELD_CALORIES));
                                    break;
                                case "com.google.weight.summary":
                                    summary.put("weight", dataSet.getDataPoints().get(0).getValue(Field.FIELD_AVERAGE));
                                    break;
                                case "com.google.step_count.delta":
                                    summary.put("steps", dataSet.getDataPoints().get(0).getValue(Field.FIELD_STEPS));
                                    break;
                                default:
                                    Log.i(TAG, "need to handle " + dataSet.getDataType().getName());
                            }
                        }
                    }
                    summary.put("activity", bucket.getActivity());
                } catch (JSONException e) {
                    call.reject(e.getMessage());
                    return;
                }
                activities.put(summary);
            }
            JSObject result = new JSObject();
            result.put("activities", activities);
            call.resolve(result);
        }
    });
}
Also used : DataSet(com.google.android.gms.fitness.data.DataSet) DataReadResponse(com.google.android.gms.fitness.result.DataReadResponse) JSONArray(org.json.JSONArray) DataReadRequest(com.google.android.gms.fitness.request.DataReadRequest) JSONException(org.json.JSONException) JSObject(com.getcapacitor.JSObject) GoogleSignInAccount(com.google.android.gms.auth.api.signin.GoogleSignInAccount) JSONObject(org.json.JSONObject) Bucket(com.google.android.gms.fitness.data.Bucket) List(java.util.List) PluginMethod(com.getcapacitor.PluginMethod)

Example 13 with JSObject

use of com.getcapacitor.JSObject in project google-maps by capacitor-community.

the class CapacitorGoogleMaps method onMarkerDragEnd.

public void onMarkerDragEnd(Marker marker) {
    JSObject result = new JSObject();
    JSObject location = new JSObject();
    JSObject coordinates = new JSObject();
    JSObject metadata = (JSObject) marker.getTag();
    coordinates.put("latitude", marker.getPosition().latitude);
    coordinates.put("longitude", marker.getPosition().longitude);
    location.put("coordinates", coordinates);
    result.put("id", marker.getId());
    result.put("title", marker.getTitle());
    result.put("snippet", marker.getSnippet());
    result.put("result", location);
    result.put("metadata", metadata);
    notifyListeners("didEndDragging", result);
}
Also used : JSObject(com.getcapacitor.JSObject)

Example 14 with JSObject

use of com.getcapacitor.JSObject in project google-maps by capacitor-community.

the class CapacitorGoogleMaps method onMarkerClick.

public void onMarkerClick(Marker marker) {
    JSObject result = new JSObject();
    JSObject location = new JSObject();
    JSObject coordinates = new JSObject();
    JSObject metadata = (JSObject) marker.getTag();
    coordinates.put("latitude", marker.getPosition().latitude);
    coordinates.put("longitude", marker.getPosition().longitude);
    location.put("coordinates", coordinates);
    result.put("id", marker.getId());
    result.put("title", marker.getTitle());
    result.put("snippet", marker.getSnippet());
    result.put("result", location);
    result.put("metadata", metadata);
    notifyListeners("didTap", result);
}
Also used : JSObject(com.getcapacitor.JSObject)

Example 15 with JSObject

use of com.getcapacitor.JSObject in project google-maps by capacitor-community.

the class CapacitorGoogleMaps method onMyLocationClick.

public void onMyLocationClick(Location location) {
    JSObject result = new JSObject();
    result.put("latitude", location.getLatitude());
    result.put("longitude", location.getLongitude());
    notifyListeners("onMyLocationClick", result);
}
Also used : JSObject(com.getcapacitor.JSObject)

Aggregations

JSObject (com.getcapacitor.JSObject)169 PluginMethod (com.getcapacitor.PluginMethod)93 JSONException (org.json.JSONException)28 JSONObject (org.json.JSONObject)20 MyRunnable (com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable)16 JSArray (com.getcapacitor.JSArray)14 Radar (io.radar.sdk.Radar)12 Uri (android.net.Uri)11 Location (android.location.Location)9 JSONArray (org.json.JSONArray)7 ArrayList (java.util.ArrayList)6 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)6 ParseException (java.text.ParseException)5 Intent (android.content.Intent)4 FirebaseUser (com.google.firebase.auth.FirebaseUser)4 Gson (com.google.gson.Gson)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4