Skip to content

Commit

Permalink
Merge pull request flutter#22 from bottlepay/android-rework-test-camera
Browse files Browse the repository at this point in the history
Test feature accessors on Camera class
  • Loading branch information
acoutts authored Mar 15, 2021
2 parents dc7e3e7 + a04e645 commit 0a344b1
Show file tree
Hide file tree
Showing 3 changed files with 370 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class Camera implements CameraCaptureCallback.CameraCaptureStateListener {
private final Context applicationContext;
private final DartMessenger dartMessenger;
private final CameraProperties cameraProperties;
private final CameraFeatureFactory cameraFeatureFactory;
private final Activity activity;
/** A {@link CameraCaptureSession.CaptureCallback} that handles events related to JPEG capture. */
private final CameraCaptureCallback cameraCaptureCallback;
Expand Down Expand Up @@ -186,6 +187,7 @@ public Camera(
this.dartMessenger = dartMessenger;
this.applicationContext = activity.getApplicationContext();
this.cameraProperties = cameraProperties;
this.cameraFeatureFactory = cameraFeatureFactory;

// Setup camera features
this.cameraFeatures =
Expand Down Expand Up @@ -409,7 +411,8 @@ private void createCaptureSession(
// Update camera regions
cameraFeatures.put(
CameraFeatures.regionBoundaries,
new RegionBoundariesFeature(cameraProperties, previewRequestBuilder));
cameraFeatureFactory.createRegionBoundariesFeature(
cameraProperties, previewRequestBuilder));

// Prepare the callback
CameraCaptureSession.StateCallback callback =
Expand Down Expand Up @@ -878,12 +881,10 @@ public CameraRegions getCameraRegions() {
* Set new exposure point from dart.
*
* @param result Flutter result.
* @param x new x.
* @param y new y.
* @param point The exposure point.
*/
public void setExposurePoint(@NonNull final Result result, Double x, Double y) {
((ExposurePointFeature) cameraFeatures.get(CameraFeatures.exposurePoint))
.setValue(new Point(x, y));
public void setExposurePoint(@NonNull final Result result, Point point) {
((ExposurePointFeature) cameraFeatures.get(CameraFeatures.exposurePoint)).setValue(point);
cameraFeatures.get(CameraFeatures.exposurePoint).updateBuilder(previewRequestBuilder);

refreshPreviewCaptureSession(
Expand Down Expand Up @@ -961,8 +962,8 @@ public void setFocusMode(@NonNull final Result result, FocusMode newMode) {
* @param x new x.
* @param y new y.
*/
public void setFocusPoint(@NonNull final Result result, Double x, Double y) {
((FocusPointFeature) cameraFeatures.get(CameraFeatures.focusPoint)).setValue(new Point(x, y));
public void setFocusPoint(@NonNull final Result result, Point point) {
((FocusPointFeature) cameraFeatures.get(CameraFeatures.focusPoint)).setValue(point);
cameraFeatures.get(CameraFeatures.focusPoint).updateBuilder(previewRequestBuilder);

refreshPreviewCaptureSession(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugins.camera.CameraPermissions.PermissionsRegistry;
import io.flutter.plugins.camera.features.CameraFeatureFactoryImpl;
import io.flutter.plugins.camera.features.Point;
import io.flutter.plugins.camera.features.autofocus.FocusMode;
import io.flutter.plugins.camera.features.exposurelock.ExposureMode;
import io.flutter.plugins.camera.features.flash.FlashMode;
Expand Down Expand Up @@ -172,7 +173,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull final Result result)
y = call.argument("y");
}
try {
camera.setExposurePoint(result, x, y);
camera.setExposurePoint(result, new Point(x, y));
} catch (Exception e) {
handleException(e, result);
}
Expand Down Expand Up @@ -239,7 +240,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull final Result result)
y = call.argument("y");
}
try {
camera.setFocusPoint(result, x, y);
camera.setFocusPoint(result, new Point(x, y));
} catch (Exception e) {
handleException(e, result);
}
Expand Down
Loading

0 comments on commit 0a344b1

Please sign in to comment.