Commit 685fca95 authored by Dennis Nienhüser's avatar Dennis Nienhüser

Keep the screen on in navigation mode

parent 93a625b5
......@@ -93,6 +93,7 @@ ApplicationWindow {
showScaleBar: false
showBackground: false
positionProvider: suspended ? "" : currentPositionProvider
keepScreenOn: !suspended && itemStack.state === "navigation"
showPositionMarker: false
placemarkDelegate: Image {
......
......@@ -17,13 +17,15 @@
#ifdef Q_OS_ANDROID
#include <QtAndroid>
#include <QAndroidJniObject>
#include <qandroidfunctions.h>
#endif
namespace Marble {
MarbleMaps::MarbleMaps(QQuickItem *parent) :
MarbleQuickItem(parent),
m_suspended(false)
m_suspended(false),
m_keepScreenOn(false)
{
QGuiApplication* application = qobject_cast<QGuiApplication*>(QGuiApplication::instance());
if (application) {
......@@ -55,6 +57,38 @@ bool MarbleMaps::isSuspended() const
return m_suspended;
}
bool MarbleMaps::keepScreenOn() const
{
return m_keepScreenOn;
}
void MarbleMaps::setKeepScreenOn(bool screenOn)
{
if (m_keepScreenOn == screenOn) {
return;
}
m_keepScreenOn = screenOn;
char const * const action = m_keepScreenOn ? "addFlags" : "clearFlags";
#ifdef Q_OS_ANDROID
#if QT_VERSION >= 0x050700
QtAndroid::runOnAndroidThread([action](){
QAndroidJniObject activity = QtAndroid::androidActivity();
if (activity.isValid()) {
QAndroidJniObject window = activity.callObjectMethod("getWindow", "()Landroid/view/Window;");
if (window.isValid()) {
const int FLAG_KEEP_SCREEN_ON = 128;
window.callObjectMethod(action, "(I)V", FLAG_KEEP_SCREEN_ON);
}
}});
#else
#warning "Please upgrade to Qt for Android 5.7 or later to enable the keep-screen-on feature"
#endif
#else
Q_UNUSED(action);
#endif
emit keepScreenOnChanged(screenOn);
}
void MarbleMaps::handleApplicationStateChange(Qt::ApplicationState state)
{
if (state == Qt::ApplicationSuspended) {
......
......@@ -20,21 +20,29 @@ class MarbleMaps : public MarbleQuickItem
Q_OBJECT
Q_PROPERTY( bool suspended READ isSuspended NOTIFY isSuspendedChanged )
Q_PROPERTY(bool keepScreenOn READ keepScreenOn WRITE setKeepScreenOn NOTIFY keepScreenOnChanged)
public:
explicit MarbleMaps(QQuickItem *parent = 0);
bool isSuspended() const;
bool keepScreenOn() const;
public Q_SLOTS:
void setKeepScreenOn(bool keepScreenOn);
Q_SIGNALS:
void isSuspendedChanged(bool isSuspended);
void keepScreenOnChanged(bool keepScreenOn);
private Q_SLOTS:
void handleApplicationStateChange(Qt::ApplicationState state);
private:
bool m_suspended;
bool m_keepScreenOn;
};
}
......
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