emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/android 77feba74564 1/2: Update Android port


From: Po Lu
Subject: feature/android 77feba74564 1/2: Update Android port
Date: Tue, 21 Feb 2023 08:08:53 -0500 (EST)

branch: feature/android
commit 77feba74564c4d58b472b82fec0137091bb5c7e1
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Update Android port
    
    * java/org/gnu/emacs/EmacsContextMenu.java (EmacsContextMenu)
    (addSubmenu, inflateMenuItems): Handle tooltips correctly.
    * src/android.c (android_scan_directory_tree): Fix limit
    generation for root directory.
    * src/androidmenu.c (android_init_emacs_context_menu)
    (android_menu_show): Implement menu item help text on Android
    8.0 and later.
---
 java/org/gnu/emacs/EmacsContextMenu.java | 13 +++++++++++--
 src/android.c                            |  8 ++++++--
 src/androidmenu.c                        | 22 +++++++++++++++++++---
 3 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/java/org/gnu/emacs/EmacsContextMenu.java 
b/java/org/gnu/emacs/EmacsContextMenu.java
index 184c611bf9d..6b3ae0c6de9 100644
--- a/java/org/gnu/emacs/EmacsContextMenu.java
+++ b/java/org/gnu/emacs/EmacsContextMenu.java
@@ -26,6 +26,7 @@ import android.content.Context;
 import android.content.Intent;
 
 import android.os.Bundle;
+import android.os.Build;
 
 import android.view.Menu;
 import android.view.MenuItem;
@@ -54,7 +55,7 @@ public class EmacsContextMenu
   private class Item implements MenuItem.OnMenuItemClickListener
   {
     public int itemID;
-    public String itemName;
+    public String itemName, tooltip;
     public EmacsContextMenu subMenu;
     public boolean isEnabled, isCheckable, isChecked;
 
@@ -147,7 +148,7 @@ public class EmacsContextMenu
      item name.  */
 
   public EmacsContextMenu
-  addSubmenu (String itemName, String title)
+  addSubmenu (String itemName, String title, String tooltip)
   {
     EmacsContextMenu submenu;
     Item item;
@@ -155,6 +156,7 @@ public class EmacsContextMenu
     item = new Item ();
     item.itemID = 0;
     item.itemName = itemName;
+    item.tooltip = tooltip;
     item.subMenu = createContextMenu (title);
     item.subMenu.parent = this;
 
@@ -214,6 +216,13 @@ public class EmacsContextMenu
 
            if (item.isChecked)
              menuItem.setChecked (true);
+
+           /* If the tooltip text is set and the system is new enough
+              to support menu item tooltips, set it on the item.  */
+
+           if (item.tooltip != null
+               && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+             menuItem.setTooltipText (item.tooltip);
          }
       }
   }
diff --git a/src/android.c b/src/android.c
index 0627b44f8fd..4639d84a2a1 100644
--- a/src/android.c
+++ b/src/android.c
@@ -777,13 +777,17 @@ android_scan_directory_tree (char *file, size_t 
*limit_return)
 
   /* If there are no tokens, just return the start of the directory
      tree.  */
+
   if (!ntokens)
     {
       SAFE_FREE ();
 
-      /* Subtract the initial header bytes.  */
+      /* Return the size of the directory tree as the limit.
+         Do not subtract the initial header bytes, as the limit
+         is an offset from the start of the file.  */
+
       if (limit_return)
-       *limit_return = directory_tree_size - 5;
+       *limit_return = directory_tree_size;
 
       return start;
     }
diff --git a/src/androidmenu.c b/src/androidmenu.c
index acad775f26a..e1b64b9a545 100644
--- a/src/androidmenu.c
+++ b/src/androidmenu.c
@@ -100,7 +100,8 @@ android_init_emacs_context_menu (void)
 
   FIND_METHOD (add_item, "addItem", "(ILjava/lang/String;ZZZ)V");
   FIND_METHOD (add_submenu, "addSubmenu", "(Ljava/lang/String;"
-              "Ljava/lang/String;)Lorg/gnu/emacs/EmacsContextMenu;");
+              "Ljava/lang/String;Ljava/lang/String;)"
+              "Lorg/gnu/emacs/EmacsContextMenu;");
   FIND_METHOD (add_pane, "addPane", "(Ljava/lang/String;)V");
   FIND_METHOD (parent, "parent", "()Lorg/gnu/emacs/EmacsContextMenu;");
   FIND_METHOD (display, "display", "(Lorg/gnu/emacs/EmacsWindow;II)Z");
@@ -236,12 +237,13 @@ android_menu_show (struct frame *f, int x, int y, int 
menuflags,
                   Lisp_Object title, const char **error_name)
 {
   jobject context_menu, current_context_menu;
-  jobject title_string, temp;
+  jobject title_string, help_string, temp;
   size_t i;
   Lisp_Object pane_name, prefix;
   const char *pane_string;
   specpdl_ref count, count1;
   Lisp_Object item_name, enable, def, tem, entry, type, selected;
+  Lisp_Object help;
   jmethodID method;
   jobject store;
   bool rc;
@@ -354,6 +356,7 @@ android_menu_show (struct frame *f, int x, int y, int 
menuflags,
          def = AREF (menu_items, i + MENU_ITEMS_ITEM_DEFINITION);
          type = AREF (menu_items, i + MENU_ITEMS_ITEM_TYPE);
          selected = AREF (menu_items, i + MENU_ITEMS_ITEM_SELECTED);
+         help = AREF (menu_items, i + MENU_ITEMS_ITEM_HELP);
 
          /* This is an actual menu item (or submenu).  Add it to the
             menu.  */
@@ -365,12 +368,22 @@ android_menu_show (struct frame *f, int x, int y, int 
menuflags,
              title_string = (!NILP (item_name)
                              ? android_build_string (item_name)
                              : NULL);
+             help_string = NULL;
+
+             /* Menu items can have tool tips on Android 26 and
+                later.  In this case, set it to the help string.  */
+
+             if (android_get_current_api_level () >= 26
+                 && STRINGP (help))
+               help_string = android_build_string (help_string);
+
              store = current_context_menu;
              current_context_menu
                = (*android_java_env)->CallObjectMethod (android_java_env,
                                                         current_context_menu,
                                                         menu_class.add_submenu,
-                                                        title_string, NULL);
+                                                        title_string, NULL,
+                                                        help_string);
              android_exception_check ();
 
              if (store != context_menu)
@@ -378,6 +391,9 @@ android_menu_show (struct frame *f, int x, int y, int 
menuflags,
 
              if (title_string)
                ANDROID_DELETE_LOCAL_REF (title_string);
+
+             if (help_string)
+               ANDROID_DELETE_LOCAL_REF (help_string);
            }
          else if (NILP (def) && menu_separator_name_p (SSDATA (item_name)))
            /* Ignore this separator item.  */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]