Commit fba38f2f authored by Volker Krause's avatar Volker Krause
Browse files

Remove the need to inherit from JNI type classes

Instead, pass the type to the JNI_OBJECT macro.
parent 1a32f33a
......@@ -12,9 +12,9 @@
using namespace KAndroidExtras;
class TestClass : android::content::Intent
class TestClass
{
JNI_OBJECT(TestClass)
JNI_OBJECT(TestClass, android::content::Intent)
public:
JNI_METHOD(java::lang::String, getName)
JNI_METHOD(void, setName, java::lang::String)
......
......@@ -14,9 +14,9 @@
using namespace KAndroidExtras;
class TestClass : android::content::Intent
class TestClass
{
JNI_OBJECT(TestClass)
JNI_OBJECT(TestClass, android::content::Intent)
JNI_CONSTANT(java::lang::String, ACTION_CREATE_DOCUMENT)
JNI_CONSTANT(jint, FLAG_GRANT_READ_URI_PERMISSION)
......
......@@ -18,8 +18,8 @@
JNI_TYPE(org, kde, itinerary, Activity)
/** Interface to the Java Activity class. */
class ItineraryActivity : org::kde::itinerary::Activity {
JNI_OBJECT(ItineraryActivity)
class ItineraryActivity {
JNI_OBJECT(ItineraryActivity, org::kde::itinerary::Activity)
public:
JNI_METHOD(void, checkCalendar)
JNI_METHOD(KAndroidExtras::Jni::Array<KAndroidExtras::java::lang::String>, attachmentsForIntent, KAndroidExtras::android::content::Intent)
......
......@@ -25,9 +25,9 @@ namespace KAndroidExtras {
* This does not only offer features beyond what QAndroidIntent, it also provides
* a putExtra() implementation that actually interoperates with system services.
*/
class KANDROIDEXTRAS_EXPORT Intent : android::content::Intent
class KANDROIDEXTRAS_EXPORT Intent
{
JNI_OBJECT(Intent)
JNI_OBJECT(Intent, android::content::Intent)
public:
/** Creates a new empty intent. */
Intent();
......
......@@ -17,9 +17,9 @@ namespace KAndroidExtras {
* Access to manifest permissions.
* @see https://developer.android.com/reference/android/Manifest.permission
*/
class ManifestPermission : android::Manifest_permission
class ManifestPermission
{
JNI_OBJECT(ManifestPermission)
JNI_OBJECT(ManifestPermission, android::Manifest_permission)
public:
JNI_CONSTANT(java::lang::String, READ_CALENDAR)
JNI_CONSTANT(java::lang::String, READ_EXTERNAL_STORAGE)
......
......@@ -17,9 +17,9 @@ namespace KAndroidExtras {
* Constants for ContentResolver queries.
* @see https://developer.android.com/reference/android/provider/OpenableColumns
*/
class OpenableColumns : android::provider::OpenableColumns
class OpenableColumns
{
JNI_OBJECT(OpenableColumns)
JNI_OBJECT(OpenableColumns, android::provider::OpenableColumns)
public:
JNI_CONSTANT(java::lang::String, DISPLAY_NAME)
JNI_CONSTANT(java::lang::String, SIZE)
......@@ -28,4 +28,3 @@ public:
}
#endif // KANDROIDEXTRAS_OPENABLECOLUMNS_H
......@@ -13,9 +13,9 @@
namespace KAndroidExtras {
/** Methods around android.provider.Settings. */
class Settings : android::provider::Settings
class Settings
{
JNI_OBJECT(Settings)
JNI_OBJECT(Settings, android::provider::Settings)
JNI_CONSTANT(java::lang::String, ACTION_APP_NOTIFICATION_SETTINGS)
JNI_CONSTANT(java::lang::String, ACTION_CHANNEL_NOTIFICATION_SETTINGS)
JNI_CONSTANT(java::lang::String, EXTRA_APP_PACKAGE)
......
......@@ -16,6 +16,22 @@ template <typename T> struct Array {};
}
/** Annotates a class for holding JNI method or property wrappers.
*
* For using non-static methods or properties, this class also has to provide a
* @p handle() method returning a @c QAndroidJniObject representing the current
* instance.
*
* @param Class the name of the class this is added to.
* @param BaseType the Java type this class represents, defined by the
* @c JNI_TYPE or @c JNI_NESTED_TYPE macros.
*/
#define JNI_OBJECT(Class, BaseType) \
private: \
typedef Class _jni_ThisType; \
static inline constexpr const char *jniName() { return KAndroidExtras::Jni::typeName<BaseType>(); } \
friend constexpr const char* KAndroidExtras::Jni::typeName<Class>();
}
#endif
......@@ -7,6 +7,7 @@
#ifndef KANDROIDEXTRAS_JNIPROPERTIES_H
#define KANDROIDEXTRAS_JNIPROPERTIES_H
#include "jnicommon.h"
#include "jnisignature.h"
#include "jnitypes.h"
#include "jnitypetraits.h"
......@@ -17,20 +18,6 @@
namespace KAndroidExtras {
/** Annotates a class for holding JNI property wrappers.
* This class has to provide a jniName() method, which is usually achieved by inheriting from
* a type defined by the @c JNI_TYPE or @c JNI_NESTED_TYPE macros.
* For using non-static properties, this class also has to provide a @p handle() method returning
* a @c QAndroidJniObject representing the current instance.
*
* @param Class the name of the class this is added to.
*/
#define JNI_OBJECT(Class) \
private: \
typedef Class _jni_ThisType; \
friend const char* KAndroidExtras::Jni::typeName<Class>();
/** @cond internal */
namespace Internal {
......
......@@ -66,7 +66,7 @@ namespace KAndroidExtras {
namespace Jni
{
/** Returns the JNI type name of the given template argument. */
template <typename T> inline const char* typeName() { return T::jniName(); }
template <typename T> inline constexpr const char* typeName() { return T::jniName(); }
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment