Search in sources :

Example 76 with JSObject

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

the class StatusBarPlugin method getInfo.

@PluginMethod
public void getInfo(final PluginCall call) {
    StatusBarInfo info = implementation.getInfo();
    JSObject data = new JSObject();
    data.put("visible", info.isVisible());
    data.put("style", info.getStyle());
    data.put("color", info.getColor());
    data.put("overlays", info.isOverlays());
    call.resolve(data);
}
Also used : JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 77 with JSObject

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

the class StoragePlugin method get.

@PluginMethod
public void get(PluginCall call) {
    String key = call.getString("key");
    if (key == null) {
        call.reject("Must provide key");
        return;
    }
    String value = storage.get(key);
    JSObject ret = new JSObject();
    ret.put("value", value == null ? JSObject.NULL : value);
    call.resolve(ret);
}
Also used : JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 78 with JSObject

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

the class CameraPlugin method returnBase64.

private void returnBase64(PluginCall call, ExifWrapper exif, ByteArrayOutputStream bitmapOutputStream) {
    byte[] byteArray = bitmapOutputStream.toByteArray();
    String encoded = Base64.encodeToString(byteArray, Base64.NO_WRAP);
    JSObject data = new JSObject();
    data.put("format", "jpeg");
    data.put("base64String", encoded);
    data.put("exif", exif.toJson());
    call.resolve(data);
}
Also used : JSObject(com.getcapacitor.JSObject)

Example 79 with JSObject

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

the class CameraPlugin method processPickedImages.

private JSObject processPickedImages(Uri imageUri) {
    InputStream imageStream = null;
    JSObject ret = new JSObject();
    try {
        imageStream = getContext().getContentResolver().openInputStream(imageUri);
        Bitmap bitmap = BitmapFactory.decodeStream(imageStream);
        if (bitmap == null) {
            ret.put("error", "Unable to process bitmap");
            return ret;
        }
        ExifWrapper exif = ImageUtils.getExifData(getContext(), bitmap, imageUri);
        try {
            bitmap = prepareBitmap(bitmap, imageUri, exif);
        } catch (IOException e) {
            ret.put("error", UNABLE_TO_PROCESS_IMAGE);
            return ret;
        }
        // Compress the final image and prepare for output to client
        ByteArrayOutputStream bitmapOutputStream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, settings.getQuality(), bitmapOutputStream);
        Uri newUri = getTempImage(imageUri, bitmapOutputStream);
        exif.copyExif(newUri.getPath());
        if (newUri != null) {
            ret.put("format", "jpeg");
            ret.put("exif", exif.toJson());
            ret.put("path", newUri.toString());
            ret.put("webPath", FileUtils.getPortablePath(getContext(), bridge.getLocalUrl(), newUri));
        } else {
            ret.put("error", UNABLE_TO_PROCESS_IMAGE);
        }
        return ret;
    } catch (OutOfMemoryError err) {
        ret.put("error", "Out of memory");
    } catch (FileNotFoundException ex) {
        ret.put("error", "No such image found");
        Logger.error(getLogTag(), "No such image found", ex);
    } finally {
        if (imageStream != null) {
            try {
                imageStream.close();
            } catch (IOException e) {
                Logger.error(getLogTag(), UNABLE_TO_PROCESS_IMAGE, e);
            }
        }
    }
    return ret;
}
Also used : Bitmap(android.graphics.Bitmap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) JSObject(com.getcapacitor.JSObject) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Uri(android.net.Uri)

Example 80 with JSObject

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

the class AppLauncherPlugin method openUrl.

@PluginMethod
public void openUrl(PluginCall call) {
    String url = call.getString("url");
    if (url == null) {
        call.reject("Must provide a url to open");
        return;
    }
    JSObject ret = new JSObject();
    final PackageManager manager = getContext().getPackageManager();
    Intent launchIntent = new Intent(Intent.ACTION_VIEW);
    launchIntent.setData(Uri.parse(url));
    try {
        getActivity().startActivity(launchIntent);
        ret.put("completed", true);
    } catch (Exception ex) {
        launchIntent = manager.getLaunchIntentForPackage(url);
        try {
            getActivity().startActivity(launchIntent);
            ret.put("completed", true);
        } catch (Exception expgk) {
            ret.put("completed", false);
        }
    }
    call.resolve(ret);
}
Also used : PackageManager(android.content.pm.PackageManager) JSObject(com.getcapacitor.JSObject) Intent(android.content.Intent) PluginMethod(com.getcapacitor.PluginMethod)

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