Use TextInputLayout for the name field in the create/rename mode page

In addition to looking nicer, this fixes two accessibility issues ("no hint when text is entered" and "reason for disabled button is unclear").

This requires a bit of theme merging black magic, because TextInputLayout requires a Theme.AppCompat descendant, which the Settings theme isn't.

Fixes: 356398157
Fixes: 370654542
Fixes: 369942776
Test: atest ZenModeEditNamePreferenceControllerTest
Flag: android.app.modes_ui
Change-Id: I92d8ec044dabc6daed5d755e206120ec7abc143e
This commit is contained in:
Matías Hernández
2024-10-03 13:21:34 +02:00
parent fd84f1203e
commit b1e28233c1
5 changed files with 75 additions and 16 deletions

View File

@@ -15,23 +15,37 @@
limitations under the License.
-->
<!-- Theme.AppCompat.DayNight is in the parent View so that it's merged with the Theme.Settings
theme below. An AppCompat descendant (which Theme.Settings isn't is necessary to inflate
TextInputLayout. -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Theme.AppCompat.DayNight"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingBottom="8dp">
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
<EditText
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/edit_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@android:id/edit"
android:minHeight="48dp"
android:maxLines="1"
android:inputType="text|textCapSentences"
android:imeOptions="actionDone"
android:selectAllOnFocus="true"
android:hint="@string/zen_mode_edit_name_hint" />
android:theme="@style/Theme.Settings"
style="?attr/textInputFilledStyle"
app:endIconMode="clear_text"
app:errorEnabled="true"
android:hint="@string/zen_mode_edit_name_hint">
</LinearLayout>
<com.google.android.material.textfield.TextInputEditText
android:id="@android:id/edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="1"
android:inputType="text|textCapSentences"
android:imeOptions="actionDone"
android:selectAllOnFocus="true" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>