-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Fix flash overlay animation not appearing fully over SurfaceView by using a dedicated overlay View #618
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?
Fix flash overlay animation not appearing fully over SurfaceView by using a dedicated overlay View #618
Conversation
…sing a dedicated overlay View
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.
Hello @bolaware, 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!
Summary of Changes
Hello! Gemini here, providing a summary of this pull request to help everyone get up to speed quickly.
This PR addresses an issue where the flash overlay animation wasn't fully covering the screen when using PreviewView
with ImplementationMode.PERFORMANCE
. This mode uses a SurfaceView
internally, which draws in a separate window layer and can cause clipping or obscuring of views placed above it in the hierarchy.
Instead of switching to the less performant TextureView
mode, this change introduces a dedicated, full-screen View
(white_overlay
) positioned above the PreviewView
. The flash animation is now implemented by animating the alpha property of this new overlay view from 1 (fully visible white) to 0 (transparent), making it appear as a flash. This approach ensures the animation covers the entire screen regardless of the underlying PreviewView
implementation and also removes the need for the previous API level check (Android 23+), making the flash animation available on all supported versions.
Highlights
- Fix Flash Overlay: Resolves the issue where the flash animation was clipped or obscured by the
SurfaceView
used byPreviewView
inPERFORMANCE
mode. - Dedicated Overlay View: Introduces a new full-screen
View
(white_overlay
) specifically for handling the flash animation, placed above the camera preview. - Alpha Animation: Implements the flash effect by animating the alpha of the new overlay view from 1 to 0, providing a smooth fade-out effect.
- Removed API Level Check: Eliminates the
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
check, making the flash animation available on all supported Android versions. - Uses Coroutines: The animation logic is now managed within a coroutine launched from the
viewLifecycleOwner.lifecycleScope
, usingdelay
for timing.
Changelog
- CameraXBasic/app/src/main/java/com/android/example/cameraxbasic/fragments/CameraFragment.kt
- Removed imports for
android.graphics.Color
andandroid.graphics.drawable.ColorDrawable
as the old foreground drawable approach is no longer used. - Added import for
kotlinx.coroutines.delay
to facilitate timing within the new coroutine-based animation. - Replaced the old
root.postDelayed
logic for flash animation with a new implementation usingviewLifecycleOwner.lifecycleScope.launch
. - The new animation targets the
whiteOverlay
view, setting its alpha to 1, making it visible, animating its alpha back to 0, and finally setting its visibility toGONE
. - Removed the
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
check, making the animation universally available.
- Removed imports for
- CameraXBasic/app/src/main/res/layout/fragment_camera.xml
- Added a new
<View>
element with the IDwhite_overlay
. - This new view is configured to match the parent size, have a white background, and is initially set to
alpha="0"
andvisibility="gone"
.
- Added a new
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
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 issue 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 is currently in preview and 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 to provide feedback.
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.
A view on top, a layer below,
Surface draws fast, but shadows show.
An overlay bright,
Fades out of sight,
Now flash works right, watch photos grow.
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 effectively addresses the issue of the flash overlay animation not appearing fully over the SurfaceView
. The introduction of a dedicated overlay View
is a clean and robust solution that works across all API levels, eliminating the previous API-specific code. The explanation in the PR description is excellent and clearly outlines the problem and the chosen solution.
The code changes are well-implemented, and the new animation logic using coroutines is clear and idiomatic Kotlin. Overall, this is a high-quality contribution that improves both functionality and code clarity.
Summary of Findings
- Minor XML Formatting: In
CameraXBasic/app/src/main/res/layout/fragment_camera.xml
, the file ends without a newline character. While this doesn't affect functionality, it's a common convention to end files with a newline. This is alow
severity issue and no review comment was added due to review settings. - Clarity of Constant Usage: In
CameraFragment.kt
,ANIMATION_SLOW_MILLIS
(100L) is used as a delay before the flash animation, whileANIMATION_FAST_MILLIS
(50L) is used for the flash animation duration itself. The naming is generally for animation durations. While functionally correct and the timings seem appropriate, using it as a delay might be slightly less intuitive if one encounters it without the broader context of these constants. This is alow
severity issue and no review comment was added due to review settings.
Merge Readiness
The changes look good and effectively solve the stated problem. The code is clear, and the approach is sound. I believe this pull request is in good shape to be merged. As I am an AI assistant, I am not authorized to approve pull requests; please ensure it undergoes further review and approval by the designated maintainers.
The foreground drawable was not rendering fully over the entire screen due to the use of
SurfaceView
byPreviewView
whenImplementationMode.PERFORMANCE
is used (which is the default)(Source).SurfaceView
draws in a separate window layer, which causes it to clip or obscure any views (like overlays or foregrounds) placed above it in the view hierarchy.Instead of switching to
TextureView
viaImplementationMode.COMPATIBLE
(which is less performant [source]), this fix introduces a dedicated full-screen overlay View positioned above the camera preview. The flash animation is now handled by toggling the visibility and animating the alpha of this overlay view, ensuring consistent visual feedback without compromising performance.Additionally, this approach eliminates the need for API-level checks (previously required for Android 23 and below), making the flash animation available across all supported versions.