You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
PopupMenu: use AOSP MenuInflater and support item visibility
This commit is contained in:
@@ -17,11 +17,27 @@ JNIEXPORT jlong JNICALL Java_android_widget_PopupMenu_native_1init
|
||||
|
||||
/*
|
||||
* Class: android_widget_PopupMenu
|
||||
* Method: native_appendItem
|
||||
* Signature: (JLjava/lang/String;I)V
|
||||
* Method: native_insertItem
|
||||
* Signature: (JILjava/lang/String;I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupMenu_native_1appendItem
|
||||
(JNIEnv *, jobject, jlong, jstring, jint);
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupMenu_native_1insertItem
|
||||
(JNIEnv *, jobject, jlong, jint, jstring, jint);
|
||||
|
||||
/*
|
||||
* Class: android_widget_PopupMenu
|
||||
* Method: native_insertSubmenu
|
||||
* Signature: (JILjava/lang/String;J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupMenu_native_1insertSubmenu
|
||||
(JNIEnv *, jobject, jlong, jint, jstring, jlong);
|
||||
|
||||
/*
|
||||
* Class: android_widget_PopupMenu
|
||||
* Method: native_removeItem
|
||||
* Signature: (JI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupMenu_native_1removeItem
|
||||
(JNIEnv *, jobject, jlong, jint);
|
||||
|
||||
/*
|
||||
* Class: android_widget_PopupMenu
|
||||
|
||||
@@ -10,13 +10,30 @@ JNIEXPORT jlong JNICALL Java_android_widget_PopupMenu_native_1init(JNIEnv *env,
|
||||
return _INTPTR(g_menu_new());
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupMenu_native_1appendItem(JNIEnv *env, jobject this, jlong menu_ptr, jstring title_jstr, jint id)
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupMenu_native_1insertItem(JNIEnv *env, jobject this, jlong menu_ptr, jint position, jstring title_jstr, jint id)
|
||||
{
|
||||
const gchar *title = (*env)->GetStringUTFChars(env, title_jstr, NULL);
|
||||
printf("insertItem position: %d title: %s\n", position, title);
|
||||
GMenuItem *item = g_menu_item_new(title, NULL);
|
||||
(*env)->ReleaseStringUTFChars(env, title_jstr, title);
|
||||
g_menu_item_set_action_and_target(item, "popupmenu.clicked", "i", id);
|
||||
g_menu_append_item(G_MENU(_PTR(menu_ptr)), item);
|
||||
g_menu_insert_item(G_MENU(_PTR(menu_ptr)), position, item);
|
||||
g_object_unref(item);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupMenu_native_1insertSubmenu(JNIEnv *env, jobject this, jlong menu_ptr, jint position, jstring title_jstr, jlong submenu_ptr)
|
||||
{
|
||||
const gchar *title = (*env)->GetStringUTFChars(env, title_jstr, NULL);
|
||||
printf("insertSubmenu position: %d title: %s\n", position, title);
|
||||
GMenuItem *item = g_menu_item_new_submenu(title, G_MENU_MODEL(_PTR(submenu_ptr)));
|
||||
(*env)->ReleaseStringUTFChars(env, title_jstr, title);
|
||||
g_menu_insert_item(G_MENU(_PTR(menu_ptr)), position, item);
|
||||
g_object_unref(item);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_widget_PopupMenu_native_1removeItem(JNIEnv *env, jobject this, jlong menu_ptr, jint position)
|
||||
{
|
||||
g_menu_remove(G_MENU(_PTR(menu_ptr)), position);
|
||||
}
|
||||
|
||||
static void popupmenu_activated(GSimpleAction *action, GVariant *parameter, gpointer user_data) {
|
||||
|
||||
Reference in New Issue
Block a user