aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergio Ahumada <sergio.ahumada@digia.com>2013-09-25 14:05:31 +0200
committerSergio Ahumada <sergio.ahumada@digia.com>2013-09-25 14:05:40 +0200
commit0469ef58b015d77cbdd87d94de1e3e128e5c633f (patch)
tree7f4e2818c8a34343066a05cad387192f9163d205
parent3ceb5e0a7a10e5a095a8f1a0b996d24d0cb0cb69 (diff)
parent4817842e1cc6a7017a2f836f69c9bea1de12dd47 (diff)
Merge branch 'stable' into dev
-rw-r--r--LGPL_EXCEPTION.txt2
-rw-r--r--LICENSE.FDL18
-rw-r--r--LICENSE.LGPL18
-rw-r--r--examples/androidextras/androidextras.pro5
-rw-r--r--examples/androidextras/notification/android-sources/AndroidManifest.xml38
-rw-r--r--examples/androidextras/notification/android-sources/src/org/qtproject/example/notification/NotificationClient.java71
-rw-r--r--examples/androidextras/notification/androidjnibindings.cpp68
-rw-r--r--examples/androidextras/notification/androidjnibindings.h61
-rw-r--r--examples/androidextras/notification/images/happy.pngbin0 -> 2804 bytes
-rw-r--r--examples/androidextras/notification/images/sad.pngbin0 -> 2447 bytes
-rw-r--r--examples/androidextras/notification/main.cpp62
-rw-r--r--examples/androidextras/notification/main.qrc7
-rw-r--r--examples/androidextras/notification/notification.pro24
-rw-r--r--examples/androidextras/notification/notificationclient.cpp74
-rw-r--r--examples/androidextras/notification/notificationclient.h67
-rw-r--r--examples/androidextras/notification/qml/main.qml106
-rw-r--r--examples/examples.pro2
-rw-r--r--src/androidextras/androidextras.pro2
-rw-r--r--src/androidextras/doc/images/notification.pngbin0 -> 26373 bytes
-rw-r--r--src/androidextras/doc/qtandroidextras.qdocconf2
-rw-r--r--src/androidextras/doc/snippets/code/src_androidextras_qjnienvironment.cpp13
-rw-r--r--src/androidextras/doc/snippets/code/src_androidextras_qjniobject.cpp13
-rw-r--r--src/androidextras/doc/src/qtandroidextras-index.qdoc20
-rw-r--r--src/androidextras/doc/src/qtandroidextras-module.qdoc16
-rw-r--r--src/androidextras/jni/qjnienvironment.cpp40
-rw-r--r--src/androidextras/jni/qjniobject.cpp162
-rw-r--r--src/src.pro2
-rw-r--r--tests/auto/auto.pro6
-rw-r--r--tests/auto/qjnienvironment/qjnienvironment.pro4
-rw-r--r--tests/auto/qjnienvironment/tst_qjnienvironment.cpp111
-rw-r--r--tests/auto/qjniobject/qjniobject.pro4
-rw-r--r--tests/auto/qjniobject/tst_qjniobject.cpp730
32 files changed, 1653 insertions, 95 deletions
diff --git a/LGPL_EXCEPTION.txt b/LGPL_EXCEPTION.txt
index add80b9..7e2e30f 100644
--- a/LGPL_EXCEPTION.txt
+++ b/LGPL_EXCEPTION.txt
@@ -4,7 +4,7 @@ As an additional permission to the GNU Lesser General Public License version
2.1, the object code form of a "work that uses the Library" may incorporate
material from a header file that is part of the Library. You may distribute
such object code under terms of your choice, provided that:
- (i) the header files of the Library have not been modified; and
+ (i) the header files of the Library have not been modified; and
(ii) the incorporated material is limited to numerical parameters, data
structure layouts, accessors, macros, inline functions and
templates; and
diff --git a/LICENSE.FDL b/LICENSE.FDL
index 086177c..938bb8d 100644
--- a/LICENSE.FDL
+++ b/LICENSE.FDL
@@ -400,19 +400,19 @@ public wiki that anybody can edit is an example of such a server. A
"Massive Multiauthor Collaboration" (or "MMC") contained in the site
means any set of copyrightable works thus published on the MMC site.
-"CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0
-license published by Creative Commons Corporation, a not-for-profit
-corporation with a principal place of business in San Francisco,
-California, as well as future copyleft versions of that license
+"CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0
+license published by Creative Commons Corporation, a not-for-profit
+corporation with a principal place of business in San Francisco,
+California, as well as future copyleft versions of that license
published by that same organization.
-"Incorporate" means to publish or republish a Document, in whole or in
+"Incorporate" means to publish or republish a Document, in whole or in
part, as part of another Document.
-An MMC is "eligible for relicensing" if it is licensed under this
-License, and if all works that were first published under this License
-somewhere other than this MMC, and subsequently incorporated in whole or
-in part into the MMC, (1) had no cover texts or invariant sections, and
+An MMC is "eligible for relicensing" if it is licensed under this
+License, and if all works that were first published under this License
+somewhere other than this MMC, and subsequently incorporated in whole or
+in part into the MMC, (1) had no cover texts or invariant sections, and
(2) were thus incorporated prior to November 1, 2008.
The operator of an MMC Site may republish an MMC contained in the site
diff --git a/LICENSE.LGPL b/LICENSE.LGPL
index dbbd590..3788d79 100644
--- a/LICENSE.LGPL
+++ b/LICENSE.LGPL
@@ -1,4 +1,4 @@
- GNU LESSER GENERAL PUBLIC LICENSE
+ GNU LESSER GENERAL PUBLIC LICENSE
The Qt Toolkit is Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
Contact: http://www.qt-project.org/legal
@@ -8,8 +8,8 @@
-------------------------------------------------------------------------
- GNU LESSER GENERAL PUBLIC LICENSE
- Version 2.1, February 1999
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
@@ -20,7 +20,7 @@
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
- Preamble
+ Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
@@ -122,7 +122,7 @@ modification follow. Pay close attention to the difference between a
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
- GNU LESSER GENERAL PUBLIC LICENSE
+ GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
@@ -156,7 +156,7 @@ such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
-
+
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
@@ -442,7 +442,7 @@ decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
- NO WARRANTY
+ NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
@@ -465,7 +465,7 @@ FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
- END OF TERMS AND CONDITIONS
+ END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
@@ -510,3 +510,5 @@ necessary. Here is a sample; alter the names:
Ty Coon, President of Vice
That's all there is to it!
+
+
diff --git a/examples/androidextras/androidextras.pro b/examples/androidextras/androidextras.pro
new file mode 100644
index 0000000..31640ad
--- /dev/null
+++ b/examples/androidextras/androidextras.pro
@@ -0,0 +1,5 @@
+TEMPLATE = subdirs
+android {
+ SUBDIRS += notification
+ EXAMPLE_FILES += notification
+}
diff --git a/examples/androidextras/notification/android-sources/AndroidManifest.xml b/examples/androidextras/notification/android-sources/AndroidManifest.xml
new file mode 100644
index 0000000..a7f10eb
--- /dev/null
+++ b/examples/androidextras/notification/android-sources/AndroidManifest.xml
@@ -0,0 +1,38 @@
+<?xml version='1.0' encoding='utf-8'?>
+<manifest android:versionCode="1" package="org.qtproject.example" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0">
+ <application android:icon="@drawable/icon" android:name="org.qtproject.qt5.android.bindings.QtApplication" android:label="@string/app_name">
+ <activity android:name="org.qtproject.example.notification.NotificationClient" android:label="@string/app_name" android:screenOrientation="unspecified" android:configChanges="orientation|locale|fontScale|keyboard|keyboardHidden|navigation">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.LAUNCHER"/>
+ </intent-filter>
+ <meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
+ <meta-data android:name="android.app.repository" android:value="@string/repository"/>
+ <meta-data android:name="android.app.qt_libs_resource_id" android:resource="@array/qt_libs"/>
+ <meta-data android:name="android.app.bundled_libs_resource_id" android:resource="@array/bundled_libs"/>
+ <meta-data android:name="android.app.lib_name" android:value="@string/app_lib_name"/>
+ <!-- Deploy Qt libs as part of package -->
+ <meta-data android:name="android.app.bundle_local_qt_libs" android:value="1"/>
+ <meta-data android:name="android.app.bundled_in_lib_resource_id" android:resource="@array/bundled_in_lib"/>
+ <meta-data android:name="android.app.bundled_in_assets_resource_id" android:resource="@array/bundled_in_assets"/>
+ <!-- Run with local libs -->
+ <meta-data android:name="android.app.use_local_qt_libs" android:value="1"/>
+ <meta-data android:name="android.app.libs_prefix" android:value="/data/local/tmp/qt/"/>
+ <meta-data android:name="android.app.load_local_libs" android:value="@string/local_libs"/>
+ <meta-data android:name="android.app.load_local_jars" android:value="@string/local_jars"/>
+ <meta-data android:name="android.app.static_init_classes" android:value="@string/init_classes"/>
+ <!-- Messages maps -->
+ <meta-data android:name="android.app.ministro_not_found_msg" android:value="@string/ministro_not_found_msg"/>
+ <meta-data android:name="android.app.ministro_needed_msg" android:value="@string/ministro_needed_msg"/>
+ <meta-data android:name="android.app.fatal_error_msg" android:value="@string/fatal_error_msg"/>
+ <!-- Messages maps -->
+ <!-- Splash screen -->
+ <meta-data android:name="android.app.splash_screen" android:resource="@layout/splash"/>
+ <!-- Splash screen -->
+ </activity>
+ </application>
+ <!-- %%INSERT_USES_SDK%% -->
+ <supports-screens android:normalScreens="true" android:anyDensity="true" android:smallScreens="true" android:largeScreens="true"/>
+ <uses-permission android:name="android.permission.INTERNET"/>
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+</manifest>
diff --git a/examples/androidextras/notification/android-sources/src/org/qtproject/example/notification/NotificationClient.java b/examples/androidextras/notification/android-sources/src/org/qtproject/example/notification/NotificationClient.java
new file mode 100644
index 0000000..9901fda
--- /dev/null
+++ b/examples/androidextras/notification/android-sources/src/org/qtproject/example/notification/NotificationClient.java
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWinExtras module 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.example.notification;
+
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.content.Context;
+
+public class NotificationClient extends org.qtproject.qt5.android.bindings.QtActivity
+{
+ private static NotificationManager m_notificationManager;
+ private static Notification.Builder m_builder;
+ private static NotificationClient m_instance;
+
+ public NotificationClient()
+ {
+ m_instance = this;
+ }
+
+ public static void notify(String s)
+ {
+ if (m_notificationManager == null) {
+ m_notificationManager = (NotificationManager)m_instance.getSystemService(Context.NOTIFICATION_SERVICE);
+ m_builder = new Notification.Builder(m_instance);
+ m_builder.setSmallIcon(R.drawable.icon);
+ m_builder.setContentTitle("A message from Qt!");
+ }
+
+ m_builder.setContentText(s);
+ m_notificationManager.notify(1, m_builder.build());
+ }
+}
diff --git a/examples/androidextras/notification/androidjnibindings.cpp b/examples/androidextras/notification/androidjnibindings.cpp
new file mode 100644
index 0000000..98280c2
--- /dev/null
+++ b/examples/androidextras/notification/androidjnibindings.cpp
@@ -0,0 +1,68 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWinExtras module 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$
+**
+****************************************************************************/
+
+#include "androidjnibindings.h"
+
+jint JNICALL JNI_OnLoad(JavaVM *vm, void *)
+{
+ JNIEnv *env;
+ if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_4) != JNI_OK) {
+ qFatal("Couldn't initialize environment!");
+ return -1;
+ }
+
+ AndroidJNIBindings::detectNotificationClientClass(env);
+
+ return JNI_VERSION_1_4;
+}
+
+jclass AndroidJNIBindings::m_notificationClientClass = 0;
+void AndroidJNIBindings::detectNotificationClientClass(JNIEnv *environment)
+{
+ jclass clazz = environment->FindClass("org/qtproject/example/notification/NotificationClient");
+ if (clazz == 0) {
+ environment->ExceptionDescribe();
+ environment->ExceptionClear();
+ return;
+ }
+
+ m_notificationClientClass = reinterpret_cast<jclass>(environment->NewGlobalRef(clazz));
+}
diff --git a/examples/androidextras/notification/androidjnibindings.h b/examples/androidextras/notification/androidjnibindings.h
new file mode 100644
index 0000000..64cca54
--- /dev/null
+++ b/examples/androidextras/notification/androidjnibindings.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWinExtras module 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$
+**
+****************************************************************************/
+
+#ifndef ANDROIDJNIBINDINGS_H
+#define ANDROIDJNIBINDINGS_H
+
+#include <QtAndroidExtras/QJNIObject>
+
+class AndroidJNIBindings
+{
+public:
+ static jclass notificationClientClass()
+ {
+ return m_notificationClientClass;
+ }
+
+ static void detectNotificationClientClass(JNIEnv *environment);
+
+private:
+ static jclass m_notificationClientClass;
+};
+
+#endif // ANDROIDJNIBINDINGS_H
diff --git a/examples/androidextras/notification/images/happy.png b/examples/androidextras/notification/images/happy.png
new file mode 100644
index 0000000..d1c1460
--- /dev/null
+++ b/examples/androidextras/notification/images/happy.png
Binary files differ
diff --git a/examples/androidextras/notification/images/sad.png b/examples/androidextras/notification/images/sad.png
new file mode 100644
index 0000000..00026bd
--- /dev/null
+++ b/examples/androidextras/notification/images/sad.png
Binary files differ
diff --git a/examples/androidextras/notification/main.cpp b/examples/androidextras/notification/main.cpp
new file mode 100644
index 0000000..8ed8d30
--- /dev/null
+++ b/examples/androidextras/notification/main.cpp
@@ -0,0 +1,62 @@
+
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWinExtras module 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$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtQuick>
+
+#include "notificationclient.h"
+
+int main(int argc, char **argv)
+{
+ QGuiApplication app(argc, argv);
+
+ QQuickView view;
+
+ NotificationClient *notificationClient = new NotificationClient(&view);
+ view.engine()->rootContext()->setContextProperty(QLatin1String("notificationClient"),
+ notificationClient);
+ view.setResizeMode(QQuickView::SizeRootObjectToView);
+ view.setSource(QUrl(QStringLiteral("qrc:/qml/main.qml")));
+ view.show();
+
+ return app.exec();
+}
diff --git a/examples/androidextras/notification/main.qrc b/examples/androidextras/notification/main.qrc
new file mode 100644
index 0000000..10190c9
--- /dev/null
+++ b/examples/androidextras/notification/main.qrc
@@ -0,0 +1,7 @@
+<RCC>
+ <qresource prefix="/">
+ <file>qml/main.qml</file>
+ <file>images/happy.png</file>
+ <file>images/sad.png</file>
+ </qresource>
+</RCC>
diff --git a/examples/androidextras/notification/notification.pro b/examples/androidextras/notification/notification.pro
new file mode 100644
index 0000000..9d57ca3
--- /dev/null
+++ b/examples/androidextras/notification/notification.pro
@@ -0,0 +1,24 @@
+QT += quick androidextras
+
+ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android-sources
+ANDROID_PACKAGE = org.qtproject.example.notification
+ANDROID_MINIMUM_VERSION = 16
+ANDROID_TARGET_VERSION = 16
+ANDROID_APP_NAME = Qt Notifier
+
+SOURCES += \
+ main.cpp \
+ notificationclient.cpp \
+ androidjnibindings.cpp
+
+OTHER_FILES += \
+ qml/main.qml \
+ android-sources/src/org/qtproject/example/notification/NotificationClient.java \
+ android-sources/AndroidManifest.xml
+
+RESOURCES += \
+ main.qrc
+
+HEADERS += \
+ notificationclient.h \
+ androidjnibindings.h
diff --git a/examples/androidextras/notification/notificationclient.cpp b/examples/androidextras/notification/notificationclient.cpp
new file mode 100644
index 0000000..d9cbf84
--- /dev/null
+++ b/examples/androidextras/notification/notificationclient.cpp
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWinExtras module 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$
+**
+****************************************************************************/
+
+#include "notificationclient.h"
+#include "androidjnibindings.h"
+
+#include <QtAndroidExtras/QJNIObject>
+
+NotificationClient::NotificationClient(QObject *parent)
+ : QObject(parent)
+{
+ connect(this, SIGNAL(notificationChanged()), this, SLOT(updateAndroidNotification()));
+}
+
+void NotificationClient::setNotification(const QString &notification)
+{
+ if (m_notification == notification)
+ return;
+
+ m_notification = notification;
+ emit notificationChanged();
+}
+
+QString NotificationClient::notification() const
+{
+ return m_notification;
+}
+
+void NotificationClient::updateAndroidNotification()
+{
+ QJNIObject javaNotification = QJNIObject::fromString(m_notification);
+ QJNIObject::callStaticMethod<void>(AndroidJNIBindings::notificationClientClass(),
+ "notify",
+ "(Ljava/lang/String;)V",
+ javaNotification.object<jstring>());
+}
diff --git a/examples/androidextras/notification/notificationclient.h b/examples/androidextras/notification/notificationclient.h
new file mode 100644
index 0000000..6b48fc7
--- /dev/null
+++ b/examples/androidextras/notification/notificationclient.h
@@ -0,0 +1,67 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWinExtras module 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$
+**
+****************************************************************************/
+
+#ifndef NOTIFICATIONCLIENT_H
+#define NOTIFICATIONCLIENT_H
+
+#include <QObject>
+
+class NotificationClient : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QString notification READ notification WRITE setNotification NOTIFY notificationChanged)
+public:
+ explicit NotificationClient(QObject *parent = 0);
+
+ void setNotification(const QString &notification);
+ QString notification() const;
+
+signals:
+ void notificationChanged();
+
+private slots:
+ void updateAndroidNotification();
+
+private:
+ QString m_notification;
+};
+
+#endif // NOTIFICATIONCLIENT_H
diff --git a/examples/androidextras/notification/qml/main.qml b/examples/androidextras/notification/qml/main.qml
new file mode 100644
index 0000000..e265f1b
--- /dev/null
+++ b/examples/androidextras/notification/qml/main.qml
@@ -0,0 +1,106 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtWinExtras module 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$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+Rectangle {
+ width: 500
+ height: 500
+ color: "white"
+
+ Column {
+ anchors.fill: parent
+ spacing: (height - happyButton.height - sadButton.height - title.height) / 3
+
+ Text {
+ id: title
+ color: "black"
+ font.pixelSize: parent.width / 20
+ text: "How are you feeling?"
+ width: parent.width
+ horizontalAlignment: Text.AlignHCenter
+ }
+
+ Image {
+ id: happyButton
+ height: parent.height / 5
+ fillMode: Image.PreserveAspectFit
+ source: "../images/happy.png"
+ anchors.horizontalCenter: parent.horizontalCenter
+ smooth: true
+
+ Behavior on scale {
+ PropertyAnimation {
+ duration: 100
+ }
+ }
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: notificationClient.notification = "User is happy!"
+ onPressed: happyButton.scale = 0.9
+ onReleased: happyButton.scale = 1.0
+ }
+ }
+
+ Image {
+ id: sadButton
+ height: parent.height / 5
+ fillMode: Image.PreserveAspectFit
+ source: "../images/sad.png"
+ anchors.horizontalCenter: parent.horizontalCenter
+ smooth: true
+
+ Behavior on scale {
+ PropertyAnimation {
+ duration: 100
+ }
+ }
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: notificationClient.notification = "User is sad :("
+ onPressed: sadButton.scale = 0.9
+ onReleased: sadButton.scale = 1.0
+ }
+ }
+ }
+}
diff --git a/examples/examples.pro b/examples/examples.pro
new file mode 100644
index 0000000..467ccc4
--- /dev/null
+++ b/examples/examples.pro
@@ -0,0 +1,2 @@
+TEMPLATE = subdirs
+android:SUBDIRS += androidextras
diff --git a/src/androidextras/androidextras.pro b/src/androidextras/androidextras.pro
index fa89194..f3caeea 100644
--- a/src/androidextras/androidextras.pro
+++ b/src/androidextras/androidextras.pro
@@ -1,6 +1,6 @@
TARGET = QtAndroidExtras
DEFINES += QT_NO_USING_NAMESPACE
-#QMAKE_DOCS = $$PWD/doc/qtandroidextras.qdocconf
+QMAKE_DOCS = $$PWD/doc/qtandroidextras.qdocconf
QT -= gui
QT += core-private
load(qt_module)
diff --git a/src/androidextras/doc/images/notification.png b/src/androidextras/doc/images/notification.png
new file mode 100644
index 0000000..4ba7818
--- /dev/null
+++ b/src/androidextras/doc/images/notification.png
Binary files differ
diff --git a/src/androidextras/doc/qtandroidextras.qdocconf b/src/androidextras/doc/qtandroidextras.qdocconf
index 9e123bb..02e5390 100644
--- a/src/androidextras/doc/qtandroidextras.qdocconf
+++ b/src/androidextras/doc/qtandroidextras.qdocconf
@@ -29,7 +29,7 @@ tagfile = ../../../doc/qtandroidextras/qtandroidextras.tags
depends += qtcore
headerdirs += ..
sourcedirs += ..
-exampledirs += ../../../examples/qtandroidextras \
+exampledirs += ../../../examples/androidextras \
../ \
snippets
diff --git a/src/androidextras/doc/snippets/code/src_androidextras_qjnienvironment.cpp b/src/androidextras/doc/snippets/code/src_androidextras_qjnienvironment.cpp
index e799420..bf1bd28 100644
--- a/src/androidextras/doc/snippets/code/src_androidextras_qjnienvironment.cpp
+++ b/src/androidextras/doc/snippets/code/src_androidextras_qjnienvironment.cpp
@@ -37,3 +37,16 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+
+//! [Create QJNIEnvironment]
+
+bool exceptionCheck()
+{
+ /*
+ The QJNIEnvironment attaches the current thread to the JavaVM on
+ creation and detach when it goes out of scope.
+ */
+ QJNIEnvironment qjniEnv;
+ return qjniEnv->ExceptionCheck();
+}
+//! [Create QJNIEnvironment]
diff --git a/src/androidextras/doc/snippets/code/src_androidextras_qjniobject.cpp b/src/androidextras/doc/snippets/code/src_androidextras_qjniobject.cpp
index 1ef86fe..8be1053 100644
--- a/src/androidextras/doc/snippets/code/src_androidextras_qjniobject.cpp
+++ b/src/androidextras/doc/snippets/code/src_androidextras_qjniobject.cpp
@@ -68,3 +68,16 @@ void function()
// Ops! myJString is no longer valid.
}
//! [QJNIObject scope]
+
+//! [Check for exceptions]
+void function()
+{
+ QJNIObject myString = QJNIObject::fromString("Hello");
+ jchar c = myString.callMethod<jchar>("charAt", "(I)C", 1000);
+ QJNIEnvironment env;
+ if (env->ExceptionCheck()) {
+ // Handle exception here.
+ env->ExceptionClear();
+ }
+}
+//! [Check for exceptions]
diff --git a/src/androidextras/doc/src/qtandroidextras-index.qdoc b/src/androidextras/doc/src/qtandroidextras-index.qdoc
index 823e71e..cf7d3df 100644
--- a/src/androidextras/doc/src/qtandroidextras-index.qdoc
+++ b/src/androidextras/doc/src/qtandroidextras-index.qdoc
@@ -33,8 +33,24 @@
\section1 Getting Started
- \list
+ To include the definitions of the module's classes, use the
+ following directive:
- \endlist
+ \code
+ #include <QtAndroidExtras>
+ \endcode
+
+ To link against the module, add this line to your \l qmake \c
+ .pro file:
+
+ \code
+ QT += androidextras
+ \endcode
+ \section1 API Reference
+
+ Links to the API reference materials:
+ \list
+ \li \l{Qt Android Extras C++ Classes}{C++ Classes}
+ \endlist
*/
diff --git a/src/androidextras/doc/src/qtandroidextras-module.qdoc b/src/androidextras/doc/src/qtandroidextras-module.qdoc
index f62484e..badb8a7 100644
--- a/src/androidextras/doc/src/qtandroidextras-module.qdoc
+++ b/src/androidextras/doc/src/qtandroidextras-module.qdoc
@@ -28,10 +28,22 @@
/*!
\module QtAndroidExtras
\title Qt Android Extras C++ Classes
- \brief The Qt Android Extras module contains functionality to additional functionality to aid development on Android.
+ \brief The Qt Android Extras module contains additional functionality for development on Android.
\ingroup modules
\qtvariable androidextras
- The Qt Android Extras module adds...
+ To include the definitions of the module's classes, use the
+ following directive:
+
+ \code
+ #include <QtAndroidExtras>
+ \endcode
+
+ To link against the module, add this line to your \l qmake \c
+ .pro file:
+
+ \code
+ QT += androidextras
+ \endcode
*/
diff --git a/src/androidextras/jni/qjnienvironment.cpp b/src/androidextras/jni/qjnienvironment.cpp
index f21d763..e27e5ce 100644
--- a/src/androidextras/jni/qjnienvironment.cpp
+++ b/src/androidextras/jni/qjnienvironment.cpp
@@ -46,6 +46,46 @@
QT_BEGIN_NAMESPACE
+/*!
+ \class QJNIEnvironment
+ \inmodule QtAndroidExtras
+ \brief The QJNIEnvironment provides access to the JNI Environment.
+ \since 5.2
+*/
+
+/*!
+ \fn QJNIEnvironment::QJNIEnvironment()
+
+ Constructs a new QJNIEnvironment object and attach the current thread to the Java VM.
+
+ \snippet code/src_androidextras_qjnienvironment.cpp Create QJNIEnvironment
+*/
+
+/*!
+ \fn QJNIEnvironment::~QJNIEnvironment()
+
+ Detaches the current thread from the Java VM and destroys the QJNIEnvironment object.
+*/
+
+/*!
+ \fn JavaVM *QJNIEnvironment::javaVM()
+
+ Returns the Java VM interface.
+*/
+
+/*!
+ \fn JNIEnv *QJNIEnvironment::operator->()
+
+ Provides access to the QJNIEnvironment's JNIEnv pointer.
+*/
+
+/*!
+ \fn QJNIEnvironment::operator JNIEnv *() const
+
+ Returns the the JNI Environment pointer.
+ */
+
+
QJNIEnvironment::QJNIEnvironment()
: d(new QJNIEnvironmentPrivate)
{
diff --git a/src/androidextras/jni/qjniobject.cpp b/src/androidextras/jni/qjniobject.cpp
index e5dc6e5..c2a510e 100644
--- a/src/androidextras/jni/qjniobject.cpp
+++ b/src/androidextras/jni/qjniobject.cpp
@@ -48,12 +48,14 @@ QT_BEGIN_NAMESPACE
/*!
\class QJNIObject
\inmodule QtAndroidExtras
- \brief The QJNIObject ...
+ \brief The QJNIObject is a C++ wrapper around a Java class.
\since 5.2
- \section1 Stub
+ QJNIObject provides APIs to call Java methods
- Supported JNI object types:
+ \section1 JNI types
+
+ Object types:
\list
\li jobject
\li jclass
@@ -70,7 +72,7 @@ QT_BEGIN_NAMESPACE
\li jdoubleArray
\endlist
- Supported JNI Primitive types:
+ Primitive types:
\list
\li jboolean
\li jbyte
@@ -82,21 +84,28 @@ QT_BEGIN_NAMESPACE
\li jdouble
\endlist
- About function types: ...
+ \section1 General Notes:
- - Class name strings needs to be the fully-qualified class name, e.g., "java/lang/String".
+ - Class name strings needs to be the fully-qualified class name, for example: "java/lang/String".
- Method signatures are written as "(Arguments)ReturnType"
- All object types are returned as a QJNIObject.
- More information about JNI can be found in the java doc [url]
+ \section1 Handling Java exception:
+
+ When calling Java functions that might throw an exception, it is important that you handle and
+ clear out the exception before continuing.
+
+ \snippet code/src_androidextras_qjniobject.cpp Check for exceptions
+ For more information about JNI see: \l http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/jniTOC.html
*/
/*!
\fn QJNIObject::QJNIObject()
- \code
- \endcode
+ Constructs an invalid QJNIObject.
+
+ \sa isValid()
*/
/*!
@@ -143,10 +152,12 @@ QT_BEGIN_NAMESPACE
/*!
\fn QJNIObject::QJNIObject(jclass clazz, const char *signature, ...)
- Constructs a new QJNIObject from \a clazz by calling the non-default
- constructor with \a signature and arguments.
+ Constructs a new QJNIObject from \a clazz by calling the constructor with \a signature
+ and arguments.
\code
+ jclass myClass = ...;
+ QJNIObject::QJNIObject(myClazz, "(I)V", 3);
\endcode
*/
@@ -167,20 +178,25 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn T QJNIObject::callMethod(const char *methodName) const
+ \fn T QJNIObject::callMethod(const char *methodName, const char *signature, ...) const
- Calls the Java object method \a methodName and returns the value.
+ Calls the method \a methodName with \a signature and returns the value.
\code
QJNIObject myJavaString = ...;
- jint size = myJavaString.callMethod<jint>("length");
+ jint index = myJavaString.callMethod<jint>("indexOf", "(I)I", 0x0051);
\endcode
+
*/
/*!
- \fn T QJNIObject::callMethod(const char *methodName, const char *signature, ...) const
+ \fn T QJNIObject::callMethod(const char *methodName) const
+
+ Calls the method \a methodName and returs the value.
\code
+ QJNIObject myJavaString = ...;
+ jint size = myJavaString.callMethod<jint>("length");
\endcode
*/
@@ -210,28 +226,38 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn T QJNIObject::callStaticMethod(const char *className, const char *methodName)
+ \fn T QJNIObject::callStaticMethod(jclass clazz, const char *methodName)
+
+ Calls the static method \a methodName on \a clazz and returns the value T.
\code
+ ...
+ jclass javaMathClass = ...; // ("java/lang/Math")
+ jdouble randNr = QJNIObject::callStaticMethod<jdouble>(javaMathClass, "random");
+ ...
\endcode
*/
/*!
- \fn T QJNIObject::callStaticMethod(const char *className, const char *methodName, const char *sig, ...)
+ \fn T QJNIObject::callStaticMethod(const char *className, const char *methodName)
+
+ Calls the static method \a methodName on class \a className and returns the value.
\code
+ jint value = QJNIObject::callStaticMethod<jint>("MyClass", "staticMethod");
\endcode
*/
/*!
- \fn T QJNIObject::callStaticMethod(jclass clazz, const char *methodName)
+ \fn T QJNIObject::callStaticMethod(const char *className, const char *methodName, const char *signature, ...)
- Calls the static method \a methodName on \a clazz and returns the value T.
+ Calls the static method with \a methodName with \a signature on class \a className with optional arguments.
\code
...
- jclass javaMathClass = ...; // ("java/lang/Math")
- jdouble randNr = QJNIObject::callStaticMethod<jdouble>(javaMathClass, "random");
+ jint a = 2;
+ jint b = 4;
+ jint max = QJNIObject::callStaticMethod<jint>("java/lang/Math", "max", "(II)I", a, b);
...
\endcode
*/
@@ -255,105 +281,101 @@ QT_BEGIN_NAMESPACE
/*!
\fn QJNIObject QJNIObject::callStaticObjectMethod(const char *className, const char *methodName)
+ Calls the static method with \a methodName on the class \a className.
+
\code
+ QJNIObject string = QJNIObject::callStaticObjectMethod<jstring>("CustomClass", "getClassName");
\endcode
*/
/*!
- \fn QJNIObject QJNIObject::callStaticObjectMethod(const char *className, const char *methodName, const char *sig, ...)
+ \fn QJNIObject QJNIObject::callStaticObjectMethod(const char *className, const char *methodName, const char *signature, ...)
+
+ Calls the static method with \a methodName and \a signature on the class \a className.
\code
+ QJNIObject thread = QJNIObject::callStaticObjectMethod("java/lang/Thread", "currentThread", "()Ljava/lang/Thread;");
+ QJNIObject string = QJNIObject::callStaticObjectMethod("java/lang/String", "valueOf", "(I)Ljava/lang/String;", 10);
\endcode
*/
/*!
\fn QJNIObject QJNIObject::callStaticObjectMethod(jclass clazz, const char *methodName)
- Calls the static \e object method \a methodName on \a clazz.
- \code
- \endcode
+ Calls the static method with \a methodName on \a clazz.
+
*/
/*!
\fn QJNIObject QJNIObject::callStaticObjectMethod(jclass clazz, const char *methodName, const char *signature, ...)
- \code
- \endcode
+ Calls the static method with \a methodName and \a signature on class \a clazz.
*/
/*!
\fn T QJNIObject::getField(const char *fieldName) const
- \code
- \endcode
-*/
-
-/*!
- \fn T QJNIObject::getField(const char *fieldName, const char *sig) const
+ Retrieves the value of the field \a fieldName.
\code
+ QJNIObject volumeControll = ...;
+ jint fieldValue = obj.getField<jint>("MAX_VOLUME");
\endcode
*/
/*!
\fn QJNIObject QJNIObject::getObjectField(const char *fieldName) const
- \code
- \endcode
+ Retrieves the object of field \a fieldName.
*/
/*!
\fn QJNIObject QJNIObject::getObjectField(const char *fieldName, const char *signature) const
- \code
- \endcode
+ Retrieves the object from the field with \a signature and \a fieldName.
*/
/*!
\fn T QJNIObject::getStaticField(const char *className, const char *fieldName)
- \code
- \endcode
+ Retrieves the value from the static field \a fieldName on the class \a className.
*/
/*!
\fn T QJNIObject::getStaticField(jclass clazz, const char *fieldName)
- \code
- \endcode
+ Retrieves the value from the static field \a fieldName on \a clazz.
*/
/*!
\fn QJNIObject QJNIObject::getStaticObjectField(const char *className, const char *fieldName)
- \code
- \endcode
+ Retrieves the object from the field \a fieldName on the class \a className.
*/
/*!
\fn QJNIObject QJNIObject::getStaticObjectField(const char *className, const char *fieldName, const char *signature)
- \code
- \endcode
+ Retrieves the object from the field with \a signature and \a fieldName on class \a className.
*/
/*!
\fn QJNIObject QJNIObject::getStaticObjectField(jclass clazz, const char *fieldName)
- \code
- \endcode
+ Retrieves the object from the field \a fieldName on \a clazz.
*/
/*!
\fn QJNIObject QJNIObject::getStaticObjectField(jclass clazz, const char *fieldName, const char *signature)
- \code
- \endcode
+ Retrieves the object from the field with \a signature and \a fieldName on \a clazz.
*/
/*!
\fn void QJNIObject::setField(const char *fieldName, T value)
+ Sets the value of \a fieldName to \a value.
+
\code
...
QJNIObject obj;
@@ -367,36 +389,37 @@ QT_BEGIN_NAMESPACE
/*!
\fn void QJNIObject::setField(const char *fieldName, const char *signature, T value)
+ Sets the value of \a fieldName with \a signature to \a value.
+
\code
+ QJNIObject stringArray = ...;
+ QJNIObject obj = ...;
+ obj.setField<jobjectArray>("KEY_VALUES", "([Ljava/lang/String;)V", stringArray.object<jobjectArray>())
\endcode
*/
/*!
\fn void QJNIObject::setStaticField(const char *className, const char *fieldName, T value)
- \code
- \endcode
+ Sets the value of the static field \a fieldName in class \a className to \a value.
*/
/*!
- \fn void QJNIObject::setStaticField(const char *className, const char *fieldName, const char *sig, T value);
+ \fn void QJNIObject::setStaticField(const char *className, const char *fieldName, const char *signature, T value);
- \code
- \endcode
+ Sets the static field with \a fieldName and \a signature to \a value on class \a className.
*/
/*!
\fn void QJNIObject::setStaticField(jclass clazz, const char *fieldName, T value)
- \code
- \endcode
+ Sets the static field \a fieldName of the class \a clazz to \a value.
*/
/*!
- \fn void QJNIObject::setStaticField(jclass clazz, const char *fieldName, const char *sig, T value);
+ \fn void QJNIObject::setStaticField(jclass clazz, const char *fieldName, const char *signature, T value);
- \code
- \endcode
+ Sets the static field with \a fieldName and \a signature to \a value on class \a clazz.
*/
/*!
@@ -448,26 +471,27 @@ QT_BEGIN_NAMESPACE
\fn QJNIObject &QJNIObject::operator=(T object)
Replace the current object with \a object. The old Java object will be released.
-
- \code
- \endcode
*/
/*!
\fn QString QJNIObject::toString() const
- Returns a QString with the data returned from calling the toString() function on a java object.
- If the QJNIObject is wrapped around a Java String, calling this is a convenient way to convert
- a Java string to a QString.
+ Returns a QString with a string representation of the java object.
+ Calling this function on a Java String object is a convenient way of getting the actuall string
+ data.
\code
+ QJNIObject string = ...; // "Hello Java"
+ QString qstring = string.toString(); // "Hello Java"
\endcode
+
+ \sa fromString()
*/
/*!
\fn QJNIObject QJNIObject::fromString(const QString &string)
- Creates a Java string from the QString \a string and returns a QJNIObject wrapping that string.
+ Creates a Java string from the QString \a string and returns a QJNIObject holding that string.
\code
...
@@ -475,6 +499,8 @@ QT_BEGIN_NAMESPACE
QJNIObject myJavaString = QJNIObject::fromString(myQString);
...
\endcode
+
+ \sa toString()
*/
/*!
@@ -1560,13 +1586,13 @@ jlong QJNIObject::getStaticField<jlong>(jclass clazz, const char *fieldName)
template <>
jlong QJNIObject::getStaticField<jlong>(const char *className, const char *fieldName)
{
- return getStaticField<jlong>(className, fieldName);
+ return QJNIObjectPrivate::getStaticField<jlong>(className, fieldName);
}
template <>
jfloat QJNIObject::getStaticField<jfloat>(jclass clazz, const char *fieldName)
{
- return getStaticField<jfloat>(clazz, fieldName);
+ return QJNIObjectPrivate::getStaticField<jfloat>(clazz, fieldName);
}
template <>
diff --git a/src/src.pro b/src/src.pro
index c7b1e74..467ccc4 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -1,2 +1,2 @@
TEMPLATE = subdirs
-SUBDIRS += androidextras
+android:SUBDIRS += androidextras
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 44b3c49..a758912 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -1,2 +1,4 @@
-TEMPLATE=subdirs
-SUBDIRS=
+TEMPLATE = subdirs
+SUBDIRS += \
+ qjnienvironment \
+ qjniobject
diff --git a/tests/auto/qjnienvironment/qjnienvironment.pro b/tests/auto/qjnienvironment/qjnienvironment.pro
new file mode 100644
index 0000000..e4b7b09
--- /dev/null
+++ b/tests/auto/qjnienvironment/qjnienvironment.pro
@@ -0,0 +1,4 @@
+CONFIG += testcase
+TARGET = tst_qjnienvironment
+QT += testlib androidextras
+SOURCES += tst_qjnienvironment.cpp
diff --git a/tests/auto/qjnienvironment/tst_qjnienvironment.cpp b/tests/auto/qjnienvironment/tst_qjnienvironment.cpp
new file mode 100644
index 0000000..7d5de58
--- /dev/null
+++ b/tests/auto/qjnienvironment/tst_qjnienvironment.cpp
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite 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$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QtAndroidExtras/QJNIEnvironment>
+
+class tst_QJNIEnvironment : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void jniEnv();
+ void javaVM();
+
+public:
+ static JavaVM *m_javaVM;
+};
+
+JavaVM *tst_QJNIEnvironment::m_javaVM = 0;
+
+void tst_QJNIEnvironment::jniEnv()
+{
+ QVERIFY(m_javaVM);
+
+ {
+ QJNIEnvironment env;
+
+ // JNI environment should now be attached to the current thread
+ JNIEnv *jni = 0;
+ QCOMPARE(m_javaVM->GetEnv((void**)&jni, JNI_VERSION_1_6), JNI_OK);
+
+ JNIEnv *e = env;
+ QVERIFY(e);
+
+ QCOMPARE(env->GetVersion(), JNI_VERSION_1_6);
+
+ // try to find an existing class
+ QVERIFY(env->FindClass("java/lang/Object"));
+ QVERIFY(!env->ExceptionCheck());
+
+ // try to find a nonexistent class
+ QVERIFY(!env->FindClass("this/doesnt/Exist"));
+ QVERIFY(env->ExceptionCheck());
+ env->ExceptionClear();
+ }
+
+ // The environment should automatically be detached when QJNIEnvironment goes out of scope
+ JNIEnv *jni = 0;
+ QCOMPARE(m_javaVM->GetEnv((void**)&jni, JNI_VERSION_1_6), JNI_EDETACHED);
+}
+
+void tst_QJNIEnvironment::javaVM()
+{
+ QVERIFY(m_javaVM);
+
+ QJNIEnvironment env;
+ QCOMPARE(env.javaVM(), m_javaVM);
+
+ JavaVM *vm = 0;
+ QCOMPARE(env->GetJavaVM(&vm), JNI_OK);
+ QCOMPARE(env.javaVM(), vm);
+}
+
+Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
+{
+ Q_UNUSED(reserved)
+ tst_QJNIEnvironment::m_javaVM = vm;
+ return JNI_VERSION_1_6;
+}
+
+QTEST_APPLESS_MAIN(tst_QJNIEnvironment)
+
+#include "tst_qjnienvironment.moc"
diff --git a/tests/auto/qjniobject/qjniobject.pro b/tests/auto/qjniobject/qjniobject.pro
new file mode 100644
index 0000000..30a0a0d
--- /dev/null
+++ b/tests/auto/qjniobject/qjniobject.pro
@@ -0,0 +1,4 @@
+CONFIG += testcase
+TARGET = tst_qjniobject
+QT += testlib androidextras
+SOURCES += tst_qjniobject.cpp
diff --git a/tests/auto/qjniobject/tst_qjniobject.cpp b/tests/auto/qjniobject/tst_qjniobject.cpp
new file mode 100644
index 0000000..cc0f286
--- /dev/null
+++ b/tests/auto/qjniobject/tst_qjniobject.cpp
@@ -0,0 +1,730 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite 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$
+**
+****************************************************************************/
+
+#include <QString>
+#include <QtTest>
+#include <QtAndroidExtras/QJNIObject>
+#include <QtAndroidExtras/QJNIEnvironment>
+
+class tst_QJNIObject : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QJNIObject();
+
+private slots:
+ void initTestCase();
+
+ void ctor();
+ void callMethodTest();
+ void callObjectMethodTest();
+ void stringConvertionTest();
+ void compareOperatorTests();
+ void callStaticObjectMethodClassName();
+ void callStaticObjectMethod();
+ void callStaticBooleanMethodClassName();
+ void callStaticBooleanMethod();
+ void callStaticCharMethodClassName();
+ void callStaticCharMethod();
+ void callStaticIntMethodClassName();
+ void callStaticIntMethod();
+ void callStaticByteMethodClassName();
+ void callStaticByteMethod();
+ void callStaticDoubleMethodClassName();
+ void callStaticDoubleMethod();
+ void callStaticFloatMethodClassName();
+ void callStaticFloatMethod();
+ void callStaticLongMethodClassName();
+ void callStaticLongMethod();
+ void callStaticShortMethodClassName();
+ void callStaticShortMethod();
+ void getStaticObjectFieldClassName();
+ void getStaticObjectField();
+ void getStaticIntFieldClassName();
+ void getStaticIntField();
+ void getStaticByteFieldClassName();
+ void getStaticByteField();
+ void getStaticLongFieldClassName();
+ void getStaticLongField();
+ void getStaticDoubleFieldClassName();
+ void getStaticDoubleField();
+ void getStaticFloatFieldClassName();
+ void getStaticFloatField();
+ void getStaticShortFieldClassName();
+ void getStaticShortField();
+ void getStaticCharFieldClassName();
+ void getStaticCharField();
+ void getBooleanField();
+ void getIntField();
+
+ void cleanupTestCase();
+
+public:
+ static jclass m_activityDelegateClass;
+};
+
+jclass tst_QJNIObject::m_activityDelegateClass = 0;
+
+tst_QJNIObject::tst_QJNIObject()
+{
+}
+
+void tst_QJNIObject::initTestCase()
+{
+}
+
+void tst_QJNIObject::cleanupTestCase()
+{
+}
+
+void tst_QJNIObject::ctor()
+{
+ {
+ QJNIObject object;
+ QVERIFY(!object.isValid());
+ }
+
+ {
+ QJNIObject object("java/lang/String");
+ QVERIFY(object.isValid());
+ }
+
+ {
+ QJNIObject string = QJNIObject::fromString(QLatin1String("Hello, Java"));
+ QJNIObject object("java/lang/String", "(Ljava/lang/String;)V", string.object<jstring>());
+ QVERIFY(object.isValid());
+ QCOMPARE(string.toString(), object.toString());
+ }
+
+ {
+ QJNIEnvironment env;
+ jclass javaStringClass = env->FindClass("java/lang/String");
+ QJNIObject string(javaStringClass);
+ QVERIFY(string.isValid());
+ }
+
+ {
+ QJNIEnvironment env;
+ const QString qString = QLatin1String("Hello, Java");
+ jclass javaStringClass = env->FindClass("java/lang/String");
+ QJNIObject string = QJNIObject::fromString(qString);
+ QJNIObject stringCpy(javaStringClass, "(Ljava/lang/String;)V", string.object<jstring>());
+ QVERIFY(stringCpy.isValid());
+ QCOMPARE(qString, stringCpy.toString());
+ }
+}
+
+void tst_QJNIObject::callMethodTest()
+{
+ {
+ QJNIObject jString1 = QJNIObject::fromString(QLatin1String("Hello, Java"));
+ QJNIObject jString2 = QJNIObject::fromString(QLatin1String("hELLO, jAVA"));
+ QVERIFY(jString1 != jString2);
+
+ const jboolean isEmpty = jString1.callMethod<jboolean>("isEmpty");
+ QVERIFY(!isEmpty);
+
+ const jint ret = jString1.callMethod<jint>("compareToIgnoreCase",
+ "(Ljava/lang/String;)I",
+ jString2.object<jstring>());
+ QVERIFY(0 == ret);
+ }
+
+ {
+ jlong jLong = 100;
+ QJNIObject longObject("java/lang/Long", "(J)V", jLong);
+ jlong ret = longObject.callMethod<jlong>("longValue");
+ QCOMPARE(ret, jLong);
+ }
+}
+
+void tst_QJNIObject::callObjectMethodTest()
+{
+ const QString qString = QLatin1String("Hello, Java");
+ QJNIObject jString = QJNIObject::fromString(qString);
+ const QString qStringRet = jString.callObjectMethod<jstring>("toUpperCase").toString();
+ QCOMPARE(qString.toUpper(), qStringRet);
+
+ QJNIObject subString = jString.callObjectMethod("substring",
+ "(II)Ljava/lang/String;",
+ 0, 4);
+ QCOMPARE(subString.toString(), qString.mid(0, 4));
+}
+
+void tst_QJNIObject::stringConvertionTest()
+{
+ const QString qString(QLatin1String("Hello, Java"));
+ QJNIObject jString = QJNIObject::fromString(qString);
+ QVERIFY(jString.isValid());
+ QString qStringRet = jString.toString();
+ QCOMPARE(qString, qStringRet);
+}
+
+void tst_QJNIObject::compareOperatorTests()
+{
+ QString str("hello!");
+ QJNIObject stringObject = QJNIObject::fromString(str);
+
+ jobject jobj = stringObject.object<jobject>();
+ jstring jsobj = stringObject.object<jstring>();
+
+ QVERIFY(jobj == stringObject);
+ QVERIFY(stringObject == jobj);
+ QVERIFY(jsobj == stringObject);
+ QVERIFY(stringObject == jsobj);
+
+ QJNIObject stringObject3 = stringObject.object<jstring>();
+ QVERIFY(stringObject3 == stringObject);
+
+ QJNIObject stringObject2 = QJNIObject::fromString(str);
+ QVERIFY(stringObject != stringObject2);
+
+ jstring jstrobj = 0;
+ QJNIObject invalidStringObject;
+ QVERIFY(invalidStringObject == jstrobj);
+
+ QVERIFY(jstrobj != stringObject);
+ QVERIFY(stringObject != jstrobj);
+ QVERIFY(!invalidStringObject.isValid());
+}
+
+void tst_QJNIObject::callStaticObjectMethodClassName()
+{
+ QJNIObject formatString = QJNIObject::fromString(QLatin1String("test format"));
+ QVERIFY(formatString.isValid());
+
+ QVERIFY(QJNIObject::isClassAvailable("java/lang/String"));
+ QJNIObject returnValue = QJNIObject::callStaticObjectMethod("java/lang/String",
+ "format",
+ "(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;",
+ formatString.object<jstring>(),
+ jobjectArray(0));
+ QVERIFY(returnValue.isValid());
+
+ QString returnedString = returnValue.toString();
+
+ QCOMPARE(returnedString, QString::fromLatin1("test format"));
+}
+
+void tst_QJNIObject::callStaticObjectMethod()
+{
+ QJNIEnvironment env;
+ jclass cls = env->FindClass("java/lang/String");
+ QVERIFY(cls != 0);
+
+ QJNIObject formatString = QJNIObject::fromString(QLatin1String("test format"));
+ QVERIFY(formatString.isValid());
+
+ QJNIObject returnValue = QJNIObject::callStaticObjectMethod(cls,
+ "format",
+ "(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;",
+ formatString.object<jstring>(),
+ jobjectArray(0));
+ QVERIFY(returnValue.isValid());
+
+ QString returnedString = returnValue.toString();
+
+ QCOMPARE(returnedString, QString::fromLatin1("test format"));
+}
+
+void tst_QJNIObject::callStaticBooleanMethod()
+{
+ QJNIEnvironment env;
+ jclass cls = env->FindClass("java/lang/Boolean");
+ QVERIFY(cls != 0);
+
+ {
+ QJNIObject parameter = QJNIObject::fromString("true");
+ QVERIFY(parameter.isValid());
+
+ jboolean b = QJNIObject::callStaticMethod<jboolean>(cls,
+ "parseBoolean",
+ "(Ljava/lang/String;)Z",
+ parameter.object<jstring>());
+ QVERIFY(b);
+ }
+
+ {
+ QJNIObject parameter = QJNIObject::fromString("false");
+ QVERIFY(parameter.isValid());
+
+ jboolean b = QJNIObject::callStaticMethod<jboolean>(cls,
+ "parseBoolean",
+ "(Ljava/lang/String;)Z",
+ parameter.object<jstring>());
+ QVERIFY(!b);
+ }
+}
+
+void tst_QJNIObject::callStaticBooleanMethodClassName()
+{
+ {
+ QJNIObject parameter = QJNIObject::fromString("true");
+ QVERIFY(parameter.isValid());
+
+ jboolean b = QJNIObject::callStaticMethod<jboolean>("java/lang/Boolean",
+ "parseBoolean",
+ "(Ljava/lang/String;)Z",
+ parameter.object<jstring>());
+ QVERIFY(b);
+ }
+
+ {
+ QJNIObject parameter = QJNIObject::fromString("false");
+ QVERIFY(parameter.isValid());
+
+ jboolean b = QJNIObject::callStaticMethod<jboolean>("java/lang/Boolean",
+ "parseBoolean",
+ "(Ljava/lang/String;)Z",
+ parameter.object<jstring>());
+ QVERIFY(!b);
+ }
+}
+
+void tst_QJNIObject::callStaticByteMethodClassName()
+{
+ QString number = QString::number(123);
+ QJNIObject parameter = QJNIObject::fromString(number);
+
+ jbyte returnValue = QJNIObject::callStaticMethod<jbyte>("java/lang/Byte",
+ "parseByte",
+ "(Ljava/lang/String;)B",
+ parameter.object<jstring>());
+ QCOMPARE(returnValue, jbyte(number.toInt()));
+}
+
+void tst_QJNIObject::callStaticByteMethod()
+{
+ QJNIEnvironment env;
+ jclass cls = env->FindClass("java/lang/Byte");
+ QVERIFY(cls != 0);
+
+ QString number = QString::number(123);
+ QJNIObject parameter = QJNIObject::fromString(number);
+
+ jbyte returnValue = QJNIObject::callStaticMethod<jbyte>(cls,
+ "parseByte",
+ "(Ljava/lang/String;)B",
+ parameter.object<jstring>());
+ QCOMPARE(returnValue, jbyte(number.toInt()));
+}
+
+void tst_QJNIObject::callStaticIntMethodClassName()
+{
+ QString number = QString::number(123);
+ QJNIObject parameter = QJNIObject::fromString(number);
+
+ jint returnValue = QJNIObject::callStaticMethod<jint>("java/lang/Integer",
+ "parseInt",
+ "(Ljava/lang/String;)I",
+ parameter.object<jstring>());
+ QCOMPARE(returnValue, number.toInt());
+}
+
+
+void tst_QJNIObject::callStaticIntMethod()
+{
+ QJNIEnvironment env;
+ jclass cls = env->FindClass("java/lang/Integer");
+ QVERIFY(cls != 0);
+
+ QString number = QString::number(123);
+ QJNIObject parameter = QJNIObject::fromString(number);
+
+ jint returnValue = QJNIObject::callStaticMethod<jint>(cls,
+ "parseInt",
+ "(Ljava/lang/String;)I",
+ parameter.object<jstring>());
+ QCOMPARE(returnValue, number.toInt());
+}
+
+void tst_QJNIObject::callStaticCharMethodClassName()
+{
+ jchar returnValue = QJNIObject::callStaticMethod<jchar>("java/lang/Character",
+ "toUpperCase",
+ "(C)C",
+ jchar('a'));
+ QCOMPARE(returnValue, jchar('A'));
+}
+
+
+void tst_QJNIObject::callStaticCharMethod()
+{
+ QJNIEnvironment env;
+ jclass cls = env->FindClass("java/lang/Character");
+ QVERIFY(cls != 0);
+
+ jchar returnValue = QJNIObject::callStaticMethod<jchar>(cls,
+ "toUpperCase",
+ "(C)C",
+ jchar('a'));
+ QCOMPARE(returnValue, jchar('A'));
+}
+
+void tst_QJNIObject::callStaticDoubleMethodClassName ()
+{
+ QString number = QString::number(123.45);
+ QJNIObject parameter = QJNIObject::fromString(number);
+
+ jdouble returnValue = QJNIObject::callStaticMethod<jdouble>("java/lang/Double",
+ "parseDouble",
+ "(Ljava/lang/String;)D",
+ parameter.object<jstring>());
+ QCOMPARE(returnValue, number.toDouble());
+}
+
+
+void tst_QJNIObject::callStaticDoubleMethod()
+{
+ QJNIEnvironment env;
+ jclass cls = env->FindClass("java/lang/Double");
+ QVERIFY(cls != 0);
+
+ QString number = QString::number(123.45);
+ QJNIObject parameter = QJNIObject::fromString(number);
+
+ jdouble returnValue = QJNIObject::callStaticMethod<jdouble>(cls,
+ "parseDouble",
+ "(Ljava/lang/String;)D",
+ parameter.object<jstring>());
+ QCOMPARE(returnValue, number.toDouble());
+}
+
+void tst_QJNIObject::callStaticFloatMethodClassName()
+{
+ QString number = QString::number(123.45);
+ QJNIObject parameter = QJNIObject::fromString(number);
+
+ jfloat returnValue = QJNIObject::callStaticMethod<jfloat>("java/lang/Float",
+ "parseFloat",
+ "(Ljava/lang/String;)F",
+ parameter.object<jstring>());
+ QCOMPARE(returnValue, number.toFloat());
+}
+
+
+void tst_QJNIObject::callStaticFloatMethod()
+{
+ QJNIEnvironment env;
+ jclass cls = env->FindClass("java/lang/Float");
+ QVERIFY(cls != 0);
+
+ QString number = QString::number(123.45);
+ QJNIObject parameter = QJNIObject::fromString(number);
+
+ jfloat returnValue = QJNIObject::callStaticMethod<jfloat>(cls,
+ "parseFloat",
+ "(Ljava/lang/String;)F",
+ parameter.object<jstring>());
+ QCOMPARE(returnValue, number.toFloat());
+}
+
+void tst_QJNIObject::callStaticShortMethodClassName()
+{
+ QString number = QString::number(123);
+ QJNIObject parameter = QJNIObject::fromString(number);
+
+ jshort returnValue = QJNIObject::callStaticMethod<jshort>("java/lang/Short",
+ "parseShort",
+ "(Ljava/lang/String;)S",
+ parameter.object<jstring>());
+ QCOMPARE(returnValue, number.toShort());
+}
+
+
+void tst_QJNIObject::callStaticShortMethod()
+{
+ QJNIEnvironment env;
+ jclass cls = env->FindClass("java/lang/Short");
+ QVERIFY(cls != 0);
+
+ QString number = QString::number(123);
+ QJNIObject parameter = QJNIObject::fromString(number);
+
+ jshort returnValue = QJNIObject::callStaticMethod<jshort>(cls,
+ "parseShort",
+ "(Ljava/lang/String;)S",
+ parameter.object<jstring>());
+ QCOMPARE(returnValue, number.toShort());
+}
+
+void tst_QJNIObject::callStaticLongMethodClassName()
+{
+ QString number = QString::number(123);
+ QJNIObject parameter = QJNIObject::fromString(number);
+
+ jlong returnValue = QJNIObject::callStaticMethod<jlong>("java/lang/Long",
+ "parseLong",
+ "(Ljava/lang/String;)J",
+ parameter.object<jstring>());
+ QCOMPARE(returnValue, jlong(number.toLong()));
+}
+
+void tst_QJNIObject::callStaticLongMethod()
+{
+ QJNIEnvironment env;
+ jclass cls = env->FindClass("java/lang/Long");
+ QVERIFY(cls != 0);
+
+ QString number = QString::number(123);
+ QJNIObject parameter = QJNIObject::fromString(number);
+
+ jlong returnValue = QJNIObject::callStaticMethod<jlong>(cls,
+ "parseLong",
+ "(Ljava/lang/String;)J",
+ parameter.object<jstring>());
+ QCOMPARE(returnValue, jlong(number.toLong()));
+}
+
+void tst_QJNIObject::getStaticObjectFieldClassName()
+{
+ {
+ QJNIObject boolObject = QJNIObject::getStaticObjectField<jobject>("java/lang/Boolean",
+ "FALSE",
+ "Ljava/lang/Boolean;");
+ QVERIFY(boolObject.isValid());
+
+ jboolean booleanValue = boolObject.callMethod<jboolean>("booleanValue");
+ QVERIFY(!booleanValue);
+ }
+
+ {
+ QJNIObject boolObject = QJNIObject::getStaticObjectField<jobject>("java/lang/Boolean",
+ "TRUE",
+ "Ljava/lang/Boolean;");
+ QVERIFY(boolObject.isValid());
+
+ jboolean booleanValue = boolObject.callMethod<jboolean>("booleanValue");
+ QVERIFY(booleanValue);
+ }
+}
+
+void tst_QJNIObject::getStaticObjectField()
+{
+ QJNIEnvironment env;
+ jclass cls = env->FindClass("java/lang/Boolean");
+ QVERIFY(cls != 0);
+
+ {
+ QJNIObject boolObject = QJNIObject::getStaticObjectField<jobject>(cls,
+ "FALSE",
+ "Ljava/lang/Boolean;");
+ QVERIFY(boolObject.isValid());
+
+ jboolean booleanValue = boolObject.callMethod<jboolean>("booleanValue");
+ QVERIFY(!booleanValue);
+ }
+
+ {
+ QJNIObject boolObject = QJNIObject::getStaticObjectField<jobject>(cls,
+ "TRUE",
+ "Ljava/lang/Boolean;");
+ QVERIFY(boolObject.isValid());
+
+ jboolean booleanValue = boolObject.callMethod<jboolean>("booleanValue");
+ QVERIFY(booleanValue);
+ }
+}
+
+void tst_QJNIObject::getStaticIntFieldClassName()
+{
+ jint i = QJNIObject::getStaticField<jint>("java/lang/Double", "SIZE");
+ QCOMPARE(i, 64);
+}
+
+void tst_QJNIObject::getStaticIntField()
+{
+ QJNIEnvironment env;
+ jclass cls = env->FindClass("java/lang/Double");
+ QVERIFY(cls != 0);
+
+ jint i = QJNIObject::getStaticField<jint>(cls, "SIZE");
+ QCOMPARE(i, 64);
+}
+
+void tst_QJNIObject::getStaticByteFieldClassName()
+{
+ jbyte i = QJNIObject::getStaticField<jbyte>("java/lang/Byte", "MAX_VALUE");
+ QCOMPARE(i, jbyte(127));
+}
+
+void tst_QJNIObject::getStaticByteField()
+{
+ QJNIEnvironment env;
+ jclass cls = env->FindClass("java/lang/Byte");
+ QVERIFY(cls != 0);
+
+ jbyte i = QJNIObject::getStaticField<jbyte>(cls, "MAX_VALUE");
+ QCOMPARE(i, jbyte(127));
+}
+
+void tst_QJNIObject::getStaticLongFieldClassName()
+{
+ jlong i = QJNIObject::getStaticField<jlong>("java/lang/Long", "MAX_VALUE");
+ QCOMPARE(i, jlong(9223372036854775807L));
+}
+
+void tst_QJNIObject::getStaticLongField()
+{
+ QJNIEnvironment env;
+ jclass cls = env->FindClass("java/lang/Long");
+ QVERIFY(cls != 0);
+
+ jlong i = QJNIObject::getStaticField<jlong>(cls, "MAX_VALUE");
+ QCOMPARE(i, jlong(9223372036854775807L));
+}
+
+void tst_QJNIObject::getStaticDoubleFieldClassName()
+{
+ jdouble i = QJNIObject::getStaticField<jdouble>("java/lang/Double", "NaN");
+ jlong *k = reinterpret_cast<jlong*>(&i);
+ QCOMPARE(*k, jlong(0x7ff8000000000000L));
+}
+
+void tst_QJNIObject::getStaticDoubleField()
+{
+ QJNIEnvironment env;
+ jclass cls = env->FindClass("java/lang/Double");
+ QVERIFY(cls != 0);
+
+ jdouble i = QJNIObject::getStaticField<jdouble>(cls, "NaN");
+ jlong *k = reinterpret_cast<jlong*>(&i);
+ QCOMPARE(*k, jlong(0x7ff8000000000000L));
+}
+
+void tst_QJNIObject::getStaticFloatFieldClassName()
+{
+ jfloat i = QJNIObject::getStaticField<jfloat>("java/lang/Float", "NaN");
+ unsigned *k = reinterpret_cast<unsigned*>(&i);
+ QCOMPARE(*k, unsigned(0x7fc00000));
+}
+
+void tst_QJNIObject::getStaticFloatField()
+{
+ QJNIEnvironment env;
+ jclass cls = env->FindClass("java/lang/Float");
+ QVERIFY(cls != 0);
+
+ jfloat i = QJNIObject::getStaticField<jfloat>(cls, "NaN");
+ unsigned *k = reinterpret_cast<unsigned*>(&i);
+ QCOMPARE(*k, unsigned(0x7fc00000));
+}
+
+void tst_QJNIObject::getStaticShortFieldClassName()
+{
+ jshort i = QJNIObject::getStaticField<jshort>("java/lang/Short", "MAX_VALUE");
+ QCOMPARE(i, jshort(32767));
+}
+
+void tst_QJNIObject::getStaticShortField()
+{
+ QJNIEnvironment env;
+ jclass cls = env->FindClass("java/lang/Short");
+ QVERIFY(cls != 0);
+
+ jshort i = QJNIObject::getStaticField<jshort>(cls, "MAX_VALUE");
+ QCOMPARE(i, jshort(32767));
+}
+
+void tst_QJNIObject::getStaticCharFieldClassName()
+{
+ jchar i = QJNIObject::getStaticField<jchar>("java/lang/Character", "MAX_VALUE");
+ QCOMPARE(i, jchar(0xffff));
+}
+
+void tst_QJNIObject::getStaticCharField()
+{
+ QJNIEnvironment env;
+ jclass cls = env->FindClass("java/lang/Character");
+ QVERIFY(cls != 0);
+
+ jchar i = QJNIObject::getStaticField<jchar>(cls, "MAX_VALUE");
+ QCOMPARE(i, jchar(0xffff));
+}
+
+
+void tst_QJNIObject::getBooleanField()
+{
+ QVERIFY(m_activityDelegateClass);
+
+ QJNIObject obj(m_activityDelegateClass);
+
+ QVERIFY(obj.isValid());
+ QVERIFY(!obj.getField<jboolean>("m_fullScreen"));
+}
+
+void tst_QJNIObject::getIntField()
+{
+ QVERIFY(m_activityDelegateClass);
+
+ QJNIObject obj(m_activityDelegateClass);
+
+ QVERIFY(obj.isValid());
+ jint res = obj.getField<jint>("m_currentRotation");
+
+ QCOMPARE(res, -1);
+}
+
+Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
+{
+ typedef union {
+ JNIEnv *nenv;
+ void *venv;
+ } _JNIEnv;
+
+ _JNIEnv uenv;
+ uenv.venv = Q_NULLPTR;
+
+ if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_6) != JNI_OK)
+ return JNI_ERR;
+
+ JNIEnv *env = uenv.nenv;
+
+ jclass clazz = env->FindClass("org/qtproject/qt5/android/QtActivityDelegate");
+ tst_QJNIObject::m_activityDelegateClass = (jclass)env->NewGlobalRef(clazz);
+
+ return JNI_VERSION_1_6;
+}
+
+QTEST_APPLESS_MAIN(tst_QJNIObject)
+
+#include "tst_qjniobject.moc"