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 intent)
25{
26 // Only intents with a tag are relevant
27 if (!QtNfc::getTag(intent).isValid())
28 return false;
29
30 listenersLock.lockForRead();
31 for (auto listener : std::as_const(listeners)) {
32 listener->newIntent(QJniObject(intent));
33 }
34 listenersLock.unlock();
35 return true;
36}
37
39{
40 static bool firstListener = true;
41 if (firstListener) {
43 if (intent.isValid()) {
44 listener->newIntent(intent);
45 }
46 paused = static_cast<QGuiApplication*>(QGuiApplication::instance())->applicationState() != Qt::ApplicationActive;
47 }
48 firstListener = false;
49 listenersLock.lockForWrite();
50 if (!listeners.contains(listener))
51 listeners.push_back(listener);
52 listenersLock.unlock();
53 updateReceiveState();
54 return true;
55}
56
58{
59 listenersLock.lockForWrite();
60 listeners.removeOne(listener);
61 listenersLock.unlock();
62 updateReceiveState();
63 return true;
64}
65
67{
68 paused = false;
69 updateReceiveState();
70}
71
73{
74 paused = true;
75 updateReceiveState();
76}
77
78void QMainNfcNewIntentListener::updateReceiveState()
79{
80 if (paused) {
81 // We were paused while receiving, so we stop receiving.
82 if (receiving) {
84 receiving = false;
85 }
86 return;
87 }
88
89 // We reach here, so we are not paused.
90 listenersLock.lockForRead();
91 // We have nfc listeners and do not receive. Switch on.
92 if (!listeners.isEmpty() && !receiving)
93 receiving = QtNfc::startDiscovery();
94
95 // we have no nfc listeners and do receive. Switch off.
96 if (listeners.isEmpty() && receiving) {
98 receiving = false;
99 }
100 listenersLock.unlock();
101}
102
virtual void newIntent(QJniObject intent)=0
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
\macro qGuiApp
\inmodule QtCore
bool isEmpty() const noexcept
Definition qlist.h:401
bool removeOne(const AT &t)
Definition qlist.h:598
void push_back(parameter_type t)
Definition qlist.h:675
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()
QJniObject getStartIntent()
bool startDiscovery()
QJniObject getTag(const QJniObject &intent)
@ ApplicationActive
Definition qnamespace.h:266
bool contains(const AT &t) const noexcept
Definition qlist.h:45