Android: Simplify the jni code in QtAndroidMenu
This is one of several fixes where the goal is to simplify the jni code by letting QJNI manage the environment. Change-Id: Ia714e25fbb3fcd170150392e822b0a3fc3812818 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@theqtcompany.com>
This commit is contained in:
parent
4835808287
commit
078380df1e
@ -44,6 +44,7 @@
|
|||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
#include <QtCore/private/qjnihelpers_p.h>
|
#include <QtCore/private/qjnihelpers_p.h>
|
||||||
|
#include <QtCore/private/qjni_p.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
@ -61,9 +62,6 @@ namespace QtAndroidMenu
|
|||||||
static QMutex menuBarMutex(QMutex::Recursive);
|
static QMutex menuBarMutex(QMutex::Recursive);
|
||||||
|
|
||||||
static jmethodID openContextMenuMethodID = 0;
|
static jmethodID openContextMenuMethodID = 0;
|
||||||
static jmethodID closeContextMenuMethodID = 0;
|
|
||||||
static jmethodID resetOptionsMenuMethodID = 0;
|
|
||||||
static jmethodID openOptionsMenuMethodID = 0;
|
|
||||||
|
|
||||||
static jmethodID clearMenuMethodID = 0;
|
static jmethodID clearMenuMethodID = 0;
|
||||||
static jmethodID addMenuItemMethodID = 0;
|
static jmethodID addMenuItemMethodID = 0;
|
||||||
@ -78,16 +76,12 @@ namespace QtAndroidMenu
|
|||||||
|
|
||||||
void resetMenuBar()
|
void resetMenuBar()
|
||||||
{
|
{
|
||||||
AttachedJNIEnv env;
|
QJNIObjectPrivate::callStaticMethod<void>(applicationClass(), "resetOptionsMenu");
|
||||||
if (env.jniEnv)
|
|
||||||
env.jniEnv->CallStaticVoidMethod(applicationClass(), resetOptionsMenuMethodID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void openOptionsMenu()
|
void openOptionsMenu()
|
||||||
{
|
{
|
||||||
AttachedJNIEnv env;
|
QJNIObjectPrivate::callStaticMethod<void>(applicationClass(), "openOptionsMenu");
|
||||||
if (env.jniEnv)
|
|
||||||
env.jniEnv->CallStaticVoidMethod(applicationClass(), openOptionsMenuMethodID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void showContextMenu(QAndroidPlatformMenu *menu, const QRect &anchorRect, JNIEnv *env)
|
void showContextMenu(QAndroidPlatformMenu *menu, const QRect &anchorRect, JNIEnv *env)
|
||||||
@ -103,22 +97,14 @@ namespace QtAndroidMenu
|
|||||||
|
|
||||||
visibleMenu = menu;
|
visibleMenu = menu;
|
||||||
menu->aboutToShow();
|
menu->aboutToShow();
|
||||||
if (env) {
|
|
||||||
env->CallStaticVoidMethod(applicationClass(), openContextMenuMethodID, anchorRect.x(), anchorRect.y(), anchorRect.width(), anchorRect.height());
|
env->CallStaticVoidMethod(applicationClass(), openContextMenuMethodID, anchorRect.x(), anchorRect.y(), anchorRect.width(), anchorRect.height());
|
||||||
} else {
|
|
||||||
AttachedJNIEnv aenv;
|
|
||||||
if (aenv.jniEnv)
|
|
||||||
aenv.jniEnv->CallStaticVoidMethod(applicationClass(), openContextMenuMethodID, anchorRect.x(), anchorRect.y(), anchorRect.width(), anchorRect.height());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void hideContextMenu(QAndroidPlatformMenu *menu)
|
void hideContextMenu(QAndroidPlatformMenu *menu)
|
||||||
{
|
{
|
||||||
QMutexLocker lock(&visibleMenuMutex);
|
QMutexLocker lock(&visibleMenuMutex);
|
||||||
if (visibleMenu == menu) {
|
if (visibleMenu == menu) {
|
||||||
AttachedJNIEnv env;
|
QJNIObjectPrivate::callStaticMethod<void>(applicationClass(), "closeContextMenu");
|
||||||
if (env.jniEnv)
|
|
||||||
env.jniEnv->CallStaticVoidMethod(applicationClass(), closeContextMenuMethodID);
|
|
||||||
pendingContextMenus.clear();
|
pendingContextMenus.clear();
|
||||||
} else {
|
} else {
|
||||||
pendingContextMenus.removeOne(menu);
|
pendingContextMenus.removeOne(menu);
|
||||||
@ -430,9 +416,6 @@ namespace QtAndroidMenu
|
|||||||
}
|
}
|
||||||
|
|
||||||
GET_AND_CHECK_STATIC_METHOD(openContextMenuMethodID, appClass, "openContextMenu", "(IIII)V");
|
GET_AND_CHECK_STATIC_METHOD(openContextMenuMethodID, appClass, "openContextMenu", "(IIII)V");
|
||||||
GET_AND_CHECK_STATIC_METHOD(closeContextMenuMethodID, appClass, "closeContextMenu", "()V");
|
|
||||||
GET_AND_CHECK_STATIC_METHOD(resetOptionsMenuMethodID, appClass, "resetOptionsMenu", "()V");
|
|
||||||
GET_AND_CHECK_STATIC_METHOD(openOptionsMenuMethodID, appClass, "openOptionsMenu", "()V");
|
|
||||||
|
|
||||||
jclass clazz;
|
jclass clazz;
|
||||||
FIND_AND_CHECK_CLASS("android/view/Menu");
|
FIND_AND_CHECK_CLASS("android/view/Menu");
|
||||||
|
@ -50,7 +50,7 @@ namespace QtAndroidMenu
|
|||||||
{
|
{
|
||||||
// Menu support
|
// Menu support
|
||||||
void openOptionsMenu();
|
void openOptionsMenu();
|
||||||
void showContextMenu(QAndroidPlatformMenu *menu, const QRect &anchorRect, JNIEnv *env = 0);
|
void showContextMenu(QAndroidPlatformMenu *menu, const QRect &anchorRect, JNIEnv *env);
|
||||||
void hideContextMenu(QAndroidPlatformMenu *menu);
|
void hideContextMenu(QAndroidPlatformMenu *menu);
|
||||||
void syncMenu(QAndroidPlatformMenu *menu);
|
void syncMenu(QAndroidPlatformMenu *menu);
|
||||||
void androidPlatformMenuDestroyed(QAndroidPlatformMenu *menu);
|
void androidPlatformMenuDestroyed(QAndroidPlatformMenu *menu);
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "qandroidplatformmenu.h"
|
#include "qandroidplatformmenu.h"
|
||||||
#include "qandroidplatformmenuitem.h"
|
#include "qandroidplatformmenuitem.h"
|
||||||
#include "androidjnimenu.h"
|
#include "androidjnimenu.h"
|
||||||
|
#include <QtCore/private/qjni_p.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
@ -140,7 +141,7 @@ void QAndroidPlatformMenu::showPopup(const QWindow *parentWindow, const QRect &t
|
|||||||
Q_UNUSED(parentWindow);
|
Q_UNUSED(parentWindow);
|
||||||
Q_UNUSED(item);
|
Q_UNUSED(item);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
QtAndroidMenu::showContextMenu(this, targetRect);
|
QtAndroidMenu::showContextMenu(this, targetRect, QJNIEnvironmentPrivate());
|
||||||
}
|
}
|
||||||
|
|
||||||
QPlatformMenuItem *QAndroidPlatformMenu::menuItemAt(int position) const
|
QPlatformMenuItem *QAndroidPlatformMenu::menuItemAt(int position) const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user