From 30d266af75149a2553277892742a31a133f260b2 Mon Sep 17 00:00:00 2001 From: FalsinSoft Date: Fri, 14 Feb 2020 16:04:15 +0100 Subject: [PATCH] Demo app now receive shared text and binary image data --- .../qtandroidtools/AndroidSharing.java | 24 +++++---- QtAndroidToolsDemo/Main.cpp | 1 + QtAndroidToolsDemo/Main.qml | 8 +++ QtAndroidToolsDemo/tools/AndroidSharing.qml | 49 ++++++++++++++----- 4 files changed, 60 insertions(+), 22 deletions(-) diff --git a/QtAndroidTools/src/com/falsinsoft/qtandroidtools/AndroidSharing.java b/QtAndroidTools/src/com/falsinsoft/qtandroidtools/AndroidSharing.java index 22ea6a6..66cca17 100644 --- a/QtAndroidTools/src/com/falsinsoft/qtandroidtools/AndroidSharing.java +++ b/QtAndroidTools/src/com/falsinsoft/qtandroidtools/AndroidSharing.java @@ -51,19 +51,23 @@ public class AndroidSharing public int getAction() { + final String ActionValue = mActivityIntent.getAction(); int ActionId = ACTION_NONE; - switch(mActivityIntent.getAction()) + if(ActionValue != null) { - case Intent.ACTION_SEND: - ActionId = ACTION_SEND; - break; - case Intent.ACTION_SEND_MULTIPLE: - ActionId = ACTION_SEND_MULTIPLE; - break; - case Intent.ACTION_PICK: - ActionId = ACTION_PICK; - break; + switch(ActionValue) + { + case Intent.ACTION_SEND: + ActionId = ACTION_SEND; + break; + case Intent.ACTION_SEND_MULTIPLE: + ActionId = ACTION_SEND_MULTIPLE; + break; + case Intent.ACTION_PICK: + ActionId = ACTION_PICK; + break; + } } return ActionId; diff --git a/QtAndroidToolsDemo/Main.cpp b/QtAndroidToolsDemo/Main.cpp index 28e7c70..cbff5dc 100644 --- a/QtAndroidToolsDemo/Main.cpp +++ b/QtAndroidToolsDemo/Main.cpp @@ -14,6 +14,7 @@ int main(int argc, char *argv[]) #ifdef Q_OS_ANDROID QtAndroidTools::InitializeQmlTools(); #endif + QObject::connect(&engine, SIGNAL(quit()), &app, SLOT(quit())); engine.load(QUrl(QStringLiteral("qrc:/Main.qml"))); if(engine.rootObjects().isEmpty()) return -1; diff --git a/QtAndroidToolsDemo/Main.qml b/QtAndroidToolsDemo/Main.qml index bfcd7e3..adb3a4a 100644 --- a/QtAndroidToolsDemo/Main.qml +++ b/QtAndroidToolsDemo/Main.qml @@ -3,6 +3,7 @@ import QtQuick 2.11 import QtQuick.Layouts 1.12 import QtQuick.Controls 2.12 import QtQuick.Controls.Material 2.12 +import QtAndroidTools 1.0 ApplicationWindow { id: window @@ -11,6 +12,13 @@ ApplicationWindow { height: 520 title: "QtAndroidTools Demo" + Component.onCompleted: { + if(QtAndroidSharing.action !== QtAndroidSharing.ACTION_NONE) + { + stackView.push("qrc:/tools/AndroidSharing.qml"); + } + } + header: ToolBar { Material.foreground: "white" diff --git a/QtAndroidToolsDemo/tools/AndroidSharing.qml b/QtAndroidToolsDemo/tools/AndroidSharing.qml index a4e197e..f5cb4a8 100644 --- a/QtAndroidToolsDemo/tools/AndroidSharing.qml +++ b/QtAndroidToolsDemo/tools/AndroidSharing.qml @@ -1,5 +1,6 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 +import QtQuick.Dialogs 1.1 import QtAndroidTools 1.0 Page { @@ -7,9 +8,19 @@ Page { padding: 20 Component.onCompleted: { - if(QtAndroidSharing.action !== QtAndroidSharing.ACTION_NONE) + if(QtAndroidSharing.action === QtAndroidSharing.ACTION_SEND) { - if(QtAndroidSharing.mimeType === "text/plain") receivedSharedtext.text = QtAndroidSharing.getSharedText(); + if(QtAndroidSharing.mimeType === "text/plain") + { + receivedSharedText.text = QtAndroidSharing.getSharedText(); + receivedSharedText.open(); + } + else if(QtAndroidSharing.mimeType.startsWith("image") === true) + { + QtAndroidTools.insertImage("SharedImage", QtAndroidSharing.getSharedData()); + sharedImage.source = "image://QtAndroidTools/SharedImage"; + receivedSharedImage.open(); + } } } @@ -22,26 +33,40 @@ Page { text: "Text to share" font.bold: true } - TextInput { + TextField { id: sharedText width: parent.width text: "Hello Qt!" - horizontalAlignment: TextInput.AlignHCenter + horizontalAlignment: TextField.AlignHCenter } Button { anchors.horizontalCenter: parent.horizontalCenter text: "Share" onClicked: QtAndroidSharing.shareText(sharedText.text) } + } - Label { - anchors.horizontalCenter: parent.horizontalCenter - text: "Received shared text" - font.bold: true - } - Label { - id: receivedSharedtext - anchors.horizontalCenter: parent.horizontalCenter + MessageDialog { + id: receivedSharedText + title: "Received shared text" + onAccepted: Qt.quit() + } + + Dialog { + id: receivedSharedImage + title: "Received shared image" + modal: true + standardButtons: Dialog.Ok + contentWidth: sharedImage.width + contentHeight: sharedImage.height + anchors.centerIn: parent + + Image { + id: sharedImage + width: page.width * 0.5 + height: width } + + onAccepted: Qt.quit() } }