blob: 4121b5a438c2e9833aefe8d66bebc11f87a84062 [file] [log] [blame]
Jeff Brown46b9ac0a2010-04-22 18:58:52 -07001//
2// Copyright 2010 The Android Open Source Project
3//
4// Provides a pipe-based transport for native events in the NDK.
5//
6#define LOG_TAG "Input"
7
8//#define LOG_NDEBUG 0
9
10#include <ui/Input.h>
11
12namespace android {
13
14// class InputEvent
15
16void InputEvent::initialize(int32_t deviceId, int32_t nature) {
17 mDeviceId = deviceId;
18 mNature = nature;
19}
20
21// class KeyEvent
22
23void KeyEvent::initialize(
24 int32_t deviceId,
25 int32_t nature,
26 int32_t action,
27 int32_t flags,
28 int32_t keyCode,
29 int32_t scanCode,
30 int32_t metaState,
31 int32_t repeatCount,
32 nsecs_t downTime,
33 nsecs_t eventTime) {
34 InputEvent::initialize(deviceId, nature);
35 mAction = action;
36 mFlags = flags;
37 mKeyCode = keyCode;
38 mScanCode = scanCode;
39 mMetaState = metaState;
40 mRepeatCount = repeatCount;
41 mDownTime = downTime;
42 mEventTime = eventTime;
43}
44
45// class MotionEvent
46
47void MotionEvent::initialize(
48 int32_t deviceId,
49 int32_t nature,
50 int32_t action,
51 int32_t edgeFlags,
52 int32_t metaState,
Jeff Brown5c225b12010-06-16 01:53:36 -070053 float xOffset,
54 float yOffset,
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070055 float xPrecision,
56 float yPrecision,
57 nsecs_t downTime,
58 nsecs_t eventTime,
59 size_t pointerCount,
60 const int32_t* pointerIds,
61 const PointerCoords* pointerCoords) {
62 InputEvent::initialize(deviceId, nature);
63 mAction = action;
64 mEdgeFlags = edgeFlags;
65 mMetaState = metaState;
Jeff Brown5c225b12010-06-16 01:53:36 -070066 mXOffset = xOffset;
67 mYOffset = yOffset;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070068 mXPrecision = xPrecision;
69 mYPrecision = yPrecision;
70 mDownTime = downTime;
71 mPointerIds.clear();
72 mPointerIds.appendArray(pointerIds, pointerCount);
73 mSampleEventTimes.clear();
74 mSamplePointerCoords.clear();
75 addSample(eventTime, pointerCoords);
76}
77
78void MotionEvent::addSample(
79 int64_t eventTime,
80 const PointerCoords* pointerCoords) {
81 mSampleEventTimes.push(eventTime);
82 mSamplePointerCoords.appendArray(pointerCoords, getPointerCount());
83}
84
85void MotionEvent::offsetLocation(float xOffset, float yOffset) {
Jeff Brown5c225b12010-06-16 01:53:36 -070086 mXOffset += xOffset;
87 mYOffset += yOffset;
Jeff Brown46b9ac0a2010-04-22 18:58:52 -070088}
89
90} // namespace android