input.cpp revision d76b67c340d1564abf8d14d976fdaf83bf2b3320
1/* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17#define LOG_TAG "input" 18#include <utils/Log.h> 19 20#include <android/input.h> 21#include <ui/Input.h> 22#include <ui/InputTransport.h> 23#include <utils/PollLoop.h> 24 25#include <android_runtime/android_app_NativeActivity.h> 26 27#include <poll.h> 28 29using android::InputEvent; 30using android::KeyEvent; 31using android::MotionEvent; 32 33int32_t AInputEvent_getType(const AInputEvent* event) { 34 return static_cast<const InputEvent*>(event)->getType(); 35} 36 37int32_t AInputEvent_getDeviceId(const AInputEvent* event) { 38 return static_cast<const InputEvent*>(event)->getDeviceId(); 39} 40 41int32_t AInputEvent_getNature(const AInputEvent* event) { 42 return static_cast<const InputEvent*>(event)->getNature(); 43} 44 45int32_t AKeyEvent_getAction(const AInputEvent* key_event) { 46 return static_cast<const KeyEvent*>(key_event)->getAction(); 47} 48 49int32_t AKeyEvent_getFlags(const AInputEvent* key_event) { 50 return static_cast<const KeyEvent*>(key_event)->getFlags(); 51} 52 53int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event) { 54 return static_cast<const KeyEvent*>(key_event)->getKeyCode(); 55} 56 57int32_t AKeyEvent_getScanCode(const AInputEvent* key_event) { 58 return static_cast<const KeyEvent*>(key_event)->getScanCode(); 59} 60 61int32_t AKeyEvent_getMetaState(const AInputEvent* key_event) { 62 return static_cast<const KeyEvent*>(key_event)->getMetaState(); 63} 64int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event) { 65 return static_cast<const KeyEvent*>(key_event)->getRepeatCount(); 66} 67 68int64_t AKeyEvent_getDownTime(const AInputEvent* key_event) { 69 return static_cast<const KeyEvent*>(key_event)->getDownTime(); 70} 71 72int64_t AKeyEvent_getEventTime(const AInputEvent* key_event) { 73 return static_cast<const KeyEvent*>(key_event)->getEventTime(); 74} 75 76int32_t AMotionEvent_getAction(const AInputEvent* motion_event) { 77 return static_cast<const MotionEvent*>(motion_event)->getAction(); 78} 79 80int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event) { 81 return static_cast<const MotionEvent*>(motion_event)->getMetaState(); 82} 83 84int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event) { 85 return reinterpret_cast<const MotionEvent*>(motion_event)->getEdgeFlags(); 86} 87 88int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event) { 89 return static_cast<const MotionEvent*>(motion_event)->getDownTime(); 90} 91 92int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event) { 93 return static_cast<const MotionEvent*>(motion_event)->getEventTime(); 94} 95 96float AMotionEvent_getXOffset(const AInputEvent* motion_event) { 97 return static_cast<const MotionEvent*>(motion_event)->getXOffset(); 98} 99 100float AMotionEvent_getYOffset(const AInputEvent* motion_event) { 101 return static_cast<const MotionEvent*>(motion_event)->getYOffset(); 102} 103 104float AMotionEvent_getXPrecision(const AInputEvent* motion_event) { 105 return static_cast<const MotionEvent*>(motion_event)->getXPrecision(); 106} 107 108float AMotionEvent_getYPrecision(const AInputEvent* motion_event) { 109 return static_cast<const MotionEvent*>(motion_event)->getYPrecision(); 110} 111 112size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event) { 113 return static_cast<const MotionEvent*>(motion_event)->getPointerCount(); 114} 115 116int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index) { 117 return static_cast<const MotionEvent*>(motion_event)->getPointerId(pointer_index); 118} 119 120float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index) { 121 return static_cast<const MotionEvent*>(motion_event)->getRawX(pointer_index); 122} 123 124float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index) { 125 return static_cast<const MotionEvent*>(motion_event)->getRawY(pointer_index); 126} 127 128float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index) { 129 return static_cast<const MotionEvent*>(motion_event)->getX(pointer_index); 130} 131 132float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index) { 133 return static_cast<const MotionEvent*>(motion_event)->getY(pointer_index); 134} 135 136float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index) { 137 return static_cast<const MotionEvent*>(motion_event)->getPressure(pointer_index); 138} 139 140float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index) { 141 return static_cast<const MotionEvent*>(motion_event)->getSize(pointer_index); 142} 143 144size_t AMotionEvent_getHistorySize(const AInputEvent* motion_event) { 145 return static_cast<const MotionEvent*>(motion_event)->getHistorySize(); 146} 147 148int64_t AMotionEvent_getHistoricalEventTime(AInputEvent* motion_event, 149 size_t history_index) { 150 return static_cast<const MotionEvent*>(motion_event)->getHistoricalEventTime( 151 history_index); 152} 153 154float AMotionEvent_getHistoricalRawX(AInputEvent* motion_event, size_t pointer_index, 155 size_t history_index) { 156 return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawX( 157 pointer_index, history_index); 158} 159 160float AMotionEvent_getHistoricalRawY(AInputEvent* motion_event, size_t pointer_index, 161 size_t history_index) { 162 return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawY( 163 pointer_index, history_index); 164} 165 166float AMotionEvent_getHistoricalX(AInputEvent* motion_event, size_t pointer_index, 167 size_t history_index) { 168 return static_cast<const MotionEvent*>(motion_event)->getHistoricalX( 169 pointer_index, history_index); 170} 171 172float AMotionEvent_getHistoricalY(AInputEvent* motion_event, size_t pointer_index, 173 size_t history_index) { 174 return static_cast<const MotionEvent*>(motion_event)->getHistoricalY( 175 pointer_index, history_index); 176} 177 178float AMotionEvent_getHistoricalPressure(AInputEvent* motion_event, size_t pointer_index, 179 size_t history_index) { 180 return static_cast<const MotionEvent*>(motion_event)->getHistoricalPressure( 181 pointer_index, history_index); 182} 183 184float AMotionEvent_getHistoricalSize(AInputEvent* motion_event, size_t pointer_index, 185 size_t history_index) { 186 return static_cast<const MotionEvent*>(motion_event)->getHistoricalSize( 187 pointer_index, history_index); 188} 189 190void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper, 191 ALooper_callbackFunc* callback, void* data) { 192 queue->attachLooper(looper, callback, data); 193} 194 195void AInputQueue_detachLooper(AInputQueue* queue) { 196 queue->detachLooper(); 197} 198 199int AInputQueue_hasEvents(AInputQueue* queue) { 200 return queue->hasEvents(); 201} 202 203int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent) { 204 return queue->getEvent(outEvent); 205} 206 207void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled) { 208 queue->finishEvent(event, handled != 0); 209} 210