Skip to content

Commit

Permalink
adds android image picker options
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrinneal committed Mar 7, 2023
1 parent 789e3a7 commit 120f005
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 15 deletions.
3 changes: 2 additions & 1 deletion packages/image_picker/image_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 0.8.6+5

* Adds `usePhotoPickerAndroid` options.
* Aligns Dart and Flutter SDK constraints.

## 0.8.6+4
Expand Down
25 changes: 25 additions & 0 deletions packages/image_picker/image_picker/lib/image_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:image_picker_android/image_picker_android.dart';
import 'package:image_picker_platform_interface/image_picker_platform_interface.dart';

export 'package:image_picker_platform_interface/image_picker_platform_interface.dart'
Expand Down Expand Up @@ -352,3 +353,27 @@ class ImagePicker {
return platform.getLostData();
}
}

/// Android specific settings for [ImagePicker].
class AndroidImagePicker {
AndroidImagePicker._();

/// Whether to select images with the Android 13 Photo Picker.
///
/// The Android 13 Photo Picker does not support cloud file selection.
static bool get useAndroidPhotoPicker {
final ImagePickerPlatform platform = ImagePickerPlatform.instance;
if (platform is ImagePickerAndroid) {
return platform.useAndroidPhotoPicker;
}
return false;
}

/// Set whether to select images with the Android 13 Photo Picker.
static set useAndroidPhotoPicker(bool useAndroidPhotoPicker) {
final ImagePickerPlatform platform = ImagePickerPlatform.instance;
if (platform is ImagePickerAndroid) {
platform.useAndroidPhotoPicker = useAndroidPhotoPicker;
}
}
}
2 changes: 1 addition & 1 deletion packages/image_picker/image_picker/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for selecting images from the Android and iOS image
library, and taking new pictures with the camera.
repository: https://github.com/flutter/packages/tree/main/packages/image_picker/image_picker
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
version: 0.8.6+4
version: 0.8.6+5

environment:
sdk: ">=2.17.0 <3.0.0"
Expand Down
3 changes: 2 additions & 1 deletion packages/image_picker/image_picker_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 0.8.6+10

* Adds `usePhotoPickerAndroid` options.
* Aligns Dart and Flutter SDK constraints.

## 0.8.5+9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ public void chooseVideoFromGallery(MethodCall methodCall, MethodChannel.Result r
return;
}

launchPickVideoFromGalleryIntent();
launchPickVideoFromGalleryIntent(methodCall.useAndroidPhotoPicker);
}

private void launchPickVideoFromGalleryIntent() {
private void launchPickVideoFromGalleryIntent(Boolean useAndroidPhotoPicker) {
Intent pickVideoIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (useAndroidPhotoPicker && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
pickVideoIntent =
new ActivityResultContracts.PickVisualMedia()
.createIntent(
Expand Down Expand Up @@ -326,7 +326,7 @@ public void chooseImageFromGallery(MethodCall methodCall, MethodChannel.Result r
return;
}

launchPickImageFromGalleryIntent();
launchPickImageFromGalleryIntent(methodCall.useAndroidPhotoPicker);
}

public void chooseMultiImageFromGallery(MethodCall methodCall, MethodChannel.Result result) {
Expand All @@ -335,12 +335,12 @@ public void chooseMultiImageFromGallery(MethodCall methodCall, MethodChannel.Res
return;
}

launchMultiPickImageFromGalleryIntent();
launchMultiPickImageFromGalleryIntent(methodCall.useAndroidPhotoPicker);
}

private void launchPickImageFromGalleryIntent() {
private void launchPickImageFromGalleryIntent(Boolean useAndroidPhotoPicker) {
Intent pickImageIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (useAndroidPhotoPicker && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
pickImageIntent =
new ActivityResultContracts.PickVisualMedia()
.createIntent(
Expand All @@ -356,9 +356,9 @@ private void launchPickImageFromGalleryIntent() {
activity.startActivityForResult(pickImageIntent, REQUEST_CODE_CHOOSE_IMAGE_FROM_GALLERY);
}

private void launchMultiPickImageFromGalleryIntent() {
private void launchMultiPickImageFromGalleryIntent(Boolean useAndroidPhotoPicker) {
Intent pickMultiImageIntent;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
if (useAndroidPhotoPicker && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
pickMultiImageIntent =
new ActivityResultContracts.PickMultipleVisualMedia()
.createIntent(
Expand Down Expand Up @@ -716,4 +716,4 @@ private void useFrontCamera(Intent intent) {
intent.putExtra("android.intent.extras.CAMERA_FACING", 1);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class ImagePickerAndroid extends ImagePickerPlatform {
'maxWidth': maxWidth,
'maxHeight': maxHeight,
'imageQuality': imageQuality,
'useAndroidPhotoPicker': useAndroidPhotoPicker,
},
);
}
Expand Down Expand Up @@ -117,6 +118,7 @@ class ImagePickerAndroid extends ImagePickerPlatform {
'imageQuality': imageQuality,
'cameraDevice': preferredCameraDevice.index,
'requestFullMetadata': requestFullMetadata,
'useAndroidPhotoPicker': useAndroidPhotoPicker,
},
);
}
Expand Down Expand Up @@ -145,7 +147,8 @@ class ImagePickerAndroid extends ImagePickerPlatform {
<String, dynamic>{
'source': source.index,
'maxDuration': maxDuration?.inSeconds,
'cameraDevice': preferredCameraDevice.index
'cameraDevice': preferredCameraDevice.index,
'useAndroidPhotoPicker': useAndroidPhotoPicker,
},
);
}
Expand Down Expand Up @@ -279,4 +282,9 @@ class ImagePickerAndroid extends ImagePickerPlatform {
files: pickedFileList,
);
}

/// Set [ImagePickerPlatform] to use [AndroidPhotoPicker]
///
/// Currently defaults to false, but the default is subject to change.
bool useAndroidPhotoPicker = false;
}
2 changes: 1 addition & 1 deletion packages/image_picker/image_picker_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Android implementation of the image_picker plugin.
repository: https://github.com/flutter/packages/tree/main/packages/image_picker/image_picker_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22

version: 0.8.5+9
version: 0.8.5+10

environment:
sdk: ">=2.17.0 <3.0.0"
Expand Down

0 comments on commit 120f005

Please sign in to comment.