aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2014-01-09 17:27:33 +0900
committerTadashi G. Takaoka <takaoka@google.com>2014-01-09 18:33:25 +0900
commit494e2d6c17cdbf27615a2fbc02b12d2562bf7cd3 (patch)
tree4c671d08eee4fb755ead6a73ce3a680be9918d48 /java
parentd7660c6f56a65b835ad178c2860f36d273655b14 (diff)
downloadlatinime-494e2d6c17cdbf27615a2fbc02b12d2562bf7cd3.tar.gz
latinime-494e2d6c17cdbf27615a2fbc02b12d2562bf7cd3.tar.xz
latinime-494e2d6c17cdbf27615a2fbc02b12d2562bf7cd3.zip
Passing SpacingAndPunctuations to RichInputConnection.getNthPreviousWords
Change-Id: I174c50f509ed6998b755e1a712e7f6c0f82f4425
Diffstat (limited to 'java')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java3
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputConnection.java12
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java22
3 files changed, 22 insertions, 15 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index aadb65192..3984c197a 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1396,7 +1396,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// word. If we are composing a word we should have the second word before the cursor
// memorized, otherwise we should have the first.
final String rereadPrevWord = mInputLogic.getNthPreviousWordForSuggestion(
- currentSettings, mInputLogic.mWordComposer.isComposingWord() ? 2 : 1);
+ currentSettings.mSpacingAndPunctuations,
+ mInputLogic.mWordComposer.isComposingWord() ? 2 : 1);
if (!TextUtils.equals(previousWord, rereadPrevWord)) {
throw new RuntimeException("Unexpected previous word: "
+ previousWord + " <> " + rereadPrevWord);
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index 22377e0b0..67ea2991c 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -28,6 +28,7 @@ import android.view.inputmethod.InputConnection;
import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.latin.settings.SettingsValues;
+import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
import com.android.inputmethod.latin.utils.CapsModeUtils;
import com.android.inputmethod.latin.utils.DebugLogUtils;
import com.android.inputmethod.latin.utils.SpannableStringUtils;
@@ -537,7 +538,8 @@ public final class RichInputConnection {
}
@SuppressWarnings("unused")
- public String getNthPreviousWord(final SettingsValues currentSettingsValues, final int n) {
+ public String getNthPreviousWord(final SpacingAndPunctuations spacingAndPunctuations,
+ final int n) {
mIC = mParent.getCurrentInputConnection();
if (null == mIC) return null;
final CharSequence prev = getTextBeforeCursor(LOOKBACK_CHARACTER_NUM, 0);
@@ -556,7 +558,7 @@ public final class RichInputConnection {
}
}
}
- return getNthPreviousWord(prev, currentSettingsValues, n);
+ return getNthPreviousWord(prev, spacingAndPunctuations, n);
}
private static boolean isSeparator(int code, String sep) {
@@ -580,7 +582,7 @@ public final class RichInputConnection {
// (n = 2) "abc |" -> null
// (n = 2) "abc. def|" -> null
public static String getNthPreviousWord(final CharSequence prev,
- final SettingsValues currentSettingsValues, final int n) {
+ final SpacingAndPunctuations spacingAndPunctuations, final int n) {
if (prev == null) return null;
final String[] w = spaceRegex.split(prev);
@@ -592,8 +594,8 @@ public final class RichInputConnection {
// If ends in a separator, return null
final char lastChar = nthPrevWord.charAt(length - 1);
- if (currentSettingsValues.isWordSeparator(lastChar)
- || currentSettingsValues.isWordConnector(lastChar)) return null;
+ if (spacingAndPunctuations.isWordSeparator(lastChar)
+ || spacingAndPunctuations.isWordConnector(lastChar)) return null;
return nthPrevWord;
}
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index 968129a96..3de7e3530 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -46,6 +46,7 @@ import com.android.inputmethod.latin.WordComposer;
import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.settings.SettingsValues;
+import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
import com.android.inputmethod.latin.suggestions.SuggestionStripView;
import com.android.inputmethod.latin.utils.AsyncResultHolder;
import com.android.inputmethod.latin.utils.CollectionUtils;
@@ -369,7 +370,8 @@ public final class InputLogic {
mWordComposer.setCapitalizedModeAndPreviousWordAtStartComposingTime(
getActualCapsMode(settingsValues, keyboardSwitcher.getKeyboardShiftMode()),
// Prev word is 1st word before cursor
- getNthPreviousWordForSuggestion(settingsValues, 1 /* nthPreviousWord */));
+ getNthPreviousWordForSuggestion(
+ settingsValues.mSpacingAndPunctuations, 1 /* nthPreviousWord */));
}
/* The sequence number member is only used in onUpdateBatchInput. It is increased each time
@@ -555,7 +557,8 @@ public final class InputLogic {
// yet, so the word we want is the 1st word before the cursor.
mWordComposer.setCapitalizedModeAndPreviousWordAtStartComposingTime(
getActualCapsMode(settingsValues, keyboardSwitcher.getKeyboardShiftMode()),
- getNthPreviousWordForSuggestion(settingsValues, 1 /* nthPreviousWord */));
+ getNthPreviousWordForSuggestion(
+ settingsValues.mSpacingAndPunctuations, 1 /* nthPreviousWord */));
}
mConnection.setComposingText(getTextWithUnderline(
mWordComposer.getTypedWord()), 1);
@@ -1107,7 +1110,7 @@ public final class InputLogic {
}
}
mWordComposer.setComposingWord(typedWord,
- getNthPreviousWordForSuggestion(settingsValues,
+ getNthPreviousWordForSuggestion(settingsValues.mSpacingAndPunctuations,
// We want the previous word for suggestion. If we have chars in the word
// before the cursor, then we want the word before that, hence 2; otherwise,
// we want the word immediately before the cursor, hence 1.
@@ -1301,17 +1304,17 @@ public final class InputLogic {
/**
* Get the nth previous word before the cursor as context for the suggestion process.
- * @param currentSettings the current settings values.
+ * @param spacingAndPunctuations the current spacing and punctuations settings.
* @param nthPreviousWord reverse index of the word to get (1-indexed)
* @return the nth previous word before the cursor.
*/
// TODO: Make this private
- public String getNthPreviousWordForSuggestion(final SettingsValues currentSettings,
- final int nthPreviousWord) {
- if (currentSettings.mSpacingAndPunctuations.mCurrentLanguageHasSpaces) {
+ public String getNthPreviousWordForSuggestion(
+ final SpacingAndPunctuations spacingAndPunctuations, final int nthPreviousWord) {
+ if (spacingAndPunctuations.mCurrentLanguageHasSpaces) {
// If we are typing in a language with spaces we can just look up the previous
// word from textview.
- return mConnection.getNthPreviousWord(currentSettings, nthPreviousWord);
+ return mConnection.getNthPreviousWord(spacingAndPunctuations, nthPreviousWord);
} else {
return LastComposedWord.NOT_A_COMPOSED_WORD == mLastComposedWord ? null
: mLastComposedWord.mCommittedWord;
@@ -1659,7 +1662,8 @@ public final class InputLogic {
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);
+ final String prevWord = mConnection.getNthPreviousWord(
+ settingsValues.mSpacingAndPunctuations, 2);
// Add the word to the user history dictionary
performAdditionToUserHistoryDictionary(settingsValues, chosenWord, prevWord);
// TODO: figure out here if this is an auto-correct or if the best word is actually