satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef LATINIME_PROXIMITY_INFO_H |
| 18 | #define LATINIME_PROXIMITY_INFO_H |
| 19 | |
| 20 | #include <stdint.h> |
satok | 552c3c2 | 2012-03-13 16:33:47 +0900 | [diff] [blame] | 21 | #include <string> |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 22 | |
| 23 | #include "defines.h" |
Ken Wakasa | bb005f7 | 2012-08-08 20:43:47 +0900 | [diff] [blame^] | 24 | #include "jni.h" |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 25 | |
| 26 | namespace latinime { |
| 27 | |
satok | cfca3c6 | 2011-08-10 14:30:10 +0900 | [diff] [blame] | 28 | class Correction; |
satok | 2df3060 | 2011-07-15 13:49:00 +0900 | [diff] [blame] | 29 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 30 | class ProximityInfo { |
Ken Wakasa | e12e9b5 | 2012-01-06 12:24:38 +0900 | [diff] [blame] | 31 | public: |
Ken Wakasa | bb005f7 | 2012-08-08 20:43:47 +0900 | [diff] [blame^] | 32 | ProximityInfo(JNIEnv *env, const char *localeCStr, const int maxProximityCharsSize, |
Tadashi G. Takaoka | a58ebc7 | 2012-04-18 15:44:34 +0900 | [diff] [blame] | 33 | const int keyboardWidth, const int keyboardHeight, const int gridWidth, |
Ken Wakasa | bb005f7 | 2012-08-08 20:43:47 +0900 | [diff] [blame^] | 34 | const int gridHeight, const int mostCommonKeyWidth, const jintArray proximityChars, |
| 35 | const int keyCount, const jintArray keyXCoordinates, const jintArray keyYCoordinates, |
| 36 | const jintArray keyWidths, const jintArray keyHeights, const jintArray keyCharCodes, |
| 37 | const jfloatArray sweetSpotCenterXs, const jfloatArray sweetSpotCenterYs, |
| 38 | const jfloatArray sweetSpotRadii); |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 39 | ~ProximityInfo(); |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 40 | bool hasSpaceProximity(const int x, const int y) const; |
Satoshi Kataoka | 3e8c58f | 2012-06-05 17:55:52 +0900 | [diff] [blame] | 41 | int getNormalizedSquaredDistance(const int inputIndex, const int proximityIndex) const; |
| 42 | bool sameAsTyped(const unsigned short *word, int length) const; |
| 43 | int squaredDistanceToEdge(const int keyId, const int x, const int y) const; |
| 44 | bool isOnKey(const int keyId, const int x, const int y) const { |
| 45 | if (keyId < 0) return true; // NOT_A_ID is -1, but return whenever < 0 just in case |
| 46 | const int left = mKeyXCoordinates[keyId]; |
| 47 | const int top = mKeyYCoordinates[keyId]; |
| 48 | const int right = left + mKeyWidths[keyId] + 1; |
| 49 | const int bottom = top + mKeyHeights[keyId]; |
| 50 | return left < right && top < bottom && x >= left && x < right && y >= top && y < bottom; |
| 51 | } |
| 52 | int getKeyIndex(const int c) const; |
| 53 | bool hasSweetSpotData(const int keyIndex) const { |
| 54 | // When there are no calibration data for a key, |
| 55 | // the radius of the key is assigned to zero. |
| 56 | return mSweetSpotRadii[keyIndex] > 0.0; |
| 57 | } |
| 58 | float getSweetSpotRadiiAt(int keyIndex) const { |
| 59 | return mSweetSpotRadii[keyIndex]; |
| 60 | } |
| 61 | float getSweetSpotCenterXAt(int keyIndex) const { |
| 62 | return mSweetSpotCenterXs[keyIndex]; |
| 63 | } |
| 64 | float getSweetSpotCenterYAt(int keyIndex) const { |
| 65 | return mSweetSpotCenterYs[keyIndex]; |
| 66 | } |
| 67 | void calculateNearbyKeyCodes( |
| 68 | const int x, const int y, const int32_t primaryKey, int *inputCodes) const; |
| 69 | |
Satoshi Kataoka | 4a3db70 | 2012-06-08 15:29:44 +0900 | [diff] [blame] | 70 | bool hasTouchPositionCorrectionData() const { |
| 71 | return HAS_TOUCH_POSITION_CORRECTION_DATA; |
| 72 | } |
| 73 | |
| 74 | int getMostCommonKeyWidthSquare() const { |
| 75 | return MOST_COMMON_KEY_WIDTH_SQUARE; |
| 76 | } |
| 77 | |
| 78 | std::string getLocaleStr() const { |
| 79 | return mLocaleStr; |
| 80 | } |
| 81 | |
| 82 | int getKeyCount() const { |
| 83 | return KEY_COUNT; |
| 84 | } |
| 85 | |
| 86 | int getCellHeight() const { |
| 87 | return CELL_HEIGHT; |
| 88 | } |
| 89 | |
| 90 | int getCellWidth() const { |
| 91 | return CELL_WIDTH; |
| 92 | } |
| 93 | |
| 94 | int getGridWidth() const { |
| 95 | return GRID_WIDTH; |
| 96 | } |
| 97 | |
| 98 | int getGridHeight() const { |
| 99 | return GRID_HEIGHT; |
| 100 | } |
satok | 635f68e | 2011-08-10 22:19:33 +0900 | [diff] [blame] | 101 | |
Satoshi Kataoka | efb6324 | 2012-06-27 14:52:40 +0900 | [diff] [blame] | 102 | // Returns the keyboard key-center information. |
| 103 | void getCenters(int *centersX, int *centersY, int *codeToKeyIndex, int *keyToCodeIndex, |
| 104 | int *keyCount, int *keyWidth) const; |
| 105 | |
Ken Wakasa | e12e9b5 | 2012-01-06 12:24:38 +0900 | [diff] [blame] | 106 | private: |
satok | 1bc038c | 2012-06-14 11:25:50 -0700 | [diff] [blame] | 107 | DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfo); |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 108 | // The max number of the keys in one keyboard layout |
| 109 | static const int MAX_KEY_COUNT_IN_A_KEYBOARD = 64; |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame] | 110 | // The upper limit of the char code in mCodeToKeyIndex |
| 111 | static const int MAX_CHAR_CODE = 127; |
satok | 1caff47 | 2012-03-14 23:17:12 +0900 | [diff] [blame] | 112 | static const float NOT_A_DISTANCE_FLOAT = -1.0f; |
| 113 | static const int NOT_A_CODE = -1; |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 114 | |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 115 | int getStartIndexFromCoordinates(const int x, const int y) const; |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 116 | void initializeCodeToKeyIndex(); |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame] | 117 | float calculateNormalizedSquaredDistance(const int keyIndex, const int inputIndex) const; |
| 118 | float calculateSquaredDistanceFromSweetSpotCenter( |
| 119 | const int keyIndex, const int inputIndex) const; |
satok | 1caff47 | 2012-03-14 23:17:12 +0900 | [diff] [blame] | 120 | bool hasInputCoordinates() const; |
Yusuke Nojima | c25c7cc | 2011-10-03 16:44:29 +0900 | [diff] [blame] | 121 | |
Ken Wakasa | de3070a | 2011-03-19 09:16:42 +0900 | [diff] [blame] | 122 | const int MAX_PROXIMITY_CHARS_SIZE; |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 123 | const int KEYBOARD_WIDTH; |
| 124 | const int KEYBOARD_HEIGHT; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 125 | const int GRID_WIDTH; |
| 126 | const int GRID_HEIGHT; |
satok | a70ee6e | 2012-03-07 15:12:22 +0900 | [diff] [blame] | 127 | const int MOST_COMMON_KEY_WIDTH_SQUARE; |
Ken Wakasa | de3070a | 2011-03-19 09:16:42 +0900 | [diff] [blame] | 128 | const int CELL_WIDTH; |
| 129 | const int CELL_HEIGHT; |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 130 | const int KEY_COUNT; |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame] | 131 | const bool HAS_TOUCH_POSITION_CORRECTION_DATA; |
satok | 5eec574 | 2012-03-13 18:26:23 +0900 | [diff] [blame] | 132 | const std::string mLocaleStr; |
satok | 0cb2097 | 2012-03-13 22:07:56 +0900 | [diff] [blame] | 133 | int32_t *mProximityCharsArray; |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 134 | int32_t mKeyXCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 135 | int32_t mKeyYCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 136 | int32_t mKeyWidths[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 137 | int32_t mKeyHeights[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 138 | int32_t mKeyCharCodes[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame] | 139 | float mSweetSpotCenterXs[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 140 | float mSweetSpotCenterYs[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 141 | float mSweetSpotRadii[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame] | 142 | int mCodeToKeyIndex[MAX_CHAR_CODE + 1]; |
Satoshi Kataoka | 3e8c58f | 2012-06-05 17:55:52 +0900 | [diff] [blame] | 143 | // TODO: move to correction.h |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 144 | }; |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 145 | } // namespace latinime |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 146 | #endif // LATINIME_PROXIMITY_INFO_H |