Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Image picker plugin: use the native Android gallery / file chooser #423

Merged
merged 21 commits into from
Mar 29, 2018
Merged

Image picker plugin: use the native Android gallery / file chooser #423

merged 21 commits into from
Mar 29, 2018

Conversation

roughike
Copy link
Contributor

@roughike roughike commented Mar 14, 2018

Changes:

  • Uses the native Android gallery UI for picking images, instead of a custom one
  • removes the image source selection dialog on iOS
  • Breaking API change: now the source named parameter for the pickImage 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":

imgpick

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:

@mtthsfrdrch
Copy link

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 👍

@roughike
Copy link
Contributor Author

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!

@roughike
Copy link
Contributor Author

roughike commented Mar 20, 2018

Pinging @goderbauer @mit-mit who have reviewed and merged image_picker PRs before.

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
Copy link
Contributor

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
Copy link
Contributor

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:".

@Hixie
Copy link
Contributor

Hixie commented Mar 20, 2018

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 - characters (hyphens).

(Our license script uses the eighty hyphen line to distinguish one license from the next in the about box.)

Copy link
Member

@goderbauer goderbauer left a 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.
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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(
Copy link
Member

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,
Copy link
Member

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.

Copy link
Contributor Author

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!

Copy link
Contributor

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

Copy link
Contributor Author

@roughike roughike Mar 21, 2018

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

@goderbauer
Copy link
Member

You'll also need add an entry to the CHANGELOG and bump the version in the pubspec.yaml.

@roughike
Copy link
Contributor Author

@goderbauer Any input on the new version number? It's a breaking change, so I was thinking of 0.4.0.

@@ -0,0 +1,137 @@
/*
Copy link
Member

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?

Copy link
Contributor Author

@roughike roughike Mar 20, 2018

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 ¯_(ツ)_/¯

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @Hixie, see above.

Copy link
Contributor

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.
Copy link
Member

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

Copy link
Contributor

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.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@goderbauer
Copy link
Member

@roughike Yeah, bumping it to 0.0.4 for the breaking change sounds good.

@roughike
Copy link
Contributor Author

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.

@mit-mit
Copy link
Member

mit-mit commented Mar 22, 2018

Just wanted to drop by and say thanks so much @roughike for all the great work here!

@roughike
Copy link
Contributor Author

@mit-mit And this is my way of saying thank you for everything that you guys have done for me :)

@roughike
Copy link
Contributor Author

roughike commented Mar 26, 2018

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 pub global run flutter_plugin_tools format and there's no changed image_picker files.

@goderbauer
Copy link
Member

@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.

@goderbauer
Copy link
Member

@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.
*/
Copy link
Member

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

Copy link
Member

@goderbauer goderbauer left a 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.

@fkorotkov
Copy link
Contributor

@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 script/incremental_build.sh where we try to find a base sha for the branch.

I'll look into fixing incremental_build.sh, for now, @roughike could you please rebase your PR?

@fkorotkov
Copy link
Contributor

Fixed the incremental_build.sh issue in #444. Sorry for the inconvenience. 😅

@roughike
Copy link
Contributor Author

roughike commented Mar 28, 2018

@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
Copy link
Contributor

@roughike haven't you done so? 😅I see a merge commit b4c8b1d. In any case status checks ^^ are green so seems you did it and good to go 👌

@roughike
Copy link
Contributor Author

@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. 👹

@Hixie
Copy link
Contributor

Hixie commented Mar 29, 2018

@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.)

@fkorotkov
Copy link
Contributor

@Hixie it might be an issue if/when we'll try to enable Cirrus on the main flutter/flutter repo. Here, Cirrus CI does a shallow clone only of the repo it's running a build for, e.g. flutter/plugins.

cirrusci/flutter:latest container on the other hand has full flutter repo cloned, so we are ok there 👌

@goderbauer goderbauer merged commit 25f0956 into flutter:master Mar 29, 2018
@@ -6,47 +6,31 @@ import 'dart:async';
import 'dart:io';

import 'package:flutter/services.dart';
import 'package:meta/meta.dart';
Copy link
Member

@goderbauer goderbauer Mar 29, 2018

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Hixie Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
8 participants