Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
5
#
include
"androidmainnewintentlistener_p.h"
6
#
include
"android/androidjninfc_p.h"
7
#
include
<
QtGui
/
QGuiApplication
>
8
#
include
<
QtCore
/
QJniObject
>
9
10
QT_BEGIN_NAMESPACE
11
12
QMainNfcNewIntentListener::QMainNfcNewIntentListener() : paused(
true
), receiving(
false
)
13
{
14
QtAndroidPrivate::registerNewIntentListener(
this
);
15
QtAndroidPrivate::registerResumePauseListener(
this
);
16
}
17
18
QMainNfcNewIntentListener
::~
QMainNfcNewIntentListener
()
19
{
20
QtAndroidPrivate::unregisterNewIntentListener(
this
);
21
QtAndroidPrivate::unregisterResumePauseListener(
this
);
22
}
23
24
bool
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
38
bool
QMainNfcNewIntentListener
::
registerListener
(
QAndroidNfcListenerInterface
*listener)
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
56
bool
QMainNfcNewIntentListener
::
unregisterListener
(
QAndroidNfcListenerInterface
*listener)
57
{
58
listenersLock.lockForWrite();
59
listeners.removeOne(listener);
60
listenersLock.unlock();
61
updateReceiveState();
62
return
true
;
63
}
64
65
void
QMainNfcNewIntentListener
::
handleResume
()
66
{
67
paused =
false
;
68
updateReceiveState();
69
}
70
71
void
QMainNfcNewIntentListener
::
handlePause
()
72
{
73
paused =
true
;
74
updateReceiveState();
75
}
76
77
void
QMainNfcNewIntentListener
::updateReceiveState()
78
{
79
if
(paused) {
80
// We were paused while receiving, so we stop receiving.
81
if
(receiving) {
82
QtNfc
::
stopDiscovery
(
)
;
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) {
96
QtNfc
::
stopDiscovery
(
)
;
97
receiving =
false
;
98
}
99
listenersLock.unlock();
100
}
101
102
QT_END_NAMESPACE
QAndroidNfcListenerInterface
Definition
androidmainnewintentlistener_p.h:28
QAndroidNfcListenerInterface::newIntent
virtual void newIntent(QJniObject intent)=0
QMainNfcNewIntentListener
Definition
androidmainnewintentlistener_p.h:36
QMainNfcNewIntentListener::registerListener
bool registerListener(QAndroidNfcListenerInterface *listener)
Definition
androidmainnewintentlistener.cpp:38
QMainNfcNewIntentListener::unregisterListener
bool unregisterListener(QAndroidNfcListenerInterface *listener)
Definition
androidmainnewintentlistener.cpp:56
QMainNfcNewIntentListener::~QMainNfcNewIntentListener
~QMainNfcNewIntentListener()
Definition
androidmainnewintentlistener.cpp:18
QMainNfcNewIntentListener::handlePause
void handlePause()
Definition
androidmainnewintentlistener.cpp:71
QMainNfcNewIntentListener::handleNewIntent
bool handleNewIntent(JNIEnv *env, jobject intent)
Definition
androidmainnewintentlistener.cpp:24
QMainNfcNewIntentListener::handleResume
void handleResume()
Definition
androidmainnewintentlistener.cpp:65
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QtNfc
Definition
androidjninfc.cpp:11
QtNfc::stopDiscovery
bool stopDiscovery()
Definition
androidjninfc.cpp:28
QtNfc::startDiscovery
bool startDiscovery()
Definition
androidjninfc.cpp:13
qtconnectivity
src
nfc
android
androidmainnewintentlistener.cpp
Generated on
for Qt by
1.18.0