summaryrefslogtreecommitdiffstats
path: root/src/android/jar
diff options
context:
space:
mode:
authorBogDan Vatra <bogdan@kde.org>2014-09-29 13:43:35 +0300
committerBogDan Vatra <bogdan@kde.org>2014-10-01 20:10:58 +0200
commit3b577dfe798bf5065a2bba4d7095709454aa709c (patch)
tree14172b58fac4e15662c58dbbd53c5790df48681a /src/android/jar
parent8ee9774e67edf57d891528749a360a0af8f0c6f7 (diff)
Use PopupMenu when possible.
On API-11+ we are going to use PopupMenu instead of ContextMenu to show context menus. A PopupMenu displays a Menu in a modal popup window anchored to a View. The popup will appear below the anchor view if there is room, or above it if there is not. Task-number: QTBUG-39736 Change-Id: Ie412ab0935b868348ce5c8bb0bf53571ffefd582 Reviewed-by: J-P Nurmi <jpnurmi@digia.com> Reviewed-by: Paul Olav Tvete <paul.tvete@digia.com>
Diffstat (limited to 'src/android/jar')
-rw-r--r--src/android/jar/jar.pri5
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java28
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtNative.java5
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtPopupMenu.java74
-rw-r--r--src/android/jar/src/org/qtproject/qt5/android/QtPopupMenu14.java77
5 files changed, 179 insertions, 10 deletions
diff --git a/src/android/jar/jar.pri b/src/android/jar/jar.pri
index 66feda1d56..a962af18ab 100644
--- a/src/android/jar/jar.pri
+++ b/src/android/jar/jar.pri
@@ -1,5 +1,6 @@
CONFIG += java
DESTDIR = $$[QT_INSTALL_PREFIX/get]/jar
+API_VERSION = android-16
PATHPREFIX = $$PWD/src/org/qtproject/qt5/android/
@@ -13,7 +14,9 @@ JAVASOURCES += \
$$PATHPREFIX/QtNative.java \
$$PATHPREFIX/QtNativeLibrariesDir.java \
$$PATHPREFIX/QtSurface.java \
- $$PATHPREFIX/ExtractStyle.java
+ $$PATHPREFIX/ExtractStyle.java \
+ $$PATHPREFIX/QtPopupMenu.java \
+ $$PATHPREFIX/QtPopupMenu14.java
# install
target.path = $$[QT_INSTALL_PREFIX]/jar
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java
index cddb06eff1..6dad8888ce 100644
--- a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java
+++ b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java
@@ -50,7 +50,6 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.graphics.drawable.ColorDrawable;
-import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@@ -76,7 +75,6 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Method;
-import java.lang.System;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -122,7 +120,6 @@ public class QtActivityDelegate
private boolean m_quitApp = true;
private Process m_debuggerProcess = null; // debugger process
private View m_dummyView = null;
-
private boolean m_keyboardIsVisible = false;
public boolean m_backKeyPressedSent = false;
private long m_showHideTimeStamp = System.nanoTime();
@@ -482,7 +479,7 @@ public class QtActivityDelegate
return true;
}
- public void debugLog(String msg)
+ public static void debugLog(String msg)
{
Log.i(QtNative.QtTAG, "DEBUGGER: " + msg);
}
@@ -939,6 +936,12 @@ public class QtActivityDelegate
m_contextMenuVisible = true;
}
+ public void onCreatePopupMenu(Menu menu)
+ {
+ QtNative.fillContextMenu(menu);
+ m_contextMenuVisible = true;
+ }
+
public void onContextMenuClosed(Menu menu)
{
if (!m_contextMenuVisible)
@@ -949,17 +952,28 @@ public class QtActivityDelegate
public boolean onContextItemSelected(MenuItem item)
{
+ m_contextMenuVisible = false;
return QtNative.onContextItemSelected(item.getItemId(), item.isChecked());
}
- public void openContextMenu()
+ public void openContextMenu(final int x, final int y, final int w, final int h)
{
m_layout.postDelayed(new Runnable() {
@Override
public void run() {
- m_activity.openContextMenu(m_layout);
+ if (Build.VERSION.SDK_INT < 11 || w <= 0 || h <= 0) {
+ m_activity.openContextMenu(m_layout);
+ } else if (Build.VERSION.SDK_INT < 14) {
+ m_layout.removeView(m_editText);
+ m_layout.addView(m_editText, new QtLayout.LayoutParams(w, h, x, y));
+ QtPopupMenu.getInstance().showMenu(m_editText);
+ } else {
+ m_layout.removeView(m_editText);
+ m_layout.addView(m_editText, new QtLayout.LayoutParams(w, h, x, y));
+ QtPopupMenu14.getInstance().showMenu(m_editText);
+ }
}
- }, 10);
+ }, 100);
}
public void closeContextMenu()
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
index aba4cfa502..51688441e0 100644
--- a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
+++ b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
@@ -440,12 +440,12 @@ public class QtNative
return m_clipboardManager.getText().toString();
}
- private static void openContextMenu()
+ private static void openContextMenu(final int x, final int y, final int w, final int h)
{
runAction(new Runnable() {
@Override
public void run() {
- m_activityDelegate.openContextMenu();
+ m_activityDelegate.openContextMenu(x, y, w, h);
}
});
}
@@ -611,6 +611,7 @@ public class QtNative
public static native void onOptionsMenuClosed(Menu menu);
public static native void onCreateContextMenu(ContextMenu menu);
+ public static native void fillContextMenu(Menu menu);
public static native boolean onContextItemSelected(int itemId, boolean checked);
public static native void onContextMenuClosed(Menu menu);
// menu methods
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtPopupMenu.java b/src/android/jar/src/org/qtproject/qt5/android/QtPopupMenu.java
new file mode 100644
index 0000000000..68143d89bf
--- /dev/null
+++ b/src/android/jar/src/org/qtproject/qt5/android/QtPopupMenu.java
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Android port of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+package org.qtproject.qt5.android;
+
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.PopupMenu;
+
+public class QtPopupMenu {
+ private QtPopupMenu() { }
+
+ private static class QtPopupMenuHolder {
+ private static final QtPopupMenu INSTANCE = new QtPopupMenu();
+ }
+
+ public static QtPopupMenu getInstance() {
+ return QtPopupMenuHolder.INSTANCE;
+ }
+
+ public void showMenu(View anchor)
+ {
+ PopupMenu popup = new PopupMenu(QtNative.activity(), anchor);
+ QtNative.activityDelegate().onCreatePopupMenu(popup.getMenu());
+ popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
+ @Override
+ public boolean onMenuItemClick(MenuItem menuItem) {
+ boolean res = QtNative.onContextItemSelected(menuItem.getItemId(), menuItem.isChecked());
+ if (res)
+ QtNative.activityDelegate().onContextMenuClosed(null);
+ return res;
+ }
+ });
+ popup.show();
+ }
+}
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtPopupMenu14.java b/src/android/jar/src/org/qtproject/qt5/android/QtPopupMenu14.java
new file mode 100644
index 0000000000..daa30ee415
--- /dev/null
+++ b/src/android/jar/src/org/qtproject/qt5/android/QtPopupMenu14.java
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 BogDan Vatra <bogdan@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Android port of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+package org.qtproject.qt5.android;
+
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.PopupMenu;
+
+public class QtPopupMenu14 {
+ private QtPopupMenu14() { }
+
+ private static class QtPopupMenu14Holder {
+ private static final QtPopupMenu14 INSTANCE = new QtPopupMenu14();
+ }
+
+ public static QtPopupMenu14 getInstance() {
+ return QtPopupMenu14Holder.INSTANCE;
+ }
+
+ public void showMenu(View anchor)
+ {
+ PopupMenu popup = new PopupMenu(QtNative.activity(), anchor);
+ QtNative.activityDelegate().onCreatePopupMenu(popup.getMenu());
+ popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
+ @Override
+ public boolean onMenuItemClick(MenuItem menuItem) {
+ return QtNative.activityDelegate().onContextItemSelected(menuItem);
+ }
+ });
+ popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
+ @Override
+ public void onDismiss(PopupMenu popupMenu) {
+ QtNative.activityDelegate().onContextMenuClosed(popupMenu.getMenu());
+ }
+ });
+ popup.show();
+ }
+}