This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[camera] Flash functionality for Android and iOS (#3314)
* Move camera to camera/camera * Fix relative path after move * First suggestion for camera platform interface * Remove test coverage folder * Update the version to 1.0.0 * Remove redundant analysis overrides * Renamed onLatestImageAvailableHandler definition * Split CameraEvents into separate streams * Updated platform interface to have recording methods return XFile instances. * Update documentation and unit tests to match platform interface changes * Make file input optional for recording methods in platform interface. Update docs. * Add missing full stop in docs. * Run dartfmt. Wrapped docs after max 80 cols. Added missing full stop. * Implemented & tested first parts of method channel implementation * Remove unused EventChannelMock class * Add missing unit tests * Add availableCameras to method channel implementation * Updated platform interface * Update packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart Co-authored-by: Maurits van Beusekom <[email protected]> * Update packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart Co-authored-by: Maurits van Beusekom <[email protected]> * Added placeholders in default method channel implementation * Add missing implementations to default method channel implementation * Fix formatting * Fix PR feedback * Add unit test for availableCameras * Expand availableCameras unit test. Added unit test for takePicture. * Add unit test for startVideoRecording * Add unit test for prepareForVideoRecording * Add unit test for stopVideoRecording * Add unit test for pauseVideoRecording * Add unit test for buildView * Remove TODO comment * Update packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart Co-authored-by: Maurits van Beusekom <[email protected]> * Update packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart Co-authored-by: Maurits van Beusekom <[email protected]> * Update packages/camera/camera_platform_interface/lib/src/method_channel/method_channel_camera.dart Co-authored-by: Maurits van Beusekom <[email protected]> * WIP: Dart and Android implementation * Have resolution stream replay last value on subscription. Replace stream_transform with rxdart. * Added reverse method channel to replace event channel. Updated initialise and takePicture implementations for android. WIP implementation for startVideoRecording * Fixed example app for Android. Removed isRecordingVideo and isStreamingImages from buildView method. * iOS implementation: Removed standard event channel. Added reverse method channel. Updated initialize method. Added resolution changed event. Updated error reporting to use new method channel. * Added some first tests for camera/camera * Started splitting initialize method * More tests and some feedback * Finish splitting up initialize for iOS * Update unit tests * Remove unused listener in plugin * Fix takePicture method on iOS * Fix video recording on iOS. Updated platform interface. * Update unit tests * Update error handling of video methods in iOS code. Make iOS code more consistent. * Split initialize method on Android * Updated startVideoRecording documentation * Make sure file is returned by stopVideoRecording * Change cast * Use correct event-type after initializing * Fix DartMessenger unit-tests * Fix formatting * Fixed tests, formatting and analysis warnings * Added missing documentation public APIs * Added missing license to Dart files * Fix formatting issues * Updated CHANGELOG and version * Added more tests * Formatted code * Added additional unit-tests to platform_interface * Fix formatting issues * Re-added the CameraPreview widget * Refactored CameraException not to use * Use import/export instead of part implementation * fixed formatting * Resolved additional feedback * Resolved additional feedback * Flash WIP * Implement flash modes for Android * Update dependency to git repo * Add missing PictureCaptureRequest class * Add PR feedback * Move enums out of Camera.java * Expanded platform interface so support setting flash mode * Formatted dart code * Manually serialize flash mode enum rather than relying on stringification. * Add default to flash mode serialization * Fix for unit tests and reformatting * Fixed CHANGELOG and remove redundant iOS files * Expose FlashMode through camera package * Add reqeusted unit tests * Clean up new tests * Add unit tests for Android implementation * Update platform interface dependency to point to pub.dev release. Co-authored-by: Maurits van Beusekom <[email protected]> Co-authored-by: Maurits van Beusekom <[email protected]> Co-authored-by: daniel <[email protected]>
- Loading branch information
1 parent
debfbec
commit 22422af
Showing
17 changed files
with
542 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
.../camera/camera/android/src/main/java/io/flutter/plugins/camera/PictureCaptureRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.flutter.plugins.camera; | ||
|
||
import androidx.annotation.Nullable; | ||
import io.flutter.plugin.common.MethodChannel; | ||
|
||
class PictureCaptureRequest { | ||
|
||
enum State { | ||
idle, | ||
awaitingPreCapture, | ||
capturing, | ||
finished, | ||
error, | ||
} | ||
|
||
private final MethodChannel.Result result; | ||
private State state; | ||
|
||
public PictureCaptureRequest(MethodChannel.Result result) { | ||
this.result = result; | ||
state = State.idle; | ||
} | ||
|
||
public void setState(State state) { | ||
if (isFinished()) throw new IllegalStateException("Request has already been finished"); | ||
this.state = state; | ||
} | ||
|
||
public State getState() { | ||
return state; | ||
} | ||
|
||
public boolean isFinished() { | ||
return state == State.finished || state == State.error; | ||
} | ||
|
||
public void finish(String absolutePath) { | ||
if (isFinished()) throw new IllegalStateException("Request has already been finished"); | ||
result.success(absolutePath); | ||
state = State.finished; | ||
} | ||
|
||
public void error( | ||
String errorCode, @Nullable String errorMessage, @Nullable Object errorDetails) { | ||
if (isFinished()) throw new IllegalStateException("Request has already been finished"); | ||
result.error(errorCode, errorMessage, errorDetails); | ||
state = State.error; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/types/FlashMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.flutter.plugins.camera.types; | ||
|
||
// Mirrors flash_mode.dart | ||
public enum FlashMode { | ||
off, | ||
auto, | ||
always; | ||
|
||
public static FlashMode getValueForString(String modeStr) { | ||
try { | ||
return valueOf(modeStr); | ||
} catch (IllegalArgumentException | NullPointerException e) { | ||
return null; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...camera/camera/android/src/main/java/io/flutter/plugins/camera/types/ResolutionPreset.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.flutter.plugins.camera.types; | ||
|
||
// Mirrors camera.dart | ||
public enum ResolutionPreset { | ||
low, | ||
medium, | ||
high, | ||
veryHigh, | ||
ultraHigh, | ||
max, | ||
} |
Oops, something went wrong.