diff options
Diffstat (limited to 'native')
-rw-r--r-- | native/android/Android.mk | 32 | ||||
-rw-r--r-- | native/android/asset_manager.cpp | 210 | ||||
-rw-r--r-- | native/android/input.cpp | 343 | ||||
-rw-r--r-- | native/android/looper.cpp | 82 | ||||
-rw-r--r-- | native/android/native_activity.cpp | 39 | ||||
-rw-r--r-- | native/android/native_window.cpp | 97 | ||||
-rw-r--r-- | native/android/sensor.cpp | 155 | ||||
-rw-r--r-- | native/include/android/asset_manager.h | 148 | ||||
-rw-r--r-- | native/include/android/input.h | 727 | ||||
-rw-r--r-- | native/include/android/keycodes.h | 166 | ||||
-rw-r--r-- | native/include/android/looper.h | 177 | ||||
-rw-r--r-- | native/include/android/native_activity.h | 254 | ||||
-rw-r--r-- | native/include/android/native_window.h | 106 | ||||
-rw-r--r-- | native/include/android/native_window_jni.h | 40 | ||||
-rw-r--r-- | native/include/android/rect.h | 36 | ||||
-rw-r--r-- | native/include/android/sensor.h | 256 | ||||
-rw-r--r-- | native/include/android/window.h | 58 |
17 files changed, 2926 insertions, 0 deletions
diff --git a/native/android/Android.mk b/native/android/Android.mk new file mode 100644 index 0000000..950a1e9 --- /dev/null +++ b/native/android/Android.mk @@ -0,0 +1,32 @@ +BASE_PATH := $(call my-dir) +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) + +# our source files +# +LOCAL_SRC_FILES:= \ + asset_manager.cpp \ + input.cpp \ + looper.cpp \ + native_activity.cpp \ + native_window.cpp \ + sensor.cpp + +LOCAL_SHARED_LIBRARIES := \ + libcutils \ + libutils \ + libbinder \ + libui \ + libgui \ + libsurfaceflinger_client \ + libandroid_runtime + +LOCAL_C_INCLUDES += \ + frameworks/base/native/include \ + frameworks/base/core/jni/android \ + dalvik/libnativehelper/include/nativehelper + +LOCAL_MODULE:= libandroid + +include $(BUILD_SHARED_LIBRARY) diff --git a/native/android/asset_manager.cpp b/native/android/asset_manager.cpp new file mode 100644 index 0000000..36c381e --- /dev/null +++ b/native/android/asset_manager.cpp @@ -0,0 +1,210 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "NAsset" +#include <utils/Log.h> + +#include <android/asset_manager.h> +#include <utils/AssetManager.h> +#include <utils/AssetDir.h> +#include <utils/Asset.h> +#include <utils/threads.h> + +#include "jni.h" +#include "JNIHelp.h" + +using namespace android; + +// -------------------- Backing implementation of the public API -------------------- + +// AAssetManager is actually a secret typedef for an empty base class of AssetManager, +// but AAssetDir and AAsset are actual wrappers for isolation. + +// ----- +struct AAssetDir { + AssetDir* mAssetDir; + size_t mCurFileIndex; + String8 mCachedFileName; + + AAssetDir(AssetDir* dir) : mAssetDir(dir), mCurFileIndex(0) { } + ~AAssetDir() { delete mAssetDir; } +}; + + +// ----- +struct AAsset { + Asset* mAsset; + + AAsset(Asset* asset) : mAsset(asset) { } + ~AAsset() { delete mAsset; } +}; + +// -------------------- Public native C API -------------------- + +/** + * Supporting information + */ + +static struct assetmanager_offsets_t +{ + jfieldID mObject; +} gAssetManagerOffsets; + +static volatile bool gJNIConfigured = false; +static Mutex gMutex; + +/** + * Asset Manager functionality + */ +AAssetManager* AAssetManager_fromJava(JNIEnv* env, jobject assetManager) +{ + { + Mutex::Autolock _l(gMutex); + + if (gJNIConfigured == false) { + jclass amClass = env->FindClass("android/content/res/AssetManager"); + gAssetManagerOffsets.mObject = env->GetFieldID(amClass, "mObject", "I"); + gJNIConfigured = true; + } + } + + return (AAssetManager*) env->GetIntField(assetManager, gAssetManagerOffsets.mObject); +} + +AAsset* AAssetManager_open(AAssetManager* amgr, const char* filename, int mode) +{ + Asset::AccessMode amMode; + switch (mode) { + case AASSET_MODE_UNKNOWN: + amMode = Asset::ACCESS_UNKNOWN; + break; + case AASSET_MODE_RANDOM: + amMode = Asset::ACCESS_RANDOM; + break; + case AASSET_MODE_STREAMING: + amMode = Asset::ACCESS_STREAMING; + break; + case AASSET_MODE_BUFFER: + amMode = Asset::ACCESS_BUFFER; + break; + default: + return NULL; + } + + AssetManager* mgr = static_cast<AssetManager*>(amgr); + Asset* asset = mgr->open(filename, amMode); + if (asset == NULL) { + return NULL; + } + + return new AAsset(asset); +} + +AAssetDir* AAssetManager_openDir(AAssetManager* amgr, const char* dirName) +{ + AssetManager* mgr = static_cast<AssetManager*>(amgr); + return new AAssetDir(mgr->openDir(dirName)); +} + +/** + * AssetDir functionality + */ + +const char* AAssetDir_getNextFileName(AAssetDir* assetDir) +{ + const char* returnName = NULL; + size_t index = assetDir->mCurFileIndex; + const size_t max = assetDir->mAssetDir->getFileCount(); + + // Find the next regular file; explicitly don't report directories even if the + // underlying implementation changes to report them. At that point we can add + // a more general iterator to this native interface set if appropriate. + while ((index < max) && (assetDir->mAssetDir->getFileType(index) != kFileTypeRegular)) { + index++; + } + + // still in bounds? then the one at 'index' is the next to be reported; generate + // the string to return and advance the iterator for next time. + if (index < max) { + assetDir->mCachedFileName = assetDir->mAssetDir->getFileName(index); + returnName = assetDir->mCachedFileName.string(); + index++; + } + + assetDir->mCurFileIndex = index; + return returnName; +} + +void AAssetDir_rewind(AAssetDir* assetDir) +{ + assetDir->mCurFileIndex = 0; +} + +const char* AAssetDir_getFileName(AAssetDir* assetDir, int index) +{ + assetDir->mCachedFileName = assetDir->mAssetDir->getFileName(index); + return assetDir->mCachedFileName.string(); +} + +void AAssetDir_close(AAssetDir* assetDir) +{ + delete assetDir; +} + +/** + * Asset functionality + */ + +int AAsset_read(AAsset* asset, void* buf, size_t count) +{ + return asset->mAsset->read(buf, (size_t)count); +} + +off_t AAsset_seek(AAsset* asset, off_t offset, int whence) +{ + return asset->mAsset->seek(offset, whence); +} + +void AAsset_close(AAsset* asset) +{ + asset->mAsset->close(); + delete asset; +} + +const void* AAsset_getBuffer(AAsset* asset) +{ + return asset->mAsset->getBuffer(false); +} + +off_t AAsset_getLength(AAsset* asset) +{ + return asset->mAsset->getLength(); +} + +off_t AAsset_getRemainingLength(AAsset* asset) +{ + return asset->mAsset->getRemainingLength(); +} + +int AAsset_openFileDescriptor(AAsset* asset, off_t* outStart, off_t* outLength) +{ + return asset->mAsset->openFileDescriptor(outStart, outLength); +} + +int AAsset_isAllocated(AAsset* asset) +{ + return asset->mAsset->isAllocated() ? 1 : 0; +} diff --git a/native/android/input.cpp b/native/android/input.cpp new file mode 100644 index 0000000..a82282d --- /dev/null +++ b/native/android/input.cpp @@ -0,0 +1,343 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "input" +#include <utils/Log.h> + +#include <android/input.h> +#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(); +} + +int32_t AInputEvent_getDeviceId(const AInputEvent* event) { + return static_cast<const InputEvent*>(event)->getDeviceId(); +} + +int32_t AInputEvent_getSource(const AInputEvent* event) { + return static_cast<const InputEvent*>(event)->getSource(); +} + +int32_t AKeyEvent_getAction(const AInputEvent* key_event) { + return static_cast<const KeyEvent*>(key_event)->getAction(); +} + +int32_t AKeyEvent_getFlags(const AInputEvent* key_event) { + return static_cast<const KeyEvent*>(key_event)->getFlags(); +} + +int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event) { + return static_cast<const KeyEvent*>(key_event)->getKeyCode(); +} + +int32_t AKeyEvent_getScanCode(const AInputEvent* key_event) { + return static_cast<const KeyEvent*>(key_event)->getScanCode(); +} + +int32_t AKeyEvent_getMetaState(const AInputEvent* key_event) { + return static_cast<const KeyEvent*>(key_event)->getMetaState(); +} +int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event) { + return static_cast<const KeyEvent*>(key_event)->getRepeatCount(); +} + +int64_t AKeyEvent_getDownTime(const AInputEvent* key_event) { + return static_cast<const KeyEvent*>(key_event)->getDownTime(); +} + + +int64_t AKeyEvent_getEventTime(const AInputEvent* key_event) { + return static_cast<const KeyEvent*>(key_event)->getEventTime(); +} + +int32_t AMotionEvent_getAction(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getAction(); +} + +int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getMetaState(); +} + +int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event) { + return reinterpret_cast<const MotionEvent*>(motion_event)->getEdgeFlags(); +} + +int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getDownTime(); +} + +int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getEventTime(); +} + +float AMotionEvent_getXOffset(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getXOffset(); +} + +float AMotionEvent_getYOffset(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getYOffset(); +} + +float AMotionEvent_getXPrecision(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getXPrecision(); +} + +float AMotionEvent_getYPrecision(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getYPrecision(); +} + +size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getPointerCount(); +} + +int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getPointerId(pointer_index); +} + +float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getRawX(pointer_index); +} + +float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getRawY(pointer_index); +} + +float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getX(pointer_index); +} + +float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getY(pointer_index); +} + +float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getPressure(pointer_index); +} + +float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getSize(pointer_index); +} + +float AMotionEvent_getTouchMajor(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getTouchMajor(pointer_index); +} + +float AMotionEvent_getTouchMinor(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getTouchMinor(pointer_index); +} + +float AMotionEvent_getToolMajor(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getToolMajor(pointer_index); +} + +float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getToolMinor(pointer_index); +} + +float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index) { + return static_cast<const MotionEvent*>(motion_event)->getOrientation(pointer_index); +} + +size_t AMotionEvent_getHistorySize(const AInputEvent* motion_event) { + return static_cast<const MotionEvent*>(motion_event)->getHistorySize(); +} + +int64_t AMotionEvent_getHistoricalEventTime(AInputEvent* motion_event, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalEventTime( + history_index); +} + +float AMotionEvent_getHistoricalRawX(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawX( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalRawY(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawY( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalX(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalX( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalY(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalY( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalPressure(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalPressure( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalSize(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalSize( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalTouchMajor(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalTouchMajor( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalTouchMinor(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalTouchMinor( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalToolMajor(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalToolMajor( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalToolMinor(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalToolMinor( + pointer_index, history_index); +} + +float AMotionEvent_getHistoricalOrientation(AInputEvent* motion_event, size_t pointer_index, + size_t history_index) { + return static_cast<const MotionEvent*>(motion_event)->getHistoricalOrientation( + pointer_index, history_index); +} + + +void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper, + ALooper_callbackFunc* callback, void* data) { + queue->attachLooper(looper, callback, data); +} + +void AInputQueue_detachLooper(AInputQueue* queue) { + queue->detachLooper(); +} + +int32_t AInputQueue_hasEvents(AInputQueue* queue) { + return queue->hasEvents(); +} + +int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent) { + return queue->getEvent(outEvent); +} + +int32_t AInputQueue_preDispatchEvent(AInputQueue* queue, AInputEvent* event) { + return queue->preDispatchEvent(event) ? 1 : 0; +} + +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/android/looper.cpp b/native/android/looper.cpp new file mode 100644 index 0000000..1564c47 --- /dev/null +++ b/native/android/looper.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "ALooper" +#include <utils/Log.h> + +#include <android/looper.h> +#include <utils/PollLoop.h> + +using android::PollLoop; +using android::sp; + +ALooper* ALooper_forThread() { + return PollLoop::getForThread().get(); +} + +ALooper* ALooper_prepare(int32_t opts) { + bool allowFds = (opts&ALOOPER_PREPARE_ALLOW_NON_CALLBACKS) != 0; + sp<PollLoop> loop = PollLoop::getForThread(); + if (loop == NULL) { + loop = new PollLoop(allowFds); + PollLoop::setForThread(loop); + } + if (loop->getAllowNonCallbacks() != allowFds) { + LOGW("ALooper_prepare again with different ALOOPER_PREPARE_ALLOW_NON_CALLBACKS"); + } + return loop.get(); +} + +int32_t ALooper_pollOnce(int timeoutMillis, int* outEvents, void** outData) { + sp<PollLoop> loop = PollLoop::getForThread(); + if (loop == NULL) { + LOGW("ALooper_pollOnce: No looper for this thread!"); + return -1; + } + return loop->pollOnce(timeoutMillis, outEvents, outData); +} + +int32_t ALooper_pollAll(int timeoutMillis, int* outEvents, void** outData) { + sp<PollLoop> loop = PollLoop::getForThread(); + if (loop == NULL) { + LOGW("ALooper_pollOnce: No looper for this thread!"); + return -1; + } + + int32_t result; + while ((result = loop->pollOnce(timeoutMillis, outEvents, outData)) == ALOOPER_POLL_CALLBACK) { + ; + } + + return result; +} + +void ALooper_acquire(ALooper* looper) { + static_cast<PollLoop*>(looper)->incStrong((void*)ALooper_acquire); +} + +void ALooper_release(ALooper* looper) { + static_cast<PollLoop*>(looper)->decStrong((void*)ALooper_acquire); +} + +void ALooper_addFd(ALooper* looper, int fd, int events, + ALooper_callbackFunc* callback, void* data) { + static_cast<PollLoop*>(looper)->setLooperCallback(fd, events, callback, data); +} + +int32_t ALooper_removeFd(ALooper* looper, int fd) { + return static_cast<PollLoop*>(looper)->removeCallback(fd) ? 1 : 0; +} diff --git a/native/android/native_activity.cpp b/native/android/native_activity.cpp new file mode 100644 index 0000000..0c6823a --- /dev/null +++ b/native/android/native_activity.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "native_activity" +#include <utils/Log.h> + +#include <android_runtime/android_app_NativeActivity.h> + +using namespace android; + +void ANativeActivity_setWindowFormat(ANativeActivity* activity, int32_t format) { + android_NativeActivity_setWindowFormat(activity, format); +} + +void ANativeActivity_setWindowFlags(ANativeActivity* activity, + uint32_t addFlags, uint32_t removeFlags) { + android_NativeActivity_setWindowFlags(activity, addFlags, addFlags|removeFlags); +} + +void ANativeActivity_showSoftInput(ANativeActivity* activity, uint32_t flags) { + android_NativeActivity_showSoftInput(activity, flags); +} + +void ANativeActivity_hideSoftInput(ANativeActivity* activity, uint32_t flags) { + android_NativeActivity_hideSoftInput(activity, flags); +} diff --git a/native/android/native_window.cpp b/native/android/native_window.cpp new file mode 100644 index 0000000..bada078 --- /dev/null +++ b/native/android/native_window.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "Surface" +#include <utils/Log.h> + +#include <android/native_window_jni.h> +#include <surfaceflinger/Surface.h> +#include <android_runtime/android_view_Surface.h> + +using namespace android; + +ANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface) { + sp<ANativeWindow> win = android_Surface_getNativeWindow(env, surface); + if (win != NULL) { + win->incStrong((void*)ANativeWindow_acquire); + } + return win.get(); +} + +void ANativeWindow_acquire(ANativeWindow* window) { + window->incStrong((void*)ANativeWindow_acquire); +} + +void ANativeWindow_release(ANativeWindow* window) { + window->decStrong((void*)ANativeWindow_acquire); +} + +static int32_t getWindowProp(ANativeWindow* window, int what) { + int value; + int res = window->query(window, what, &value); + return res < 0 ? res : value; +} + +int32_t ANativeWindow_getWidth(ANativeWindow* window) { + return getWindowProp(window, NATIVE_WINDOW_WIDTH); +} + +int32_t ANativeWindow_getHeight(ANativeWindow* window) { + return getWindowProp(window, NATIVE_WINDOW_HEIGHT); +} + +int32_t ANativeWindow_getFormat(ANativeWindow* window) { + return getWindowProp(window, NATIVE_WINDOW_FORMAT); +} + +int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window, int32_t width, + int32_t height) { + native_window_set_buffers_geometry(window, width, height, 0); + return 0; +} + +int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer, + ARect* inOutDirtyBounds) { + Region dirtyRegion; + Region* dirtyParam = NULL; + if (inOutDirtyBounds != NULL) { + dirtyRegion.set(*(Rect*)inOutDirtyBounds); + dirtyParam = &dirtyRegion; + } + + Surface::SurfaceInfo info; + status_t res = static_cast<Surface*>(window)->lock(&info, dirtyParam); + if (res != OK) { + return -1; + } + + outBuffer->width = (int32_t)info.w; + outBuffer->height = (int32_t)info.h; + outBuffer->stride = (int32_t)info.s; + outBuffer->format = (int32_t)info.format; + outBuffer->bits = info.bits; + + if (inOutDirtyBounds != NULL) { + *inOutDirtyBounds = dirtyRegion.getBounds(); + } + + return 0; +} + +int32_t ANativeWindow_unlockAndPost(ANativeWindow* window) { + status_t res = static_cast<Surface*>(window)->unlockAndPost(); + return res == android::OK ? 0 : -1; +} diff --git a/native/android/sensor.cpp b/native/android/sensor.cpp new file mode 100644 index 0000000..db534e0 --- /dev/null +++ b/native/android/sensor.cpp @@ -0,0 +1,155 @@ +/* + * Copyright (C) 2009 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "sensor" +#include <utils/Log.h> + +#include <android/looper.h> +#include <android/sensor.h> + +#include <utils/RefBase.h> +#include <utils/PollLoop.h> +#include <utils/Timers.h> + +#include <gui/Sensor.h> +#include <gui/SensorManager.h> +#include <gui/SensorEventQueue.h> + +#include <poll.h> + +using android::sp; +using android::Sensor; +using android::SensorManager; +using android::SensorEventQueue; +using android::String8; + +/*****************************************************************************/ + +ASensorManager* ASensorManager_getInstance() +{ + return &SensorManager::getInstance(); +} + +int ASensorManager_getSensorList(ASensorManager* manager, + ASensorList* list) +{ + Sensor const* const* l; + int c = static_cast<SensorManager*>(manager)->getSensorList(&l); + if (list) { + *list = reinterpret_cast<ASensorList>(l); + } + return c; +} + +ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type) +{ + return static_cast<SensorManager*>(manager)->getDefaultSensor(type); +} + +ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager, + ALooper* looper, ALooper_callbackFunc* callback, void* data) +{ + sp<SensorEventQueue> queue = + static_cast<SensorManager*>(manager)->createEventQueue(); + if (queue != 0) { + ALooper_addFd(looper, queue->getFd(), POLLIN, callback, data); + queue->looper = looper; + queue->incStrong(manager); + } + return static_cast<ASensorEventQueue*>(queue.get()); +} + +int ASensorManager_destroyEventQueue(ASensorManager* manager, + ASensorEventQueue* inQueue) +{ + sp<SensorEventQueue> queue = static_cast<SensorEventQueue*>(inQueue); + ALooper_removeFd(queue->looper, queue->getFd()); + queue->decStrong(manager); + return 0; +} + +/*****************************************************************************/ + +int ASensorEventQueue_enableSensor(ASensorEventQueue* queue, ASensor const* sensor) +{ + return static_cast<SensorEventQueue*>(queue)->enableSensor( + static_cast<Sensor const*>(sensor)); +} + +int ASensorEventQueue_disableSensor(ASensorEventQueue* queue, ASensor const* sensor) +{ + return static_cast<SensorEventQueue*>(queue)->disableSensor( + static_cast<Sensor const*>(sensor)); +} + +int ASensorEventQueue_setEventRate(ASensorEventQueue* queue, ASensor const* sensor, + int32_t usec) +{ + return static_cast<SensorEventQueue*>(queue)->setEventRate( + static_cast<Sensor const*>(sensor), us2ns(usec)); +} + +int ASensorEventQueue_hasEvents(ASensorEventQueue* queue) +{ + struct pollfd pfd; + pfd.fd = static_cast<SensorEventQueue*>(queue)->getFd(); + pfd.events = POLLIN; + pfd.revents = 0; + + int nfd = poll(&pfd, 1, 0); + + if (nfd < 0) + return -errno; + + if (pfd.revents != POLLIN) + return -1; + + return (nfd == 0) ? 0 : 1; +} + +ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, + ASensorEvent* events, size_t count) +{ + return static_cast<SensorEventQueue*>(queue)->read(events, count); +} + + +/*****************************************************************************/ + +const char* ASensor_getName(ASensor const* sensor) +{ + return static_cast<Sensor const*>(sensor)->getName().string(); +} + +const char* ASensor_getVendor(ASensor const* sensor) +{ + return static_cast<Sensor const*>(sensor)->getVendor().string(); +} + +int ASensor_getType(ASensor const* sensor) +{ + return static_cast<Sensor const*>(sensor)->getType(); +} + +float ASensor_getResolution(ASensor const* sensor) +{ + return static_cast<Sensor const*>(sensor)->getResolution(); +} + +int ASensor_getMinDelay(ASensor const* sensor) +{ + return static_cast<Sensor const*>(sensor)->getMinDelay(); +} diff --git a/native/include/android/asset_manager.h b/native/include/android/asset_manager.h new file mode 100644 index 0000000..89989f8 --- /dev/null +++ b/native/include/android/asset_manager.h @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef ANDROID_ASSET_MANAGER_H +#define ANDROID_ASSET_MANAGER_H + +#include <jni.h> + +#ifdef __cplusplus +extern "C" { +#endif + +struct AAssetManager; +typedef struct AAssetManager AAssetManager; + +struct AAssetDir; +typedef struct AAssetDir AAssetDir; + +struct AAsset; +typedef struct AAsset AAsset; + +/* Available modes for opening assets */ +enum { + AASSET_MODE_UNKNOWN = 0, + AASSET_MODE_RANDOM = 1, + AASSET_MODE_STREAMING = 2, + AASSET_MODE_BUFFER = 3 +}; + + +/** + * Given a Dalvik AssetManager object, obtain the corresponding native AAssetManager + * object. Note that the caller is responsible for obtaining and holding a VM reference + * to the jobject to prevent its being garbage collected while the native object is + * in use. + */ +AAssetManager* AAssetManager_fromJava(JNIEnv* env, jobject assetManager); + +/** + * Open the named directory within the asset hierarchy. The directory can then + * be inspected with the AAssetDir functions. To open the top-level directory, + * pass in "" as the dirName. + * + * The object returned here should be freed by calling AAssetDir_close(). + */ +AAssetDir* AAssetManager_openDir(AAssetManager* mgr, const char* dirName); + +/** + * Open an asset. + * + * The object returned here should be freed by calling AAsset_close(). + */ +AAsset* AAssetManager_open(AAssetManager* mgr, const char* filename, int mode); + +/** + * Iterate over the files in an asset directory. A NULL string is returned + * when all the file names have been returned. + * + * The returned file name is suitable for passing to AAssetManager_open(). + * + * The string returned here is owned by the AssetDir implementation and is not + * guaranteed to remain valid if any other calls are made on this AAssetDir + * instance. + */ +const char* AAssetDir_getNextFileName(AAssetDir* assetDir); + +/** + * Reset the iteration state of AAssetDir_getNextFileName() to the beginning. + */ +void AAssetDir_rewind(AAssetDir* assetDir); + +/** + * Close an opened AAssetDir, freeing any related resources. + */ +void AAssetDir_close(AAssetDir* assetDir); + +/** + * Attempt to read 'count' bytes of data from the current offset. + * + * Returns the number of bytes read, zero on EOF, or < 0 on error. + */ +int AAsset_read(AAsset* asset, void* buf, size_t count); + +/** + * Seek to the specified offset within the asset data. 'whence' uses the + * same constants as lseek()/fseek(). + * + * Returns the new position on success, or (off_t) -1 on error. + */ +off_t AAsset_seek(AAsset* asset, off_t offset, int whence); + +/** + * Close the asset, freeing all associated resources. + */ +void AAsset_close(AAsset* asset); + +/** + * Get a pointer to a buffer holding the entire contents of the assset. + * + * Returns NULL on failure. + */ +const void* AAsset_getBuffer(AAsset* asset); + +/** + * Report the total size of the asset data. + */ +off_t AAsset_getLength(AAsset* asset); + +/** + * Report the total amount of asset data that can be read from the current position. + */ +off_t AAsset_getRemainingLength(AAsset* asset); + +/** + * Open a new file descriptor that can be used to read the asset data. + * + * Returns < 0 if direct fd access is not possible (for example, if the asset is + * compressed). + */ +int AAsset_openFileDescriptor(AAsset* asset, off_t* outStart, off_t* outLength); + +/** + * Returns whether this asset's internal buffer is allocated in ordinary RAM (i.e. not + * mmapped). + */ +int AAsset_isAllocated(AAsset* asset); + + + +#ifdef __cplusplus +}; +#endif + +#endif // ANDROID_ASSET_MANAGER_H diff --git a/native/include/android/input.h b/native/include/android/input.h new file mode 100644 index 0000000..243c33c --- /dev/null +++ b/native/include/android/input.h @@ -0,0 +1,727 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _ANDROID_INPUT_H +#define _ANDROID_INPUT_H + +/****************************************************************** + * + * IMPORTANT NOTICE: + * + * This file is part of Android's set of stable system headers + * exposed by the Android NDK (Native Development Kit). + * + * Third-party source AND binary code relies on the definitions + * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES. + * + * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES) + * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS + * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY + * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES + */ + +/* + * Structures and functions to receive and process input events in + * native code. + * + * NOTE: These functions MUST be implemented by /system/lib/libui.so + */ + +#include <stdint.h> +#include <sys/types.h> +#include <android/keycodes.h> +#include <android/looper.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Key states (may be returned by queries about the current state of a + * particular key code, scan code or switch). + */ +enum { + /* The key state is unknown or the requested key itself is not supported. */ + AKEY_STATE_UNKNOWN = -1, + + /* The key is up. */ + AKEY_STATE_UP = 0, + + /* The key is down. */ + AKEY_STATE_DOWN = 1, + + /* The key is down but is a virtual key press that is being emulated by the system. */ + AKEY_STATE_VIRTUAL = 2 +}; + +/* + * Meta key / modifer state. + */ +enum { + /* No meta keys are pressed. */ + AMETA_NONE = 0, + + /* This mask is used to check whether one of the ALT meta keys is pressed. */ + AMETA_ALT_ON = 0x02, + + /* This mask is used to check whether the left ALT meta key is pressed. */ + AMETA_ALT_LEFT_ON = 0x10, + + /* This mask is used to check whether the right ALT meta key is pressed. */ + AMETA_ALT_RIGHT_ON = 0x20, + + /* This mask is used to check whether one of the SHIFT meta keys is pressed. */ + AMETA_SHIFT_ON = 0x01, + + /* This mask is used to check whether the left SHIFT meta key is pressed. */ + AMETA_SHIFT_LEFT_ON = 0x40, + + /* This mask is used to check whether the right SHIFT meta key is pressed. */ + AMETA_SHIFT_RIGHT_ON = 0x80, + + /* This mask is used to check whether the SYM meta key is pressed. */ + AMETA_SYM_ON = 0x04 +}; + +/* + * Input events. + * + * Input events are opaque structures. Use the provided accessors functions to + * read their properties. + */ +struct AInputEvent; +typedef struct AInputEvent AInputEvent; + +/* + * Input event types. + */ +enum { + /* Indicates that the input event is a key event. */ + AINPUT_EVENT_TYPE_KEY = 1, + + /* Indicates that the input event is a motion event. */ + AINPUT_EVENT_TYPE_MOTION = 2 +}; + +/* + * Key event actions. + */ +enum { + /* The key has been pressed down. */ + AKEY_EVENT_ACTION_DOWN = 0, + + /* The key has been released. */ + AKEY_EVENT_ACTION_UP = 1, + + /* Multiple duplicate key events have occurred in a row, or a complex string is + * being delivered. The repeat_count property of the key event contains the number + * of times the given key code should be executed. + */ + AKEY_EVENT_ACTION_MULTIPLE = 2 +}; + +/* + * Key event flags. + */ +enum { + /* This mask is set if the device woke because of this key event. */ + AKEY_EVENT_FLAG_WOKE_HERE = 0x1, + + /* This mask is set if the key event was generated by a software keyboard. */ + AKEY_EVENT_FLAG_SOFT_KEYBOARD = 0x2, + + /* This mask is set if we don't want the key event to cause us to leave touch mode. */ + AKEY_EVENT_FLAG_KEEP_TOUCH_MODE = 0x4, + + /* This mask is set if an event was known to come from a trusted part + * of the system. That is, the event is known to come from the user, + * and could not have been spoofed by a third party component. */ + AKEY_EVENT_FLAG_FROM_SYSTEM = 0x8, + + /* This mask is used for compatibility, to identify enter keys that are + * coming from an IME whose enter key has been auto-labelled "next" or + * "done". This allows TextView to dispatch these as normal enter keys + * for old applications, but still do the appropriate action when + * receiving them. */ + AKEY_EVENT_FLAG_EDITOR_ACTION = 0x10, + + /* When associated with up key events, this indicates that the key press + * has been canceled. Typically this is used with virtual touch screen + * keys, where the user can slide from the virtual key area on to the + * display: in that case, the application will receive a canceled up + * event and should not perform the action normally associated with the + * key. Note that for this to work, the application can not perform an + * action for a key until it receives an up or the long press timeout has + * expired. */ + AKEY_EVENT_FLAG_CANCELED = 0x20, + + /* This key event was generated by a virtual (on-screen) hard key area. + * Typically this is an area of the touchscreen, outside of the regular + * display, dedicated to "hardware" buttons. */ + AKEY_EVENT_FLAG_VIRTUAL_HARD_KEY = 0x40, + + /* This flag is set for the first key repeat that occurs after the + * long press timeout. */ + AKEY_EVENT_FLAG_LONG_PRESS = 0x80, + + /* Set when a key event has AKEY_EVENT_FLAG_CANCELED set because a long + * press action was executed while it was down. */ + AKEY_EVENT_FLAG_CANCELED_LONG_PRESS = 0x100, + + /* Set for AKEY_EVENT_ACTION_UP when this event's key code is still being + * tracked from its initial down. That is, somebody requested that tracking + * started on the key down and a long press has not caused + * the tracking to be canceled. */ + AKEY_EVENT_FLAG_TRACKING = 0x200 +}; + +/* + * Motion event actions. + */ + +/* Bit shift for the action bits holding the pointer index as + * defined by AMOTION_EVENT_ACTION_POINTER_INDEX_MASK. + */ +#define AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT 8 + +enum { + /* Bit mask of the parts of the action code that are the action itself. + */ + AMOTION_EVENT_ACTION_MASK = 0xff, + + /* Bits in the action code that represent a pointer index, used with + * AMOTION_EVENT_ACTION_POINTER_DOWN and AMOTION_EVENT_ACTION_POINTER_UP. Shifting + * down by AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT provides the actual pointer + * index where the data for the pointer going up or down can be found. + */ + AMOTION_EVENT_ACTION_POINTER_INDEX_MASK = 0xff00, + + /* A pressed gesture has started, the motion contains the initial starting location. + */ + AMOTION_EVENT_ACTION_DOWN = 0, + + /* A pressed gesture has finished, the motion contains the final release location + * as well as any intermediate points since the last down or move event. + */ + AMOTION_EVENT_ACTION_UP = 1, + + /* A change has happened during a press gesture (between AMOTION_EVENT_ACTION_DOWN and + * AMOTION_EVENT_ACTION_UP). The motion contains the most recent point, as well as + * any intermediate points since the last down or move event. + */ + AMOTION_EVENT_ACTION_MOVE = 2, + + /* The current gesture has been aborted. + * You will not receive any more points in it. You should treat this as + * an up event, but not perform any action that you normally would. + */ + AMOTION_EVENT_ACTION_CANCEL = 3, + + /* A movement has happened outside of the normal bounds of the UI element. + * This does not provide a full gesture, but only the initial location of the movement/touch. + */ + AMOTION_EVENT_ACTION_OUTSIDE = 4, + + /* A non-primary pointer has gone down. + * The bits in AMOTION_EVENT_ACTION_POINTER_INDEX_MASK indicate which pointer changed. + */ + AMOTION_EVENT_ACTION_POINTER_DOWN = 5, + + /* A non-primary pointer has gone up. + * The bits in AMOTION_EVENT_ACTION_POINTER_INDEX_MASK indicate which pointer changed. + */ + AMOTION_EVENT_ACTION_POINTER_UP = 6 +}; + +/* + * Motion event edge touch flags. + */ +enum { + /* No edges intersected */ + AMOTION_EVENT_EDGE_FLAG_NONE = 0, + + /* Flag indicating the motion event intersected the top edge of the screen. */ + AMOTION_EVENT_EDGE_FLAG_TOP = 0x01, + + /* Flag indicating the motion event intersected the bottom edge of the screen. */ + AMOTION_EVENT_EDGE_FLAG_BOTTOM = 0x02, + + /* Flag indicating the motion event intersected the left edge of the screen. */ + AMOTION_EVENT_EDGE_FLAG_LEFT = 0x04, + + /* Flag indicating the motion event intersected the right edge of the screen. */ + AMOTION_EVENT_EDGE_FLAG_RIGHT = 0x08 +}; + +/* + * Input sources. + * + * Refer to the documentation on android.view.InputDevice for more details about input sources + * and their correct interpretation. + */ +enum { + AINPUT_SOURCE_CLASS_MASK = 0x000000ff, + + AINPUT_SOURCE_CLASS_BUTTON = 0x00000001, + AINPUT_SOURCE_CLASS_POINTER = 0x00000002, + AINPUT_SOURCE_CLASS_NAVIGATION = 0x00000004, + AINPUT_SOURCE_CLASS_POSITION = 0x00000008, + AINPUT_SOURCE_CLASS_JOYSTICK = 0x00000010, +}; + +enum { + AINPUT_SOURCE_UNKNOWN = 0x00000000, + + AINPUT_SOURCE_KEYBOARD = 0x00000100 | AINPUT_SOURCE_CLASS_BUTTON, + AINPUT_SOURCE_DPAD = 0x00000200 | AINPUT_SOURCE_CLASS_BUTTON, + AINPUT_SOURCE_GAMEPAD = 0x00000400 | AINPUT_SOURCE_CLASS_BUTTON, + AINPUT_SOURCE_TOUCHSCREEN = 0x00001000 | AINPUT_SOURCE_CLASS_POINTER, + AINPUT_SOURCE_MOUSE = 0x00002000 | AINPUT_SOURCE_CLASS_POINTER, + AINPUT_SOURCE_TRACKBALL = 0x00010000 | AINPUT_SOURCE_CLASS_NAVIGATION, + AINPUT_SOURCE_TOUCHPAD = 0x00100000 | AINPUT_SOURCE_CLASS_POSITION, + AINPUT_SOURCE_JOYSTICK_LEFT = 0x01000000 | AINPUT_SOURCE_CLASS_JOYSTICK, + AINPUT_SOURCE_JOYSTICK_RIGHT = 0x02000000 | AINPUT_SOURCE_CLASS_JOYSTICK, +}; + +/* + * 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. + * Calling these functions on input events of other types will yield undefined behavior. + */ + +/*** Accessors for all input events. ***/ + +/* Get the input event type. */ +int32_t AInputEvent_getType(const AInputEvent* event); + +/* Get the id for the device that an input event came from. + * + * Input events can be generated by multiple different input devices. + * Use the input device id to obtain information about the input + * device that was responsible for generating a particular event. + * + * An input device id of 0 indicates that the event didn't come from a physical device; + * other numbers are arbitrary and you shouldn't depend on the values. + * Use the provided input device query API to obtain information about input devices. + */ +int32_t AInputEvent_getDeviceId(const AInputEvent* event); + +/* Get the input event source. */ +int32_t AInputEvent_getSource(const AInputEvent* event); + +/*** Accessors for key events only. ***/ + +/* Get the key event action. */ +int32_t AKeyEvent_getAction(const AInputEvent* key_event); + +/* Get the key event flags. */ +int32_t AKeyEvent_getFlags(const AInputEvent* key_event); + +/* Get the key code of the key event. + * This is the physical key that was pressed, not the Unicode character. */ +int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event); + +/* Get the hardware key id of this key event. + * These values are not reliable and vary from device to device. */ +int32_t AKeyEvent_getScanCode(const AInputEvent* key_event); + +/* Get the meta key state. */ +int32_t AKeyEvent_getMetaState(const AInputEvent* key_event); + +/* Get the repeat count of the event. + * For both key up an key down events, this is the number of times the key has + * repeated with the first down starting at 0 and counting up from there. For + * multiple key events, this is the number of down/up pairs that have occurred. */ +int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event); + +/* Get the time of the most recent key down event, in the + * java.lang.System.nanoTime() time base. If this is a down event, + * this will be the same as eventTime. + * Note that when chording keys, this value is the down time of the most recently + * pressed key, which may not be the same physical key of this event. */ +int64_t AKeyEvent_getDownTime(const AInputEvent* key_event); + +/* Get the time this event occurred, in the + * java.lang.System.nanoTime() time base. */ +int64_t AKeyEvent_getEventTime(const AInputEvent* key_event); + +/*** Accessors for motion events only. ***/ + +/* Get the combined motion event action code and pointer index. */ +int32_t AMotionEvent_getAction(const AInputEvent* motion_event); + +/* Get the state of any meta / modifier keys that were in effect when the + * event was generated. */ +int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event); + +/* Get a bitfield indicating which edges, if any, were touched by this motion event. + * For touch events, clients can use this to determine if the user's finger was + * touching the edge of the display. */ +int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event); + +/* Get the time when the user originally pressed down to start a stream of + * position events, in the java.lang.System.nanoTime() time base. */ +int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event); + +/* Get the time when this specific event was generated, + * in the java.lang.System.nanoTime() time base. */ +int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event); + +/* Get the X coordinate offset. + * For touch events on the screen, this is the delta that was added to the raw + * screen coordinates to adjust for the absolute position of the containing windows + * and views. */ +float AMotionEvent_getXOffset(const AInputEvent* motion_event); + +/* Get the precision of the Y coordinates being reported. + * For touch events on the screen, this is the delta that was added to the raw + * screen coordinates to adjust for the absolute position of the containing windows + * and views. */ +float AMotionEvent_getYOffset(const AInputEvent* motion_event); + +/* Get the precision of the X coordinates being reported. + * You can multiply this number with an X coordinate sample to find the + * actual hardware value of the X coordinate. */ +float AMotionEvent_getXPrecision(const AInputEvent* motion_event); + +/* Get the precision of the Y coordinates being reported. + * You can multiply this number with a Y coordinate sample to find the + * actual hardware value of the Y coordinate. */ +float AMotionEvent_getYPrecision(const AInputEvent* motion_event); + +/* Get the number of pointers of data contained in this event. + * Always >= 1. */ +size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event); + +/* Get the pointer identifier associated with a particular pointer + * data index is this event. The identifier tells you the actual pointer + * number associated with the data, accounting for individual pointers + * going up and down since the start of the current gesture. */ +int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index); + +/* Get the original raw X coordinate of this event. + * For touch events on the screen, this is the original location of the event + * on the screen, before it had been adjusted for the containing window + * and views. */ +float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index); + +/* Get the original raw X coordinate of this event. + * For touch events on the screen, this is the original location of the event + * on the screen, before it had been adjusted for the containing window + * and views. */ +float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index); + +/* Get the current X coordinate of this event for the given pointer index. + * Whole numbers are pixels; the value may have a fraction for input devices + * that are sub-pixel precise. */ +float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index); + +/* Get the current Y coordinate of this event for the given pointer index. + * Whole numbers are pixels; the value may have a fraction for input devices + * that are sub-pixel precise. */ +float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index); + +/* Get the current pressure of this event for the given pointer index. + * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure), + * however values higher than 1 may be generated depending on the calibration of + * the input device. */ +float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index); + +/* Get the current scaled value of the approximate size for the given pointer index. + * This represents some approximation of the area of the screen being + * pressed; the actual value in pixels corresponding to the + * touch is normalized with the device specific range of values + * and scaled to a value between 0 and 1. The value of size can be used to + * determine fat touch events. */ +float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index); + +/* Get the current length of the major axis of an ellipse that describes the touch area + * at the point of contact for the given pointer index. */ +float AMotionEvent_getTouchMajor(const AInputEvent* motion_event, size_t pointer_index); + +/* Get the current length of the minor axis of an ellipse that describes the touch area + * at the point of contact for the given pointer index. */ +float AMotionEvent_getTouchMinor(const AInputEvent* motion_event, size_t pointer_index); + +/* Get the current length of the major axis of an ellipse that describes the size + * of the approaching tool for the given pointer index. + * The tool area represents the estimated size of the finger or pen that is + * touching the device independent of its actual touch area at the point of contact. */ +float AMotionEvent_getToolMajor(const AInputEvent* motion_event, size_t pointer_index); + +/* Get the current length of the minor axis of an ellipse that describes the size + * of the approaching tool for the given pointer index. + * The tool area represents the estimated size of the finger or pen that is + * touching the device independent of its actual touch area at the point of contact. */ +float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_index); + +/* Get the current orientation of the touch area and tool area in radians clockwise from + * vertical for the given pointer index. + * An angle of 0 degrees indicates that the major axis of contact is oriented + * 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/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); + +/* Get the number of historical points in this event. These are movements that + * have occurred between this event and the previous event. This only applies + * to AMOTION_EVENT_ACTION_MOVE events -- all other actions will have a size of 0. + * Historical samples are indexed from oldest to newest. */ +size_t AMotionEvent_getHistorySize(const AInputEvent* motion_event); + +/* Get the time that a historical movement occurred between this event and + * the previous event, in the java.lang.System.nanoTime() time base. */ +int64_t AMotionEvent_getHistoricalEventTime(AInputEvent* motion_event, + size_t history_index); + +/* Get the historical raw X coordinate of this event for the given pointer index that + * occurred between this event and the previous motion event. + * For touch events on the screen, this is the original location of the event + * on the screen, before it had been adjusted for the containing window + * and views. + * Whole numbers are pixels; the value may have a fraction for input devices + * that are sub-pixel precise. */ +float AMotionEvent_getHistoricalRawX(const AInputEvent* motion_event, size_t pointer_index); + +/* Get the historical raw Y coordinate of this event for the given pointer index that + * occurred between this event and the previous motion event. + * For touch events on the screen, this is the original location of the event + * on the screen, before it had been adjusted for the containing window + * and views. + * Whole numbers are pixels; the value may have a fraction for input devices + * that are sub-pixel precise. */ +float AMotionEvent_getHistoricalRawY(const AInputEvent* motion_event, size_t pointer_index); + +/* Get the historical X coordinate of this event for the given pointer index that + * occurred between this event and the previous motion event. + * Whole numbers are pixels; the value may have a fraction for input devices + * that are sub-pixel precise. */ +float AMotionEvent_getHistoricalX(AInputEvent* motion_event, size_t pointer_index, + size_t history_index); + +/* Get the historical Y coordinate of this event for the given pointer index that + * occurred between this event and the previous motion event. + * Whole numbers are pixels; the value may have a fraction for input devices + * that are sub-pixel precise. */ +float AMotionEvent_getHistoricalY(AInputEvent* motion_event, size_t pointer_index, + size_t history_index); + +/* Get the historical pressure of this event for the given pointer index that + * occurred between this event and the previous motion event. + * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure), + * however values higher than 1 may be generated depending on the calibration of + * the input device. */ +float AMotionEvent_getHistoricalPressure(AInputEvent* motion_event, size_t pointer_index, + size_t history_index); + +/* Get the current scaled value of the approximate size for the given pointer index that + * occurred between this event and the previous motion event. + * This represents some approximation of the area of the screen being + * pressed; the actual value in pixels corresponding to the + * touch is normalized with the device specific range of values + * and scaled to a value between 0 and 1. The value of size can be used to + * determine fat touch events. */ +float AMotionEvent_getHistoricalSize(AInputEvent* motion_event, size_t pointer_index, + size_t history_index); + +/* Get the historical length of the major axis of an ellipse that describes the touch area + * at the point of contact for the given pointer index that + * occurred between this event and the previous motion event. */ +float AMotionEvent_getHistoricalTouchMajor(const AInputEvent* motion_event, size_t pointer_index, + size_t history_index); + +/* Get the historical length of the minor axis of an ellipse that describes the touch area + * at the point of contact for the given pointer index that + * occurred between this event and the previous motion event. */ +float AMotionEvent_getHistoricalTouchMinor(const AInputEvent* motion_event, size_t pointer_index, + size_t history_index); + +/* Get the historical length of the major axis of an ellipse that describes the size + * of the approaching tool for the given pointer index that + * occurred between this event and the previous motion event. + * The tool area represents the estimated size of the finger or pen that is + * touching the device independent of its actual touch area at the point of contact. */ +float AMotionEvent_getHistoricalToolMajor(const AInputEvent* motion_event, size_t pointer_index, + size_t history_index); + +/* Get the historical length of the minor axis of an ellipse that describes the size + * of the approaching tool for the given pointer index that + * occurred between this event and the previous motion event. + * The tool area represents the estimated size of the finger or pen that is + * touching the device independent of its actual touch area at the point of contact. */ +float AMotionEvent_getHistoricalToolMinor(const AInputEvent* motion_event, size_t pointer_index, + size_t history_index); + +/* Get the historical orientation of the touch area and tool area in radians clockwise from + * vertical for the given pointer index that + * occurred between this event and the previous motion event. + * An angle of 0 degrees indicates that the major axis of contact is oriented + * 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/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); + + +/* + * Input queue + * + * An input queue is the facility through which you retrieve input + * events. + */ +struct AInputQueue; +typedef struct AInputQueue AInputQueue; + +/* + * Add this input queue to a looper for processing. See + * ALooper_addFd() for information on the callback and data params. + */ +void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper, + ALooper_callbackFunc* callback, void* data); + +/* + * Remove the input queue from the looper it is currently attached to. + */ +void AInputQueue_detachLooper(AInputQueue* queue); + +/* + * Returns true if there are one or more events available in the + * input queue. Returns 1 if the queue has events; 0 if + * it does not have events; and a negative value if there is an error. + */ +int32_t AInputQueue_hasEvents(AInputQueue* queue); + +/* + * Returns the next available event from the queue. Returns a negative + * value if no events are available or an error has occurred. + */ +int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent); + +/* + * Sends the key for standard pre-dispatching -- that is, possibly deliver + * it to the current IME to be consumed before the app. Returns 0 if it + * was not pre-dispatched, meaning you can process it right now. If non-zero + * is returned, you must abandon the current event processing and allow the + * event to appear again in the event queue (if it does not get consumed during + * pre-dispatching). + */ +int32_t AInputQueue_preDispatchEvent(AInputQueue* queue, AInputEvent* event); + +/* + * Report that dispatching has finished with the given event. + * This must be called after receiving an event with AInputQueue_get_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 + +#endif // _ANDROID_INPUT_H diff --git a/native/include/android/keycodes.h b/native/include/android/keycodes.h new file mode 100644 index 0000000..496eccc --- /dev/null +++ b/native/include/android/keycodes.h @@ -0,0 +1,166 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _ANDROID_KEYCODES_H +#define _ANDROID_KEYCODES_H + +/****************************************************************** + * + * IMPORTANT NOTICE: + * + * This file is part of Android's set of stable system headers + * exposed by the Android NDK (Native Development Kit). + * + * Third-party source AND binary code relies on the definitions + * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES. + * + * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES) + * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS + * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY + * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES + */ + +#include <sys/types.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Key codes. + */ +enum { + AKEYCODE_UNKNOWN = 0, + AKEYCODE_SOFT_LEFT = 1, + AKEYCODE_SOFT_RIGHT = 2, + AKEYCODE_HOME = 3, + AKEYCODE_BACK = 4, + AKEYCODE_CALL = 5, + AKEYCODE_ENDCALL = 6, + AKEYCODE_0 = 7, + AKEYCODE_1 = 8, + AKEYCODE_2 = 9, + AKEYCODE_3 = 10, + AKEYCODE_4 = 11, + AKEYCODE_5 = 12, + AKEYCODE_6 = 13, + AKEYCODE_7 = 14, + AKEYCODE_8 = 15, + AKEYCODE_9 = 16, + AKEYCODE_STAR = 17, + AKEYCODE_POUND = 18, + AKEYCODE_DPAD_UP = 19, + AKEYCODE_DPAD_DOWN = 20, + AKEYCODE_DPAD_LEFT = 21, + AKEYCODE_DPAD_RIGHT = 22, + AKEYCODE_DPAD_CENTER = 23, + AKEYCODE_VOLUME_UP = 24, + AKEYCODE_VOLUME_DOWN = 25, + AKEYCODE_POWER = 26, + AKEYCODE_CAMERA = 27, + AKEYCODE_CLEAR = 28, + AKEYCODE_A = 29, + AKEYCODE_B = 30, + AKEYCODE_C = 31, + AKEYCODE_D = 32, + AKEYCODE_E = 33, + AKEYCODE_F = 34, + AKEYCODE_G = 35, + AKEYCODE_H = 36, + AKEYCODE_I = 37, + AKEYCODE_J = 38, + AKEYCODE_K = 39, + AKEYCODE_L = 40, + AKEYCODE_M = 41, + AKEYCODE_N = 42, + AKEYCODE_O = 43, + AKEYCODE_P = 44, + AKEYCODE_Q = 45, + AKEYCODE_R = 46, + AKEYCODE_S = 47, + AKEYCODE_T = 48, + AKEYCODE_U = 49, + AKEYCODE_V = 50, + AKEYCODE_W = 51, + AKEYCODE_X = 52, + AKEYCODE_Y = 53, + AKEYCODE_Z = 54, + AKEYCODE_COMMA = 55, + AKEYCODE_PERIOD = 56, + AKEYCODE_ALT_LEFT = 57, + AKEYCODE_ALT_RIGHT = 58, + AKEYCODE_SHIFT_LEFT = 59, + AKEYCODE_SHIFT_RIGHT = 60, + AKEYCODE_TAB = 61, + AKEYCODE_SPACE = 62, + AKEYCODE_SYM = 63, + AKEYCODE_EXPLORER = 64, + AKEYCODE_ENVELOPE = 65, + AKEYCODE_ENTER = 66, + AKEYCODE_DEL = 67, + AKEYCODE_GRAVE = 68, + AKEYCODE_MINUS = 69, + AKEYCODE_EQUALS = 70, + AKEYCODE_LEFT_BRACKET = 71, + AKEYCODE_RIGHT_BRACKET = 72, + AKEYCODE_BACKSLASH = 73, + AKEYCODE_SEMICOLON = 74, + AKEYCODE_APOSTROPHE = 75, + AKEYCODE_SLASH = 76, + AKEYCODE_AT = 77, + AKEYCODE_NUM = 78, + AKEYCODE_HEADSETHOOK = 79, + AKEYCODE_FOCUS = 80, // *Camera* focus + AKEYCODE_PLUS = 81, + AKEYCODE_MENU = 82, + AKEYCODE_NOTIFICATION = 83, + AKEYCODE_SEARCH = 84, + AKEYCODE_MEDIA_PLAY_PAUSE= 85, + AKEYCODE_MEDIA_STOP = 86, + AKEYCODE_MEDIA_NEXT = 87, + AKEYCODE_MEDIA_PREVIOUS = 88, + AKEYCODE_MEDIA_REWIND = 89, + AKEYCODE_MEDIA_FAST_FORWARD = 90, + AKEYCODE_MUTE = 91, + AKEYCODE_PAGE_UP = 92, + AKEYCODE_PAGE_DOWN = 93, + AKEYCODE_PICTSYMBOLS = 94, + AKEYCODE_SWITCH_CHARSET = 95, + AKEYCODE_BUTTON_A = 96, + AKEYCODE_BUTTON_B = 97, + AKEYCODE_BUTTON_C = 98, + AKEYCODE_BUTTON_X = 99, + AKEYCODE_BUTTON_Y = 100, + AKEYCODE_BUTTON_Z = 101, + AKEYCODE_BUTTON_L1 = 102, + AKEYCODE_BUTTON_R1 = 103, + AKEYCODE_BUTTON_L2 = 104, + AKEYCODE_BUTTON_R2 = 105, + AKEYCODE_BUTTON_THUMBL = 106, + AKEYCODE_BUTTON_THUMBR = 107, + AKEYCODE_BUTTON_START = 108, + AKEYCODE_BUTTON_SELECT = 109, + AKEYCODE_BUTTON_MODE = 110, + + // NOTE: If you add a new keycode here you must also add it to several other files. + // Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list. +}; + +#ifdef __cplusplus +} +#endif + +#endif // _ANDROID_KEYCODES_H diff --git a/native/include/android/looper.h b/native/include/android/looper.h new file mode 100644 index 0000000..2917216 --- /dev/null +++ b/native/include/android/looper.h @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef ANDROID_LOOPER_H +#define ANDROID_LOOPER_H + +#include <poll.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * ALooper + * + * A looper is the state tracking an event loop for a thread. + * Loopers do not define event structures or other such things; rather + * they are a lower-level facility to attach one or more discrete objects + * listening for an event. An "event" here is simply data available on + * a file descriptor: each attached object has an associated file descriptor, + * and waiting for "events" means (internally) polling on all of these file + * descriptors until one or more of them have data available. + * + * A thread can have only one ALooper associated with it. + */ +struct ALooper; +typedef struct ALooper ALooper; + +/** + * For callback-based event loops, this is the prototype of the function + * that is called. It is given the file descriptor it is associated with, + * a bitmask of the poll events that were triggered (typically POLLIN), and + * the data pointer that was originally supplied. + * + * Implementations should return 1 to continue receiving callbacks, or 0 + * to have this file descriptor and callback unregistered from the looper. + */ +typedef int ALooper_callbackFunc(int fd, int events, void* data); + +/** + * Return the ALooper associated with the calling thread, or NULL if + * there is not one. + */ +ALooper* ALooper_forThread(); + +enum { + /** + * Option for ALooper_prepare: this ALooper will accept calls to + * ALooper_addFd() that do not have a callback (that is provide NULL + * for the callback). In this case the caller of ALooper_pollOnce() + * or ALooper_pollAll() MUST check the return from these functions to + * discover when data is available on such fds and process it. + */ + ALOOPER_PREPARE_ALLOW_NON_CALLBACKS = 1<<0 +}; + +/** + * Prepare an ALooper associated with the calling thread, and return it. + * If the thread already has an ALooper, it is returned. Otherwise, a new + * one is created, associated with the thread, and returned. + * + * The opts may be ALOOPER_PREPARE_ALLOW_NON_CALLBACKS or 0. + */ +ALooper* ALooper_prepare(int32_t opts); + +enum { + /** + * Result from ALooper_pollOnce() and ALooper_pollAll(): one or + * more callbacks were executed. + */ + ALOOPER_POLL_CALLBACK = -1, + + /** + * Result from ALooper_pollOnce() and ALooper_pollAll(): the + * timeout expired. + */ + ALOOPER_POLL_TIMEOUT = -2, + + /** + * Result from ALooper_pollOnce() and ALooper_pollAll(): an error + * occurred. + */ + ALOOPER_POLL_ERROR = -3, +}; + +/** + * Wait for events to be available, with optional timeout in milliseconds. + * Invokes callbacks for all file descriptors on which an event occurred. + * + * If the timeout is zero, returns immediately without blocking. + * If the timeout is negative, waits indefinitely until an event appears. + * + * Returns ALOOPER_POLL_CALLBACK if a callback was invoked. + * + * Returns ALOOPER_POLL_TIMEOUT if there was no data before the given + * timeout expired. + * + * Returns ALOPER_POLL_ERROR if an error occurred. + * + * Returns a value >= 0 containing a file descriptor if it has data + * and it has no callback function (requiring the caller here to handle it). + * In this (and only this) case outEvents and outData will contain the poll + * events and data associated with the fd. + * + * This method does not return until it has finished invoking the appropriate callbacks + * for all file descriptors that were signalled. + */ +int32_t ALooper_pollOnce(int timeoutMillis, int* outEvents, void** outData); + +/** + * Like ALooper_pollOnce(), but performs all pending callbacks until all + * data has been consumed or a file descriptor is available with no callback. + * This function will never return ALOOPER_POLL_CALLBACK. + */ +int32_t ALooper_pollAll(int timeoutMillis, int* outEvents, void** outData); + +/** + * Acquire a reference on the given ALooper object. This prevents the object + * from being deleted until the reference is removed. This is only needed + * to safely hand an ALooper from one thread to another. + */ +void ALooper_acquire(ALooper* looper); + +/** + * Remove a reference that was previously acquired with ALooper_acquire(). + */ +void ALooper_release(ALooper* looper); + +/** + * Add a new file descriptor to be polled by the looper. If the same file + * descriptor was previously added, it is replaced. + * + * "fd" is the file descriptor to be added. + * "events" are the poll events to wake up on. Typically this is POLLIN. + * "callback" is the function to call when there is an event on the file + * descriptor. + * "id" is an identifier to associated with this file descriptor, or 0. + * "data" is a private data pointer to supply to the callback. + * + * There are two main uses of this function: + * + * (1) If "callback" is non-NULL, then + * this function will be called when there is data on the file descriptor. It + * should execute any events it has pending, appropriately reading from the + * file descriptor. + * + * (2) If "callback" is NULL, the fd will be returned by ALooper_pollOnce + * when it has data available, requiring the caller to take care of processing + * it. + */ +void ALooper_addFd(ALooper* looper, int fd, int events, + ALooper_callbackFunc* callback, void* data); + +/** + * Remove a previously added file descriptor from the looper. + */ +int32_t ALooper_removeFd(ALooper* looper, int fd); + +#ifdef __cplusplus +}; +#endif + +#endif // ANDROID_NATIVE_WINDOW_H diff --git a/native/include/android/native_activity.h b/native/include/android/native_activity.h new file mode 100644 index 0000000..ee4204d --- /dev/null +++ b/native/include/android/native_activity.h @@ -0,0 +1,254 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef ANDROID_NATIVE_ACTIVITY_H +#define ANDROID_NATIVE_ACTIVITY_H + +#include <stdint.h> +#include <sys/types.h> + +#include <jni.h> + +#include <android/asset_manager.h> +#include <android/input.h> +#include <android/native_window.h> + +#ifdef __cplusplus +extern "C" { +#endif + +struct ANativeActivityCallbacks; + +/** + * This structure defines the native side of an android.app.NativeActivity. + * It is created by the framework, and handed to the application's native + * code as it is being launched. + */ +typedef struct ANativeActivity { + /** + * Pointer to the callback function table of the native application. + * You can set the functions here to your own callbacks. The callbacks + * pointer itself here should not be changed; it is allocated and managed + * for you by the framework. + */ + struct ANativeActivityCallbacks* callbacks; + + /** + * The global handle on the process's Java VM. + */ + JavaVM* vm; + + /** + * JNI context for the main thread of the app. Note that this field + * can ONLY be used from the main thread of the process; that is, the + * thread that calls into the ANativeActivityCallbacks. + */ + JNIEnv* env; + + /** + * The NativeActivity Java class. + */ + jobject clazz; + + /** + * Path to this application's internal data directory. + */ + const char* internalDataPath; + + /** + * Path to this application's external (removable/mountable) data directory. + */ + const char* externalDataPath; + + /** + * The platform's SDK version code. + */ + int32_t sdkVersion; + + /** + * This is the native instance of the application. It is not used by + * the framework, but can be set by the application to its own instance + * state. + */ + void* instance; + + /** + * Pointer to the Asset Manager instance for the application. The application + * uses this to access binary assets bundled inside its own .apk file. + */ + AAssetManager* assetManager; +} ANativeActivity; + +/** + * These are the callbacks the framework makes into a native application. + * All of these callbacks happen on the main thread of the application. + * By default, all callbacks are NULL; set to a pointer to your own function + * to have it called. + */ +typedef struct ANativeActivityCallbacks { + /** + * NativeActivity has started. See Java documentation for Activity.onStart() + * for more information. + */ + void (*onStart)(ANativeActivity* activity); + + /** + * NativeActivity has resumed. See Java documentation for Activity.onResume() + * for more information. + */ + void (*onResume)(ANativeActivity* activity); + + /** + * Framework is asking NativeActivity to save its current instance state. + * See Java documentation for Activity.onSaveInstanceState() for more + * information. The returned pointer needs to be created with malloc(); + * the framework will call free() on it for you. You also must fill in + * outSize with the number of bytes in the allocation. Note that the + * saved state will be persisted, so it can not contain any active + * entities (pointers to memory, file descriptors, etc). + */ + void* (*onSaveInstanceState)(ANativeActivity* activity, size_t* outSize); + + /** + * NativeActivity has paused. See Java documentation for Activity.onPause() + * for more information. + */ + void (*onPause)(ANativeActivity* activity); + + /** + * NativeActivity has stopped. See Java documentation for Activity.onStop() + * for more information. + */ + void (*onStop)(ANativeActivity* activity); + + /** + * NativeActivity is being destroyed. See Java documentation for Activity.onDestroy() + * for more information. + */ + void (*onDestroy)(ANativeActivity* activity); + + /** + * Focus has changed in this NativeActivity's window. This is often used, + * for example, to pause a game when it loses input focus. + */ + void (*onWindowFocusChanged)(ANativeActivity* activity, int hasFocus); + + /** + * The drawing window for this native activity has been created. You + * can use the given native window object to start drawing. + */ + void (*onNativeWindowCreated)(ANativeActivity* activity, ANativeWindow* window); + + /** + * The drawing window for this native activity has been resized. You should + * retrieve the new size from the window and ensure that your rendering in + * it now matches. + */ + void (*onNativeWindowResized)(ANativeActivity* activity, ANativeWindow* window); + + /** + * The drawing window for this native activity needs to be redrawn. To avoid + * transient artifacts during screen changes (such resizing after rotation), + * applications should not return from this function until they have finished + * drawing their window in its current state. + */ + void (*onNativeWindowRedrawNeeded)(ANativeActivity* activity, ANativeWindow* window); + + /** + * The drawing window for this native activity is going to be destroyed. + * You MUST ensure that you do not touch the window object after returning + * from this function: in the common case of drawing to the window from + * another thread, that means the implementation of this callback must + * properly synchronize with the other thread to stop its drawing before + * returning from here. + */ + void (*onNativeWindowDestroyed)(ANativeActivity* activity, ANativeWindow* window); + + /** + * The input queue for this native activity's window has been created. + * You can use the given input queue to start retrieving input events. + */ + void (*onInputQueueCreated)(ANativeActivity* activity, AInputQueue* queue); + + /** + * The input queue for this native activity's window is being destroyed. + * You should no longer try to reference this object upon returning from this + * function. + */ + void (*onInputQueueDestroyed)(ANativeActivity* activity, AInputQueue* queue); + + /** + * The rectangle in the window in which content should be placed has changed. + */ + void (*onContentRectChanged)(ANativeActivity* activity, const ARect* rect); + + /** + * The system is running low on memory. Use this callback to release + * resources you do not need, to help the system avoid killing more + * important processes. + */ + void (*onLowMemory)(ANativeActivity* activity); +} ANativeActivityCallbacks; + +/** + * This is the function that must be in the native code to instantiate the + * application's native activity. It is called with the activity instance (see + * above); if the code is being instantiated from a previously saved instance, + * the savedState will be non-NULL and point to the saved data. + */ +typedef void ANativeActivity_createFunc(ANativeActivity* activity, + void* savedState, size_t savedStateSize); + +/** + * The name of the function that NativeInstance looks for when launching its + * native code. + */ +extern ANativeActivity_createFunc ANativeActivity_onCreate; + +void ANativeActivity_setWindowFormat(ANativeActivity* activity, int32_t format); + +void ANativeActivity_setWindowFlags(ANativeActivity* activity, + uint32_t addFlags, uint32_t removeFlags); + +/** + * Flags for ANativeActivity_showSoftInput; see the Java InputMethodManager + * API for documentation. + */ +enum { + ANATIVEACTIVITY_SHOW_SOFT_INPUT_IMPLICIT = 0x0001, + ANATIVEACTIVITY_SHOW_SOFT_INPUT_FORCED = 0x0002, +}; + +void ANativeActivity_showSoftInput(ANativeActivity* activity, uint32_t flags); + +/** + * Flags for ANativeActivity_hideSoftInput; see the Java InputMethodManager + * API for documentation. + */ +enum { + ANATIVEACTIVITY_HIDE_SOFT_INPUT_IMPLICIT_ONLY = 0x0001, + ANATIVEACTIVITY_HIDE_SOFT_INPUT_NOT_ALWAYS = 0x0002, +}; + +void ANativeActivity_hideSoftInput(ANativeActivity* activity, uint32_t flags); + +#ifdef __cplusplus +}; +#endif + +#endif // ANDROID_NATIVE_ACTIVITY_H + diff --git a/native/include/android/native_window.h b/native/include/android/native_window.h new file mode 100644 index 0000000..7599d7e --- /dev/null +++ b/native/include/android/native_window.h @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_NATIVE_WINDOW_H +#define ANDROID_NATIVE_WINDOW_H + +#include <android/rect.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Pixel formats that a window can use. + */ +enum { + WINDOW_FORMAT_RGBA_8888 = 1, + WINDOW_FORMAT_RGBX_8888 = 2, + WINDOW_FORMAT_RGB_565 = 4, +}; + +struct ANativeWindow; +typedef struct ANativeWindow ANativeWindow; + +typedef struct ANativeWindow_Buffer { + int32_t width; + int32_t height; + int32_t stride; + int32_t format; + void* bits; + + uint32_t reserved[6]; +} ANativeWindow_Buffer; + +/** + * Acquire a reference on the given ANativeWindow object. This prevents the object + * from being deleted until the reference is removed. + */ +void ANativeWindow_acquire(ANativeWindow* window); + +/** + * Remove a reference that was previously acquired with ANativeWindow_acquire(). + */ +void ANativeWindow_release(ANativeWindow* window); + +/* + * Return the current width in pixels of the window surface. Returns a + * negative value on error. + */ +int32_t ANativeWindow_getWidth(ANativeWindow* window); + +/* + * Return the current height in pixels of the window surface. Returns a + * negative value on error. + */ +int32_t ANativeWindow_getHeight(ANativeWindow* window); + +/* + * Return the current pixel format of the window surface. Returns a + * negative value on error. + */ +int32_t ANativeWindow_getFormat(ANativeWindow* window); + +/* + * Change the format and size of the window buffers. + * + * The width and height control the number of pixels in the buffers, not the + * dimensions of the window on screen. If these are different than the + * window's physical size, then it buffer will be scaled to match that size + * when compositing it to the screen. + * + * For all of these parameters, if 0 is supplied then the window's base + * value will come back in force. + */ +int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window, int32_t width, int32_t height); + +/** + * Lock the window's next drawing surface for writing. + */ +int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer, + ARect* inOutDirtyBounds); + +/** + * Unlock the window's drawing surface after previously locking it, + * posting the new buffer to the display. + */ +int32_t ANativeWindow_unlockAndPost(ANativeWindow* window); + +#ifdef __cplusplus +}; +#endif + +#endif // ANDROID_NATIVE_WINDOW_H diff --git a/native/include/android/native_window_jni.h b/native/include/android/native_window_jni.h new file mode 100644 index 0000000..b9e72ef --- /dev/null +++ b/native/include/android/native_window_jni.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_NATIVE_WINDOW_JNI_H +#define ANDROID_NATIVE_WINDOW_JNI_H + +#include <android/native_window.h> + +#include <jni.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Return the ANativeWindow associated with a Java Surface object, + * for interacting with it through native code. This acquires a reference + * on the ANativeWindow that is returned; be sure to use ANativeWindow_release() + * when done with it so that it doesn't leak. + */ +ANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface); + +#ifdef __cplusplus +}; +#endif + +#endif // ANDROID_NATIVE_WINDOW_H diff --git a/native/include/android/rect.h b/native/include/android/rect.h new file mode 100644 index 0000000..3e81f53 --- /dev/null +++ b/native/include/android/rect.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef ANDROID_RECT_H +#define ANDROID_RECT_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ARect { + int32_t left; + int32_t top; + int32_t right; + int32_t bottom; +} ARect; + +#ifdef __cplusplus +}; +#endif + +#endif // ANDROID_RECT_H diff --git a/native/include/android/sensor.h b/native/include/android/sensor.h new file mode 100644 index 0000000..b4ce024 --- /dev/null +++ b/native/include/android/sensor.h @@ -0,0 +1,256 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef ANDROID_SENSOR_H +#define ANDROID_SENSOR_H + +/****************************************************************** + * + * IMPORTANT NOTICE: + * + * This file is part of Android's set of stable system headers + * exposed by the Android NDK (Native Development Kit). + * + * Third-party source AND binary code relies on the definitions + * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES. + * + * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES) + * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS + * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY + * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES + */ + +/* + * Structures and functions to receive and process sensor events in + * native code. + * + */ + +#include <sys/types.h> + +#include <android/looper.h> + +#ifdef __cplusplus +extern "C" { +#endif + + +/* + * Sensor types + * (keep in sync with hardware/sensor.h) + */ + +enum { + ASENSOR_TYPE_ACCELEROMETER = 1, + ASENSOR_TYPE_MAGNETIC_FIELD = 2, + ASENSOR_TYPE_GYROSCOPE = 4, + ASENSOR_TYPE_LIGHT = 5, + ASENSOR_TYPE_PROXIMITY = 8 +}; + +/* + * Sensor accuracy measure + */ +enum { + ASENSOR_STATUS_UNRELIABLE = 0, + ASENSOR_STATUS_ACCURACY_LOW = 1, + ASENSOR_STATUS_ACCURACY_MEDIUM = 2, + ASENSOR_STATUS_ACCURACY_HIGH = 3 +}; + +/* + * A few useful constants + */ + +/* Earth's gravity in m/s^2 */ +#define ASENSOR_STANDARD_GRAVITY (9.80665f) +/* Maximum magnetic field on Earth's surface in uT */ +#define ASENSOR_MAGNETIC_FIELD_EARTH_MAX (60.0f) +/* Minimum magnetic field on Earth's surface in uT*/ +#define ASENSOR_MAGNETIC_FIELD_EARTH_MIN (30.0f) + +/* + * A sensor event. + */ + +/* NOTE: Must match hardware/sensors.h */ +typedef struct ASensorVector { + union { + float v[3]; + struct { + float x; + float y; + float z; + }; + struct { + float azimuth; + float pitch; + float roll; + }; + }; + int8_t status; + uint8_t reserved[3]; +} ASensorVector; + +/* NOTE: Must match hardware/sensors.h */ +typedef struct ASensorEvent { + int32_t version; /* sizeof(struct ASensorEvent) */ + int32_t sensor; + int32_t type; + int32_t reserved0; + int64_t timestamp; + union { + float data[16]; + ASensorVector vector; + ASensorVector acceleration; + ASensorVector magnetic; + float temperature; + float distance; + float light; + float pressure; + }; + int32_t reserved1[4]; +} ASensorEvent; + + +struct ASensorManager; +typedef struct ASensorManager ASensorManager; + +struct ASensorEventQueue; +typedef struct ASensorEventQueue ASensorEventQueue; + +struct ASensor; +typedef struct ASensor ASensor; +typedef ASensor const* ASensorRef; +typedef ASensorRef const* ASensorList; + +/*****************************************************************************/ + +/* + * Get a reference to the sensor manager. ASensorManager is a singleton. + * + * Example: + * + * ASensorManager* sensorManager = ASensorManager_getInstance(); + * + */ +ASensorManager* ASensorManager_getInstance(); + + +/* + * Returns the list of available sensors. + */ +int ASensorManager_getSensorList(ASensorManager* manager, ASensorList* list); + +/* + * Returns the default sensor for the given type, or NULL if no sensor + * of that type exist. + */ +ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type); + +/* + * Creates a new sensor event queue and associate it with a looper. + */ +ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager, + ALooper* looper, ALooper_callbackFunc* callback, void* data); + +/* + * Destroys the event queue and free all resources associated to it. + */ +int ASensorManager_destroyEventQueue(ASensorManager* manager, ASensorEventQueue* queue); + + +/*****************************************************************************/ + +/* + * Enable the selected sensor. Returns a negative error code on failure. + */ +int ASensorEventQueue_enableSensor(ASensorEventQueue* queue, ASensor const* sensor); + +/* + * Disable the selected sensor. Returns a negative error code on failure. + */ +int ASensorEventQueue_disableSensor(ASensorEventQueue* queue, ASensor const* sensor); + +/* + * Sets the delivery rate of events in microseconds for the given sensor. + * Note that this is a hint only, generally event will arrive at a higher + * rate. It is an error to set a rate inferior to the value returned by + * ASensor_getMinDelay(). + * Returns a negative error code on failure. + */ +int ASensorEventQueue_setEventRate(ASensorEventQueue* queue, ASensor const* sensor, int32_t usec); + +/* + * Returns true if there are one or more events available in the + * sensor queue. Returns 1 if the queue has events; 0 if + * it does not have events; and a negative value if there is an error. + */ +int ASensorEventQueue_hasEvents(ASensorEventQueue* queue); + +/* + * Returns the next available events from the queue. Returns a negative + * value if no events are available or an error has occurred, otherwise + * the number of events returned. + * + * Examples: + * ASensorEvent event; + * ssize_t numEvent = ASensorEventQueue_getEvents(queue, &event, 1); + * + * ASensorEvent eventBuffer[8]; + * ssize_t numEvent = ASensorEventQueue_getEvents(queue, eventBuffer, 8); + * + */ +ssize_t ASensorEventQueue_getEvents(ASensorEventQueue* queue, + ASensorEvent* events, size_t count); + + +/*****************************************************************************/ + +/* + * Returns this sensor's name (non localized) + */ +const char* ASensor_getName(ASensor const* sensor); + +/* + * Returns this sensor's vendor's name (non localized) + */ +const char* ASensor_getVendor(ASensor const* sensor); + +/* + * Return this sensor's type + */ +int ASensor_getType(ASensor const* sensor); + +/* + * Returns this sensors's resolution + */ +float ASensor_getResolution(ASensor const* sensor); + +/* + * Returns the minimum delay allowed between events in microseconds. + * A value of zero means that this sensor doesn't report events at a + * constant rate, but rather only when a new data is available. + */ +int ASensor_getMinDelay(ASensor const* sensor); + + +#ifdef __cplusplus +}; +#endif + +#endif // ANDROID_SENSOR_H diff --git a/native/include/android/window.h b/native/include/android/window.h new file mode 100644 index 0000000..2ab192b --- /dev/null +++ b/native/include/android/window.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef ANDROID_WINDOW_H +#define ANDROID_WINDOW_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Window flags, as per the Java API at android.view.WindowManager.LayoutParams. + */ +enum { + AWINDOW_FLAG_ALLOW_LOCK_WHILE_SCREEN_ON = 0x00000001, + AWINDOW_FLAG_DIM_BEHIND = 0x00000002, + AWINDOW_FLAG_BLUR_BEHIND = 0x00000004, + AWINDOW_FLAG_NOT_FOCUSABLE = 0x00000008, + AWINDOW_FLAG_NOT_TOUCHABLE = 0x00000010, + AWINDOW_FLAG_NOT_TOUCH_MODAL = 0x00000020, + AWINDOW_FLAG_TOUCHABLE_WHEN_WAKING = 0x00000040, + AWINDOW_FLAG_KEEP_SCREEN_ON = 0x00000080, + AWINDOW_FLAG_LAYOUT_IN_SCREEN = 0x00000100, + AWINDOW_FLAG_LAYOUT_NO_LIMITS = 0x00000200, + AWINDOW_FLAG_FULLSCREEN = 0x00000400, + AWINDOW_FLAG_FORCE_NOT_FULLSCREEN = 0x00000800, + AWINDOW_FLAG_DITHER = 0x00001000, + AWINDOW_FLAG_SECURE = 0x00002000, + AWINDOW_FLAG_SCALED = 0x00004000, + AWINDOW_FLAG_IGNORE_CHEEK_PRESSES = 0x00008000, + AWINDOW_FLAG_LAYOUT_INSET_DECOR = 0x00010000, + AWINDOW_FLAG_ALT_FOCUSABLE_IM = 0x00020000, + AWINDOW_FLAG_WATCH_OUTSIDE_TOUCH = 0x00040000, + AWINDOW_FLAG_SHOW_WHEN_LOCKED = 0x00080000, + AWINDOW_FLAG_SHOW_WALLPAPER = 0x00100000, + AWINDOW_FLAG_TURN_SCREEN_ON = 0x00200000, + AWINDOW_FLAG_DISMISS_KEYGUARD = 0x00400000, +}; + +#ifdef __cplusplus +}; +#endif + +#endif // ANDROID_WINDOW_H |