diff options
author | Jeff Brown <jeffbrown@google.com> | 2010-07-28 14:27:55 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-07-28 14:27:55 -0700 |
commit | 2279971b6f66d60240b8c72a9d52644a3bcdf01b (patch) | |
tree | 6bb439e7b3c2b8c32a10a4b71cd8220045a49a90 /native | |
parent | 5193a5bab165a4f812b8e72d656b6a18ee04f42b (diff) | |
parent | 9795a25da060f9a7df87da8ab43fb1086d4322a5 (diff) | |
download | frameworks_base-2279971b6f66d60240b8c72a9d52644a3bcdf01b.zip frameworks_base-2279971b6f66d60240b8c72a9d52644a3bcdf01b.tar.gz frameworks_base-2279971b6f66d60240b8c72a9d52644a3bcdf01b.tar.bz2 |
am 9795a25d: am 6d0fec2d: Refactor input reader to support new device types more easily.
Merge commit '9795a25da060f9a7df87da8ab43fb1086d4322a5'
* commit '9795a25da060f9a7df87da8ab43fb1086d4322a5':
Refactor input reader to support new device types more easily.
Diffstat (limited to 'native')
-rw-r--r-- | native/android/input.cpp | 78 | ||||
-rw-r--r-- | native/include/android/input.h | 94 |
2 files changed, 169 insertions, 3 deletions
diff --git a/native/android/input.cpp b/native/android/input.cpp index 59bf711..a82282d 100644 --- a/native/android/input.cpp +++ b/native/android/input.cpp @@ -21,14 +21,21 @@ #include <ui/Input.h> #include <ui/InputTransport.h> #include <utils/PollLoop.h> +#include <utils/RefBase.h> +#include <utils/Vector.h> #include <android_runtime/android_app_NativeActivity.h> #include <poll.h> +#include <errno.h> using android::InputEvent; using android::KeyEvent; using android::MotionEvent; +using android::InputDeviceInfo; +using android::InputDeviceProxy; +using android::sp; +using android::Vector; int32_t AInputEvent_getType(const AInputEvent* event) { return static_cast<const InputEvent*>(event)->getType(); @@ -263,3 +270,74 @@ int32_t AInputQueue_preDispatchEvent(AInputQueue* queue, AInputEvent* event) { void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled) { queue->finishEvent(event, handled != 0); } + + +int32_t AInputDevice_getDeviceIds(int32_t* idBuf, size_t nMax, size_t* nActual) { + Vector<int32_t> ids; + InputDeviceProxy::getDeviceIds(ids); + + if (nActual) { + *nActual = ids.size(); + } + + if (idBuf && ids.size() < nMax) { + memcpy(idBuf, ids.array(), ids.size() * sizeof(int32_t)); + return 0; + } + + return -ENOMEM; +} + +AInputDevice* AInputDevice_acquire(int32_t deviceId) { + sp<InputDeviceProxy> proxy(InputDeviceProxy::getDevice(deviceId)); + if (proxy == NULL) { + return NULL; + } + proxy->incStrong((void*)AInputDevice_acquire); + return static_cast<AInputDevice*>(proxy.get()); +} + +void AInputDevice_release(AInputDevice* device) { + if (device) { + InputDeviceProxy* proxy = static_cast<InputDeviceProxy*>(device); + proxy->decStrong((void*)AInputDevice_acquire); + } +} + +const char* AInputDevice_getName(AInputDevice* device) { + InputDeviceProxy* proxy = static_cast<InputDeviceProxy*>(device); + return proxy->getInfo()->getName().string(); +} + +uint32_t AInputDevice_getSources(AInputDevice* device) { + InputDeviceProxy* proxy = static_cast<InputDeviceProxy*>(device); + return proxy->getInfo()->getSources(); +} + +int32_t AInputDevice_getKeyboardType(AInputDevice* device) { + InputDeviceProxy* proxy = static_cast<InputDeviceProxy*>(device); + return proxy->getInfo()->getKeyboardType(); +} + +int32_t AInputDevice_getMotionRange(AInputDevice* device, int32_t rangeType, + float* outMin, float* outMax, float* outFlat, float* outFuzz) { + InputDeviceProxy* proxy = static_cast<InputDeviceProxy*>(device); + const InputDeviceInfo::MotionRange* range = proxy->getInfo()->getMotionRange(rangeType); + if (range) { + if (outMin) { + *outMin = range->min; + } + if (outMax) { + *outMax = range->max; + } + if (outFlat) { + *outFlat = range->flat; + } + if (outFuzz) { + *outFuzz = range->fuzz; + } + return 0; + } else { + return -ENOTSUP; + } +} diff --git a/native/include/android/input.h b/native/include/android/input.h index 0b8c7e4..9883ac70 100644 --- a/native/include/android/input.h +++ b/native/include/android/input.h @@ -268,7 +268,6 @@ enum { /* * Input sources. * - * The appropriate interpretation for an input event depends on its source. * Refer to the documentation on android.view.InputDevice for more details about input sources * and their correct interpretation. */ @@ -297,6 +296,37 @@ enum { }; /* + * Keyboard types. + * + * Refer to the documentation on android.view.InputDevice for more details. + */ +enum { + AINPUT_KEYBOARD_TYPE_NONE = 0, + AINPUT_KEYBOARD_TYPE_NON_ALPHABETIC = 1, + AINPUT_KEYBOARD_TYPE_ALPHABETIC = 2, +}; + +/* + * Constants used to retrieve information about the range of motion for a particular + * coordinate of a motion event. + * + * Refer to the documentation on android.view.InputDevice for more details about input sources + * and their correct interpretation. + */ +enum { + AINPUT_MOTION_RANGE_X = 0, + AINPUT_MOTION_RANGE_Y = 1, + AINPUT_MOTION_RANGE_PRESSURE = 2, + AINPUT_MOTION_RANGE_SIZE = 3, + AINPUT_MOTION_RANGE_TOUCH_MAJOR = 4, + AINPUT_MOTION_RANGE_TOUCH_MINOR = 5, + AINPUT_MOTION_RANGE_TOOL_MAJOR = 6, + AINPUT_MOTION_RANGE_TOOL_MINOR = 7, + AINPUT_MOTION_RANGE_ORIENTATION = 8, +}; + + +/* * Input event accessors. * * Note that most functions can only be used on input events that are of a given type. @@ -475,7 +505,7 @@ float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_ * upwards, is perfectly circular or is of unknown orientation. A positive angle * indicates that the major axis of contact is oriented to the right. A negative angle * indicates that the major axis of contact is oriented to the left. - * The full range is from -PI/4 radians (finger pointing fully left) to PI/4 radians + * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians * (finger pointing fully right). */ float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index); @@ -575,7 +605,7 @@ float AMotionEvent_getHistoricalToolMinor(const AInputEvent* motion_event, size_ * upwards, is perfectly circular or is of unknown orientation. A positive angle * indicates that the major axis of contact is oriented to the right. A negative angle * indicates that the major axis of contact is oriented to the left. - * The full range is from -PI/4 radians (finger pointing fully left) to PI/4 radians + * The full range is from -PI/2 radians (finger pointing fully left) to PI/2 radians * (finger pointing fully right). */ float AMotionEvent_getHistoricalOrientation(const AInputEvent* motion_event, size_t pointer_index, size_t history_index); @@ -631,6 +661,64 @@ int32_t AInputQueue_preDispatchEvent(AInputQueue* queue, AInputEvent* event); */ void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled); +/* + * Input devices. + * + * These functions provide a mechanism for querying the set of available input devices + * and their characteristics and capabilities. + */ +struct AInputDevice; +typedef struct AInputDevice AInputDevice; + +/* + * Populates the supplied array with the ids of all input devices in the system. + * Sets nActual to the actual number of devices. + * Returns zero if enumeration was successful. + * Returns non-zero if the actual number of devices is greater than nMax, in which case the + * client should call the method again with a larger id buffer. + */ +int32_t AInputDevice_getDeviceIds(int32_t* idBuf, size_t nMax, size_t* nActual); + +/* + * Acquires a device by id. + * Returns NULL if the device was not found. + * + * Note: The returned object must be freed using AInputDevice_release when no longer needed. + */ +AInputDevice* AInputDevice_acquire(int32_t deviceId); + +/* + * Releases a device previously acquired by AInputDevice_acquire. + * If device is NULL, this function does nothing. + */ +void AInputDevice_release(AInputDevice* device); + +/* + * Gets the name of an input device. + * + * Note: The caller should copy the name into a private buffer since the returned pointer + * will become invalid when the device object is released. + */ +const char* AInputDevice_getName(AInputDevice* device); + +/* + * Gets the combination of input sources provided by the input device. + */ +uint32_t AInputDevice_getSources(AInputDevice* device); + +/* + * Gets the keyboard type. + */ +int32_t AInputDevice_getKeyboardType(AInputDevice* device); + +/* Gets the minimum value, maximum value, flat position and error tolerance for a + * particular motion coodinate. + * Returns zero if the device supports the specified motion range. */ +int32_t AInputDevice_getMotionRange(AInputDevice* device, int32_t rangeType, + float* outMin, float* outMax, float* outFlat, float* outFuzz); + +//TODO hasKey, keymap stuff, etc... + #ifdef __cplusplus } #endif |