blob: 6d571d7bba22e3d93f1dead3b7e2374e2bc59c16 [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
satok8fbd5522011-02-22 17:28:55 +090020#include "defines.h"
Tom Ouyang13216852012-09-03 12:50:21 -070021#include "hash_map_compat.h"
Ken Wakasabb005f72012-08-08 20:43:47 +090022#include "jni.h"
Satoshi Kataokabf78e132013-01-17 19:46:12 +090023#include "proximity_info_utils.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 Wakasa6c224392013-01-22 13:14:53 +090031 ProximityInfo(JNIEnv *env, const jstring localeJStr,
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 Kataoka0edab9d2012-09-24 18:29:31 +090041 float getNormalizedSquaredDistanceFromCenterFloatG(
Satoshi Kataokae7398cd2012-08-13 20:20:04 +090042 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 getCodePointOf(const int keyIndex) const;
Satoshi Kataoka3e8c58f2012-06-05 17:55:52 +090045 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 Wakasafee0ac62012-08-16 19:34:02 +090048 return mSweetSpotRadii[keyIndex] > 0.0f;
Satoshi Kataoka3e8c58f2012-06-05 17:55:52 +090049 }
50 float getSweetSpotRadiiAt(int keyIndex) const {
51 return mSweetSpotRadii[keyIndex];
52 }
53 float getSweetSpotCenterXAt(int keyIndex) const {
54 return mSweetSpotCenterXs[keyIndex];
55 }
56 float getSweetSpotCenterYAt(int keyIndex) const {
57 return mSweetSpotCenterYs[keyIndex];
58 }
59 void calculateNearbyKeyCodes(
Ken Wakasa1d516fb2012-12-03 19:43:15 +090060 const int x, const int y, const int primaryKey, int *inputCodes) const;
Satoshi Kataoka3e8c58f2012-06-05 17:55:52 +090061
Satoshi Kataoka4a3db702012-06-08 15:29:44 +090062 bool hasTouchPositionCorrectionData() const {
63 return HAS_TOUCH_POSITION_CORRECTION_DATA;
64 }
65
Satoshi Kataoka6b4a1d72012-08-10 15:42:56 +090066 int getMostCommonKeyWidth() const {
67 return MOST_COMMON_KEY_WIDTH;
68 }
69
Satoshi Kataoka4a3db702012-06-08 15:29:44 +090070 int getMostCommonKeyWidthSquare() const {
71 return MOST_COMMON_KEY_WIDTH_SQUARE;
72 }
73
Satoshi Kataoka4a3db702012-06-08 15:29:44 +090074 int getKeyCount() const {
75 return KEY_COUNT;
76 }
77
78 int getCellHeight() const {
79 return CELL_HEIGHT;
80 }
81
82 int getCellWidth() const {
83 return CELL_WIDTH;
84 }
85
86 int getGridWidth() const {
87 return GRID_WIDTH;
88 }
89
90 int getGridHeight() const {
91 return GRID_HEIGHT;
92 }
satok635f68e2011-08-10 22:19:33 +090093
Keisuke Kuroyanagi95a49a52012-09-04 17:00:24 +090094 int getKeyboardWidth() const {
95 return KEYBOARD_WIDTH;
96 }
97
98 int getKeyboardHeight() const {
99 return KEYBOARD_HEIGHT;
100 }
101
Ken Wakasa5964d4e2012-09-10 16:49:36 +0900102 int getKeyCenterXOfCodePointG(int charCode) const;
103 int getKeyCenterYOfCodePointG(int charCode) const;
104 int getKeyCenterXOfKeyIdG(int keyId) const;
105 int getKeyCenterYOfKeyIdG(int keyId) const;
Keisuke Kuroyanagiff74cc32012-10-11 13:08:06 +0900106 int getKeyKeyDistanceG(int keyId0, int keyId1) const;
Satoshi Kataoka6b4a1d72012-08-10 15:42:56 +0900107
Satoshi Kataokabf78e132013-01-17 19:46:12 +0900108 void initializeProximities(const int *const inputCodes, const int *const inputXCoordinates,
109 const int *const inputYCoordinates, const int inputSize, int *allInputCodes) const {
110 ProximityInfoUtils::initializeProximities(inputCodes, inputXCoordinates, inputYCoordinates,
111 inputSize, mKeyXCoordinates, mKeyYCoordinates, mKeyWidths, mKeyHeights,
112 mProximityCharsArray, MAX_PROXIMITY_CHARS_SIZE, CELL_HEIGHT, CELL_WIDTH,
113 GRID_WIDTH, MOST_COMMON_KEY_WIDTH, KEY_COUNT, mLocaleStr, &mCodeToKeyMap,
114 allInputCodes);
115 }
116
117 int getKeyIndexOf(const int c) const {
118 return ProximityInfoUtils::getKeyIndexOf(KEY_COUNT, c, &mCodeToKeyMap);
119 }
120
Ken Wakasae12e9b52012-01-06 12:24:38 +0900121 private:
satok1bc038c2012-06-14 11:25:50 -0700122 DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfo);
Ken Wakasa162c2112012-08-24 14:51:15 +0900123 static const float NOT_A_DISTANCE_FLOAT;
Yusuke Nojima0e1f6562011-09-21 12:02:47 +0900124
Satoshi Kataoka6b4a1d72012-08-10 15:42:56 +0900125 void initializeG();
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +0900126 float calculateNormalizedSquaredDistance(const int keyIndex, const int inputIndex) const;
satok1caff472012-03-14 23:17:12 +0900127 bool hasInputCoordinates() const;
Yusuke Nojimac25c7cc2011-10-03 16:44:29 +0900128
satok8fbd5522011-02-22 17:28:55 +0900129 const int GRID_WIDTH;
130 const int GRID_HEIGHT;
Satoshi Kataoka6b4a1d72012-08-10 15:42:56 +0900131 const int MOST_COMMON_KEY_WIDTH;
satoka70ee6e2012-03-07 15:12:22 +0900132 const int MOST_COMMON_KEY_WIDTH_SQUARE;
Ken Wakasade3070a2011-03-19 09:16:42 +0900133 const int CELL_WIDTH;
134 const int CELL_HEIGHT;
Yusuke Nojima0e1f6562011-09-21 12:02:47 +0900135 const int KEY_COUNT;
Keisuke Kuroyanagi95a49a52012-09-04 17:00:24 +0900136 const int KEYBOARD_WIDTH;
137 const int KEYBOARD_HEIGHT;
Yusuke Nojimaa4c1f1c2011-10-06 19:12:20 +0900138 const bool HAS_TOUCH_POSITION_CORRECTION_DATA;
Ken Wakasa9e0c7112012-08-09 22:26:58 +0900139 char mLocaleStr[MAX_LOCALE_STRING_LENGTH];
Ken Wakasa1d516fb2012-12-03 19:43:15 +0900140 int *mProximityCharsArray;
141 int mKeyXCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
142 int mKeyYCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
143 int mKeyWidths[MAX_KEY_COUNT_IN_A_KEYBOARD];
144 int mKeyHeights[MAX_KEY_COUNT_IN_A_KEYBOARD];
145 int mKeyCodePoints[MAX_KEY_COUNT_IN_A_KEYBOARD];
Yusuke Nojimaad358352011-09-29 16:44:54 +0900146 float mSweetSpotCenterXs[MAX_KEY_COUNT_IN_A_KEYBOARD];
147 float mSweetSpotCenterYs[MAX_KEY_COUNT_IN_A_KEYBOARD];
148 float mSweetSpotRadii[MAX_KEY_COUNT_IN_A_KEYBOARD];
Tom Ouyang13216852012-09-03 12:50:21 -0700149 hash_map_compat<int, int> mCodeToKeyMap;
Satoshi Kataoka6b4a1d72012-08-10 15:42:56 +0900150
Ken Wakasaf2789812012-09-04 12:49:46 +0900151 int mKeyIndexToCodePointG[MAX_KEY_COUNT_IN_A_KEYBOARD];
Satoshi Kataoka6b4a1d72012-08-10 15:42:56 +0900152 int mCenterXsG[MAX_KEY_COUNT_IN_A_KEYBOARD];
153 int mCenterYsG[MAX_KEY_COUNT_IN_A_KEYBOARD];
154 int mKeyKeyDistancesG[MAX_KEY_COUNT_IN_A_KEYBOARD][MAX_KEY_COUNT_IN_A_KEYBOARD];
Satoshi Kataoka3e8c58f2012-06-05 17:55:52 +0900155 // TODO: move to correction.h
satok8fbd5522011-02-22 17:28:55 +0900156};
Ken Wakasace9e52a2011-06-18 13:09:55 +0900157} // namespace latinime
satok8fbd5522011-02-22 17:28:55 +0900158#endif // LATINIME_PROXIMITY_INFO_H