Skip to content

Commit 28455d7

Browse files
MHShettythestinger
authored andcommitted
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)
1 parent 7489e04 commit 28455d7

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

app/src/main/java/app/grapheneos/camera/capturer/VideoCapturer.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.content.Context
77
import android.content.pm.PackageManager.PERMISSION_GRANTED
88
import android.graphics.Bitmap
99
import android.graphics.drawable.GradientDrawable
10+
import android.graphics.drawable.StateListDrawable
1011
import android.location.Location
1112
import android.media.MediaMetadataRetriever
1213
import android.net.Uri
@@ -273,7 +274,13 @@ class VideoCapturer(private val mActivity: MainActivity) {
273274
// TODO: Uncomment this once the main indicator UI gets implemented
274275
// mActivity.micOffIcon.visibility = View.GONE
275276

276-
val gd: GradientDrawable = mActivity.captureButton.drawable as GradientDrawable
277+
val drawable = mActivity.captureButton.drawable
278+
279+
val gd: GradientDrawable = if (drawable is StateListDrawable) {
280+
drawable.current as GradientDrawable
281+
} else {
282+
drawable as GradientDrawable
283+
}
277284

278285
val animator = ValueAnimator.ofFloat(dp16, dp8)
279286

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

318325
private fun afterRecordingStops() {
319326

320-
val gd: GradientDrawable = mActivity.captureButton.drawable as GradientDrawable
327+
val drawable = mActivity.captureButton.drawable
328+
329+
val gd: GradientDrawable = if (drawable is StateListDrawable) {
330+
drawable.current as GradientDrawable
331+
} else {
332+
drawable as GradientDrawable
333+
}
321334

322335
val animator = ValueAnimator.ofFloat(dp8, dp16)
323336

0 commit comments

Comments
 (0)