0% found this document useful (0 votes)
27 views21 pages

React Native Image Crop Picker+0.36.4.patch

The document outlines changes made to the Android build configuration for the react-native-image-crop-picker library, including updates to the Gradle build script and properties. Key modifications include updating the compile and build tools versions, adjusting the minimum SDK version, and changing dependencies. Additionally, it introduces new repositories and updates the Exif interface imports to use androidx.exifinterface.

Uploaded by

Dimas Alvin Faiz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views21 pages

React Native Image Crop Picker+0.36.4.patch

The document outlines changes made to the Android build configuration for the react-native-image-crop-picker library, including updates to the Gradle build script and properties. Key modifications include updating the compile and build tools versions, adjusting the minimum SDK version, and changing dependencies. Additionally, it introduces new repositories and updates the Exif interface imports to use androidx.exifinterface.

Uploaded by

Dimas Alvin Faiz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 21

diff --git a/node_modules/react-native-image-crop-picker/android/build.

gradle
b/node_modules/react-native-image-crop-picker/android/build.gradle
index 48443cc..e6b9829 100644
--- a/node_modules/react-native-image-crop-picker/android/build.gradle
+++ b/node_modules/react-native-image-crop-picker/android/build.gradle
@@ -1,9 +1,20 @@
+buildscript {
+ repositories {
+ google()
+ mavenCentral()
+ }
+
+ dependencies {
+ classpath 'com.android.tools.build:gradle:4.2.2'
+ }
+}
+
apply plugin: 'com.android.library'

def DEFAULT_COMPILE_SDK_VERSION = 30
-def DEFAULT_BUILD_TOOLS_VERSION = "29.0.3"
+def DEFAULT_BUILD_TOOLS_VERSION = "30.0.2"
def DEFAULT_TARGET_SDK_VERSION = 30
-def DEFAULT_MIN_SDK_VERSION = 16
+def DEFAULT_MIN_SDK_VERSION = 23

android {
compileSdkVersion rootProject.hasProperty('compileSdkVersion') ?
rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION
@@ -19,8 +30,21 @@ android {
}
}

+repositories {
+ mavenCentral()
+ mavenLocal()
+ google()
+ maven {
+ // All of React Native (JS, Obj-C sources, Android binaries) is installed
from npm
+ url "$rootDir/../../../node_modules/react-native/android"
+ }
+ maven { url 'https://maven.google.com' }
+ maven { url 'https://www.jitpack.io' }
+}
+
dependencies {
+ //noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
- implementation 'com.github.yalantis:ucrop:2.2.6-native'
+ implementation 'com.github.yalantis:ucrop:2.2.7'
}
diff --git a/node_modules/react-native-image-crop-picker/android/gradle.properties
b/node_modules/react-native-image-crop-picker/android/gradle.properties
new file mode 100644
index 0000000..5ed3516
--- /dev/null
+++ b/node_modules/react-native-image-crop-picker/android/gradle.properties
@@ -0,0 +1,16 @@
+## For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+#
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+# Default value: -Xmx1024m -XX:MaxPermSize=256m
+# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:
+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
+#
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+#
http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decouple
d_projects
+# org.gradle.parallel=true
+#Wed Sep 15 11:45:10 EDT 2021
+android.useAndroidX=true
+android.enableJetifier=true
+
diff --git a/node_modules/react-native-image-crop-picker/android/gradle/wrapper/
gradle-wrapper.properties
b/node_modules/react-native-image-crop-picker/android/gradle/wrapper/gradle-
wrapper.properties
index 0f5c93f..d5d191a 100644
--- a/node_modules/react-native-image-crop-picker/android/gradle/wrapper/gradle-
wrapper.properties
+++ b/node_modules/react-native-image-crop-picker/android/gradle/wrapper/gradle-
wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
diff --git a/node_modules/react-native-image-crop-picker/android/gradlew
b/node_modules/react-native-image-crop-picker/android/gradlew
old mode 100644
new mode 100755
diff --git a/node_modules/react-native-image-crop-picker/android/local.properties
b/node_modules/react-native-image-crop-picker/android/local.properties
index 6e18bcb..78e7d02 100644
--- a/node_modules/react-native-image-crop-picker/android/local.properties
+++ b/node_modules/react-native-image-crop-picker/android/local.properties
@@ -4,5 +4,5 @@
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
-#Tue Jun 09 15:44:48 CEST 2020
-sdk.dir=/Users/ipusic/Library/Android/sdk
+#Wed Sep 15 14:12:26 EDT 2021
+sdk.dir=/Users/craig/Library/Android/sdk
diff --git
a/node_modules/react-native-image-crop-picker/android/src/main/AndroidManifest.xml
b/node_modules/react-native-image-crop-picker/android/src/main/AndroidManifest.xml
index d9b32ba..e577793 100644
---
a/node_modules/react-native-image-crop-picker/android/src/main/AndroidManifest.xml
+++
b/node_modules/react-native-image-crop-picker/android/src/main/AndroidManifest.xml
@@ -1,4 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
package="com.reactnative.ivpusic.imagepicker">

<queries>
@@ -7,9 +8,11 @@
</intent>
</queries>

- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
+ android:maxSdkVersion="28" />

- <application>
+ <application android:preserveLegacyExternalStorage="true"
+ tools:targetApi="r">

