-
Notifications
You must be signed in to change notification settings - Fork 202
feat(camera): volume buttons act as shutter (only on camera screen, respects enabled state) #142
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
base: main
Are you sure you want to change the base?
feat(camera): volume buttons act as shutter (only on camera screen, respects enabled state) #142
Conversation
…espects enabled state) Intercepts Volume Up/Down (and KEYCODE_CAMERA) to trigger captureImage(). Scoped to the camera screen only; otherwise volume works normally. Gated by the same shutter enabled flag as the UI button; ignores long-press repeats. Activity forwards keys via lightweight HardwareKeyManager; screen registers via DisposableEffect. CameraCaptureButton remains UI-only (no hardware-key code).
…espects enabled state) Intercepts Volume Up/Down (and KEYCODE_CAMERA) to trigger captureImage(). Scoped to the camera screen only; otherwise volume works normally. Gated by the same shutter enabled flag as the UI button; ignores long-press repeats. Activity forwards keys via lightweight HardwareKeyManager; screen registers via DisposableEffect. CameraCaptureButton remains UI-only (no hardware-key code). Fixes android#117
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @Asp9998, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a new feature that allows users to capture images using their device's volume buttons or a dedicated camera button while on the camera screen. The change integrates a robust hardware key management system to ensure that this functionality is context-aware, respecting the camera's enabled state and avoiding unintended repeated captures, thereby enhancing the user experience for camera interaction.
Highlights
- Volume Button Shutter: Volume Up/Down buttons and the dedicated camera button (KEYCODE_CAMERA) now act as a shutter to capture images when on the camera screen.
- Scoped Functionality: This hardware key functionality is strictly limited to the camera screen, ensuring volume buttons behave normally elsewhere in the application.
- Respects Enabled State: The hardware shutter respects the existing
shutter enabled
flag, meaning it will only trigger a capture if the UI button would also be enabled. - Long-Press Ignored: The implementation specifically ignores long-press repeat events from the hardware keys to prevent multiple unintended captures.
- Hardware Key Management System: A new
HardwareKeyManager
object has been introduced to centralize the dispatching and handling of hardware key events across the application. - Composable Registration: The hardware shutter handler is registered using a
DisposableEffect
within a new@Composable
function,RegisterHardwareShutter
, ensuring proper lifecycle management.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point by creating a comment using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands on the current page.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a great feature to use hardware volume buttons as a camera shutter. The implementation is well-thought-out, using a centralized HardwareKeyManager
for dispatching key events and a DisposableEffect
to manage the lifecycle of the key handler within the camera screen. The code is clean and correctly handles the feature's scope and enabled state. I've provided a few suggestions to enhance code conciseness and remove an unused import, which will improve maintainability.
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean = | ||
if (HardwareKeyManager.dispatchDown(keyCode, event)) true | ||
else super.onKeyDown(keyCode, event) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of onKeyDown
can be made more concise and idiomatic by using the logical OR (||
) operator. The current if-else
expression is equivalent to HardwareKeyManager.dispatchDown(keyCode, event) || super.onKeyDown(keyCode, event)
, which is more readable.
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean =
HardwareKeyManager.dispatchDown(keyCode, event) || super.onKeyDown(keyCode, event)
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean = | ||
if (HardwareKeyManager.dispatchUp(keyCode, event)) true | ||
else super.onKeyUp(keyCode, event) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to onKeyDown
, the implementation of onKeyUp
can be made more concise by using the logical OR (||
) operator. This improves readability and is more idiomatic in Kotlin.
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean =
HardwareKeyManager.dispatchUp(keyCode, event) || super.onKeyUp(keyCode, event)
private fun isShutterKey(keyCode: Int): Boolean { | ||
return when (keyCode) { | ||
KeyEvent.KEYCODE_VOLUME_UP, | ||
KeyEvent.KEYCODE_VOLUME_DOWN, | ||
KeyEvent.KEYCODE_CAMERA -> true | ||
else -> false | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
package com.android.developers.androidify.camera | ||
|
||
import android.view.KeyEvent | ||
import java.util.concurrent.CopyOnWriteArrayList |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thankssss
Intercepts Volume Up/Down (and KEYCODE_CAMERA) to trigger captureImage().
Scoped to the camera screen only; otherwise volume works normally.
Gated by the same shutter enabled flag as the UI button; ignores long-press repeats.
Activity forwards keys via lightweight HardwareKeyManager; screen registers via DisposableEffect.
CameraCaptureButton remains UI-only (no hardware-key code).
Fixes #117