2
* Copyright (C) 2011 The Android Open Source Project
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
#ifndef _UI_INPUT_LISTENER_H
18
#define _UI_INPUT_LISTENER_H
20
#include <androidfw/Input.h>
21
#include <utils/RefBase.h>
22
#include <utils/Vector.h>
26
class InputListenerInterface;
29
/* Superclass of all input event argument objects */
31
virtual ~NotifyArgs() { }
33
virtual void notify(const sp<InputListenerInterface>& listener) const = 0;
37
/* Describes a configuration change event. */
38
struct NotifyConfigurationChangedArgs : public NotifyArgs {
41
inline NotifyConfigurationChangedArgs() { }
43
NotifyConfigurationChangedArgs(nsecs_t eventTime);
45
NotifyConfigurationChangedArgs(const NotifyConfigurationChangedArgs& other);
47
virtual ~NotifyConfigurationChangedArgs() { }
49
virtual void notify(const sp<InputListenerInterface>& listener) const;
53
/* Describes a key event. */
54
struct NotifyKeyArgs : public NotifyArgs {
66
inline NotifyKeyArgs() { }
68
NotifyKeyArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source, uint32_t policyFlags,
69
int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode,
70
int32_t metaState, nsecs_t downTime);
72
NotifyKeyArgs(const NotifyKeyArgs& other);
74
virtual ~NotifyKeyArgs() { }
76
virtual void notify(const sp<InputListenerInterface>& listener) const;
80
/* Describes a motion event. */
81
struct NotifyMotionArgs : public NotifyArgs {
91
uint32_t pointerCount;
92
PointerProperties pointerProperties[MAX_POINTERS];
93
PointerCoords pointerCoords[MAX_POINTERS];
98
inline NotifyMotionArgs() { }
100
NotifyMotionArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source, uint32_t policyFlags,
101
int32_t action, int32_t flags, int32_t metaState, int32_t buttonState,
102
int32_t edgeFlags, uint32_t pointerCount,
103
const PointerProperties* pointerProperties, const PointerCoords* pointerCoords,
104
float xPrecision, float yPrecision, nsecs_t downTime);
106
NotifyMotionArgs(const NotifyMotionArgs& other);
108
virtual ~NotifyMotionArgs() { }
110
virtual void notify(const sp<InputListenerInterface>& listener) const;
114
/* Describes a switch event. */
115
struct NotifySwitchArgs : public NotifyArgs {
117
uint32_t policyFlags;
121
inline NotifySwitchArgs() { }
123
NotifySwitchArgs(nsecs_t eventTime, uint32_t policyFlags,
124
int32_t switchCode, int32_t switchValue);
126
NotifySwitchArgs(const NotifySwitchArgs& other);
128
virtual ~NotifySwitchArgs() { }
130
virtual void notify(const sp<InputListenerInterface>& listener) const;
134
/* Describes a device reset event, such as when a device is added,
135
* reconfigured, or removed. */
136
struct NotifyDeviceResetArgs : public NotifyArgs {
140
inline NotifyDeviceResetArgs() { }
142
NotifyDeviceResetArgs(nsecs_t eventTime, int32_t deviceId);
144
NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other);
146
virtual ~NotifyDeviceResetArgs() { }
148
virtual void notify(const sp<InputListenerInterface>& listener) const;
153
* The interface used by the InputReader to notify the InputListener about input events.
155
class InputListenerInterface : public virtual RefBase {
157
InputListenerInterface() { }
158
virtual ~InputListenerInterface() { }
161
virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) = 0;
162
virtual void notifyKey(const NotifyKeyArgs* args) = 0;
163
virtual void notifyMotion(const NotifyMotionArgs* args) = 0;
164
virtual void notifySwitch(const NotifySwitchArgs* args) = 0;
165
virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) = 0;
170
* An implementation of the listener interface that queues up and defers dispatch
171
* of decoded events until flushed.
173
class QueuedInputListener : public InputListenerInterface {
175
virtual ~QueuedInputListener();
178
QueuedInputListener(const sp<InputListenerInterface>& innerListener);
180
virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args);
181
virtual void notifyKey(const NotifyKeyArgs* args);
182
virtual void notifyMotion(const NotifyMotionArgs* args);
183
virtual void notifySwitch(const NotifySwitchArgs* args);
184
virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args);
189
sp<InputListenerInterface> mInnerListener;
190
Vector<NotifyArgs*> mArgsQueue;
193
} // namespace android
195
#endif // _UI_INPUT_LISTENER_H