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 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 20 | #include "defines.h" |
Tom Ouyang | 1321685 | 2012-09-03 12:50:21 -0700 | [diff] [blame] | 21 | #include "hash_map_compat.h" |
Ken Wakasa | bb005f7 | 2012-08-08 20:43:47 +0900 | [diff] [blame] | 22 | #include "jni.h" |
Satoshi Kataoka | bf78e13 | 2013-01-17 19:46:12 +0900 | [diff] [blame] | 23 | #include "proximity_info_utils.h" |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 24 | |
| 25 | namespace latinime { |
| 26 | |
satok | cfca3c6 | 2011-08-10 14:30:10 +0900 | [diff] [blame] | 27 | class Correction; |
satok | 2df3060 | 2011-07-15 13:49:00 +0900 | [diff] [blame] | 28 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 29 | class ProximityInfo { |
Ken Wakasa | e12e9b5 | 2012-01-06 12:24:38 +0900 | [diff] [blame] | 30 | public: |
Ken Wakasa | 6c22439 | 2013-01-22 13:14:53 +0900 | [diff] [blame] | 31 | ProximityInfo(JNIEnv *env, const jstring localeJStr, |
Tadashi G. Takaoka | a58ebc7 | 2012-04-18 15:44:34 +0900 | [diff] [blame] | 32 | const int keyboardWidth, const int keyboardHeight, const int gridWidth, |
Ken Wakasa | bb005f7 | 2012-08-08 20:43:47 +0900 | [diff] [blame] | 33 | const int gridHeight, const int mostCommonKeyWidth, const jintArray proximityChars, |
| 34 | const int keyCount, const jintArray keyXCoordinates, const jintArray keyYCoordinates, |
| 35 | const jintArray keyWidths, const jintArray keyHeights, const jintArray keyCharCodes, |
| 36 | const jfloatArray sweetSpotCenterXs, const jfloatArray sweetSpotCenterYs, |
| 37 | const jfloatArray sweetSpotRadii); |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 38 | ~ProximityInfo(); |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 39 | bool hasSpaceProximity(const int x, const int y) const; |
Satoshi Kataoka | 3e8c58f | 2012-06-05 17:55:52 +0900 | [diff] [blame] | 40 | int getNormalizedSquaredDistance(const int inputIndex, const int proximityIndex) const; |
Satoshi Kataoka | 0edab9d | 2012-09-24 18:29:31 +0900 | [diff] [blame] | 41 | float getNormalizedSquaredDistanceFromCenterFloatG( |
Satoshi Kataoka | e7398cd | 2012-08-13 20:20:04 +0900 | [diff] [blame] | 42 | const int keyId, const int x, const int y) const; |
Satoshi Kataoka | 3e8c58f | 2012-06-05 17:55:52 +0900 | [diff] [blame] | 43 | bool sameAsTyped(const unsigned short *word, int length) const; |
Ken Wakasa | f278981 | 2012-09-04 12:49:46 +0900 | [diff] [blame] | 44 | int getCodePointOf(const int keyIndex) const; |
Satoshi Kataoka | 3e8c58f | 2012-06-05 17:55:52 +0900 | [diff] [blame] | 45 | bool hasSweetSpotData(const int keyIndex) const { |
| 46 | // When there are no calibration data for a key, |
| 47 | // the radius of the key is assigned to zero. |
Ken Wakasa | fee0ac6 | 2012-08-16 19:34:02 +0900 | [diff] [blame] | 48 | return mSweetSpotRadii[keyIndex] > 0.0f; |
Satoshi Kataoka | 3e8c58f | 2012-06-05 17:55:52 +0900 | [diff] [blame] | 49 | } |
Ken Wakasa | a47c699 | 2013-01-30 18:37:58 +0900 | [diff] [blame] | 50 | float getSweetSpotRadiiAt(int keyIndex) const { return mSweetSpotRadii[keyIndex]; } |
| 51 | float getSweetSpotCenterXAt(int keyIndex) const { return mSweetSpotCenterXs[keyIndex]; } |
| 52 | float getSweetSpotCenterYAt(int keyIndex) const { return mSweetSpotCenterYs[keyIndex]; } |
Satoshi Kataoka | 3e8c58f | 2012-06-05 17:55:52 +0900 | [diff] [blame] | 53 | void calculateNearbyKeyCodes( |
Ken Wakasa | 1d516fb | 2012-12-03 19:43:15 +0900 | [diff] [blame] | 54 | const int x, const int y, const int primaryKey, int *inputCodes) const; |
Ken Wakasa | a47c699 | 2013-01-30 18:37:58 +0900 | [diff] [blame] | 55 | bool hasTouchPositionCorrectionData() const { return HAS_TOUCH_POSITION_CORRECTION_DATA; } |
| 56 | int getMostCommonKeyWidth() const { return MOST_COMMON_KEY_WIDTH; } |
| 57 | int getMostCommonKeyWidthSquare() const { return MOST_COMMON_KEY_WIDTH_SQUARE; } |
| 58 | int getKeyCount() const { return KEY_COUNT; } |
| 59 | int getCellHeight() const { return CELL_HEIGHT; } |
| 60 | int getCellWidth() const { return CELL_WIDTH; } |
| 61 | int getGridWidth() const { return GRID_WIDTH; } |
| 62 | int getGridHeight() const { return GRID_HEIGHT; } |
| 63 | int getKeyboardWidth() const { return KEYBOARD_WIDTH; } |
| 64 | int getKeyboardHeight() const { return KEYBOARD_HEIGHT; } |
Tom Ouyang | 625778f | 2013-02-08 11:35:19 -0800 | [diff] [blame] | 65 | float getKeyboardHypotenuse() const { return KEYBOARD_HYPOTENUSE; } |
Keisuke Kuroyanagi | 95a49a5 | 2012-09-04 17:00:24 +0900 | [diff] [blame] | 66 | |
Ken Wakasa | 5964d4e | 2012-09-10 16:49:36 +0900 | [diff] [blame] | 67 | int getKeyCenterXOfCodePointG(int charCode) const; |
| 68 | int getKeyCenterYOfCodePointG(int charCode) const; |
| 69 | int getKeyCenterXOfKeyIdG(int keyId) const; |
| 70 | int getKeyCenterYOfKeyIdG(int keyId) const; |
Keisuke Kuroyanagi | ff74cc3 | 2012-10-11 13:08:06 +0900 | [diff] [blame] | 71 | int getKeyKeyDistanceG(int keyId0, int keyId1) const; |
Satoshi Kataoka | 6b4a1d7 | 2012-08-10 15:42:56 +0900 | [diff] [blame] | 72 | |
Ken Wakasa | d74214d | 2013-02-13 19:56:19 +0900 | [diff] [blame] | 73 | void AK_FORCE_INLINE initializeProximities(const int *const inputCodes, |
| 74 | const int *const inputXCoordinates, const int *const inputYCoordinates, |
| 75 | const int inputSize, int *allInputCodes) const { |
Satoshi Kataoka | bf78e13 | 2013-01-17 19:46:12 +0900 | [diff] [blame] | 76 | ProximityInfoUtils::initializeProximities(inputCodes, inputXCoordinates, inputYCoordinates, |
| 77 | inputSize, mKeyXCoordinates, mKeyYCoordinates, mKeyWidths, mKeyHeights, |
Ken Wakasa | 6e2ba9b | 2013-01-30 19:24:03 +0900 | [diff] [blame] | 78 | mProximityCharsArray, CELL_HEIGHT, CELL_WIDTH, GRID_WIDTH, MOST_COMMON_KEY_WIDTH, |
| 79 | KEY_COUNT, mLocaleStr, &mCodeToKeyMap, allInputCodes); |
Satoshi Kataoka | bf78e13 | 2013-01-17 19:46:12 +0900 | [diff] [blame] | 80 | } |
| 81 | |
Ken Wakasa | d74214d | 2013-02-13 19:56:19 +0900 | [diff] [blame] | 82 | int AK_FORCE_INLINE getKeyIndexOf(const int c) const { |
Satoshi Kataoka | bf78e13 | 2013-01-17 19:46:12 +0900 | [diff] [blame] | 83 | return ProximityInfoUtils::getKeyIndexOf(KEY_COUNT, c, &mCodeToKeyMap); |
| 84 | } |
| 85 | |
Ken Wakasa | e12e9b5 | 2012-01-06 12:24:38 +0900 | [diff] [blame] | 86 | private: |
satok | 1bc038c | 2012-06-14 11:25:50 -0700 | [diff] [blame] | 87 | DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfo); |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 88 | |
Satoshi Kataoka | 6b4a1d7 | 2012-08-10 15:42:56 +0900 | [diff] [blame] | 89 | void initializeG(); |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame] | 90 | float calculateNormalizedSquaredDistance(const int keyIndex, const int inputIndex) const; |
satok | 1caff47 | 2012-03-14 23:17:12 +0900 | [diff] [blame] | 91 | bool hasInputCoordinates() const; |
Yusuke Nojima | c25c7cc | 2011-10-03 16:44:29 +0900 | [diff] [blame] | 92 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 93 | const int GRID_WIDTH; |
| 94 | const int GRID_HEIGHT; |
Satoshi Kataoka | 6b4a1d7 | 2012-08-10 15:42:56 +0900 | [diff] [blame] | 95 | const int MOST_COMMON_KEY_WIDTH; |
satok | a70ee6e | 2012-03-07 15:12:22 +0900 | [diff] [blame] | 96 | const int MOST_COMMON_KEY_WIDTH_SQUARE; |
Ken Wakasa | de3070a | 2011-03-19 09:16:42 +0900 | [diff] [blame] | 97 | const int CELL_WIDTH; |
| 98 | const int CELL_HEIGHT; |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 99 | const int KEY_COUNT; |
Keisuke Kuroyanagi | 95a49a5 | 2012-09-04 17:00:24 +0900 | [diff] [blame] | 100 | const int KEYBOARD_WIDTH; |
| 101 | const int KEYBOARD_HEIGHT; |
Tom Ouyang | 625778f | 2013-02-08 11:35:19 -0800 | [diff] [blame] | 102 | const float KEYBOARD_HYPOTENUSE; |
Yusuke Nojima | a4c1f1c | 2011-10-06 19:12:20 +0900 | [diff] [blame] | 103 | const bool HAS_TOUCH_POSITION_CORRECTION_DATA; |
Ken Wakasa | 9e0c711 | 2012-08-09 22:26:58 +0900 | [diff] [blame] | 104 | char mLocaleStr[MAX_LOCALE_STRING_LENGTH]; |
Ken Wakasa | 1d516fb | 2012-12-03 19:43:15 +0900 | [diff] [blame] | 105 | int *mProximityCharsArray; |
| 106 | int mKeyXCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 107 | int mKeyYCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 108 | int mKeyWidths[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 109 | int mKeyHeights[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 110 | int mKeyCodePoints[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame] | 111 | float mSweetSpotCenterXs[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 112 | float mSweetSpotCenterYs[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 113 | float mSweetSpotRadii[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
Tom Ouyang | 1321685 | 2012-09-03 12:50:21 -0700 | [diff] [blame] | 114 | hash_map_compat<int, int> mCodeToKeyMap; |
Satoshi Kataoka | 6b4a1d7 | 2012-08-10 15:42:56 +0900 | [diff] [blame] | 115 | |
Ken Wakasa | f278981 | 2012-09-04 12:49:46 +0900 | [diff] [blame] | 116 | int mKeyIndexToCodePointG[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
Satoshi Kataoka | 6b4a1d7 | 2012-08-10 15:42:56 +0900 | [diff] [blame] | 117 | int mCenterXsG[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 118 | int mCenterYsG[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 119 | int mKeyKeyDistancesG[MAX_KEY_COUNT_IN_A_KEYBOARD][MAX_KEY_COUNT_IN_A_KEYBOARD]; |
Satoshi Kataoka | 3e8c58f | 2012-06-05 17:55:52 +0900 | [diff] [blame] | 120 | // TODO: move to correction.h |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 121 | }; |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 122 | } // namespace latinime |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 123 | #endif // LATINIME_PROXIMITY_INFO_H |