aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/Keyboard.java3
-rw-r--r--java/src/com/android/inputmethod/keyboard/ProximityInfo.java79
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java55
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java4
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java10
-rw-r--r--java/src/com/android/inputmethod/latin/MoreSuggestionsView.java18
-rw-r--r--java/src/com/android/inputmethod/latin/SuggestionsView.java37
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java87
8 files changed, 207 insertions, 86 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index 045f0d7b2..9e4c1ea79 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -138,7 +138,8 @@ public class Keyboard {
mProximityInfo = new ProximityInfo(
params.GRID_WIDTH, params.GRID_HEIGHT, mOccupiedWidth, mOccupiedHeight,
- mMostCommonKeyWidth, mKeys);
+ mMostCommonKeyWidth, mMostCommonKeyHeight, mKeys, params.mTouchPositionCorrectionXs,
+ params.mTouchPositionCorrectionYs, params.mTouchPositionCorrectionRadii);
}
public ProximityInfo getProximityInfo() {
diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
index 71b46d646..d35b1a939 100644
--- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
+++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
@@ -16,6 +16,9 @@
package com.android.inputmethod.keyboard;
+import android.graphics.Rect;
+
+import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.latin.spellcheck.SpellCheckerProximityInfo;
@@ -27,9 +30,9 @@ public class ProximityInfo {
public static final int MAX_PROXIMITY_CHARS_SIZE = 16;
/** Number of key widths from current touch point to search for nearest keys. */
private static float SEARCH_DISTANCE = 1.2f;
- private static final int UNKNOWN_THEME = -1;
private static final int[] EMPTY_INT_ARRAY = new int[0];
+ private final int mKeyHeight;
private final int mGridWidth;
private final int mGridHeight;
private final int mGridSize;
@@ -40,8 +43,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,
+ int keyHeight, List<Key> keys, float[] touchPositionCorrectionXs,
+ float[] touchPositionCorrectionYs, float[] touchPositionCorrectionRadii) {
mGridWidth = gridWidth;
mGridHeight = gridHeight;
mGridSize = mGridWidth * mGridHeight;
@@ -49,6 +57,10 @@ public class ProximityInfo {
mCellHeight = (height + mGridHeight - 1) / mGridHeight;
mKeyboardMinWidth = minWidth;
mKeyboardHeight = height;
+ mKeyHeight = keyHeight;
+ 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 +70,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, 1, Collections.<Key>emptyList(), null, null, null);
}
public static ProximityInfo createSpellCheckerProximityInfo() {
@@ -67,7 +79,7 @@ public class ProximityInfo {
spellCheckerProximityInfo.setProximityInfoNative(
SpellCheckerProximityInfo.ROW_SIZE,
480, 300, 10, 3, SpellCheckerProximityInfo.PROXIMITY,
- 0, null, null, null, null, null, UNKNOWN_THEME);
+ 0, null, null, null, null, null, null, null, null);
return spellCheckerProximityInfo;
}
@@ -78,7 +90,8 @@ public class ProximityInfo {
private native int setProximityInfoNative(int maxProximityCharsSize, int displayWidth,
int displayHeight, int gridWidth, int gridHeight, int[] proximityCharsArray,
int keyCount, int[] keyXCoordinates, int[] keyYCoordinates,
- int[] keyWidths, int[] keyHeights, int[] keyCharCodes, int themeId);
+ int[] keyWidths, int[] keyHeights, int[] keyCharCodes,
+ float[] sweetSpotCenterX, float[] sweetSpotCenterY, float[] sweetSpotRadii);
private native void releaseProximityInfoNative(int nativeProximityInfo);
private final void setProximityInfo(int[][] gridNeighborKeyIndexes, int keyboardWidth,
@@ -93,12 +106,11 @@ public class ProximityInfo {
}
}
final int keyCount = keys.size();
- int[] keyXCoordinates = new int[keyCount];
- int[] keyYCoordinates = new int[keyCount];
- int[] keyWidths = new int[keyCount];
- int[] keyHeights = new int[keyCount];
- int[] keyCharCodes = new int[keyCount];
- final int themeId = 5; // TODO: Use real theme id.
+ final int[] keyXCoordinates = new int[keyCount];
+ final int[] keyYCoordinates = new int[keyCount];
+ final int[] keyWidths = new int[keyCount];
+ final int[] keyHeights = new int[keyCount];
+ final int[] keyCharCodes = new int[keyCount];
for (int i = 0; i < keyCount; ++i) {
final Key key = keys.get(i);
keyXCoordinates[i] = key.mX;
@@ -107,10 +119,51 @@ public class ProximityInfo {
keyHeights[i] = key.mHeight;
keyCharCodes[i] = key.mCode;
}
+
+ final boolean hasTouchPositionCorrectionData =
+ mTouchPositionCorrectionXs != null
+ && mTouchPositionCorrectionYs != null
+ && mTouchPositionCorrectionRadii != null
+ && mTouchPositionCorrectionXs.length > 0
+ && mTouchPositionCorrectionYs.length > 0
+ && mTouchPositionCorrectionRadii.length > 0;
+ final float[] sweetSpotCenterXs =
+ hasTouchPositionCorrectionData ? new float[keyCount] : null;
+ final float[] sweetSpotCenterYs =
+ hasTouchPositionCorrectionData ? new float[keyCount] : null;
+ final float[] sweetSpotRadii =
+ hasTouchPositionCorrectionData ? new float[keyCount] : null;
+ if (hasTouchPositionCorrectionData) {
+ calculateSweetSpot(keys, sweetSpotCenterXs, sweetSpotCenterYs, sweetSpotRadii);
+ }
+
mNativeProximityInfo = setProximityInfoNative(MAX_PROXIMITY_CHARS_SIZE,
keyboardWidth, keyboardHeight, mGridWidth, mGridHeight, proximityCharsArray,
keyCount, keyXCoordinates, keyYCoordinates, keyWidths, keyHeights, keyCharCodes,
- themeId);
+ sweetSpotCenterXs, sweetSpotCenterYs, sweetSpotRadii);
+ }
+
+ private void calculateSweetSpot(List<Key> keys, float[] sweetSpotCenterXs,
+ float[] sweetSpotCenterYs, float[] sweetSpotRadii) {
+ final int keyCount = keys.size();
+ for (int i = 0; i < keyCount; ++i) {
+ final Key key = keys.get(i);
+ final Rect hitBox = key.mHitBox;
+ final int row = hitBox.top / mKeyHeight;
+ if (row < mTouchPositionCorrectionRadii.length) {
+ final float hitBoxCenterX = (hitBox.left + hitBox.right) * 0.5f;
+ final float hitBoxCenterY = (hitBox.top + hitBox.bottom) * 0.5f;
+ final float hitBoxWidth = hitBox.right - hitBox.left;
+ final float hitBoxHeight = hitBox.bottom - hitBox.top;
+ final float x = mTouchPositionCorrectionXs[row];
+ final float y = mTouchPositionCorrectionYs[row];
+ final float radius = mTouchPositionCorrectionRadii[row];
+ sweetSpotCenterXs[i] = hitBoxCenterX + x * hitBoxWidth;
+ sweetSpotCenterYs[i] = hitBoxCenterY + y * hitBoxHeight;
+ sweetSpotRadii[i] = radius
+ * (float)Math.sqrt(hitBoxWidth * hitBoxWidth + hitBoxHeight * hitBoxHeight);
+ }
+ }
}
public int getNativeProximityInfo() {
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
index 187a1adcb..46836da67 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
@@ -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 {
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
index 97f58fad2..d1aea72a5 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
@@ -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();
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 48a1f8bd7..cf1cb8f25 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1661,9 +1661,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
builder.setTypedWordValid(typedWordValid).setHasMinimalSuggestion(
autoCorrectionAvailable);
} else {
- final SuggestedWords previousSuggestions = mSuggestionsView.getSuggestions();
- if (previousSuggestions == mSettingsValues.mSuggestPuncList)
- return;
+ SuggestedWords previousSuggestions = mSuggestionsView.getSuggestions();
+ if (previousSuggestions == mSettingsValues.mSuggestPuncList) {
+ if (builder.size() == 0) {
+ return;
+ }
+ previousSuggestions = SuggestedWords.EMPTY;
+ }
builder.addTypedWordAndPreviousSuggestions(typedWord, previousSuggestions);
}
}
diff --git a/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java
index 5a2eb1632..51f6c040d 100644
--- a/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/MoreSuggestionsView.java
@@ -163,8 +163,6 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel {
- (container.getMeasuredHeight() - container.getPaddingBottom())
+ parentView.getPaddingTop() + mCoordinates[1];
- window.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
- window.setOutsideTouchable(true);
window.setContentView(container);
window.setWidth(container.getMeasuredWidth());
window.setHeight(container.getMeasuredHeight());
@@ -221,22 +219,6 @@ public class MoreSuggestionsView extends KeyboardView implements MoreKeysPanel {
};
@Override
- public boolean dispatchTouchEvent(MotionEvent me) {
- final int index = me.getActionIndex();
- final int id = me.getPointerId(index);
- final PointerTracker tracker = PointerTracker.getPointerTracker(id, this);
- final int x = (int)me.getX(index);
- final int y = (int)me.getY(index);
- final boolean inside = (x >= 0 && x < getWidth() && y >= 0 && y < getHeight());
- if (inside || tracker.isInSlidingKeyInput()) {
- return super.dispatchTouchEvent(me);
- } else {
- dismissMoreKeysPanel();
- return true;
- }
- }
-
- @Override
public boolean onTouchEvent(MotionEvent me) {
final int action = me.getAction();
final long eventTime = me.getEventTime();
diff --git a/java/src/com/android/inputmethod/latin/SuggestionsView.java b/java/src/com/android/inputmethod/latin/SuggestionsView.java
index 9d0e42a18..fe54f4ae1 100644
--- a/java/src/com/android/inputmethod/latin/SuggestionsView.java
+++ b/java/src/com/android/inputmethod/latin/SuggestionsView.java
@@ -27,6 +27,7 @@ import android.graphics.Paint.Align;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Message;
import android.os.SystemClock;
@@ -506,10 +507,22 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
mMoreSuggestionsView = (MoreSuggestionsView)mMoreSuggestionsContainer
.findViewById(R.id.more_suggestions_view);
mMoreSuggestionsBuilder = new MoreSuggestions.Builder(mMoreSuggestionsView);
- mMoreSuggestionsWindow = new PopupWindow(context);
- mMoreSuggestionsWindow.setWindowLayoutMode(
+
+ final PopupWindow moreWindow = new PopupWindow(context);
+ moreWindow.setWindowLayoutMode(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- mMoreSuggestionsWindow.setBackgroundDrawable(null);
+ moreWindow.setBackgroundDrawable(new ColorDrawable(android.R.color.transparent));
+ moreWindow.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
+ moreWindow.setFocusable(true);
+ moreWindow.setOutsideTouchable(true);
+ moreWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
+ @Override
+ public void onDismiss() {
+ mKeyboardView.dimEntireKeyboard(false);
+ }
+ });
+ mMoreSuggestionsWindow = moreWindow;
+
final Resources res = context.getResources();
mMoreSuggestionsModalTolerance = res.getDimensionPixelOffset(
R.dimen.more_suggestions_modal_tolerance);
@@ -517,21 +530,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
context, mMoreSuggestionsSlidingListener);
}
- private final View.OnTouchListener mMoreSuggestionsCanceller = new View.OnTouchListener() {
- @Override
- public boolean onTouch(View view, MotionEvent me) {
- if (!mMoreSuggestionsWindow.isShowing()) return false;
-
- switch (me.getAction()) {
- case MotionEvent.ACTION_UP:
- case MotionEvent.ACTION_POINTER_UP:
- return mMoreSuggestionsView.dismissMoreKeysPanel();
- default:
- return true;
- }
- }
- };
-
/**
* A connection back to the input method.
* @param listener
@@ -726,8 +724,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
private boolean dismissMoreSuggestions() {
if (mMoreSuggestionsWindow.isShowing()) {
mMoreSuggestionsWindow.dismiss();
- mKeyboardView.dimEntireKeyboard(false);
- mKeyboardView.setOnTouchListener(null);
return true;
}
return false;
@@ -767,7 +763,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
mOriginX = mLastX;
mOriginY = mLastY;
mKeyboardView.dimEntireKeyboard(true);
- mKeyboardView.setOnTouchListener(mMoreSuggestionsCanceller);
for (int i = 0; i < params.mSuggestionsCountInStrip; i++) {
mWords.get(i).setPressed(false);
}
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
index 2546df0a2..1d5986ef9 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
@@ -70,11 +70,17 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
private Map<String, Dictionary> mUserDictionaries =
Collections.synchronizedMap(new TreeMap<String, Dictionary>());
- private double mTypoThreshold;
+ // The threshold for a candidate to be offered as a suggestion.
+ private double mSuggestionThreshold;
+ // The threshold for a suggestion to be considered "likely".
+ private double mLikelyThreshold;
@Override public void onCreate() {
super.onCreate();
- mTypoThreshold = Double.parseDouble(getString(R.string.spellchecker_typo_threshold_value));
+ mSuggestionThreshold =
+ Double.parseDouble(getString(R.string.spellchecker_suggestion_threshold_value));
+ mLikelyThreshold =
+ Double.parseDouble(getString(R.string.spellchecker_likely_threshold_value));
}
@Override
@@ -95,6 +101,9 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
private final int DEFAULT_SUGGESTION_LENGTH = 16;
private final ArrayList<CharSequence> mSuggestions;
private final int[] mScores;
+ private final String mOriginalText;
+ private final double mSuggestionThreshold;
+ private final double mLikelyThreshold;
private final int mMaxLength;
private int mLength = 0;
@@ -103,7 +112,11 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
private String mBestSuggestion = null;
private int mBestScore = Integer.MIN_VALUE; // As small as possible
- SuggestionsGatherer(final int maxLength) {
+ SuggestionsGatherer(final String originalText, final double suggestionThreshold,
+ final double likelyThreshold, final int maxLength) {
+ mOriginalText = originalText;
+ mSuggestionThreshold = suggestionThreshold;
+ mLikelyThreshold = likelyThreshold;
mMaxLength = maxLength;
mSuggestions = new ArrayList<CharSequence>(maxLength + 1);
mScores = new int[mMaxLength];
@@ -117,28 +130,42 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
// if it doesn't. See documentation for binarySearch.
final int insertIndex = positionIndex >= 0 ? positionIndex : -positionIndex - 1;
+ if (insertIndex == 0 && mLength >= mMaxLength) {
+ // In the future, we may want to keep track of the best suggestion score even if
+ // we are asked for 0 suggestions. In this case, we can use the following
+ // (tested) code to keep it:
+ // If the maxLength is 0 (should never be less, but if it is, it's treated as 0)
+ // then we need to keep track of the best suggestion in mBestScore and
+ // mBestSuggestion. This is so that we know whether the best suggestion makes
+ // the score cutoff, since we need to know that to return a meaningful
+ // looksLikeTypo.
+ // if (0 >= mMaxLength) {
+ // if (score > mBestScore) {
+ // mBestScore = score;
+ // mBestSuggestion = new String(word, wordOffset, wordLength);
+ // }
+ // }
+ return true;
+ }
+
+ // Compute the normalized score and skip this word if it's normalized score does not
+ // make the threshold.
+ final String wordString = new String(word, wordOffset, wordLength);
+ final double normalizedScore =
+ Utils.calcNormalizedScore(mOriginalText, wordString, score);
+ if (normalizedScore < mSuggestionThreshold) {
+ if (DBG) Log.i(TAG, wordString + " does not make the score threshold");
+ return true;
+ }
+
if (mLength < mMaxLength) {
final int copyLen = mLength - insertIndex;
++mLength;
System.arraycopy(mScores, insertIndex, mScores, insertIndex + 1, copyLen);
- mSuggestions.add(insertIndex, new String(word, wordOffset, wordLength));
+ mSuggestions.add(insertIndex, wordString);
} else {
- if (insertIndex == 0) {
- // If the maxLength is 0 (should never be less, but if it is, it's treated as 0)
- // then we need to keep track of the best suggestion in mBestScore and
- // mBestSuggestion. This is so that we know whether the best suggestion makes
- // the score cutoff, since we need to know that to return a meaningful
- // looksLikeTypo.
- if (0 >= mMaxLength) {
- if (score > mBestScore) {
- mBestScore = score;
- mBestSuggestion = new String(word, wordOffset, wordLength);
- }
- }
- return true;
- }
System.arraycopy(mScores, 1, mScores, 0, insertIndex);
- mSuggestions.add(insertIndex, new String(word, wordOffset, wordLength));
+ mSuggestions.add(insertIndex, wordString);
mSuggestions.remove(0);
}
mScores[insertIndex] = score;
@@ -146,8 +173,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
return true;
}
- public Result getResults(final CharSequence originalText, final double threshold,
- final int capitalizeType, final Locale locale) {
+ public Result getResults(final int capitalizeType, final Locale locale) {
final String[] gatheredSuggestions;
final boolean hasLikelySuggestions;
if (0 == mLength) {
@@ -160,8 +186,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
} else {
gatheredSuggestions = EMPTY_STRING_ARRAY;
final double normalizedScore =
- Utils.calcNormalizedScore(originalText, mBestSuggestion, mBestScore);
- hasLikelySuggestions = (normalizedScore > threshold);
+ Utils.calcNormalizedScore(mOriginalText, mBestSuggestion, mBestScore);
+ hasLikelySuggestions = (normalizedScore > mLikelyThreshold);
}
} else {
if (DBG) {
@@ -194,11 +220,12 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
final int bestScore = mScores[mLength - 1];
final CharSequence bestSuggestion = mSuggestions.get(0);
final double normalizedScore =
- Utils.calcNormalizedScore(originalText, bestSuggestion, bestScore);
- hasLikelySuggestions = (normalizedScore > threshold);
+ Utils.calcNormalizedScore(mOriginalText, bestSuggestion, bestScore);
+ hasLikelySuggestions = (normalizedScore > mLikelyThreshold);
if (DBG) {
Log.i(TAG, "Best suggestion : " + bestSuggestion + ", score " + bestScore);
- Log.i(TAG, "Normalized score = " + normalizedScore + " (threshold " + threshold
+ Log.i(TAG, "Normalized score = " + normalizedScore
+ + " (threshold " + mLikelyThreshold
+ ") => hasLikelySuggestions = " + hasLikelySuggestions);
}
}
@@ -350,8 +377,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
}
// TODO: Don't gather suggestions if the limit is <= 0 unless necessary
- final SuggestionsGatherer suggestionsGatherer =
- new SuggestionsGatherer(suggestionsLimit);
+ final SuggestionsGatherer suggestionsGatherer = new SuggestionsGatherer(text,
+ mService.mSuggestionThreshold, mService.mLikelyThreshold, suggestionsLimit);
final WordComposer composer = new WordComposer();
final int length = text.length();
for (int i = 0; i < length; ++i) {
@@ -392,8 +419,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
}
}
- final SuggestionsGatherer.Result result = suggestionsGatherer.getResults(text,
- mService.mTypoThreshold, capitalizeType, mLocale);
+ final SuggestionsGatherer.Result result = suggestionsGatherer.getResults(
+ capitalizeType, mLocale);
if (DBG) {
Log.i(TAG, "Spell checking results for " + text + " with suggestion limit "