Calibrate the scores of the proximity chars according to the distances.

+1      75
-1      27
+2       0
-2       0
+3       0
-3       0
+4      30
-4      48
+5      37
-5      27
+6       4
-6      35
+7       9
-7      18

Change-Id: I3c6ab06a0084c18ab595147c36c2ff4b1e961a7b
diff --git a/native/src/proximity_info.h b/native/src/proximity_info.h
index 3425efe..35e354c 100644
--- a/native/src/proximity_info.h
+++ b/native/src/proximity_info.h
@@ -28,6 +28,8 @@
 class ProximityInfo {
 public:
     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;
 
     // Used as a return value for character comparison
     typedef enum {
@@ -53,19 +55,20 @@
     unsigned short getPrimaryCharAt(const int index) const;
     bool existsCharInProximityAt(const int index, const int c) const;
     bool existsAdjacentProximityChars(const int index) const;
-    ProximityType getMatchedProximityId(
-            const int index, const unsigned short c, const bool checkProximityChars) const;
-    int getNormalizedSquaredDistance(int index) const {
-        return mNormalizedSquaredDistance[index];
+    ProximityType getMatchedProximityId(const int index, const unsigned short c,
+            const bool checkProximityChars, int *proximityIndex = NULL) const;
+    int getNormalizedSquaredDistance(const int inputIndex, const int proximityIndex) const {
+        return mNormalizedSquaredDistances[inputIndex * MAX_PROXIMITY_CHARS_SIZE + proximityIndex];
     }
     bool sameAsTyped(const unsigned short *word, int length) const;
     const unsigned short* getPrimaryInputWord() const {
         return mPrimaryInputWord;
     }
+    bool touchPositionCorrectionEnabled() const {
+        return mTouchPositionCorrectionEnabled;
+    }
 
 private:
-    static const int NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR =
-            1 << NORMALIZED_SQUARED_DISTANCE_SCALING_FACTOR_LOG_2;
     // The max number of the keys in one keyboard layout
     static const int MAX_KEY_COUNT_IN_A_KEYBOARD = 64;
     // The upper limit of the char code in mCodeToKeyIndex
@@ -73,8 +76,15 @@
 
     int getStartIndexFromCoordinates(const int x, const int y) const;
     void initializeCodeToKeyIndex();
-    float calculateNormalizedSquaredDistance(int index) const;
-    float calculateSquaredDistanceFromSweetSpotCenter(int keyIndex, int inputIndex) const;
+    float calculateNormalizedSquaredDistance(const int keyIndex, const int inputIndex) const;
+    float calculateSquaredDistanceFromSweetSpotCenter(
+            const int keyIndex, const int inputIndex) const;
+    int getKeyIndex(const int c) const;
+    bool hasSweetSpotData(const int keyIndex) const {
+        // When there are no calibration data for a key,
+        // the radius of the key is assigned to zero.
+        return mSweetSpotRadii[keyIndex] > 0.0;
+    }
 
     const int MAX_PROXIMITY_CHARS_SIZE;
     const int KEYBOARD_WIDTH;
@@ -84,10 +94,13 @@
     const int CELL_WIDTH;
     const int CELL_HEIGHT;
     const int KEY_COUNT;
+    const bool HAS_TOUCH_POSITION_CORRECTION_DATA;
     const int *mInputCodes;
     const int *mInputXCoordinates;
     const int *mInputYCoordinates;
+    bool mTouchPositionCorrectionEnabled;
     uint32_t *mProximityCharsArray;
+    int *mNormalizedSquaredDistances;
     int32_t mKeyXCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
     int32_t mKeyYCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
     int32_t mKeyWidths[MAX_KEY_COUNT_IN_A_KEYBOARD];
@@ -96,7 +109,6 @@
     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 mNormalizedSquaredDistance[MAX_WORD_LENGTH_INTERNAL];
     int mInputLength;
     unsigned short mPrimaryInputWord[MAX_WORD_LENGTH_INTERNAL];
     int mCodeToKeyIndex[MAX_CHAR_CODE + 1];