satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2011, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #define LOG_TAG "LatinIME: jni: ProximityInfo" |
| 19 | |
| 20 | #include "com_android_inputmethod_keyboard_ProximityInfo.h" |
| 21 | #include "jni.h" |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 22 | #include "jni_common.h" |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 23 | #include "proximity_info.h" |
| 24 | |
| 25 | #include <assert.h> |
| 26 | #include <errno.h> |
| 27 | #include <stdio.h> |
| 28 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 29 | namespace latinime { |
| 30 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 31 | static jint latinime_Keyboard_setProximityInfo(JNIEnv *env, jobject object, |
| 32 | jint maxProximityCharsSize, jint displayWidth, jint displayHeight, jint gridWidth, |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 33 | jint gridHeight, jintArray proximityCharsArray, jint keyCount, |
| 34 | jintArray keyXCoordinateArray, jintArray keyYCoordinateArray, jintArray keyWidthArray, |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame^] | 35 | jintArray keyHeightArray, jintArray keyCharCodeArray, |
| 36 | jfloatArray sweetSpotCenterXArray, jfloatArray sweetSpotCenterYArray, |
| 37 | jfloatArray sweetSpotRadiusArray) { |
Yusuke Nojima | de2f842 | 2011-09-27 11:15:18 +0900 | [diff] [blame] | 38 | jint *proximityChars = env->GetIntArrayElements(proximityCharsArray, NULL); |
| 39 | jint *keyXCoordinates = safeGetIntArrayElements(env, keyXCoordinateArray); |
| 40 | jint *keyYCoordinates = safeGetIntArrayElements(env, keyYCoordinateArray); |
| 41 | jint *keyWidths = safeGetIntArrayElements(env, keyWidthArray); |
| 42 | jint *keyHeights = safeGetIntArrayElements(env, keyHeightArray); |
| 43 | jint *keyCharCodes = safeGetIntArrayElements(env, keyCharCodeArray); |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame^] | 44 | jfloat *sweetSpotCenterXs = safeGetFloatArrayElements(env, sweetSpotCenterXArray); |
| 45 | jfloat *sweetSpotCenterYs = safeGetFloatArrayElements(env, sweetSpotCenterYArray); |
| 46 | jfloat *sweetSpotRadii = safeGetFloatArrayElements(env, sweetSpotRadiusArray); |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 47 | ProximityInfo *proximityInfo = new ProximityInfo(maxProximityCharsSize, displayWidth, |
Yusuke Nojima | de2f842 | 2011-09-27 11:15:18 +0900 | [diff] [blame] | 48 | displayHeight, gridWidth, gridHeight, (const uint32_t*)proximityChars, |
| 49 | keyCount, (const int32_t*)keyXCoordinates, (const int32_t*)keyYCoordinates, |
Yusuke Nojima | 1c923d8 | 2011-09-28 11:38:34 +0900 | [diff] [blame] | 50 | (const int32_t*)keyWidths, (const int32_t*)keyHeights, (const int32_t*)keyCharCodes, |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame^] | 51 | (const float*)sweetSpotCenterXs, (const float*)sweetSpotCenterYs, |
| 52 | (const float*)sweetSpotRadii); |
| 53 | safeReleaseFloatArrayElements(env, sweetSpotRadiusArray, sweetSpotRadii); |
| 54 | safeReleaseFloatArrayElements(env, sweetSpotCenterYArray, sweetSpotCenterYs); |
| 55 | safeReleaseFloatArrayElements(env, sweetSpotCenterXArray, sweetSpotCenterXs); |
Yusuke Nojima | de2f842 | 2011-09-27 11:15:18 +0900 | [diff] [blame] | 56 | safeReleaseIntArrayElements(env, keyCharCodeArray, keyCharCodes); |
| 57 | safeReleaseIntArrayElements(env, keyHeightArray, keyHeights); |
| 58 | safeReleaseIntArrayElements(env, keyWidthArray, keyWidths); |
| 59 | safeReleaseIntArrayElements(env, keyYCoordinateArray, keyYCoordinates); |
| 60 | safeReleaseIntArrayElements(env, keyXCoordinateArray, keyXCoordinates); |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 61 | env->ReleaseIntArrayElements(proximityCharsArray, proximityChars, 0); |
| 62 | return (jint)proximityInfo; |
| 63 | } |
| 64 | |
| 65 | static void latinime_Keyboard_release(JNIEnv *env, jobject object, jint proximityInfo) { |
| 66 | ProximityInfo *pi = (ProximityInfo*)proximityInfo; |
| 67 | if (!pi) return; |
| 68 | delete pi; |
| 69 | } |
| 70 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 71 | static JNINativeMethod sKeyboardMethods[] = { |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame^] | 72 | {"setProximityInfoNative", "(IIIII[II[I[I[I[I[I[F[F[F)I", |
| 73 | (void*)latinime_Keyboard_setProximityInfo}, |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 74 | {"releaseProximityInfoNative", "(I)V", (void*)latinime_Keyboard_release} |
| 75 | }; |
| 76 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 77 | int register_ProximityInfo(JNIEnv *env) { |
Yusuke Nojima | de2f842 | 2011-09-27 11:15:18 +0900 | [diff] [blame] | 78 | const char *const kClassPathName = "com/android/inputmethod/keyboard/ProximityInfo"; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 79 | return registerNativeMethods(env, kClassPathName, sKeyboardMethods, |
| 80 | sizeof(sKeyboardMethods) / sizeof(sKeyboardMethods[0])); |
| 81 | } |
| 82 | |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 83 | } // namespace latinime |