added in the three roles: search, adjustable, link that require localization
Summary: Added the android functionality for those three roles: search, adjustable, and link. Until React Native internal framework ports internationalization and localization of strings, I'll handle localization by allowing an extra prop to be passed in that can override talkback's description in another language if needed. Reviewed By: blavalla Differential Revision: D8807692 fbshipit-source-id: b51877d187cb6cb663d65d6b4d072e6dc52a2d03
This commit is contained in:
parent
d0b86ecb4f
commit
e739143809
|
@ -31,9 +31,12 @@ public class AccessibilityRoleUtil {
|
|||
public enum AccessibilityRole {
|
||||
NONE(null),
|
||||
BUTTON("android.widget.Button"),
|
||||
LINK("android.widget.Button"),
|
||||
SEARCH("android.widget.EditText"),
|
||||
IMAGE("android.widget.ImageView"),
|
||||
KEYBOARD_KEY("android.inputmethodservice.Keyboard$Key"),
|
||||
TEXT("android.widget.ViewGroup");
|
||||
KEYBOARDKEY("android.inputmethodservice.Keyboard$Key"),
|
||||
TEXT("android.widget.ViewGroup"),
|
||||
ADJUSTABLE("android.widget.SeekBar");
|
||||
|
||||
@Nullable private final String mValue;
|
||||
|
||||
|
@ -79,38 +82,33 @@ public class AccessibilityRoleUtil {
|
|||
|
||||
public static void setRole(AccessibilityNodeInfoCompat nodeInfo, final AccessibilityRole role) {
|
||||
nodeInfo.setClassName(role.getValue());
|
||||
if (role.equals(AccessibilityRole.LINK)) {
|
||||
nodeInfo.setRoleDescription("Link");
|
||||
}
|
||||
if (role.equals(AccessibilityRole.SEARCH)) {
|
||||
nodeInfo.setRoleDescription("Search Field");
|
||||
}
|
||||
if (role.equals(AccessibilityRole.IMAGE)) {
|
||||
nodeInfo.setRoleDescription("Image");
|
||||
}
|
||||
if (role.equals(AccessibilityRole.ADJUSTABLE)) {
|
||||
nodeInfo.setRoleDescription("Adjustable");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Variables and methods for setting accessibilityRole on view properties.
|
||||
*/
|
||||
private static final String NONE = "none";
|
||||
private static final String BUTTON = "button";
|
||||
private static final String IMAGE = "image";
|
||||
private static final String KEYBOARDKEY = "keyboardkey";
|
||||
private static final String TEXT = "text";
|
||||
|
||||
public static void updateAccessibilityRole(View view, String role) {
|
||||
if (role == null) {
|
||||
view.setAccessibilityDelegate(null);
|
||||
}
|
||||
switch (role) {
|
||||
case NONE:
|
||||
break;
|
||||
case BUTTON:
|
||||
setRole(view, AccessibilityRoleUtil.AccessibilityRole.BUTTON);
|
||||
break;
|
||||
case IMAGE:
|
||||
setRole(view, AccessibilityRoleUtil.AccessibilityRole.IMAGE);
|
||||
break;
|
||||
case KEYBOARDKEY:
|
||||
setRole(view, AccessibilityRoleUtil.AccessibilityRole.KEYBOARD_KEY);
|
||||
break;
|
||||
case TEXT:
|
||||
setRole(view, AccessibilityRoleUtil.AccessibilityRole.TEXT);
|
||||
break;
|
||||
default:
|
||||
view.setAccessibilityDelegate(null);
|
||||
try {
|
||||
setRole(view, AccessibilityRole.valueOf(role.toUpperCase()));
|
||||
} catch (NullPointerException e) {
|
||||
view.setAccessibilityDelegate(null);
|
||||
} catch (IllegalArgumentException e) {
|
||||
view.setAccessibilityDelegate(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue