summaryrefslogtreecommitdiffstats
path: root/core/jni
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2011-05-25 14:46:53 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2011-05-25 14:46:53 -0700
commit3c2fb0242b0ec21101959dfa08aad3162a523634 (patch)
tree5f338cb0714dbe36988431320f8919576d91009a /core/jni
parent13412d31650366f41b1f3d9f429cb0a01dd575ef (diff)
parent8148cc3e47e50c916066e2fed562618b5827188f (diff)
downloadframeworks_base-3c2fb0242b0ec21101959dfa08aad3162a523634.zip
frameworks_base-3c2fb0242b0ec21101959dfa08aad3162a523634.tar.gz
frameworks_base-3c2fb0242b0ec21101959dfa08aad3162a523634.tar.bz2
am 8148cc3e: am 86ea1f5f: Initial checkin of spot presentation for touchpad gestures. (DO NOT MERGE)
* commit '8148cc3e47e50c916066e2fed562618b5827188f': Initial checkin of spot presentation for touchpad gestures. (DO NOT MERGE)
Diffstat (limited to 'core/jni')
-rw-r--r--core/jni/Android.mk1
-rw-r--r--core/jni/AndroidRuntime.cpp2
-rw-r--r--core/jni/android_view_PointerIcon.cpp149
-rw-r--r--core/jni/android_view_PointerIcon.h80
4 files changed, 232 insertions, 0 deletions
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index fb65743..91a1935 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -54,6 +54,7 @@ LOCAL_SRC_FILES:= \
android_view_KeyCharacterMap.cpp \
android_view_GLES20Canvas.cpp \
android_view_MotionEvent.cpp \
+ android_view_PointerIcon.cpp \
android_view_VelocityTracker.cpp \
android_text_AndroidCharacter.cpp \
android_text_AndroidBidi.cpp \
diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp
index e4eb692..2e7142a 100644
--- a/core/jni/AndroidRuntime.cpp
+++ b/core/jni/AndroidRuntime.cpp
@@ -170,6 +170,7 @@ extern int register_android_view_InputChannel(JNIEnv* env);
extern int register_android_view_InputQueue(JNIEnv* env);
extern int register_android_view_KeyEvent(JNIEnv* env);
extern int register_android_view_MotionEvent(JNIEnv* env);
+extern int register_android_view_PointerIcon(JNIEnv* env);
extern int register_android_view_VelocityTracker(JNIEnv* env);
extern int register_android_content_res_ObbScanner(JNIEnv* env);
extern int register_android_content_res_Configuration(JNIEnv* env);
@@ -1303,6 +1304,7 @@ static const RegJNIRec gRegJNI[] = {
REG_JNI(register_android_view_InputQueue),
REG_JNI(register_android_view_KeyEvent),
REG_JNI(register_android_view_MotionEvent),
+ REG_JNI(register_android_view_PointerIcon),
REG_JNI(register_android_view_VelocityTracker),
REG_JNI(register_android_content_res_ObbScanner),
diff --git a/core/jni/android_view_PointerIcon.cpp b/core/jni/android_view_PointerIcon.cpp
new file mode 100644
index 0000000..091341a
--- /dev/null
+++ b/core/jni/android_view_PointerIcon.cpp
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2011 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 "PointerIcon-JNI"
+
+#include "JNIHelp.h"
+
+#include "android_view_PointerIcon.h"
+
+#include <android_runtime/AndroidRuntime.h>
+#include <utils/Log.h>
+#include <android/graphics/GraphicsJNI.h>
+
+namespace android {
+
+static struct {
+ jclass clazz;
+ jfieldID mStyle;
+ jfieldID mBitmap;
+ jfieldID mHotSpotX;
+ jfieldID mHotSpotY;
+ jmethodID getSystemIcon;
+ jmethodID load;
+} gPointerIconClassInfo;
+
+
+// --- Global Functions ---
+
+jobject android_view_PointerIcon_getSystemIcon(JNIEnv* env, jobject contextObj, int32_t style) {
+ jobject pointerIconObj = env->CallStaticObjectMethod(gPointerIconClassInfo.clazz,
+ gPointerIconClassInfo.getSystemIcon, contextObj, style);
+ if (env->ExceptionCheck()) {
+ LOGW("An exception occurred while getting a pointer icon with style %d.", style);
+ LOGW_EX(env);
+ env->ExceptionClear();
+ return NULL;
+ }
+ return pointerIconObj;
+}
+
+status_t android_view_PointerIcon_load(JNIEnv* env, jobject pointerIconObj, jobject contextObj,
+ PointerIcon* outPointerIcon) {
+ outPointerIcon->reset();
+
+ if (!pointerIconObj) {
+ return OK;
+ }
+
+ jobject loadedPointerIconObj = env->CallObjectMethod(pointerIconObj,
+ gPointerIconClassInfo.load, contextObj);
+ if (env->ExceptionCheck() || !loadedPointerIconObj) {
+ LOGW("An exception occurred while loading a pointer icon.");
+ LOGW_EX(env);
+ env->ExceptionClear();
+ return UNKNOWN_ERROR;
+ }
+
+ outPointerIcon->style = env->GetIntField(loadedPointerIconObj,
+ gPointerIconClassInfo.mStyle);
+ outPointerIcon->hotSpotX = env->GetFloatField(loadedPointerIconObj,
+ gPointerIconClassInfo.mHotSpotX);
+ outPointerIcon->hotSpotY = env->GetFloatField(loadedPointerIconObj,
+ gPointerIconClassInfo.mHotSpotY);
+
+ jobject bitmapObj = env->GetObjectField(loadedPointerIconObj, gPointerIconClassInfo.mBitmap);
+ if (bitmapObj) {
+ SkBitmap* bitmap = GraphicsJNI::getNativeBitmap(env, bitmapObj);
+ if (bitmap) {
+ outPointerIcon->bitmap = *bitmap; // use a shared pixel ref
+ }
+ env->DeleteLocalRef(bitmapObj);
+ }
+
+ env->DeleteLocalRef(loadedPointerIconObj);
+ return OK;
+}
+
+status_t android_view_PointerIcon_loadSystemIcon(JNIEnv* env, jobject contextObj,
+ int32_t style, PointerIcon* outPointerIcon) {
+ jobject pointerIconObj = android_view_PointerIcon_getSystemIcon(env, contextObj, style);
+ if (!pointerIconObj) {
+ outPointerIcon->reset();
+ return UNKNOWN_ERROR;
+ }
+
+ status_t status = android_view_PointerIcon_load(env, pointerIconObj,
+ contextObj, outPointerIcon);
+ env->DeleteLocalRef(pointerIconObj);
+ return status;
+}
+
+
+// --- JNI Registration ---
+
+#define FIND_CLASS(var, className) \
+ var = env->FindClass(className); \
+ LOG_FATAL_IF(! var, "Unable to find class " className); \
+ var = jclass(env->NewGlobalRef(var));
+
+#define GET_STATIC_METHOD_ID(var, clazz, methodName, methodDescriptor) \
+ var = env->GetStaticMethodID(clazz, methodName, methodDescriptor); \
+ LOG_FATAL_IF(! var, "Unable to find method " methodName);
+
+#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
+ var = env->GetMethodID(clazz, methodName, methodDescriptor); \
+ LOG_FATAL_IF(! var, "Unable to find method " methodName);
+
+#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \
+ var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
+ LOG_FATAL_IF(! var, "Unable to find field " fieldName);
+
+int register_android_view_PointerIcon(JNIEnv* env) {
+ FIND_CLASS(gPointerIconClassInfo.clazz, "android/view/PointerIcon");
+
+ GET_FIELD_ID(gPointerIconClassInfo.mBitmap, gPointerIconClassInfo.clazz,
+ "mBitmap", "Landroid/graphics/Bitmap;");
+
+ GET_FIELD_ID(gPointerIconClassInfo.mStyle, gPointerIconClassInfo.clazz,
+ "mStyle", "I");
+
+ GET_FIELD_ID(gPointerIconClassInfo.mHotSpotX, gPointerIconClassInfo.clazz,
+ "mHotSpotX", "F");
+
+ GET_FIELD_ID(gPointerIconClassInfo.mHotSpotY, gPointerIconClassInfo.clazz,
+ "mHotSpotY", "F");
+
+ GET_STATIC_METHOD_ID(gPointerIconClassInfo.getSystemIcon, gPointerIconClassInfo.clazz,
+ "getSystemIcon", "(Landroid/content/Context;I)Landroid/view/PointerIcon;");
+
+ GET_METHOD_ID(gPointerIconClassInfo.load, gPointerIconClassInfo.clazz,
+ "load", "(Landroid/content/Context;)Landroid/view/PointerIcon;");
+
+ return 0;
+}
+
+} // namespace android
diff --git a/core/jni/android_view_PointerIcon.h b/core/jni/android_view_PointerIcon.h
new file mode 100644
index 0000000..3bfd645
--- /dev/null
+++ b/core/jni/android_view_PointerIcon.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2011 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_VIEW_POINTER_ICON_H
+#define _ANDROID_VIEW_POINTER_ICON_H
+
+#include "jni.h"
+
+#include <utils/Errors.h>
+#include <SkBitmap.h>
+
+namespace android {
+
+/* Pointer icon styles.
+ * Must match the definition in android.view.PointerIcon.
+ */
+enum {
+ POINTER_ICON_STYLE_CUSTOM = -1,
+ POINTER_ICON_STYLE_NULL = 0,
+ POINTER_ICON_STYLE_ARROW = 1000,
+ POINTER_ICON_STYLE_SPOT_HOVER = 2000,
+ POINTER_ICON_STYLE_SPOT_TOUCH = 2001,
+ POINTER_ICON_STYLE_SPOT_ANCHOR = 2002,
+};
+
+/*
+ * Describes a pointer icon.
+ */
+struct PointerIcon {
+ inline PointerIcon() {
+ reset();
+ }
+
+ int32_t style;
+ SkBitmap bitmap;
+ float hotSpotX;
+ float hotSpotY;
+
+ inline bool isNullIcon() {
+ return style == POINTER_ICON_STYLE_NULL;
+ }
+
+ inline void reset() {
+ style = POINTER_ICON_STYLE_NULL;
+ bitmap.reset();
+ hotSpotX = 0;
+ hotSpotY = 0;
+ }
+};
+
+/* Gets a system pointer icon with the specified style. */
+extern jobject android_view_PointerIcon_getSystemIcon(JNIEnv* env,
+ jobject contextObj, int32_t style);
+
+/* Loads the bitmap associated with a pointer icon.
+ * If pointerIconObj is NULL, returns OK and a pointer icon with POINTER_ICON_STYLE_NULL. */
+extern status_t android_view_PointerIcon_load(JNIEnv* env,
+ jobject pointerIconObj, jobject contextObj, PointerIcon* outPointerIcon);
+
+/* Loads the bitmap associated with a pointer icon by style.
+ * If pointerIconObj is NULL, returns OK and a pointer icon with POINTER_ICON_STYLE_NULL. */
+extern status_t android_view_PointerIcon_loadSystemIcon(JNIEnv* env,
+ jobject contextObj, int32_t style, PointerIcon* outPointerIcon);
+
+} // namespace android
+
+#endif // _ANDROID_OS_POINTER_ICON_H