@connectedbits/react-native-image-picker 2.4.16-rc1 → 2.4.16-rc2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/.gradle/5.4.1/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/5.4.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/5.4.1/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/5.4.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/5.4.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/.idea/.gitignore +3 -0
- package/android/.idea/compiler.xml +6 -0
- package/android/.idea/gradle.xml +18 -0
- package/android/.idea/jarRepositories.xml +40 -0
- package/android/.idea/ktfmt.xml +6 -0
- package/android/.idea/misc.xml +9 -0
- package/android/.idea/vcs.xml +6 -0
- package/android/src/main/java/com/imagepicker/ImagePickerModule.java +321 -297
- package/package.json +1 -1
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="GradleMigrationSettings" migrationVersion="1" />
|
|
4
|
+
<component name="GradleSettings">
|
|
5
|
+
<option name="linkedExternalProjectsSettings">
|
|
6
|
+
<GradleProjectSettings>
|
|
7
|
+
<option name="testRunner" value="GRADLE" />
|
|
8
|
+
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
|
9
|
+
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
|
10
|
+
<option name="modules">
|
|
11
|
+
<set>
|
|
12
|
+
<option value="$PROJECT_DIR$" />
|
|
13
|
+
</set>
|
|
14
|
+
</option>
|
|
15
|
+
</GradleProjectSettings>
|
|
16
|
+
</option>
|
|
17
|
+
</component>
|
|
18
|
+
</project>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="RemoteRepositoriesConfiguration">
|
|
4
|
+
<remote-repository>
|
|
5
|
+
<option name="id" value="central" />
|
|
6
|
+
<option name="name" value="Maven Central repository" />
|
|
7
|
+
<option name="url" value="https://repo1.maven.org/maven2" />
|
|
8
|
+
</remote-repository>
|
|
9
|
+
<remote-repository>
|
|
10
|
+
<option name="id" value="jboss.community" />
|
|
11
|
+
<option name="name" value="JBoss Community repository" />
|
|
12
|
+
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
|
13
|
+
</remote-repository>
|
|
14
|
+
<remote-repository>
|
|
15
|
+
<option name="id" value="maven" />
|
|
16
|
+
<option name="name" value="maven" />
|
|
17
|
+
<option name="url" value="file:$PROJECT_DIR$/../node_modules/react-native/android/" />
|
|
18
|
+
</remote-repository>
|
|
19
|
+
<remote-repository>
|
|
20
|
+
<option name="id" value="maven2" />
|
|
21
|
+
<option name="name" value="maven2" />
|
|
22
|
+
<option name="url" value="file:$PROJECT_DIR$/../node_modules/jsc-android/dist/" />
|
|
23
|
+
</remote-repository>
|
|
24
|
+
<remote-repository>
|
|
25
|
+
<option name="id" value="MavenLocal" />
|
|
26
|
+
<option name="name" value="MavenLocal" />
|
|
27
|
+
<option name="url" value="file:$USER_HOME$/.m2/repository/" />
|
|
28
|
+
</remote-repository>
|
|
29
|
+
<remote-repository>
|
|
30
|
+
<option name="id" value="BintrayJCenter" />
|
|
31
|
+
<option name="name" value="BintrayJCenter" />
|
|
32
|
+
<option name="url" value="https://jcenter.bintray.com/" />
|
|
33
|
+
</remote-repository>
|
|
34
|
+
<remote-repository>
|
|
35
|
+
<option name="id" value="Google" />
|
|
36
|
+
<option name="name" value="Google" />
|
|
37
|
+
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
|
|
38
|
+
</remote-repository>
|
|
39
|
+
</component>
|
|
40
|
+
</project>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<project version="4">
|
|
2
|
+
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
|
3
|
+
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="zulu-1.8" project-jdk-type="JavaSDK">
|
|
4
|
+
<output url="file://$PROJECT_DIR$/build/classes" />
|
|
5
|
+
</component>
|
|
6
|
+
<component name="ProjectType">
|
|
7
|
+
<option name="id" value="Android" />
|
|
8
|
+
</component>
|
|
9
|
+
</project>
|
|
@@ -11,6 +11,7 @@ import android.graphics.Bitmap;
|
|
|
11
11
|
import android.graphics.BitmapFactory;
|
|
12
12
|
import android.net.Uri;
|
|
13
13
|
import android.os.Build;
|
|
14
|
+
import android.os.Handler;
|
|
14
15
|
import android.provider.MediaStore;
|
|
15
16
|
import android.provider.Settings;
|
|
16
17
|
import androidx.annotation.NonNull;
|
|
@@ -151,62 +152,68 @@ public class ImagePickerModule extends ReactContextBaseJavaModule
|
|
|
151
152
|
|
|
152
153
|
@ReactMethod
|
|
153
154
|
public void showImagePicker(final ReadableMap options, final Callback callback) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (currentActivity == null)
|
|
157
|
-
{
|
|
158
|
-
responseHelper.invokeError(callback, "can't find current Activity");
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
this.callback = callback;
|
|
163
|
-
this.options = options;
|
|
164
|
-
imageConfig = new ImageConfig(0, 0, 100, 0, false);
|
|
165
|
-
|
|
166
|
-
final AlertDialog dialog = UI.chooseDialog(this, options, new UI.OnAction()
|
|
167
|
-
{
|
|
155
|
+
Handler handler = new Handler(this.reactContext.getMainLooper());
|
|
156
|
+
handler.post(new Runnable() {
|
|
168
157
|
@Override
|
|
169
|
-
public void
|
|
170
|
-
|
|
171
|
-
if (module == null)
|
|
172
|
-
{
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
module.launchCamera();
|
|
176
|
-
}
|
|
158
|
+
public void run() {
|
|
159
|
+
Activity currentActivity = getCurrentActivity();
|
|
177
160
|
|
|
178
|
-
|
|
179
|
-
public void onUseLibrary(@NonNull final ImagePickerModule module)
|
|
180
|
-
{
|
|
181
|
-
if (module == null)
|
|
161
|
+
if (currentActivity == null)
|
|
182
162
|
{
|
|
163
|
+
responseHelper.invokeError(callback, "can't find current Activity");
|
|
183
164
|
return;
|
|
184
165
|
}
|
|
185
|
-
module.launchImageLibrary();
|
|
186
|
-
}
|
|
187
166
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (module == null)
|
|
192
|
-
{
|
|
193
|
-
return;
|
|
194
|
-
}
|
|
195
|
-
module.doOnCancel();
|
|
196
|
-
}
|
|
167
|
+
this.callback = callback;
|
|
168
|
+
this.options = options;
|
|
169
|
+
imageConfig = new ImageConfig(0, 0, 100, 0, false);
|
|
197
170
|
|
|
198
|
-
|
|
199
|
-
public void onCustomButton(@NonNull final ImagePickerModule module,
|
|
200
|
-
@NonNull final String action)
|
|
201
|
-
{
|
|
202
|
-
if (module == null)
|
|
171
|
+
final AlertDialog dialog = UI.chooseDialog(this, options, new UI.OnAction()
|
|
203
172
|
{
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
173
|
+
@Override
|
|
174
|
+
public void onTakePhoto(@NonNull final ImagePickerModule module)
|
|
175
|
+
{
|
|
176
|
+
if (module == null)
|
|
177
|
+
{
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
module.launchCamera();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
@Override
|
|
184
|
+
public void onUseLibrary(@NonNull final ImagePickerModule module)
|
|
185
|
+
{
|
|
186
|
+
if (module == null)
|
|
187
|
+
{
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
module.launchImageLibrary();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
@Override
|
|
194
|
+
public void onCancel(@NonNull final ImagePickerModule module)
|
|
195
|
+
{
|
|
196
|
+
if (module == null)
|
|
197
|
+
{
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
module.doOnCancel();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
@Override
|
|
204
|
+
public void onCustomButton(@NonNull final ImagePickerModule module,
|
|
205
|
+
@NonNull final String action)
|
|
206
|
+
{
|
|
207
|
+
if (module == null)
|
|
208
|
+
{
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
module.invokeCustomButton(action);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
dialog.show();
|
|
207
215
|
}
|
|
208
216
|
});
|
|
209
|
-
dialog.show();
|
|
210
217
|
}
|
|
211
218
|
|
|
212
219
|
public void doOnCancel()
|
|
@@ -226,85 +233,91 @@ public class ImagePickerModule extends ReactContextBaseJavaModule
|
|
|
226
233
|
@ReactMethod
|
|
227
234
|
public void launchCamera(final ReadableMap options, final Callback callback)
|
|
228
235
|
{
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
236
|
+
Handler handler = new Handler(this.reactContext.getMainLooper());
|
|
237
|
+
handler.post(new Runnable() {
|
|
238
|
+
@Override
|
|
239
|
+
public void run() {
|
|
240
|
+
permissionRequestCallback = callback;
|
|
241
|
+
|
|
242
|
+
if (!isCameraAvailable())
|
|
243
|
+
{
|
|
244
|
+
responseHelper.invokeError(callback, "Camera not available");
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
final Activity currentActivity = getCurrentActivity();
|
|
249
|
+
if (currentActivity == null)
|
|
250
|
+
{
|
|
251
|
+
responseHelper.invokeError(callback, "can't find current Activity");
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
this.callback = callback;
|
|
256
|
+
this.options = options;
|
|
257
|
+
|
|
258
|
+
if (!permissionsCheck(currentActivity, callback, REQUEST_PERMISSIONS_FOR_CAMERA))
|
|
259
|
+
{
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
parseOptions(this.options);
|
|
264
|
+
|
|
265
|
+
int requestCode;
|
|
266
|
+
Intent cameraIntent;
|
|
267
|
+
|
|
268
|
+
if (pickVideo)
|
|
269
|
+
{
|
|
270
|
+
requestCode = REQUEST_LAUNCH_VIDEO_CAPTURE;
|
|
271
|
+
cameraIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
|
|
272
|
+
cameraIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, videoQuality);
|
|
273
|
+
if (videoDurationLimit > 0)
|
|
274
|
+
{
|
|
275
|
+
cameraIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, videoDurationLimit);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
else
|
|
279
|
+
{
|
|
280
|
+
requestCode = REQUEST_LAUNCH_IMAGE_CAPTURE;
|
|
281
|
+
cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
|
282
|
+
|
|
283
|
+
final File original = createNewFile(reactContext, this.options, false);
|
|
284
|
+
|
|
285
|
+
if (original != null) {
|
|
286
|
+
cameraCaptureURI = RealPathUtil.compatUriFromFile(reactContext, original);
|
|
287
|
+
}else {
|
|
288
|
+
responseHelper.invokeError(callback, "Couldn't get file path for photo");
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
if (cameraCaptureURI == null)
|
|
292
|
+
{
|
|
293
|
+
responseHelper.invokeError(callback, "Couldn't get file path for photo");
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, cameraCaptureURI);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Workaround for Android bug.
|
|
300
|
+
// grantUriPermission also needed for KITKAT,
|
|
301
|
+
// see https://code.google.com/p/android/issues/detail?id=76683
|
|
302
|
+
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
|
|
303
|
+
List<ResolveInfo> resInfoList = reactContext.getPackageManager().queryIntentActivities(cameraIntent, PackageManager.MATCH_DEFAULT_ONLY);
|
|
304
|
+
for (ResolveInfo resolveInfo : resInfoList) {
|
|
305
|
+
String packageName = resolveInfo.activityInfo.packageName;
|
|
306
|
+
reactContext.grantUriPermission(packageName, cameraCaptureURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
try
|
|
311
|
+
{
|
|
312
|
+
currentActivity.startActivityForResult(cameraIntent, requestCode);
|
|
313
|
+
}
|
|
314
|
+
catch (ActivityNotFoundException e)
|
|
315
|
+
{
|
|
316
|
+
e.printStackTrace();
|
|
317
|
+
responseHelper.invokeError(callback, "Cannot launch camera, unable to start");
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
});
|
|
308
321
|
}
|
|
309
322
|
|
|
310
323
|
public void launchImageLibrary()
|
|
@@ -315,208 +328,219 @@ public class ImagePickerModule extends ReactContextBaseJavaModule
|
|
|
315
328
|
@ReactMethod
|
|
316
329
|
public void launchImageLibrary(final ReadableMap options, final Callback callback)
|
|
317
330
|
{
|
|
318
|
-
|
|
331
|
+
Handler handler = new Handler(this.reactContext.getMainLooper());
|
|
332
|
+
handler.post(new Runnable() {
|
|
333
|
+
@Override
|
|
334
|
+
public void run(){
|
|
335
|
+
permissionRequestCallback = callback;
|
|
319
336
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
337
|
+
final Activity currentActivity = getCurrentActivity();
|
|
338
|
+
if (currentActivity == null) {
|
|
339
|
+
responseHelper.invokeError(callback, "can't find current Activity");
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
325
342
|
|
|
326
|
-
|
|
327
|
-
|
|
343
|
+
this.callback = callback;
|
|
344
|
+
this.options = options;
|
|
328
345
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
346
|
+
if (!permissionsCheck(currentActivity, callback, REQUEST_PERMISSIONS_FOR_LIBRARY))
|
|
347
|
+
{
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
333
350
|
|
|
334
|
-
|
|
351
|
+
parseOptions(this.options);
|
|
335
352
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
353
|
+
int requestCode;
|
|
354
|
+
Intent libraryIntent;
|
|
355
|
+
if (pickVideo)
|
|
356
|
+
{
|
|
357
|
+
requestCode = REQUEST_LAUNCH_VIDEO_LIBRARY;
|
|
358
|
+
libraryIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
|
359
|
+
libraryIntent.setType("video/*");
|
|
360
|
+
libraryIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
|
|
361
|
+
libraryIntent.putExtra(Intent.CATEGORY_OPENABLE, true);
|
|
362
|
+
}
|
|
363
|
+
else
|
|
364
|
+
{
|
|
365
|
+
requestCode = REQUEST_LAUNCH_IMAGE_LIBRARY;
|
|
366
|
+
libraryIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
|
367
|
+
libraryIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
|
|
368
|
+
libraryIntent.putExtra(Intent.CATEGORY_OPENABLE, true);
|
|
369
|
+
|
|
370
|
+
if (pickBoth)
|
|
371
|
+
{
|
|
372
|
+
libraryIntent.setType("image/* video/*");
|
|
373
|
+
} else {
|
|
374
|
+
libraryIntent.setType("image/*");
|
|
375
|
+
}
|
|
376
|
+
}
|
|
352
377
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
378
|
+
try
|
|
379
|
+
{
|
|
380
|
+
String chooseWhichLibraryTitle = null;
|
|
381
|
+
if (ReadableMapUtils.hasAndNotEmptyString(options, "chooseWhichLibraryTitle"))
|
|
382
|
+
{
|
|
383
|
+
chooseWhichLibraryTitle = options.getString("chooseWhichLibraryTitle");
|
|
384
|
+
}
|
|
360
385
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
386
|
+
currentActivity.startActivityForResult(Intent.createChooser(libraryIntent, chooseWhichLibraryTitle), requestCode);
|
|
387
|
+
}
|
|
388
|
+
catch (ActivityNotFoundException e)
|
|
389
|
+
{
|
|
390
|
+
e.printStackTrace();
|
|
391
|
+
responseHelper.invokeError(callback, "Cannot launch photo library");
|
|
392
|
+
}
|
|
367
393
|
}
|
|
368
|
-
|
|
369
|
-
currentActivity.startActivityForResult(Intent.createChooser(libraryIntent, chooseWhichLibraryTitle), requestCode);
|
|
370
|
-
}
|
|
371
|
-
catch (ActivityNotFoundException e)
|
|
372
|
-
{
|
|
373
|
-
e.printStackTrace();
|
|
374
|
-
responseHelper.invokeError(callback, "Cannot launch photo library");
|
|
375
|
-
}
|
|
394
|
+
});
|
|
376
395
|
}
|
|
377
396
|
|
|
378
397
|
@Override
|
|
379
398
|
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
399
|
+
Handler handler = new Handler(this.reactContext.getMainLooper());
|
|
400
|
+
handler.post(new Runnable() {
|
|
401
|
+
@Override
|
|
402
|
+
public void run() {
|
|
403
|
+
if (passResult(requestCode))
|
|
404
|
+
{
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
385
407
|
|
|
386
|
-
|
|
408
|
+
responseHelper.cleanResponse();
|
|
387
409
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
410
|
+
// user cancel
|
|
411
|
+
if (resultCode != Activity.RESULT_OK)
|
|
412
|
+
{
|
|
413
|
+
responseHelper.invokeCancel(callback);
|
|
414
|
+
callback = null;
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
395
417
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
418
|
+
Uri uri = null;
|
|
419
|
+
switch (requestCode)
|
|
420
|
+
{
|
|
421
|
+
case REQUEST_LAUNCH_IMAGE_CAPTURE:
|
|
422
|
+
uri = cameraCaptureURI;
|
|
423
|
+
break;
|
|
402
424
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
425
|
+
case REQUEST_LAUNCH_IMAGE_LIBRARY:
|
|
426
|
+
uri = data.getData();
|
|
427
|
+
if(uri == null){
|
|
428
|
+
responseHelper.putString("error", "Could not read photo");
|
|
429
|
+
responseHelper.invokeResponse(callback);
|
|
430
|
+
callback = null;
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
break;
|
|
434
|
+
|
|
435
|
+
case REQUEST_LAUNCH_VIDEO_LIBRARY:
|
|
436
|
+
responseHelper.putString("uri", data.getData().toString());
|
|
407
437
|
responseHelper.invokeResponse(callback);
|
|
408
438
|
callback = null;
|
|
409
439
|
return;
|
|
440
|
+
|
|
441
|
+
case REQUEST_LAUNCH_VIDEO_CAPTURE:
|
|
442
|
+
responseHelper.putString("uri", data.getData().toString());
|
|
443
|
+
responseHelper.invokeResponse(callback);
|
|
444
|
+
callback = null;
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
ReadExifResult result = null;
|
|
449
|
+
try {
|
|
450
|
+
InputStream imageInputStream = reactContext.getContentResolver().openInputStream(uri);
|
|
451
|
+
if(imageInputStream != null){
|
|
452
|
+
result = readExifInterface(imageInputStream, responseHelper);
|
|
410
453
|
}
|
|
411
|
-
|
|
454
|
+
} catch(IOException ex){
|
|
455
|
+
responseHelper.invokeError(callback, ex.getMessage());
|
|
456
|
+
callback = null;
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
if (result == null) {
|
|
460
|
+
responseHelper.invokeError(callback, "Image could not be read");
|
|
461
|
+
callback = null;
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
if (result.error != null)
|
|
465
|
+
{
|
|
466
|
+
responseHelper.invokeError(callback, result.error.getMessage());
|
|
467
|
+
callback = null;
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
412
470
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
471
|
+
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
472
|
+
options.inJustDecodeBounds = true;
|
|
473
|
+
Bitmap imageBitmap = null;
|
|
474
|
+
try {
|
|
475
|
+
InputStream imageInputStream = reactContext.getContentResolver().openInputStream(uri);
|
|
476
|
+
imageBitmap = BitmapFactory.decodeStream(imageInputStream, null, options);
|
|
477
|
+
} catch(FileNotFoundException ex){
|
|
478
|
+
responseHelper.invokeError(callback, "Could not find file");
|
|
479
|
+
callback = null;
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
418
482
|
|
|
419
|
-
case REQUEST_LAUNCH_VIDEO_CAPTURE:
|
|
420
|
-
responseHelper.putString("uri", data.getData().toString());
|
|
421
|
-
responseHelper.invokeResponse(callback);
|
|
422
|
-
callback = null;
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
483
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
InputStream imageInputStream = reactContext.getContentResolver().openInputStream(uri);
|
|
429
|
-
if(imageInputStream != null){
|
|
430
|
-
result = readExifInterface(imageInputStream, responseHelper);
|
|
431
|
-
}
|
|
432
|
-
} catch(IOException ex){
|
|
433
|
-
responseHelper.invokeError(callback, ex.getMessage());
|
|
434
|
-
callback = null;
|
|
435
|
-
return;
|
|
436
|
-
}
|
|
437
|
-
if (result == null) {
|
|
438
|
-
responseHelper.invokeError(callback, "Image could not be read");
|
|
439
|
-
callback = null;
|
|
440
|
-
return;
|
|
441
|
-
}
|
|
442
|
-
if (result.error != null)
|
|
443
|
-
{
|
|
444
|
-
responseHelper.invokeError(callback, result.error.getMessage());
|
|
445
|
-
callback = null;
|
|
446
|
-
return;
|
|
447
|
-
}
|
|
484
|
+
int initialWidth = options.outWidth;
|
|
485
|
+
int initialHeight = options.outHeight;
|
|
448
486
|
|
|
449
|
-
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
450
|
-
options.inJustDecodeBounds = true;
|
|
451
|
-
Bitmap imageBitmap = null;
|
|
452
|
-
try {
|
|
453
|
-
InputStream imageInputStream = reactContext.getContentResolver().openInputStream(uri);
|
|
454
|
-
imageBitmap = BitmapFactory.decodeStream(imageInputStream, null, options);
|
|
455
|
-
} catch(FileNotFoundException ex){
|
|
456
|
-
responseHelper.invokeError(callback, "Could not find file");
|
|
457
|
-
callback = null;
|
|
458
|
-
return;
|
|
459
|
-
}
|
|
460
487
|
|
|
488
|
+
// don't create a new file if contraint are respected
|
|
489
|
+
if (imageConfig.useOriginal(initialWidth, initialHeight, result.currentRotation))
|
|
490
|
+
{
|
|
491
|
+
responseHelper.putInt("width", initialWidth);
|
|
492
|
+
responseHelper.putInt("height", initialHeight);
|
|
493
|
+
|
|
494
|
+
try {
|
|
495
|
+
InputStream imageInputStream = reactContext.getContentResolver().openInputStream(uri);
|
|
496
|
+
updatedResultResponse(imageInputStream);
|
|
497
|
+
} catch(FileNotFoundException ex){
|
|
498
|
+
responseHelper.invokeError(callback, "Could not find file");
|
|
499
|
+
callback = null;
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
else
|
|
504
|
+
{
|
|
505
|
+
Bitmap resizedImage = null;
|
|
506
|
+
ImageConfig rotatedImageConfig = imageConfig.withRotation(result.currentRotation);
|
|
507
|
+
try {
|
|
508
|
+
InputStream imageInputStream = reactContext.getContentResolver().openInputStream(uri);
|
|
509
|
+
resizedImage = getResizedImage(imageInputStream, rotatedImageConfig, initialWidth, initialHeight);
|
|
510
|
+
} catch(FileNotFoundException ex){
|
|
511
|
+
responseHelper.invokeError(callback, "Could not find file");
|
|
512
|
+
callback = null;
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
461
515
|
|
|
462
|
-
|
|
463
|
-
|
|
516
|
+
if (resizedImage == null)
|
|
517
|
+
{
|
|
518
|
+
responseHelper.putString("error", "Can't resize the image");
|
|
519
|
+
}
|
|
520
|
+
else
|
|
521
|
+
{
|
|
522
|
+
responseHelper.putInt("width", resizedImage.getWidth());
|
|
523
|
+
responseHelper.putInt("height", resizedImage.getHeight());
|
|
524
|
+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
525
|
+
resizedImage.compress(Bitmap.CompressFormat.JPEG, imageConfig.quality, bos);
|
|
526
|
+
byte[] bitmapdata = bos.toByteArray();
|
|
527
|
+
ByteArrayInputStream bs = new ByteArrayInputStream(bitmapdata);
|
|
528
|
+
updatedResultResponse(bs);
|
|
529
|
+
resizedImage.recycle();
|
|
530
|
+
resizedImage = null;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
if(imageBitmap != null){
|
|
534
|
+
imageBitmap.recycle();
|
|
535
|
+
imageBitmap = null;
|
|
536
|
+
}
|
|
464
537
|
|
|
465
538
|
|
|
466
|
-
|
|
467
|
-
if (imageConfig.useOriginal(initialWidth, initialHeight, result.currentRotation))
|
|
468
|
-
{
|
|
469
|
-
responseHelper.putInt("width", initialWidth);
|
|
470
|
-
responseHelper.putInt("height", initialHeight);
|
|
471
|
-
|
|
472
|
-
try {
|
|
473
|
-
InputStream imageInputStream = reactContext.getContentResolver().openInputStream(uri);
|
|
474
|
-
updatedResultResponse(imageInputStream);
|
|
475
|
-
} catch(FileNotFoundException ex){
|
|
476
|
-
responseHelper.invokeError(callback, "Could not find file");
|
|
477
|
-
callback = null;
|
|
478
|
-
return;
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
else
|
|
482
|
-
{
|
|
483
|
-
Bitmap resizedImage = null;
|
|
484
|
-
ImageConfig rotatedImageConfig = imageConfig.withRotation(result.currentRotation);
|
|
485
|
-
try {
|
|
486
|
-
InputStream imageInputStream = reactContext.getContentResolver().openInputStream(uri);
|
|
487
|
-
resizedImage = getResizedImage(imageInputStream, rotatedImageConfig, initialWidth, initialHeight);
|
|
488
|
-
} catch(FileNotFoundException ex){
|
|
489
|
-
responseHelper.invokeError(callback, "Could not find file");
|
|
539
|
+
responseHelper.invokeResponse(callback);
|
|
490
540
|
callback = null;
|
|
491
|
-
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
if (resizedImage == null)
|
|
495
|
-
{
|
|
496
|
-
responseHelper.putString("error", "Can't resize the image");
|
|
497
|
-
}
|
|
498
|
-
else
|
|
499
|
-
{
|
|
500
|
-
responseHelper.putInt("width", resizedImage.getWidth());
|
|
501
|
-
responseHelper.putInt("height", resizedImage.getHeight());
|
|
502
|
-
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
503
|
-
resizedImage.compress(Bitmap.CompressFormat.JPEG, imageConfig.quality, bos);
|
|
504
|
-
byte[] bitmapdata = bos.toByteArray();
|
|
505
|
-
ByteArrayInputStream bs = new ByteArrayInputStream(bitmapdata);
|
|
506
|
-
updatedResultResponse(bs);
|
|
507
|
-
resizedImage.recycle();
|
|
508
|
-
resizedImage = null;
|
|
541
|
+
this.options = null;
|
|
509
542
|
}
|
|
510
|
-
}
|
|
511
|
-
if(imageBitmap != null){
|
|
512
|
-
imageBitmap.recycle();
|
|
513
|
-
imageBitmap = null;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
responseHelper.invokeResponse(callback);
|
|
518
|
-
callback = null;
|
|
519
|
-
this.options = null;
|
|
543
|
+
});
|
|
520
544
|
}
|
|
521
545
|
|
|
522
546
|
public void invokeCustomButton(@NonNull final String action)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@connectedbits/react-native-image-picker",
|
|
3
|
-
"version": "2.4.16-
|
|
3
|
+
"version": "2.4.16-rc2",
|
|
4
4
|
"description": "A React Native module that allows you to use native UI to select media from the device library or directly from the camera",
|
|
5
5
|
"react-native": "src/index.ts",
|
|
6
6
|
"types": "lib/typescript/index.d.ts",
|