am 71b379df
: Merge "Use GetStringUTFRegion" into jb-mr1-dev
* commit '71b379df51de95dfb0071506b4eb6a64eadd8832': Use GetStringUTFRegion
This commit is contained in:
commit
d26d20fe22
3 changed files with 14 additions and 12 deletions
|
@ -29,18 +29,15 @@ static jlong latinime_Keyboard_setProximityInfo(JNIEnv *env, jobject object,
|
||||||
jint keyCount, jintArray keyXCoordinates, jintArray keyYCoordinates,
|
jint keyCount, jintArray keyXCoordinates, jintArray keyYCoordinates,
|
||||||
jintArray keyWidths, jintArray keyHeights, jintArray keyCharCodes,
|
jintArray keyWidths, jintArray keyHeights, jintArray keyCharCodes,
|
||||||
jfloatArray sweetSpotCenterXs, jfloatArray sweetSpotCenterYs, jfloatArray sweetSpotRadii) {
|
jfloatArray sweetSpotCenterXs, jfloatArray sweetSpotCenterYs, jfloatArray sweetSpotRadii) {
|
||||||
const char *localeCStr = env->GetStringUTFChars(localeJStr, 0);
|
ProximityInfo *proximityInfo = new ProximityInfo(env, localeJStr, maxProximityCharsSize,
|
||||||
ProximityInfo *proximityInfo = new ProximityInfo(env, localeCStr, maxProximityCharsSize,
|
|
||||||
displayWidth, displayHeight, gridWidth, gridHeight, mostCommonkeyWidth, proximityChars,
|
displayWidth, displayHeight, gridWidth, gridHeight, mostCommonkeyWidth, proximityChars,
|
||||||
keyCount, keyXCoordinates, keyYCoordinates, keyWidths, keyHeights, keyCharCodes,
|
keyCount, keyXCoordinates, keyYCoordinates, keyWidths, keyHeights, keyCharCodes,
|
||||||
sweetSpotCenterXs, sweetSpotCenterYs, sweetSpotRadii);
|
sweetSpotCenterXs, sweetSpotCenterYs, sweetSpotRadii);
|
||||||
env->ReleaseStringUTFChars(localeJStr, localeCStr);
|
|
||||||
return reinterpret_cast<jlong>(proximityInfo);
|
return reinterpret_cast<jlong>(proximityInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void latinime_Keyboard_release(JNIEnv *env, jobject object, jlong proximityInfo) {
|
static void latinime_Keyboard_release(JNIEnv *env, jobject object, jlong proximityInfo) {
|
||||||
ProximityInfo *pi = reinterpret_cast<ProximityInfo*>(proximityInfo);
|
ProximityInfo *pi = reinterpret_cast<ProximityInfo*>(proximityInfo);
|
||||||
if (!pi) return;
|
|
||||||
delete pi;
|
delete pi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ static inline void safeGetOrFillZeroFloatArrayRegion(JNIEnv *env, jfloatArray jA
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ProximityInfo::ProximityInfo(JNIEnv *env, const char *localeCStr, const int maxProximityCharsSize,
|
ProximityInfo::ProximityInfo(JNIEnv *env, const jstring localeJStr, const int maxProximityCharsSize,
|
||||||
const int keyboardWidth, const int keyboardHeight, const int gridWidth,
|
const int keyboardWidth, const int keyboardHeight, const int gridWidth,
|
||||||
const int gridHeight, const int mostCommonKeyWidth, const jintArray proximityChars,
|
const int gridHeight, const int mostCommonKeyWidth, const jintArray proximityChars,
|
||||||
const int keyCount, const jintArray keyXCoordinates, const jintArray keyYCoordinates,
|
const int keyCount, const jintArray keyXCoordinates, const jintArray keyYCoordinates,
|
||||||
|
@ -62,12 +62,16 @@ ProximityInfo::ProximityInfo(JNIEnv *env, const char *localeCStr, const int maxP
|
||||||
KEY_COUNT(min(keyCount, MAX_KEY_COUNT_IN_A_KEYBOARD)),
|
KEY_COUNT(min(keyCount, MAX_KEY_COUNT_IN_A_KEYBOARD)),
|
||||||
HAS_TOUCH_POSITION_CORRECTION_DATA(keyCount > 0 && keyXCoordinates && keyYCoordinates
|
HAS_TOUCH_POSITION_CORRECTION_DATA(keyCount > 0 && keyXCoordinates && keyYCoordinates
|
||||||
&& keyWidths && keyHeights && keyCharCodes && sweetSpotCenterXs
|
&& keyWidths && keyHeights && keyCharCodes && sweetSpotCenterXs
|
||||||
&& sweetSpotCenterYs && sweetSpotRadii),
|
&& sweetSpotCenterYs && sweetSpotRadii) {
|
||||||
mLocaleStr(localeCStr) {
|
|
||||||
const int proximityGridLength = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE;
|
const int proximityGridLength = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE;
|
||||||
if (DEBUG_PROXIMITY_INFO) {
|
if (DEBUG_PROXIMITY_INFO) {
|
||||||
AKLOGI("Create proximity info array %d", proximityGridLength);
|
AKLOGI("Create proximity info array %d", proximityGridLength);
|
||||||
}
|
}
|
||||||
|
const jsize localeCStrUtf8Length = env->GetStringUTFLength(localeJStr);
|
||||||
|
char localeCStr[localeCStrUtf8Length + 1];
|
||||||
|
env->GetStringUTFRegion(localeJStr, 0, env->GetStringLength(localeJStr), localeCStr);
|
||||||
|
localeCStr[localeCStrUtf8Length] = '\0';
|
||||||
|
mLocaleStr = new std::string(localeCStr);
|
||||||
mProximityCharsArray = new int32_t[proximityGridLength];
|
mProximityCharsArray = new int32_t[proximityGridLength];
|
||||||
safeGetOrFillZeroIntArrayRegion(env, proximityChars, proximityGridLength, mProximityCharsArray);
|
safeGetOrFillZeroIntArrayRegion(env, proximityChars, proximityGridLength, mProximityCharsArray);
|
||||||
safeGetOrFillZeroIntArrayRegion(env, keyXCoordinates, KEY_COUNT, mKeyXCoordinates);
|
safeGetOrFillZeroIntArrayRegion(env, keyXCoordinates, KEY_COUNT, mKeyXCoordinates);
|
||||||
|
@ -94,6 +98,7 @@ void ProximityInfo::initializeCodeToKeyIndex() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ProximityInfo::~ProximityInfo() {
|
ProximityInfo::~ProximityInfo() {
|
||||||
|
delete mLocaleStr;
|
||||||
delete[] mProximityCharsArray;
|
delete[] mProximityCharsArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +171,7 @@ void ProximityInfo::calculateNearbyKeyCodes(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const int additionalProximitySize =
|
const int additionalProximitySize =
|
||||||
AdditionalProximityChars::getAdditionalCharsSize(&mLocaleStr, primaryKey);
|
AdditionalProximityChars::getAdditionalCharsSize(mLocaleStr, primaryKey);
|
||||||
if (additionalProximitySize > 0) {
|
if (additionalProximitySize > 0) {
|
||||||
inputCodes[insertPos++] = ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE;
|
inputCodes[insertPos++] = ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE;
|
||||||
if (insertPos >= MAX_PROXIMITY_CHARS_SIZE) {
|
if (insertPos >= MAX_PROXIMITY_CHARS_SIZE) {
|
||||||
|
@ -177,7 +182,7 @@ void ProximityInfo::calculateNearbyKeyCodes(
|
||||||
}
|
}
|
||||||
|
|
||||||
const int32_t *additionalProximityChars =
|
const int32_t *additionalProximityChars =
|
||||||
AdditionalProximityChars::getAdditionalChars(&mLocaleStr, primaryKey);
|
AdditionalProximityChars::getAdditionalChars(mLocaleStr, primaryKey);
|
||||||
for (int j = 0; j < additionalProximitySize; ++j) {
|
for (int j = 0; j < additionalProximitySize; ++j) {
|
||||||
const int32_t ac = additionalProximityChars[j];
|
const int32_t ac = additionalProximityChars[j];
|
||||||
int k = 0;
|
int k = 0;
|
||||||
|
|
|
@ -29,7 +29,7 @@ class Correction;
|
||||||
|
|
||||||
class ProximityInfo {
|
class ProximityInfo {
|
||||||
public:
|
public:
|
||||||
ProximityInfo(JNIEnv *env, const char *localeCStr, const int maxProximityCharsSize,
|
ProximityInfo(JNIEnv *env, const jstring localeJStr, const int maxProximityCharsSize,
|
||||||
const int keyboardWidth, const int keyboardHeight, const int gridWidth,
|
const int keyboardWidth, const int keyboardHeight, const int gridWidth,
|
||||||
const int gridHeight, const int mostCommonKeyWidth, const jintArray proximityChars,
|
const int gridHeight, const int mostCommonKeyWidth, const jintArray proximityChars,
|
||||||
const int keyCount, const jintArray keyXCoordinates, const jintArray keyYCoordinates,
|
const int keyCount, const jintArray keyXCoordinates, const jintArray keyYCoordinates,
|
||||||
|
@ -76,7 +76,7 @@ class ProximityInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getLocaleStr() const {
|
std::string getLocaleStr() const {
|
||||||
return mLocaleStr;
|
return *mLocaleStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getKeyCount() const {
|
int getKeyCount() const {
|
||||||
|
@ -129,7 +129,7 @@ class ProximityInfo {
|
||||||
const int CELL_HEIGHT;
|
const int CELL_HEIGHT;
|
||||||
const int KEY_COUNT;
|
const int KEY_COUNT;
|
||||||
const bool HAS_TOUCH_POSITION_CORRECTION_DATA;
|
const bool HAS_TOUCH_POSITION_CORRECTION_DATA;
|
||||||
const std::string mLocaleStr;
|
const std::string *mLocaleStr;
|
||||||
int32_t *mProximityCharsArray;
|
int32_t *mProximityCharsArray;
|
||||||
int32_t mKeyXCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
int32_t mKeyXCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
||||||
int32_t mKeyYCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
int32_t mKeyYCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
||||||
|
|
Loading…
Reference in a new issue