-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[image_picker_android] Name picked files to match the original filenames where possible #6096
Changes from all commits
ca8ed1e
59266d7
d217cb5
6e7aaf7
bff7f32
8856099
a302713
36b8d2d
bd3ce11
d970a64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.imagepickerexample; | ||
|
||
import static androidx.test.espresso.flutter.EspressoFlutter.onFlutterWidget; | ||
import static androidx.test.espresso.flutter.action.FlutterActions.click; | ||
import static androidx.test.espresso.flutter.assertion.FlutterAssertions.matches; | ||
import static androidx.test.espresso.flutter.matcher.FlutterMatchers.withText; | ||
import static androidx.test.espresso.flutter.matcher.FlutterMatchers.withValueKey; | ||
import static androidx.test.espresso.intent.Intents.intended; | ||
import static androidx.test.espresso.intent.Intents.intending; | ||
import static androidx.test.espresso.intent.matcher.IntentMatchers.hasAction; | ||
|
||
import android.app.Activity; | ||
import android.app.Instrumentation; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import androidx.test.espresso.intent.rule.IntentsTestRule; | ||
import org.junit.Ignore; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TestRule; | ||
|
||
public class ImagePickerPickTest { | ||
|
||
@Rule public TestRule rule = new IntentsTestRule<>(DriverExtensionActivity.class); | ||
|
||
@Test | ||
@Ignore("Doesn't run in Firebase Test Lab: https://github.com/flutter/flutter/issues/94748") | ||
public void imageIsPickedWithOriginalName() { | ||
Instrumentation.ActivityResult result = | ||
new Instrumentation.ActivityResult( | ||
Activity.RESULT_OK, new Intent().setData(Uri.parse("content://dummy/dummy.png"))); | ||
intending(hasAction(Intent.ACTION_GET_CONTENT)).respondWith(result); | ||
onFlutterWidget(withValueKey("image_picker_example_from_gallery")).perform(click()); | ||
onFlutterWidget(withText("PICK")).perform(click()); | ||
intended(hasAction(Intent.ACTION_GET_CONTENT)); | ||
onFlutterWidget(withValueKey("image_picker_example_picked_image_name")) | ||
.check(matches(withText("dummy.png"))); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.imagepickerexample; | ||
|
||
import androidx.annotation.NonNull; | ||
import io.flutter.embedding.android.FlutterActivity; | ||
|
||
public class DriverExtensionActivity extends FlutterActivity { | ||
@NonNull | ||
@Override | ||
public String getDartEntrypointFunctionName() { | ||
return "appMain"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.imagepickerexample; | ||
|
||
import android.content.ContentProvider; | ||
import android.content.ContentValues; | ||
import android.content.res.AssetFileDescriptor; | ||
import android.database.Cursor; | ||
import android.database.MatrixCursor; | ||
import android.net.Uri; | ||
import android.provider.MediaStore; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
public class DummyContentProvider extends ContentProvider { | ||
@Override | ||
public boolean onCreate() { | ||
return true; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public AssetFileDescriptor openAssetFile(@NonNull Uri uri, @NonNull String mode) { | ||
return getContext().getResources().openRawResourceFd(R.raw.ic_launcher); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Cursor query( | ||
@NonNull Uri uri, | ||
@Nullable String[] projection, | ||
@Nullable String selection, | ||
@Nullable String[] selectionArgs, | ||
@Nullable String sortOrder) { | ||
MatrixCursor cursor = new MatrixCursor(new String[] {MediaStore.MediaColumns.DISPLAY_NAME}); | ||
cursor.addRow(new Object[] {"dummy.png"}); | ||
return cursor; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public String getType(@NonNull Uri uri) { | ||
return "image/png"; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public int delete( | ||
@NonNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int update( | ||
@NonNull Uri uri, | ||
@Nullable ContentValues values, | ||
@Nullable String selection, | ||
@Nullable String[] selectionArgs) { | ||
return 0; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment refers to the flutter_logo.png file We generally don't include image files that are non-trivially large in the repo if possible. We prefer to either get them in another repo and import them or if the goal is to have an image to test with, generate a trivial image. @stuartmorgan Do we have this rule in the plugins repo? What do you think about this case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have a specific rule/enforcement around this for flutter/plugins, since checking out the entire repo isn't part of the normal usage of plugins (unlike for flutter/flutter). But using a copy of one of the images that's already in the repo, such as an app icon image from one of the example templates, would be preferable to a new image. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We cannot easily use an existing file, because it needs to be placed in the 'res/raw' folder. But I replaced this logo file with a copy of the smallest icon, just ~500 bytes so it shouldn't be a problem. |
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'm not seeing where the uuid is being added in the original code. This seems to produce a single file named
image_picker.<ext>
in the cache dir rather thanimage_picker<uuid>.<ext>
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
createTempFile
method used in the original code creates a file with a given prefix and suffix, but randomizes the part between them (but it's not explicitly said to be an UUID).