blob: 7c22e108b2db6b2c7e0b90e112f5f7c11a6b4f60 [file] [log] [blame]
satok8fbd5522011-02-22 17:28:55 +09001/*
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"
Ken Wakasabb005f72012-08-08 20:43:47 +090023#include "jni.h"
satok8fbd5522011-02-22 17:28:55 +090024
25namespace latinime {
26
satokcfca3c62011-08-10 14:30:10 +090027class Correction;
satok2df30602011-07-15 13:49:00 +090028
satok8fbd5522011-02-22 17:28:55 +090029class ProximityInfo {
Ken Wakasae12e9b52012-01-06 12:24:38 +090030 public:
Ken Wakasa01511452012-08-09 15:58:15 +090031 ProximityInfo(JNIEnv *env, const jstring localeJStr, const int maxProximityCharsSize,
Tadashi G. Takaokaa58ebc72012-04-18 15:44:34 +090032 const int keyboardWidth, const int keyboardHeight, const int gridWidth,
Ken Wakasabb005f72012-08-08 20:43:47 +090033 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);
satok8fbd5522011-02-22 17:28:55 +090038 ~ProximityInfo();
satok817e5172011-03-04 06:06:45 -080039 bool hasSpaceProximity(const int x, const int y) const;
Satoshi Kataoka3e8c58f2012-06-05 17:55:52 +090040 int getNormalizedSquaredDistance(const int inputIndex, const int proximityIndex) const;
Satoshi Kataokae7398cd2012-08-13 20:20:04 +090041 float getNormalizedSquaredDistanceFromCenterFloat(
42 const int keyId, const int x, const int y) const;
Satoshi Kataoka3e8c58f2012-06-05 17:55:52 +090043 bool sameAsTyped(const unsigned short *word, int length) const;
Ken Wakasaf2789812012-09-04 12:49:46 +090044 int getKeyIndexOf(const int c) const;
45 int getCodePointOf(const int keyIndex) const;
Satoshi Kataoka3e8c58f2012-06-05 17:55:52 +090046 bool hasSweetSpotData(const int keyIndex) const {
47 // When there are no calibration data for a key,
48 // the radius of the key is assigned to zero.
Ken Wakasafee0ac62012-08-16 19:34:02 +090049 return mSweetSpotRadii[keyIndex] > 0.0f;
Satoshi Kataoka3e8c58f2012-06-05 17:55:52 +090050 }
51 float getSweetSpotRadiiAt(int keyIndex) const {
52 return mSweetSpotRadii[keyIndex];
53 }
54 float getSweetSpotCenterXAt(int keyIndex) const {
55 return mSweetSpotCenterXs[keyIndex];
56 }
57 float getSweetSpotCenterYAt(int keyIndex) const {
58 return mSweetSpotCenterYs[keyIndex];
59 }
60 void calculateNearbyKeyCodes(
61 const int x, const int y, const int32_t primaryKey, int *inputCodes) const;
62
Satoshi Kataoka4a3db702012-06-08 15:29:44 +090063 bool hasTouchPositionCorrectionData() const {
64 return HAS_TOUCH_POSITION_CORRECTION_DATA;
65 }
66
Satoshi Kataoka6b4a1d72012-08-10 15:42:56 +090067 int getMostCommonKeyWidth() const {
68 return MOST_COMMON_KEY_WIDTH;
69 }
70
Satoshi Kataoka4a3db702012-06-08 15:29:44 +090071 int getMostCommonKeyWidthSquare() const {
72 return MOST_COMMON_KEY_WIDTH_SQUARE;
73 }
74
Ken Wakasa9e0c7112012-08-09 22:26:58 +090075 const char *getLocaleStr() const {
76 return mLocaleStr;
Satoshi Kataoka4a3db702012-06-08 15:29:44 +090077 }
78
79 int getKeyCount() const {
80 return KEY_COUNT;
81 }
82
83 int getCellHeight() const {
84 return CELL_HEIGHT;
85 }
86
87 int getCellWidth() const {
88 return CELL_WIDTH;
89 }
90
91 int getGridWidth() const {
92 return GRID_WIDTH;
93 }
94
95 int getGridHeight() const {
96 return GRID_HEIGHT;
97 }
satok635f68e2011-08-10 22:19:33 +090098
Keisuke Kuroyanagi95a49a52012-09-04 17:00:24 +090099 int getKeyboardWidth() const {
100 return KEYBOARD_WIDTH;
101 }
102
103 int getKeyboardHeight() const {
104 return KEYBOARD_HEIGHT;
105 }
106
Ken Wakasaf2789812012-09-04 12:49:46 +0900107 // TODO: These should return int.
108 float getKeyCenterXOfCodePointG(int charCode) const;
109 float getKeyCenterYOfCodePointG(int charCode) const;
110 float getKeyCenterXOfKeyIdG(int keyId) const;
111 float getKeyCenterYOfKeyIdG(int keyId) const;
Satoshi Kataoka6b4a1d72012-08-10 15:42:56 +0900112 int getKeyKeyDistanceG(int key0, int key1) const;
113
Ken Wakasae12e9b52012-01-06 12:24:38 +0900114 private:
satok1bc038c2012-06-14 11:25:50 -0700115 DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfo);
Ken Wakasaf2789812012-09-04 12:49:46 +0900116 // The upper limit of the char code in mCodePointToKeyIndex
Yusuke Nojimaad358352011-09-29 16:44:54 +0900117 static const int MAX_CHAR_CODE = 127;
Ken Wakasa162c2112012-08-24 14:51:15 +0900118 static const float NOT_A_DISTANCE_FLOAT;
Yusuke Nojima0e1f6562011-09-21 12:02:47 +0900119
satok817e5172011-03-04 06:06:45 -0800120 int getStartIndexFromCoordinates(const int x, const int y) const;
Ken Wakasaf2789812012-09-04 12:49:46 +0900121 void initializeCodePointToKeyIndex();
Satoshi Kataoka6b4a1d72012-08-10 15:42:56 +0900122 void initializeG();
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +0900123 float calculateNormalizedSquaredDistance(const int keyIndex, const int inputIndex) const;
124 float calculateSquaredDistanceFromSweetSpotCenter(
125 const int keyIndex, const int inputIndex) const;
satok1caff472012-03-14 23:17:12 +0900126 bool hasInputCoordinates() const;
Ken Wakasafee0ac62012-08-16 19:34:02 +0900127 int squaredDistanceToEdge(const int keyId, const int x, const int y) const;
128 bool isOnKey(const int keyId, const int x, const int y) const {
129 if (keyId < 0) return true; // NOT_A_ID is -1, but return whenever < 0 just in case
130 const int left = mKeyXCoordinates[keyId];
131 const int top = mKeyYCoordinates[keyId];
132 const int right = left + mKeyWidths[keyId] + 1;
133 const int bottom = top + mKeyHeights[keyId];
134 return left < right && top < bottom && x >= left && x < right && y >= top && y < bottom;
135 }
Yusuke Nojimac25c7cc2011-10-03 16:44:29 +0900136
Ken Wakasade3070a2011-03-19 09:16:42 +0900137 const int MAX_PROXIMITY_CHARS_SIZE;
satok8fbd5522011-02-22 17:28:55 +0900138 const int GRID_WIDTH;
139 const int GRID_HEIGHT;
Satoshi Kataoka6b4a1d72012-08-10 15:42:56 +0900140 const int MOST_COMMON_KEY_WIDTH;
satoka70ee6e2012-03-07 15:12:22 +0900141 const int MOST_COMMON_KEY_WIDTH_SQUARE;
Ken Wakasade3070a2011-03-19 09:16:42 +0900142 const int CELL_WIDTH;
143 const int CELL_HEIGHT;
Yusuke Nojima0e1f6562011-09-21 12:02:47 +0900144 const int KEY_COUNT;
Keisuke Kuroyanagi95a49a52012-09-04 17:00:24 +0900145 const int KEYBOARD_WIDTH;
146 const int KEYBOARD_HEIGHT;
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +0900147 const bool HAS_TOUCH_POSITION_CORRECTION_DATA;
Ken Wakasa9e0c7112012-08-09 22:26:58 +0900148 char mLocaleStr[MAX_LOCALE_STRING_LENGTH];
satok0cb20972012-03-13 22:07:56 +0900149 int32_t *mProximityCharsArray;
Yusuke Nojima0e1f6562011-09-21 12:02:47 +0900150 int32_t mKeyXCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
151 int32_t mKeyYCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
152 int32_t mKeyWidths[MAX_KEY_COUNT_IN_A_KEYBOARD];
153 int32_t mKeyHeights[MAX_KEY_COUNT_IN_A_KEYBOARD];
Ken Wakasaf2789812012-09-04 12:49:46 +0900154 int32_t mKeyCodePoints[MAX_KEY_COUNT_IN_A_KEYBOARD];
Yusuke Nojimaad358352011-09-29 16:44:54 +0900155 float mSweetSpotCenterXs[MAX_KEY_COUNT_IN_A_KEYBOARD];
156 float mSweetSpotCenterYs[MAX_KEY_COUNT_IN_A_KEYBOARD];
157 float mSweetSpotRadii[MAX_KEY_COUNT_IN_A_KEYBOARD];
Ken Wakasaf2789812012-09-04 12:49:46 +0900158 int mCodePointToKeyIndex[MAX_CHAR_CODE + 1];
Satoshi Kataoka6b4a1d72012-08-10 15:42:56 +0900159
Ken Wakasaf2789812012-09-04 12:49:46 +0900160 int mKeyIndexToCodePointG[MAX_KEY_COUNT_IN_A_KEYBOARD];
Satoshi Kataoka6b4a1d72012-08-10 15:42:56 +0900161 int mCenterXsG[MAX_KEY_COUNT_IN_A_KEYBOARD];
162 int mCenterYsG[MAX_KEY_COUNT_IN_A_KEYBOARD];
163 int mKeyKeyDistancesG[MAX_KEY_COUNT_IN_A_KEYBOARD][MAX_KEY_COUNT_IN_A_KEYBOARD];
Satoshi Kataoka3e8c58f2012-06-05 17:55:52 +0900164 // TODO: move to correction.h
satok8fbd5522011-02-22 17:28:55 +0900165};
Ken Wakasace9e52a2011-06-18 13:09:55 +0900166} // namespace latinime
satok8fbd5522011-02-22 17:28:55 +0900167#endif // LATINIME_PROXIMITY_INFO_H