<provider
android:name="androidx.core.content.FileProvider"
@@ -24,6 +27,7 @@
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
+
</application>

</manifest>
diff --git a/node_modules/react-native-image-crop-picker/android/src/main/java/
com/reactnative/ivpusic/imagepicker/Compression.java b/node_modules/react-native-
image-crop-picker/android/src/main/java/com/reactnative/ivpusic/imagepicker/
Compression.java
index 5ea266c..bc87d3d 100644
--- a/node_modules/react-native-image-crop-picker/android/src/main/java/com/
reactnative/ivpusic/imagepicker/Compression.java
+++ b/node_modules/react-native-image-crop-picker/android/src/main/java/com/
reactnative/ivpusic/imagepicker/Compression.java
@@ -4,11 +4,12 @@ import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.media.ExifInterface;
import android.os.Environment;
import android.util.Log;
import android.util.Pair;

+import androidx.exifinterface.media.ExifInterface;
+
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReadableMap;

@@ -19,6 +20,7 @@ import java.io.IOException;


import java.io.OutputStream;
import java.util.Arrays;
import java.util.List;
+import java.util.Locale;
import java.util.UUID;
/**
@@ -114,8 +116,8 @@ class Compression {
boolean useOriginalWidth = (maxWidth == null || maxWidth >=
bitmapOptions.outWidth);
boolean useOriginalHeight = (maxHeight == null || maxHeight >=
bitmapOptions.outHeight);

- List knownMimes = Arrays.asList("image/jpeg", "image/jpg", "image/png",


"image/gif", "image/tiff");
- boolean isKnownMimeType = (bitmapOptions.outMimeType != null &&
knownMimes.contains(bitmapOptions.outMimeType.toLowerCase()));
+ List<String> knownMimes = Arrays.asList("image/jpeg", "image/jpg",
"image/png", "image/gif", "image/tiff");
+ boolean isKnownMimeType = (bitmapOptions.outMimeType != null &&
knownMimes.contains(bitmapOptions.outMimeType.toLowerCase(Locale.getDefault())));

if (isLossLess && useOriginalWidth && useOriginalHeight &&


isKnownMimeType) {
Log.d("image-crop-picker", "Skipping image compression");
diff --git a/node_modules/react-native-image-crop-picker/android/src/main/java/
com/reactnative/ivpusic/imagepicker/ExifExtractor.java b/node_modules/react-native-
image-crop-picker/android/src/main/java/com/reactnative/ivpusic/imagepicker/
ExifExtractor.java
index ab303e9..0a8afc3 100644
--- a/node_modules/react-native-image-crop-picker/android/src/main/java/com/
reactnative/ivpusic/imagepicker/ExifExtractor.java
+++ b/node_modules/react-native-image-crop-picker/android/src/main/java/com/
reactnative/ivpusic/imagepicker/ExifExtractor.java
@@ -1,7 +1,32 @@
package com.reactnative.ivpusic.imagepicker;

-import android.media.ExifInterface;
-import android.os.Build;
+import static androidx.exifinterface.media.ExifInterface.TAG_APERTURE_VALUE;
+import static androidx.exifinterface.media.ExifInterface.TAG_DATETIME;
+import static androidx.exifinterface.media.ExifInterface.TAG_DATETIME_DIGITIZED;
+import static androidx.exifinterface.media.ExifInterface.TAG_EXPOSURE_TIME;
+import static androidx.exifinterface.media.ExifInterface.TAG_FLASH;
+import static androidx.exifinterface.media.ExifInterface.TAG_FOCAL_LENGTH;
+import static androidx.exifinterface.media.ExifInterface.TAG_GPS_ALTITUDE;
+import static androidx.exifinterface.media.ExifInterface.TAG_GPS_ALTITUDE_REF;
+import static androidx.exifinterface.media.ExifInterface.TAG_GPS_DATESTAMP;
+import static androidx.exifinterface.media.ExifInterface.TAG_GPS_LATITUDE;
+import static androidx.exifinterface.media.ExifInterface.TAG_GPS_LATITUDE_REF;
+import static androidx.exifinterface.media.ExifInterface.TAG_GPS_LONGITUDE;
+import static androidx.exifinterface.media.ExifInterface.TAG_GPS_LONGITUDE_REF;
+import static
androidx.exifinterface.media.ExifInterface.TAG_GPS_PROCESSING_METHOD;
+import static androidx.exifinterface.media.ExifInterface.TAG_GPS_TIMESTAMP;
+import static androidx.exifinterface.media.ExifInterface.TAG_IMAGE_LENGTH;
+import static androidx.exifinterface.media.ExifInterface.TAG_IMAGE_WIDTH;
+import static androidx.exifinterface.media.ExifInterface.TAG_ISO_SPEED;
+import static androidx.exifinterface.media.ExifInterface.TAG_MAKE;
+import static androidx.exifinterface.media.ExifInterface.TAG_MODEL;
+import static androidx.exifinterface.media.ExifInterface.TAG_ORIENTATION;
+import static androidx.exifinterface.media.ExifInterface.TAG_SUBSEC_TIME;
+import static
androidx.exifinterface.media.ExifInterface.TAG_SUBSEC_TIME_DIGITIZED;
+import static androidx.exifinterface.media.ExifInterface.TAG_SUBSEC_TIME_ORIGINAL;
+import static androidx.exifinterface.media.ExifInterface.TAG_WHITE_BALANCE;
+
+import androidx.exifinterface.media.ExifInterface;

import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeMap;
@@ -11,8 +36,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

-import static android.media.ExifInterface.*;


-
class ExifExtractor {

static WritableMap extract(String path) throws IOException {


@@ -20,9 +43,7 @@ class ExifExtractor {

List<String> attributes = getBasicAttributes();

- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {


- attributes.addAll(getLevel23Attributes());
- }
+ attributes.addAll(getLevel23Attributes());

ExifInterface exif = new ExifInterface(path);

@@ -46,7 +67,7 @@ class ExifExtractor {

private static List<String> getBasicAttributes() {


return new ArrayList<>(Arrays.asList(
- TAG_APERTURE,
+ TAG_APERTURE_VALUE,
TAG_DATETIME,
TAG_EXPOSURE_TIME,
TAG_FLASH,
@@ -62,7 +83,7 @@ class ExifExtractor {
TAG_GPS_TIMESTAMP,
TAG_IMAGE_LENGTH,
TAG_IMAGE_WIDTH,
- TAG_ISO,
+ TAG_ISO_SPEED,
TAG_MAKE,
TAG_MODEL,
TAG_ORIENTATION,
@@ -74,8 +95,8 @@ class ExifExtractor {
return new ArrayList<>(Arrays.asList(
TAG_DATETIME_DIGITIZED,
TAG_SUBSEC_TIME,
- TAG_SUBSEC_TIME_DIG,
- TAG_SUBSEC_TIME_ORIG
+ TAG_SUBSEC_TIME_DIGITIZED,
+ TAG_SUBSEC_TIME_ORIGINAL
));
}
}
\ No newline at end of file
diff --git a/node_modules/react-native-image-crop-picker/android/src/main/java/
com/reactnative/ivpusic/imagepicker/GeoDegree.java b/node_modules/react-native-
image-crop-picker/android/src/main/java/com/reactnative/ivpusic/imagepicker/
GeoDegree.java
index 6250c16..d5368b1 100644
--- a/node_modules/react-native-image-crop-picker/android/src/main/java/com/
reactnative/ivpusic/imagepicker/GeoDegree.java
+++ b/node_modules/react-native-image-crop-picker/android/src/main/java/com/
reactnative/ivpusic/imagepicker/GeoDegree.java
@@ -1,6 +1,6 @@
package com.reactnative.ivpusic.imagepicker;

-import android.media.ExifInterface;
+import androidx.exifinterface.media.ExifInterface;

public class GeoDegree {


Float latitude;
diff --git a/node_modules/react-native-image-crop-picker/android/src/main/java/
com/reactnative/ivpusic/imagepicker/PickerModule.java b/node_modules/react-native-
image-crop-picker/android/src/main/java/com/reactnative/ivpusic/imagepicker/
PickerModule.java
index 6335949..40c98bb 100644
--- a/node_modules/react-native-image-crop-picker/android/src/main/java/com/
reactnative/ivpusic/imagepicker/PickerModule.java
+++ b/node_modules/react-native-image-crop-picker/android/src/main/java/com/
reactnative/ivpusic/imagepicker/PickerModule.java
@@ -17,6 +17,7 @@ import android.provider.MediaStore;
import android.util.Base64;
import android.webkit.MimeTypeMap;

+import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.FileProvider;

@@ -45,6 +46,8 @@ import java.util.ArrayList;


import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.Callable;

@@ -96,9 +99,9 @@ class PickerModule extends ReactContextBaseJavaModule implements


ActivityEventLi

private Uri mCameraCaptureURI;


private String mCurrentMediaPath;
- private ResultCollector resultCollector = new ResultCollector();
- private Compression compression = new Compression();
- private ReactApplicationContext reactContext;
+ private final ResultCollector resultCollector = new ResultCollector();
+ private final Compression compression = new Compression();
+ private final ReactApplicationContext reactContext;

PickerModule(ReactApplicationContext reactContext) {
super(reactContext);
@@ -113,6 +116,7 @@ class PickerModule extends ReactContextBaseJavaModule
implements ActivityEventLi
return tmpDir;
}
+ @NonNull
@Override
public String getName() {
return "ImageCropPicker";
@@ -126,8 +130,11 @@ class PickerModule extends ReactContextBaseJavaModule
implements ActivityEventLi
width = options.hasKey("width") ? options.getInt("width") : 0;
height = options.hasKey("height") ? options.getInt("height") : 0;
cropping = options.hasKey("cropping") && options.getBoolean("cropping");
- cropperActiveWidgetColor = options.hasKey("cropperActiveWidgetColor") ?
options.getString("cropperActiveWidgetColor") : null;
- cropperStatusBarColor = options.hasKey("cropperStatusBarColor") ?
options.getString("cropperStatusBarColor") : null;
+ cropperActiveWidgetColor = options.hasKey("cropperActiveWidgetColor")
+ ? options.getString("cropperActiveWidgetColor")
+ : null;
+ cropperStatusBarColor = options.hasKey("cropperStatusBarColor") ?
options.getString("cropperStatusBarColor")
+ : null;
cropperToolbarColor = options.hasKey("cropperToolbarColor") ?
options.getString("cropperToolbarColor") : null;
cropperToolbarTitle = options.hasKey("cropperToolbarTitle") ?
options.getString("cropperToolbarTitle") : null;
cropperToolbarWidgetColor = options.hasKey("cropperToolbarWidgetColor") ?
options.getString("cropperToolbarWidgetColor") : null;
@@ -137,14 +144,15 @@ class PickerModule extends ReactContextBaseJavaModule
implements ActivityEventLi
showCropFrame = !options.hasKey("showCropFrame") ||
options.getBoolean("showCropFrame");
hideBottomControls = options.hasKey("hideBottomControls") &&
options.getBoolean("hideBottomControls");
enableRotationGesture = options.hasKey("enableRotationGesture") &&
options.getBoolean("enableRotationGesture");
- disableCropperColorSetters = options.hasKey("disableCropperColorSetters")
&& options.getBoolean("disableCropperColorSetters");
+ disableCropperColorSetters = options.hasKey("disableCropperColorSetters")
+ && options.getBoolean("disableCropperColorSetters");
useFrontCamera = options.hasKey("useFrontCamera") &&
options.getBoolean("useFrontCamera");
this.options = options;
}

private void deleteRecursive(File fileOrDirectory) {


if (fileOrDirectory.isDirectory()) {
- for (File child : fileOrDirectory.listFiles()) {
+ for (File child : Objects.requireNonNull(fileOrDirectory.listFiles()))
{
deleteRecursive(child);
}
}
@@ -163,23 +171,25 @@ class PickerModule extends ReactContextBaseJavaModule
implements ActivityEventLi
return;
}

- permissionsCheck(activity, promise,
Collections.singletonList(Manifest.permission.WRITE_EXTERNAL_STORAGE), new
Callable<Void>() {
- @Override
- public Void call() {
- try {
- File file = new File(module.getTmpDir(activity));
- if (!file.exists()) throw new Exception("File does not
exist");
-
- module.deleteRecursive(file);
- promise.resolve(null);
- } catch (Exception ex) {
- ex.printStackTrace();
- promise.reject(E_ERROR_WHILE_CLEANING_FILES, ex.getMessage());
- }
+ permissionsCheck(activity, promise,
Collections.singletonList(Manifest.permission.WRITE_EXTERNAL_STORAGE),
+ new Callable<Void>() {
+ @Override
+ public Void call() {
+ try {
+ File file = new File(module.getTmpDir(activity));
+ if (!file.exists())
+ throw new Exception("File does not exist");
+
+ module.deleteRecursive(file);
+ promise.resolve(null);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ promise.reject(E_ERROR_WHILE_CLEANING_FILES,
ex.getMessage());
+ }

- return null;
- }
- });
+ return null;
+ }
+ });
}

@ReactMethod
@@ -197,38 +207,42 @@ class PickerModule extends ReactContextBaseJavaModule
implements ActivityEventLi
return;
}

- permissionsCheck(activity, promise,
Collections.singletonList(Manifest.permission.WRITE_EXTERNAL_STORAGE), new
Callable<Void>() {
- @Override
- public Void call() throws Exception {
- try {
- String path = pathToDelete;
- final String filePrefix = "file://";
- if (path.startsWith(filePrefix)) {
- path = path.substring(filePrefix.length());
- }
+ permissionsCheck(activity, promise,
Collections.singletonList(Manifest.permission.WRITE_EXTERNAL_STORAGE),
+ new Callable<Void>() {
+ @Override
+ public Void call() {
+ try {
+ String path = pathToDelete;
+ final String filePrefix = "file://";
+ if (path.startsWith(filePrefix)) {
+ path = path.substring(filePrefix.length());
+ }

- File file = new File(path);


- if (!file.exists()) throw new Exception("File does not exist.
Path: " + path);
+ File file = new File(path);
+ if (!file.exists())
+ throw new Exception("File does not exist. Path: "
+ path);

- module.deleteRecursive(file);
- promise.resolve(null);
- } catch (Exception ex) {
- ex.printStackTrace();
- promise.reject(E_ERROR_WHILE_CLEANING_FILES, ex.getMessage());
- }
+ module.deleteRecursive(file);
+ promise.resolve(null);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ promise.reject(E_ERROR_WHILE_CLEANING_FILES,
ex.getMessage());
+ }

- return null;
- }
- });
+ return null;
+ }
+ });
}

- private void permissionsCheck(final Activity activity, final Promise promise,


final List<String> requiredPermissions, final Callable<Void> callback) {
+ private void permissionsCheck(final Activity activity, final Promise promise,
+ final List<String> requiredPermissions, final Callable<Void> callback)
{

List<String> missingPermissions = new ArrayList<>();


List<String> supportedPermissions = new ArrayList<>(requiredPermissions);

- // android 11 introduced scoped storage, and WRITE_EXTERNAL_STORAGE no


longer works there
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
+ // android 11 introduced scoped storage, and WRITE_EXTERNAL_STORAGE no
longer
+ // works there
+ if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {

supportedPermissions.remove(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}

@@ -241,39 +255,42 @@ class PickerModule extends ReactContextBaseJavaModule


implements ActivityEventLi

if (!missingPermissions.isEmpty()) {

- ((PermissionAwareActivity)
activity).requestPermissions(missingPermissions.toArray(new
String[missingPermissions.size()]), 1, new PermissionListener() {
-
- @Override
- public boolean onRequestPermissionsResult(int requestCode,
String[] permissions, int[] grantResults) {
- if (requestCode == 1) {
-
- for (int permissionIndex = 0; permissionIndex <
permissions.length; permissionIndex++) {
- String permission = permissions[permissionIndex];
- int grantResult = grantResults[permissionIndex];
+ ((PermissionAwareActivity)
activity).requestPermissions(missingPermissions.toArray(new String[0]), 1,
+ new PermissionListener() {
+
+ @Override
+ public boolean onRequestPermissionsResult(int requestCode,
String[] permissions,
+ int[] grantResults) {
+ if (requestCode == 1) {
+
+ for (int permissionIndex = 0; permissionIndex <
permissions.length; permissionIndex++) {
+ String permission =
permissions[permissionIndex];
+ int grantResult =
grantResults[permissionIndex];
+
+ if (grantResult ==
PackageManager.PERMISSION_DENIED) {
+ if
(permission.equals(Manifest.permission.CAMERA)) {
+
promise.reject(E_NO_CAMERA_PERMISSION_KEY, E_NO_CAMERA_PERMISSION_MSG);
+ } else if
(permission.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
+
promise.reject(E_NO_LIBRARY_PERMISSION_KEY, E_NO_LIBRARY_PERMISSION_MSG);
+ } else {
+ // should not happen, we fallback on
E_NO_LIBRARY_PERMISSION_KEY rejection
+ // for minimal consistency
+
promise.reject(E_NO_LIBRARY_PERMISSION_KEY, "Required permission missing");
+ }
+ return true;
+ }
+ }

- if (grantResult == PackageManager.PERMISSION_DENIED) {
- if (permission.equals(Manifest.permission.CAMERA))
{
- promise.reject(E_NO_CAMERA_PERMISSION_KEY,
E_NO_CAMERA_PERMISSION_MSG);
- } else if
(permission.equals(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
- promise.reject(E_NO_LIBRARY_PERMISSION_KEY,
E_NO_LIBRARY_PERMISSION_MSG);
- } else {
- // should not happen, we fallback on
E_NO_LIBRARY_PERMISSION_KEY rejection for minimal consistency
- promise.reject(E_NO_LIBRARY_PERMISSION_KEY,
"Required permission missing");
+ try {
+ callback.call();
+ } catch (Exception e) {
+ promise.reject(E_CALLBACK_ERROR, "Unknown
error", e);
}
- return true;
}
- }

- try {
- callback.call();
- } catch (Exception e) {
- promise.reject(E_CALLBACK_ERROR, "Unknown error", e);
+ return true;
}
- }
-
- return true;
- }
- });
+ });

return;
}
@@ -303,13 +320,15 @@ class PickerModule extends ReactContextBaseJavaModule
implements ActivityEventLi
setConfiguration(options);
resultCollector.setup(promise, false);

- permissionsCheck(activity, promise,
Arrays.asList(Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE), new Callable<Void>() {
- @Override
- public Void call() {
- initiateCamera(activity);
- return null;
- }
- });
+ permissionsCheck(activity, promise,
+ Arrays.asList(Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE),
+ new Callable<Void>() {
+ @Override
+ public Void call() {
+ initiateCamera(activity);
+ return null;
+ }
+ });
}

private void initiateCamera(Activity activity) {


@@ -328,13 +347,8 @@ class PickerModule extends ReactContextBaseJavaModule
implements ActivityEventLi

Intent cameraIntent = new Intent(intent);

- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {


- mCameraCaptureURI = Uri.fromFile(dataFile);
- } else {
- mCameraCaptureURI = FileProvider.getUriForFile(activity,
- activity.getApplicationContext().getPackageName() +
".provider",
- dataFile);
- }
+ mCameraCaptureURI = FileProvider.getUriForFile(activity,
+ activity.getApplicationContext().getPackageName() +
".provider", dataFile);

cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraCaptureURI);

@@ -363,14 +377,14 @@ class PickerModule extends ReactContextBaseJavaModule


implements ActivityEventLi
if (cropping || mediaType.equals("photo")) {
galleryIntent.setType("image/*");
if (cropping) {
- String[] mimetypes = {"image/jpeg", "image/png"};
+ String[] mimetypes = { "image/jpeg", "image/png" };
galleryIntent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
}
} else if (mediaType.equals("video")) {
galleryIntent.setType("video/*");
} else {
galleryIntent.setType("*/*");
- String[] mimetypes = {"image/*", "video/*"};
+ String[] mimetypes = { "image/*", "video/*" };
galleryIntent.putExtra(Intent.EXTRA_MIME_TYPES, mimetypes);
}

