From 4a328b857812625ec82b31d8efd928f8580d9561 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Sat, 11 Mar 2023 11:35:59 +0800 Subject: [PATCH] Fix problems with the menu bar on large screen Android devices * java/org/gnu/emacs/EmacsActivity.java (onContextMenuClosed): Process submenu closing normally if it happens more than 300 ms after a submenu item was selected. * java/org/gnu/emacs/EmacsContextMenu.java (EmacsContextMenu) (onMenuItemClick, display1): Give `wasSubmenuSelected' different values depending on how the submenu was selected. --- java/org/gnu/emacs/EmacsActivity.java | 8 ++++++-- java/org/gnu/emacs/EmacsContextMenu.java | 20 ++++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/java/org/gnu/emacs/EmacsActivity.java b/java/org/gnu/emacs/EmacsActivity.java index 735a464be8e..b480fc40b2e 100644 --- a/java/org/gnu/emacs/EmacsActivity.java +++ b/java/org/gnu/emacs/EmacsActivity.java @@ -321,10 +321,14 @@ public class EmacsActivity extends Activity /* See the comment inside onMenuItemClick. */ - if (EmacsContextMenu.wasSubmenuSelected + if (((EmacsContextMenu.wasSubmenuSelected == -2) + || (EmacsContextMenu.wasSubmenuSelected >= 0 + && ((System.currentTimeMillis () + - EmacsContextMenu.wasSubmenuSelected) + <= 300))) || menu == lastClosedMenu) { - EmacsContextMenu.wasSubmenuSelected = false; + EmacsContextMenu.wasSubmenuSelected = -1; lastClosedMenu = menu; return; } diff --git a/java/org/gnu/emacs/EmacsContextMenu.java b/java/org/gnu/emacs/EmacsContextMenu.java index abc1869ac6a..d780641ba70 100644 --- a/java/org/gnu/emacs/EmacsContextMenu.java +++ b/java/org/gnu/emacs/EmacsContextMenu.java @@ -46,8 +46,11 @@ public final class EmacsContextMenu /* Whether or not an item was selected. */ public static boolean itemAlreadySelected; - /* Whether or not a submenu was selected. */ - public static boolean wasSubmenuSelected; + /* Whether or not a submenu was selected. + Value is -1 if no; value is -2 if yes, and a context menu + close event will definitely be sent. Any other value is + the timestamp when the submenu was selected. */ + public static long wasSubmenuSelected; /* The serial ID of the last context menu to be displayed. */ public static int lastMenuEventSerial; @@ -78,7 +81,7 @@ public final class EmacsContextMenu /* Still set wasSubmenuSelected -- if not set, the dismissal of this context menu will result in a context menu event being sent. */ - wasSubmenuSelected = true; + wasSubmenuSelected = -2; /* Running a popup menu from inside a click handler doesn't work, so make sure it is displayed @@ -103,8 +106,13 @@ public final class EmacsContextMenu Setting this flag makes EmacsActivity to only handle SubMenuBuilder being closed, which always means the menu - has actually been dismissed. */ - wasSubmenuSelected = true; + has actually been dismissed. + + However, these extraneous events aren't sent on devices + where submenus display without dismissing their parents. + Thus, only ignore the close event if it happens within + 300 milliseconds of the submenu being selected. */ + wasSubmenuSelected = System.currentTimeMillis (); return false; } @@ -291,7 +299,7 @@ public final class EmacsContextMenu itemAlreadySelected = false; /* No submenu has been selected yet. */ - wasSubmenuSelected = false; + wasSubmenuSelected = -1; return window.view.popupMenu (this, xPosition, yPosition, false); -- 2.39.2