Skip to content

Commit dce51f2

Browse files
committed
Merge pull request #346 from onuralpszr/fix/dialog-radio-indicator
fix: render radio buttons in single choice dialogs
2 parents 0364b32 + 1bbedef commit dce51f2

9 files changed

Lines changed: 39 additions & 3 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
[![snyk-security](https://snyk.io/test/github/onuralpszr/CvCamera-Mobile/badge.svg)](https://snyk.io/test/github/onuralpszr/CvCamera-Mobile)
2020
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commit-1.0.0-FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org)
2121

22-
<img src="appPreview/appOverview.png" width="220" alt="Live preview with the FPS overlay"/>
23-
<img src="appPreview/appOverview2.png" width="220" alt="Canny edge detection on the live preview"/>
22+
<img src="appPreview/appOverview.png" width="220" alt="Live camera preview with the FPS overlay"/>
23+
<img src="appPreview/appOverview2.png" width="220" alt="Bottom bar menu"/>
24+
<img src="appPreview/appOverview3.png" width="220" alt="Effect picker"/>
2425

2526
</div>
2627

app/src/main/java/com/os/cvCamera/features/FeatureUi.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.os.cvCamera.features
22

33
import android.app.Activity
4+
import android.widget.ArrayAdapter
45
import android.widget.Toast
56
import androidx.annotation.StringRes
67
import com.google.android.material.dialog.MaterialAlertDialogBuilder
8+
import com.os.cvCamera.R
79

810
// Small helpers shared by the features, so each one does not repeat the same toast and dialog
911
// boilerplate.
@@ -25,9 +27,14 @@ internal fun Activity.showSingleChoiceDialog(
2527
checked: Int,
2628
onPicked: (Int) -> Unit,
2729
) {
30+
// A custom row layout is used because Material3 leaves android:listChoiceIndicatorSingle
31+
// unset, and the default single choice layout resolves its check mark from that attribute,
32+
// so the built in overload draws no radio button at all.
33+
val adapter = ArrayAdapter(this, R.layout.item_single_choice, labels)
34+
2835
MaterialAlertDialogBuilder(this)
2936
.setTitle(title)
30-
.setSingleChoiceItems(labels, checked) { dialog, which ->
37+
.setSingleChoiceItems(adapter, checked) { dialog, which ->
3138
dialog.dismiss()
3239
if (which != checked) onPicked(which)
3340
}.setNegativeButton(android.R.string.cancel, null)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp" android:tint="?attr/colorPrimary">
2+
<path android:fillColor="@android:color/white" android:pathData="M12,7c-2.76,0 -5,2.24 -5,5s2.24,5 5,5 5,-2.24 5,-5 -2.24,-5 -5,-5zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
3+
</vector>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp" android:tint="?attr/colorOnSurfaceVariant">
2+
<path android:fillColor="@android:color/white" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
3+
</vector>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
2+
<item android:drawable="@drawable/ic_radio_checked" android:state_checked="true"/>
3+
<item android:drawable="@drawable/ic_radio_unchecked"/>
4+
</selector>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Single choice row with the radio indicator set directly on the view. Material3 leaves
3+
android:listChoiceIndicatorSingle unset, so relying on the theme attribute renders no
4+
indicator at all. -->
5+
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
6+
android:id="@android:id/text1"
7+
style="?attr/textAppearanceBodyLarge"
8+
android:layout_width="match_parent"
9+
android:layout_height="wrap_content"
10+
android:minHeight="48dp"
11+
android:gravity="center_vertical"
12+
android:paddingStart="24dp"
13+
android:paddingEnd="24dp"
14+
android:drawablePadding="20dp"
15+
android:textColor="?attr/colorOnSurface"
16+
android:checkMark="@drawable/radio_choice_indicator"
17+
android:ellipsize="marquee"
18+
android:singleLine="true"/>

appPreview/appOverview.png

30.8 KB
Loading

appPreview/appOverview2.png

531 KB
Loading

appPreview/appOverview3.png

305 KB
Loading

0 commit comments

Comments
 (0)