@@ -397,13 +411,14 @@ class PickerModule extends ReactContextBaseJavaModule


implements ActivityEventLi
setConfiguration(options);
resultCollector.setup(promise, multiple);

- permissionsCheck(activity, promise,
Collections.singletonList(Manifest.permission.WRITE_EXTERNAL_STORAGE), new
Callable<Void>() {
- @Override
- public Void call() {
- initiatePicker(activity);
- return null;
- }
- });
+ permissionsCheck(activity, promise,
Collections.singletonList(Manifest.permission.WRITE_EXTERNAL_STORAGE),
+ new Callable<Void>() {
+ @Override
+ public Void call() {
+ initiatePicker(activity);
+ return null;
+ }
+ });
}

@ReactMethod
@@ -432,7 +447,7 @@ class PickerModule extends ReactContextBaseJavaModule
implements ActivityEventLi
InputStream inputStream;

try {
- inputStream = new FileInputStream(new File(absoluteFilePath));
+ inputStream = new FileInputStream(absoluteFilePath);
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
@@ -462,10 +477,10 @@ class PickerModule extends ReactContextBaseJavaModule
implements ActivityEventLi
ContentResolver cr = this.reactContext.getContentResolver();
mimeType = cr.getType(uri);
} else {
- String fileExtension = MimeTypeMap.getFileExtensionFromUrl(uri
- .toString());
+ String fileExtension =
MimeTypeMap.getFileExtensionFromUrl(uri.toString());
if (fileExtension != null) {
- mimeType =
MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension.toLowerCase());
+ mimeType = MimeTypeMap.getSingleton()
+ .getMimeTypeFromExtension(fileExtension.toLowerCase(Locale
.getDefault()));
}
}
return mimeType;
@@ -486,8 +501,8 @@ class PickerModule extends ReactContextBaseJavaModule
implements ActivityEventLi
return getImage(activity, path);
}

