diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2017-06-23 07:31:44 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-06-23 08:42:45 -0700 |
commit | 57e365222b939668a54281f9edea34c7fdf3a152 (patch) | |
tree | 3f7fc5f8c2c2094e14a640fe467bb13711024162 /mobile-widgets/qmlmanager.cpp | |
parent | b109b51f7f1f764ef195726e9b676ef0c49d6add (diff) | |
download | subsurface-57e365222b939668a54281f9edea34c7fdf3a152.tar.gz |
QML UI: color the status bar on Android
This code is based on code from Marco Martin from the Kirigami Android
sample app. In order to simplify the QML code the QMLManager function is
there for all OSs, but it's a no-op on anything but Android.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'mobile-widgets/qmlmanager.cpp')
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index fef7e72ce..9c78b2eb0 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -1490,3 +1490,36 @@ void QMLManager::setShowPin(bool enable) m_showPin = enable; emit showPinChanged(); } + +#if defined (Q_OS_ANDROID) + + +//HACK to color the system bar on Android, use qtandroidextras and call the appropriate Java methods +//this code is based on code in the Kirigami example app for Android (under LGPL-2) Copyright 2017 Marco Martin + +#include <QtAndroid> + +// there doesn't appear to be an include that defines these in an easily accessible way +// WindowManager.LayoutParams +#define FLAG_TRANSLUCENT_STATUS 0x04000000 +#define FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS 0x80000000 +// View +#define SYSTEM_UI_FLAG_LIGHT_STATUS_BAR 0x00002000 + +void QMLManager::setStatusbarColor(QColor color) +{ + QtAndroid::runOnAndroidThread([=]() { + QAndroidJniObject window = QtAndroid::androidActivity().callObjectMethod("getWindow", "()Landroid/view/Window;"); + window.callMethod<void>("addFlags", "(I)V", FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + window.callMethod<void>("clearFlags", "(I)V", FLAG_TRANSLUCENT_STATUS); + window.callMethod<void>("setStatusBarColor", "(I)V", color.rgba()); + window.callMethod<void>("setNavigationBarColor", "(I)V", color.rgba()); + }); +} +#else +void QMLManager::setStatusbarColor(QColor color) +{ + // noop +} + +#endif |