aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java63
-rw-r--r--java/src/com/android/inputmethod/keyboard/Keyboard.java20
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java6
-rw-r--r--java/src/com/android/inputmethod/keyboard/MiniKeyboard.java12
-rw-r--r--java/src/com/android/inputmethod/keyboard/ProximityInfo.java9
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java10
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java1
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java21
-rw-r--r--java/src/com/android/inputmethod/latin/MoreSuggestions.java17
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java30
10 files changed, 111 insertions, 78 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index b1cc7cafb..1e2ea559b 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -19,6 +19,7 @@ package com.android.inputmethod.keyboard;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
+import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
@@ -86,6 +87,9 @@ public class Key {
public final int mX;
/** Y coordinate of the key in the keyboard layout */
public final int mY;
+ /** Hit bounding box of the key */
+ public final Rect mHitBox = new Rect();
+
/** Text to output when pressed. This can be multiple characters, like ".com" */
public final CharSequence mOutputText;
/** More keys */
@@ -93,14 +97,6 @@ public class Key {
/** More keys maximum column number */
public final int mMaxMoreKeysColumn;
- /**
- * Flags that specify the anchoring to edges of the keyboard for detecting touch events
- * that are just out of the boundary of the key. This is a bit mask of
- * {@link Keyboard#EDGE_LEFT}, {@link Keyboard#EDGE_RIGHT},
- * {@link Keyboard#EDGE_TOP} and {@link Keyboard#EDGE_BOTTOM}.
- */
- private int mEdgeFlags;
-
/** Background type that represents different key background visual than normal one. */
public final int mBackgroundType;
public static final int BACKGROUND_TYPE_NORMAL = 0;
@@ -167,23 +163,22 @@ public class Key {
* This constructor is being used only for key in more keys keyboard.
*/
public Key(Resources res, KeyboardParams params, String moreKeySpec,
- int x, int y, int width, int height, int edgeFlags) {
+ int x, int y, int width, int height) {
this(params, MoreKeySpecParser.getLabel(moreKeySpec), null, getIcon(params, moreKeySpec),
getCode(res, params, moreKeySpec), MoreKeySpecParser.getOutputText(moreKeySpec),
- x, y, width, height, edgeFlags);
+ x, y, width, height);
}
/**
* This constructor is being used only for key in popup suggestions pane.
*/
public Key(KeyboardParams params, CharSequence label, CharSequence hintLabel, Drawable icon,
- int code, CharSequence outputText, int x, int y, int width, int height, int edgeFlags) {
+ int code, CharSequence outputText, int x, int y, int width, int height) {
mHeight = height - params.mVerticalGap;
mHorizontalGap = params.mHorizontalGap;
mVerticalGap = params.mVerticalGap;
mVisualInsetsLeft = mVisualInsetsRight = 0;
mWidth = width - mHorizontalGap;
- mEdgeFlags = edgeFlags;
mHintLabel = hintLabel;
mLabelOption = 0;
mBackgroundType = BACKGROUND_TYPE_NORMAL;
@@ -197,6 +192,7 @@ public class Key {
// Horizontal gap is divided equally to both sides of the key.
mX = x + mHorizontalGap / 2;
mY = y;
+ mHitBox.set(x, y, x + width + 1, y + height);
}
/**
@@ -212,8 +208,9 @@ public class Key {
public Key(Resources res, KeyboardParams params, KeyboardBuilder.Row row,
XmlResourceParser parser, KeyStyles keyStyles) {
final float horizontalGap = isSpacer() ? 0 : params.mHorizontalGap;
+ final int keyHeight = row.mRowHeight;
mVerticalGap = params.mVerticalGap;
- mHeight = row.mRowHeight - mVerticalGap;
+ mHeight = keyHeight - mVerticalGap;
final TypedArray keyAttr = res.obtainAttributes(Xml.asAttributeSet(parser),
R.styleable.Keyboard_Key);
@@ -230,12 +227,14 @@ public class Key {
final float keyXPos = row.getKeyX(keyAttr);
final float keyWidth = row.getKeyWidth(keyAttr, keyXPos);
+ final int keyYPos = row.getKeyY();
// Horizontal gap is divided equally to both sides of the key.
mX = (int) (keyXPos + horizontalGap / 2);
- mY = row.getKeyY();
+ mY = keyYPos;
mWidth = (int) (keyWidth - horizontalGap);
mHorizontalGap = (int) horizontalGap;
+ mHitBox.set((int)keyXPos, keyYPos, (int)(keyXPos + keyWidth) + 1, keyYPos + keyHeight);
// Update row to have current x coordinate.
row.setXPos(keyXPos + keyWidth);
@@ -256,7 +255,6 @@ public class Key {
R.styleable.Keyboard_Key_backgroundType, BACKGROUND_TYPE_NORMAL);
mRepeatable = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_isRepeatable, false);
mEnabled = style.getBoolean(keyAttr, R.styleable.Keyboard_Key_enabled, true);
- mEdgeFlags = 0;
final KeyboardIconsSet iconsSet = params.mIconsSet;
mVisualInsetsLeft = (int) KeyboardBuilder.getDimensionOrFraction(keyAttr,
@@ -294,8 +292,20 @@ public class Key {
keyAttr.recycle();
}
- public void addEdgeFlags(int flags) {
- mEdgeFlags |= flags;
+ public void markAsLeftEdge(KeyboardParams params) {
+ mHitBox.left = params.mHorizontalEdgesPadding;
+ }
+
+ public void markAsRightEdge(KeyboardParams params) {
+ mHitBox.right = params.mOccupiedWidth - params.mHorizontalEdgesPadding;
+ }
+
+ public void markAsTopEdge(KeyboardParams params) {
+ mHitBox.top = params.mTopPadding;
+ }
+
+ public void markAsBottomEdge(KeyboardParams params) {
+ mHitBox.bottom = params.mOccupiedHeight + params.mBottomPadding;
}
public boolean isSticky() {
@@ -427,23 +437,10 @@ public class Key {
* @param y the y-coordinate of the point
* @return whether or not the point falls on the key. If the key is attached to an edge, it will
* assume that all points between the key and the edge are considered to be on the key.
+ * @see {@link #markAsLeftEdge(KeyboardParams)} etc.
*/
public boolean isOnKey(int x, int y) {
- final int left = mX - mHorizontalGap / 2;
- final int right = left + mWidth + mHorizontalGap;
- final int top = mY;
- final int bottom = top + mHeight + mVerticalGap;
- final int flags = mEdgeFlags;
- if (flags == 0) {
- return x >= left && x <= right && y >= top && y <= bottom;
- }
- final boolean leftEdge = (flags & Keyboard.EDGE_LEFT) != 0;
- final boolean rightEdge = (flags & Keyboard.EDGE_RIGHT) != 0;
- final boolean topEdge = (flags & Keyboard.EDGE_TOP) != 0;
- final boolean bottomEdge = (flags & Keyboard.EDGE_BOTTOM) != 0;
- // In order to mitigate rounding errors, we use (left <= x <= right) here.
- return (x >= left || leftEdge) && (x <= right || rightEdge)
- && (y >= top || topEdge) && (y <= bottom || bottomEdge);
+ return mHitBox.contains(x, y);
}
/**
@@ -547,7 +544,7 @@ public class Key {
* This constructor is being used only for divider in more keys keyboard.
*/
public Spacer(KeyboardParams params, Drawable icon, int x, int y, int width, int height) {
- super(params, null, null, icon, Keyboard.CODE_DUMMY, null, x, y, width, height, 0);
+ super(params, null, null, icon, Keyboard.CODE_DUMMY, null, x, y, width, height);
}
@Override
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index 2f11164f9..045f0d7b2 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -47,11 +47,6 @@ import java.util.Set;
* </pre>
*/
public class Keyboard {
- public static final int EDGE_LEFT = 0x01;
- public static final int EDGE_RIGHT = 0x02;
- public static final int EDGE_TOP = 0x04;
- public static final int EDGE_BOTTOM = 0x08;
-
/** Some common keys code. These should be aligned with values/keycodes.xml */
public static final int CODE_ENTER = '\n';
public static final int CODE_TAB = '\t';
@@ -84,6 +79,7 @@ public class Keyboard {
public static final int CODE_UNSPECIFIED = -99;
public final KeyboardId mId;
+ public final int mThemeId;
/** Total height of the keyboard, including the padding and keys */
public final int mOccupiedHeight;
@@ -121,6 +117,7 @@ public class Keyboard {
public Keyboard(KeyboardParams params) {
mId = params.mId;
+ mThemeId = params.mThemeId;
mOccupiedHeight = params.mOccupiedHeight;
mOccupiedWidth = params.mOccupiedWidth;
mMostCommonKeyHeight = params.mMostCommonKeyHeight;
@@ -238,4 +235,17 @@ public class Keyboard {
public int[] getNearestKeys(int x, int y) {
return mProximityInfo.getNearestKeys(x, y);
}
+
+ public static String themeName(int themeId) {
+ // This should be aligned with theme-*.xml resource files' themeId attribute.
+ switch (themeId) {
+ case 0: return "Basic";
+ case 1: return "BasicHighContrast";
+ case 5: return "IceCreamSandwich";
+ case 6: return "Stone";
+ case 7: return "StoneBold";
+ case 8: return "GingerBread";
+ default: return null;
+ }
+ }
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index a4684358d..13e8ba13c 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -275,10 +275,12 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
if (DEBUG_CACHE) {
Log.d(TAG, "keyboard cache size=" + mKeyboardCache.size() + ": "
- + ((ref == null) ? "LOAD" : "GCed") + " id=" + id);
+ + ((ref == null) ? "LOAD" : "GCed") + " id=" + id
+ + " theme=" + Keyboard.themeName(keyboard.mThemeId));
}
} else if (DEBUG_CACHE) {
- Log.d(TAG, "keyboard cache size=" + mKeyboardCache.size() + ": HIT id=" + id);
+ Log.d(TAG, "keyboard cache size=" + mKeyboardCache.size() + ": HIT id=" + id
+ + " theme=" + Keyboard.themeName(keyboard.mThemeId));
}
keyboard.onAutoCorrectionStateChanged(mIsAutoCorrectionActive);
diff --git a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
index c90439474..d4b35a556 100644
--- a/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/MiniKeyboard.java
@@ -193,13 +193,11 @@ public class MiniKeyboard extends Keyboard {
return (mNumRows - 1 - row) * mDefaultRowHeight + mTopPadding;
}
- public int getRowFlags(int row) {
- int rowFlags = 0;
+ public void markAsEdgeKey(Key key, int row) {
if (row == 0)
- rowFlags |= Keyboard.EDGE_TOP;
+ key.markAsTopEdge(this);
if (isTopRow(row))
- rowFlags |= Keyboard.EDGE_BOTTOM;
- return rowFlags;
+ key.markAsBottomEdge(this);
}
private boolean isTopRow(int rowCount) {
@@ -254,8 +252,8 @@ public class MiniKeyboard extends Keyboard {
final String moreKeySpec = mMoreKeys[n].toString();
final int row = n / params.mNumColumns;
final Key key = new Key(mResources, params, moreKeySpec, params.getX(n, row),
- params.getY(row), params.mDefaultKeyWidth, params.mDefaultRowHeight,
- params.getRowFlags(row));
+ params.getY(row), params.mDefaultKeyWidth, params.mDefaultRowHeight);
+ params.markAsEdgeKey(key, row);
params.onAddKey(key);
}
return new MiniKeyboard(params);
diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
index 0e2d28024..71b46d646 100644
--- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
+++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
@@ -27,6 +27,7 @@ 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 mGridWidth;
@@ -66,7 +67,7 @@ public class ProximityInfo {
spellCheckerProximityInfo.setProximityInfoNative(
SpellCheckerProximityInfo.ROW_SIZE,
480, 300, 10, 3, SpellCheckerProximityInfo.PROXIMITY,
- 0, null, null, null, null, null);
+ 0, null, null, null, null, null, UNKNOWN_THEME);
return spellCheckerProximityInfo;
}
@@ -77,7 +78,7 @@ 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[] keyWidths, int[] keyHeights, int[] keyCharCodes, int themeId);
private native void releaseProximityInfoNative(int nativeProximityInfo);
private final void setProximityInfo(int[][] gridNeighborKeyIndexes, int keyboardWidth,
@@ -97,6 +98,7 @@ public class ProximityInfo {
int[] keyWidths = new int[keyCount];
int[] keyHeights = new int[keyCount];
int[] keyCharCodes = new int[keyCount];
+ final int themeId = 5; // TODO: Use real theme id.
for (int i = 0; i < keyCount; ++i) {
final Key key = keys.get(i);
keyXCoordinates[i] = key.mX;
@@ -107,7 +109,8 @@ public class ProximityInfo {
}
mNativeProximityInfo = setProximityInfoNative(MAX_PROXIMITY_CHARS_SIZE,
keyboardWidth, keyboardHeight, mGridWidth, mGridHeight, proximityCharsArray,
- keyCount, keyXCoordinates, keyYCoordinates, keyWidths, keyHeights, keyCharCodes);
+ keyCount, keyXCoordinates, keyYCoordinates, keyWidths, keyHeights, keyCharCodes,
+ themeId);
}
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 99b917c86..187a1adcb 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
@@ -244,6 +244,10 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
mParams = params;
+ final TypedArray a = context.obtainStyledAttributes(R.styleable.KeyboardTheme);
+ mParams.mThemeId = a.getInt(R.styleable.KeyboardTheme_themeId, 0);
+ a.recycle();
+
mParams.GRID_WIDTH = res.getInteger(R.integer.config_keyboard_grid_width);
mParams.GRID_HEIGHT = res.getInteger(R.integer.config_keyboard_grid_height);
}
@@ -749,7 +753,7 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
if (mCurrentRow == null)
throw new InflateException("orphant end row tag");
if (mRightEdgeKey != null) {
- mRightEdgeKey.addEdgeFlags(Keyboard.EDGE_RIGHT);
+ mRightEdgeKey.markAsRightEdge(mParams);
mRightEdgeKey = null;
}
addEdgeSpace(mParams.mHorizontalEdgesPadding, row);
@@ -761,11 +765,11 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
private void endKey(Key key) {
mParams.onAddKey(key);
if (mLeftEdge) {
- key.addEdgeFlags(Keyboard.EDGE_LEFT);
+ key.markAsLeftEdge(mParams);
mLeftEdge = false;
}
if (mTopEdge) {
- key.addEdgeFlags(Keyboard.EDGE_TOP);
+ key.markAsTopEdge(mParams);
}
mRightEdgeKey = key;
}
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
index 01f9d3bb1..97f58fad2 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
@@ -31,6 +31,7 @@ import java.util.Set;
public class KeyboardParams {
public KeyboardId mId;
+ public int mThemeId;
/** Total height and width of the keyboard, including the paddings and keys */
public int mOccupiedHeight;
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index ddda184aa..32649d5a1 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -241,7 +241,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private static final int MSG_SET_BIGRAM_PREDICTIONS = 7;
private static final int MSG_START_ORIENTATION_CHANGE = 8;
private static final int MSG_START_INPUT_VIEW = 9;
- private static final int MSG_RESTORE_KEYBOARD_LAYOUT = 10;
+ private static final int MSG_DISPLAY_COMPLETIONS = 10;
+ private static final int MSG_RESTORE_KEYBOARD_LAYOUT = 11;
public UIHandler(LatinIME outerInstance) {
super(outerInstance);
@@ -293,6 +294,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
case MSG_START_INPUT_VIEW:
latinIme.onStartInputView((EditorInfo)msg.obj, false);
break;
+ case MSG_DISPLAY_COMPLETIONS:
+ latinIme.onDisplayCompletions((CompletionInfo[])msg.obj);
+ break;
case MSG_RESTORE_KEYBOARD_LAYOUT:
removeMessages(MSG_UPDATE_SHIFT_STATE);
((KeyboardLayoutState)msg.obj).restore();
@@ -417,6 +421,18 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
}
return false;
}
+
+ public boolean postDisplayCompletions(CompletionInfo[] applicationSpecifiedCompletions) {
+ if (hasMessages(MSG_START_INPUT_VIEW) || hasMessages(MSG_DISPLAY_COMPLETIONS)) {
+ removeMessages(MSG_DISPLAY_COMPLETIONS);
+ // Postpone onDisplayCompletions by ACCUMULATE_START_INPUT_VIEW_DELAY.
+ sendMessageDelayed(
+ obtainMessage(MSG_DISPLAY_COMPLETIONS, applicationSpecifiedCompletions),
+ ACCUMULATE_START_INPUT_VIEW_DELAY);
+ return true;
+ }
+ return false;
+ }
}
@Override
@@ -923,6 +939,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
@Override
public void onDisplayCompletions(CompletionInfo[] applicationSpecifiedCompletions) {
+ if (mHandler.postDisplayCompletions(applicationSpecifiedCompletions)) {
+ return;
+ }
if (DEBUG) {
Log.i(TAG, "Received completions:");
if (applicationSpecifiedCompletions != null) {
diff --git a/java/src/com/android/inputmethod/latin/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/MoreSuggestions.java
index 1afa07214..9a59ef2e0 100644
--- a/java/src/com/android/inputmethod/latin/MoreSuggestions.java
+++ b/java/src/com/android/inputmethod/latin/MoreSuggestions.java
@@ -153,23 +153,19 @@ public class MoreSuggestions extends Keyboard {
return (mOccupiedWidth - mDividerWidth * (numColumnInRow - 1)) / numColumnInRow;
}
- public int getFlags(int pos) {
- int rowFlags = 0;
-
+ public void markAsEdgeKey(Key key, int pos) {
final int row = mRowNumbers[pos];
if (row == 0)
- rowFlags |= Keyboard.EDGE_BOTTOM;
+ key.markAsBottomEdge(this);
if (row == mNumRows - 1)
- rowFlags |= Keyboard.EDGE_TOP;
+ key.markAsTopEdge(this);
final int numColumnInRow = mNumColumnsInRow[row];
final int column = getColumnNumber(pos);
if (column == 0)
- rowFlags |= Keyboard.EDGE_LEFT;
+ key.markAsLeftEdge(this);
if (column == numColumnInRow - 1)
- rowFlags |= Keyboard.EDGE_RIGHT;
-
- return rowFlags;
+ key.markAsRightEdge(this);
}
}
@@ -214,7 +210,8 @@ public class MoreSuggestions extends Keyboard {
final int index = pos + SUGGESTION_CODE_BASE;
final Key key = new Key(
params, word, info, null, index, null, x, y, width,
- params.mDefaultRowHeight, params.getFlags(pos));
+ params.mDefaultRowHeight);
+ params.markAsEdgeKey(key, pos);
params.onAddKey(key);
final int columnNumber = params.getColumnNumber(pos);
final int numColumnInRow = params.getNumColumnInRow(pos);
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
index 77fbe3ec6..2546df0a2 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
@@ -85,10 +85,10 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
private static class SuggestionsGatherer implements WordCallback {
public static class Result {
public final String[] mSuggestions;
- public final boolean mLooksLikeTypo;
- public Result(final String[] gatheredSuggestions, final boolean looksLikeTypo) {
+ public final boolean mHasLikelySuggestions;
+ public Result(final String[] gatheredSuggestions, final boolean hasLikelySuggestions) {
mSuggestions = gatheredSuggestions;
- mLooksLikeTypo = looksLikeTypo;
+ mHasLikelySuggestions = hasLikelySuggestions;
}
}
@@ -149,19 +149,19 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
public Result getResults(final CharSequence originalText, final double threshold,
final int capitalizeType, final Locale locale) {
final String[] gatheredSuggestions;
- final boolean looksLikeTypo;
+ final boolean hasLikelySuggestions;
if (0 == mLength) {
// Either we found no suggestions, or we found some BUT the max length was 0.
// If we found some mBestSuggestion will not be null. If it is null, then
// we found none, regardless of the max length.
if (null == mBestSuggestion) {
gatheredSuggestions = null;
- looksLikeTypo = false;
+ hasLikelySuggestions = false;
} else {
gatheredSuggestions = EMPTY_STRING_ARRAY;
final double normalizedScore =
Utils.calcNormalizedScore(originalText, mBestSuggestion, mBestScore);
- looksLikeTypo = (normalizedScore > threshold);
+ hasLikelySuggestions = (normalizedScore > threshold);
}
} else {
if (DBG) {
@@ -195,14 +195,14 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
final CharSequence bestSuggestion = mSuggestions.get(0);
final double normalizedScore =
Utils.calcNormalizedScore(originalText, bestSuggestion, bestScore);
- looksLikeTypo = (normalizedScore > threshold);
+ hasLikelySuggestions = (normalizedScore > threshold);
if (DBG) {
Log.i(TAG, "Best suggestion : " + bestSuggestion + ", score " + bestScore);
Log.i(TAG, "Normalized score = " + normalizedScore + " (threshold " + threshold
- + ") => looksLikeTypo = " + looksLikeTypo);
+ + ") => hasLikelySuggestions = " + hasLikelySuggestions);
}
}
- return new Result(gatheredSuggestions, looksLikeTypo);
+ return new Result(gatheredSuggestions, hasLikelySuggestions);
}
}
@@ -349,6 +349,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
}
}
+ // TODO: Don't gather suggestions if the limit is <= 0 unless necessary
final SuggestionsGatherer suggestionsGatherer =
new SuggestionsGatherer(suggestionsLimit);
final WordComposer composer = new WordComposer();
@@ -397,17 +398,18 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
if (DBG) {
Log.i(TAG, "Spell checking results for " + text + " with suggestion limit "
+ suggestionsLimit);
- Log.i(TAG, "IsInDict = " + result.mLooksLikeTypo);
- Log.i(TAG, "LooksLikeTypo = " + result.mLooksLikeTypo);
+ Log.i(TAG, "IsInDict = " + isInDict);
+ Log.i(TAG, "LooksLikeTypo = " + (!isInDict));
+ Log.i(TAG, "HasLikelySuggestions = " + result.mHasLikelySuggestions);
for (String suggestion : result.mSuggestions) {
Log.i(TAG, suggestion);
}
}
+ // TODO: actually use result.mHasLikelySuggestions
final int flags =
- (isInDict ? SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY : 0)
- | (result.mLooksLikeTypo
- ? SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO : 0);
+ (isInDict ? SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY
+ : SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO);
return new SuggestionsInfo(flags, result.mSuggestions);
} catch (RuntimeException e) {
// Don't kill the keyboard if there is a bug in the spell checker