Skip to content

Commit

Permalink
Merge pull request flutter#7 from bottlepay/android-rework-fix-tests
Browse files Browse the repository at this point in the history
Fix tests after feature refactor
  • Loading branch information
acoutts authored Mar 8, 2021
2 parents 1acf379 + 367d496 commit 3523016
Show file tree
Hide file tree
Showing 37 changed files with 692 additions and 764 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2019 The Chromium 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.camera;

import android.hardware.camera2.CameraCaptureSession;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2019 The Chromium 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.camera;

import android.graphics.Rect;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2019 The Chromium 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.camera;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2019 The Chromium 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.camera;

import android.media.Image;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.flutter.plugin.common.MethodChannel;
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.autofocus.FocusMode;
import io.flutter.plugins.camera.features.exposurelock.ExposureMode;
import io.flutter.plugins.camera.features.flash.FlashMode;
Expand Down Expand Up @@ -364,6 +365,7 @@ private void instantiateCamera(MethodCall call, Result result) throws CameraAcce
new Camera(
activity,
flutterSurfaceTexture,
new CameraFeatureFactoryImpl(),
dartMessenger,
cameraProperties,
resolutionPreset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ class PictureCaptureRequest {
*/
private long preCaptureStartTime;

private final Runnable timeoutCallback =
() -> {
error("captureTimeout", "Picture capture request timed out", null);
};

/**
* Factory method to create a picture capture request.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// Copyright 2019 The Chromium 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.camera.features;

import android.hardware.camera2.CaptureRequest;
import androidx.annotation.NonNull;
import io.flutter.plugins.camera.CameraProperties;

/**
Expand All @@ -11,35 +16,42 @@
*
* @param <T>
*/
public interface CameraFeature<T> {
public abstract class CameraFeature<T> {
protected final CameraProperties cameraProperties;


protected CameraFeature(@NonNull CameraProperties cameraProperties) {
this.cameraProperties = cameraProperties;
}

/** Debug name for this feature. */
public String getDebugName();
public abstract String getDebugName();

/**
* Get the current value of this feature's setting.
*
* @return
*/
public T getValue();
public abstract T getValue();

/**
* Set a new value for this feature's setting.
*
* @param value
*/
public void setValue(T value);
public abstract void setValue(T value);

/**
* Returns whether or not this feature is supported on the given camera properties.
* Returns whether or not this feature is supported.
*
* @return
*/
public boolean checkIsSupported(CameraProperties cameraProperties);
public abstract boolean checkIsSupported();

/**
* Update the setting in a provided request builder.
*
* @param requestBuilder
*/
public void updateBuilder(CaptureRequest.Builder requestBuilder);
public abstract void updateBuilder(CaptureRequest.Builder requestBuilder);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// Copyright 2019 The Chromium 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.camera.features;

import android.app.Activity;
import android.hardware.camera2.CaptureRequest;
import androidx.annotation.NonNull;
import io.flutter.plugins.camera.CameraProperties;
import io.flutter.plugins.camera.DartMessenger;
import io.flutter.plugins.camera.features.autofocus.AutoFocusFeature;
import io.flutter.plugins.camera.features.exposurelock.ExposureLockFeature;
import io.flutter.plugins.camera.features.exposureoffset.ExposureOffsetFeature;
import io.flutter.plugins.camera.features.exposurepoint.ExposurePointFeature;
import io.flutter.plugins.camera.features.flash.FlashFeature;
import io.flutter.plugins.camera.features.focuspoint.FocusPointFeature;
import io.flutter.plugins.camera.features.fpsrange.FpsRangeFeature;
import io.flutter.plugins.camera.features.noisereduction.NoiseReductionFeature;
import io.flutter.plugins.camera.features.regionboundaries.CameraRegions;
import io.flutter.plugins.camera.features.regionboundaries.RegionBoundariesFeature;
import io.flutter.plugins.camera.features.resolution.ResolutionFeature;
import io.flutter.plugins.camera.features.resolution.ResolutionPreset;
import io.flutter.plugins.camera.features.sensororientation.SensorOrientationFeature;
import io.flutter.plugins.camera.features.zoomlevel.ZoomLevelFeature;
import java.util.concurrent.Callable;

public interface CameraFeatureFactory {

/**
* Creates a new instance of the auto focus feature.
*
* @param cameraProperties instance of the CameraProperties class containing information about the cameras features.
* @param recordingVideo indicates if the camera is currently recording.
* @return newly created instance of the AutoFocusFeature class.
*/
AutoFocusFeature createAutoFocusFeature(
@NonNull CameraProperties cameraProperties,
boolean recordingVideo);

/**
* Creates a new instance of the exposure lock feature.
*
* @param cameraProperties instance of the CameraProperties class containing information about the cameras features.
* @return newly created instance of the ExposureLockFeature class.
*/
ExposureLockFeature createExposureLockFeature(@NonNull CameraProperties cameraProperties);

/**
* Creates a new instance of the exposure offset feature.
*
* @param cameraProperties instance of the CameraProperties class containing information about the cameras features.
* @return newly created instance of the ExposureOffsetFeature class.
*/
ExposureOffsetFeature createExposureOffsetFeature(@NonNull CameraProperties cameraProperties);

/**
* Creates a new instance of the flash feature.
*
* @param cameraProperties instance of the CameraProperties class containing information about the cameras features.
* @return newly created instance of the FlashFeature class.
*/
FlashFeature createFlashFeature(@NonNull CameraProperties cameraProperties);

/**
* Creates a new instance of the resolution feature.
*
* @param cameraProperties instance of the CameraProperties class containing information about the cameras features.
* @param initialSetting initial resolution preset.
* @param cameraName the name of the camera which can be used to identify the camera device.
* @return newly created instance of the ResolutionFeature class.
*/
ResolutionFeature createResolutionFeature(
@NonNull CameraProperties cameraProperties,
ResolutionPreset initialSetting,
String cameraName);

/**
* Creates a new instance of the focus point feature.
*
* @param cameraProperties instance of the CameraProperties class containing information about the cameras features.
* @param getCameraRegions function which is used to retrieve the current camera regions.
* @return newly created instance of the FocusPointFeature class.
*/
FocusPointFeature createFocusPointFeature(
@NonNull CameraProperties cameraProperties,
Callable<CameraRegions> getCameraRegions);

/**
* Creates a new instance of the FPS range feature.
*
* @param cameraProperties instance of the CameraProperties class containing information about the cameras features.
* @return newly created instance of the FpsRangeFeature class.
*/
FpsRangeFeature createFpsRangeFeature(@NonNull CameraProperties cameraProperties);

/**
* Creates a new instance of the sensor orientation feature.
*
* @param cameraProperties instance of the CameraProperties class containing information about the cameras features.
* @param activity current activity associated with the camera plugin.
* @param dartMessenger instance of the DartMessenger class, used to send state updates back to Dart.
* @return newly created instance of the SensorOrientationFeature class.
*/
SensorOrientationFeature createSensorOrientationFeature(
@NonNull CameraProperties cameraProperties,
@NonNull Activity activity,
@NonNull DartMessenger dartMessenger);

/**
* Creates a new instance of the zoom level feature.
*
* @param cameraProperties instance of the CameraProperties class containing information about the cameras features.
* @return newly created instance of the ZoomLevelFeature class.
*/
ZoomLevelFeature createZoomLevelFeature(@NonNull CameraProperties cameraProperties);

/**
* Creates a new instance of the region boundaries feature.
*
* @param cameraProperties instance of the CameraProperties class containing information about the cameras features.
* @param requestBuilder instance of the CaptureRequest.Builder class, used to inform the Camera2 API that the settings are updated.
* @return newly created instance of the RegionBoundariesFeature class.
*/
RegionBoundariesFeature createRegionBoundariesFeature(
@NonNull CameraProperties cameraProperties,
@NonNull CaptureRequest.Builder requestBuilder);

/**
* Creates a new instance of the exposure point feature.
*
* @param cameraProperties instance of the CameraProperties class containing information about the cameras features.
* @param getCameraRegions function which is used to retrieve the current camera regions.
* @return newly created instance of the ExposurePointFeature class.
*/
ExposurePointFeature createExposurePointFeature(
@NonNull CameraProperties cameraProperties,
@NonNull Callable<CameraRegions> getCameraRegions);

/**
* Creates a new instance of the noise reduction feature.
*
* @param cameraProperties instance of the CameraProperties class containing information about the cameras features.
* @return newly created instance of the NoiseReductionFeature class.
*/
NoiseReductionFeature createNoiseReductionFeature(
@NonNull CameraProperties cameraProperties);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright 2019 The Chromium 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.camera.features;

import android.app.Activity;
import android.hardware.camera2.CaptureRequest;
import androidx.annotation.NonNull;
import io.flutter.plugins.camera.CameraProperties;
import io.flutter.plugins.camera.DartMessenger;
import io.flutter.plugins.camera.features.autofocus.AutoFocusFeature;
import io.flutter.plugins.camera.features.exposurelock.ExposureLockFeature;
import io.flutter.plugins.camera.features.exposureoffset.ExposureOffsetFeature;
import io.flutter.plugins.camera.features.exposurepoint.ExposurePointFeature;
import io.flutter.plugins.camera.features.flash.FlashFeature;
import io.flutter.plugins.camera.features.focuspoint.FocusPointFeature;
import io.flutter.plugins.camera.features.fpsrange.FpsRangeFeature;
import io.flutter.plugins.camera.features.noisereduction.NoiseReductionFeature;
import io.flutter.plugins.camera.features.regionboundaries.CameraRegions;
import io.flutter.plugins.camera.features.regionboundaries.RegionBoundariesFeature;
import io.flutter.plugins.camera.features.resolution.ResolutionFeature;
import io.flutter.plugins.camera.features.resolution.ResolutionPreset;
import io.flutter.plugins.camera.features.sensororientation.SensorOrientationFeature;
import io.flutter.plugins.camera.features.zoomlevel.ZoomLevelFeature;
import java.util.concurrent.Callable;

public class CameraFeatureFactoryImpl implements CameraFeatureFactory {

@Override
public AutoFocusFeature createAutoFocusFeature(
@NonNull CameraProperties cameraProperties,
boolean recordingVideo) {
return new AutoFocusFeature(cameraProperties, recordingVideo);
}

@Override
public ExposureLockFeature createExposureLockFeature(@NonNull CameraProperties cameraProperties) {
return new ExposureLockFeature(cameraProperties);
}

@Override
public ExposureOffsetFeature createExposureOffsetFeature(
@NonNull CameraProperties cameraProperties) {
return new ExposureOffsetFeature(cameraProperties);
}

@Override
public FlashFeature createFlashFeature(@NonNull CameraProperties cameraProperties) {
return new FlashFeature(cameraProperties);
}

@Override
public ResolutionFeature createResolutionFeature(
@NonNull CameraProperties cameraProperties,
ResolutionPreset initialSetting,
String cameraName) {
return new ResolutionFeature(cameraProperties, initialSetting, cameraName);
}

@Override
public FocusPointFeature createFocusPointFeature(
@NonNull CameraProperties cameraProperties,
Callable<CameraRegions> getCameraRegions) {
return new FocusPointFeature(cameraProperties, getCameraRegions);
}

@Override
public FpsRangeFeature createFpsRangeFeature(@NonNull CameraProperties cameraProperties) {
return new FpsRangeFeature(cameraProperties);
}

@Override
public SensorOrientationFeature createSensorOrientationFeature(
@NonNull CameraProperties cameraProperties,
@NonNull Activity activity,
@NonNull DartMessenger dartMessenger) {
return new SensorOrientationFeature(cameraProperties, activity, dartMessenger);
}

@Override
public ZoomLevelFeature createZoomLevelFeature(@NonNull CameraProperties cameraProperties) {
return new ZoomLevelFeature(cameraProperties);
}

@Override
public RegionBoundariesFeature createRegionBoundariesFeature(
@NonNull CameraProperties cameraProperties,
@NonNull CaptureRequest.Builder requestBuilder) {
return new RegionBoundariesFeature(cameraProperties, requestBuilder);
}

@Override
public ExposurePointFeature createExposurePointFeature(
@NonNull CameraProperties cameraProperties,
@NonNull Callable<CameraRegions> getCameraRegions) {
return new ExposurePointFeature(cameraProperties, getCameraRegions);
}

@Override
public NoiseReductionFeature createNoiseReductionFeature(
@NonNull CameraProperties cameraProperties) {
return new NoiseReductionFeature(cameraProperties);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2019 The Chromium 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.camera.features;

/**
Expand All @@ -24,13 +28,6 @@ public enum CameraFeatures {
this.strValue = strValue;
}

public static CameraFeatures getValueForString(String modeStr) {
for (CameraFeatures value : values()) {
if (value.strValue.equals(modeStr)) return value;
}
return null;
}

@Override
public String toString() {
return strValue;
Expand Down
Loading

0 comments on commit 3523016

Please sign in to comment.