Merge "Fix a bug with negative coordinates, step 1"

main
Jean Chalard 2012-03-23 03:48:53 -07:00 committed by Android (Google) Code Review
commit 7f18f44461
1 changed files with 39 additions and 37 deletions

View File

@ -156,57 +156,59 @@ void ProximityInfo::calculateNearbyKeyCodes(
int insertPos = 0; int insertPos = 0;
inputCodes[insertPos++] = primaryKey; inputCodes[insertPos++] = primaryKey;
const int startIndex = getStartIndexFromCoordinates(x, y); const int startIndex = getStartIndexFromCoordinates(x, y);
for (int i = 0; i < MAX_PROXIMITY_CHARS_SIZE; ++i) {
const int32_t c = mProximityCharsArray[startIndex + i]; for (int i = 0; i < MAX_PROXIMITY_CHARS_SIZE; ++i) {
if (c < KEYCODE_SPACE || c == primaryKey) { const int32_t c = mProximityCharsArray[startIndex + i];
continue; if (c < KEYCODE_SPACE || c == primaryKey) {
} continue;
const int keyIndex = getKeyIndex(c); }
const bool onKey = isOnKey(keyIndex, x, y); const int keyIndex = getKeyIndex(c);
const int distance = squaredDistanceToEdge(keyIndex, x, y); const bool onKey = isOnKey(keyIndex, x, y);
if (onKey || distance < MOST_COMMON_KEY_WIDTH_SQUARE) { const int distance = squaredDistanceToEdge(keyIndex, x, y);
inputCodes[insertPos++] = c; if (onKey || distance < MOST_COMMON_KEY_WIDTH_SQUARE) {
if (insertPos >= MAX_PROXIMITY_CHARS_SIZE) { inputCodes[insertPos++] = c;
if (DEBUG_DICT) { if (insertPos >= MAX_PROXIMITY_CHARS_SIZE) {
assert(false); if (DEBUG_DICT) {
assert(false);
}
return;
} }
return;
} }
} }
} 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) {
if (DEBUG_DICT) { if (DEBUG_DICT) {
assert(false); assert(false);
} }
return; return;
} }
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;
for (; k < insertPos; ++k) { for (; k < insertPos; ++k) {
if ((int)ac == inputCodes[k]) { if ((int)ac == inputCodes[k]) {
break; break;
}
} }
} if (k < insertPos) {
if (k < insertPos) { continue;
continue;
}
inputCodes[insertPos++] = ac;
if (insertPos >= MAX_PROXIMITY_CHARS_SIZE) {
if (DEBUG_DICT) {
assert(false);
} }
return; inputCodes[insertPos++] = ac;
if (insertPos >= MAX_PROXIMITY_CHARS_SIZE) {
if (DEBUG_DICT) {
assert(false);
}
return;
} }
} }
} }
// Add a delimiter for the proximity characters // Add a delimiter for the proximity characters
for (int i = insertPos; i < MAX_PROXIMITY_CHARS_SIZE; ++i) { for (int i = insertPos; i < MAX_PROXIMITY_CHARS_SIZE; ++i) {
inputCodes[i] = NOT_A_CODE; inputCodes[i] = NOT_A_CODE;