am 43149e45: Merge "Pass the touch position correction data to native."

* commit '43149e454c31dde869ae5dfebb1245d9687efc70':
  Pass the touch position correction data to native.
main
Yusuke Nojima 2011-09-29 01:44:59 -07:00 committed by Android Git Automerger
commit e8cb8d2836
8 changed files with 107 additions and 106 deletions

View File

@ -50,6 +50,7 @@ $(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/app/LatinIME.apk)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libjni_latinime_intermediates) $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libjni_latinime_intermediates)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libjni_latinime_intermediates) $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libjni_latinime_intermediates)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libjni_latinime_intermediates) $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libjni_latinime_intermediates)
$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libjni_latinime_intermediates)
# ************************************************ # ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
# ************************************************ # ************************************************

View File

@ -138,7 +138,7 @@ public class Keyboard {
mProximityInfo = new ProximityInfo( mProximityInfo = new ProximityInfo(
params.GRID_WIDTH, params.GRID_HEIGHT, mOccupiedWidth, mOccupiedHeight, params.GRID_WIDTH, params.GRID_HEIGHT, mOccupiedWidth, mOccupiedHeight,
mMostCommonKeyWidth, mKeys, params.mTouchPositionCorrectionXs, mMostCommonKeyWidth, mMostCommonKeyHeight, mKeys, params.mTouchPositionCorrectionXs,
params.mTouchPositionCorrectionYs, params.mTouchPositionCorrectionRadii); params.mTouchPositionCorrectionYs, params.mTouchPositionCorrectionRadii);
} }

View File

@ -16,6 +16,9 @@
package com.android.inputmethod.keyboard; package com.android.inputmethod.keyboard;
import android.graphics.Rect;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.latin.Utils; import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.latin.spellcheck.SpellCheckerProximityInfo; import com.android.inputmethod.latin.spellcheck.SpellCheckerProximityInfo;
@ -27,9 +30,9 @@ public class ProximityInfo {
public static final int MAX_PROXIMITY_CHARS_SIZE = 16; public static final int MAX_PROXIMITY_CHARS_SIZE = 16;
/** Number of key widths from current touch point to search for nearest keys. */ /** Number of key widths from current touch point to search for nearest keys. */
private static float SEARCH_DISTANCE = 1.2f; private static float SEARCH_DISTANCE = 1.2f;
private static final int UNKNOWN_THEME = -1;
private static final int[] EMPTY_INT_ARRAY = new int[0]; private static final int[] EMPTY_INT_ARRAY = new int[0];
private final int mKeyHeight;
private final int mGridWidth; private final int mGridWidth;
private final int mGridHeight; private final int mGridHeight;
private final int mGridSize; private final int mGridSize;
@ -45,8 +48,8 @@ public class ProximityInfo {
private final float[] mTouchPositionCorrectionRadii; private final float[] mTouchPositionCorrectionRadii;
ProximityInfo(int gridWidth, int gridHeight, int minWidth, int height, int keyWidth, ProximityInfo(int gridWidth, int gridHeight, int minWidth, int height, int keyWidth,
List<Key> keys, float[] touchPositionCorrectionXs, float[] touchPositionCorrectionYs, int keyHeight, List<Key> keys, float[] touchPositionCorrectionXs,
float[] touchPositionCorrectionRadii) { float[] touchPositionCorrectionYs, float[] touchPositionCorrectionRadii) {
mGridWidth = gridWidth; mGridWidth = gridWidth;
mGridHeight = gridHeight; mGridHeight = gridHeight;
mGridSize = mGridWidth * mGridHeight; mGridSize = mGridWidth * mGridHeight;
@ -54,6 +57,7 @@ public class ProximityInfo {
mCellHeight = (height + mGridHeight - 1) / mGridHeight; mCellHeight = (height + mGridHeight - 1) / mGridHeight;
mKeyboardMinWidth = minWidth; mKeyboardMinWidth = minWidth;
mKeyboardHeight = height; mKeyboardHeight = height;
mKeyHeight = keyHeight;
mTouchPositionCorrectionXs = touchPositionCorrectionXs; mTouchPositionCorrectionXs = touchPositionCorrectionXs;
mTouchPositionCorrectionYs = touchPositionCorrectionYs; mTouchPositionCorrectionYs = touchPositionCorrectionYs;
mTouchPositionCorrectionRadii = touchPositionCorrectionRadii; mTouchPositionCorrectionRadii = touchPositionCorrectionRadii;
@ -66,7 +70,7 @@ public class ProximityInfo {
} }
public static ProximityInfo createDummyProximityInfo() { public static ProximityInfo createDummyProximityInfo() {
return new ProximityInfo(1, 1, 1, 1, 1, Collections.<Key>emptyList(), null, null, null); return new ProximityInfo(1, 1, 1, 1, 1, 1, Collections.<Key>emptyList(), null, null, null);
} }
public static ProximityInfo createSpellCheckerProximityInfo() { public static ProximityInfo createSpellCheckerProximityInfo() {
@ -75,7 +79,7 @@ public class ProximityInfo {
spellCheckerProximityInfo.setProximityInfoNative( spellCheckerProximityInfo.setProximityInfoNative(
SpellCheckerProximityInfo.ROW_SIZE, SpellCheckerProximityInfo.ROW_SIZE,
480, 300, 10, 3, SpellCheckerProximityInfo.PROXIMITY, 480, 300, 10, 3, SpellCheckerProximityInfo.PROXIMITY,
0, null, null, null, null, null, UNKNOWN_THEME); 0, null, null, null, null, null, null, null, null);
return spellCheckerProximityInfo; return spellCheckerProximityInfo;
} }
@ -86,7 +90,8 @@ public class ProximityInfo {
private native int setProximityInfoNative(int maxProximityCharsSize, int displayWidth, private native int setProximityInfoNative(int maxProximityCharsSize, int displayWidth,
int displayHeight, int gridWidth, int gridHeight, int[] proximityCharsArray, int displayHeight, int gridWidth, int gridHeight, int[] proximityCharsArray,
int keyCount, int[] keyXCoordinates, int[] keyYCoordinates, int keyCount, int[] keyXCoordinates, int[] keyYCoordinates,
int[] keyWidths, int[] keyHeights, int[] keyCharCodes, int themeId); int[] keyWidths, int[] keyHeights, int[] keyCharCodes,
float[] sweetSpotCenterX, float[] sweetSpotCenterY, float[] sweetSpotRadii);
private native void releaseProximityInfoNative(int nativeProximityInfo); private native void releaseProximityInfoNative(int nativeProximityInfo);
private final void setProximityInfo(int[][] gridNeighborKeyIndexes, int keyboardWidth, private final void setProximityInfo(int[][] gridNeighborKeyIndexes, int keyboardWidth,
@ -101,12 +106,11 @@ public class ProximityInfo {
} }
} }
final int keyCount = keys.size(); final int keyCount = keys.size();
int[] keyXCoordinates = new int[keyCount]; final int[] keyXCoordinates = new int[keyCount];
int[] keyYCoordinates = new int[keyCount]; final int[] keyYCoordinates = new int[keyCount];
int[] keyWidths = new int[keyCount]; final int[] keyWidths = new int[keyCount];
int[] keyHeights = new int[keyCount]; final int[] keyHeights = new int[keyCount];
int[] keyCharCodes = new int[keyCount]; final int[] keyCharCodes = new int[keyCount];
final int themeId = 5; // TODO: Use real theme id.
for (int i = 0; i < keyCount; ++i) { for (int i = 0; i < keyCount; ++i) {
final Key key = keys.get(i); final Key key = keys.get(i);
keyXCoordinates[i] = key.mX; keyXCoordinates[i] = key.mX;
@ -115,10 +119,51 @@ public class ProximityInfo {
keyHeights[i] = key.mHeight; keyHeights[i] = key.mHeight;
keyCharCodes[i] = key.mCode; keyCharCodes[i] = key.mCode;
} }
final boolean hasTouchPositionCorrectionData =
mTouchPositionCorrectionXs != null
&& mTouchPositionCorrectionYs != null
&& mTouchPositionCorrectionRadii != null
&& mTouchPositionCorrectionXs.length > 0
&& mTouchPositionCorrectionYs.length > 0
&& mTouchPositionCorrectionRadii.length > 0;
final float[] sweetSpotCenterXs =
hasTouchPositionCorrectionData ? new float[keyCount] : null;
final float[] sweetSpotCenterYs =
hasTouchPositionCorrectionData ? new float[keyCount] : null;
final float[] sweetSpotRadii =
hasTouchPositionCorrectionData ? new float[keyCount] : null;
if (hasTouchPositionCorrectionData) {
calculateSweetSpot(keys, sweetSpotCenterXs, sweetSpotCenterYs, sweetSpotRadii);
}
mNativeProximityInfo = setProximityInfoNative(MAX_PROXIMITY_CHARS_SIZE, mNativeProximityInfo = setProximityInfoNative(MAX_PROXIMITY_CHARS_SIZE,
keyboardWidth, keyboardHeight, mGridWidth, mGridHeight, proximityCharsArray, keyboardWidth, keyboardHeight, mGridWidth, mGridHeight, proximityCharsArray,
keyCount, keyXCoordinates, keyYCoordinates, keyWidths, keyHeights, keyCharCodes, keyCount, keyXCoordinates, keyYCoordinates, keyWidths, keyHeights, keyCharCodes,
themeId); sweetSpotCenterXs, sweetSpotCenterYs, sweetSpotRadii);
}
private void calculateSweetSpot(List<Key> keys, float[] sweetSpotCenterXs,
float[] sweetSpotCenterYs, float[] sweetSpotRadii) {
final int keyCount = keys.size();
for (int i = 0; i < keyCount; ++i) {
final Key key = keys.get(i);
final Rect hitBox = key.mHitBox;
final int row = hitBox.top / mKeyHeight;
if (row < mTouchPositionCorrectionRadii.length) {
final float hitBoxCenterX = (hitBox.left + hitBox.right) * 0.5f;
final float hitBoxCenterY = (hitBox.top + hitBox.bottom) * 0.5f;
final float hitBoxWidth = hitBox.right - hitBox.left;
final float hitBoxHeight = hitBox.bottom - hitBox.top;
final float x = mTouchPositionCorrectionXs[row];
final float y = mTouchPositionCorrectionYs[row];
final float radius = mTouchPositionCorrectionRadii[row];
sweetSpotCenterXs[i] = hitBoxCenterX + x * hitBoxWidth;
sweetSpotCenterYs[i] = hitBoxCenterY + y * hitBoxHeight;
sweetSpotRadii[i] = radius
* (float)Math.sqrt(hitBoxWidth * hitBoxWidth + hitBoxHeight * hitBoxHeight);
}
}
} }
public int getNativeProximityInfo() { public int getNativeProximityInfo() {

View File

@ -32,18 +32,27 @@ static jint latinime_Keyboard_setProximityInfo(JNIEnv *env, jobject object,
jint maxProximityCharsSize, jint displayWidth, jint displayHeight, jint gridWidth, jint maxProximityCharsSize, jint displayWidth, jint displayHeight, jint gridWidth,
jint gridHeight, jintArray proximityCharsArray, jint keyCount, jint gridHeight, jintArray proximityCharsArray, jint keyCount,
jintArray keyXCoordinateArray, jintArray keyYCoordinateArray, jintArray keyWidthArray, jintArray keyXCoordinateArray, jintArray keyYCoordinateArray, jintArray keyWidthArray,
jintArray keyHeightArray, jintArray keyCharCodeArray, jint themeId) { jintArray keyHeightArray, jintArray keyCharCodeArray,
jfloatArray sweetSpotCenterXArray, jfloatArray sweetSpotCenterYArray,
jfloatArray sweetSpotRadiusArray) {
jint *proximityChars = env->GetIntArrayElements(proximityCharsArray, NULL); jint *proximityChars = env->GetIntArrayElements(proximityCharsArray, NULL);
jint *keyXCoordinates = safeGetIntArrayElements(env, keyXCoordinateArray); jint *keyXCoordinates = safeGetIntArrayElements(env, keyXCoordinateArray);
jint *keyYCoordinates = safeGetIntArrayElements(env, keyYCoordinateArray); jint *keyYCoordinates = safeGetIntArrayElements(env, keyYCoordinateArray);
jint *keyWidths = safeGetIntArrayElements(env, keyWidthArray); jint *keyWidths = safeGetIntArrayElements(env, keyWidthArray);
jint *keyHeights = safeGetIntArrayElements(env, keyHeightArray); jint *keyHeights = safeGetIntArrayElements(env, keyHeightArray);
jint *keyCharCodes = safeGetIntArrayElements(env, keyCharCodeArray); jint *keyCharCodes = safeGetIntArrayElements(env, keyCharCodeArray);
jfloat *sweetSpotCenterXs = safeGetFloatArrayElements(env, sweetSpotCenterXArray);
jfloat *sweetSpotCenterYs = safeGetFloatArrayElements(env, sweetSpotCenterYArray);
jfloat *sweetSpotRadii = safeGetFloatArrayElements(env, sweetSpotRadiusArray);
ProximityInfo *proximityInfo = new ProximityInfo(maxProximityCharsSize, displayWidth, ProximityInfo *proximityInfo = new ProximityInfo(maxProximityCharsSize, displayWidth,
displayHeight, gridWidth, gridHeight, (const uint32_t*)proximityChars, displayHeight, gridWidth, gridHeight, (const uint32_t*)proximityChars,
keyCount, (const int32_t*)keyXCoordinates, (const int32_t*)keyYCoordinates, keyCount, (const int32_t*)keyXCoordinates, (const int32_t*)keyYCoordinates,
(const int32_t*)keyWidths, (const int32_t*)keyHeights, (const int32_t*)keyCharCodes, (const int32_t*)keyWidths, (const int32_t*)keyHeights, (const int32_t*)keyCharCodes,
themeId); (const float*)sweetSpotCenterXs, (const float*)sweetSpotCenterYs,
(const float*)sweetSpotRadii);
safeReleaseFloatArrayElements(env, sweetSpotRadiusArray, sweetSpotRadii);
safeReleaseFloatArrayElements(env, sweetSpotCenterYArray, sweetSpotCenterYs);
safeReleaseFloatArrayElements(env, sweetSpotCenterXArray, sweetSpotCenterXs);
safeReleaseIntArrayElements(env, keyCharCodeArray, keyCharCodes); safeReleaseIntArrayElements(env, keyCharCodeArray, keyCharCodes);
safeReleaseIntArrayElements(env, keyHeightArray, keyHeights); safeReleaseIntArrayElements(env, keyHeightArray, keyHeights);
safeReleaseIntArrayElements(env, keyWidthArray, keyWidths); safeReleaseIntArrayElements(env, keyWidthArray, keyWidths);
@ -60,7 +69,8 @@ static void latinime_Keyboard_release(JNIEnv *env, jobject object, jint proximit
} }
static JNINativeMethod sKeyboardMethods[] = { static JNINativeMethod sKeyboardMethods[] = {
{"setProximityInfoNative", "(IIIII[II[I[I[I[I[II)I", (void*)latinime_Keyboard_setProximityInfo}, {"setProximityInfoNative", "(IIIII[II[I[I[I[I[I[F[F[F)I",
(void*)latinime_Keyboard_setProximityInfo},
{"releaseProximityInfoNative", "(I)V", (void*)latinime_Keyboard_release} {"releaseProximityInfoNative", "(I)V", (void*)latinime_Keyboard_release}
}; };

View File

@ -35,12 +35,26 @@ inline jint *safeGetIntArrayElements(JNIEnv *env, jintArray jArray) {
} }
} }
inline jfloat *safeGetFloatArrayElements(JNIEnv *env, jfloatArray jArray) {
if (jArray) {
return env->GetFloatArrayElements(jArray, NULL);
} else {
return NULL;
}
}
inline void safeReleaseIntArrayElements(JNIEnv *env, jintArray jArray, jint *cArray) { inline void safeReleaseIntArrayElements(JNIEnv *env, jintArray jArray, jint *cArray) {
if (jArray) { if (jArray) {
env->ReleaseIntArrayElements(jArray, cArray, 0); env->ReleaseIntArrayElements(jArray, cArray, 0);
} }
} }
inline void safeReleaseFloatArrayElements(JNIEnv *env, jfloatArray jArray, jfloat *cArray) {
if (jArray) {
env->ReleaseFloatArrayElements(jArray, cArray, 0);
}
}
} // namespace latinime } // namespace latinime
#endif // LATINIME_JNI_COMMON_H #endif // LATINIME_JNI_COMMON_H

View File

@ -1,61 +0,0 @@
/*
**
** Copyright 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 LATINIME_DEFINES_TOUCH_POSITION_CORRECTION_H
#define LATINIME_DEFINES_TOUCH_POSITION_CORRECTION_H
#define OUTER_SWEET_SPOT_RADIUS_RATIO 1.3
static const char* TOUCH_POSITION_CORRECTION_GROUPS[] = {
"qwertyuiop",
"a",
"sdfghjk",
"l",
"zxcvbnm",
};
// (center X) / (key width)
static const float RELATIVE_TOUCH_CENTER_X[] = {
0, // qwertyuiop
-0.26871, // a
0, // sdfghjk
0.028050, // l
0, // zxcvbnm
};
// (center Y) / (key height)
static const float RELATIVE_TOUCH_CENTER_Y[] = {
0.192088, // qwertyuiop
0.214100, // a
0.216640, // sdfghjk
0.233288, // l
0.286598, // zxcvbnm
};
// (sweet spot radius) / ((key width) + (key height))
static const float SWEET_SPOT_RADIUS[] = {
0.148955, // qwertyuiop
0.185437, // a
0.145522, // sdfghjk
0.156882, // l
0.144211, // zxcvbnm
};
#define CORRECTION_GROUP_COUNT \
((int)(sizeof(TOUCH_POSITION_CORRECTION_GROUPS) / sizeof(TOUCH_POSITION_CORRECTION_GROUPS[0])))
#endif // LATINIME_DEFINES_TOUCH_POSITION_CORRECTION_H

View File

@ -20,7 +20,6 @@
#define LOG_TAG "LatinIME: proximity_info.cpp" #define LOG_TAG "LatinIME: proximity_info.cpp"
#include "defines_touch_position_correction.h"
#include "dictionary.h" #include "dictionary.h"
#include "proximity_info.h" #include "proximity_info.h"
@ -38,12 +37,13 @@ ProximityInfo::ProximityInfo(const int maxProximityCharsSize, const int keyboard
const int keyboardHeight, const int gridWidth, const int gridHeight, const int keyboardHeight, const int gridWidth, const int gridHeight,
const uint32_t *proximityCharsArray, const int keyCount, const int32_t *keyXCoordinates, const uint32_t *proximityCharsArray, const int keyCount, const int32_t *keyXCoordinates,
const int32_t *keyYCoordinates, const int32_t *keyWidths, const int32_t *keyHeights, const int32_t *keyYCoordinates, const int32_t *keyWidths, const int32_t *keyHeights,
const int32_t *keyCharCodes, int themeId) const int32_t *keyCharCodes, const float *sweetSpotCenterXs, const float *sweetSpotCenterYs,
const float *sweetSpotRadii)
: MAX_PROXIMITY_CHARS_SIZE(maxProximityCharsSize), KEYBOARD_WIDTH(keyboardWidth), : MAX_PROXIMITY_CHARS_SIZE(maxProximityCharsSize), KEYBOARD_WIDTH(keyboardWidth),
KEYBOARD_HEIGHT(keyboardHeight), GRID_WIDTH(gridWidth), GRID_HEIGHT(gridHeight), KEYBOARD_HEIGHT(keyboardHeight), GRID_WIDTH(gridWidth), GRID_HEIGHT(gridHeight),
CELL_WIDTH((keyboardWidth + gridWidth - 1) / gridWidth), CELL_WIDTH((keyboardWidth + gridWidth - 1) / gridWidth),
CELL_HEIGHT((keyboardHeight + gridHeight - 1) / gridHeight), CELL_HEIGHT((keyboardHeight + gridHeight - 1) / gridHeight),
KEY_COUNT(min(keyCount, MAX_KEY_COUNT_IN_A_KEYBOARD)), THEME_ID(themeId) { KEY_COUNT(min(keyCount, MAX_KEY_COUNT_IN_A_KEYBOARD)) {
const int len = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE; const int len = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE;
mProximityCharsArray = new uint32_t[len]; mProximityCharsArray = new uint32_t[len];
if (DEBUG_PROXIMITY_INFO) { if (DEBUG_PROXIMITY_INFO) {
@ -56,35 +56,26 @@ ProximityInfo::ProximityInfo(const int maxProximityCharsSize, const int keyboard
copyOrFillZero(mKeyWidths, keyWidths, KEY_COUNT * sizeof(mKeyWidths[0])); copyOrFillZero(mKeyWidths, keyWidths, KEY_COUNT * sizeof(mKeyWidths[0]));
copyOrFillZero(mKeyHeights, keyHeights, KEY_COUNT * sizeof(mKeyHeights[0])); copyOrFillZero(mKeyHeights, keyHeights, KEY_COUNT * sizeof(mKeyHeights[0]));
copyOrFillZero(mKeyCharCodes, keyCharCodes, KEY_COUNT * sizeof(mKeyCharCodes[0])); copyOrFillZero(mKeyCharCodes, keyCharCodes, KEY_COUNT * sizeof(mKeyCharCodes[0]));
copyOrFillZero(mSweetSpotCenterXs, sweetSpotCenterXs,
KEY_COUNT * sizeof(mSweetSpotCenterXs[0]));
copyOrFillZero(mSweetSpotCenterYs, sweetSpotCenterYs,
KEY_COUNT * sizeof(mSweetSpotCenterYs[0]));
copyOrFillZero(mSweetSpotRadii, sweetSpotRadii, KEY_COUNT * sizeof(mSweetSpotRadii[0]));
initializeCodeToGroup();
initializeCodeToKeyIndex(); initializeCodeToKeyIndex();
} }
// Build the reversed look up table from the char code to the index in its group.
// see TOUCH_POSITION_CORRECTION_GROUPS
void ProximityInfo::initializeCodeToGroup() {
memset(mCodeToGroup, -1, (MAX_GROUPED_CHAR_CODE + 1) * sizeof(mCodeToGroup[0]));
for (int i = 0; i < CORRECTION_GROUP_COUNT; ++i) {
const char *group = TOUCH_POSITION_CORRECTION_GROUPS[i];
for (int j = 0; group[j]; ++j) {
const int code = group[j];
if (0 <= code && code <= MAX_GROUPED_CHAR_CODE)
mCodeToGroup[code] = i;
}
}
}
// Build the reversed look up table from the char code to the index in mKeyXCoordinates, // Build the reversed look up table from the char code to the index in mKeyXCoordinates,
// mKeyYCoordinates, mKeyWidths, mKeyHeights, mKeyCharCodes. // mKeyYCoordinates, mKeyWidths, mKeyHeights, mKeyCharCodes.
void ProximityInfo::initializeCodeToKeyIndex() { void ProximityInfo::initializeCodeToKeyIndex() {
memset(mCodeToKeyIndex, -1, (MAX_GROUPED_CHAR_CODE + 1) * sizeof(mCodeToKeyIndex[0])); memset(mCodeToKeyIndex, -1, (MAX_CHAR_CODE + 1) * sizeof(mCodeToKeyIndex[0]));
for (int i = 0; i < KEY_COUNT; ++i) { for (int i = 0; i < KEY_COUNT; ++i) {
const int code = mKeyCharCodes[i]; const int code = mKeyCharCodes[i];
if (0 <= code && code <= MAX_GROUPED_CHAR_CODE) if (0 <= code && code <= MAX_CHAR_CODE) {
mCodeToKeyIndex[code] = i; mCodeToKeyIndex[code] = i;
} }
} }
}
ProximityInfo::~ProximityInfo() { ProximityInfo::~ProximityInfo() {
delete[] mProximityCharsArray; delete[] mProximityCharsArray;
@ -210,6 +201,6 @@ bool ProximityInfo::sameAsTyped(const unsigned short *word, int length) const {
} }
const int ProximityInfo::MAX_KEY_COUNT_IN_A_KEYBOARD; const int ProximityInfo::MAX_KEY_COUNT_IN_A_KEYBOARD;
const int ProximityInfo::MAX_GROUPED_CHAR_CODE; const int ProximityInfo::MAX_CHAR_CODE;
} // namespace latinime } // namespace latinime

View File

@ -37,7 +37,8 @@ public:
const int keybaordHeight, const int gridWidth, const int gridHeight, const int keybaordHeight, const int gridWidth, const int gridHeight,
const uint32_t *proximityCharsArray, const int keyCount, const int32_t *keyXCoordinates, const uint32_t *proximityCharsArray, const int keyCount, const int32_t *keyXCoordinates,
const int32_t *keyYCoordinates, const int32_t *keyWidths, const int32_t *keyHeights, const int32_t *keyYCoordinates, const int32_t *keyWidths, const int32_t *keyHeights,
const int32_t *keyCharCodes, int themeId); const int32_t *keyCharCodes, const float *sweetSpotCenterXs,
const float *sweetSpotCenterYs, const float *sweetSpotRadii);
~ProximityInfo(); ~ProximityInfo();
bool hasSpaceProximity(const int x, const int y) const; bool hasSpaceProximity(const int x, const int y) const;
void setInputParams(const int* inputCodes, const int inputLength); void setInputParams(const int* inputCodes, const int inputLength);
@ -55,11 +56,10 @@ public:
private: private:
// The max number of the keys in one keyboard layout // The max number of the keys in one keyboard layout
static const int MAX_KEY_COUNT_IN_A_KEYBOARD = 64; static const int MAX_KEY_COUNT_IN_A_KEYBOARD = 64;
// The upper limit of the char code in TOUCH_POSITION_CORRECTION_GROUP // The upper limit of the char code in mCodeToKeyIndex
static const int MAX_GROUPED_CHAR_CODE = 127; static const int MAX_CHAR_CODE = 127;
int getStartIndexFromCoordinates(const int x, const int y) const; int getStartIndexFromCoordinates(const int x, const int y) const;
void initializeCodeToGroup();
void initializeCodeToKeyIndex(); void initializeCodeToKeyIndex();
const int MAX_PROXIMITY_CHARS_SIZE; const int MAX_PROXIMITY_CHARS_SIZE;
const int KEYBOARD_WIDTH; const int KEYBOARD_WIDTH;
@ -69,7 +69,6 @@ private:
const int CELL_WIDTH; const int CELL_WIDTH;
const int CELL_HEIGHT; const int CELL_HEIGHT;
const int KEY_COUNT; const int KEY_COUNT;
const int THEME_ID;
const int *mInputCodes; const int *mInputCodes;
uint32_t *mProximityCharsArray; uint32_t *mProximityCharsArray;
int32_t mKeyXCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD]; int32_t mKeyXCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
@ -77,10 +76,12 @@ private:
int32_t mKeyWidths[MAX_KEY_COUNT_IN_A_KEYBOARD]; int32_t mKeyWidths[MAX_KEY_COUNT_IN_A_KEYBOARD];
int32_t mKeyHeights[MAX_KEY_COUNT_IN_A_KEYBOARD]; int32_t mKeyHeights[MAX_KEY_COUNT_IN_A_KEYBOARD];
int32_t mKeyCharCodes[MAX_KEY_COUNT_IN_A_KEYBOARD]; int32_t mKeyCharCodes[MAX_KEY_COUNT_IN_A_KEYBOARD];
float mSweetSpotCenterXs[MAX_KEY_COUNT_IN_A_KEYBOARD];
float mSweetSpotCenterYs[MAX_KEY_COUNT_IN_A_KEYBOARD];
float mSweetSpotRadii[MAX_KEY_COUNT_IN_A_KEYBOARD];
int mInputLength; int mInputLength;
unsigned short mPrimaryInputWord[MAX_WORD_LENGTH_INTERNAL]; unsigned short mPrimaryInputWord[MAX_WORD_LENGTH_INTERNAL];
int mCodeToGroup[MAX_GROUPED_CHAR_CODE + 1]; int mCodeToKeyIndex[MAX_CHAR_CODE + 1];
int mCodeToKeyIndex[MAX_GROUPED_CHAR_CODE + 1];
}; };
} // namespace latinime } // namespace latinime