Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0e301bdc authored by Tom Ouyang's avatar Tom Ouyang Committed by Android (Google) Code Review
Browse files

Merge "Generalize incremental recognition to non-Latin languages" into jb-mr1-dev

parents f8986ac6 13216851
Loading
Loading
Loading
Loading
+9 −24
Original line number Diff line number Diff line
@@ -67,7 +67,8 @@ ProximityInfo::ProximityInfo(JNIEnv *env, const jstring localeJStr, const int ma
                  && keyWidths && keyHeights && keyCharCodes && sweetSpotCenterXs
                  && sweetSpotCenterYs && sweetSpotRadii),
          mProximityCharsArray(new int32_t[GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE
                  /* proximityGridLength */]) {
                  /* proximityGridLength */]),
          mCodeToKeyMap() {
    const int proximityGridLength = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE;
    if (DEBUG_PROXIMITY_INFO) {
        AKLOGI("Create proximity info array %d", proximityGridLength);
@@ -88,22 +89,9 @@ ProximityInfo::ProximityInfo(JNIEnv *env, const jstring localeJStr, const int ma
    safeGetOrFillZeroFloatArrayRegion(env, sweetSpotCenterXs, KEY_COUNT, mSweetSpotCenterXs);
    safeGetOrFillZeroFloatArrayRegion(env, sweetSpotCenterYs, KEY_COUNT, mSweetSpotCenterYs);
    safeGetOrFillZeroFloatArrayRegion(env, sweetSpotRadii, KEY_COUNT, mSweetSpotRadii);
    initializeCodePointToKeyIndex();
    initializeG();
}

// Build the reversed look up table from the char code to the index in mKeyXCoordinates,
// mKeyYCoordinates, mKeyWidths, mKeyHeights, mKeyCharCodes.
void ProximityInfo::initializeCodePointToKeyIndex() {
    memset(mCodePointToKeyIndex, -1, sizeof(mCodePointToKeyIndex));
    for (int i = 0; i < KEY_COUNT; ++i) {
        const int code = mKeyCodePoints[i];
        if (0 <= code && code <= MAX_CHAR_CODE) {
            mCodePointToKeyIndex[code] = i;
        }
    }
}

ProximityInfo::~ProximityInfo() {
    delete[] mProximityCharsArray;
}
@@ -239,11 +227,12 @@ int ProximityInfo::getKeyIndexOf(const int c) const {
        // We do not have the coordinate data
        return NOT_AN_INDEX;
    }
    const unsigned short baseLowerC = toBaseLowerCase(c);
    if (baseLowerC > MAX_CHAR_CODE) {
        return NOT_AN_INDEX;
    const int baseLowerC = static_cast<int>(toBaseLowerCase(c));
    hash_map_compat<int, int>::const_iterator mapPos = mCodeToKeyMap.find(baseLowerC);
    if (mapPos != mCodeToKeyMap.end()) {
        return mapPos->second;
    }
    return mCodePointToKeyIndex[baseLowerC];
    return NOT_AN_INDEX;
}

int ProximityInfo::getCodePointOf(const int keyIndex) const {
@@ -260,12 +249,8 @@ void ProximityInfo::initializeG() {
        const int lowerCode = toBaseLowerCase(code);
        mCenterXsG[i] = mKeyXCoordinates[i] + mKeyWidths[i] / 2;
        mCenterYsG[i] = mKeyYCoordinates[i] + mKeyHeights[i] / 2;
        if (code != lowerCode && lowerCode >= 0 && lowerCode <= MAX_CHAR_CODE) {
            mCodePointToKeyIndex[lowerCode] = i;
        mCodeToKeyMap[lowerCode] = i;
        mKeyIndexToCodePointG[i] = lowerCode;
        } else {
            mKeyIndexToCodePointG[i] = code;
        }
    }
    for (int i = 0; i < KEY_COUNT; i++) {
        mKeyKeyDistancesG[i][i] = 0;
+2 −4
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <stdint.h>

#include "defines.h"
#include "hash_map_compat.h"
#include "jni.h"

namespace latinime {
@@ -112,12 +113,9 @@ class ProximityInfo {

 private:
    DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfo);
    // The upper limit of the char code in mCodePointToKeyIndex
    static const int MAX_CHAR_CODE = 127;
    static const float NOT_A_DISTANCE_FLOAT;

    int getStartIndexFromCoordinates(const int x, const int y) const;
    void initializeCodePointToKeyIndex();
    void initializeG();
    float calculateNormalizedSquaredDistance(const int keyIndex, const int inputIndex) const;
    float calculateSquaredDistanceFromSweetSpotCenter(
@@ -154,7 +152,7 @@ class ProximityInfo {
    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 mCodePointToKeyIndex[MAX_CHAR_CODE + 1];
    hash_map_compat<int, int> mCodeToKeyMap;

    int mKeyIndexToCodePointG[MAX_KEY_COUNT_IN_A_KEYBOARD];
    int mCenterXsG[MAX_KEY_COUNT_IN_A_KEYBOARD];
+0 −2
Original line number Diff line number Diff line
@@ -37,8 +37,6 @@ class ProximityInfoState {
    static const int NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR_LOG_2 = 10;
    static const int NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR =
            1 << NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR_LOG_2;
    // The upper limit of the char code in mCodeToKeyIndex
    static const int MAX_CHAR_CODE = 127;
    static const float NOT_A_DISTANCE_FLOAT = -1.0f;
    static const int NOT_A_CODE = -1;