am b45e095a
: Merge "Add touch position correction data to resources."
* commit 'b45e095aa205c25c29689be6c5db3308fb97e673': Add touch position correction data to resources.
This commit is contained in:
commit
8a75f125df
12 changed files with 155 additions and 5 deletions
|
@ -34,6 +34,8 @@
|
||||||
<attr name="moreSuggestionsViewStyle" format="reference" />
|
<attr name="moreSuggestionsViewStyle" format="reference" />
|
||||||
<attr name="suggestionBackgroundStyle" format="reference" />
|
<attr name="suggestionBackgroundStyle" format="reference" />
|
||||||
<attr name="suggestionPreviewBackgroundStyle" format="reference" />
|
<attr name="suggestionPreviewBackgroundStyle" format="reference" />
|
||||||
|
<!-- Touch position correction -->
|
||||||
|
<attr name="touchPositionCorrectionData" format="reference" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="KeyboardView">
|
<declare-styleable name="KeyboardView">
|
||||||
|
|
|
@ -28,5 +28,6 @@
|
||||||
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
|
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
|
||||||
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
||||||
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
|
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
|
||||||
|
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_empty</item>
|
||||||
</style>
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -28,5 +28,6 @@
|
||||||
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
|
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
|
||||||
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
||||||
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
|
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
|
||||||
|
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_empty</item>
|
||||||
</style>
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -28,5 +28,6 @@
|
||||||
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
|
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
|
||||||
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
||||||
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
|
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
|
||||||
|
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_gingerbread</item>
|
||||||
</style>
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -28,5 +28,6 @@
|
||||||
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle.IceCreamSandwich</item>
|
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle.IceCreamSandwich</item>
|
||||||
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle.IceCreamSandwich</item>
|
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle.IceCreamSandwich</item>
|
||||||
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle.IceCreamSandwich</item>
|
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle.IceCreamSandwich</item>
|
||||||
|
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_ice_cream_sandwich</item>
|
||||||
</style>
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -28,5 +28,6 @@
|
||||||
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
|
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
|
||||||
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
||||||
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
|
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
|
||||||
|
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_empty</item>
|
||||||
</style>
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -28,5 +28,6 @@
|
||||||
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
|
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
|
||||||
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
||||||
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
|
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
|
||||||
|
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_empty</item>
|
||||||
</style>
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
74
java/res/values/touch-position-correction.xml
Normal file
74
java/res/values/touch-position-correction.xml
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
/*
|
||||||
|
**
|
||||||
|
** Copyright 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.
|
||||||
|
*/
|
||||||
|
-->
|
||||||
|
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||||
|
<!--
|
||||||
|
An entry of the touch_position_correction word should be:
|
||||||
|
1. (float) (touch_center_x - key_center_x) / key_width
|
||||||
|
2. (float) (touch_center_y - key_center_y) / key_height
|
||||||
|
3. (float) sweet_spot_radius / (key_width^2 + key_height^2)
|
||||||
|
-->
|
||||||
|
|
||||||
|
<string-array
|
||||||
|
name="touch_position_correction_data_empty"
|
||||||
|
translatable="false"
|
||||||
|
>
|
||||||
|
<!-- empty -->
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array
|
||||||
|
name="touch_position_correction_data_gingerbread"
|
||||||
|
translatable="false"
|
||||||
|
>
|
||||||
|
<!-- First row -->
|
||||||
|
<item>0.0091285</item>
|
||||||
|
<item>0.1193203</item>
|
||||||
|
<item>0.1622607</item>
|
||||||
|
|
||||||
|
<!-- Second row -->
|
||||||
|
<item>-0.0233128</item>
|
||||||
|
<item>0.1379798</item>
|
||||||
|
<item>0.1585229</item>
|
||||||
|
|
||||||
|
<!-- Third row -->
|
||||||
|
<item>-0.0080185</item>
|
||||||
|
<item>0.1911477</item>
|
||||||
|
<item>0.1570948</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array
|
||||||
|
name="touch_position_correction_data_ice_cream_sandwich"
|
||||||
|
translatable="false"
|
||||||
|
>
|
||||||
|
<!-- First row -->
|
||||||
|
<item>0.0038756</item>
|
||||||
|
<item>-0.0005677</item>
|
||||||
|
<item>0.1577026</item>
|
||||||
|
|
||||||
|
<!-- Second row -->
|
||||||
|
<item>-0.0236678</item>
|
||||||
|
<item>0.0381731</item>
|
||||||
|
<item>0.1529972</item>
|
||||||
|
|
||||||
|
<!-- Third row -->
|
||||||
|
<item>-0.0086827</item>
|
||||||
|
<item>0.0880847</item>
|
||||||
|
<item>0.1522819</item>
|
||||||
|
</string-array>
|
||||||
|
</resources>
|
|
@ -138,7 +138,8 @@ public class Keyboard {
|
||||||
|
|
||||||
mProximityInfo = new ProximityInfo(
|
mProximityInfo = new ProximityInfo(
|
||||||
params.GRID_WIDTH, params.GRID_HEIGHT, mOccupiedWidth, mOccupiedHeight,
|
params.GRID_WIDTH, params.GRID_HEIGHT, mOccupiedWidth, mOccupiedHeight,
|
||||||
mMostCommonKeyWidth, mKeys);
|
mMostCommonKeyWidth, mKeys, params.mTouchPositionCorrectionXs,
|
||||||
|
params.mTouchPositionCorrectionYs, params.mTouchPositionCorrectionRadii);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProximityInfo getProximityInfo() {
|
public ProximityInfo getProximityInfo() {
|
||||||
|
|
|
@ -40,8 +40,13 @@ public class ProximityInfo {
|
||||||
private final int mKeyboardHeight;
|
private final int mKeyboardHeight;
|
||||||
private final int[][] mGridNeighbors;
|
private final int[][] mGridNeighbors;
|
||||||
|
|
||||||
ProximityInfo(
|
private final float[] mTouchPositionCorrectionXs;
|
||||||
int gridWidth, int gridHeight, int minWidth, int height, int keyWidth, List<Key> keys) {
|
private final float[] mTouchPositionCorrectionYs;
|
||||||
|
private final float[] mTouchPositionCorrectionRadii;
|
||||||
|
|
||||||
|
ProximityInfo(int gridWidth, int gridHeight, int minWidth, int height, int keyWidth,
|
||||||
|
List<Key> keys, float[] touchPositionCorrectionXs, float[] touchPositionCorrectionYs,
|
||||||
|
float[] touchPositionCorrectionRadii) {
|
||||||
mGridWidth = gridWidth;
|
mGridWidth = gridWidth;
|
||||||
mGridHeight = gridHeight;
|
mGridHeight = gridHeight;
|
||||||
mGridSize = mGridWidth * mGridHeight;
|
mGridSize = mGridWidth * mGridHeight;
|
||||||
|
@ -49,6 +54,9 @@ public class ProximityInfo {
|
||||||
mCellHeight = (height + mGridHeight - 1) / mGridHeight;
|
mCellHeight = (height + mGridHeight - 1) / mGridHeight;
|
||||||
mKeyboardMinWidth = minWidth;
|
mKeyboardMinWidth = minWidth;
|
||||||
mKeyboardHeight = height;
|
mKeyboardHeight = height;
|
||||||
|
mTouchPositionCorrectionXs = touchPositionCorrectionXs;
|
||||||
|
mTouchPositionCorrectionYs = touchPositionCorrectionYs;
|
||||||
|
mTouchPositionCorrectionRadii = touchPositionCorrectionRadii;
|
||||||
mGridNeighbors = new int[mGridSize][];
|
mGridNeighbors = new int[mGridSize][];
|
||||||
if (minWidth == 0 || height == 0) {
|
if (minWidth == 0 || height == 0) {
|
||||||
// No proximity required. Keyboard might be mini keyboard.
|
// No proximity required. Keyboard might be mini keyboard.
|
||||||
|
@ -58,7 +66,7 @@ public class ProximityInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ProximityInfo createDummyProximityInfo() {
|
public static ProximityInfo createDummyProximityInfo() {
|
||||||
return new ProximityInfo(1, 1, 1, 1, 1, Collections.<Key>emptyList());
|
return new ProximityInfo(1, 1, 1, 1, 1, Collections.<Key>emptyList(), null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ProximityInfo createSpellCheckerProximityInfo() {
|
public static ProximityInfo createSpellCheckerProximityInfo() {
|
||||||
|
|
|
@ -30,6 +30,7 @@ import com.android.inputmethod.compat.EditorInfoCompatUtils;
|
||||||
import com.android.inputmethod.keyboard.Key;
|
import com.android.inputmethod.keyboard.Key;
|
||||||
import com.android.inputmethod.keyboard.Keyboard;
|
import com.android.inputmethod.keyboard.Keyboard;
|
||||||
import com.android.inputmethod.keyboard.KeyboardId;
|
import com.android.inputmethod.keyboard.KeyboardId;
|
||||||
|
import com.android.inputmethod.latin.LatinImeLogger;
|
||||||
import com.android.inputmethod.latin.R;
|
import com.android.inputmethod.latin.R;
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
|
@ -126,6 +127,8 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
private static final int DEFAULT_KEYBOARD_COLUMNS = 10;
|
private static final int DEFAULT_KEYBOARD_COLUMNS = 10;
|
||||||
private static final int DEFAULT_KEYBOARD_ROWS = 4;
|
private static final int DEFAULT_KEYBOARD_ROWS = 4;
|
||||||
|
|
||||||
|
private static final int TOUCH_POSITION_CORRECTION_RECORD_SIZE = 3;
|
||||||
|
|
||||||
protected final KP mParams;
|
protected final KP mParams;
|
||||||
protected final Context mContext;
|
protected final Context mContext;
|
||||||
protected final Resources mResources;
|
protected final Resources mResources;
|
||||||
|
@ -248,10 +251,62 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
||||||
mParams.mThemeId = a.getInt(R.styleable.KeyboardTheme_themeId, 0);
|
mParams.mThemeId = a.getInt(R.styleable.KeyboardTheme_themeId, 0);
|
||||||
a.recycle();
|
a.recycle();
|
||||||
|
|
||||||
|
if (!setTouchPositionCorrectionData(context)) {
|
||||||
|
// In the regression test, setTouchPositionCorrectionData() fails
|
||||||
|
mParams.mTouchPositionCorrectionXs = null;
|
||||||
|
mParams.mTouchPositionCorrectionYs = null;
|
||||||
|
mParams.mTouchPositionCorrectionRadii = null;
|
||||||
|
}
|
||||||
|
|
||||||
mParams.GRID_WIDTH = res.getInteger(R.integer.config_keyboard_grid_width);
|
mParams.GRID_WIDTH = res.getInteger(R.integer.config_keyboard_grid_width);
|
||||||
mParams.GRID_HEIGHT = res.getInteger(R.integer.config_keyboard_grid_height);
|
mParams.GRID_HEIGHT = res.getInteger(R.integer.config_keyboard_grid_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean setTouchPositionCorrectionData(Context context) {
|
||||||
|
final TypedArray a = context.obtainStyledAttributes(R.styleable.KeyboardTheme);
|
||||||
|
final int resourceId = a.getResourceId(
|
||||||
|
R.styleable.KeyboardTheme_touchPositionCorrectionData, 0);
|
||||||
|
if (resourceId == 0) {
|
||||||
|
// In the regression test, we cannot use theme resources
|
||||||
|
// TODO: Fix this
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final String[] data = context.getResources().getStringArray(resourceId);
|
||||||
|
a.recycle();
|
||||||
|
final int dataLength = data.length;
|
||||||
|
if (dataLength % TOUCH_POSITION_CORRECTION_RECORD_SIZE != 0) {
|
||||||
|
if (LatinImeLogger.sDBG) {
|
||||||
|
throw new RuntimeException("the size of touch position correction data is invalid");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final int length = dataLength / TOUCH_POSITION_CORRECTION_RECORD_SIZE;
|
||||||
|
mParams.mTouchPositionCorrectionXs = new float[length];
|
||||||
|
mParams.mTouchPositionCorrectionYs = new float[length];
|
||||||
|
mParams.mTouchPositionCorrectionRadii = new float[length];
|
||||||
|
try {
|
||||||
|
for (int i = 0; i < dataLength; ++i) {
|
||||||
|
final int type = i % TOUCH_POSITION_CORRECTION_RECORD_SIZE;
|
||||||
|
final int index = i / TOUCH_POSITION_CORRECTION_RECORD_SIZE;
|
||||||
|
final float value = Float.parseFloat(data[i]);
|
||||||
|
if (type == 0) {
|
||||||
|
mParams.mTouchPositionCorrectionXs[index] = value;
|
||||||
|
} else if (type == 1) {
|
||||||
|
mParams.mTouchPositionCorrectionYs[index] = value;
|
||||||
|
} else {
|
||||||
|
mParams.mTouchPositionCorrectionRadii[index] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
if (LatinImeLogger.sDBG) {
|
||||||
|
throw new RuntimeException(
|
||||||
|
"the number format for touch position correction data is invalid");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public KeyboardBuilder<KP> load(KeyboardId id) {
|
public KeyboardBuilder<KP> load(KeyboardId id) {
|
||||||
mParams.mId = id;
|
mParams.mId = id;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -68,6 +68,10 @@ public class KeyboardParams {
|
||||||
public int mMostCommonKeyHeight = 0;
|
public int mMostCommonKeyHeight = 0;
|
||||||
public int mMostCommonKeyWidth = 0;
|
public int mMostCommonKeyWidth = 0;
|
||||||
|
|
||||||
|
public float[] mTouchPositionCorrectionXs;
|
||||||
|
public float[] mTouchPositionCorrectionYs;
|
||||||
|
public float[] mTouchPositionCorrectionRadii;
|
||||||
|
|
||||||
protected void clearKeys() {
|
protected void clearKeys() {
|
||||||
mKeys.clear();
|
mKeys.clear();
|
||||||
mShiftKeys.clear();
|
mShiftKeys.clear();
|
||||||
|
|
Loading…
Reference in a new issue