Skip to content

Commit

Permalink
added in the three roles: search, adjustable, link that require local…
Browse files Browse the repository at this point in the history
…ization

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
  • Loading branch information
Ziqi Chen authored and facebook-github-bot committed Jul 13, 2018
1 parent d0b86ec commit e739143
Showing 1 changed file with 24 additions and 26 deletions.
Expand Up @@ -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;

Expand Down Expand Up @@ -79,38 +82,33 @@ public void onInitializeAccessibilityNodeInfo(

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);
}
}
}

0 comments on commit e739143

Please sign in to comment.