From b34da51ee81737faf2113ea2979f8d266589d063 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Thu, 27 Oct 2022 12:10:52 -0700 Subject: [PATCH] Revert "Fixes Android text field to use hint text for accessibility (#36846)" (flutter/engine#37083) This reverts commit 0a923d0c2429c7348fa7fe03459987c9338324f0. --- .../io/flutter/view/AccessibilityBridge.java | 52 ++++--------------- .../flutter/view/AccessibilityBridgeTest.java | 7 +-- 2 files changed, 13 insertions(+), 46 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java b/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java index 72b78221dd..ba0d904559 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/view/AccessibilityBridge.java @@ -885,8 +885,7 @@ public class AccessibilityBridge extends AccessibilityNodeProvider { // Scopes routes are not focusable, only need to set the content // for non-scopes-routes semantics nodes. if (semanticsNode.hasFlag(Flag.IS_TEXT_FIELD)) { - result.setText(semanticsNode.getValue()); - result.setHintText(semanticsNode.getTextFieldHint()); + result.setText(semanticsNode.getValueLabelHint()); } else if (!semanticsNode.hasFlag(Flag.SCOPES_ROUTE)) { CharSequence content = semanticsNode.getValueLabelHint(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { @@ -2774,47 +2773,18 @@ public class AccessibilityBridge extends AccessibilityNodeProvider { return Math.max(a, Math.max(b, Math.max(c, d))); } - private CharSequence getValue() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - return value; - } else { - return createSpannableString(value, valueAttributes); - } - } - - private CharSequence getLabel() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - return label; - } else { - return createSpannableString(label, labelAttributes); - } - } - - private CharSequence getHint() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - return hint; - } else { - return createSpannableString(hint, hintAttributes); - } - } - private CharSequence getValueLabelHint() { - CharSequence[] array = new CharSequence[] {getValue(), getLabel(), getHint()}; - CharSequence result = null; - for (CharSequence word : array) { - if (word != null && word.length() > 0) { - if (result == null || result.length() == 0) { - result = word; - } else { - result = TextUtils.concat(result, ", ", word); - } - } + CharSequence[] array; + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + array = new CharSequence[] {value, label, hint}; + } else { + array = + new CharSequence[] { + createSpannableString(value, valueAttributes), + createSpannableString(label, labelAttributes), + createSpannableString(hint, hintAttributes), + }; } - return result; - } - - private CharSequence getTextFieldHint() { - CharSequence[] array = new CharSequence[] {getLabel(), getHint()}; CharSequence result = null; for (CharSequence word : array) { if (word != null && word.length() > 0) { diff --git a/engine/src/flutter/shell/platform/android/test/io/flutter/view/AccessibilityBridgeTest.java b/engine/src/flutter/shell/platform/android/test/io/flutter/view/AccessibilityBridgeTest.java index 0d4a46b100..a88c0323a7 100644 --- a/engine/src/flutter/shell/platform/android/test/io/flutter/view/AccessibilityBridgeTest.java +++ b/engine/src/flutter/shell/platform/android/test/io/flutter/view/AccessibilityBridgeTest.java @@ -77,13 +77,11 @@ public class AccessibilityBridgeTest { } @Test - public void itDescribesTextFieldsWithTextAndHint() { + public void itDescribesTextFieldsWithText() { AccessibilityBridge accessibilityBridge = setUpBridge(); TestSemanticsNode testSemanticsNode = new TestSemanticsNode(); - testSemanticsNode.value = "Hello, World"; - testSemanticsNode.label = "some label"; - testSemanticsNode.hint = "some hint"; + testSemanticsNode.label = "Hello, World"; testSemanticsNode.addFlag(AccessibilityBridge.Flag.IS_TEXT_FIELD); TestSemanticsUpdate testSemanticsUpdate = testSemanticsNode.toUpdate(); testSemanticsUpdate.sendUpdateToBridge(accessibilityBridge); @@ -91,7 +89,6 @@ public class AccessibilityBridgeTest { assertEquals(nodeInfo.getContentDescription(), null); assertEquals(nodeInfo.getText().toString(), "Hello, World"); - assertEquals(nodeInfo.getHintText().toString(), "some label, some hint"); } @Test