From 2508e4dd8a5f06e586b45096a5e07bbcdcccd1b1 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 2 Oct 2020 23:50:59 +0200 Subject: [PATCH] More work on NFC support --- androidservice/androidservice.pro | 2 + .../controlviews/devicecontrolapplication.cpp | 17 +- .../controlviews/devicecontrolapplication.h | 3 +- nymea-app/images.qrc | 1 + nymea-app/nymea-app.pro | 8 +- nymea-app/resources.qrc | 1 + nymea-app/ui/devicepages/DevicePageBase.qml | 6 +- nymea-app/ui/images/smartphone.svg | 166 +++++++++++++++ nymea-app/ui/magic/WriteNfcTagPage.qml | 197 ++++++++++++++++++ 9 files changed, 386 insertions(+), 15 deletions(-) create mode 100644 nymea-app/ui/images/smartphone.svg create mode 100644 nymea-app/ui/magic/WriteNfcTagPage.qml diff --git a/androidservice/androidservice.pro b/androidservice/androidservice.pro index 1b0cb54b..08ab083e 100644 --- a/androidservice/androidservice.pro +++ b/androidservice/androidservice.pro @@ -29,6 +29,7 @@ SOURCES += \ nymeaappservice/androidbinder.cpp \ ../nymea-app/stylecontroller.cpp \ ../nymea-app/platformhelper.cpp \ + ../nymea-app/nfchelper.cpp \ ../nymea-app/platformintegration/android/platformhelperandroid.cpp \ service_main.cpp @@ -38,6 +39,7 @@ HEADERS += \ nymeaappservice/androidbinder.h \ ../nymea-app/stylecontroller.h \ ../nymea-app/platformhelper.h \ + ../nymea-app/nfchelper.h \ ../nymea-app/platformintegration/android/platformhelperandroid.h \ DISTFILES += \ diff --git a/androidservice/controlviews/devicecontrolapplication.cpp b/androidservice/controlviews/devicecontrolapplication.cpp index 70a3e5f3..39a724a1 100644 --- a/androidservice/controlviews/devicecontrolapplication.cpp +++ b/androidservice/controlviews/devicecontrolapplication.cpp @@ -6,6 +6,7 @@ #include "libnymea-app-core.h" #include "../nymea-app/stylecontroller.h" #include "../nymea-app/platformhelper.h" +#include "../nymea-app/nfchelper.h" #include "../nymea-app/platformintegration/android/platformhelperandroid.h" #include @@ -54,20 +55,21 @@ DeviceControlApplication::DeviceControlApplication(int argc, char *argv[]) : QAp qDebug() << "Connecting to:" << host; qDebug() << "Creating QML view"; - QQmlApplicationEngine *qmlEngine = new QQmlApplicationEngine(this); + m_qmlEngine = new QQmlApplicationEngine(this); registerQmlTypes(); qmlRegisterSingletonType("Nymea", 1, 0, "PlatformHelper", platformHelperProvider); qmlRegisterSingletonType(QUrl("qrc:///ui/utils/NymeaUtils.qml"), "Nymea", 1, 0, "NymeaUtils" ); + qmlRegisterType("Nymea", 1, 0, "NfcHelper"); StyleController styleController; - qmlEngine->rootContext()->setContextProperty("styleController", &styleController); - qmlEngine->rootContext()->setContextProperty("engine", m_engine); - qmlEngine->rootContext()->setContextProperty("_engine", m_engine); - qmlEngine->rootContext()->setContextProperty("controlledThingId", thingId); + m_qmlEngine->rootContext()->setContextProperty("styleController", &styleController); + m_qmlEngine->rootContext()->setContextProperty("engine", m_engine); + m_qmlEngine->rootContext()->setContextProperty("_engine", m_engine); + m_qmlEngine->rootContext()->setContextProperty("controlledThingId", thingId); - qmlEngine->load(QUrl(QLatin1String("qrc:/Main.qml"))); + m_qmlEngine->load(QUrl(QLatin1String("qrc:/Main.qml"))); } void DeviceControlApplication::handleNdefMessage(QNdefMessage message, QNearFieldTarget *target) @@ -88,8 +90,7 @@ void DeviceControlApplication::handleNdefMessage(QNdefMessage message, QNearFiel NymeaHost *host = m_discovery->nymeaHosts()->find(nymeaId); m_engine->jsonRpcClient()->connectToHost(host); - qmlEngine->rootContext()->setContextProperty("controlledThingId", thingId); - + m_qmlEngine->rootContext()->setContextProperty("controlledThingId", thingId); } } diff --git a/androidservice/controlviews/devicecontrolapplication.h b/androidservice/controlviews/devicecontrolapplication.h index ef1fb332..aa557ee8 100644 --- a/androidservice/controlviews/devicecontrolapplication.h +++ b/androidservice/controlviews/devicecontrolapplication.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "connection/discovery/nymeadiscovery.h" #include "engine.h" @@ -22,7 +23,7 @@ private slots: private: NymeaDiscovery *m_discovery = nullptr; Engine *m_engine = nullptr; - + QQmlApplicationEngine *m_qmlEngine = nullptr; }; #endif // DEVICECONTROLAPPLICATION_H diff --git a/nymea-app/images.qrc b/nymea-app/images.qrc index 0e2c299e..dd6ab995 100644 --- a/nymea-app/images.qrc +++ b/nymea-app/images.qrc @@ -237,5 +237,6 @@ ui/images/connections/bluetooth.svg ui/images/connections/network-wired-disabled.svg ui/images/nfc.svg + ui/images/smartphone.svg diff --git a/nymea-app/nymea-app.pro b/nymea-app/nymea-app.pro index ffaedaa8..e847d96d 100644 --- a/nymea-app/nymea-app.pro +++ b/nymea-app/nymea-app.pro @@ -165,4 +165,10 @@ BR=$$BRANDING target.path = /usr/bin INSTALLS += target -ANDROID_ABIS = armeabi-v7a arm64-v8a +ANDROID_ABIS = armeabi-v7a + +contains(ANDROID_TARGET_ARCH,) { + ANDROID_ABIS = \ + armeabi-v7a \ + arm64-v8a +} diff --git a/nymea-app/resources.qrc b/nymea-app/resources.qrc index 8a09163c..3867539f 100644 --- a/nymea-app/resources.qrc +++ b/nymea-app/resources.qrc @@ -223,5 +223,6 @@ ui/components/BatteryStatusIcon.qml ui/components/SetupStatusIcon.qml ui/components/UpdateStatusIcon.qml + ui/magic/WriteNfcTagPage.qml diff --git a/nymea-app/ui/devicepages/DevicePageBase.qml b/nymea-app/ui/devicepages/DevicePageBase.qml index 794ffec1..2acfaa2b 100644 --- a/nymea-app/ui/devicepages/DevicePageBase.qml +++ b/nymea-app/ui/devicepages/DevicePageBase.qml @@ -146,12 +146,8 @@ Page { pageStack.push(Qt.resolvedUrl("DeviceLogPage.qml"), {device: root.device }); } - NfcHelper { - id: nfcHelper - } - function writeNfcTag() { - nfcHelper.writeThingStates(engine, root.thing) + pageStack.push(Qt.resolvedUrl("../magic/WriteNfcTagPage.qml"), {thing: root.thing}) } Component { diff --git a/nymea-app/ui/images/smartphone.svg b/nymea-app/ui/images/smartphone.svg new file mode 100644 index 00000000..1cf0b449 --- /dev/null +++ b/nymea-app/ui/images/smartphone.svg @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/nymea-app/ui/magic/WriteNfcTagPage.qml b/nymea-app/ui/magic/WriteNfcTagPage.qml new file mode 100644 index 00000000..d5cfe4a1 --- /dev/null +++ b/nymea-app/ui/magic/WriteNfcTagPage.qml @@ -0,0 +1,197 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +* +* Copyright 2013 - 2020, nymea GmbH +* Contact: contact@nymea.io +* +* This file is part of nymea. +* This project including source code and documentation is protected by +* copyright law, and remains the property of nymea GmbH. All rights, including +* reproduction, publication, editing and translation, are reserved. The use of +* this project is subject to the terms of a license agreement to be concluded +* with nymea GmbH in accordance with the terms of use of nymea GmbH, available +* under https://nymea.io/license +* +* GNU General Public License Usage +* Alternatively, this project may be redistributed and/or modified under the +* terms of the GNU General Public License as published by the Free Software +* Foundation, GNU version 3. This project is distributed in the hope that it +* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty +* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +* Public License for more details. +* +* You should have received a copy of the GNU General Public License along with +* this project. If not, see . +* +* For any further details and any questions please contact us under +* contact@nymea.io or see our FAQ/Licensing Information on +* https://nymea.io/license/faq +* +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +import QtQuick 2.5 +import QtQuick.Controls 2.1 +import QtQuick.Layouts 1.1 +import Nymea 1.0 +import "../components" + +Page { + id: root + property Thing thing: null + readonly property ThingClass thingClass: thing.thingClass + + header: NymeaHeader { + text: qsTr("Write NFC tag") + onBackPressed: { + root.backPressed(); + } + } + + + NfcHelper { + id: nfcHelper + } +// nfcHelper.writeThingStates(engine, root.thing) + + GridLayout { + anchors.fill: parent + columns: app.landscape ? 2 : 1 + + Item { + Layout.preferredWidth: Math.min(root.width / parent.columns, root.height) + Layout.preferredHeight: app.iconSize * 8 + + SequentialAnimation { + loops: Animation.Infinite + running: true + + PropertyAction { target: phoneIcon; property: "anchors.horizontalCenterOffset"; value: app.iconSize * 2 } + PropertyAction { target: phoneIcon; property: "scale"; value: 1.3 } + NumberAnimation { + target: phoneIcon + property: "opacity" + duration: 500 + to: 1 + } + + PauseAnimation { duration: 500 } + ParallelAnimation { + NumberAnimation { + target: phoneIcon + property: "anchors.horizontalCenterOffset" + from: app.iconSize * 2 + to: -app.iconSize * 2 + duration: 1500 + easing.type: Easing.OutQuad + } + + NumberAnimation { + target: phoneIcon + property: "scale" + duration: 1500 + from: 1.3 + to: 1 + easing.type: Easing.InOutQuad + } + } + + ParallelAnimation { + loops: 2 + NumberAnimation { + duration: 250 + target: vibrateCircle + property: "scale" + from: .8 + to: 1.5 + } + NumberAnimation { + duration: 250 + target: vibrateCircle + property: "opacity" + from: 1 + to: 0 + } + } + PauseAnimation { + duration: 500 + } + + NumberAnimation { + target: phoneIcon + property: "opacity" + duration: 500 + to: 0 + } + } + + + ColorIcon { + id: nfcIcon + name: "../images/nfc.svg" + height: app.iconSize * 2 + width: app.iconSize * 2 + anchors.centerIn: parent + anchors.horizontalCenterOffset: - app.iconSize * 2 + } + + Item { + id: phoneIcon + height: app.iconSize * 5 + width: app.iconSize * 5 + scale: 1.5 + anchors.centerIn: parent + anchors.horizontalCenterOffset: app.iconSize * 2 + + Rectangle { + id: vibrateCircle + anchors.centerIn: parent + anchors.fill: parent + radius: width / 2 + color: "transparent" +// border.color: nfcIcon.keyColor + border.color: app.accentColor + border.width: 2 + scale: .8 + opacity: 0 + } + + Rectangle { + anchors.fill: parent + anchors.leftMargin: phoneIcon.width * .21 + anchors.rightMargin: phoneIcon.width * .21 + anchors.topMargin: phoneIcon.height * .1 + anchors.bottomMargin: phoneIcon.height * .1 + color: app.backgroundColor + } + + ColorIcon { + name: "../images/smartphone.svg" + anchors.fill: parent + } + } + + } + + ColumnLayout { + + Label { + Layout.fillWidth: true + Layout.leftMargin: app.margins; Layout.rightMargin: app.margins + text: qsTr("Select the wanted states and tap an NFC tag to store them. When tapping this tag later, they will be restored.").arg(root.thing.name) + wrapMode: Text.WordWrap + font.pixelSize: app.smallFont + } + + ListView { + Layout.fillWidth: true + Layout.fillHeight: true + model: root.thingClass.stateTypes + clip: true + delegate: CheckDelegate { + width: parent.width + text: model.displayName + checked: true + } + } + } + } +}