Commit d32d5a03 authored by Volker Krause's avatar Volker Krause

Port JNI code to the new compile-time signature methods

parent e4ee30cb
......@@ -17,6 +17,8 @@
#include "activity.h"
#include "intent.h"
#include "jnisignature.h"
#include "jnitypes.h"
#include <QtAndroid>
......@@ -28,6 +30,6 @@ Intent Activity::getIntent()
if (!activity.isValid())
return {};
const auto intent = activity.callObjectMethod("getIntent", "()Landroid/content/Intent;");
const auto intent = activity.callObjectMethod("getIntent", Jni::signature<android::content::Intent()>());
return Intent(intent);
}
......@@ -17,6 +17,8 @@
#include "contentresolver.h"
#include "uri.h"
#include "jnisignature.h"
#include "jnitypes.h"
#include <QtAndroid>
#include <QAndroidJniObject>
......@@ -28,14 +30,14 @@ using namespace KAndroidExtras;
QAndroidJniObject ContentResolver::get()
{
return QtAndroid::androidContext().callObjectMethod("getContentResolver", "()Landroid/content/ContentResolver;");
return QtAndroid::androidContext().callObjectMethod("getContentResolver", Jni::signature<android::content::ContentResolver()>());
}
QString ContentResolver::mimeType(const QUrl &url)
{
auto cs = ContentResolver::get();
const auto uri = Uri::fromUrl(url);
auto mt = cs.callObjectMethod("getType", "(Landroid/net/Uri;)Ljava/lang/String;", uri.object<jobject>());
auto mt = cs.callObjectMethod("getType", Jni::signature<java::lang::String(android::net::Uri)>(), uri.object<jobject>());
return mt.toString();
}
......@@ -45,10 +47,10 @@ QString ContentResolver::fileName(const QUrl &url)
const auto uri = Uri::fromUrl(url);
// query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
auto cursor = cs.callObjectMethod("query", "(Landroid/net/Uri;[Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;Ljava/lang/String;)Landroid/database/Cursor;", uri.object<jobject>(), 0, 0, 0, 0);
auto cursor = cs.callObjectMethod("query", Jni::signature<android::database::Cursor(android::net::Uri, java::lang::String[], java::lang::String, java::lang::String[], java::lang::String)>(), uri.object<jobject>(), 0, 0, 0, 0);
const auto DISPLAY_NAME = QAndroidJniObject::getStaticObjectField<jstring>("android/provider/OpenableColumns", "DISPLAY_NAME");
const auto nameIndex = cursor.callMethod<jint>("getColumnIndex", "(Ljava/lang/String;)I", DISPLAY_NAME.object<jobject>());
cursor.callMethod<jboolean>("moveToFirst", "()Z");
return cursor.callObjectMethod("getString", "(I)Ljava/lang/String;", nameIndex).toString();
const auto DISPLAY_NAME = QAndroidJniObject::getStaticObjectField<jstring>(Jni::typeName<android::provider::OpenableColumns>(), "DISPLAY_NAME");
const auto nameIndex = cursor.callMethod<jint>("getColumnIndex", Jni::signature<int(java::lang::String)>(), DISPLAY_NAME.object<jobject>());
cursor.callMethod<jboolean>("moveToFirst", Jni::signature<bool()>());
return cursor.callObjectMethod("getString", Jni::signature<java::lang::String(int)>(), nameIndex).toString();
}
......@@ -17,6 +17,8 @@
#include "intent.h"
#include "uri.h"
#include "jnitypes.h"
#include "jnisignature.h"
#include <QAndroidJniObject>
#include <QUrl>
......@@ -25,7 +27,7 @@ using namespace KAndroidExtras;
Intent::Intent()
{
m_intent = QAndroidJniObject("android/content/Intent");
m_intent = QAndroidJniObject(Jni::typeName<android::content::Intent>());
}
Intent::Intent(const QAndroidJniObject &intent)
......@@ -37,7 +39,7 @@ Intent::~Intent() = default;
void Intent::addCategory(const QAndroidJniObject &category)
{
m_intent.callObjectMethod("addCategory", "(Ljava/lang/String;)Landroid/content/Intent;", category.object());
m_intent.callObjectMethod("addCategory", Jni::signature<android::content::Intent(java::lang::String)>(), category.object());
}
QUrl Intent::getData() const
......@@ -45,18 +47,24 @@ QUrl Intent::getData() const
if (!m_intent.isValid()) {
return {};
}
const auto uri = m_intent.callObjectMethod("getData", "()Landroid/net/Uri;");
const auto uri = m_intent.callObjectMethod("getData", Jni::signature<android::net::Uri()>());
return Uri::toUrl(uri);
}
void Intent::setAction(const QAndroidJniObject &action)
{
m_intent.callObjectMethod("setAction", "(Ljava/lang/String;)Landroid/content/Intent;", action.object());
m_intent.callObjectMethod("setAction", Jni::signature<android::content::Intent(java::lang::String)>(), action.object());
}
void Intent::setData(const QUrl& url)
{
const auto uri = Uri::fromUrl(url);
m_intent.callObjectMethod("setData", Jni::signature<android::content::Intent(android::net::Uri)>(), uri.object());
}
void Intent::setType(const QString &type)
{
m_intent.callObjectMethod("setType", "(Ljava/lang/String;)Landroid/content/Intent;", QAndroidJniObject::fromString(type).object());
m_intent.callObjectMethod("setType", Jni::signature<android::content::Intent(java::lang::String)>(), QAndroidJniObject::fromString(type).object());
}
Intent::operator QAndroidJniObject() const
......@@ -66,20 +74,20 @@ Intent::operator QAndroidJniObject() const
QAndroidJniObject Intent::ACTION_CREATE_DOCUMENT()
{
return QAndroidJniObject::getStaticObjectField<jstring>("android/content/Intent", "ACTION_CREATE_DOCUMENT");
return QAndroidJniObject::getStaticObjectField<jstring>(Jni::typeName<android::content::Intent>(), "ACTION_CREATE_DOCUMENT");
}
QAndroidJniObject Intent::ACTION_OPEN_DOCUMENT()
{
return QAndroidJniObject::getStaticObjectField<jstring>("android/content/Intent", "ACTION_OPEN_DOCUMENT");
return QAndroidJniObject::getStaticObjectField<jstring>(Jni::typeName<android::content::Intent>(), "ACTION_OPEN_DOCUMENT");
}
QAndroidJniObject Intent::ACTION_VIEW()
{
return QAndroidJniObject::getStaticObjectField<jstring>("android/content/Intent", "ACTION_VIEW");
return QAndroidJniObject::getStaticObjectField<jstring>(Jni::typeName<android::content::Intent>(), "ACTION_VIEW");
}
QAndroidJniObject Intent::CATEGORY_OPENABLE()
{
return QAndroidJniObject::getStaticObjectField<jstring>("android/content/Intent", "CATEGORY_OPENABLE");
return QAndroidJniObject::getStaticObjectField<jstring>(Jni::typeName<android::content::Intent>(), "CATEGORY_OPENABLE");
}
......@@ -40,6 +40,8 @@ public:
QUrl getData() const;
/** Sets the action of the intent. */
void setAction(const QAndroidJniObject &action);
/** Set the data URL of this intent. */
void setData(const QUrl &url);
/** Set the mime type for this intent. */
void setType(const QString &type);
......
......@@ -16,6 +16,8 @@
*/
#include "uri.h"
#include "jnisignature.h"
#include "jnitypes.h"
#include <QAndroidJniObject>
#include <QUrl>
......@@ -24,7 +26,7 @@ using namespace KAndroidExtras;
QAndroidJniObject Uri::fromUrl(const QUrl &url)
{
return QAndroidJniObject::callStaticObjectMethod("android/net/Uri", "parse", "(Ljava/lang/String;)Landroid/net/Uri;",
return QAndroidJniObject::callStaticObjectMethod(Jni::typeName<android::net::Uri>(), "parse", Jni::signature<android::net::Uri(java::lang::String)>(),
QAndroidJniObject::fromString(url.toString()).object<jstring>());
}
......@@ -33,5 +35,5 @@ QUrl Uri::toUrl(const QAndroidJniObject &uri)
if (!uri.isValid()) {
return QUrl();
}
return QUrl(uri.callObjectMethod("toString", "()Ljava/lang/String;").toString());
return QUrl(uri.callObjectMethod("toString", Jni::signature<java::lang::String()>()).toString());
}
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