This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Fixes Android text field to use hint text for accessibility #36846
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Fixes Android text field to use hint text for accessibility
- Loading branch information
commit d601780f335263a913401c7aed8ef6e069a27552
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -885,7 +885,8 @@ && shouldSetCollectionInfo(semanticsNode)) { | |
| // 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.getValueLabelHint()); | ||
| result.setText(semanticsNode.getValue()); | ||
| result.setHintText(semanticsNode.getTextFieldHint()); | ||
| } else if (!semanticsNode.hasFlag(Flag.SCOPES_ROUTE)) { | ||
| CharSequence content = semanticsNode.getValueLabelHint(); | ||
| if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { | ||
|
|
@@ -2773,18 +2774,49 @@ private float max(float a, float b, float c, float d) { | |
| return Math.max(a, Math.max(b, Math.max(c, d))); | ||
| } | ||
|
|
||
| private CharSequence getValueLabelHint() { | ||
| CharSequence[] array; | ||
| 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) { | ||
| array = new CharSequence[] {value, label, hint}; | ||
| return hint; | ||
| } else { | ||
| array = | ||
| new CharSequence[] { | ||
| createSpannableString(value, valueAttributes), | ||
| createSpannableString(label, labelAttributes), | ||
| createSpannableString(hint, hintAttributes), | ||
| }; | ||
| 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); | ||
| } | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| private CharSequence getTextFieldHint() { | ||
| CharSequence[] array = new CharSequence[] {getLabel(), getHint()}; | ||
| ; | ||
|
||
| CharSequence result = null; | ||
| for (CharSequence word : array) { | ||
| if (word != null && word.length() > 0) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, extra semicolon?