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> |
| 21 | |
| 22 | #include "defines.h" |
| 23 | |
| 24 | namespace latinime { |
| 25 | |
satok | cfca3c6 | 2011-08-10 14:30:10 +0900 | [diff] [blame] | 26 | class Correction; |
satok | 2df3060 | 2011-07-15 13:49:00 +0900 | [diff] [blame] | 27 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 28 | class ProximityInfo { |
| 29 | public: |
satok | d24df43 | 2011-07-14 15:43:42 +0900 | [diff] [blame] | 30 | typedef enum { // Used as a return value for character comparison |
| 31 | SAME_OR_ACCENTED_OR_CAPITALIZED_CHAR, // Same char, possibly with different case or accent |
| 32 | NEAR_PROXIMITY_CHAR, // It is a char located nearby on the keyboard |
| 33 | UNRELATED_CHAR // It is an unrelated char |
| 34 | } ProximityType; |
| 35 | |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 36 | ProximityInfo(const int maxProximityCharsSize, const int keyboardWidth, |
| 37 | const int keybaordHeight, const int gridWidth, const int gridHeight, |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 38 | const uint32_t *proximityCharsArray, const int keyCount, const int32_t *keyXCoordinates, |
| 39 | const int32_t *keyYCoordinates, const int32_t *keyWidths, const int32_t *keyHeights, |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame^] | 40 | const int32_t *keyCharCodes, const float *sweetSpotCenterXs, |
| 41 | const float *sweetSpotCenterYs, const float *sweetSpotRadii); |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 42 | ~ProximityInfo(); |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 43 | bool hasSpaceProximity(const int x, const int y) const; |
satok | 1d7eaf8 | 2011-07-13 10:32:02 +0900 | [diff] [blame] | 44 | void setInputParams(const int* inputCodes, const int inputLength); |
| 45 | const int* getProximityCharsAt(const int index) const; |
satok | d24df43 | 2011-07-14 15:43:42 +0900 | [diff] [blame] | 46 | unsigned short getPrimaryCharAt(const int index) const; |
| 47 | bool existsCharInProximityAt(const int index, const int c) const; |
| 48 | bool existsAdjacentProximityChars(const int index) const; |
| 49 | ProximityType getMatchedProximityId( |
satok | 985312e | 2011-08-05 21:21:01 +0900 | [diff] [blame] | 50 | const int index, const unsigned short c, const bool checkProximityChars) const; |
satok | 1d7eaf8 | 2011-07-13 10:32:02 +0900 | [diff] [blame] | 51 | bool sameAsTyped(const unsigned short *word, int length) const; |
satok | 0cedd2b | 2011-08-12 01:05:27 +0900 | [diff] [blame] | 52 | const unsigned short* getPrimaryInputWord() const { |
| 53 | return mPrimaryInputWord; |
| 54 | } |
satok | 635f68e | 2011-08-10 22:19:33 +0900 | [diff] [blame] | 55 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 56 | private: |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 57 | // The max number of the keys in one keyboard layout |
| 58 | static const int MAX_KEY_COUNT_IN_A_KEYBOARD = 64; |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame^] | 59 | // The upper limit of the char code in mCodeToKeyIndex |
| 60 | static const int MAX_CHAR_CODE = 127; |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 61 | |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 62 | int getStartIndexFromCoordinates(const int x, const int y) const; |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 63 | void initializeCodeToKeyIndex(); |
Ken Wakasa | de3070a | 2011-03-19 09:16:42 +0900 | [diff] [blame] | 64 | const int MAX_PROXIMITY_CHARS_SIZE; |
satok | 817e517 | 2011-03-04 06:06:45 -0800 | [diff] [blame] | 65 | const int KEYBOARD_WIDTH; |
| 66 | const int KEYBOARD_HEIGHT; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 67 | const int GRID_WIDTH; |
| 68 | const int GRID_HEIGHT; |
Ken Wakasa | de3070a | 2011-03-19 09:16:42 +0900 | [diff] [blame] | 69 | const int CELL_WIDTH; |
| 70 | const int CELL_HEIGHT; |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 71 | const int KEY_COUNT; |
satok | 1d7eaf8 | 2011-07-13 10:32:02 +0900 | [diff] [blame] | 72 | const int *mInputCodes; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 73 | uint32_t *mProximityCharsArray; |
Yusuke Nojima | 0e1f656 | 2011-09-21 12:02:47 +0900 | [diff] [blame] | 74 | int32_t mKeyXCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 75 | int32_t mKeyYCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 76 | int32_t mKeyWidths[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 77 | int32_t mKeyHeights[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 78 | int32_t mKeyCharCodes[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame^] | 79 | float mSweetSpotCenterXs[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 80 | float mSweetSpotCenterYs[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
| 81 | float mSweetSpotRadii[MAX_KEY_COUNT_IN_A_KEYBOARD]; |
satok | 1d7eaf8 | 2011-07-13 10:32:02 +0900 | [diff] [blame] | 82 | int mInputLength; |
satok | 0cedd2b | 2011-08-12 01:05:27 +0900 | [diff] [blame] | 83 | unsigned short mPrimaryInputWord[MAX_WORD_LENGTH_INTERNAL]; |
Yusuke Nojima | ad35835 | 2011-09-29 16:44:54 +0900 | [diff] [blame^] | 84 | int mCodeToKeyIndex[MAX_CHAR_CODE + 1]; |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 85 | }; |
Ken Wakasa | ce9e52a | 2011-06-18 13:09:55 +0900 | [diff] [blame] | 86 | |
| 87 | } // namespace latinime |
| 88 | |
satok | 8fbd552 | 2011-02-22 17:28:55 +0900 | [diff] [blame] | 89 | #endif // LATINIME_PROXIMITY_INFO_H |