Skip to content

Commit 09ce277

Browse files
committed
Support custom accessibility descriptions for buttons on Android
1 parent e8dc67a commit 09ce277

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/android/ThemeableBrowser.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
630630
// Back button
631631
final Button back = createButton(
632632
features.backButton,
633-
"back button",
633+
"back button" ,
634634
new View.OnClickListener() {
635635
public void onClick(View v) {
636636
emitButtonEvent(
@@ -653,7 +653,7 @@ public void onClick(View v) {
653653
// Forward button
654654
final Button forward = createButton(
655655
features.forwardButton,
656-
"forward button",
656+
"forward button" ,
657657
new View.OnClickListener() {
658658
public void onClick(View v) {
659659
emitButtonEvent(
@@ -673,7 +673,7 @@ public void onClick(View v) {
673673
// Close/Done button
674674
Button close = createButton(
675675
features.closeButton,
676-
"close button",
676+
"close button" ,
677677
new View.OnClickListener() {
678678
public void onClick(View v) {
679679
emitButtonEvent(
@@ -684,13 +684,19 @@ public void onClick(View v) {
684684
}
685685
);
686686

687+
687688
// Menu button
688689
Spinner menu = features.menu != null
689690
? new MenuSpinner(cordova.getActivity()) : null;
690691
if (menu != null) {
691692
menu.setLayoutParams(new LinearLayout.LayoutParams(
692693
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
693-
menu.setContentDescription("menu button");
694+
695+
if(features.menu.accessibilityDescription != null){
696+
menu.setContentDescription(features.menu.accessibilityDescription);
697+
}else{
698+
menu.setContentDescription("menu button");
699+
}
694700
setButtonImages(menu, features.menu, DISABLED_ALPHA);
695701

696702
// We are not allowed to use onClickListener for Spinner, so we will use
@@ -746,6 +752,7 @@ public void onNothingSelected(
746752
}
747753
}
748754

755+
749756
// Title
750757
final TextView title = features.title != null
751758
? new TextView(cordova.getActivity()) : null;
@@ -1213,12 +1220,12 @@ private void setBackground(View view, Drawable drawable) {
12131220
}
12141221
}
12151222

1216-
private Button createButton(BrowserButton buttonProps, String description,
1223+
private Button createButton(BrowserButton buttonProps, String defaultDescription,
12171224
View.OnClickListener listener) {
12181225
Button result = null;
12191226
if (buttonProps != null) {
12201227
result = new Button(cordova.getActivity());
1221-
result.setContentDescription(description);
1228+
result.setContentDescription(buttonProps.accessibilityDescription != null ? buttonProps.accessibilityDescription : defaultDescription);
12221229
result.setLayoutParams(new LinearLayout.LayoutParams(
12231230
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
12241231
setButtonImages(result, buttonProps, DISABLED_ALPHA);
@@ -1228,7 +1235,7 @@ private Button createButton(BrowserButton buttonProps, String description,
12281235
} else {
12291236
emitWarning(WRN_UNDEFINED,
12301237
String.format("%s is not defined. Button will not be shown.",
1231-
description));
1238+
defaultDescription));
12321239
}
12331240
return result;
12341241
}
@@ -1546,6 +1553,7 @@ private static class BrowserButton extends Event {
15461553
public String wwwImagePressed;
15471554
public double wwwImageDensity = 1;
15481555
public String align = ALIGN_LEFT;
1556+
public String accessibilityDescription;
15491557
}
15501558

15511559
private static class BrowserMenu extends BrowserButton {

0 commit comments

Comments
 (0)