diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 33094a27e9a4..defaf4f91ea4 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -16,6 +16,22 @@ updates: interval: "weekly" open-pull-requests-limit: 10 + - package-ecosystem: "gradle" + directory: "/packages/camera/camera_android_camerax/android" + commit-message: + prefix: "[camera]" + schedule: + interval: "weekly" + open-pull-requests-limit: 10 + + - package-ecosystem: "gradle" + directory: "/packages/camera/camera_android_camerax/example/android/app" + commit-message: + prefix: "[camera]" + schedule: + interval: "weekly" + open-pull-requests-limit: 10 + - package-ecosystem: "gradle" directory: "/packages/camera/camera/example/android/app" commit-message: diff --git a/packages/camera/camera_android_camerax/.metadata b/packages/camera/camera_android_camerax/.metadata new file mode 100644 index 000000000000..1667b9356657 --- /dev/null +++ b/packages/camera/camera_android_camerax/.metadata @@ -0,0 +1,30 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled. + +version: + revision: 6b04999e4aaa9dfafdcb5ca09e812df7379d9ee5 + channel: spellcheck_1_1 + +project_type: plugin + +# Tracks metadata for the flutter migrate command +migration: + platforms: + - platform: root + create_revision: 6b04999e4aaa9dfafdcb5ca09e812df7379d9ee5 + base_revision: 6b04999e4aaa9dfafdcb5ca09e812df7379d9ee5 + - platform: android + create_revision: 6b04999e4aaa9dfafdcb5ca09e812df7379d9ee5 + base_revision: 6b04999e4aaa9dfafdcb5ca09e812df7379d9ee5 + + # User provided section + + # List of Local paths (relative to this file) that should be + # ignored by the migrate tool. + # + # Files that are not part of the templates will be ignored by default. + unmanaged_files: + - 'lib/main.dart' + - 'ios/Runner.xcodeproj/project.pbxproj' diff --git a/packages/camera/camera_android_camerax/AUTHORS b/packages/camera/camera_android_camerax/AUTHORS new file mode 100644 index 000000000000..513c0b0e2f86 --- /dev/null +++ b/packages/camera/camera_android_camerax/AUTHORS @@ -0,0 +1,4 @@ +# Below is a list of people and organizations that have contributed +# to the Flutter project. Names should be added to the list like so: +# +# Name/Organization diff --git a/packages/camera/camera_android_camerax/CHANGELOG.md b/packages/camera/camera_android_camerax/CHANGELOG.md new file mode 100644 index 000000000000..044fecbb5272 --- /dev/null +++ b/packages/camera/camera_android_camerax/CHANGELOG.md @@ -0,0 +1,3 @@ +## NEXT + +* Creates camera_android_camerax plugin for development. diff --git a/packages/camera/camera_android_camerax/LICENSE b/packages/camera/camera_android_camerax/LICENSE new file mode 100644 index 000000000000..c6823b81eb84 --- /dev/null +++ b/packages/camera/camera_android_camerax/LICENSE @@ -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. diff --git a/packages/camera/camera_android_camerax/README.md b/packages/camera/camera_android_camerax/README.md new file mode 100644 index 000000000000..06d837ac7214 --- /dev/null +++ b/packages/camera/camera_android_camerax/README.md @@ -0,0 +1,3 @@ +# camera_android_camerax + +An implementation of the camera plugin on Android using CameraX. diff --git a/packages/camera/camera_android_camerax/android/build.gradle b/packages/camera/camera_android_camerax/android/build.gradle new file mode 100644 index 000000000000..15932c52c527 --- /dev/null +++ b/packages/camera/camera_android_camerax/android/build.gradle @@ -0,0 +1,35 @@ +group 'io.flutter.plugins.camerax' +version '1.0' + +buildscript { + repositories { + google() + mavenCentral() + } + + dependencies { + classpath 'com.android.tools.build:gradle:7.2.0' + } +} + +rootProject.allprojects { + repositories { + google() + mavenCentral() + } +} + +apply plugin: 'com.android.library' + +android { + compileSdkVersion 31 + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + defaultConfig { + minSdkVersion 16 + } +} diff --git a/packages/camera/camera_android_camerax/android/settings.gradle b/packages/camera/camera_android_camerax/android/settings.gradle new file mode 100644 index 000000000000..613f994165a0 --- /dev/null +++ b/packages/camera/camera_android_camerax/android/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'camera_android_camerax' diff --git a/packages/camera/camera_android_camerax/android/src/main/AndroidManifest.xml b/packages/camera/camera_android_camerax/android/src/main/AndroidManifest.xml new file mode 100644 index 000000000000..ea4275c757cf --- /dev/null +++ b/packages/camera/camera_android_camerax/android/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + diff --git a/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraAndroidCameraxPlugin.java b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraAndroidCameraxPlugin.java new file mode 100644 index 000000000000..0e60b13c2cfa --- /dev/null +++ b/packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraAndroidCameraxPlugin.java @@ -0,0 +1,42 @@ +// 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.camerax; + +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; + +/** CameraAndroidCameraxPlugin */ +public class CameraAndroidCameraxPlugin 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(), "camera_android_camerax"); + 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); + } +} diff --git a/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/CameraxPluginTest.java b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/CameraxPluginTest.java new file mode 100644 index 000000000000..69b0e34f6bb6 --- /dev/null +++ b/packages/camera/camera_android_camerax/android/src/test/java/io/flutter/plugins/camerax/CameraxPluginTest.java @@ -0,0 +1,7 @@ +// 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.camerax; + +public class CameraxPluginTest {} diff --git a/packages/camera/camera_android_camerax/example/README.md b/packages/camera/camera_android_camerax/example/README.md new file mode 100644 index 000000000000..438e446d1921 --- /dev/null +++ b/packages/camera/camera_android_camerax/example/README.md @@ -0,0 +1,3 @@ +# camera_android_camerax_example + +Demonstrates how to use the camera_android_camerax plugin. diff --git a/packages/camera/camera_android_camerax/example/android/app/build.gradle b/packages/camera/camera_android_camerax/example/android/app/build.gradle new file mode 100644 index 000000000000..1dbeb6653915 --- /dev/null +++ b/packages/camera/camera_android_camerax/example/android/app/build.gradle @@ -0,0 +1,66 @@ +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 { + 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.cameraxexample" + // You can update the following values to match your application needs. + // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration. + minSdkVersion flutter.minSdkVersion + 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 '../..' +} + +dependencies { + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test:runner:1.2.0' + api 'androidx.test:core:1.2.0' +} diff --git a/packages/camera/camera_android_camerax/example/android/app/src/androidTest/java/io/flutter/plugins/DartIntegrationTest.java b/packages/camera/camera_android_camerax/example/android/app/src/androidTest/java/io/flutter/plugins/DartIntegrationTest.java new file mode 100644 index 000000000000..0f4298dca155 --- /dev/null +++ b/packages/camera/camera_android_camerax/example/android/app/src/androidTest/java/io/flutter/plugins/DartIntegrationTest.java @@ -0,0 +1,14 @@ +// 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; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface DartIntegrationTest {} diff --git a/packages/camera/camera_android_camerax/example/android/app/src/androidTest/java/io/flutter/plugins/cameraxexample/MainActivityTest.java b/packages/camera/camera_android_camerax/example/android/app/src/androidTest/java/io/flutter/plugins/cameraxexample/MainActivityTest.java new file mode 100644 index 000000000000..8bcb398abb87 --- /dev/null +++ b/packages/camera/camera_android_camerax/example/android/app/src/androidTest/java/io/flutter/plugins/cameraxexample/MainActivityTest.java @@ -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.cameraxexample; + +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 rule = new ActivityTestRule<>(MainActivity.class); +} diff --git a/packages/camera/camera_android_camerax/example/android/app/src/debug/AndroidManifest.xml b/packages/camera/camera_android_camerax/example/android/app/src/debug/AndroidManifest.xml new file mode 100644 index 000000000000..093e904635f7 --- /dev/null +++ b/packages/camera/camera_android_camerax/example/android/app/src/debug/AndroidManifest.xml @@ -0,0 +1,8 @@ + + + + diff --git a/packages/camera/camera_android_camerax/example/android/app/src/main/AndroidManifest.xml b/packages/camera/camera_android_camerax/example/android/app/src/main/AndroidManifest.xml new file mode 100644 index 000000000000..82b92e25bdfe --- /dev/null +++ b/packages/camera/camera_android_camerax/example/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + diff --git a/packages/camera/camera_android_camerax/example/android/app/src/main/java/io/flutter/plugins/cameraexample/MainActivity.java b/packages/camera/camera_android_camerax/example/android/app/src/main/java/io/flutter/plugins/cameraexample/MainActivity.java new file mode 100644 index 000000000000..5e2a10f1555a --- /dev/null +++ b/packages/camera/camera_android_camerax/example/android/app/src/main/java/io/flutter/plugins/cameraexample/MainActivity.java @@ -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.cameraxexample; + +import io.flutter.embedding.android.FlutterActivity; + +public class MainActivity extends FlutterActivity {} diff --git a/packages/camera/camera_android_camerax/example/android/app/src/main/res/drawable-v21/launch_background.xml b/packages/camera/camera_android_camerax/example/android/app/src/main/res/drawable-v21/launch_background.xml new file mode 100644 index 000000000000..f74085f3f6a2 --- /dev/null +++ b/packages/camera/camera_android_camerax/example/android/app/src/main/res/drawable-v21/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/packages/camera/camera_android_camerax/example/android/app/src/main/res/drawable/launch_background.xml b/packages/camera/camera_android_camerax/example/android/app/src/main/res/drawable/launch_background.xml new file mode 100644 index 000000000000..304732f88420 --- /dev/null +++ b/packages/camera/camera_android_camerax/example/android/app/src/main/res/drawable/launch_background.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/packages/camera/camera_android_camerax/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/packages/camera/camera_android_camerax/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 000000000000..db77bb4b7b09 Binary files /dev/null and b/packages/camera/camera_android_camerax/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/packages/camera/camera_android_camerax/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/packages/camera/camera_android_camerax/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 000000000000..17987b79bb8a Binary files /dev/null and b/packages/camera/camera_android_camerax/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/packages/camera/camera_android_camerax/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/packages/camera/camera_android_camerax/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 000000000000..09d4391482be Binary files /dev/null and b/packages/camera/camera_android_camerax/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/packages/camera/camera_android_camerax/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/packages/camera/camera_android_camerax/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 000000000000..d5f1c8d34e7a Binary files /dev/null and b/packages/camera/camera_android_camerax/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/packages/camera/camera_android_camerax/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/packages/camera/camera_android_camerax/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 000000000000..4d6372eebdb2 Binary files /dev/null and b/packages/camera/camera_android_camerax/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/packages/camera/camera_android_camerax/example/android/app/src/main/res/values-night/styles.xml b/packages/camera/camera_android_camerax/example/android/app/src/main/res/values-night/styles.xml new file mode 100644 index 000000000000..06952be745f9 --- /dev/null +++ b/packages/camera/camera_android_camerax/example/android/app/src/main/res/values-night/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/packages/camera/camera_android_camerax/example/android/app/src/main/res/values/styles.xml b/packages/camera/camera_android_camerax/example/android/app/src/main/res/values/styles.xml new file mode 100644 index 000000000000..cb1ef88056ed --- /dev/null +++ b/packages/camera/camera_android_camerax/example/android/app/src/main/res/values/styles.xml @@ -0,0 +1,18 @@ + + + + + + + diff --git a/packages/camera/camera_android_camerax/example/android/app/src/profile/AndroidManifest.xml b/packages/camera/camera_android_camerax/example/android/app/src/profile/AndroidManifest.xml new file mode 100644 index 000000000000..093e904635f7 --- /dev/null +++ b/packages/camera/camera_android_camerax/example/android/app/src/profile/AndroidManifest.xml @@ -0,0 +1,8 @@ + + + + diff --git a/packages/camera/camera_android_camerax/example/android/build.gradle b/packages/camera/camera_android_camerax/example/android/build.gradle new file mode 100644 index 000000000000..58a8c74b1474 --- /dev/null +++ b/packages/camera/camera_android_camerax/example/android/build.gradle @@ -0,0 +1,31 @@ +buildscript { + ext.kotlin_version = '1.7.10' + repositories { + google() + mavenCentral() + } + + dependencies { + classpath 'com.android.tools.build:gradle:7.2.0' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} + +allprojects { + repositories { + google() + mavenCentral() + } +} + +rootProject.buildDir = '../build' +subprojects { + project.buildDir = "${rootProject.buildDir}/${project.name}" +} +subprojects { + project.evaluationDependsOn(':app') +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/packages/camera/camera_android_camerax/example/android/gradle.properties b/packages/camera/camera_android_camerax/example/android/gradle.properties new file mode 100644 index 000000000000..94adc3a3f97a --- /dev/null +++ b/packages/camera/camera_android_camerax/example/android/gradle.properties @@ -0,0 +1,3 @@ +org.gradle.jvmargs=-Xmx1536M +android.useAndroidX=true +android.enableJetifier=true diff --git a/packages/camera/camera_android_camerax/example/android/gradle/wrapper/gradle-wrapper.properties b/packages/camera/camera_android_camerax/example/android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000000..3c472b99c6f3 --- /dev/null +++ b/packages/camera/camera_android_camerax/example/android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip diff --git a/packages/camera/camera_android_camerax/example/android/settings.gradle b/packages/camera/camera_android_camerax/example/android/settings.gradle new file mode 100644 index 000000000000..44e62bcf06ae --- /dev/null +++ b/packages/camera/camera_android_camerax/example/android/settings.gradle @@ -0,0 +1,11 @@ +include ':app' + +def localPropertiesFile = new File(rootProject.projectDir, "local.properties") +def properties = new Properties() + +assert localPropertiesFile.exists() +localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + +def flutterSdkPath = properties.getProperty("flutter.sdk") +assert flutterSdkPath != null, "flutter.sdk not set in local.properties" +apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" diff --git a/packages/camera/camera_android_camerax/example/integration_test/integration_test.dart b/packages/camera/camera_android_camerax/example/integration_test/integration_test.dart new file mode 100644 index 000000000000..2b82b4bda5e4 --- /dev/null +++ b/packages/camera/camera_android_camerax/example/integration_test/integration_test.dart @@ -0,0 +1,12 @@ +// 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. + +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; + +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + + testWidgets('placeholder test', (WidgetTester tester) async {}); +} diff --git a/packages/camera/camera_android_camerax/example/lib/main.dart b/packages/camera/camera_android_camerax/example/lib/main.dart new file mode 100644 index 000000000000..c5391096374e --- /dev/null +++ b/packages/camera/camera_android_camerax/example/lib/main.dart @@ -0,0 +1,34 @@ +// 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. + +import 'package:flutter/material.dart'; + +void main() { + runApp(const MyApp()); +} + +/// Example app +class MyApp extends StatefulWidget { + /// App instantiation + const MyApp({Key? key}) : super(key: key); + + @override + State createState() => _MyAppState(); +} + +class _MyAppState extends State { + @override + Widget build(BuildContext context) { + return MaterialApp( + home: Scaffold( + appBar: AppBar( + title: const Text('Plugin example app'), + ), + body: const Center( + child: Text('Hello, world!'), + ), + ), + ); + } +} diff --git a/packages/camera/camera_android_camerax/example/pubspec.yaml b/packages/camera/camera_android_camerax/example/pubspec.yaml new file mode 100644 index 000000000000..891e9486e846 --- /dev/null +++ b/packages/camera/camera_android_camerax/example/pubspec.yaml @@ -0,0 +1,85 @@ +name: camera_android_camerax_example +description: Demonstrates how to use the camera_android_camerax plugin. + +# The following line prevents the package from being accidentally published to +# pub.dev using `flutter pub publish`. This is preferred for private packages. +publish_to: 'none' # Remove this line if you wish to publish to pub.dev + +environment: + sdk: '>=2.14.0 <3.0.0' + +# Dependencies specify other packages that your package needs in order to work. +# To automatically upgrade your package dependencies to the latest versions +# consider running `flutter pub upgrade --major-versions`. Alternatively, +# dependencies can be manually updated by changing the version numbers below to +# the latest version available on pub.dev. To see which dependencies have newer +# versions available, run `flutter pub outdated`. +dependencies: + camera_android_camerax: + # When depending on this package from a real application you should use: + # camera_android_camerax: ^x.y.z + # See https://dart.dev/tools/pub/dependencies#version-constraints + # The example app is bundled with the plugin so we use a path dependency on + # the parent directory to use the current plugin's version. + path: ../ + # The following adds the Cupertino Icons font to your application. + # Use with the CupertinoIcons class for iOS style icons. + cupertino_icons: ^1.0.2 + flutter: + sdk: flutter + +dev_dependencies: + # The "flutter_lints" package below contains a set of recommended lints to + # encourage good coding practices. The lint set provided by the package is + # activated in the `analysis_options.yaml` file located at the root of your + # package. See that file for information about deactivating specific lint + # rules and activating additional ones. + flutter_lints: ^2.0.0 + + flutter_test: + sdk: flutter + + integration_test: + sdk: flutter + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + + # The following line ensures that the Material Icons font is + # included with your application, so that you can use the icons in + # the material Icons class. + uses-material-design: true + + # To add assets to your application, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware + + # For details regarding adding assets from package dependencies, see + # https://flutter.dev/assets-and-images/#from-packages + + # To add custom fonts to your application, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts from package dependencies, + # see https://flutter.dev/custom-fonts/#from-packages diff --git a/packages/camera/camera_android_camerax/example/test/widget_test.dart b/packages/camera/camera_android_camerax/example/test/widget_test.dart new file mode 100644 index 000000000000..bfe91af3eae6 --- /dev/null +++ b/packages/camera/camera_android_camerax/example/test/widget_test.dart @@ -0,0 +1,18 @@ +// 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. + +// This is a basic Flutter widget test. +// +// To perform an interaction with a widget in your test, use the WidgetTester +// utility in the flutter_test package. For example, you can send tap and scroll +// gestures. You can also use WidgetTester to find child widgets in the widget +// tree, read text, and verify that the values of widget properties are correct. + +import 'package:flutter_test/flutter_test.dart'; + +void main() { + testWidgets('Fake test', (WidgetTester tester) async { + expect(true, isTrue); + }); +} diff --git a/packages/camera/camera_android_camerax/example/test_driver/integration_test.dart b/packages/camera/camera_android_camerax/example/test_driver/integration_test.dart new file mode 100644 index 000000000000..4f10f2a522f3 --- /dev/null +++ b/packages/camera/camera_android_camerax/example/test_driver/integration_test.dart @@ -0,0 +1,7 @@ +// 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. + +import 'package:integration_test/integration_test_driver.dart'; + +Future main() => integrationDriver(); diff --git a/packages/camera/camera_android_camerax/lib/camera_android_camerax.dart b/packages/camera/camera_android_camerax/lib/camera_android_camerax.dart new file mode 100644 index 000000000000..40f8c703fa9f --- /dev/null +++ b/packages/camera/camera_android_camerax/lib/camera_android_camerax.dart @@ -0,0 +1,13 @@ +// 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. + +import 'camera_android_camerax_platform_interface.dart'; + +/// Android Camera implented with the CameraX library. +class CameraAndroidCamerax { + /// Returns platform version of this instance. + Future getPlatformVersion() { + return CameraAndroidCameraxPlatform.instance.getPlatformVersion(); + } +} diff --git a/packages/camera/camera_android_camerax/lib/camera_android_camerax_method_channel.dart b/packages/camera/camera_android_camerax/lib/camera_android_camerax_method_channel.dart new file mode 100644 index 000000000000..699a3667d14d --- /dev/null +++ b/packages/camera/camera_android_camerax/lib/camera_android_camerax_method_channel.dart @@ -0,0 +1,23 @@ +// 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. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +import 'camera_android_camerax_platform_interface.dart'; + +/// An implementation of [CameraAndroidCameraxPlatform] that uses method channels. +class MethodChannelCameraAndroidCamerax extends CameraAndroidCameraxPlatform { + /// The method channel used to interact with the native platform. + @visibleForTesting + final MethodChannel methodChannel = + const MethodChannel('camera_android_camerax'); + + @override + Future getPlatformVersion() async { + final String? version = + await methodChannel.invokeMethod('getPlatformVersion'); + return version; + } +} diff --git a/packages/camera/camera_android_camerax/lib/camera_android_camerax_platform_interface.dart b/packages/camera/camera_android_camerax/lib/camera_android_camerax_platform_interface.dart new file mode 100644 index 000000000000..03554caf3245 --- /dev/null +++ b/packages/camera/camera_android_camerax/lib/camera_android_camerax_platform_interface.dart @@ -0,0 +1,36 @@ +// 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. + +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +import 'camera_android_camerax_method_channel.dart'; + +/// The platform interface for the Android Camera implemented with CameraX. +abstract class CameraAndroidCameraxPlatform extends PlatformInterface { + /// Constructs a CameraAndroidCameraxPlatform. + CameraAndroidCameraxPlatform() : super(token: _token); + + static final Object _token = Object(); + + static CameraAndroidCameraxPlatform _instance = + MethodChannelCameraAndroidCamerax(); + + /// The default instance of [CameraAndroidCameraxPlatform] to use. + /// + /// Defaults to [MethodChannelCameraAndroidCamerax]. + static CameraAndroidCameraxPlatform get instance => _instance; + + /// Platform-specific implementations should set this with their own + /// platform-specific class that extends [CameraAndroidCameraxPlatform] when + /// they register themselves. + static set instance(CameraAndroidCameraxPlatform instance) { + PlatformInterface.verifyToken(instance, _token); + _instance = instance; + } + + /// Returns the platform version of this isntance. + Future getPlatformVersion() { + throw UnimplementedError('platformVersion() has not been implemented.'); + } +} diff --git a/packages/camera/camera_android_camerax/pubspec.yaml b/packages/camera/camera_android_camerax/pubspec.yaml new file mode 100644 index 000000000000..bb5b15b6baf4 --- /dev/null +++ b/packages/camera/camera_android_camerax/pubspec.yaml @@ -0,0 +1,73 @@ +name: camera_android_camerax +description: A new Flutter plugin project. +repository: https://github.com/flutter/plugins/tree/main/packages/camera/camera_android_camerax +issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 +homepage: +publish_to: 'none' + +environment: + sdk: '>=2.14.0 <3.0.0' + flutter: ">=2.5.0" + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + # This section identifies this Flutter project as a plugin project. + # The 'pluginClass' specifies the class (in Java, Kotlin, Swift, Objective-C, etc.) + # which should be registered in the plugin registry. This is required for + # using method channels. + # The Android 'package' specifies package in which the registered class is. + # This is required for using method channels on Android. + # The 'ffiPlugin' specifies that native code should be built and bundled. + # This is required for using `dart:ffi`. + # All these are used by the tooling to maintain consistency when + # adding or updating assets for this project. + plugin: + implements: camera + platforms: + android: + package: io.flutter.plugins.camerax + pluginClass: CameraAndroidCameraxPlugin + + # To add assets to your plugin package, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + # + # For details regarding assets in packages, see + # https://flutter.dev/assets-and-images/#from-packages + # + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/assets-and-images/#resolution-aware + + # To add custom fonts to your plugin package, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts in packages, see + # https://flutter.dev/custom-fonts/#from-packages + +dependencies: + flutter: + sdk: flutter + plugin_platform_interface: ^2.0.2 + +dev_dependencies: + flutter_lints: ^2.0.0 + flutter_test: + sdk: flutter diff --git a/packages/camera/camera_android_camerax/test/camera_android_camerax_method_channel_test.dart b/packages/camera/camera_android_camerax/test/camera_android_camerax_method_channel_test.dart new file mode 100644 index 000000000000..0a1ea847e1a5 --- /dev/null +++ b/packages/camera/camera_android_camerax/test/camera_android_camerax_method_channel_test.dart @@ -0,0 +1,29 @@ +// 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. + +import 'package:camera_android_camerax/camera_android_camerax_method_channel.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + final MethodChannelCameraAndroidCamerax platform = + MethodChannelCameraAndroidCamerax(); + const MethodChannel channel = MethodChannel('camera_android_camerax'); + + TestWidgetsFlutterBinding.ensureInitialized(); + + setUp(() { + channel.setMockMethodCallHandler((MethodCall methodCall) async { + return '42'; + }); + }); + + tearDown(() { + channel.setMockMethodCallHandler(null); + }); + + test('getPlatformVersion', () async { + expect(await platform.getPlatformVersion(), '42'); + }); +} diff --git a/packages/camera/camera_android_camerax/test/camera_android_camerax_test.dart b/packages/camera/camera_android_camerax/test/camera_android_camerax_test.dart new file mode 100644 index 000000000000..05ff46c1c55d --- /dev/null +++ b/packages/camera/camera_android_camerax/test/camera_android_camerax_test.dart @@ -0,0 +1,35 @@ +// 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. + +import 'package:camera_android_camerax/camera_android_camerax.dart'; +import 'package:camera_android_camerax/camera_android_camerax_method_channel.dart'; +import 'package:camera_android_camerax/camera_android_camerax_platform_interface.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +class MockCameraAndroidCameraxPlatform + with MockPlatformInterfaceMixin + implements CameraAndroidCameraxPlatform { + @override + Future getPlatformVersion() => Future.value('42'); +} + +void main() { + final CameraAndroidCameraxPlatform initialPlatform = + CameraAndroidCameraxPlatform.instance; + + test('$MethodChannelCameraAndroidCamerax is the default instance', () { + expect(initialPlatform, isInstanceOf()); + }); + + test('getPlatformVersion', () async { + final CameraAndroidCamerax cameraAndroidCameraxPlugin = + CameraAndroidCamerax(); + final MockCameraAndroidCameraxPlatform fakePlatform = + MockCameraAndroidCameraxPlatform(); + CameraAndroidCameraxPlatform.instance = fakePlatform; + + expect(await cameraAndroidCameraxPlugin.getPlatformVersion(), '42'); + }); +}