1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-01 08:17:38 +00:00

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.
This commit is contained in:
Po Lu 2023-02-21 21:07:57 +08:00
parent 8ca4162ecd
commit 77feba7456
3 changed files with 36 additions and 7 deletions

View File

@ -26,6 +26,7 @@
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 @@ private class Item implements MenuItem.OnMenuItemClickListener
item name. */
public EmacsContextMenu
addSubmenu (String itemName, String title)
addSubmenu (String itemName, String title, String tooltip)
{
EmacsContextMenu submenu;
Item item;
@ -155,6 +156,7 @@ private class Item implements MenuItem.OnMenuItemClickListener
item = new Item ();
item.itemID = 0;
item.itemName = itemName;
item.tooltip = tooltip;
item.subMenu = createContextMenu (title);
item.subMenu.parent = this;
@ -214,6 +216,13 @@ private class Item implements MenuItem.OnMenuItemClickListener
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);
}
}
}

View File

@ -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;
}

View File

@ -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. */