Handle the iPhone notch better

pull/240/head
Michael Zanetti 2019-09-11 17:39:49 +02:00
parent 3a2b90f60c
commit d814404698
9 changed files with 88 additions and 6 deletions

View File

@ -29,3 +29,29 @@ void PlatformHelper::setScreenBrightness(int percent)
{
Q_UNUSED(percent)
}
QColor PlatformHelper::topPanelColor() const
{
return m_topPanelColor;
}
void PlatformHelper::setTopPanelColor(const QColor &color)
{
if (m_topPanelColor != color) {
m_topPanelColor = color;
emit topPanelColorChanged();
}
}
QColor PlatformHelper::bottomPanelColor() const
{
return m_bottomPanelColor;
}
void PlatformHelper::setBottomPanelColor(const QColor &color)
{
if (m_bottomPanelColor != color) {
m_bottomPanelColor = color;
emit bottomPanelColorChanged();
}
}

View File

@ -2,6 +2,7 @@
#define PLATFORMHELPER_H
#include <QObject>
#include <QColor>
class PlatformHelper : public QObject
{
@ -15,6 +16,8 @@ class PlatformHelper : public QObject
Q_PROPERTY(bool canControlScreen READ canControlScreen CONSTANT)
Q_PROPERTY(int screenTimeout READ screenTimeout WRITE setScreenTimeout NOTIFY screenTimeoutChanged)
Q_PROPERTY(int screenBrightness READ screenBrightness WRITE setScreenBrightness NOTIFY screenBrightnessChanged)
Q_PROPERTY(QColor topPanelColor READ topPanelColor WRITE setTopPanelColor NOTIFY topPanelColorChanged)
Q_PROPERTY(QColor bottomPanelColor READ bottomPanelColor WRITE setBottomPanelColor NOTIFY bottomPanelColorChanged)
public:
enum HapticsFeedback {
@ -44,6 +47,11 @@ public:
virtual int screenBrightness() const;
virtual void setScreenBrightness(int percent);
virtual QColor topPanelColor() const;
virtual void setTopPanelColor(const QColor &color);
virtual QColor bottomPanelColor() const;
virtual void setBottomPanelColor(const QColor &color);
Q_INVOKABLE virtual void vibrate(HapticsFeedback feedbackType) = 0;
@ -51,6 +59,12 @@ signals:
void permissionsRequestFinished();
void screenTimeoutChanged();
void screenBrightnessChanged();
void topPanelColorChanged();
void bottomPanelColorChanged();
private:
QColor m_topPanelColor = QColor("black");
QColor m_bottomPanelColor = QColor("black");
};
#endif // PLATFORMHELPER_H

View File

@ -2,6 +2,7 @@
#include <QDebug>
#include <QUuid>
PlatformHelperIOS::PlatformHelperIOS(QObject *parent) : PlatformHelper(parent)
{
@ -73,3 +74,15 @@ void PlatformHelperIOS::vibrate(PlatformHelper::HapticsFeedback feedbackType)
}
}
void PlatformHelperIOS::setTopPanelColor(const QColor &color)
{
PlatformHelper::setTopPanelColor(color);
setTopPanelColorInternal(color);
}
void PlatformHelperIOS::setBottomPanelColor(const QColor &color)
{
PlatformHelper::setBottomPanelColor(color);
setBottomPanelColorInternal(color);
}

View File

@ -24,11 +24,17 @@ public:
Q_INVOKABLE virtual void vibrate(HapticsFeedback feedbackType) override;
void setTopPanelColor(const QColor &color) override;
void setBottomPanelColor(const QColor &color) override;
private:
// defined in platformhelperios.mm
QString readKeyChainEntry(const QString &service, const QString &key);
void writeKeyChainEntry(const QString &service, const QString &key, const QString &value);
void setTopPanelColorInternal(const QColor &color);
void setBottomPanelColorInternal(const QColor &color);
void generateSelectionFeedback();
void generateImpactFeedback();
void generateNotificationFeedback();

View File

@ -21,7 +21,7 @@ ApplicationWindow {
property string appName: "nymea:app"
// The header background color
property color primaryColor: Qt.darker("#50514f", 1.1)
property color primaryColor: "#494948"
// Header font color

View File

@ -187,8 +187,6 @@ Page {
SwipeView {
id: swipeView
anchors.fill: parent
anchors.leftMargin: (systemProductType === "ios" && Screen.width === 812) ? 25 : 0
anchors.rightMargin: anchors.leftMargin
currentIndex: root.currentViewIndex
onCurrentIndexChanged: {
@ -308,9 +306,7 @@ Page {
id: tabBar
Material.elevation: 3
position: TabBar.Footer
implicitHeight: 70 + (app.landscape ?
((systemProductType === "ios" && Screen.height === 375) ? -10 : -20) :
(systemProductType === "ios" && Screen.height === 812) ? 14 : 0)
implicitHeight: 70 + (app.landscape ? -20 : 0)
Component {
id: tabEntryComponent

View File

@ -14,6 +14,11 @@ Item {
Rectangle {
anchors.fill: parent
color: Material.background
Component.onCompleted: {
PlatformHelper.topPanelColor = app.primaryColor
PlatformHelper.bottomPanelColor = color
}
}
function handleAndroidBackButton() {

View File

@ -37,5 +37,7 @@
</array>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Nymea boxes can be connected to WiFi using a Bluetooth setup. Also, this app can connect to nymea boxes using Bluetooth only, without requiring WiFi at all.</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict>
</plist>

View File

@ -99,3 +99,23 @@ void PlatformHelperIOS::generateNotificationFeedback()
[generator notificationOccurred:UINotificationFeedbackTypeSuccess];
generator = nil;
}
void PlatformHelperIOS::setTopPanelColorInternal(const QColor &color)
{
UIView *statusBar = (UIView *)[[UIApplication sharedApplication] valueForKey:@"statusBar"];
statusBar.backgroundColor = [UIColor colorWithRed:color.redF() green:color.greenF() blue:color.blueF() alpha:color.alphaF()];
if (((color.red() * 299 + color.green() * 587 + color.blue() * 114) / 1000) > 123) {
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
} else {
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
}
}
void PlatformHelperIOS::setBottomPanelColorInternal(const QColor &color)
{
//Bottom
UIApplication *app = [UIApplication sharedApplication];
app.windows.firstObject.backgroundColor = [UIColor colorWithRed:color.redF() green:color.greenF() blue:color.blueF() alpha:color.alphaF()];
}