Merge "Add touch position correction data to resources."
commit
b45e095aa2
|
@ -34,6 +34,8 @@
|
|||
<attr name="moreSuggestionsViewStyle" format="reference" />
|
||||
<attr name="suggestionBackgroundStyle" format="reference" />
|
||||
<attr name="suggestionPreviewBackgroundStyle" format="reference" />
|
||||
<!-- Touch position correction -->
|
||||
<attr name="touchPositionCorrectionData" format="reference" />
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="KeyboardView">
|
||||
|
|
|
@ -28,5 +28,6 @@
|
|||
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
|
||||
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
||||
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
|
||||
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_empty</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
|
@ -28,5 +28,6 @@
|
|||
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
|
||||
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
||||
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
|
||||
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_empty</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
|
@ -28,5 +28,6 @@
|
|||
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
|
||||
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
||||
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
|
||||
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_gingerbread</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
|
@ -28,5 +28,6 @@
|
|||
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle.IceCreamSandwich</item>
|
||||
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle.IceCreamSandwich</item>
|
||||
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle.IceCreamSandwich</item>
|
||||
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_ice_cream_sandwich</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
|
@ -28,5 +28,6 @@
|
|||
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
|
||||
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
||||
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
|
||||
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_empty</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
|
@ -28,5 +28,6 @@
|
|||
<item name="moreSuggestionsViewStyle">@style/MoreSuggestionsViewStyle</item>
|
||||
<item name="suggestionBackgroundStyle">@style/SuggestionBackgroundStyle</item>
|
||||
<item name="suggestionPreviewBackgroundStyle">@style/SuggestionPreviewBackgroundStyle</item>
|
||||
<item name="touchPositionCorrectionData">@array/touch_position_correction_data_empty</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
|
@ -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(
|
||||
params.GRID_WIDTH, params.GRID_HEIGHT, mOccupiedWidth, mOccupiedHeight,
|
||||
mMostCommonKeyWidth, mKeys);
|
||||
mMostCommonKeyWidth, mKeys, params.mTouchPositionCorrectionXs,
|
||||
params.mTouchPositionCorrectionYs, params.mTouchPositionCorrectionRadii);
|
||||
}
|
||||
|
||||
public ProximityInfo getProximityInfo() {
|
||||
|
|
|
@ -40,8 +40,13 @@ public class ProximityInfo {
|
|||
private final int mKeyboardHeight;
|
||||
private final int[][] mGridNeighbors;
|
||||
|
||||
ProximityInfo(
|
||||
int gridWidth, int gridHeight, int minWidth, int height, int keyWidth, List<Key> keys) {
|
||||
private final float[] mTouchPositionCorrectionXs;
|
||||
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;
|
||||
mGridHeight = gridHeight;
|
||||
mGridSize = mGridWidth * mGridHeight;
|
||||
|
@ -49,6 +54,9 @@ public class ProximityInfo {
|
|||
mCellHeight = (height + mGridHeight - 1) / mGridHeight;
|
||||
mKeyboardMinWidth = minWidth;
|
||||
mKeyboardHeight = height;
|
||||
mTouchPositionCorrectionXs = touchPositionCorrectionXs;
|
||||
mTouchPositionCorrectionYs = touchPositionCorrectionYs;
|
||||
mTouchPositionCorrectionRadii = touchPositionCorrectionRadii;
|
||||
mGridNeighbors = new int[mGridSize][];
|
||||
if (minWidth == 0 || height == 0) {
|
||||
// No proximity required. Keyboard might be mini keyboard.
|
||||
|
@ -58,7 +66,7 @@ public class ProximityInfo {
|
|||
}
|
||||
|
||||
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() {
|
||||
|
|
|
@ -30,6 +30,7 @@ import com.android.inputmethod.compat.EditorInfoCompatUtils;
|
|||
import com.android.inputmethod.keyboard.Key;
|
||||
import com.android.inputmethod.keyboard.Keyboard;
|
||||
import com.android.inputmethod.keyboard.KeyboardId;
|
||||
import com.android.inputmethod.latin.LatinImeLogger;
|
||||
import com.android.inputmethod.latin.R;
|
||||
|
||||
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_ROWS = 4;
|
||||
|
||||
private static final int TOUCH_POSITION_CORRECTION_RECORD_SIZE = 3;
|
||||
|
||||
protected final KP mParams;
|
||||
protected final Context mContext;
|
||||
protected final Resources mResources;
|
||||
|
@ -248,10 +251,62 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
|
|||
mParams.mThemeId = a.getInt(R.styleable.KeyboardTheme_themeId, 0);
|
||||
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_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) {
|
||||
mParams.mId = id;
|
||||
try {
|
||||
|
|
|
@ -68,6 +68,10 @@ public class KeyboardParams {
|
|||
public int mMostCommonKeyHeight = 0;
|
||||
public int mMostCommonKeyWidth = 0;
|
||||
|
||||
public float[] mTouchPositionCorrectionXs;
|
||||
public float[] mTouchPositionCorrectionYs;
|
||||
public float[] mTouchPositionCorrectionRadii;
|
||||
|
||||
protected void clearKeys() {
|
||||
mKeys.clear();
|
||||
mShiftKeys.clear();
|
||||
|
|
Loading…
Reference in New Issue