Skip to content

Commit

Permalink
Fix crash when capture button drawable has an unexpected type
Browse files Browse the repository at this point in the history
(Certain devices wrap the shape drawable with a selector group which leads to a crash while performing explicit type-cast to animate corner radius of the recording drawable)
  • Loading branch information
MHShetty authored and thestinger committed Feb 24, 2025
1 parent 7489e04 commit 28455d7
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions app/src/main/java/app/grapheneos/camera/capturer/VideoCapturer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.content.Context
import android.content.pm.PackageManager.PERMISSION_GRANTED
import android.graphics.Bitmap
import android.graphics.drawable.GradientDrawable
import android.graphics.drawable.StateListDrawable
import android.location.Location
import android.media.MediaMetadataRetriever
import android.net.Uri
Expand Down Expand Up @@ -273,7 +274,13 @@ class VideoCapturer(private val mActivity: MainActivity) {
// TODO: Uncomment this once the main indicator UI gets implemented
// mActivity.micOffIcon.visibility = View.GONE

val gd: GradientDrawable = mActivity.captureButton.drawable as GradientDrawable
val drawable = mActivity.captureButton.drawable

val gd: GradientDrawable = if (drawable is StateListDrawable) {
drawable.current as GradientDrawable
} else {
drawable as GradientDrawable
}

val animator = ValueAnimator.ofFloat(dp16, dp8)

Expand Down Expand Up @@ -317,7 +324,13 @@ class VideoCapturer(private val mActivity: MainActivity) {

private fun afterRecordingStops() {

val gd: GradientDrawable = mActivity.captureButton.drawable as GradientDrawable
val drawable = mActivity.captureButton.drawable

val gd: GradientDrawable = if (drawable is StateListDrawable) {
drawable.current as GradientDrawable
} else {
drawable as GradientDrawable
}

val animator = ValueAnimator.ofFloat(dp8, dp16)

Expand Down

0 comments on commit 28455d7

Please sign in to comment.