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

Use the JNI wrappers for interfacing with the Activity class

parent b3f720c4
/*
SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef ITINERARY_ACTIVITY_H
#define ITINERARY_ACTIVITY_H
#include <kandroidextras/jnitypes.h>
#include <kandroidextras/jnimethod.h>
#include <kandroidextras/jniproperty.h>
#include <kandroidextras/javatypes.h>
#include <kandroidextras/androidtypes.h>
#include <kandroidextras/uri.h>
#include <QtAndroid>
JNI_TYPE(org, kde, itinerary, Activity)
/** Interface to the Java Activity class. */
class ItineraryActivity : org::kde::itinerary::Activity {
JNI_OBJECT(ItineraryActivity)
public:
JNI_METHOD(void, checkCalendar)
JNI_METHOD(KAndroidExtras::Jni::Array<KAndroidExtras::java::lang::String>, attachmentsForIntent, KAndroidExtras::android::content::Intent)
JNI_METHOD(KAndroidExtras::android::net::Uri, openDocument, java::lang::String)
private:
inline QAndroidJniObject handle() const { return QtAndroid::androidActivity(); }
};
#endif
......@@ -56,6 +56,8 @@
#include <KMime/Types>
#ifdef Q_OS_ANDROID
#include "android/itineraryactivity.h"
#include <kandroidextras/activity.h>
#include <kandroidextras/contentresolver.h>
#include <kandroidextras/intent.h>
......@@ -118,7 +120,7 @@ Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void*)
qCWarning(Log) << "Failed to get JNI environment.";
return -1;
}
jclass cls = env->FindClass("org/kde/itinerary/Activity");
jclass cls = env->FindClass(KAndroidExtras::Jni::typeName<ItineraryActivity>());
if (env->RegisterNatives(cls, methods, sizeof(methods) / sizeof(JNINativeMethod)) < 0) {
qCWarning(Log) << "Failed to register native functions.";
return -1;
......@@ -225,7 +227,7 @@ void ApplicationController::importFromIntent(const KAndroidExtras::Intent &inten
const auto from = intent.getStringArrayExtra(Intent::EXTRA_EMAIL);
const auto text = intent.getStringExtra(Intent::EXTRA_TEXT);
qCInfo(Log) << action << type << subject << from << text;
const auto attachments = Jni::fromArray<QStringList>(QtAndroid::androidActivity().callObjectMethod("attachmentsForIntent", Jni::signature<Jni::Array<java::lang::String>(android::content::Intent)>(), static_cast<QAndroidJniObject>(intent).object()));
const QStringList attachments = ItineraryActivity().attachmentsForIntent(intent);
qCInfo(Log) << attachments;
KMime::Message msg;
......@@ -627,7 +629,7 @@ void ApplicationController::openDocument(const QUrl &url)
#ifdef Q_OS_ANDROID
using namespace KAndroidExtras;
auto activity = QtAndroid::androidActivity();
auto uri = activity.callObjectMethod("openDocument", Jni::signature<android::net::Uri(java::lang::String)>(), QAndroidJniObject::fromString(url.toLocalFile()).object());
auto uri = ItineraryActivity().openDocument(url.toLocalFile());
Intent intent;
intent.setData(uri);
......
......@@ -154,7 +154,6 @@ namespace Internal {
} else {
return Internal::call_return<RetT>::toReturnValue(handle.callObjectMethod(name, signature, toFinalCallArgument(std::get<Index>(params))...));
}
return {};
}
};
......
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