Skip to content

Commit

Permalink
feat(android): add accessibility properties to MenuItem
Browse files Browse the repository at this point in the history
Add "accessibilityHint", "accessibilityLabel" and "accessibilityValue" properties to MenuItem
element.

refs TIMOB-26463
  • Loading branch information
drauggres authored and sgtcoolguy committed Sep 17, 2019
1 parent 8ecfb1e commit 9f3c6b7
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
32 changes: 32 additions & 0 deletions apidoc/Titanium/Android/MenuItem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
<Titanium.Android.MenuItem.accessibilityLabel> and <Titanium.Android.MenuItem.accessibilityValue> 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
<Titanium.Android.MenuItem.accessibilityValue> and <Titanium.Android.MenuItem.accessibilityHint> 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
<Titanium.Android.MenuItem.accessibilityLabel> and <Titanium.Android.MenuItem.accessibilityHint> 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.
Expand Down

0 comments on commit 9f3c6b7

Please sign in to comment.