- private void getAsyncSelection(final Activity activity, Uri uri, boolean


isCamera) throws Exception {
- String path = resolveRealPath(activity, uri, isCamera);
+ private void getAsyncSelection(final Activity activity, Uri uri) throws
Exception {
+ String path = resolveRealPath(activity, uri, false);
if (path == null || path.isEmpty()) {
resultCollector.notifyProblem(E_NO_IMAGE_DATA_FOUND, "Cannot resolve
asset path.");
return;
@@ -565,21 +580,17 @@ class PickerModule extends ReactContextBaseJavaModule
implements ActivityEventLi
}
}));
}
- }).run();
+ }).start();
}
- private String resolveRealPath(Activity activity, Uri uri, boolean isCamera)
throws IOException {
+ private String resolveRealPath(Activity activity, Uri uri, boolean isCamera) {
String path;

- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {


- path = RealPathUtil.getRealPathFromURI(activity, uri);
+ if (isCamera) {
+ Uri mediaUri = Uri.parse(mCurrentMediaPath);
+ path = mediaUri.getPath();
} else {
- if (isCamera) {
- Uri mediaUri = Uri.parse(mCurrentMediaPath);
- path = mediaUri.getPath();
- } else {
- path = RealPathUtil.getRealPathFromURI(activity, uri);
- }
+ path = RealPathUtil.getRealPathFromURI(activity, uri);
}

return path;
@@ -608,7 +619,8 @@ class PickerModule extends ReactContextBaseJavaModule
implements ActivityEventLi
}
BitmapFactory.Options original = validateImage(path);

- // if compression options are provided image will be compressed. If none


options is provided,
+ // if compression options are provided image will be compressed. If none
options
+ // is provided,
// then original image will be returned
File compressedImage = compression.compressImage(this.reactContext,
options, path, original);
String compressedImagePath = compressedImage.getPath();
@@ -672,10 +684,9 @@ class PickerModule extends ReactContextBaseJavaModule
implements ActivityEventLi

if (enableRotationGesture) {
// UCropActivity.ALL = enable both rotation & scaling
- options.setAllowedGestures(
- UCropActivity.ALL, // When 'scale'-tab active
+ options.setAllowedGestures(UCropActivity.ALL, // When 'scale'-tab
active
UCropActivity.ALL, // When 'rotate'-tab active
- UCropActivity.ALL // When 'aspect ratio'-tab active
+ UCropActivity.ALL // When 'aspect ratio'-tab active
);
}

@@ -705,11 +716,11 @@ class PickerModule extends ReactContextBaseJavaModule


implements ActivityEventLi
// only one image selected
if (clipData == null) {
resultCollector.setWaitCount(1);
- getAsyncSelection(activity, data.getData(), false);
+ getAsyncSelection(activity, data.getData());
} else {
resultCollector.setWaitCount(clipData.getItemCount());
for (int i = 0; i < clipData.getItemCount(); i++) {
- getAsyncSelection(activity,
clipData.getItemAt(i).getUri(), false);
+ getAsyncSelection(activity,
clipData.getItemAt(i).getUri());
}
}
} catch (Exception ex) {
@@ -728,7 +739,7 @@ class PickerModule extends ReactContextBaseJavaModule
implements ActivityEventLi
startCropping(activity, uri);
} else {
try {
- getAsyncSelection(activity, uri, false);
+ getAsyncSelection(activity, uri);
} catch (Exception ex) {
resultCollector.notifyProblem(E_NO_IMAGE_DATA_FOUND,
ex.getMessage());
}
@@ -757,7 +768,8 @@ class PickerModule extends ReactContextBaseJavaModule
implements ActivityEventLi
resultCollector.setWaitCount(1);
WritableMap result = getSelection(activity, uri, true);

- // If recording a video getSelection handles resultCollector


part itself and returns null
+ // If recording a video getSelection handles resultCollector
part itself and
+ // returns null
if (result != null) {
resultCollector.notifySuccess(result);
}
@@ -816,8 +828,7 @@ class PickerModule extends ReactContextBaseJavaModule
implements ActivityEventLi
}

private boolean isCameraAvailable(Activity activity) {


- return
activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)
- ||
activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
+ return
activity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
}

private File createImageFile() throws IOException {


diff --git a/node_modules/react-native-image-crop-picker/android/src/main/java/
com/reactnative/ivpusic/imagepicker/PickerPackage.java b/node_modules/react-native-
image-crop-picker/android/src/main/java/com/reactnative/ivpusic/imagepicker/
PickerPackage.java
index 092ed9b..f4a4d95 100644
--- a/node_modules/react-native-image-crop-picker/android/src/main/java/com/
reactnative/ivpusic/imagepicker/PickerPackage.java
+++ b/node_modules/react-native-image-crop-picker/android/src/main/java/com/
reactnative/ivpusic/imagepicker/PickerPackage.java
@@ -1,7 +1,8 @@
package com.reactnative.ivpusic.imagepicker;

+import androidx.annotation.NonNull;
+
import com.facebook.react.ReactPackage;
-import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
@@ -15,18 +16,16 @@ import java.util.List;
*/
public class PickerPackage implements ReactPackage {

- // Deprecated RN 0.47
- public List<Class<? extends JavaScriptModule>> createJSModules() {
- return Collections.emptyList();
- }
-
+ @NonNull
+ @SuppressWarnings("rawtypes")
@Override
- public List<ViewManager> createViewManagers(ReactApplicationContext
reactContext) {
+ public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext
reactContext) {
return Collections.emptyList();
}

+ @NonNull
@Override
- public List<NativeModule> createNativeModules(ReactApplicationContext
reactContext) {
+ public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext
reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new PickerModule(reactContext));

diff --git a/node_modules/react-native-image-crop-picker/android/src/main/java/


com/reactnative/ivpusic/imagepicker/RealPathUtil.java b/node_modules/react-native-
image-crop-picker/android/src/main/java/com/reactnative/ivpusic/imagepicker/
RealPathUtil.java
index bcc5dd6..6d703c5 100644
--- a/node_modules/react-native-image-crop-picker/android/src/main/java/com/
reactnative/ivpusic/imagepicker/RealPathUtil.java
+++ b/node_modules/react-native-image-crop-picker/android/src/main/java/com/
reactnative/ivpusic/imagepicker/RealPathUtil.java
@@ -1,89 +1,25 @@
package com.reactnative.ivpusic.imagepicker;

import android.annotation.TargetApi;
-import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Build;
-import android.os.Environment;
-import android.provider.DocumentsContract;
import android.provider.MediaStore;

import java.io.File;
import java.io.FileOutputStream;
-import java.io.IOException;
import java.io.InputStream;

class RealPathUtil {
@TargetApi(Build.VERSION_CODES.KITKAT)
- static String getRealPathFromURI(final Context context, final Uri uri) throws
IOException {
+ static String getRealPathFromURI(final Context context, final Uri uri) {

- final boolean isKitKat = Build.VERSION.SDK_INT ==


Build.VERSION_CODES.KITKAT;
-
- // DocumentProvider
- if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
- // ExternalStorageProvider
- if (isExternalStorageDocument(uri)) {
- final String docId = DocumentsContract.getDocumentId(uri);
- final String[] split = docId.split(":");
- final String type = split[0];
-
- if ("primary".equalsIgnoreCase(type)) {
- return Environment.getExternalStorageDirectory() + "/" +
split[1];
- } else {
- final int splitIndex = docId.indexOf(':', 1);
- final String tag = docId.substring(0, splitIndex);
- final String path = docId.substring(splitIndex + 1);
-
- String nonPrimaryVolume = getPathToNonPrimaryVolume(context,
tag);
- if (nonPrimaryVolume != null) {
- String result = nonPrimaryVolume + "/" + path;
- File file = new File(result);
- if (file.exists() && file.canRead()) {
- return result;
- }
- return null;
- }
- }
- }
- // DownloadsProvider
- else if (isDownloadsDocument(uri)) {
- final String id = DocumentsContract.getDocumentId(uri);
- final Uri contentUri = ContentUris.withAppendedId(
- Uri.parse("content://downloads/public_downloads"),
Long.valueOf(id));
-
- return getDataColumn(context, contentUri, null, null);
- }
- // MediaProvider
- else if (isMediaDocument(uri)) {
- final String docId = DocumentsContract.getDocumentId(uri);
- final String[] split = docId.split(":");
- final String type = split[0];
-
- Uri contentUri = null;
- if ("image".equals(type)) {
- contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
- } else if ("video".equals(type)) {
- contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
- } else if ("audio".equals(type)) {
- contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
- }
-
- final String selection = "_id=?";
- final String[] selectionArgs = new String[] {
- split[1]
- };
-
- return getDataColumn(context, contentUri, selection,
selectionArgs);
- }
- }
- // MediaStore (and general)
- else if ("content".equalsIgnoreCase(uri.getScheme())) {
+ if ("content".equalsIgnoreCase(uri.getScheme())) {
// Return the remote address
if (isGooglePhotosUri(uri))
return uri.getLastPathSegment();
- return getDataColumn(context, uri, null, null);
+ return getDataColumn(context, uri);
}
// File
else if ("file".equalsIgnoreCase(uri.getScheme())) {
@@ -98,13 +34,12 @@ class RealPathUtil {
* should be call to download the file in the cache folder.
*
* @param context The context
- * @param fileName donwloaded file's name
+ * @param fileName downloaded file's name
* @param uri file's URI
* @return file that has been written
*/
private static File writeToFile(Context context, String fileName, Uri uri) {
String tmpDir = context.getCacheDir() + "/react-native-image-crop-picker";
- Boolean created = new File(tmpDir).mkdir();
fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
File path = new File(tmpDir);
File file = new File(path, fileName);
@@ -112,7 +47,7 @@ class RealPathUtil {
FileOutputStream oos = new FileOutputStream(file);
byte[] buf = new byte[8192];
InputStream is = context.getContentResolver().openInputStream(uri);
- int c = 0;
+ int c;
while ((c = is.read(buf, 0, buf.length)) > 0) {
oos.write(buf, 0, c);
oos.flush();
@@ -131,22 +66,17 @@ class RealPathUtil {
*
* @param context The context.
* @param uri The Uri to query.
- * @param selection (Optional) Filter used in the query.
- * @param selectionArgs (Optional) Selection arguments used in the query.
* @return The value of the _data column, which is typically a file path.
*/
- private static String getDataColumn(Context context, Uri uri, String
selection,
- String[] selectionArgs) {
+ private static String getDataColumn(Context context, Uri uri) {

- Cursor cursor = null;


final String[] projection = {
MediaStore.MediaColumns.DATA,
MediaStore.MediaColumns.DISPLAY_NAME,
};

- try {
- cursor = context.getContentResolver().query(uri, projection,
selection, selectionArgs,
- null);
+ try (Cursor cursor = context.getContentResolver().query(uri, projection,
null, null,
+ null)) {
if (cursor != null && cursor.moveToFirst()) {
// Fall back to writing to file if _data column does not exist
final int index =
cursor.getColumnIndex(MediaStore.MediaColumns.DATA);
@@ -160,38 +90,10 @@ class RealPathUtil {
return fileWritten.getAbsolutePath();
}
}
- } finally {
- if (cursor != null)
- cursor.close();
}
return null;
}

-
- /**
- * @param uri The Uri to check.
- * @return Whether the Uri authority is ExternalStorageProvider.
- */
- private static boolean isExternalStorageDocument(Uri uri) {
- return "com.android.externalstorage.documents".equals(uri.getAuthority());
- }
-
- /**
- * @param uri The Uri to check.
- * @return Whether the Uri authority is DownloadsProvider.
- */
- private static boolean isDownloadsDocument(Uri uri) {
- return
"com.android.providers.downloads.documents".equals(uri.getAuthority());
- }
-
- /**
- * @param uri The Uri to check.
- * @return Whether the Uri authority is MediaProvider.
- */
- private static boolean isMediaDocument(Uri uri) {
- return "com.android.providers.media.documents".equals(uri.getAuthority());
- }
-
/**
* @param uri The Uri to check.
* @return Whether the Uri authority is Google Photos.
@@ -200,23 +102,4 @@ class RealPathUtil {
return
"com.google.android.apps.photos.content".equals(uri.getAuthority());
}

- @TargetApi(Build.VERSION_CODES.KITKAT)
- private static String getPathToNonPrimaryVolume(Context context, String tag) {
- File[] volumes = context.getExternalCacheDirs();
- if (volumes != null) {
- for (File volume : volumes) {
- if (volume != null) {
- String path = volume.getAbsolutePath();
- if (path != null) {
- int index = path.indexOf(tag);
- if (index != -1) {
- return path.substring(0, index) + tag;
- }
- }
- }
- }
- }
- return null;
- }
-
}
diff --git a/node_modules/react-native-image-crop-picker/android/src/main/java/
com/reactnative/ivpusic/imagepicker/ResultCollector.java b/node_modules/react-
native-image-crop-picker/android/src/main/java/com/reactnative/ivpusic/
imagepicker/ResultCollector.java
index 8bd1b60..6866637 100644
--- a/node_modules/react-native-image-crop-picker/android/src/main/java/com/
reactnative/ivpusic/imagepicker/ResultCollector.java
+++ b/node_modules/react-native-image-crop-picker/android/src/main/java/com/
reactnative/ivpusic/imagepicker/ResultCollector.java
@@ -44,19 +44,19 @@ class ResultCollector {
synchronized private boolean isRequestValid() {
if (resultSent) {
Log.w("image-crop-picker", "Skipping result, already sent...");
- return false;
+ return true;
}

if (promise == null) {
Log.w("image-crop-picker", "Trying to notify success but promise is
not set");
- return false;
+ return true;
}

- return true;
+ return false;
}

synchronized void notifySuccess(WritableMap result) {


- if (!isRequestValid()) {
+ if (isRequestValid()) {
return;
}
@@ -75,7 +75,7 @@ class ResultCollector {
}

synchronized void notifyProblem(String code, String message) {


- if (!isRequestValid()) {
+ if (isRequestValid()) {
return;
}

@@ -85,7 +85,7 @@ class ResultCollector {


}

synchronized void notifyProblem(String code, Throwable throwable) {


- if (!isRequestValid()) {
+ if (isRequestValid()) {
return;
}

You might also like