Changeset 57e3652 in subsurface


Ignore:
Timestamp:
Jun 23, 2017, 8:42:45 AM (4 months ago)
Author:
Dirk Hohndel <dirk@…>
Branches:
master
Children:
3f055ac
Parents:
b109b51
git-author:
Dirk Hohndel <dirk@…> (06/23/17 07:31:44)
git-committer:
Dirk Hohndel <dirk@…> (06/23/17 08:42:45)
Message:

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@…>

Location:
mobile-widgets
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • mobile-widgets/qml/main.qml

    re0f46b03 r57e3652  
    337337                subsurfaceTheme.backgroundColor = "#eff0f1"
    338338                subsurfaceTheme.diveListTextColor = subsurfaceTheme.lightPrimaryTextColor
     339                manager.setStatusbarColor(subsurfaceTheme.darkPrimaryColor)
    339340        }
    340341
     
    348349                subsurfaceTheme.backgroundColor = "#eff0f1"
    349350                subsurfaceTheme.diveListTextColor = subsurfaceTheme.lightPrimaryTextColor
     351                manager.setStatusbarColor(subsurfaceTheme.darkPrimaryColor)
    350352        }
    351353
     
    359361                subsurfaceTheme.backgroundColor = "#000000"
    360362                subsurfaceTheme.diveListTextColor = subsurfaceTheme.primaryTextColor
     363                manager.setStatusbarColor(subsurfaceTheme.darkPrimaryColor)
    361364        }
    362365
     
    384387                        Kirigami.Theme.backgroundColor = Qt.binding(function() { return backgroundColor })
    385388                        Kirigami.Theme.textColor = Qt.binding(function() { return diveListTextColor })
     389                        manager.setStatusbarColor(darkPrimaryColor)
    386390                }
    387391        }
  • mobile-widgets/qmlmanager.cpp

    r2b01ab7 r57e3652  
    14911491        emit showPinChanged();
    14921492}
     1493
     1494#if defined (Q_OS_ANDROID)
     1495
     1496
     1497//HACK to color the system bar on Android, use qtandroidextras and call the appropriate Java methods
     1498//this code is based on code in the Kirigami example app for Android (under LGPL-2) Copyright 2017 Marco Martin
     1499
     1500#include <QtAndroid>
     1501
     1502// there doesn't appear to be an include that defines these in an easily accessible way
     1503// WindowManager.LayoutParams
     1504#define FLAG_TRANSLUCENT_STATUS 0x04000000
     1505#define FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS 0x80000000
     1506// View
     1507#define SYSTEM_UI_FLAG_LIGHT_STATUS_BAR 0x00002000
     1508
     1509void QMLManager::setStatusbarColor(QColor color)
     1510{
     1511        QtAndroid::runOnAndroidThread([=]() {
     1512                QAndroidJniObject window = QtAndroid::androidActivity().callObjectMethod("getWindow", "()Landroid/view/Window;");
     1513                window.callMethod<void>("addFlags", "(I)V", FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
     1514                window.callMethod<void>("clearFlags", "(I)V", FLAG_TRANSLUCENT_STATUS);
     1515                window.callMethod<void>("setStatusBarColor", "(I)V", color.rgba());
     1516                window.callMethod<void>("setNavigationBarColor", "(I)V", color.rgba());
     1517        });
     1518}
     1519#else
     1520void QMLManager::setStatusbarColor(QColor color)
     1521{
     1522        // noop
     1523}
     1524
     1525#endif
  • mobile-widgets/qmlmanager.h

    rb2b51c8 r57e3652  
    88#include <QScreen>
    99#include <QElapsedTimer>
     10#include <QColor>
    1011
    1112#include "core/btdiscovery.h"
     
    116117        bool showPin() const;
    117118        void setShowPin(bool enable);
     119        Q_INVOKABLE void setStatusbarColor(QColor color);
    118120
    119121public slots:
Note: See TracChangeset for help on using the changeset viewer.