Skip to content

Implement Camera2 - Image Capture Sample #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 22, 2023
Merged

Conversation

madebymozart
Copy link
Contributor

@madebymozart madebymozart commented May 23, 2023

Description

This CL contains sample code for Camera2 Image Capture. This sample demonstrate how a developer can capture and image using the Camera2 APIs. This sample also demonstrate howt o display the captured image via the ImageViewerFragment class

How Has This Been Tested?

This sample app was tested on 3 devices on 3 different version of android:

Test Configuration #1 - Pixel 6 Pro API 33 (Android 13)
**Test Configuration #2 - Samsung Galaxy S22 Ultra (Android 12) **
Test Configuration #3 - Pixel 5a With 5G (Android 11)

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation

Screenshots

1000000876
1000000875

@madebymozart madebymozart requested a review from marcelpinto May 23, 2023 15:33
@madebymozart madebymozart self-assigned this May 23, 2023
@madebymozart madebymozart added the new sample This denotes the creation of a new sample in the platform samples app label May 23, 2023
@madebymozart madebymozart force-pushed the camera2-imagecapture branch 2 times, most recently from f14dfb1 to 1160bff Compare May 23, 2023 15:41
@android android deleted a comment from google-cla bot May 23, 2023
@@ -24,6 +24,14 @@ android {
}

dependencies {
// Add samples specific dependencies
// EXIF Interface
implementation("androidx.exifinterface:exifinterface:1.3.6")
Copy link
Contributor

Choose a reason for hiding this comment

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

implementation("androidx.viewpager2:viewpager2:1.0.0")

// Glide
implementation("com.github.bumptech.glide:glide:4.15.1")
Copy link
Contributor

Choose a reason for hiding this comment

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

The project already uses Coil for image loading. Could you use that instead?
https://github.com/coil-kt/coil

description = "This sample demonstrates how to capture and image and encode it into a JPEG "
+ "container. Includes enable torch (flash) support is available.",
documentation = "https://developer.android.com/training/camera2/capture-sessions-requests",
owners = ["Mozart Louis (mozart@google.com)"],
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's avoid this feature. Better not to expose your email in the codebase + owners tend to change quite fast and we rather track this internally

@Sample(
name = "Camera2 - Image Capture",
description = "This sample demonstrates how to capture and image and encode it into a JPEG "
+ "container. Includes enable torch (flash) support is available.",
Copy link
Contributor

Choose a reason for hiding this comment

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

"if it's available?"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some Devices don't have a touch light (Flash Capabilities)

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, but I mean the sentence is not correct.

Includes enable torch (flash) support when available.

or

Includes enable torch (flash) support if it's available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I see what you mean, Correcting in the next commit

@@ -18,6 +18,7 @@

<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see it being used btw. Is it needed?

Copy link
Contributor Author

@madebymozart madebymozart Jun 5, 2023

Choose a reason for hiding this comment

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

I originally meant for it to be used to send a quick notification so the user can view the photos in an external viewer, but not needed anymore. Will remove

import java.io.File
import kotlin.math.max

class ImageViewerFragment(
Copy link
Contributor

Choose a reason for hiding this comment

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

You should not pass argument like this in a fragment.
https://developer.android.com/guide/fragments/create#add-programmatic

@madebymozart madebymozart force-pushed the camera2-imagecapture branch from fb1bbdb to 9c5ff19 Compare June 8, 2023 21:33
@madebymozart madebymozart requested a review from marcelpinto June 12, 2023 16:43
binding.fragmentCamera2ImageCaptureViewfinder.visibility = View.GONE
binding.fragmentCamera2ImageCaptureButton.visibility = View.GONE

parentFragmentManager.commit {
Copy link
Contributor

Choose a reason for hiding this comment

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

The simple image viewer is already part of this fragment. You don't need the commit right?

binding.fragmentCamera2ImageCaptureButton.visibility = View.GONE

parentFragmentManager.commit {
binding.fragmentCamera2ImageCaptureImageView.setContent {
Copy link
Contributor

Choose a reason for hiding this comment

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

How are you handling the back navigation? Once you set the content the image will take most of the screen and user cannot remove it right?

@madebymozart madebymozart force-pushed the camera2-imagecapture branch from b87f495 to 4a28e64 Compare June 14, 2023 17:28
private fun returnToImageCapture() {
binding.fragmentCamera2ImageCaptureButton.visibility = View.VISIBLE
binding.fragmentCamera2PostCaptureBackButton.visibility = View.GONE
binding.fragmentCamera2ImageCaptureImageView.setContent { }
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: if you make it gone there is probably no need to set an empty content

@madebymozart madebymozart force-pushed the camera2-imagecapture branch from 4a28e64 to 6bb0fa5 Compare June 20, 2023 21:03
@madebymozart madebymozart merged commit 6e27e45 into main Jun 22, 2023
@madebymozart madebymozart deleted the camera2-imagecapture branch June 22, 2023 06:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new sample This denotes the creation of a new sample in the platform samples app
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants