aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorPo Lu2023-03-17 13:10:23 +0800
committerPo Lu2023-03-17 13:10:23 +0800
commit45b5c9b8b72a9dd561c7e2d43ead8ce64e79b041 (patch)
treed868f96a69003ec82a8ef72222ca82bca4257ada /java
parentda660a1ffa3218f8e6ec4dfd5422ca6c1ded38ae (diff)
downloademacs-45b5c9b8b72a9dd561c7e2d43ead8ce64e79b041.tar.gz
emacs-45b5c9b8b72a9dd561c7e2d43ead8ce64e79b041.zip
Improve radio button appearance in Android menus
* java/org/gnu/emacs/EmacsContextMenu.java (EmacsContextMenu): New field `lastGroupId'. (Item): New field `isRadio'. (addItem): New arg `isRadio'. (inflateMenuItems): Apply an empty radio button group if required. * src/androidmenu.c (android_init_emacs_context_menu): Adjust accordingly. (android_menu_show): Likewise.
Diffstat (limited to 'java')
-rw-r--r--java/org/gnu/emacs/EmacsContextMenu.java23
1 files changed, 20 insertions, 3 deletions
diff --git a/java/org/gnu/emacs/EmacsContextMenu.java b/java/org/gnu/emacs/EmacsContextMenu.java
index d780641ba70..5bae41bd61d 100644
--- a/java/org/gnu/emacs/EmacsContextMenu.java
+++ b/java/org/gnu/emacs/EmacsContextMenu.java
@@ -55,6 +55,9 @@ public final class EmacsContextMenu
55 /* The serial ID of the last context menu to be displayed. */ 55 /* The serial ID of the last context menu to be displayed. */
56 public static int lastMenuEventSerial; 56 public static int lastMenuEventSerial;
57 57
58 /* The last group ID used for a menu item. */
59 public int lastGroupId;
60
58 private static class Item implements MenuItem.OnMenuItemClickListener 61 private static class Item implements MenuItem.OnMenuItemClickListener
59 { 62 {
60 public int itemID; 63 public int itemID;
@@ -62,6 +65,7 @@ public final class EmacsContextMenu
62 public EmacsContextMenu subMenu; 65 public EmacsContextMenu subMenu;
63 public boolean isEnabled, isCheckable, isChecked; 66 public boolean isEnabled, isCheckable, isChecked;
64 public EmacsView inflatedView; 67 public EmacsView inflatedView;
68 public boolean isRadio;
65 69
66 @Override 70 @Override
67 public boolean 71 public boolean
@@ -153,12 +157,14 @@ public final class EmacsContextMenu
153 checkable. Likewise, if ISCHECKED is set, make the item 157 checkable. Likewise, if ISCHECKED is set, make the item
154 checked. 158 checked.
155 159
156 If TOOLTIP is non-NULL, set the menu item tooltip to TOOLTIP. */ 160 If TOOLTIP is non-NULL, set the menu item tooltip to TOOLTIP.
161
162 If ISRADIO, then display the check mark as a radio button. */
157 163
158 public void 164 public void
159 addItem (int itemID, String itemName, boolean isEnabled, 165 addItem (int itemID, String itemName, boolean isEnabled,
160 boolean isCheckable, boolean isChecked, 166 boolean isCheckable, boolean isChecked,
161 String tooltip) 167 String tooltip, boolean isRadio)
162 { 168 {
163 Item item; 169 Item item;
164 170
@@ -169,6 +175,7 @@ public final class EmacsContextMenu
169 item.isCheckable = isCheckable; 175 item.isCheckable = isCheckable;
170 item.isChecked = isChecked; 176 item.isChecked = isChecked;
171 item.tooltip = tooltip; 177 item.tooltip = tooltip;
178 item.isRadio = isRadio;
172 179
173 menuItems.add (item); 180 menuItems.add (item);
174 } 181 }
@@ -244,7 +251,11 @@ public final class EmacsContextMenu
244 } 251 }
245 else 252 else
246 { 253 {
247 menuItem = menu.add (item.itemName); 254 if (item.isRadio)
255 menuItem = menu.add (++lastGroupId, Menu.NONE, Menu.NONE,
256 item.itemName);
257 else
258 menuItem = menu.add (item.itemName);
248 menuItem.setOnMenuItemClickListener (item); 259 menuItem.setOnMenuItemClickListener (item);
249 260
250 /* If the item ID is zero, then disable the item. */ 261 /* If the item ID is zero, then disable the item. */
@@ -260,6 +271,12 @@ public final class EmacsContextMenu
260 if (item.isChecked) 271 if (item.isChecked)
261 menuItem.setChecked (true); 272 menuItem.setChecked (true);
262 273
274 /* Define an exclusively checkable group if the item is a
275 radio button. */
276
277 if (item.isRadio)
278 menu.setGroupCheckable (lastGroupId, true, true);
279
263 /* If the tooltip text is set and the system is new enough 280 /* If the tooltip text is set and the system is new enough
264 to support menu item tooltips, set it on the item. */ 281 to support menu item tooltips, set it on the item. */
265 282