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);
}
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);
}
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);
}
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;
}
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);
}
Aggregations