aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
-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
3 files changed, 43 insertions, 25 deletions
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