Search in sources :

Example 16 with JSArray

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

the class StoragePlugin method migrate.

@PluginMethod
public void migrate(PluginCall call) {
    List<String> migrated = new ArrayList<>();
    List<String> existing = new ArrayList<>();
    Storage oldStorage = new Storage(getContext(), StorageConfiguration.DEFAULTS);
    for (String key : oldStorage.keys()) {
        String value = oldStorage.get(key);
        String currentValue = storage.get(key);
        if (currentValue == null) {
            storage.set(key, value);
            migrated.add(key);
        } else {
            existing.add(key);
        }
    }
    JSObject ret = new JSObject();
    ret.put("migrated", new JSArray(migrated));
    ret.put("existing", new JSArray(existing));
    call.resolve(ret);
}
Also used : ArrayList(java.util.ArrayList) JSArray(com.getcapacitor.JSArray) JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 17 with JSArray

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

the class StoragePlugin method keys.

@PluginMethod
public void keys(PluginCall call) {
    Set<String> keySet = storage.keys();
    String[] keys = keySet.toArray(new String[0]);
    JSObject ret = new JSObject();
    try {
        ret.put("keys", new JSArray(keys));
    } catch (JSONException ex) {
        call.reject("Unable to serialize response.", ex);
        return;
    }
    call.resolve(ret);
}
Also used : JSArray(com.getcapacitor.JSArray) JSObject(com.getcapacitor.JSObject) JSONException(org.json.JSONException) PluginMethod(com.getcapacitor.PluginMethod)

Example 18 with JSArray

use of com.getcapacitor.JSArray in project capacitor-sms by moberwasserlechner.

the class SmsManagerPlugin method sendSms.

private void sendSms(final PluginCall call) {
    JSArray numberArray = call.getArray("numbers");
    List<String> recipientNumbers = null;
    try {
        recipientNumbers = numberArray.toList();
    } catch (JSONException ignore) {
    }
    if (recipientNumbers == null || recipientNumbers.isEmpty()) {
        call.reject(ERR_NO_NUMBERS);
        return;
    }
    String text = ConfigUtils.getCallParam(String.class, call, "text");
    if (text == null || text.length() == 0) {
        call.reject(ERR_NO_TEXT);
        return;
    }
    String separator = ";";
    if (android.os.Build.MANUFACTURER.equalsIgnoreCase("Samsung")) {
        // See http://stackoverflow.com/questions/18974898/send-sms-through-intent-to-multiple-phone-numbers/18975676#18975676
        separator = ",";
    }
    String phoneNumber = getJoinedNumbers(recipientNumbers, separator);
    Intent smsIntent = new Intent(Intent.ACTION_VIEW);
    smsIntent.putExtra("sms_body", text);
    // See http://stackoverflow.com/questions/7242190/sending-sms-using-intent-does-not-add-recipients-on-some-devices
    smsIntent.putExtra("address", phoneNumber);
    smsIntent.setData(Uri.parse("smsto:" + Uri.encode(phoneNumber)));
    if (smsIntent.resolveActivity(getContext().getPackageManager()) != null) {
        startActivityForResult(call, smsIntent, "onSmsRequestResult");
    } else {
        call.reject(ERR_SERVICE_NOTFOUND);
    }
}
Also used : JSArray(com.getcapacitor.JSArray) JSONException(org.json.JSONException) Intent(android.content.Intent)

Example 19 with JSArray

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

the class CapacitorGoogleMaps method addPolygon.

@PluginMethod()
public void addPolygon(final PluginCall call) {
    final JSArray points = call.getArray("points", new JSArray());
    getBridge().executeOnMainThread(new Runnable() {

        @Override
        public void run() {
            PolygonOptions polygonOptions = new PolygonOptions();
            for (int i = 0; i < points.length(); i++) {
                try {
                    JSONObject point = points.getJSONObject(i);
                    LatLng latLng = new LatLng(point.getDouble("latitude"), point.getDouble("longitude"));
                    polygonOptions.add(latLng);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            googleMap.addPolygon(polygonOptions);
            call.resolve();
        }
    });
}
Also used : JSONObject(org.json.JSONObject) PolygonOptions(com.google.android.libraries.maps.model.PolygonOptions) JSArray(com.getcapacitor.JSArray) JSONException(org.json.JSONException) LatLng(com.google.android.libraries.maps.model.LatLng) PluginMethod(com.getcapacitor.PluginMethod)

Example 20 with JSArray

use of com.getcapacitor.JSArray in project capacitor-firebase by robingenz.

the class OAuthProviderHandler method applySignInConfig.

private void applySignInConfig(PluginCall call, OAuthProvider.Builder provider) {
    JSArray customParameters = call.getArray("customParameters");
    if (customParameters != null) {
        try {
            List<Object> customParametersList = customParameters.toList();
            for (int i = 0; i < customParametersList.size(); i++) {
                JSObject customParameter = JSObject.fromJSONObject((JSONObject) customParametersList.get(i));
                String key = customParameter.getString("key");
                String value = customParameter.getString("value");
                if (key == null || value == null) {
                    continue;
                }
                provider.addCustomParameter(key, value);
            }
        } catch (JSONException exception) {
            Log.e(FirebaseAuthenticationPlugin.TAG, "applySignInConfig failed.", exception);
        }
    }
}
Also used : JSArray(com.getcapacitor.JSArray) JSObject(com.getcapacitor.JSObject) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) JSObject(com.getcapacitor.JSObject)

Aggregations

JSArray (com.getcapacitor.JSArray)20 JSObject (com.getcapacitor.JSObject)14 PluginMethod (com.getcapacitor.PluginMethod)12 JSONException (org.json.JSONException)10 JSONObject (org.json.JSONObject)7 Intent (android.content.Intent)3 ArrayList (java.util.ArrayList)3 NotificationChannel (android.app.NotificationChannel)2 LatLng (com.google.android.libraries.maps.model.LatLng)2 Notification (android.app.Notification)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 Parcelable (android.os.Parcelable)1 StatusBarNotification (android.service.notification.StatusBarNotification)1 ActivityCallback (com.getcapacitor.annotation.ActivityCallback)1 PolygonOptions (com.google.android.libraries.maps.model.PolygonOptions)1 PolylineOptions (com.google.android.libraries.maps.model.PolylineOptions)1 ParseException (java.text.ParseException)1 Executor (java.util.concurrent.Executor)1 JSONArray (org.json.JSONArray)1