Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
androidmainnewintentlistener.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 BasysKom GmbH
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
7#include <QtGui/QGuiApplication>
8#include <QtCore/QJniObject>
9
11
17
23
24bool QMainNfcNewIntentListener::handleNewIntent(JNIEnv * /*env*/, jobject intentObject)
25{
26 QtJniTypes::Intent intent = intentObject;
27 // Only intents with a tag are relevant
28 if (!QtNfc::getTag(intent).isValid())
29 return false;
30
31 listenersLock.lockForRead();
32 for (auto listener : std::as_const(listeners))
33 listener->newIntent(intent);
34 listenersLock.unlock();
35 return true;
36}
37
39{
40 static bool firstListener = true;
41 if (firstListener) {
42 QtJniTypes::Intent intent = QtNfc::getStartIntent();
43 if (intent.isValid())
44 listener->newIntent(intent);
45 paused = static_cast<QGuiApplication*>(QGuiApplication::instance())->applicationState() != Qt::ApplicationActive;
46 }
47 firstListener = false;
48 listenersLock.lockForWrite();
49 if (!listeners.contains(listener))
50 listeners.push_back(listener);
51 listenersLock.unlock();
52 updateReceiveState();
53 return true;
54}
55
57{
58 listenersLock.lockForWrite();
59 listeners.removeOne(listener);
60 listenersLock.unlock();
61 updateReceiveState();
62 return true;
63}
64
66{
67 paused = false;
68 updateReceiveState();
69}
70
72{
73 paused = true;
74 updateReceiveState();
75}
76
77void QMainNfcNewIntentListener::updateReceiveState()
78{
79 if (paused) {
80 // We were paused while receiving, so we stop receiving.
81 if (receiving) {
83 receiving = false;
84 }
85 return;
86 }
87
88 // We reach here, so we are not paused.
89 listenersLock.lockForRead();
90 // We have nfc listeners and do not receive. Switch on.
91 if (!listeners.isEmpty() && !receiving)
92 receiving = QtNfc::startDiscovery();
93
94 // we have no nfc listeners and do receive. Switch off.
95 if (listeners.isEmpty() && receiving) {
97 receiving = false;
98 }
99 listenersLock.unlock();
100}
101
virtual void newIntent(QJniObject intent)=0
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
\macro qGuiApp
bool isEmpty() const noexcept
Definition qlist.h:402
bool removeOne(const AT &t)
Definition qlist.h:599
void push_back(parameter_type t)
Definition qlist.h:676
bool registerListener(QAndroidNfcListenerInterface *listener)
bool unregisterListener(QAndroidNfcListenerInterface *listener)
bool handleNewIntent(JNIEnv *env, jobject intent)
Combined button and popup list for selecting options.
Q_CORE_EXPORT void unregisterNewIntentListener(NewIntentListener *listener)
Q_CORE_EXPORT void registerNewIntentListener(NewIntentListener *listener)
Q_CORE_EXPORT void unregisterResumePauseListener(ResumePauseListener *listener)
Q_CORE_EXPORT void registerResumePauseListener(ResumePauseListener *listener)
bool stopDiscovery()
QtJniTypes::Intent getStartIntent()
bool startDiscovery()
QtJniTypes::Parcelable getTag(const QtJniTypes::Intent &intent)
@ ApplicationActive
Definition qnamespace.h:266
bool contains(const AT &t) const noexcept
Definition qlist.h:46