File indexing completed on 2024-05-12 03:57:05

0001 /*
0002  *  SPDX-FileCopyrightText: 2017 Marco Martin <mart@kde.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifdef Q_OS_ANDROID
0008 #include <QGuiApplication>
0009 #else
0010 #include <QApplication>
0011 #endif
0012 
0013 #include <QColor>
0014 #include <QQmlApplicationEngine>
0015 #include <QUrl>
0016 
0017 #ifdef Q_OS_ANDROID
0018 #include <QtAndroid>
0019 
0020 // WindowManager.LayoutParams
0021 #define FLAG_TRANSLUCENT_STATUS 0x04000000
0022 #define FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS 0x80000000
0023 // View
0024 #define SYSTEM_UI_FLAG_LIGHT_STATUS_BAR 0x00002000
0025 
0026 #endif
0027 
0028 Q_IMPORT_PLUGIN(KirigamiPlugin)
0029 
0030 Q_DECL_EXPORT int main(int argc, char *argv[])
0031 {
0032 // The desktop QQC2 style needs it to be a QApplication
0033 #ifdef Q_OS_ANDROID
0034     QGuiApplication app(argc, argv);
0035 #else
0036     QApplication app(argc, argv);
0037 #endif
0038 
0039     // qputenv("QML_IMPORT_TRACE", "1");
0040 
0041     QQmlApplicationEngine engine;
0042 
0043     engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
0044 
0045     if (engine.rootObjects().isEmpty()) {
0046         return -1;
0047     }
0048 
0049     // HACK to color the system bar on Android, use qtandroidextras and call the appropriate Java methods
0050 #ifdef Q_OS_ANDROID
0051     QtAndroid::runOnAndroidThread([=]() {
0052         QAndroidJniObject window = QtAndroid::androidActivity().callObjectMethod("getWindow", "()Landroid/view/Window;");
0053         window.callMethod<void>("addFlags", "(I)V", FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
0054         window.callMethod<void>("clearFlags", "(I)V", FLAG_TRANSLUCENT_STATUS);
0055         window.callMethod<void>("setStatusBarColor", "(I)V", QColor("#2196f3").rgba());
0056         window.callMethod<void>("setNavigationBarColor", "(I)V", QColor("#2196f3").rgba());
0057     });
0058 #endif
0059 
0060     return app.exec();
0061 }