Search in sources :

Example 11 with ReadableMap

use of com.facebook.react.bridge.ReadableMap in project react-native-image-picker by marcshilling.

the class ImageConfig method updateFromOptions.

@NonNull
public ImageConfig updateFromOptions(@NonNull final ReadableMap options) {
    int maxWidth = 0;
    if (options.hasKey("maxWidth")) {
        maxWidth = options.getInt("maxWidth");
    }
    int maxHeight = 0;
    if (options.hasKey("maxHeight")) {
        maxHeight = options.getInt("maxHeight");
    }
    int quality = 100;
    if (options.hasKey("quality")) {
        quality = (int) (options.getDouble("quality") * 100);
    }
    int rotation = 0;
    if (options.hasKey("rotation")) {
        rotation = options.getInt("rotation");
    }
    boolean saveToCameraRoll = false;
    if (options.hasKey("storageOptions")) {
        final ReadableMap storageOptions = options.getMap("storageOptions");
        if (storageOptions.hasKey("cameraRoll")) {
            saveToCameraRoll = storageOptions.getBoolean("cameraRoll");
        }
    }
    return new ImageConfig(this.original, this.resized, maxWidth, maxHeight, quality, rotation, saveToCameraRoll);
}
Also used : ReadableMap(com.facebook.react.bridge.ReadableMap) NonNull(android.support.annotation.NonNull)

Example 12 with ReadableMap

use of com.facebook.react.bridge.ReadableMap in project react-native-image-picker by marcshilling.

the class PermissionUtils method explainingDialog.

@Nullable
public static AlertDialog explainingDialog(@NonNull final ImagePickerModule module, @NonNull final ReadableMap options, @NonNull final OnExplainingPermissionCallback callback) {
    if (module.getContext() == null) {
        return null;
    }
    if (!options.hasKey("permissionDenied")) {
        return null;
    }
    final ReadableMap permissionDenied = options.getMap("permissionDenied");
    if (((ReadableNativeMap) permissionDenied).toHashMap().size() == 0) {
        return null;
    }
    final String title = permissionDenied.getString("title");
    final String text = permissionDenied.getString("text");
    final String btnReTryTitle = permissionDenied.getString("reTryTitle");
    final String btnOkTitle = permissionDenied.getString("okTitle");
    final WeakReference<ImagePickerModule> reference = new WeakReference<>(module);
    final Activity activity = module.getActivity();
    if (activity == null) {
        return null;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(activity, module.getDialogThemeId());
    builder.setTitle(title).setMessage(text).setCancelable(false).setNegativeButton(btnOkTitle, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialogInterface, int i) {
            callback.onCancel(reference, dialogInterface);
        }
    }).setPositiveButton(btnReTryTitle, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            callback.onReTry(reference, dialogInterface);
        }
    });
    return builder.create();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ReadableNativeMap(com.facebook.react.bridge.ReadableNativeMap) DialogInterface(android.content.DialogInterface) ImagePickerModule(com.imagepicker.ImagePickerModule) Activity(android.app.Activity) WeakReference(java.lang.ref.WeakReference) ReadableMap(com.facebook.react.bridge.ReadableMap) Nullable(android.support.annotation.Nullable)

Example 13 with ReadableMap

use of com.facebook.react.bridge.ReadableMap in project react-native-camera by react-native-community.

the class MutableImage method writeLocationExifData.

private void writeLocationExifData(ReadableMap options, ExifInterface exif) {
    if (!options.hasKey("metadata"))
        return;
    ReadableMap metadata = options.getMap("metadata");
    if (!metadata.hasKey("location"))
        return;
    ReadableMap location = metadata.getMap("location");
    if (!location.hasKey("coords"))
        return;
    try {
        ReadableMap coords = location.getMap("coords");
        double latitude = coords.getDouble("latitude");
        double longitude = coords.getDouble("longitude");
        GPS.writeExifData(latitude, longitude, exif);
    } catch (IOException e) {
        Log.e(TAG, "Couldn't write location data", e);
    }
}
Also used : ReadableMap(com.facebook.react.bridge.ReadableMap) IOException(java.io.IOException)

Example 14 with ReadableMap

use of com.facebook.react.bridge.ReadableMap in project react-native-camera by react-native-community.

the class TextRecognizedEvent method rotateTextX.

private WritableMap rotateTextX(WritableMap text) {
    ReadableMap faceBounds = text.getMap("bounds");
    ReadableMap oldOrigin = faceBounds.getMap("origin");
    WritableMap mirroredOrigin = FaceDetectorUtils.positionMirroredHorizontally(oldOrigin, mImageDimensions.getWidth(), mScaleX);
    double translateX = -faceBounds.getMap("size").getDouble("width");
    WritableMap translatedMirroredOrigin = FaceDetectorUtils.positionTranslatedHorizontally(mirroredOrigin, translateX);
    WritableMap newBounds = Arguments.createMap();
    newBounds.merge(faceBounds);
    newBounds.putMap("origin", translatedMirroredOrigin);
    text.putMap("bounds", newBounds);
    ReadableArray oldComponents = text.getArray("components");
    WritableArray newComponents = Arguments.createArray();
    for (int i = 0; i < oldComponents.size(); ++i) {
        WritableMap component = Arguments.createMap();
        component.merge(oldComponents.getMap(i));
        rotateTextX(component);
        newComponents.pushMap(component);
    }
    text.putArray("components", newComponents);
    return text;
}
Also used : ReadableArray(com.facebook.react.bridge.ReadableArray) WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) ReadableMap(com.facebook.react.bridge.ReadableMap)

Example 15 with ReadableMap

use of com.facebook.react.bridge.ReadableMap in project react-native-camera by react-native-community.

the class FaceDetectorUtils method rotateFaceX.

public static WritableMap rotateFaceX(WritableMap face, int sourceWidth, double scaleX) {
    ReadableMap faceBounds = face.getMap("bounds");
    ReadableMap oldOrigin = faceBounds.getMap("origin");
    WritableMap mirroredOrigin = positionMirroredHorizontally(oldOrigin, sourceWidth, scaleX);
    double translateX = -faceBounds.getMap("size").getDouble("width");
    WritableMap translatedMirroredOrigin = positionTranslatedHorizontally(mirroredOrigin, translateX);
    WritableMap newBounds = Arguments.createMap();
    newBounds.merge(faceBounds);
    newBounds.putMap("origin", translatedMirroredOrigin);
    for (String landmarkName : landmarkNames) {
        ReadableMap landmark = face.hasKey(landmarkName) ? face.getMap(landmarkName) : null;
        if (landmark != null) {
            WritableMap mirroredPosition = positionMirroredHorizontally(landmark, sourceWidth, scaleX);
            face.putMap(landmarkName, mirroredPosition);
        }
    }
    face.putMap("bounds", newBounds);
    return face;
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) ReadableMap(com.facebook.react.bridge.ReadableMap)

Aggregations

ReadableMap (com.facebook.react.bridge.ReadableMap)23 WritableMap (com.facebook.react.bridge.WritableMap)6 ReadableArray (com.facebook.react.bridge.ReadableArray)4 ReadableMapKeySetIterator (com.facebook.react.bridge.ReadableMapKeySetIterator)4 IOException (java.io.IOException)4 WritableArray (com.facebook.react.bridge.WritableArray)3 Resources (android.content.res.Resources)2 NonNull (android.support.annotation.NonNull)2 Nullable (android.support.annotation.Nullable)2 Promise (com.facebook.react.bridge.Promise)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Activity (android.app.Activity)1 Notification (android.app.Notification)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 Bitmap (android.graphics.Bitmap)1