Skip to content

Add CameraX take-a-photo snippets - #1090

Open
hamen wants to merge 1 commit into
android:mainfrom
StellarElements:hamen/camerax-take-photo-snippets
Open

hamen wants to merge 1 commit into
android:mainfrom
StellarElements:hamen/camerax-take-photo-snippets

Conversation

@hamen

@hamen hamen commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Code snippets are for: Take a photo with CameraX

Two Kotlin blocks, into camerax/src/main/java/com/example/camerax/snippets/TakePhoto.kt.

Region tag Page section Same as the page? Lines snippet/page
android_camerax_take_photo_setup Set up the camera Yes 5/5
android_camerax_take_photo_save_to_file Take a picture Three lines differ, see below 14/13

The line-count difference is line splits, not different code. A paste test confirms it: the page's block, pasted unchanged and run through spotlessApply, gives exactly this file's form.

List of modifications

File(...) becomes File("photo.jpg"). The page prints Builder(File(...)).build(), which is not valid Kotlin. An earlier draft of this extraction kept the page's line inside a block comment with a real value hidden beside it, so the rendered page stayed byte-identical. The docs team asked for a placeholder file name instead, accepting the visible page change, so the snippet binds the value once and the page changes to match.

// insert your code here. becomes // Insert your code here, in both callbacks. The page prints the lowercase form with a full stop in its Kotlin and its Java block. Capitalized and without the stop matches the comment style in this repository.

All three are page edits. They are listed again at the end.

What the formatter moved

Three changes, all from spotlessApply:

  • takePicture( wraps, and the two arguments stay together on the next line.
  • The onError brace joins its declaration.
  • The call closes as } then ), not }).

To reproduce: paste the page's Kotlin block into camerax and run ./gradlew :camerax:spotlessApply.

Snippets not migrated

Block Page line Lines Why
Java, Set up the camera 59 6 This module is Kotlin only
Java, Take a picture 93 16 This module is Kotlin only

For the page edit

  • File(...) becomes File("photo.jpg") in the Kotlin block.
  • // insert your code here. becomes // Insert your code here in both callbacks, in the Kotlin block and in the Java block.
  • Two Java samples to retire: Set up the camera, Take a picture.
  • The Kotlin block puts the onError brace on its own line. No other block on the page does this.
  • The Kotlin block orders the callbacks onError then onImageSaved. The Java block below it uses the opposite order.

No deprecated APIs. The prose names ImageCapture, takePicture, OutputFileOptions and OnImageSavedCallback, and those stay as published.

Extracts the two Kotlin blocks from the CameraX take-a-photo guide into
camerax/.../snippets/TakePhoto.kt.

Three lines differ from the page, and each changes the page:

- The page prints Builder(File(...)).build(), which is not valid Kotlin.
  The snippet binds Builder(File("photo.jpg")).build(), a placeholder file
  name, on the docs team's ruling.
- Both callbacks print // insert your code here. The snippet prints
  // Insert your code here, to match the comment style in this repository.

The Java samples on the page are not extracted; this module is Kotlin only.
@hamen
hamen marked this pull request as ready for review September 12, 2026 21:30
@hamen
hamen requested a review from a team as a code owner September 12, 2026 21:30
@snippet-bot

snippet-bot Bot commented Sep 12, 2026

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 2 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant