Skip to content

Commit 897f695

Browse files
authored
[camerax] Wrap classes to implement resolution configuration for image capture, image analysis, and preview (flutter#4523)
Wraps classes to implement resolution configuration for image capture, image analysis, and preview. Also bumps CameraX version to latest and removes the deprecated classes used previously. No functionality changes. Also thanks to @bparrishMines who did majority of the work here! Part of flutter#120462
1 parent 867f2a4 commit 897f695

40 files changed

+2158
-369
lines changed

packages/camera/camera_android_camerax/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.5.0+12
2+
3+
* Wraps classes needed to implement resolution configuration for image capture, image analysis, and preview.
4+
* Removes usages of deprecated APIs for resolution configuration.
5+
* Bumps CameraX version to 1.3.0-beta01.
6+
17
## 0.5.0+11
28

39
* Fixes issue with image data not being emitted after relistening to stream returned by `onStreamedFrameAvailable`.

packages/camera/camera_android_camerax/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ android {
6161

6262
dependencies {
6363
// CameraX core library using the camera2 implementation must use same version number.
64-
def camerax_version = "1.3.0-alpha05"
64+
def camerax_version = "1.3.0-beta01"
6565
implementation "androidx.camera:camera-core:${camerax_version}"
6666
implementation "androidx.camera:camera-camera2:${camerax_version}"
6767
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
package io.flutter.plugins.camerax;
6+
7+
import androidx.annotation.NonNull;
8+
import androidx.annotation.VisibleForTesting;
9+
import androidx.camera.core.resolutionselector.AspectRatioStrategy;
10+
import io.flutter.plugins.camerax.GeneratedCameraXLibrary.AspectRatioStrategyHostApi;
11+
12+
/**
13+
* Host API implementation for {@link AspectRatioStrategy}.
14+
*
15+
* <p>This class handles instantiating and adding native object instances that are attached to a
16+
* Dart instance or handle method calls on the associated native class or an instance of the class.
17+
*/
18+
public class AspectRatioStrategyHostApiImpl implements AspectRatioStrategyHostApi {
19+
private final InstanceManager instanceManager;
20+
private final AspectRatioStrategyProxy proxy;
21+
22+
/** Proxy for constructors and static method of {@link AspectRatioStrategy}. */
23+
@VisibleForTesting
24+
public static class AspectRatioStrategyProxy {
25+
/** Creates an instance of {@link AspectRatioStrategy}. */
26+
@NonNull
27+
public AspectRatioStrategy create(
28+
@NonNull Long preferredAspectRatio, @NonNull Long fallbackRule) {
29+
return new AspectRatioStrategy(preferredAspectRatio.intValue(), fallbackRule.intValue());
30+
}
31+
}
32+
33+
/**
34+
* Constructs an {@link AspectRatioStrategyHostApiImpl}.
35+
*
36+
* @param instanceManager maintains instances stored to communicate with attached Dart objects
37+
*/
38+
public AspectRatioStrategyHostApiImpl(@NonNull InstanceManager instanceManager) {
39+
this(instanceManager, new AspectRatioStrategyProxy());
40+
}
41+
42+
/**
43+
* Constructs an {@link AspectRatioStrategyHostApiImpl}.
44+
*
45+
* @param instanceManager maintains instances stored to communicate with attached Dart objects
46+
* @param proxy proxy for constructors and static method of {@link AspectRatioStrategy}
47+
*/
48+
@VisibleForTesting
49+
AspectRatioStrategyHostApiImpl(
50+
@NonNull InstanceManager instanceManager, @NonNull AspectRatioStrategyProxy proxy) {
51+
this.instanceManager = instanceManager;
52+
this.proxy = proxy;
53+
}
54+
55+
/**
56+
* Creates an {@link AspectRatioStrategy} instance with the preferred aspect ratio and fallback
57+
* rule specified.
58+
*/
59+
@Override
60+
public void create(
61+
@NonNull Long identifier, @NonNull Long preferredAspectRatio, @NonNull Long fallbackRule) {
62+
instanceManager.addDartCreatedInstance(
63+
proxy.create(preferredAspectRatio, fallbackRule), identifier);
64+
}
65+
}

packages/camera/camera_android_camerax/android/src/main/java/io/flutter/plugins/camerax/CameraAndroidCameraxPlugin.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ public void setUp(
9797
binaryMessenger, pendingRecordingHostApiImpl);
9898
videoCaptureHostApiImpl = new VideoCaptureHostApiImpl(binaryMessenger, instanceManager);
9999
GeneratedCameraXLibrary.VideoCaptureHostApi.setup(binaryMessenger, videoCaptureHostApiImpl);
100+
GeneratedCameraXLibrary.ResolutionSelectorHostApi.setup(
101+
binaryMessenger, new ResolutionSelectorHostApiImpl(instanceManager));
102+
GeneratedCameraXLibrary.ResolutionStrategyHostApi.setup(
103+
binaryMessenger, new ResolutionStrategyHostApiImpl(instanceManager));
104+
GeneratedCameraXLibrary.AspectRatioStrategyHostApi.setup(
105+
binaryMessenger, new AspectRatioStrategyHostApiImpl(instanceManager));
100106
}
101107

102108
@Override

0 commit comments

Comments
 (0)