From 9f3c6b75c3d71dd65ca7cd33383bc90d3e565d6f Mon Sep 17 00:00:00 2001 From: Sergey Volkov Date: Fri, 30 Aug 2019 16:20:34 +0300 Subject: [PATCH] feat(android): add accessibility properties to MenuItem Add "accessibilityHint", "accessibilityLabel" and "accessibilityValue" properties to MenuItem element. refs TIMOB-26463 --- .../titanium/proxy/MenuItemProxy.java | 98 +++++++++++++++++++ .../titanium/proxy/MenuProxy.java | 2 + apidoc/Titanium/Android/MenuItem.yml | 32 ++++++ 3 files changed, 132 insertions(+) diff --git a/android/titanium/src/java/org/appcelerator/titanium/proxy/MenuItemProxy.java b/android/titanium/src/java/org/appcelerator/titanium/proxy/MenuItemProxy.java index 4595726e007..fd8af62077c 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/proxy/MenuItemProxy.java +++ b/android/titanium/src/java/org/appcelerator/titanium/proxy/MenuItemProxy.java @@ -6,6 +6,7 @@ */ package org.appcelerator.titanium.proxy; +import org.appcelerator.kroll.KrollDict; import org.appcelerator.kroll.KrollProxy; import org.appcelerator.kroll.annotations.Kroll; import org.appcelerator.kroll.common.AsyncResult; @@ -17,6 +18,7 @@ import org.appcelerator.titanium.util.TiFileHelper; import org.appcelerator.titanium.util.TiUIHelper; import org.appcelerator.titanium.util.TiUrl; +import org.appcelerator.titanium.view.TiUIView; import android.graphics.drawable.Drawable; import android.os.Build; @@ -143,6 +145,102 @@ public boolean isVisible() return item.isVisible(); } + // clang-format off + @Kroll.method + @Kroll.getProperty + public String getAccessibilityLabel() + // clang-format on + { + return TiConvert.toString(properties, TiC.PROPERTY_ACCESSIBILITY_LABEL); + } + + // clang-format off + @Kroll.method + @Kroll.getProperty + public String getAccessibilityHint() + // clang-format on + { + return TiConvert.toString(properties, TiC.PROPERTY_ACCESSIBILITY_HINT); + } + + // clang-format off + @Kroll.method + @Kroll.getProperty + public String getAccessibilityValue() + // clang-format on + { + return TiConvert.toString(properties, TiC.PROPERTY_ACCESSIBILITY_VALUE); + } + + private void updateContentDescription() + { + String contentDescription = composeContentDescription(); + MenuItemCompat.setContentDescription(item, contentDescription); + } + + public void setContentDescription(KrollDict d) + { + if (d.containsKeyAndNotNull(TiC.PROPERTY_ACCESSIBILITY_LABEL)) { + properties.put(TiC.PROPERTY_ACCESSIBILITY_LABEL, d.get(TiC.PROPERTY_ACCESSIBILITY_LABEL)); + } else { + properties.remove(TiC.PROPERTY_ACCESSIBILITY_LABEL); + } + if (d.containsKey(TiC.PROPERTY_ACCESSIBILITY_HINT)) { + properties.put(TiC.PROPERTY_ACCESSIBILITY_HINT, d.get(TiC.PROPERTY_ACCESSIBILITY_HINT)); + } else { + properties.remove(TiC.PROPERTY_ACCESSIBILITY_HINT); + } + if (d.containsKey(TiC.PROPERTY_ACCESSIBILITY_VALUE)) { + properties.put(TiC.PROPERTY_ACCESSIBILITY_VALUE, d.get(TiC.PROPERTY_ACCESSIBILITY_VALUE)); + } else { + properties.remove(TiC.PROPERTY_ACCESSIBILITY_VALUE); + } + updateContentDescription(); + } + + // clang-format off + @Kroll.method + @Kroll.setProperty + public void setAccessibilityLabel(String label) + // clang-format on + { + if (label != null && label.length() != 0) { + properties.put(TiC.PROPERTY_ACCESSIBILITY_LABEL, label); + } else { + properties.remove(TiC.PROPERTY_ACCESSIBILITY_LABEL); + } + updateContentDescription(); + } + + // clang-format off + @Kroll.method + @Kroll.setProperty + public void setAccessibilityHint(String hint) + // clang-format on + { + if (hint != null && hint.length() != 0) { + properties.put(TiC.PROPERTY_ACCESSIBILITY_HINT, hint); + } else { + properties.remove(TiC.PROPERTY_ACCESSIBILITY_HINT); + } + updateContentDescription(); + } + + // clang-format off + @Kroll.method + @Kroll.setProperty + public void setAccessibilityValue(String value) + // clang-format on + { + if (value != null && value.length() != 0) { + properties.put(TiC.PROPERTY_ACCESSIBILITY_VALUE, value); + } else { + properties.remove(TiC.PROPERTY_ACCESSIBILITY_VALUE); + } + + updateContentDescription(); + } + // clang-format off @Kroll.method @Kroll.setProperty diff --git a/android/titanium/src/java/org/appcelerator/titanium/proxy/MenuProxy.java b/android/titanium/src/java/org/appcelerator/titanium/proxy/MenuProxy.java index 68e46b86f08..fd25b9fe4e3 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/proxy/MenuProxy.java +++ b/android/titanium/src/java/org/appcelerator/titanium/proxy/MenuProxy.java @@ -117,6 +117,8 @@ public MenuItemProxy handleAdd(KrollDict d) if (d.containsKey(TiC.PROPERTY_VISIBLE)) { mip.setVisible(TiConvert.toBoolean(d, TiC.PROPERTY_VISIBLE)); } + + mip.setContentDescription(d); return mip; } diff --git a/apidoc/Titanium/Android/MenuItem.yml b/apidoc/Titanium/Android/MenuItem.yml index 5247e3e0cc5..322a9ea1c40 100644 --- a/apidoc/Titanium/Android/MenuItem.yml +++ b/apidoc/Titanium/Android/MenuItem.yml @@ -127,6 +127,38 @@ events: since: "3.0.0" properties: + - name: accessibilityHint + summary: Briefly describes what performing an action (such as a click) on the view will do. + description: | + Value of this property is concatenated together with + and in the order: `accessibilityLabel`, + `accessibilityValue`, `accessibilityHint`. The concatenated value is then passed as the + argument to the native [MenuItemCompat.setContentDescription](https://developer.android.com/reference/android/support/v4/view/MenuItemCompat#setContentDescription(android.view.MenuItem,%20java.lang.CharSequence)) method. + type: String + since: "8.2.0" + default: null + + - name: accessibilityLabel + summary: A succint label identifying the view for the device's accessibility service. + description: | + Value of this property is concatenated together with + and in the order: `accessibilityLabel`, + `accessibilityValue`, `accessibilityHint`. The concatenated value is then passed as the + argument to the native [MenuItemCompat.setContentDescription](https://developer.android.com/reference/android/support/v4/view/MenuItemCompat#setContentDescription(android.view.MenuItem,%20java.lang.CharSequence)) method. + since: "8.2.0" + type: String + default: null + + - name: accessibilityValue + summary: A string describing the value (if any) of the view for the device's accessibility service. + description: | + Value of this property is concatenated together with + and in the order: `accessibilityLabel`, + `accessibilityValue`, `accessibilityHint`. The concatenated value is then passed as the + argument to the native [MenuItemCompat.setContentDescription](https://developer.android.com/reference/android/support/v4/view/MenuItemCompat#setContentDescription(android.view.MenuItem,%20java.lang.CharSequence)) method. + since: "8.2.0" + type: String + default: null - name: actionView summary: Custom view that replaces the default menu item button.