-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[file_selector_android] Create initial Android implementation of the file_selector package #3814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
241eadc
8619800
7ebaa32
a7f88ad
7ad4d46
40a6178
25f36b1
87179de
ba934f9
0dbdc12
13f55ee
1f28c7d
017ed72
fe605c0
0fec82b
f179ab0
1002bc3
32c440b
f45cc08
2adae90
b49eab6
a513192
9cd2774
b8aae60
6c92c72
82a6c79
7725cc5
a6a4066
6d7a340
750e588
0e5e416
1b08e94
56dcdd8
be9dcc8
4e6c548
407a118
fb8485b
b165ed4
2673f12
c5643ae
d25a689
6ae37e6
20c55f8
12070b6
9498a56
a99550a
0942fb8
f3b07c8
33c3801
21419de
8dfc2b1
882acb7
e351b7a
dc85a97
b809399
f83d6f3
e84c565
6074461
d667d8a
2b72838
9827799
fff7692
245336d
0ceef57
563e570
66b32aa
791c67e
7d50a42
443e4c8
776a771
b85e1a7
018aa30
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,3 @@ | ||
| ## 0.0.1 | ||
|
|
||
| * Implements file_selector_platform_interface for Android. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| Copyright 2013 The Flutter Authors. All rights reserved. | ||
|
|
||
| Redistribution and use in source and binary forms, with or without modification, | ||
| are permitted provided that the following conditions are met: | ||
|
|
||
| * Redistributions of source code must retain the above copyright | ||
| notice, this list of conditions and the following disclaimer. | ||
| * Redistributions in binary form must reproduce the above | ||
| copyright notice, this list of conditions and the following | ||
| disclaimer in the documentation and/or other materials provided | ||
| with the distribution. | ||
| * Neither the name of Google Inc. nor the names of its | ||
| contributors may be used to endorse or promote products derived | ||
| from this software without specific prior written permission. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
| ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
| WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
| ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
| (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| LOSS OF USE, 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # file\_selector\_android | ||
|
|
||
| The Android implementation of [`file_selector`][1]. | ||
|
|
||
| ## Usage | ||
|
|
||
| This package is [endorsed][2], which means you can simply use `file_selector` | ||
| normally. This package will be automatically included in your app when you do, | ||
| so you do not need to add it to your `pubspec.yaml`. | ||
|
|
||
| However, if you `import` this package to use any of its APIs directly, you | ||
| should add it to your `pubspec.yaml` as usual. | ||
|
|
||
| [1]: https://pub.dev/packages/file_selector | ||
| [2]: https://flutter.dev/docs/development/packages-and-plugins/developing-packages#endorsed-federated-plugin |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| group 'io.flutter.plugins.file_selector_android' | ||
| version '1.0' | ||
|
|
||
| buildscript { | ||
| repositories { | ||
| google() | ||
| mavenCentral() | ||
| } | ||
|
|
||
| dependencies { | ||
| classpath 'com.android.tools.build:gradle:7.3.0' | ||
| } | ||
| } | ||
|
|
||
| rootProject.allprojects { | ||
| repositories { | ||
| google() | ||
| mavenCentral() | ||
| } | ||
| } | ||
|
|
||
| apply plugin: 'com.android.library' | ||
|
|
||
| android { | ||
| namespace 'io.flutter.plugins.file_selector_android' | ||
|
Contributor
Author
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. @stuartmorgan Is there a preference for the org of new Android implementations? This is the standard, but I think new ones should be
Collaborator
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. Yes, we should definitely use |
||
| compileSdkVersion 33 | ||
|
|
||
| compileOptions { | ||
| sourceCompatibility JavaVersion.VERSION_1_8 | ||
| targetCompatibility JavaVersion.VERSION_1_8 | ||
| } | ||
|
|
||
| defaultConfig { | ||
| minSdkVersion 16 | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation 'androidx.annotation:annotation:1.5.0' | ||
| testImplementation 'junit:junit:4.13.2' | ||
| testImplementation 'org.mockito:mockito-inline:5.1.0' | ||
| testImplementation 'androidx.test:core:1.3.0' | ||
| } | ||
|
|
||
| lintOptions { | ||
| checkAllWarnings true | ||
| warningsAsErrors true | ||
| disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency' | ||
| } | ||
|
|
||
| testOptions { | ||
| unitTests.includeAndroidResources = true | ||
| unitTests.returnDefaultValues = true | ||
| unitTests.all { | ||
| testLogging { | ||
| events "passed", "skipped", "failed", "standardOut", "standardError" | ||
| outputs.upToDateWhen {false} | ||
| showStandardStreams = true | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| rootProject.name = 'file_selector_android' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="io.flutter.plugins.file_selector_android"> | ||
| </manifest> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // 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.file_selector_android; | ||
|
|
||
| import androidx.annotation.NonNull; | ||
| import io.flutter.embedding.engine.plugins.FlutterPlugin; | ||
| import io.flutter.plugin.common.MethodCall; | ||
| import io.flutter.plugin.common.MethodChannel; | ||
| import io.flutter.plugin.common.MethodChannel.MethodCallHandler; | ||
| import io.flutter.plugin.common.MethodChannel.Result; | ||
|
|
||
| /** FileSelectorAndroidPlugin */ | ||
| public class FileSelectorAndroidPlugin implements FlutterPlugin, MethodCallHandler { | ||
| /// The MethodChannel that will the communication between Flutter and native Android | ||
| /// | ||
| /// This local reference serves to register the plugin with the Flutter Engine and unregister it | ||
| /// when the Flutter Engine is detached from the Activity | ||
| private MethodChannel channel; | ||
|
|
||
| @Override | ||
| public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) { | ||
| channel = new MethodChannel(flutterPluginBinding.getBinaryMessenger(), "file_selector_android"); | ||
| channel.setMethodCallHandler(this); | ||
| } | ||
|
|
||
| @Override | ||
| public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { | ||
| if (call.method.equals("getPlatformVersion")) { | ||
| result.success("Android " + android.os.Build.VERSION.RELEASE); | ||
| } else { | ||
| result.notImplemented(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { | ||
| channel.setMethodCallHandler(null); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // 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.file_selector_android; | ||
|
|
||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.verify; | ||
|
|
||
| import io.flutter.plugin.common.MethodCall; | ||
| import io.flutter.plugin.common.MethodChannel; | ||
| import org.junit.Test; | ||
|
|
||
| /** | ||
| * This demonstrates a simple unit test of the Java portion of this plugin's implementation. | ||
| * | ||
| * <p>Once you have built the plugin's example app, you can run these tests from the command line by | ||
| * running `./gradlew testDebugUnitTest` in the `example/android/` directory, or you can run them | ||
| * directly from IDEs that support JUnit such as Android Studio. | ||
| */ | ||
| public class FileSelectorAndroidPluginTest { | ||
| @Test | ||
| public void onMethodCall_getPlatformVersion_returnsExpectedValue() { | ||
| FileSelectorAndroidPlugin plugin = new FileSelectorAndroidPlugin(); | ||
|
|
||
| final MethodCall call = new MethodCall("getPlatformVersion", null); | ||
| MethodChannel.Result mockResult = mock(MethodChannel.Result.class); | ||
| plugin.onMethodCall(call, mockResult); | ||
|
|
||
| verify(mockResult).success("Android " + android.os.Build.VERSION.RELEASE); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Platform Implementation Test App | ||
|
|
||
| This is a test app for manual testing and automated integration testing | ||
| of this platform implementation. It is not intended to demonstrate actual use of | ||
| this package, since the intent is that plugin clients use the app-facing | ||
| package. | ||
|
|
||
| Unless you are making changes to this implementation package, this example is | ||
| very unlikely to be relevant. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| def localProperties = new Properties() | ||
| def localPropertiesFile = rootProject.file('local.properties') | ||
| if (localPropertiesFile.exists()) { | ||
| localPropertiesFile.withReader('UTF-8') { reader -> | ||
| localProperties.load(reader) | ||
| } | ||
| } | ||
|
|
||
| def flutterRoot = localProperties.getProperty('flutter.sdk') | ||
| if (flutterRoot == null) { | ||
| throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") | ||
| } | ||
|
|
||
| def flutterVersionCode = localProperties.getProperty('flutter.versionCode') | ||
| if (flutterVersionCode == null) { | ||
| flutterVersionCode = '1' | ||
| } | ||
|
|
||
| def flutterVersionName = localProperties.getProperty('flutter.versionName') | ||
| if (flutterVersionName == null) { | ||
| flutterVersionName = '1.0' | ||
| } | ||
|
|
||
| apply plugin: 'com.android.application' | ||
| apply plugin: 'kotlin-android' | ||
| apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" | ||
|
|
||
| android { | ||
| namespace "io.flutter.plugins.file_selector_android_example" | ||
| compileSdkVersion flutter.compileSdkVersion | ||
| ndkVersion flutter.ndkVersion | ||
|
|
||
| compileOptions { | ||
| sourceCompatibility JavaVersion.VERSION_1_8 | ||
| targetCompatibility JavaVersion.VERSION_1_8 | ||
| } | ||
|
|
||
| defaultConfig { | ||
| // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). | ||
| applicationId "io.flutter.plugins.file_selector_android_example" | ||
| // You can update the following values to match your application needs. | ||
| // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. | ||
| minSdkVersion 21 | ||
| targetSdkVersion 30 | ||
| versionCode flutterVersionCode.toInteger() | ||
| versionName flutterVersionName | ||
| testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
| } | ||
|
|
||
| buildTypes { | ||
| release { | ||
| // TODO: Add your own signing config for the release build. | ||
| // Signing with the debug keys for now, so `flutter run --release` works. | ||
| signingConfig signingConfigs.debug | ||
| } | ||
| } | ||
| } | ||
|
|
||
| flutter { | ||
| source '../..' | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // 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; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /* | ||
| * Annotation to aid repository tooling in determining if a test is | ||
| * a native java unit test or a java class with a dart integration. | ||
| * | ||
| * See: https://github.com/flutter/flutter/wiki/Plugin-Tests#enabling-android-ui-tests | ||
| * for more infomation. | ||
| */ | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target(ElementType.TYPE) | ||
| public @interface DartIntegrationTest {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // 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.file_selector_android_example; | ||
|
|
||
| import androidx.test.rule.ActivityTestRule; | ||
| import dev.flutter.plugins.integration_test.FlutterTestRunner; | ||
| import io.flutter.plugins.DartIntegrationTest; | ||
| import org.junit.Rule; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| @DartIntegrationTest | ||
| @RunWith(FlutterTestRunner.class) | ||
| public class MainActivityTest { | ||
| @Rule public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <!-- The INTERNET permission is required for development. Specifically, | ||
| the Flutter tool needs it to communicate with the running application | ||
| to allow setting breakpoints, to provide hot reload, etc. | ||
| --> | ||
| <uses-permission android:name="android.permission.INTERNET"/> | ||
| </manifest> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <application | ||
| android:label="file_selector_android_example" | ||
| android:name="${applicationName}" | ||
| android:icon="@mipmap/ic_launcher"> | ||
| <activity | ||
| android:name=".MainActivity" | ||
| android:exported="true" | ||
| android:launchMode="singleTop" | ||
| android:theme="@style/LaunchTheme" | ||
| android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" | ||
| android:hardwareAccelerated="true" | ||
| android:windowSoftInputMode="adjustResize"> | ||
| <!-- Specifies an Android theme to apply to this Activity as soon as | ||
| the Android process has started. This theme is visible to the user | ||
| while the Flutter UI initializes. After that, this theme continues | ||
| to determine the Window background behind the Flutter UI. --> | ||
| <meta-data | ||
| android:name="io.flutter.embedding.android.NormalTheme" | ||
| android:resource="@style/NormalTheme" | ||
| /> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN"/> | ||
| <category android:name="android.intent.category.LAUNCHER"/> | ||
| </intent-filter> | ||
| </activity> | ||
| <!-- Don't delete the meta-data below. | ||
| This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --> | ||
| <meta-data | ||
| android:name="flutterEmbedding" | ||
| android:value="2" /> | ||
| </application> | ||
| </manifest> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // 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.file_selector_android_example; | ||
|
|
||
| import io.flutter.embedding.android.FlutterActivity; | ||
|
|
||
| public class MainActivity extends FlutterActivity {} |
Uh oh!
There was an error while loading. Please reload this page.