-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Image picker plugin: use the native Android gallery / file chooser #423
Image picker plugin: use the native Android gallery / file chooser #423
Conversation
…the ask user selection.
…r a scaled image.
hehe, started to do this as well, yesterday, but you were faster 😉 ... the library dependencies on the Android side could be removed as well now 👍 |
Sorry about that 👹 Actually, it still depends on the third-party library to take images with the camera. The plan is to refactor that out too when/if this gets merged first! |
Pinging @goderbauer @mit-mit who have reviewed and merged If there's something wonky about this, I would be happy to hear some feedback! :) |
import android.text.TextUtils; | ||
|
||
/* | ||
* Copyright (C) 2007-2008 OpenIntents.org |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this comment to the top of the file.
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* A modified version of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than just "A modified version of", please say something like "This file was modified by the Flutter authors from the following original file:".
Please make sure you append https://raw.githubusercontent.com/iPaulPro/aFileChooser/master/LICENSE.txt to the end of https://github.com/flutter/plugins/blob/master/packages/image_picker/LICENSE, separated from the previous license by a single line of exactly eighty (Our license script uses the eighty hyphen line to distinguish one license from the next in the about box.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution.
/cc @jonahwilliams, who also recently modified this plugin and might be intersted.
gallery, | ||
} | ||
|
||
class ImagePicker { | ||
static const MethodChannel _channel = const MethodChannel('image_picker'); | ||
static const MethodChannel _channel = | ||
const MethodChannel('plugins.flutter.io/image_picker'); | ||
|
||
/// Returns a [File] object pointing to the image that was picked. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update this doc comment? It should include that you have to specify the source parameter and no longer say that it all allows the user to chose.
@@ -0,0 +1,51 @@ | |||
package io.flutter.plugins.imagepicker; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file needs a license header (see existing source files).
@@ -0,0 +1,132 @@ | |||
package io.flutter.plugins.imagepicker; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file needs a license header (see existing source files).
@@ -0,0 +1,66 @@ | |||
package io.flutter.plugins.imagepicker; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file needs a license header (see existing source files).
@@ -104,7 +99,7 @@ public void onMethodCall(MethodCall call, Result result) { | |||
new String[] { | |||
Manifest.permission.CAMERA, Manifest.permission.READ_EXTERNAL_STORAGE | |||
}, | |||
REQUEST_PERMISSIONS); | |||
REQUEST_CAMERA_PERMISSIONS); | |||
break; | |||
} | |||
activity.startActivityForResult( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a TODO here that the Camera should also be switched to use the native camera?
/// On iOS, the user is presented with an alert box with options to | ||
/// either take a photo using the device camera or pick an image from | ||
/// the photo library. | ||
askUser, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this feature (and thus the default value) is a breaking change - I think it would be a good idea to send an email to [email protected] letting people know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally there was no way of choosing a source for the images. The native sides of this plugin had the "source chooser dialogs" on iOS and Android. I introduced an option of controlling the image source in #271, and I think I should've removed the dialogs back then, but I didn't want to break anything.
(that was just me rationalizing why I did this breaking change :))
I can do the email when/if this PR gets approved, thanks for the idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prefer to warn people in advance of landing the PRs -- see https://flutter.io/design-principles/#handling-breaking-changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I just read it through and that makes a lot of sense!
It's now here: https://groups.google.com/forum/#!topic/flutter-dev/YE5tM2Y0BP8
You'll also need add an entry to the CHANGELOG and bump the version in the pubspec.yaml. |
@goderbauer Any input on the new version number? It's a breaking change, so I was thinking of |
@@ -0,0 +1,137 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This differs from the license header in the source file you mentioned below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original authors' LICENSE file states Copyright 2011 - 2013 Paul Burke
and the file header Copyright (C) 2007-2008 OpenIntents.org
.
I wanted to have this uniformed, but I'm not sure which one to use ¯_(ツ)_/¯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @Hixie, see above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file header should be copied verbatim and unchanged.
* https://raw.githubusercontent.com/iPaulPro/aFileChooser/master/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java | ||
*/ | ||
|
||
// Copyright 2017 The Chromium Authors. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably only want one license header (the one from the original file)
/cc @Hixie
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, don't add a new license here, this file is under the original license.
packages/image_picker/LICENSE
Outdated
@@ -24,3 +24,17 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
-------------------------------------------------------------------------------- | |||
Copyright 2011 - 2013 Paul Burke |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the content of https://raw.githubusercontent.com/iPaulPro/aFileChooser/master/LICENSE.txt?
/cc @Hixie
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must be the contents of https://raw.githubusercontent.com/iPaulPro/aFileChooser/master/LICENSE.txt.
@roughike Yeah, bumping it to 0.0.4 for the breaking change sounds good. |
It's sleepy time in Finland right now. I'll get back to this tomorrow. At least the license & file headers have to be fixed. Also, the example in the README must be modified a bit; the current one won't compile because of the breaking API changes. |
Just wanted to drop by and say thanks so much @roughike for all the great work here! |
@mit-mit And this is my way of saying thank you for everything that you guys have done for me :) |
Hey! Just a friendly Monday evening ping. The breaking change announcement on the flutter-dev mailing group has been live for 4 days now. So far, it hasn't gotten any comments. Being a noob to mailing groups, I accidentally posted it twice. Are we going to wait for a full week or how are things looking from that end? :) Also, AFAIK, I've addressed all feedback and change requests. Please let me know if I missed something or if there's any additional work needed to be done. The Cirrus CI build failures shouldn't be my fault; I double checked by running |
@roughike Sorry for the delay. I was OOO for the last few days. Once I am all caught up I will take another looks at this. |
@fkorotkov (you added the Cirrus CI to this repository): Any idea why Cirrus is consistently failing on this PR (even after multiple re-runs) without a clear exception whereas travis is just running fine? |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now missing the following note that @Hixie wanted included below the license.
This file was modified by the Flutter authors from the following original file: https://raw.githubusercontent.com/iPaulPro/aFileChooser/master/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, this looks good to me modulo the attribution comment I made.
@goderbauer I think the issue is that this branch is pretty out dated. Cirrus CI does a single branch clone with only 50 commits in history. This seems to break logic in I'll look into fixing |
Fixed the |
@fkorotkov Now that the build is mysteriously not broken anymore, do you still need me to rebase the PR? :) I've never done that before and I was just figuring it out. |
@fkorotkov Oh I see, I thought you meant something like this: https://github.com/edx/edx-platform/wiki/How-to-Rebase-a-Pull-Request. I thought it was going to be a long night for me. 👹 |
@fkorotkov fwiw, flutter needs the complete history to figure out its version number; not sure if that is relevant to your point or not. (Well, specifically, it needs the most recent tag and all the commits since then.) |
@Hixie it might be an issue if/when we'll try to enable Cirrus on the main
|
@@ -6,47 +6,31 @@ import 'dart:async'; | |||
import 'dart:io'; | |||
|
|||
import 'package:flutter/services.dart'; | |||
import 'package:meta/meta.dart'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just trying to publish the new version and pub is complaining that package:meta is not a dependency declared in the pubspec.yaml. If you have a change, can you send a follow-up PR that ads the dependency and I'll then publish the new version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird, shouldn't it automatically come with Flutter? I've never had to define package:meta as a dependency in pubspec.yaml if I was already depending on Flutter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import flutter foundation for meta
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Hixie Thanks!
Changes:
source
named parameter for thepickImage
method is annotated with@required
.Issues fixed:
Currently, the image picker plugin uses a custom gallery UI from this library, instead of the native one. I'll guess that the original reason for that is that picking images by using the native gallery can be quite wonky.
While this worked fine on my emulator and Motorola Z, there might be a risk that this breaks picking images from gallery for some devices.
Here's what I mean by "native Android gallery":
I also refactored the image resizing and Exif data copying logic to separate classes to make the code cleaner.
Here's what's currently missing to land this, feel free to give further feedback: