Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package com.android.example.cameraxbasic.fragments
import android.annotation.SuppressLint
import android.content.*
import android.content.res.Configuration
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.hardware.display.DisplayManager
import android.os.Build
import android.os.Bundle
Expand Down Expand Up @@ -51,6 +49,7 @@ import com.android.example.cameraxbasic.utils.MediaStoreUtils
import com.android.example.cameraxbasic.utils.simulateClick
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.nio.ByteBuffer
import java.text.SimpleDateFormat
Expand Down Expand Up @@ -517,15 +516,17 @@ class CameraFragment : Fragment() {
}
})

// We can only change the foreground Drawable using API level 23+ API
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

// Display flash animation to indicate that photo was captured
fragmentCameraBinding.root.postDelayed({
fragmentCameraBinding.root.foreground = ColorDrawable(Color.WHITE)
fragmentCameraBinding.root.postDelayed(
{ fragmentCameraBinding.root.foreground = null }, ANIMATION_FAST_MILLIS)
}, ANIMATION_SLOW_MILLIS)
// Display flash animation to indicate that photo was captured
viewLifecycleOwner.lifecycleScope.launch {
delay(ANIMATION_SLOW_MILLIS)
fragmentCameraBinding.whiteOverlay.apply {
alpha = 1f
visibility = View.VISIBLE
animate()
.alpha(0f)
.setDuration(ANIMATION_FAST_MILLIS)
.withEndAction { visibility = View.GONE }
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions CameraXBasic/app/src/main/res/layout/fragment_camera.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />

<View
android:id="@+id/white_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:alpha="0"
android:visibility="gone"/>

</androidx.constraintlayout.widget.ConstraintLayout>