mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
b109b51f7f
commit
57e365222b
3 changed files with 39 additions and 0 deletions
|
@ -336,6 +336,7 @@ Kirigami.ApplicationWindow {
|
||||||
subsurfaceTheme.lightPrimaryTextColor = "#212121"
|
subsurfaceTheme.lightPrimaryTextColor = "#212121"
|
||||||
subsurfaceTheme.backgroundColor = "#eff0f1"
|
subsurfaceTheme.backgroundColor = "#eff0f1"
|
||||||
subsurfaceTheme.diveListTextColor = subsurfaceTheme.lightPrimaryTextColor
|
subsurfaceTheme.diveListTextColor = subsurfaceTheme.lightPrimaryTextColor
|
||||||
|
manager.setStatusbarColor(subsurfaceTheme.darkPrimaryColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
function pinkTheme() {
|
function pinkTheme() {
|
||||||
|
@ -347,6 +348,7 @@ Kirigami.ApplicationWindow {
|
||||||
subsurfaceTheme.lightPrimaryTextColor = "#212121"
|
subsurfaceTheme.lightPrimaryTextColor = "#212121"
|
||||||
subsurfaceTheme.backgroundColor = "#eff0f1"
|
subsurfaceTheme.backgroundColor = "#eff0f1"
|
||||||
subsurfaceTheme.diveListTextColor = subsurfaceTheme.lightPrimaryTextColor
|
subsurfaceTheme.diveListTextColor = subsurfaceTheme.lightPrimaryTextColor
|
||||||
|
manager.setStatusbarColor(subsurfaceTheme.darkPrimaryColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
function darkTheme() {
|
function darkTheme() {
|
||||||
|
@ -358,6 +360,7 @@ Kirigami.ApplicationWindow {
|
||||||
subsurfaceTheme.lightPrimaryTextColor = "#212121"
|
subsurfaceTheme.lightPrimaryTextColor = "#212121"
|
||||||
subsurfaceTheme.backgroundColor = "#000000"
|
subsurfaceTheme.backgroundColor = "#000000"
|
||||||
subsurfaceTheme.diveListTextColor = subsurfaceTheme.primaryTextColor
|
subsurfaceTheme.diveListTextColor = subsurfaceTheme.primaryTextColor
|
||||||
|
manager.setStatusbarColor(subsurfaceTheme.darkPrimaryColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
QtObject {
|
QtObject {
|
||||||
|
@ -383,6 +386,7 @@ Kirigami.ApplicationWindow {
|
||||||
Kirigami.Theme.highlighedTextColor = Qt.binding(function() { return darkPrimaryTextColor })
|
Kirigami.Theme.highlighedTextColor = Qt.binding(function() { return darkPrimaryTextColor })
|
||||||
Kirigami.Theme.backgroundColor = Qt.binding(function() { return backgroundColor })
|
Kirigami.Theme.backgroundColor = Qt.binding(function() { return backgroundColor })
|
||||||
Kirigami.Theme.textColor = Qt.binding(function() { return diveListTextColor })
|
Kirigami.Theme.textColor = Qt.binding(function() { return diveListTextColor })
|
||||||
|
manager.setStatusbarColor(darkPrimaryColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
property Item stackView: pageStack
|
property Item stackView: pageStack
|
||||||
|
|
|
@ -1490,3 +1490,36 @@ void QMLManager::setShowPin(bool enable)
|
||||||
m_showPin = enable;
|
m_showPin = enable;
|
||||||
emit showPinChanged();
|
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
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
|
#include <QColor>
|
||||||
|
|
||||||
#include "core/btdiscovery.h"
|
#include "core/btdiscovery.h"
|
||||||
#include "core/gpslocation.h"
|
#include "core/gpslocation.h"
|
||||||
|
@ -115,6 +116,7 @@ public:
|
||||||
QStringList cylinderInit() const;
|
QStringList cylinderInit() const;
|
||||||
bool showPin() const;
|
bool showPin() const;
|
||||||
void setShowPin(bool enable);
|
void setShowPin(bool enable);
|
||||||
|
Q_INVOKABLE void setStatusbarColor(QColor color);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void applicationStateChanged(Qt::ApplicationState state);
|
void applicationStateChanged(Qt::ApplicationState state);
|
||||||
|
|
Loading…
Add table
Reference in a new issue