[ML13] Fix the locale passing in ProximityInfo
The locale is used to determine additional proximity characters. This is dependent on the dictionary language, but was passed as a function of the layout, which is wrong and would have given bad suggestions in multi-lingual mode. Ideally, additional proximity characters should be inserted in the dictionary header, but for now it's a rather simple change to get it from the dictionary's locale instead of the proximity info locale. Also, that allows us to remove completely the locale parameter from proximity info, which is a much needed change. This change has zero effect on unit tests and on regression tests. Bug: 11230254 Change-Id: If95157155db7dccd1f00b8ba55ccb3600283f9e4main
parent
fb051c3957
commit
4ef27c0358
|
@ -108,10 +108,9 @@ public class Keyboard {
|
|||
mAltCodeKeysWhileTyping = Collections.unmodifiableList(params.mAltCodeKeysWhileTyping);
|
||||
mIconsSet = params.mIconsSet;
|
||||
|
||||
mProximityInfo = new ProximityInfo(params.mId.mLocale.toString(),
|
||||
params.GRID_WIDTH, params.GRID_HEIGHT, mOccupiedWidth, mOccupiedHeight,
|
||||
mMostCommonKeyWidth, mMostCommonKeyHeight, mSortedKeys,
|
||||
params.mTouchPositionCorrection);
|
||||
mProximityInfo = new ProximityInfo(params.GRID_WIDTH, params.GRID_HEIGHT,
|
||||
mOccupiedWidth, mOccupiedHeight, mMostCommonKeyWidth, mMostCommonKeyHeight,
|
||||
mSortedKeys, params.mTouchPositionCorrection);
|
||||
mProximityCharsCorrectionEnabled = params.mProximityCharsCorrectionEnabled;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,18 +52,11 @@ public class ProximityInfo {
|
|||
private final int mMostCommonKeyHeight;
|
||||
private final List<Key> mSortedKeys;
|
||||
private final List<Key>[] mGridNeighbors;
|
||||
private final String mLocaleStr;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ProximityInfo(final String localeStr, final int gridWidth, final int gridHeight,
|
||||
final int minWidth, final int height, final int mostCommonKeyWidth,
|
||||
final int mostCommonKeyHeight, final List<Key> sortedKeys,
|
||||
ProximityInfo(final int gridWidth, final int gridHeight, final int minWidth, final int height,
|
||||
final int mostCommonKeyWidth, final int mostCommonKeyHeight, final List<Key> sortedKeys,
|
||||
final TouchPositionCorrection touchPositionCorrection) {
|
||||
if (TextUtils.isEmpty(localeStr)) {
|
||||
mLocaleStr = "";
|
||||
} else {
|
||||
mLocaleStr = localeStr;
|
||||
}
|
||||
mGridWidth = gridWidth;
|
||||
mGridHeight = gridHeight;
|
||||
mGridSize = mGridWidth * mGridHeight;
|
||||
|
@ -89,11 +82,10 @@ public class ProximityInfo {
|
|||
}
|
||||
|
||||
// TODO: Stop passing proximityCharsArray
|
||||
private static native long setProximityInfoNative(String locale,
|
||||
int displayWidth, int displayHeight, int gridWidth, int gridHeight,
|
||||
int mostCommonKeyWidth, int mostCommonKeyHeight, int[] proximityCharsArray,
|
||||
int keyCount, int[] keyXCoordinates, int[] keyYCoordinates, int[] keyWidths,
|
||||
int[] keyHeights, int[] keyCharCodes, float[] sweetSpotCenterXs,
|
||||
private static native long setProximityInfoNative(int displayWidth, int displayHeight,
|
||||
int gridWidth, int gridHeight, int mostCommonKeyWidth, int mostCommonKeyHeight,
|
||||
int[] proximityCharsArray, int keyCount, int[] keyXCoordinates, int[] keyYCoordinates,
|
||||
int[] keyWidths, int[] keyHeights, int[] keyCharCodes, float[] sweetSpotCenterXs,
|
||||
float[] sweetSpotCenterYs, float[] sweetSpotRadii);
|
||||
|
||||
private static native void releaseProximityInfoNative(long nativeProximityInfo);
|
||||
|
@ -221,10 +213,10 @@ public class ProximityInfo {
|
|||
}
|
||||
|
||||
// TODO: Stop passing proximityCharsArray
|
||||
return setProximityInfoNative(mLocaleStr, mKeyboardMinWidth, mKeyboardHeight,
|
||||
mGridWidth, mGridHeight, mMostCommonKeyWidth, mMostCommonKeyHeight,
|
||||
proximityCharsArray, keyCount, keyXCoordinates, keyYCoordinates, keyWidths,
|
||||
keyHeights, keyCharCodes, sweetSpotCenterXs, sweetSpotCenterYs, sweetSpotRadii);
|
||||
return setProximityInfoNative(mKeyboardMinWidth, mKeyboardHeight, mGridWidth, mGridHeight,
|
||||
mMostCommonKeyWidth, mMostCommonKeyHeight, proximityCharsArray, keyCount,
|
||||
keyXCoordinates, keyYCoordinates, keyWidths, keyHeights, keyCharCodes,
|
||||
sweetSpotCenterXs, sweetSpotCenterYs, sweetSpotRadii);
|
||||
}
|
||||
|
||||
public long getNativeProximityInfo() {
|
||||
|
|
|
@ -25,13 +25,13 @@
|
|||
|
||||
namespace latinime {
|
||||
|
||||
static jlong latinime_Keyboard_setProximityInfo(JNIEnv *env, jclass clazz, jstring localeJStr,
|
||||
static jlong latinime_Keyboard_setProximityInfo(JNIEnv *env, jclass clazz,
|
||||
jint displayWidth, jint displayHeight, jint gridWidth, jint gridHeight,
|
||||
jint mostCommonkeyWidth, jint mostCommonkeyHeight, jintArray proximityChars, jint keyCount,
|
||||
jintArray keyXCoordinates, jintArray keyYCoordinates, jintArray keyWidths,
|
||||
jintArray keyHeights, jintArray keyCharCodes, jfloatArray sweetSpotCenterXs,
|
||||
jfloatArray sweetSpotCenterYs, jfloatArray sweetSpotRadii) {
|
||||
ProximityInfo *proximityInfo = new ProximityInfo(env, localeJStr, displayWidth, displayHeight,
|
||||
ProximityInfo *proximityInfo = new ProximityInfo(env, displayWidth, displayHeight,
|
||||
gridWidth, gridHeight, mostCommonkeyWidth, mostCommonkeyHeight, proximityChars,
|
||||
keyCount, keyXCoordinates, keyYCoordinates, keyWidths, keyHeights, keyCharCodes,
|
||||
sweetSpotCenterXs, sweetSpotCenterYs, sweetSpotRadii);
|
||||
|
@ -46,7 +46,7 @@ static void latinime_Keyboard_release(JNIEnv *env, jclass clazz, jlong proximity
|
|||
static const JNINativeMethod sMethods[] = {
|
||||
{
|
||||
const_cast<char *>("setProximityInfoNative"),
|
||||
const_cast<char *>("(Ljava/lang/String;IIIIII[II[I[I[I[I[I[F[F[F)J"),
|
||||
const_cast<char *>("(IIIIII[II[I[I[I[I[I[F[F[F)J"),
|
||||
reinterpret_cast<void *>(latinime_Keyboard_setProximityInfo)
|
||||
},
|
||||
{
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
namespace latinime {
|
||||
// TODO: Stop using hardcoded additional proximity characters.
|
||||
// TODO: Have proximity character informations in each language's binary dictionary.
|
||||
const char *AdditionalProximityChars::LOCALE_EN_US = "en";
|
||||
const int AdditionalProximityChars::LOCALE_EN_US[LOCALE_EN_US_SIZE] = { 'e', 'n' };
|
||||
|
||||
const int AdditionalProximityChars::EN_US_ADDITIONAL_A[EN_US_ADDITIONAL_A_SIZE] = {
|
||||
'e', 'i', 'o', 'u'
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#define LATINIME_ADDITIONAL_PROXIMITY_CHARS_H
|
||||
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
|
@ -26,7 +27,8 @@ namespace latinime {
|
|||
class AdditionalProximityChars {
|
||||
private:
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(AdditionalProximityChars);
|
||||
static const char *LOCALE_EN_US;
|
||||
static const int LOCALE_EN_US_SIZE = 2;
|
||||
static const int LOCALE_EN_US[LOCALE_EN_US_SIZE];
|
||||
static const int EN_US_ADDITIONAL_A_SIZE = 4;
|
||||
static const int EN_US_ADDITIONAL_A[];
|
||||
static const int EN_US_ADDITIONAL_E_SIZE = 4;
|
||||
|
@ -38,15 +40,22 @@ class AdditionalProximityChars {
|
|||
static const int EN_US_ADDITIONAL_U_SIZE = 4;
|
||||
static const int EN_US_ADDITIONAL_U[];
|
||||
|
||||
AK_FORCE_INLINE static bool isEnLocale(const char *localeStr) {
|
||||
const size_t LOCALE_EN_US_SIZE = strlen(LOCALE_EN_US);
|
||||
return localeStr && strlen(localeStr) >= LOCALE_EN_US_SIZE
|
||||
&& strncmp(localeStr, LOCALE_EN_US, LOCALE_EN_US_SIZE) == 0;
|
||||
AK_FORCE_INLINE static bool isEnLocale(const std::vector<int> *locale) {
|
||||
const int NCHARS = NELEMS(LOCALE_EN_US);
|
||||
if (locale->size() < NCHARS) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < NCHARS; ++i) {
|
||||
if ((*locale)[i] != LOCALE_EN_US[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public:
|
||||
static int getAdditionalCharsSize(const char *const localeStr, const int c) {
|
||||
if (!isEnLocale(localeStr)) {
|
||||
static int getAdditionalCharsSize(const std::vector<int> *locale, const int c) {
|
||||
if (!isEnLocale(locale)) {
|
||||
return 0;
|
||||
}
|
||||
switch (c) {
|
||||
|
@ -65,8 +74,8 @@ class AdditionalProximityChars {
|
|||
}
|
||||
}
|
||||
|
||||
static const int *getAdditionalChars(const char *const localeStr, const int c) {
|
||||
if (!isEnLocale(localeStr)) {
|
||||
static const int *getAdditionalChars(const std::vector<int> *locale, const int c) {
|
||||
if (!isEnLocale(locale)) {
|
||||
return 0;
|
||||
}
|
||||
switch (c) {
|
||||
|
|
|
@ -49,13 +49,13 @@ static AK_FORCE_INLINE void safeGetOrFillZeroFloatArrayRegion(JNIEnv *env, jfloa
|
|||
}
|
||||
}
|
||||
|
||||
ProximityInfo::ProximityInfo(JNIEnv *env, const jstring localeJStr,
|
||||
const int keyboardWidth, const int keyboardHeight, const int gridWidth,
|
||||
const int gridHeight, const int mostCommonKeyWidth, const int mostCommonKeyHeight,
|
||||
const jintArray proximityChars, const int keyCount, const jintArray keyXCoordinates,
|
||||
const jintArray keyYCoordinates, const jintArray keyWidths, const jintArray keyHeights,
|
||||
const jintArray keyCharCodes, const jfloatArray sweetSpotCenterXs,
|
||||
const jfloatArray sweetSpotCenterYs, const jfloatArray sweetSpotRadii)
|
||||
ProximityInfo::ProximityInfo(JNIEnv *env, const int keyboardWidth, const int keyboardHeight,
|
||||
const int gridWidth, const int gridHeight, const int mostCommonKeyWidth,
|
||||
const int mostCommonKeyHeight, const jintArray proximityChars, const int keyCount,
|
||||
const jintArray keyXCoordinates, const jintArray keyYCoordinates,
|
||||
const jintArray keyWidths, const jintArray keyHeights, const jintArray keyCharCodes,
|
||||
const jfloatArray sweetSpotCenterXs, const jfloatArray sweetSpotCenterYs,
|
||||
const jfloatArray sweetSpotRadii)
|
||||
: GRID_WIDTH(gridWidth), GRID_HEIGHT(gridHeight), MOST_COMMON_KEY_WIDTH(mostCommonKeyWidth),
|
||||
MOST_COMMON_KEY_WIDTH_SQUARE(mostCommonKeyWidth * mostCommonKeyWidth),
|
||||
NORMALIZED_SQUARED_MOST_COMMON_KEY_HYPOTENUSE(1.0f +
|
||||
|
@ -82,13 +82,6 @@ ProximityInfo::ProximityInfo(JNIEnv *env, const jstring localeJStr,
|
|||
if (DEBUG_PROXIMITY_INFO) {
|
||||
AKLOGI("Create proximity info array %d", proximityCharsLength);
|
||||
}
|
||||
const jsize localeCStrUtf8Length = env->GetStringUTFLength(localeJStr);
|
||||
if (localeCStrUtf8Length >= MAX_LOCALE_STRING_LENGTH) {
|
||||
AKLOGI("Locale string length too long: length=%d", localeCStrUtf8Length);
|
||||
ASSERT(false);
|
||||
}
|
||||
memset(mLocaleStr, 0, sizeof(mLocaleStr));
|
||||
env->GetStringUTFRegion(localeJStr, 0, env->GetStringLength(localeJStr), mLocaleStr);
|
||||
safeGetOrFillZeroIntArrayRegion(env, proximityChars, proximityCharsLength,
|
||||
mProximityCharsArray);
|
||||
safeGetOrFillZeroIntArrayRegion(env, keyXCoordinates, KEY_COUNT, mKeyXCoordinates);
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#define LATINIME_PROXIMITY_INFO_H
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "defines.h"
|
||||
#include "jni.h"
|
||||
|
@ -27,9 +28,9 @@ namespace latinime {
|
|||
|
||||
class ProximityInfo {
|
||||
public:
|
||||
ProximityInfo(JNIEnv *env, const jstring localeJStr,
|
||||
const int keyboardWidth, const int keyboardHeight, const int gridWidth,
|
||||
const int gridHeight, const int mostCommonKeyWidth, const int mostCommonKeyHeight,
|
||||
ProximityInfo(JNIEnv *env, const int keyboardWidth, const int keyboardHeight,
|
||||
const int gridWidth, const int gridHeight,
|
||||
const int mostCommonKeyWidth, const int mostCommonKeyHeight,
|
||||
const jintArray proximityChars, const int keyCount, const jintArray keyXCoordinates,
|
||||
const jintArray keyYCoordinates, const jintArray keyWidths, const jintArray keyHeights,
|
||||
const jintArray keyCharCodes, const jfloatArray sweetSpotCenterXs,
|
||||
|
@ -71,11 +72,11 @@ class ProximityInfo {
|
|||
|
||||
AK_FORCE_INLINE void initializeProximities(const int *const inputCodes,
|
||||
const int *const inputXCoordinates, const int *const inputYCoordinates,
|
||||
const int inputSize, int *allInputCodes) const {
|
||||
const int inputSize, int *allInputCodes, const std::vector<int> *locale) const {
|
||||
ProximityInfoUtils::initializeProximities(inputCodes, inputXCoordinates, inputYCoordinates,
|
||||
inputSize, mKeyXCoordinates, mKeyYCoordinates, mKeyWidths, mKeyHeights,
|
||||
mProximityCharsArray, CELL_HEIGHT, CELL_WIDTH, GRID_WIDTH, MOST_COMMON_KEY_WIDTH,
|
||||
KEY_COUNT, mLocaleStr, &mLowerCodePointToKeyMap, allInputCodes);
|
||||
KEY_COUNT, locale, &mLowerCodePointToKeyMap, allInputCodes);
|
||||
}
|
||||
|
||||
AK_FORCE_INLINE int getKeyIndexOf(const int c) const {
|
||||
|
@ -103,9 +104,6 @@ class ProximityInfo {
|
|||
const int KEYBOARD_HEIGHT;
|
||||
const float KEYBOARD_HYPOTENUSE;
|
||||
const bool HAS_TOUCH_POSITION_CORRECTION_DATA;
|
||||
// Assuming locale strings such as en_US, sr-Latn etc.
|
||||
static const int MAX_LOCALE_STRING_LENGTH = 10;
|
||||
char mLocaleStr[MAX_LOCALE_STRING_LENGTH];
|
||||
int *mProximityCharsArray;
|
||||
int mKeyXCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
||||
int mKeyYCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
||||
|
|
|
@ -42,7 +42,7 @@ int ProximityInfoState::getPrimaryOriginalCodePointAt(const int index) const {
|
|||
void ProximityInfoState::initInputParams(const int pointerId, const float maxPointToKeyLength,
|
||||
const ProximityInfo *proximityInfo, const int *const inputCodes, const int inputSize,
|
||||
const int *const xCoordinates, const int *const yCoordinates, const int *const times,
|
||||
const int *const pointerIds, const bool isGeometric) {
|
||||
const int *const pointerIds, const bool isGeometric, const std::vector<int> *locale) {
|
||||
ASSERT(isGeometric || (inputSize < MAX_WORD_LENGTH));
|
||||
mIsContinuousSuggestionPossible = (mHasBeenUpdatedByGeometricInput != isGeometric) ?
|
||||
false : ProximityInfoStateUtils::checkAndReturnIsContinuousSuggestionPossible(
|
||||
|
@ -66,7 +66,7 @@ void ProximityInfoState::initInputParams(const int pointerId, const float maxPoi
|
|||
|
||||
if (!isGeometric && pointerId == 0) {
|
||||
mProximityInfo->initializeProximities(inputCodes, xCoordinates, yCoordinates,
|
||||
inputSize, mInputProximities);
|
||||
inputSize, mInputProximities, locale);
|
||||
}
|
||||
|
||||
///////////////////////
|
||||
|
|
|
@ -37,7 +37,8 @@ class ProximityInfoState {
|
|||
void initInputParams(const int pointerId, const float maxPointToKeyLength,
|
||||
const ProximityInfo *proximityInfo, const int *const inputCodes,
|
||||
const int inputSize, const int *xCoordinates, const int *yCoordinates,
|
||||
const int *const times, const int *const pointerIds, const bool isGeometric);
|
||||
const int *const times, const int *const pointerIds, const bool isGeometric,
|
||||
const std::vector<int> *locale);
|
||||
|
||||
/////////////////////////////////////////
|
||||
// Defined here //
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include <cmath>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "defines.h"
|
||||
#include "suggest/core/layout/additional_proximity_chars.h"
|
||||
|
@ -51,7 +52,7 @@ class ProximityInfoUtils {
|
|||
const int *const keyYCoordinates, const int *const keyWidths, const int *keyHeights,
|
||||
const int *const proximityCharsArray, const int cellHeight, const int cellWidth,
|
||||
const int gridWidth, const int mostCommonKeyWidth, const int keyCount,
|
||||
const char *const localeStr,
|
||||
const std::vector<int> *locale,
|
||||
const std::unordered_map<int, int> *const codeToKeyMap, int *inputProximities) {
|
||||
// Initialize
|
||||
// - mInputCodes
|
||||
|
@ -64,7 +65,7 @@ class ProximityInfoUtils {
|
|||
int *proximities = &inputProximities[i * MAX_PROXIMITY_CHARS_SIZE];
|
||||
calculateProximities(keyXCoordinates, keyYCoordinates, keyWidths, keyHeights,
|
||||
proximityCharsArray, cellHeight, cellWidth, gridWidth, mostCommonKeyWidth,
|
||||
keyCount, x, y, primaryKey, localeStr, codeToKeyMap, proximities);
|
||||
keyCount, x, y, primaryKey, locale, codeToKeyMap, proximities);
|
||||
}
|
||||
|
||||
if (DEBUG_PROXIMITY_CHARS) {
|
||||
|
@ -143,7 +144,7 @@ class ProximityInfoUtils {
|
|||
const int *const keyYCoordinates, const int *const keyWidths, const int *keyHeights,
|
||||
const int *const proximityCharsArray, const int cellHeight, const int cellWidth,
|
||||
const int gridWidth, const int mostCommonKeyWidth, const int keyCount,
|
||||
const int x, const int y, const int primaryKey, const char *const localeStr,
|
||||
const int x, const int y, const int primaryKey, const std::vector<int> *locale,
|
||||
const std::unordered_map<int, int> *const codeToKeyMap, int *proximities) {
|
||||
const int mostCommonKeyWidthSquare = mostCommonKeyWidth * mostCommonKeyWidth;
|
||||
int insertPos = 0;
|
||||
|
@ -177,7 +178,7 @@ class ProximityInfoUtils {
|
|||
}
|
||||
}
|
||||
const int additionalProximitySize =
|
||||
AdditionalProximityChars::getAdditionalCharsSize(localeStr, primaryKey);
|
||||
AdditionalProximityChars::getAdditionalCharsSize(locale, primaryKey);
|
||||
if (additionalProximitySize > 0) {
|
||||
proximities[insertPos++] = ADDITIONAL_PROXIMITY_CHAR_DELIMITER_CODE;
|
||||
if (insertPos >= MAX_PROXIMITY_CHARS_SIZE) {
|
||||
|
@ -188,7 +189,7 @@ class ProximityInfoUtils {
|
|||
}
|
||||
|
||||
const int *additionalProximityChars =
|
||||
AdditionalProximityChars::getAdditionalChars(localeStr, primaryKey);
|
||||
AdditionalProximityChars::getAdditionalChars(locale, primaryKey);
|
||||
for (int j = 0; j < additionalProximitySize; ++j) {
|
||||
const int ac = additionalProximityChars[j];
|
||||
int k = 0;
|
||||
|
|
|
@ -69,8 +69,12 @@ void DicTraverseSession::initializeProximityInfoStates(const int *const inputCod
|
|||
for (int i = 0; i < maxPointerCount; ++i) {
|
||||
mProximityInfoStates[i].initInputParams(i, maxSpatialDistance, getProximityInfo(),
|
||||
inputCodePoints, inputSize, inputXs, inputYs, times, pointerIds,
|
||||
maxPointerCount == MAX_POINTER_COUNT_G
|
||||
/* TODO: this is a hack. fix proximity info state */);
|
||||
// Right now the line below is trying to figure out whether this is a gesture by
|
||||
// looking at the pointer count and assuming whatever is above the cutoff is
|
||||
// a gesture and whatever is below is type. This is hacky and incorrect, we
|
||||
// should pass the correct information instead.
|
||||
maxPointerCount == MAX_POINTER_COUNT_G,
|
||||
getDictionaryStructurePolicy()->getHeaderStructurePolicy()->getLocale());
|
||||
mInputSize += mProximityInfoStates[i].size();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue