Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[camerax] Adds functionality to bind UseCases to a lifecycle #6939

Merged
merged 18 commits into from
Jan 25, 2023

Conversation

camsim99
Copy link
Contributor

@camsim99 camsim99 commented Jan 9, 2023

Adds UseCase and Camera classes and adds methods in the ProcessCameraProvider class to allow for the binding of UseCases to the lifecycle of a Camera.

Fixes flutter/flutter#111220.
Part of flutter/flutter#111127, flutter/flutter#115846.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@camsim99 camsim99 marked this pull request as ready for review January 12, 2023 01:50
@@ -66,7 +63,11 @@ public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {

@Override
public void onAttachedToActivity(@NonNull ActivityPluginBinding activityPluginBinding) {
updateContext(activityPluginBinding.getActivity());
CameraAndroidCameraxPlugin plugin = new CameraAndroidCameraxPlugin();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I missed this in the last PR. But I don't think it is necessary to create a new CameraAndroidCameraxPlugin instance. You should be able to just call setUp on the current instance, right?

@NonNull Long cameraSelectorIdentifier,
@NonNull List<Long> useCaseIds) {
ProcessCameraProvider processCameraProvider =
(ProcessCameraProvider) instanceManager.getInstance(identifier);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you wrap instanceManager.getInstance(..) with Objects.requireNonnull(...). It helps with debugging and removes the lint warning. Same for the line below and other apis.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @gmackall just a heads up about this

ProcessCameraProvider instance) async {
/// Gets identifier that the [instanceManager] has set for
/// the [ProcessCameraProvider] instance.
int getProcessCameraProviderIdentifier(ProcessCameraProvider instance) {
int? identifier = instanceManager.getIdentifier(instance);
identifier ??= instanceManager.addDartCreatedInstance(instance,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this add the instance to the InstanceManager if it doesn't contain the ProcessCameraProvider.?Shouldn't getInstancefromInstances add the ProcessCameraProvider to the InstanceManager? This should throw an error if the InstanceManager doesn't contain instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Fixed that.

Copy link
Contributor

@bparrishMines bparrishMines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nits

camsim99 and others added 2 commits January 25, 2023 14:08
…o/flutter/plugins/camerax/ProcessCameraProviderHostApiImpl.java

Co-authored-by: Maurice Parrish <[email protected]>
@camsim99 camsim99 added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 25, 2023
@auto-submit auto-submit bot merged commit e9406bc into flutter:main Jan 25, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 26, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 26, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jan 26, 2023
* bc0174fd5 [path_provider] Fix iOS `getApplicationSupportDirectory` regression (flutter/plugins#7026)

* 15d799b89 [url_launcher] Convert Windows to Pigeon (flutter/plugins#6991)

* dc8ad7701 Roll Flutter from c35efda to a815ee6 (22 revisions) (flutter/plugins#7025)

* e9406bc20 [camerax] Adds functionality to bind UseCases to a lifecycle (flutter/plugins#6939)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App p: camera platform-android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[camera] Add UseCase class to CameraX Plugin
2 participants