2011-02-22 08:28:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LATINIME_PROXIMITY_INFO_H
|
|
|
|
#define LATINIME_PROXIMITY_INFO_H
|
|
|
|
|
|
|
|
#include "defines.h"
|
2012-09-03 19:50:21 +00:00
|
|
|
#include "hash_map_compat.h"
|
2012-08-08 11:43:47 +00:00
|
|
|
#include "jni.h"
|
2013-01-17 10:46:12 +00:00
|
|
|
#include "proximity_info_utils.h"
|
2011-02-22 08:28:55 +00:00
|
|
|
|
|
|
|
namespace latinime {
|
|
|
|
|
2011-08-10 05:30:10 +00:00
|
|
|
class Correction;
|
2011-07-15 04:49:00 +00:00
|
|
|
|
2011-02-22 08:28:55 +00:00
|
|
|
class ProximityInfo {
|
2012-01-06 03:24:38 +00:00
|
|
|
public:
|
2013-01-22 04:14:53 +00:00
|
|
|
ProximityInfo(JNIEnv *env, const jstring localeJStr,
|
2012-04-18 06:44:34 +00:00
|
|
|
const int keyboardWidth, const int keyboardHeight, const int gridWidth,
|
2012-08-08 11:43:47 +00:00
|
|
|
const int gridHeight, const int mostCommonKeyWidth, const jintArray proximityChars,
|
|
|
|
const int keyCount, const jintArray keyXCoordinates, const jintArray keyYCoordinates,
|
|
|
|
const jintArray keyWidths, const jintArray keyHeights, const jintArray keyCharCodes,
|
|
|
|
const jfloatArray sweetSpotCenterXs, const jfloatArray sweetSpotCenterYs,
|
|
|
|
const jfloatArray sweetSpotRadii);
|
2011-02-22 08:28:55 +00:00
|
|
|
~ProximityInfo();
|
2011-03-04 14:06:45 +00:00
|
|
|
bool hasSpaceProximity(const int x, const int y) const;
|
2012-06-05 08:55:52 +00:00
|
|
|
int getNormalizedSquaredDistance(const int inputIndex, const int proximityIndex) const;
|
2012-09-24 09:29:31 +00:00
|
|
|
float getNormalizedSquaredDistanceFromCenterFloatG(
|
2013-04-09 05:15:47 +00:00
|
|
|
const int keyId, const int x, const int y,
|
|
|
|
const float verticalScale) const;
|
2012-06-05 08:55:52 +00:00
|
|
|
bool sameAsTyped(const unsigned short *word, int length) const;
|
2012-09-04 03:49:46 +00:00
|
|
|
int getCodePointOf(const int keyIndex) const;
|
2012-06-05 08:55:52 +00:00
|
|
|
bool hasSweetSpotData(const int keyIndex) const {
|
|
|
|
// When there are no calibration data for a key,
|
|
|
|
// the radius of the key is assigned to zero.
|
2012-08-16 10:34:02 +00:00
|
|
|
return mSweetSpotRadii[keyIndex] > 0.0f;
|
2012-06-05 08:55:52 +00:00
|
|
|
}
|
2013-01-30 09:37:58 +00:00
|
|
|
float getSweetSpotRadiiAt(int keyIndex) const { return mSweetSpotRadii[keyIndex]; }
|
|
|
|
float getSweetSpotCenterXAt(int keyIndex) const { return mSweetSpotCenterXs[keyIndex]; }
|
|
|
|
float getSweetSpotCenterYAt(int keyIndex) const { return mSweetSpotCenterYs[keyIndex]; }
|
2012-06-05 08:55:52 +00:00
|
|
|
void calculateNearbyKeyCodes(
|
2012-12-03 10:43:15 +00:00
|
|
|
const int x, const int y, const int primaryKey, int *inputCodes) const;
|
2013-01-30 09:37:58 +00:00
|
|
|
bool hasTouchPositionCorrectionData() const { return HAS_TOUCH_POSITION_CORRECTION_DATA; }
|
|
|
|
int getMostCommonKeyWidth() const { return MOST_COMMON_KEY_WIDTH; }
|
|
|
|
int getMostCommonKeyWidthSquare() const { return MOST_COMMON_KEY_WIDTH_SQUARE; }
|
|
|
|
int getKeyCount() const { return KEY_COUNT; }
|
|
|
|
int getCellHeight() const { return CELL_HEIGHT; }
|
|
|
|
int getCellWidth() const { return CELL_WIDTH; }
|
|
|
|
int getGridWidth() const { return GRID_WIDTH; }
|
|
|
|
int getGridHeight() const { return GRID_HEIGHT; }
|
|
|
|
int getKeyboardWidth() const { return KEYBOARD_WIDTH; }
|
|
|
|
int getKeyboardHeight() const { return KEYBOARD_HEIGHT; }
|
2013-02-08 19:35:19 +00:00
|
|
|
float getKeyboardHypotenuse() const { return KEYBOARD_HYPOTENUSE; }
|
2012-09-04 08:00:24 +00:00
|
|
|
|
2012-09-10 07:49:36 +00:00
|
|
|
int getKeyCenterXOfCodePointG(int charCode) const;
|
|
|
|
int getKeyCenterYOfCodePointG(int charCode) const;
|
|
|
|
int getKeyCenterXOfKeyIdG(int keyId) const;
|
|
|
|
int getKeyCenterYOfKeyIdG(int keyId) const;
|
2012-10-11 04:08:06 +00:00
|
|
|
int getKeyKeyDistanceG(int keyId0, int keyId1) const;
|
2012-08-10 06:42:56 +00:00
|
|
|
|
2013-02-28 05:17:25 +00:00
|
|
|
AK_FORCE_INLINE void initializeProximities(const int *const inputCodes,
|
2013-02-13 10:56:19 +00:00
|
|
|
const int *const inputXCoordinates, const int *const inputYCoordinates,
|
|
|
|
const int inputSize, int *allInputCodes) const {
|
2013-01-17 10:46:12 +00:00
|
|
|
ProximityInfoUtils::initializeProximities(inputCodes, inputXCoordinates, inputYCoordinates,
|
|
|
|
inputSize, mKeyXCoordinates, mKeyYCoordinates, mKeyWidths, mKeyHeights,
|
2013-01-30 10:24:03 +00:00
|
|
|
mProximityCharsArray, CELL_HEIGHT, CELL_WIDTH, GRID_WIDTH, MOST_COMMON_KEY_WIDTH,
|
|
|
|
KEY_COUNT, mLocaleStr, &mCodeToKeyMap, allInputCodes);
|
2013-01-17 10:46:12 +00:00
|
|
|
}
|
|
|
|
|
2013-02-28 05:17:25 +00:00
|
|
|
AK_FORCE_INLINE int getKeyIndexOf(const int c) const {
|
2013-01-17 10:46:12 +00:00
|
|
|
return ProximityInfoUtils::getKeyIndexOf(KEY_COUNT, c, &mCodeToKeyMap);
|
|
|
|
}
|
|
|
|
|
2013-02-28 05:17:25 +00:00
|
|
|
AK_FORCE_INLINE bool isCodePointOnKeyboard(const int codePoint) const {
|
|
|
|
return getKeyIndexOf(codePoint) != NOT_AN_INDEX;
|
|
|
|
}
|
|
|
|
|
2012-01-06 03:24:38 +00:00
|
|
|
private:
|
2012-06-14 18:25:50 +00:00
|
|
|
DISALLOW_IMPLICIT_CONSTRUCTORS(ProximityInfo);
|
2011-09-21 03:02:47 +00:00
|
|
|
|
2012-08-10 06:42:56 +00:00
|
|
|
void initializeG();
|
2011-10-06 10:12:20 +00:00
|
|
|
float calculateNormalizedSquaredDistance(const int keyIndex, const int inputIndex) const;
|
2012-03-14 14:17:12 +00:00
|
|
|
bool hasInputCoordinates() const;
|
2011-10-03 07:44:29 +00:00
|
|
|
|
2011-02-22 08:28:55 +00:00
|
|
|
const int GRID_WIDTH;
|
|
|
|
const int GRID_HEIGHT;
|
2012-08-10 06:42:56 +00:00
|
|
|
const int MOST_COMMON_KEY_WIDTH;
|
2012-03-07 06:12:22 +00:00
|
|
|
const int MOST_COMMON_KEY_WIDTH_SQUARE;
|
2011-03-19 00:16:42 +00:00
|
|
|
const int CELL_WIDTH;
|
|
|
|
const int CELL_HEIGHT;
|
2011-09-21 03:02:47 +00:00
|
|
|
const int KEY_COUNT;
|
2012-09-04 08:00:24 +00:00
|
|
|
const int KEYBOARD_WIDTH;
|
|
|
|
const int KEYBOARD_HEIGHT;
|
2013-02-08 19:35:19 +00:00
|
|
|
const float KEYBOARD_HYPOTENUSE;
|
2011-10-06 10:12:20 +00:00
|
|
|
const bool HAS_TOUCH_POSITION_CORRECTION_DATA;
|
2012-08-09 13:26:58 +00:00
|
|
|
char mLocaleStr[MAX_LOCALE_STRING_LENGTH];
|
2012-12-03 10:43:15 +00:00
|
|
|
int *mProximityCharsArray;
|
|
|
|
int mKeyXCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
|
|
|
int mKeyYCoordinates[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
|
|
|
int mKeyWidths[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
|
|
|
int mKeyHeights[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
|
|
|
int mKeyCodePoints[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
2011-09-29 07:44:54 +00:00
|
|
|
float mSweetSpotCenterXs[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
|
|
|
float mSweetSpotCenterYs[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
|
|
|
float mSweetSpotRadii[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
2012-09-03 19:50:21 +00:00
|
|
|
hash_map_compat<int, int> mCodeToKeyMap;
|
2012-08-10 06:42:56 +00:00
|
|
|
|
2012-09-04 03:49:46 +00:00
|
|
|
int mKeyIndexToCodePointG[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
2012-08-10 06:42:56 +00:00
|
|
|
int mCenterXsG[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
|
|
|
int mCenterYsG[MAX_KEY_COUNT_IN_A_KEYBOARD];
|
|
|
|
int mKeyKeyDistancesG[MAX_KEY_COUNT_IN_A_KEYBOARD][MAX_KEY_COUNT_IN_A_KEYBOARD];
|
2012-06-05 08:55:52 +00:00
|
|
|
// TODO: move to correction.h
|
2011-02-22 08:28:55 +00:00
|
|
|
};
|
2011-06-18 04:09:55 +00:00
|
|
|
} // namespace latinime
|
2011-02-22 08:28:55 +00:00
|
|
|
#endif // LATINIME_PROXIMITY_INFO_H
|