Reformat android.h/android.cpp
This commit is contained in:
parent
b4750c38fe
commit
232936a15d
|
@ -5,11 +5,12 @@
|
||||||
|
|
||||||
#include <c++utilities/conversion/stringbuilder.h>
|
#include <c++utilities/conversion/stringbuilder.h>
|
||||||
|
|
||||||
#include <QtAndroid>
|
|
||||||
#include <QAndroidJniObject>
|
#include <QAndroidJniObject>
|
||||||
|
#include <QColor>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QMetaObject>
|
|
||||||
#include <QMessageLogContext>
|
#include <QMessageLogContext>
|
||||||
|
#include <QMetaObject>
|
||||||
|
#include <QtAndroid>
|
||||||
|
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
|
|
||||||
|
@ -56,53 +57,65 @@ bool showAndroidFileDialog(bool existing)
|
||||||
|
|
||||||
int openFileDescriptorFromAndroidContentUrl(const QString &url, const QString &mode)
|
int openFileDescriptorFromAndroidContentUrl(const QString &url, const QString &mode)
|
||||||
{
|
{
|
||||||
return QtAndroid::androidActivity().callMethod<jint>("openFileDescriptorFromAndroidContentUri", "(Ljava/lang/String;Ljava/lang/String;)I", QAndroidJniObject::fromString(url).object<jstring>(), QAndroidJniObject::fromString(mode).object<jstring>());
|
return QtAndroid::androidActivity().callMethod<jint>("openFileDescriptorFromAndroidContentUri", "(Ljava/lang/String;Ljava/lang/String;)I",
|
||||||
|
QAndroidJniObject::fromString(url).object<jstring>(), QAndroidJniObject::fromString(mode).object<jstring>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeToAndroidLog(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
|
void writeToAndroidLog(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||||
|
{
|
||||||
constexpr auto tag = PROJECT_NAME "-" APP_VERSION;
|
constexpr auto tag = PROJECT_NAME "-" APP_VERSION;
|
||||||
auto report = msg.toStdString();
|
auto report = msg.toStdString();
|
||||||
if (context.file && *context.file) {
|
if (context.file && *context.file) {
|
||||||
report += argsToString(" in file ", context.file, " line ", context.line);
|
report += argsToString(" in file ", context.file, " line ", context.line);
|
||||||
}
|
}
|
||||||
if (context.function && !QString(context.function).isEmpty()) {
|
if (context.function && !QString(context.function).isEmpty()) {
|
||||||
report += argsToString(" function ", context.function);
|
report += argsToString(" function ", context.function);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case QtDebugMsg:
|
case QtDebugMsg:
|
||||||
__android_log_write(ANDROID_LOG_DEBUG, tag, report.data());
|
__android_log_write(ANDROID_LOG_DEBUG, tag, report.data());
|
||||||
break;
|
break;
|
||||||
case QtInfoMsg:
|
case QtInfoMsg:
|
||||||
__android_log_write(ANDROID_LOG_INFO,tag,report.data());
|
__android_log_write(ANDROID_LOG_INFO, tag, report.data());
|
||||||
break;
|
break;
|
||||||
case QtWarningMsg:
|
case QtWarningMsg:
|
||||||
__android_log_write(ANDROID_LOG_WARN,tag,report.data());
|
__android_log_write(ANDROID_LOG_WARN, tag, report.data());
|
||||||
break;
|
break;
|
||||||
case QtCriticalMsg:
|
case QtCriticalMsg:
|
||||||
__android_log_write(ANDROID_LOG_ERROR,tag,report.data());
|
__android_log_write(ANDROID_LOG_ERROR, tag, report.data());
|
||||||
break;
|
break;
|
||||||
case QtFatalMsg:
|
case QtFatalMsg:
|
||||||
__android_log_write(ANDROID_LOG_FATAL,tag,report.data());
|
__android_log_write(ANDROID_LOG_FATAL, tag, report.data());
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setupAndroidSpecifics()
|
||||||
|
{
|
||||||
|
qInstallMessageHandler(writeToAndroidLog);
|
||||||
|
applyThemingForAndroid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace QtGui
|
||||||
|
|
||||||
static void onAndroidError(JNIEnv *, jobject, jstring message)
|
static void onAndroidError(JNIEnv *, jobject, jstring message)
|
||||||
{
|
{
|
||||||
QMetaObject::invokeMethod(QtGui::controllerForAndroid, "newNotification", Qt::QueuedConnection, Q_ARG(QString, QAndroidJniObject::fromLocalRef(message).toString()));
|
QMetaObject::invokeMethod(
|
||||||
|
QtGui::controllerForAndroid, "newNotification", Qt::QueuedConnection, Q_ARG(QString, QAndroidJniObject::fromLocalRef(message).toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onAndroidFileDialogAccepted(JNIEnv *, jobject, jstring fileName, jboolean existing)
|
static void onAndroidFileDialogAccepted(JNIEnv *, jobject, jstring fileName, jboolean existing)
|
||||||
{
|
{
|
||||||
QMetaObject::invokeMethod(QtGui::controllerForAndroid, "handleFileSelectionAccepted", Qt::QueuedConnection, Q_ARG(QString, QAndroidJniObject::fromLocalRef(fileName).toString()), Q_ARG(bool, existing));
|
QMetaObject::invokeMethod(QtGui::controllerForAndroid, "handleFileSelectionAccepted", Qt::QueuedConnection,
|
||||||
|
Q_ARG(QString, QAndroidJniObject::fromLocalRef(fileName).toString()), Q_ARG(bool, existing));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onAndroidFileDialogAcceptedDescriptor(JNIEnv *, jobject, jstring nativeUrl, jstring fileName, jint fileHandle, jboolean existing)
|
static void onAndroidFileDialogAcceptedDescriptor(JNIEnv *, jobject, jstring nativeUrl, jstring fileName, jint fileHandle, jboolean existing)
|
||||||
{
|
{
|
||||||
QMetaObject::invokeMethod(QtGui::controllerForAndroid, "handleFileSelectionAcceptedDescriptor", Qt::QueuedConnection, Q_ARG(QString, QAndroidJniObject::fromLocalRef(nativeUrl).toString()), Q_ARG(QString, QAndroidJniObject::fromLocalRef(fileName).toString()), Q_ARG(int, fileHandle), Q_ARG(bool, existing));
|
QMetaObject::invokeMethod(QtGui::controllerForAndroid, "handleFileSelectionAcceptedDescriptor", Qt::QueuedConnection,
|
||||||
|
Q_ARG(QString, QAndroidJniObject::fromLocalRef(nativeUrl).toString()), Q_ARG(QString, QAndroidJniObject::fromLocalRef(fileName).toString()),
|
||||||
|
Q_ARG(int, fileHandle), Q_ARG(bool, existing));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void onAndroidFileDialogRejected(JNIEnv *, jobject)
|
static void onAndroidFileDialogRejected(JNIEnv *, jobject)
|
||||||
|
@ -118,7 +131,7 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *)
|
||||||
{
|
{
|
||||||
// get the JNIEnv pointer
|
// get the JNIEnv pointer
|
||||||
JNIEnv *env;
|
JNIEnv *env;
|
||||||
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
|
if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK) {
|
||||||
return JNI_ERR;
|
return JNI_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,10 +143,11 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *)
|
||||||
|
|
||||||
// register native methods
|
// register native methods
|
||||||
static const JNINativeMethod methods[] = {
|
static const JNINativeMethod methods[] = {
|
||||||
{"onAndroidError", "(Ljava/lang/String;)V", reinterpret_cast<void *>(onAndroidError)},
|
{ "onAndroidError", "(Ljava/lang/String;)V", reinterpret_cast<void *>(onAndroidError) },
|
||||||
{"onAndroidFileDialogAccepted", "(Ljava/lang/String;Z)V", reinterpret_cast<void *>(onAndroidFileDialogAccepted)},
|
{ "onAndroidFileDialogAccepted", "(Ljava/lang/String;Z)V", reinterpret_cast<void *>(onAndroidFileDialogAccepted) },
|
||||||
{"onAndroidFileDialogAcceptedDescriptor", "(Ljava/lang/String;Ljava/lang/String;IZ)V", reinterpret_cast<void *>(onAndroidFileDialogAcceptedDescriptor)},
|
{ "onAndroidFileDialogAcceptedDescriptor", "(Ljava/lang/String;Ljava/lang/String;IZ)V",
|
||||||
{"onAndroidFileDialogRejected", "()V", reinterpret_cast<void *>(onAndroidFileDialogRejected)},
|
reinterpret_cast<void *>(onAndroidFileDialogAcceptedDescriptor) },
|
||||||
|
{ "onAndroidFileDialogRejected", "()V", reinterpret_cast<void *>(onAndroidFileDialogRejected) },
|
||||||
};
|
};
|
||||||
if (env->RegisterNatives(javaClass, methods, sizeof(methods) / sizeof(methods[0])) < 0) {
|
if (env->RegisterNatives(javaClass, methods, sizeof(methods) / sizeof(methods[0])) < 0) {
|
||||||
return JNI_ERR;
|
return JNI_ERR;
|
||||||
|
|
|
@ -3,10 +3,8 @@
|
||||||
|
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_FORWARD_DECLARE_CLASS(QMessageLogContext)
|
||||||
class QMessageLogContext;
|
QT_FORWARD_DECLARE_CLASS(QString)
|
||||||
class QString;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace QtGui {
|
namespace QtGui {
|
||||||
|
|
||||||
|
@ -18,7 +16,6 @@ bool showAndroidFileDialog(bool existing);
|
||||||
int openFileDescriptorFromAndroidContentUrl(const QString &url, const QString &mode);
|
int openFileDescriptorFromAndroidContentUrl(const QString &url, const QString &mode);
|
||||||
void writeToAndroidLog(QtMsgType type, const QMessageLogContext &context, const QString &msg);
|
void writeToAndroidLog(QtMsgType type, const QMessageLogContext &context, const QString &msg);
|
||||||
void setupAndroidSpecifics();
|
void setupAndroidSpecifics();
|
||||||
|
} // namespace QtGui
|
||||||
}
|
|
||||||
|
|
||||||
#endif // QT_QUICK_GUI_ANDROID_H
|
#endif // QT_QUICK_GUI_ANDROID_H
|
||||||
|
|
Loading…
Reference in New Issue