Skip to content

Conversation

Asp9998
Copy link

@Asp9998 Asp9998 commented Sep 17, 2025

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

…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
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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

  1. 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

Comment on lines +100 to +102
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean =
if (HardwareKeyManager.dispatchDown(keyCode, event)) true
else super.onKeyDown(keyCode, event)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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)

Comment on lines +104 to +106
override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean =
if (HardwareKeyManager.dispatchUp(keyCode, event)) true
else super.onKeyUp(keyCode, event)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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)

Comment on lines +164 to +171
private fun isShutterKey(keyCode: Int): Boolean {
return when (keyCode) {
KeyEvent.KEYCODE_VOLUME_UP,
KeyEvent.KEYCODE_VOLUME_DOWN,
KeyEvent.KEYCODE_CAMERA -> true
else -> false
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The isShutterKey function can be written more concisely as an expression body, which is a common Kotlin idiom.

            private fun isShutterKey(keyCode: Int): Boolean = when (keyCode) {
                KeyEvent.KEYCODE_VOLUME_UP,
                KeyEvent.KEYCODE_VOLUME_DOWN,
                KeyEvent.KEYCODE_CAMERA -> true
                else -> false
            }

package com.android.developers.androidify.camera

import android.view.KeyEvent
import java.util.concurrent.CopyOnWriteArrayList
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This import of java.util.concurrent.CopyOnWriteArrayList is unused and should be removed to improve code clarity. The current thread-safe implementation using a synchronized mutableListOf is correct, so this leftover import can be confusing.

Copy link

@Herrera9794 Herrera9794 left a comment

Choose a reason for hiding this comment

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

Thankssss

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.

Make volume buttons take a photo
2 participants