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/DictionaryFacilitatorForSuggest.java7
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java67
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java2
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java75
-rw-r--r--java/src/com/android/inputmethod/latin/utils/FileUtils.java10
5 files changed, 82 insertions, 79 deletions
diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java
index e8b9a796a..c7f055393 100644
--- a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java
+++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java
@@ -309,10 +309,10 @@ public class DictionaryFacilitatorForSuggest {
mUserDictionary.addWordToUserDictionary(word);
}
- public String addToUserHistory(final WordComposer wordComposer, final String previousWord,
+ public void addToUserHistory(final WordComposer wordComposer, final String previousWord,
final String suggestion) {
if (mUserHistoryDictionary == null) {
- return null;
+ return;
}
final String secondWord;
if (wordComposer.wasAutoCapitalized() && !wordComposer.isMostlyCaps()) {
@@ -324,12 +324,11 @@ public class DictionaryFacilitatorForSuggest {
// We don't add words with 0-frequency (assuming they would be profanity etc.).
final int maxFreq = getMaxFrequency(suggestion);
if (maxFreq == 0) {
- return null;
+ return;
}
final boolean isValid = maxFreq > 0;
final int timeStamp = (int)TimeUnit.MILLISECONDS.toSeconds((System.currentTimeMillis()));
mUserHistoryDictionary.addToDictionary(previousWord, secondWord, isValid, timeStamp);
- return previousWord;
}
public void cancelAddingUserHistory(final String previousWord, final String committedWord) {
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 7a4164cf1..33f09e45b 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -183,7 +183,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
switch (msg.what) {
case MSG_UPDATE_SUGGESTION_STRIP:
latinIme.mInputLogic.performUpdateSuggestionStripSync(
- latinIme.mSettings.getCurrent(), this);
+ latinIme.mSettings.getCurrent(), this /* handler */,
+ latinIme.mInputUpdater);
break;
case MSG_UPDATE_SHIFT_STATE:
switcher.updateShiftState();
@@ -1060,9 +1061,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
false /* isObsoleteSuggestions */,
false /* isPrediction */);
// When in fullscreen mode, show completions generated by the application
- final boolean isAutoCorrection = false;
- setSuggestedWords(suggestedWords, isAutoCorrection);
- setAutoCorrectionIndicator(isAutoCorrection);
+ setSuggestedWords(suggestedWords);
+ setAutoCorrectionIndicator(false);
setSuggestionStripShown(true);
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.latinIME_onDisplayCompletions(applicationSpecifiedCompletions);
@@ -1252,13 +1252,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Implementation of {@link KeyboardActionListener}.
@Override
public void onCodeInput(final int primaryCode, final int x, final int y) {
- mInputLogic.onCodeInput(primaryCode, x, y, mHandler, mKeyboardSwitcher, mSubtypeSwitcher);
+ mInputLogic.onCodeInput(primaryCode, x, y, mHandler, mInputUpdater,
+ mKeyboardSwitcher, mSubtypeSwitcher);
}
// Called from PointerTracker through the KeyboardActionListener interface
@Override
public void onTextInput(final String rawText) {
- mInputLogic.onTextInput(mSettings.getCurrent(), rawText, mHandler);
+ mInputLogic.onTextInput(mSettings.getCurrent(), rawText, mHandler, mInputUpdater);
mKeyboardSwitcher.updateShiftState();
mKeyboardSwitcher.onCodeInput(Constants.CODE_OUTPUT_TEXT);
}
@@ -1384,20 +1385,20 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void getSuggestedWordsGestureLocked(final InputPointers batchPointers,
final int sequenceNumber, final OnGetSuggestedWordsCallback callback) {
mLatinIme.mInputLogic.mWordComposer.setBatchInputPointers(batchPointers);
- mLatinIme.getSuggestedWordsOrOlderSuggestionsAsync(Suggest.SESSION_GESTURE,
- sequenceNumber, new OnGetSuggestedWordsCallback() {
- @Override
- public void onGetSuggestedWords(SuggestedWords suggestedWords) {
- if (suggestedWords.isEmpty()) {
- // Previous suggestions are found in InputLogic#mSuggestedWords. Since
- // these are the most recent suggestions and we just recomputed new
- // ones to update them, it means the previous ones are there.
- callback.onGetSuggestedWords(mLatinIme.mInputLogic.mSuggestedWords);
- } else {
- callback.onGetSuggestedWords(suggestedWords);
- }
- }
- });
+ getSuggestedWords(Suggest.SESSION_GESTURE, sequenceNumber,
+ new OnGetSuggestedWordsCallback() {
+ @Override
+ public void onGetSuggestedWords(SuggestedWords suggestedWords) {
+ if (suggestedWords.isEmpty()) {
+ // Previous suggestions are found in InputLogic#mSuggestedWords.
+ // Since these are the most recent ones and we just recomputed new
+ // ones to update them, it means the previous ones are there.
+ callback.onGetSuggestedWords(mLatinIme.mInputLogic.mSuggestedWords);
+ } else {
+ callback.onGetSuggestedWords(suggestedWords);
+ }
+ }
+ });
}
public void getSuggestedWords(final int sessionId, final int sequenceNumber,
@@ -1504,16 +1505,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// TODO[IL]: Define a clear interface for this
public void clearSuggestionStrip() {
- setSuggestedWords(SuggestedWords.EMPTY, false);
+ setSuggestedWords(SuggestedWords.EMPTY);
setAutoCorrectionIndicator(false);
}
// TODO[IL]: Define a clear interface for this
- public void setSuggestedWords(final SuggestedWords words, final boolean isAutoCorrection) {
+ public void setSuggestedWords(final SuggestedWords words) {
mInputLogic.mSuggestedWords = words;
if (mSuggestionStripView != null) {
mSuggestionStripView.setSuggestions(words);
- mKeyboardSwitcher.onAutoCorrectionStateChanged(isAutoCorrection);
+ mKeyboardSwitcher.onAutoCorrectionStateChanged(words.mWillAutoCorrect);
}
}
@@ -1571,20 +1572,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
additionalFeaturesOptions, sessionId, sequenceNumber, callback);
}
- // TODO[IL]: Move this to InputLogic?
- public void getSuggestedWordsOrOlderSuggestionsAsync(final int sessionId,
- final int sequenceNumber, final OnGetSuggestedWordsCallback callback) {
- mInputUpdater.getSuggestedWords(sessionId, sequenceNumber,
- new OnGetSuggestedWordsCallback() {
- @Override
- public void onGetSuggestedWords(SuggestedWords suggestedWords) {
- callback.onGetSuggestedWords(maybeRetrieveOlderSuggestions(
- mInputLogic.mWordComposer.getTypedWord(), suggestedWords));
- }
- });
- }
-
- private SuggestedWords maybeRetrieveOlderSuggestions(final String typedWord,
+ // TODO[IL]: Move this to InputLogic
+ public SuggestedWords maybeRetrieveOlderSuggestions(final String typedWord,
final SuggestedWords suggestedWords) {
// TODO: consolidate this into getSuggestedWords
// We update the suggestion strip only when we have some suggestions to show, i.e. when
@@ -1638,7 +1627,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
autoCorrection = typedWord;
}
mInputLogic.mWordComposer.setAutoCorrection(autoCorrection);
- setSuggestedWords(suggestedWords, suggestedWords.mWillAutoCorrect);
+ setSuggestedWords(suggestedWords);
setAutoCorrectionIndicator(suggestedWords.mWillAutoCorrect);
setSuggestionStripShown(isSuggestionsStripVisible());
// An auto-correction is available, cache it in accessibility code so
@@ -1757,7 +1746,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (currentSettings.mBigramPredictionEnabled) {
clearSuggestionStrip();
} else {
- setSuggestedWords(currentSettings.mSuggestPuncList, false);
+ setSuggestedWords(currentSettings.mSuggestPuncList);
}
setAutoCorrectionIndicator(false);
setSuggestionStripShown(isSuggestionsStripVisible());
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index 7da97e57a..f078c7346 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -472,7 +472,7 @@ public final class WordComposer {
mCapsCount = 0;
mDigitsCount = 0;
mIsBatchMode = false;
- mPreviousWordForSuggestion = mTypedWord.toString();
+ mPreviousWordForSuggestion = committedWord;
mTypedWord.setLength(0);
mCodePointSize = 0;
mTrailingSingleQuotesCount = 0;
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index b417a3e37..59b722134 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -140,11 +140,11 @@ public final class InputLogic {
* @param rawText the text to input.
*/
public void onTextInput(final SettingsValues settingsValues, final String rawText,
- // TODO: remove this argument
- final LatinIME.UIHandler handler) {
+ // TODO: remove these arguments
+ final LatinIME.UIHandler handler, final LatinIME.InputUpdater inputUpdater) {
mConnection.beginBatchEdit();
if (mWordComposer.isComposingWord()) {
- commitCurrentAutoCorrection(settingsValues, rawText, handler);
+ commitCurrentAutoCorrection(settingsValues, rawText, handler, inputUpdater);
} else {
resetComposingState(true /* alsoResetLastComposedWord */);
}
@@ -180,9 +180,9 @@ public final class InputLogic {
* @param y the y-coordinate where the user pressed the key, or NOT_A_COORDINATE.
*/
public void onCodeInput(final int code, final int x, final int y,
- // TODO: remove these three arguments
- final LatinIME.UIHandler handler, final KeyboardSwitcher keyboardSwitcher,
- final SubtypeSwitcher subtypeSwitcher) {
+ // TODO: remove these four arguments
+ final LatinIME.UIHandler handler, final LatinIME.InputUpdater inputUpdater,
+ final KeyboardSwitcher keyboardSwitcher, final SubtypeSwitcher subtypeSwitcher) {
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.latinIME_onCodeInput(code, x, y);
}
@@ -273,17 +273,17 @@ public final class InputLogic {
} else {
// No action label, and the action from imeOptions is NONE: this is a regular
// enter key that should input a carriage return.
- didAutoCorrect = handleNonSpecialCharacter(settingsValues,
- Constants.CODE_ENTER, x, y, spaceState, keyboardSwitcher, handler);
+ didAutoCorrect = handleNonSpecialCharacter(settingsValues, Constants.CODE_ENTER,
+ x, y, spaceState, keyboardSwitcher, handler, inputUpdater);
}
break;
case Constants.CODE_SHIFT_ENTER:
- didAutoCorrect = handleNonSpecialCharacter(settingsValues,
- Constants.CODE_ENTER, x, y, spaceState, keyboardSwitcher, handler);
+ didAutoCorrect = handleNonSpecialCharacter(settingsValues, Constants.CODE_ENTER,
+ x, y, spaceState, keyboardSwitcher, handler, inputUpdater);
break;
default:
didAutoCorrect = handleNonSpecialCharacter(settingsValues,
- code, x, y, spaceState, keyboardSwitcher, handler);
+ code, x, y, spaceState, keyboardSwitcher, handler, inputUpdater);
break;
}
keyboardSwitcher.onCodeInput(code);
@@ -329,7 +329,7 @@ public final class InputLogic {
// so we do not attempt to correct, on the assumption that if that was a dictionary
// word, the user would probably have gestured instead.
commitCurrentAutoCorrection(settingsValues, LastComposedWord.NOT_A_SEPARATOR,
- handler);
+ handler, inputUpdater);
} else {
commitTyped(settingsValues, LastComposedWord.NOT_A_SEPARATOR);
}
@@ -431,13 +431,14 @@ public final class InputLogic {
private boolean handleNonSpecialCharacter(final SettingsValues settingsValues,
final int codePoint, final int x, final int y, final int spaceState,
// TODO: remove these arguments
- final KeyboardSwitcher keyboardSwitcher, final LatinIME.UIHandler handler) {
+ final KeyboardSwitcher keyboardSwitcher, final LatinIME.UIHandler handler,
+ final LatinIME.InputUpdater inputUpdater) {
mSpaceState = SpaceState.NONE;
final boolean didAutoCorrect;
if (settingsValues.isWordSeparator(codePoint)
|| Character.getType(codePoint) == Character.OTHER_SYMBOL) {
didAutoCorrect = handleSeparator(settingsValues, codePoint, x, y, spaceState,
- keyboardSwitcher, handler);
+ keyboardSwitcher, handler, inputUpdater);
} else {
didAutoCorrect = false;
if (SpaceState.PHANTOM == spaceState) {
@@ -577,7 +578,8 @@ public final class InputLogic {
private boolean handleSeparator(final SettingsValues settingsValues,
final int codePoint, final int x, final int y, final int spaceState,
// TODO: remove these arguments
- final KeyboardSwitcher keyboardSwitcher, final LatinIME.UIHandler handler) {
+ final KeyboardSwitcher keyboardSwitcher, final LatinIME.UIHandler handler,
+ final LatinIME.InputUpdater inputUpdater) {
boolean didAutoCorrect = false;
// We avoid sending spaces in languages without spaces if we were composing.
final boolean shouldAvoidSendingCode = Constants.CODE_SPACE == codePoint
@@ -593,7 +595,7 @@ public final class InputLogic {
if (settingsValues.mCorrectionEnabled) {
final String separator = shouldAvoidSendingCode ? LastComposedWord.NOT_A_SEPARATOR
: StringUtils.newSingleCodePointString(codePoint);
- commitCurrentAutoCorrection(settingsValues, separator, handler);
+ commitCurrentAutoCorrection(settingsValues, separator, handler, inputUpdater);
didAutoCorrect = true;
} else {
commitTyped(settingsValues, StringUtils.newSingleCodePointString(codePoint));
@@ -974,24 +976,23 @@ public final class InputLogic {
mConnection.setSelection(mLastSelectionStart, mLastSelectionEnd);
}
- private String performAdditionToUserHistoryDictionary(final SettingsValues settingsValues,
- final String suggestion) {
+ private void performAdditionToUserHistoryDictionary(final SettingsValues settingsValues,
+ final String suggestion, final String prevWord) {
// If correction is not enabled, we don't add words to the user history dictionary.
// That's to avoid unintended additions in some sensitive fields, or fields that
// expect to receive non-words.
- if (!settingsValues.mCorrectionEnabled) return null;
+ if (!settingsValues.mCorrectionEnabled) return;
- if (TextUtils.isEmpty(suggestion)) return null;
+ if (TextUtils.isEmpty(suggestion)) return;
final Suggest suggest = mSuggest;
- if (suggest == null) return null;
+ if (suggest == null) return;
- final String prevWord = mConnection.getNthPreviousWord(settingsValues, 2);
- return suggest.mDictionaryFacilitator.addToUserHistory(mWordComposer, prevWord, suggestion);
+ suggest.mDictionaryFacilitator.addToUserHistory(mWordComposer, prevWord, suggestion);
}
public void performUpdateSuggestionStripSync(final SettingsValues settingsValues,
// TODO: Remove this variable
- final LatinIME.UIHandler handler) {
+ final LatinIME.UIHandler handler, final LatinIME.InputUpdater inputUpdater) {
handler.cancelUpdateSuggestionStrip();
// Check if we have a suggestion engine attached.
@@ -1009,11 +1010,14 @@ public final class InputLogic {
}
final AsyncResultHolder<SuggestedWords> holder = new AsyncResultHolder<SuggestedWords>();
- mLatinIME.getSuggestedWordsOrOlderSuggestionsAsync(Suggest.SESSION_TYPING,
+ inputUpdater.getSuggestedWords(Suggest.SESSION_TYPING,
SuggestedWords.NOT_A_SEQUENCE_NUMBER, new OnGetSuggestedWordsCallback() {
@Override
public void onGetSuggestedWords(final SuggestedWords suggestedWords) {
- holder.set(suggestedWords);
+ final SuggestedWords suggestedWordsWithMaybeOlderSuggestions =
+ mLatinIME.maybeRetrieveOlderSuggestions(
+ mWordComposer.getTypedWord(), suggestedWords);
+ holder.set(suggestedWordsWithMaybeOlderSuggestions);
}
}
);
@@ -1386,7 +1390,7 @@ public final class InputLogic {
if (settingsValues.mBigramPredictionEnabled) {
mLatinIME.clearSuggestionStrip();
} else {
- mLatinIME.setSuggestedWords(settingsValues.mSuggestPuncList, false);
+ mLatinIME.setSuggestedWords(settingsValues.mSuggestPuncList);
}
mConnection.resetCachesUponCursorMoveAndReturnSuccess(newSelStart, newSelEnd,
shouldFinishComposition);
@@ -1551,11 +1555,11 @@ public final class InputLogic {
// TODO: Make this private
public void commitCurrentAutoCorrection(final SettingsValues settingsValues,
final String separator,
- // TODO: Remove this argument.
- final LatinIME.UIHandler handler) {
+ // TODO: Remove these arguments.
+ final LatinIME.UIHandler handler, final LatinIME.InputUpdater inputUpdater) {
// Complete any pending suggestions query first
if (handler.hasPendingUpdateSuggestions()) {
- performUpdateSuggestionStripSync(settingsValues, handler);
+ performUpdateSuggestionStripSync(settingsValues, handler, inputUpdater);
}
final String typedAutoCorrection = mWordComposer.getAutoCorrectionOrNull();
final String typedWord = mWordComposer.getTypedWord();
@@ -1605,8 +1609,10 @@ public final class InputLogic {
final SuggestedWords suggestedWords = mSuggestedWords;
mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(mLatinIME, chosenWord,
suggestedWords), 1);
+ // TODO: we pass 2 here, but would it be better to move this above and pass 1 instead?
+ final String prevWord = mConnection.getNthPreviousWord(settingsValues, 2);
// Add the word to the user history dictionary
- final String prevWord = performAdditionToUserHistoryDictionary(settingsValues, chosenWord);
+ performAdditionToUserHistoryDictionary(settingsValues, chosenWord, prevWord);
// TODO: figure out here if this is an auto-correct or if the best word is actually
// what user typed. Note: currently this is done much later in
// LastComposedWord#didCommitTypedWord by string equality of the remembered
@@ -1615,8 +1621,11 @@ public final class InputLogic {
chosenWord, separatorString, prevWord);
final boolean shouldDiscardPreviousWordForSuggestion;
if (0 == StringUtils.codePointCount(separatorString)) {
- // Separator is 0-length. Discard the word only if the current language has spaces.
- shouldDiscardPreviousWordForSuggestion = settingsValues.mCurrentLanguageHasSpaces;
+ // Separator is 0-length, we can keep the previous word for suggestion. Either this
+ // was a manual pick or the language has no spaces in which case we want to keep the
+ // previous word, or it was the keyboard closing or the cursor moving in which case it
+ // will be reset anyway.
+ shouldDiscardPreviousWordForSuggestion = false;
} else {
// Otherwise, we discard if the separator contains any non-whitespace.
shouldDiscardPreviousWordForSuggestion =
diff --git a/java/src/com/android/inputmethod/latin/utils/FileUtils.java b/java/src/com/android/inputmethod/latin/utils/FileUtils.java
index 22b0fbbcd..f1106a6c6 100644
--- a/java/src/com/android/inputmethod/latin/utils/FileUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/FileUtils.java
@@ -25,8 +25,11 @@ import java.io.FilenameFilter;
public class FileUtils {
public static boolean deleteRecursively(final File path) {
if (path.isDirectory()) {
- for (final File child : path.listFiles()) {
- deleteRecursively(child);
+ final File[] files = path.listFiles();
+ if (files != null) {
+ for (final File child : files) {
+ deleteRecursively(child);
+ }
}
}
return path.delete();
@@ -37,6 +40,9 @@ public class FileUtils {
return false;
}
final File[] files = dir.listFiles(fileNameFilter);
+ if (files == null) {
+ return false;
+ }
boolean hasDeletedAllFiles = true;
for (final File file : files) {
if (!deleteRecursively(file)) {