Skip to content

Commit e8dc67a

Browse files
committed
Add support for Cancel option in the list of menu items on Android (enables screenreader users to dismiss the popup menu).
1 parent 5c05191 commit e8dc67a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/android/ThemeableBrowser.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Licensed to the Apache Software Foundation (ASF) under one
8181
import java.io.InputStream;
8282
import java.lang.reflect.InvocationTargetException;
8383
import java.lang.reflect.Method;
84+
import java.util.Arrays;
8485

8586
@SuppressLint("SetJavaScriptEnabled")
8687
public class ThemeableBrowser extends CordovaPlugin {
@@ -707,6 +708,13 @@ public boolean onTouch(View v, MotionEvent event) {
707708
});
708709

709710
if (features.menu.items != null) {
711+
if (features.menu.cancel != null) {
712+
EventLabel cancelEventLabel = new EventLabel();
713+
cancelEventLabel.label = features.menu.cancel;
714+
cancelEventLabel.event = "cancel";
715+
features.menu.items = ArrayHelper.push(features.menu.items, cancelEventLabel);
716+
}
717+
710718
HideSelectedAdapter<EventLabel> adapter
711719
= new HideSelectedAdapter<EventLabel>(
712720
cordova.getActivity(),
@@ -1542,6 +1550,7 @@ private static class BrowserButton extends Event {
15421550

15431551
private static class BrowserMenu extends BrowserButton {
15441552
public EventLabel[] items;
1553+
public String cancel;
15451554
}
15461555

15471556
private static class Toolbar {
@@ -1557,4 +1566,17 @@ private static class Title {
15571566
public String staticText;
15581567
public boolean showPageTitle;
15591568
}
1569+
1570+
public static class ArrayHelper {
1571+
public static <T> T[] push(T[] arr, T item) {
1572+
T[] tmp = Arrays.copyOf(arr, arr.length + 1);
1573+
tmp[tmp.length - 1] = item;
1574+
return tmp;
1575+
}
1576+
1577+
public static <T> T[] pop(T[] arr) {
1578+
T[] tmp = Arrays.copyOf(arr, arr.length - 1);
1579+
return tmp;
1580+
}
1581+
}
15601582
}

0 commit comments

Comments
 (0)