From d4137e8ad39f03cb793685d7cbd74bf31405b705 Mon Sep 17 00:00:00 2001 From: MHShetty Date: Mon, 24 Feb 2025 14:36:31 +0530 Subject: [PATCH] Fix crash when capture button drawable has an unexpected type (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) --- .../grapheneos/camera/capturer/VideoCapturer.kt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/app/grapheneos/camera/capturer/VideoCapturer.kt b/app/src/main/java/app/grapheneos/camera/capturer/VideoCapturer.kt index e418c0cc..b7407928 100644 --- a/app/src/main/java/app/grapheneos/camera/capturer/VideoCapturer.kt +++ b/app/src/main/java/app/grapheneos/camera/capturer/VideoCapturer.kt @@ -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 @@ -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) @@ -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)