2011-02-22 08:28:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.keyboard;
|
|
|
|
|
2011-02-25 09:21:02 +00:00
|
|
|
import com.android.inputmethod.latin.Utils;
|
|
|
|
|
2011-03-04 14:06:45 +00:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
2011-02-22 08:28:55 +00:00
|
|
|
public class ProximityInfo {
|
|
|
|
public static final int MAX_PROXIMITY_CHARS_SIZE = 16;
|
|
|
|
|
|
|
|
private final int mGridWidth;
|
|
|
|
private final int mGridHeight;
|
|
|
|
private final int mGridSize;
|
|
|
|
|
2011-03-04 14:06:45 +00:00
|
|
|
ProximityInfo(int gridWidth, int gridHeight) {
|
2011-02-22 08:28:55 +00:00
|
|
|
mGridWidth = gridWidth;
|
|
|
|
mGridHeight = gridHeight;
|
|
|
|
mGridSize = mGridWidth * mGridHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int mNativeProximityInfo;
|
2011-02-25 09:21:02 +00:00
|
|
|
static {
|
|
|
|
Utils.loadNativeLibrary();
|
|
|
|
}
|
2011-02-22 08:28:55 +00:00
|
|
|
private native int setProximityInfoNative(int maxProximityCharsSize, int displayWidth,
|
|
|
|
int displayHeight, int gridWidth, int gridHeight, int[] proximityCharsArray);
|
|
|
|
private native void releaseProximityInfoNative(int nativeProximityInfo);
|
|
|
|
|
2011-03-04 14:06:45 +00:00
|
|
|
public final void setProximityInfo(int[][] gridNeighborKeyIndexes, int keyboardWidth,
|
|
|
|
int keyboardHeight, List<Key> keys) {
|
2011-02-22 08:28:55 +00:00
|
|
|
int[] proximityCharsArray = new int[mGridSize * MAX_PROXIMITY_CHARS_SIZE];
|
2011-03-04 14:06:45 +00:00
|
|
|
Arrays.fill(proximityCharsArray, KeyDetector.NOT_A_CODE);
|
2011-02-22 08:28:55 +00:00
|
|
|
for (int i = 0; i < mGridSize; ++i) {
|
2011-03-04 14:06:45 +00:00
|
|
|
final int proximityCharsLength = gridNeighborKeyIndexes[i].length;
|
|
|
|
for (int j = 0; j < proximityCharsLength; ++j) {
|
|
|
|
proximityCharsArray[i * MAX_PROXIMITY_CHARS_SIZE + j] =
|
|
|
|
keys.get(gridNeighborKeyIndexes[i][j]).mCode;
|
2011-02-22 08:28:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mNativeProximityInfo = setProximityInfoNative(MAX_PROXIMITY_CHARS_SIZE,
|
2011-03-04 14:06:45 +00:00
|
|
|
keyboardWidth, keyboardHeight, mGridWidth, mGridHeight, proximityCharsArray);
|
2011-02-22 08:28:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Get rid of this function's input (keyboard).
|
|
|
|
public int getNativeProximityInfo(Keyboard keyboard) {
|
|
|
|
if (mNativeProximityInfo == 0) {
|
|
|
|
// TODO: Move this function to ProximityInfo and make this private.
|
|
|
|
keyboard.computeNearestNeighbors();
|
|
|
|
}
|
|
|
|
return mNativeProximityInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void finalize() throws Throwable {
|
|
|
|
try {
|
|
|
|
if (mNativeProximityInfo != 0) {
|
|
|
|
releaseProximityInfoNative(mNativeProximityInfo);
|
|
|
|
mNativeProximityInfo = 0;
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
super.finalize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|