Merge "TextView should report in an AccessibilityNodeInfo's text its hint if the View text is empty."
This commit is contained in:
committed by
Android (Google) Code Review
commit
98c8b52b0a
@@ -8939,14 +8939,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
|
|
||||||
final boolean isPassword = hasPasswordTransformationMethod();
|
final boolean isPassword = hasPasswordTransformationMethod();
|
||||||
if (!isPassword) {
|
if (!isPassword) {
|
||||||
CharSequence text = getText();
|
CharSequence text = getTextForAccessibility();
|
||||||
if (TextUtils.isEmpty(text)) {
|
if (TextUtils.isEmpty(text)) {
|
||||||
text = getHint();
|
|
||||||
}
|
|
||||||
if (TextUtils.isEmpty(text)) {
|
|
||||||
text = getContentDescription();
|
|
||||||
}
|
|
||||||
if (!TextUtils.isEmpty(text)) {
|
|
||||||
event.getText().add(text);
|
event.getText().add(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8972,7 +8966,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
|
|
||||||
final boolean isPassword = hasPasswordTransformationMethod();
|
final boolean isPassword = hasPasswordTransformationMethod();
|
||||||
if (!isPassword) {
|
if (!isPassword) {
|
||||||
info.setText(getText());
|
info.setText(getTextForAccessibility());
|
||||||
}
|
}
|
||||||
info.setPassword(isPassword);
|
info.setPassword(isPassword);
|
||||||
}
|
}
|
||||||
@@ -8988,6 +8982,20 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
super.sendAccessibilityEvent(eventType);
|
super.sendAccessibilityEvent(eventType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the text reported for accessibility purposes. It is the
|
||||||
|
* text if not empty or the hint.
|
||||||
|
*
|
||||||
|
* @return The accessibility text.
|
||||||
|
*/
|
||||||
|
private CharSequence getTextForAccessibility() {
|
||||||
|
CharSequence text = getText();
|
||||||
|
if (TextUtils.isEmpty(text)) {
|
||||||
|
text = getHint();
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
void sendAccessibilityEventTypeViewTextChanged(CharSequence beforeText,
|
void sendAccessibilityEventTypeViewTextChanged(CharSequence beforeText,
|
||||||
int fromIndex, int removedCount, int addedCount) {
|
int fromIndex, int removedCount, int addedCount) {
|
||||||
AccessibilityEvent event =
|
AccessibilityEvent event =
|
||||||
|
|||||||
Reference in New Issue
Block a user