aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/ActionBatch.java12
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java37
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/MetadataHandler.java3
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/MetadataParser.java2
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/WordListMetadata.java13
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java11
-rw-r--r--java/src/com/android/inputmethod/latin/PrevWordsInfo.java14
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputConnection.java55
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java6
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java35
10 files changed, 128 insertions, 60 deletions
diff --git a/java/src/com/android/inputmethod/dictionarypack/ActionBatch.java b/java/src/com/android/inputmethod/dictionarypack/ActionBatch.java
index 706bdea8e..3f69cedee 100644
--- a/java/src/com/android/inputmethod/dictionarypack/ActionBatch.java
+++ b/java/src/com/android/inputmethod/dictionarypack/ActionBatch.java
@@ -325,8 +325,9 @@ public final class ActionBatch {
MetadataDbHelper.TYPE_BULK, MetadataDbHelper.STATUS_AVAILABLE,
mWordList.mId, mWordList.mLocale, mWordList.mDescription,
null == mWordList.mLocalFilename ? "" : mWordList.mLocalFilename,
- mWordList.mRemoteFilename, mWordList.mLastUpdate, mWordList.mChecksum,
- mWordList.mFileSize, mWordList.mVersion, mWordList.mFormatVersion);
+ mWordList.mRemoteFilename, mWordList.mLastUpdate, mWordList.mRawChecksum,
+ mWordList.mChecksum, mWordList.mFileSize, mWordList.mVersion,
+ mWordList.mFormatVersion);
PrivateLog.log("Insert 'available' record for " + mWordList.mDescription
+ " and locale " + mWordList.mLocale);
db.insert(MetadataDbHelper.METADATA_TABLE_NAME, null, values);
@@ -374,7 +375,7 @@ public final class ActionBatch {
final ContentValues values = MetadataDbHelper.makeContentValues(0,
MetadataDbHelper.TYPE_BULK, MetadataDbHelper.STATUS_INSTALLED,
mWordList.mId, mWordList.mLocale, mWordList.mDescription,
- "", mWordList.mRemoteFilename, mWordList.mLastUpdate,
+ "", mWordList.mRemoteFilename, mWordList.mLastUpdate, mWordList.mRawChecksum,
mWordList.mChecksum, mWordList.mFileSize, mWordList.mVersion,
mWordList.mFormatVersion);
PrivateLog.log("Insert 'preinstalled' record for " + mWordList.mDescription
@@ -416,8 +417,9 @@ public final class ActionBatch {
oldValues.getAsInteger(MetadataDbHelper.STATUS_COLUMN),
mWordList.mId, mWordList.mLocale, mWordList.mDescription,
oldValues.getAsString(MetadataDbHelper.LOCAL_FILENAME_COLUMN),
- mWordList.mRemoteFilename, mWordList.mLastUpdate, mWordList.mChecksum,
- mWordList.mFileSize, mWordList.mVersion, mWordList.mFormatVersion);
+ mWordList.mRemoteFilename, mWordList.mLastUpdate, mWordList.mRawChecksum,
+ mWordList.mChecksum, mWordList.mFileSize, mWordList.mVersion,
+ mWordList.mFormatVersion);
PrivateLog.log("Updating record for " + mWordList.mDescription
+ " and locale " + mWordList.mLocale);
db.update(MetadataDbHelper.METADATA_TABLE_NAME, values,
diff --git a/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java b/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java
index 4a8fa51ee..668eb925b 100644
--- a/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java
+++ b/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java
@@ -20,6 +20,7 @@ import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.text.TextUtils;
import android.util.Log;
@@ -46,7 +47,7 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
// used to identify the versions for upgrades. This should never change going forward.
private static final int METADATA_DATABASE_VERSION_WITH_CLIENTID = 6;
// The current database version.
- private static final int CURRENT_METADATA_DATABASE_VERSION = 7;
+ private static final int CURRENT_METADATA_DATABASE_VERSION = 8;
private final static long NOT_A_DOWNLOAD_ID = -1;
@@ -66,7 +67,8 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
public static final String VERSION_COLUMN = "version";
public static final String FORMATVERSION_COLUMN = "formatversion";
public static final String FLAGS_COLUMN = "flags";
- public static final int COLUMN_COUNT = 13;
+ public static final String RAW_CHECKSUM_COLUMN = "rawChecksum";
+ public static final int COLUMN_COUNT = 14;
private static final String CLIENT_CLIENT_ID_COLUMN = "clientid";
private static final String CLIENT_METADATA_URI_COLUMN = "uri";
@@ -119,8 +121,9 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
+ CHECKSUM_COLUMN + " TEXT, "
+ FILESIZE_COLUMN + " INTEGER, "
+ VERSION_COLUMN + " INTEGER,"
- + FORMATVERSION_COLUMN + " INTEGER,"
- + FLAGS_COLUMN + " INTEGER,"
+ + FORMATVERSION_COLUMN + " INTEGER, "
+ + FLAGS_COLUMN + " INTEGER, "
+ + RAW_CHECKSUM_COLUMN + " TEXT,"
+ "PRIMARY KEY (" + WORDLISTID_COLUMN + "," + VERSION_COLUMN + "));";
private static final String METADATA_CREATE_CLIENT_TABLE =
"CREATE TABLE IF NOT EXISTS " + CLIENT_TABLE_NAME + " ("
@@ -136,7 +139,8 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
static final String[] METADATA_TABLE_COLUMNS = { PENDINGID_COLUMN, TYPE_COLUMN,
STATUS_COLUMN, WORDLISTID_COLUMN, LOCALE_COLUMN, DESCRIPTION_COLUMN,
LOCAL_FILENAME_COLUMN, REMOTE_FILENAME_COLUMN, DATE_COLUMN, CHECKSUM_COLUMN,
- FILESIZE_COLUMN, VERSION_COLUMN, FORMATVERSION_COLUMN, FLAGS_COLUMN };
+ FILESIZE_COLUMN, VERSION_COLUMN, FORMATVERSION_COLUMN, FLAGS_COLUMN,
+ RAW_CHECKSUM_COLUMN };
// List of all client table columns.
static final String[] CLIENT_TABLE_COLUMNS = { CLIENT_CLIENT_ID_COLUMN,
CLIENT_METADATA_URI_COLUMN, CLIENT_PENDINGID_COLUMN, FLAGS_COLUMN };
@@ -215,6 +219,17 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
createClientTable(db);
}
+ private void addRawChecksumColumnUnlessPresent(final SQLiteDatabase db, final String clientId) {
+ try {
+ db.execSQL("SELECT " + RAW_CHECKSUM_COLUMN + " FROM "
+ + METADATA_TABLE_NAME + " LIMIT 0;");
+ } catch (SQLiteException e) {
+ Log.i(TAG, "No " + RAW_CHECKSUM_COLUMN + " column : creating it");
+ db.execSQL("ALTER TABLE " + METADATA_TABLE_NAME + " ADD COLUMN "
+ + RAW_CHECKSUM_COLUMN + " TEXT;");
+ }
+ }
+
/**
* Upgrade the database. Upgrade from version 3 is supported.
* Version 3 has a DB named METADATA_DATABASE_NAME_STEM containing a table METADATA_TABLE_NAME.
@@ -260,6 +275,12 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
db.execSQL("DROP TABLE IF EXISTS " + CLIENT_TABLE_NAME);
onCreate(db);
}
+ // A rawChecksum column that did not exist in the previous versions was added that
+ // corresponds to the md5 checksum of the file after decompression/decryption. This is to
+ // strengthen the system against corrupted dictionary files.
+ // The most secure way to upgrade a database is to just test for the column presence, and
+ // add it if it's not there.
+ addRawChecksumColumnUnlessPresent(db, mClientId);
}
/**
@@ -431,7 +452,7 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
public static ContentValues makeContentValues(final int pendingId, final int type,
final int status, final String wordlistId, final String locale,
final String description, final String filename, final String url, final long date,
- final String checksum, final long filesize, final int version,
+ final String rawChecksum, final String checksum, final long filesize, final int version,
final int formatVersion) {
final ContentValues result = new ContentValues(COLUMN_COUNT);
result.put(PENDINGID_COLUMN, pendingId);
@@ -443,6 +464,7 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
result.put(LOCAL_FILENAME_COLUMN, filename);
result.put(REMOTE_FILENAME_COLUMN, url);
result.put(DATE_COLUMN, date);
+ result.put(RAW_CHECKSUM_COLUMN, rawChecksum);
result.put(CHECKSUM_COLUMN, checksum);
result.put(FILESIZE_COLUMN, filesize);
result.put(VERSION_COLUMN, version);
@@ -478,6 +500,8 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
if (null == result.get(REMOTE_FILENAME_COLUMN)) result.put(REMOTE_FILENAME_COLUMN, "");
// 0 for the update date : 1970/1/1. Unless specified.
if (null == result.get(DATE_COLUMN)) result.put(DATE_COLUMN, 0);
+ // Raw checksum unknown unless specified
+ if (null == result.get(RAW_CHECKSUM_COLUMN)) result.put(RAW_CHECKSUM_COLUMN, "");
// Checksum unknown unless specified
if (null == result.get(CHECKSUM_COLUMN)) result.put(CHECKSUM_COLUMN, "");
// No filesize unless specified
@@ -525,6 +549,7 @@ public class MetadataDbHelper extends SQLiteOpenHelper {
putStringResult(result, cursor, LOCAL_FILENAME_COLUMN);
putStringResult(result, cursor, REMOTE_FILENAME_COLUMN);
putIntResult(result, cursor, DATE_COLUMN);
+ putStringResult(result, cursor, RAW_CHECKSUM_COLUMN);
putStringResult(result, cursor, CHECKSUM_COLUMN);
putIntResult(result, cursor, FILESIZE_COLUMN);
putIntResult(result, cursor, VERSION_COLUMN);
diff --git a/java/src/com/android/inputmethod/dictionarypack/MetadataHandler.java b/java/src/com/android/inputmethod/dictionarypack/MetadataHandler.java
index 5c2289911..63e419871 100644
--- a/java/src/com/android/inputmethod/dictionarypack/MetadataHandler.java
+++ b/java/src/com/android/inputmethod/dictionarypack/MetadataHandler.java
@@ -52,6 +52,8 @@ public class MetadataHandler {
final int idIndex = results.getColumnIndex(MetadataDbHelper.WORDLISTID_COLUMN);
final int updateIndex = results.getColumnIndex(MetadataDbHelper.DATE_COLUMN);
final int fileSizeIndex = results.getColumnIndex(MetadataDbHelper.FILESIZE_COLUMN);
+ final int rawChecksumIndex =
+ results.getColumnIndex(MetadataDbHelper.RAW_CHECKSUM_COLUMN);
final int checksumIndex = results.getColumnIndex(MetadataDbHelper.CHECKSUM_COLUMN);
final int localFilenameIndex =
results.getColumnIndex(MetadataDbHelper.LOCAL_FILENAME_COLUMN);
@@ -66,6 +68,7 @@ public class MetadataHandler {
results.getString(descriptionColumn),
results.getLong(updateIndex),
results.getLong(fileSizeIndex),
+ results.getString(rawChecksumIndex),
results.getString(checksumIndex),
results.getString(localFilenameIndex),
results.getString(remoteFilenameIndex),
diff --git a/java/src/com/android/inputmethod/dictionarypack/MetadataParser.java b/java/src/com/android/inputmethod/dictionarypack/MetadataParser.java
index 27670fddf..a88173e8e 100644
--- a/java/src/com/android/inputmethod/dictionarypack/MetadataParser.java
+++ b/java/src/com/android/inputmethod/dictionarypack/MetadataParser.java
@@ -37,6 +37,7 @@ public class MetadataParser {
private static final String DESCRIPTION_FIELD_NAME = MetadataDbHelper.DESCRIPTION_COLUMN;
private static final String UPDATE_FIELD_NAME = "update";
private static final String FILESIZE_FIELD_NAME = MetadataDbHelper.FILESIZE_COLUMN;
+ private static final String RAW_CHECKSUM_FIELD_NAME = MetadataDbHelper.RAW_CHECKSUM_COLUMN;
private static final String CHECKSUM_FIELD_NAME = MetadataDbHelper.CHECKSUM_COLUMN;
private static final String REMOTE_FILENAME_FIELD_NAME =
MetadataDbHelper.REMOTE_FILENAME_COLUMN;
@@ -80,6 +81,7 @@ public class MetadataParser {
arguments.get(DESCRIPTION_FIELD_NAME),
Long.parseLong(arguments.get(UPDATE_FIELD_NAME)),
Long.parseLong(arguments.get(FILESIZE_FIELD_NAME)),
+ arguments.get(RAW_CHECKSUM_FIELD_NAME),
arguments.get(CHECKSUM_FIELD_NAME),
null,
arguments.get(REMOTE_FILENAME_FIELD_NAME),
diff --git a/java/src/com/android/inputmethod/dictionarypack/WordListMetadata.java b/java/src/com/android/inputmethod/dictionarypack/WordListMetadata.java
index 69bff9597..9e510a68b 100644
--- a/java/src/com/android/inputmethod/dictionarypack/WordListMetadata.java
+++ b/java/src/com/android/inputmethod/dictionarypack/WordListMetadata.java
@@ -30,6 +30,7 @@ public class WordListMetadata {
public final String mDescription;
public final long mLastUpdate;
public final long mFileSize;
+ public final String mRawChecksum;
public final String mChecksum;
public final String mLocalFilename;
public final String mRemoteFilename;
@@ -50,13 +51,15 @@ public class WordListMetadata {
public WordListMetadata(final String id, final int type,
final String description, final long lastUpdate, final long fileSize,
- final String checksum, final String localFilename, final String remoteFilename,
- final int version, final int formatVersion, final int flags, final String locale) {
+ final String rawChecksum, final String checksum, final String localFilename,
+ final String remoteFilename, final int version, final int formatVersion,
+ final int flags, final String locale) {
mId = id;
mType = type;
mDescription = description;
mLastUpdate = lastUpdate; // In milliseconds
mFileSize = fileSize;
+ mRawChecksum = rawChecksum;
mChecksum = checksum;
mLocalFilename = localFilename;
mRemoteFilename = remoteFilename;
@@ -77,6 +80,7 @@ public class WordListMetadata {
final String description = values.getAsString(MetadataDbHelper.DESCRIPTION_COLUMN);
final Long lastUpdate = values.getAsLong(MetadataDbHelper.DATE_COLUMN);
final Long fileSize = values.getAsLong(MetadataDbHelper.FILESIZE_COLUMN);
+ final String rawChecksum = values.getAsString(MetadataDbHelper.RAW_CHECKSUM_COLUMN);
final String checksum = values.getAsString(MetadataDbHelper.CHECKSUM_COLUMN);
final String localFilename = values.getAsString(MetadataDbHelper.LOCAL_FILENAME_COLUMN);
final String remoteFilename = values.getAsString(MetadataDbHelper.REMOTE_FILENAME_COLUMN);
@@ -98,8 +102,8 @@ public class WordListMetadata {
|| null == locale) {
throw new IllegalArgumentException();
}
- return new WordListMetadata(id, type, description, lastUpdate, fileSize, checksum,
- localFilename, remoteFilename, version, formatVersion, flags, locale);
+ return new WordListMetadata(id, type, description, lastUpdate, fileSize, rawChecksum,
+ checksum, localFilename, remoteFilename, version, formatVersion, flags, locale);
}
@Override
@@ -110,6 +114,7 @@ public class WordListMetadata {
sb.append("\nDescription : ").append(mDescription);
sb.append("\nLastUpdate : ").append(mLastUpdate);
sb.append("\nFileSize : ").append(mFileSize);
+ sb.append("\nRawChecksum : ").append(mRawChecksum);
sb.append("\nChecksum : ").append(mChecksum);
sb.append("\nLocalFilename : ").append(mLocalFilename);
sb.append("\nRemoteFilename : ").append(mRemoteFilename);
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 5e45275f8..19c777a3e 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -1435,12 +1435,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// We're checking the previous word in the text field against the memorized previous
// word. If we are composing a word we should have the second word before the cursor
// memorized, otherwise we should have the first.
- final CharSequence rereadPrevWord = mInputLogic.getNthPreviousWordForSuggestion(
- currentSettings.mSpacingAndPunctuations,
- mInputLogic.mWordComposer.isComposingWord() ? 2 : 1);
- if (!TextUtils.equals(prevWordsInfo.mPrevWord, rereadPrevWord)) {
+ final PrevWordsInfo rereadPrevWordsInfo =
+ mInputLogic.getPrevWordsInfoFromNthPreviousWordForSuggestion(
+ currentSettings.mSpacingAndPunctuations,
+ mInputLogic.mWordComposer.isComposingWord() ? 2 : 1);
+ if (!TextUtils.equals(prevWordsInfo.mPrevWord, rereadPrevWordsInfo.mPrevWord)) {
throw new RuntimeException("Unexpected previous word: "
- + prevWordsInfo.mPrevWord + " <> " + rereadPrevWord);
+ + prevWordsInfo.mPrevWord + " <> " + rereadPrevWordsInfo.mPrevWord);
}
}
}
diff --git a/java/src/com/android/inputmethod/latin/PrevWordsInfo.java b/java/src/com/android/inputmethod/latin/PrevWordsInfo.java
index 9d8543183..ecc8947db 100644
--- a/java/src/com/android/inputmethod/latin/PrevWordsInfo.java
+++ b/java/src/com/android/inputmethod/latin/PrevWordsInfo.java
@@ -16,6 +16,9 @@
package com.android.inputmethod.latin;
+import android.util.Log;
+
+// TODO: Support multiple previous words for n-gram.
public class PrevWordsInfo {
// The previous word. May be null after resetting and before starting a new composing word, or
// when there is no context like at the start of text for example. It can also be set to null
@@ -23,7 +26,18 @@ public class PrevWordsInfo {
// or a comma.
public final String mPrevWord;
+ // TODO: Have sentence separator.
+ // Whether the current context is beginning of sentence or not.
+ public final boolean mIsBeginningOfSentence;
+
+ // Beginning of sentence.
+ public PrevWordsInfo() {
+ mPrevWord = null;
+ mIsBeginningOfSentence = true;
+ }
+
public PrevWordsInfo(final String prevWord) {
mPrevWord = prevWord;
+ mIsBeginningOfSentence = false;
}
}
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index 606bb775e..2c54e10aa 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -538,10 +538,12 @@ public final class RichInputConnection {
}
@SuppressWarnings("unused")
- public String getNthPreviousWord(final SpacingAndPunctuations spacingAndPunctuations,
- final int n) {
+ public PrevWordsInfo getPrevWordsInfoFromNthPreviousWord(
+ final SpacingAndPunctuations spacingAndPunctuations, final int n) {
mIC = mParent.getCurrentInputConnection();
- if (null == mIC) return null;
+ if (null == mIC) {
+ return new PrevWordsInfo(null);
+ }
final CharSequence prev = getTextBeforeCursor(LOOKBACK_CHARACTER_NUM, 0);
if (DEBUG_PREVIOUS_TEXT && null != prev) {
final int checkLength = LOOKBACK_CHARACTER_NUM - 1;
@@ -561,46 +563,57 @@ public final class RichInputConnection {
}
}
}
- return getNthPreviousWord(prev, spacingAndPunctuations, n);
+ return getPrevWordsInfoFromNthPreviousWord(prev, spacingAndPunctuations, n);
}
private static boolean isSeparator(final int code, final int[] sortedSeparators) {
return Arrays.binarySearch(sortedSeparators, code) >= 0;
}
- // Get the nth word before cursor. n = 1 retrieves the word immediately before the cursor,
- // n = 2 retrieves the word before that, and so on. This splits on whitespace only.
+ // Get information of the nth word before cursor. n = 1 retrieves the word immediately before
+ // the cursor, n = 2 retrieves the word before that, and so on. This splits on whitespace only.
// Also, it won't return words that end in a separator (if the nth word before the cursor
- // ends in a separator, it returns null).
+ // ends in a separator, it returns information represents beginning-of-sentence).
// Example :
// (n = 1) "abc def|" -> def
// (n = 1) "abc def |" -> def
- // (n = 1) "abc def. |" -> null
- // (n = 1) "abc def . |" -> null
+ // (n = 1) "abc def. |" -> beginning-of-sentence
+ // (n = 1) "abc def . |" -> beginning-of-sentence
// (n = 2) "abc def|" -> abc
// (n = 2) "abc def |" -> abc
// (n = 2) "abc def. |" -> abc
// (n = 2) "abc def . |" -> def
- // (n = 2) "abc|" -> null
- // (n = 2) "abc |" -> null
- // (n = 2) "abc. def|" -> null
- public static String getNthPreviousWord(final CharSequence prev,
+ // (n = 2) "abc|" -> beginning-of-sentence
+ // (n = 2) "abc |" -> beginning-of-sentence
+ // (n = 2) "abc. def|" -> beginning-of-sentence
+ public static PrevWordsInfo getPrevWordsInfoFromNthPreviousWord(final CharSequence prev,
final SpacingAndPunctuations spacingAndPunctuations, final int n) {
- if (prev == null) return null;
+ if (prev == null) return new PrevWordsInfo(null);
final String[] w = spaceRegex.split(prev);
- // If we can't find n words, or we found an empty word, return null.
- if (w.length < n) return null;
+ // If we can't find n words, or we found an empty word, the context is
+ // beginning-of-sentence.
+ if (w.length < n) {
+ return new PrevWordsInfo();
+ }
final String nthPrevWord = w[w.length - n];
final int length = nthPrevWord.length();
- if (length <= 0) return null;
+ if (length <= 0) {
+ return new PrevWordsInfo();
+ }
- // If ends in a separator, return null
+ // If ends in a sentence separator, the context is beginning-of-sentence.
final char lastChar = nthPrevWord.charAt(length - 1);
+ if (spacingAndPunctuations.isSentenceSeparator(lastChar)) {
+ new PrevWordsInfo();
+ }
+ // If ends in a word separator or connector, the context is unclear.
+ // TODO: Return meaningful context for this case.
if (spacingAndPunctuations.isWordSeparator(lastChar)
- || spacingAndPunctuations.isWordConnector(lastChar)) return null;
-
- return nthPrevWord;
+ || spacingAndPunctuations.isWordConnector(lastChar)) {
+ return new PrevWordsInfo(null);
+ }
+ return new PrevWordsInfo(nthPrevWord);
}
/**
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index 09e905481..6ecb37346 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -371,12 +371,12 @@ public final class WordComposer {
* Also, batch input needs to know about the current caps mode to display correctly
* capitalized suggestions.
* @param mode the mode at the time of start
- * @param previousWord the previous word as context for suggestions. May be null if none.
+ * @param prevWordsInfo the information of previous words
*/
public void setCapitalizedModeAndPreviousWordAtStartComposingTime(final int mode,
- final CharSequence previousWord) {
+ final PrevWordsInfo prevWordsInfo) {
mCapitalizedMode = mode;
- mPrevWordsInfo = new PrevWordsInfo(null == previousWord ? null : previousWord.toString());
+ mPrevWordsInfo = prevWordsInfo;
}
/**
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index 799a08007..faab76944 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -575,7 +575,7 @@ public final class InputLogic {
mWordComposer.setCapitalizedModeAndPreviousWordAtStartComposingTime(
getActualCapsMode(settingsValues, keyboardSwitcher.getKeyboardShiftMode()),
// Prev word is 1st word before cursor
- getNthPreviousWordForSuggestion(
+ getPrevWordsInfoFromNthPreviousWordForSuggestion(
settingsValues.mSpacingAndPunctuations, 1 /* nthPreviousWord */));
}
@@ -614,7 +614,8 @@ public final class InputLogic {
getCurrentAutoCapsState(settingsValues), getCurrentRecapitalizeState());
mWordComposer.setCapitalizedModeAndPreviousWordAtStartComposingTime(
getActualCapsMode(settingsValues,
- keyboardSwitcher.getKeyboardShiftMode()), commitParts[0]);
+ keyboardSwitcher.getKeyboardShiftMode()),
+ new PrevWordsInfo(commitParts[0]));
++mAutoCommitSequenceNumber;
}
}
@@ -765,7 +766,8 @@ public final class InputLogic {
// We pass 1 to getPreviousWordForSuggestion because we were not composing a word
// yet, so the word we want is the 1st word before the cursor.
mWordComposer.setCapitalizedModeAndPreviousWordAtStartComposingTime(
- inputTransaction.mShiftState, getNthPreviousWordForSuggestion(
+ inputTransaction.mShiftState,
+ getPrevWordsInfoFromNthPreviousWordForSuggestion(
settingsValues.mSpacingAndPunctuations, 1 /* nthPreviousWord */));
}
mConnection.setComposingText(getTextWithUnderline(
@@ -1326,7 +1328,8 @@ public final class InputLogic {
// Show predictions.
mWordComposer.setCapitalizedModeAndPreviousWordAtStartComposingTime(
WordComposer.CAPS_MODE_OFF,
- getNthPreviousWordForSuggestion(settingsValues.mSpacingAndPunctuations, 1));
+ getPrevWordsInfoFromNthPreviousWordForSuggestion(
+ settingsValues.mSpacingAndPunctuations, 1));
mLatinIME.mHandler.postUpdateSuggestionStrip();
return;
}
@@ -1374,11 +1377,9 @@ public final class InputLogic {
// 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.
- final CharSequence prevWord = getNthPreviousWordForSuggestion(
+ final PrevWordsInfo prevWordsInfo = getPrevWordsInfoFromNthPreviousWordForSuggestion(
settingsValues.mSpacingAndPunctuations,
0 == numberOfCharsInWordBeforeCursor ? 1 : 2);
- final PrevWordsInfo prevWordsInfo =
- new PrevWordsInfo(prevWord != null ? prevWord.toString() : null);
mWordComposer.setComposingWord(codePoints,
mLatinIME.getCoordinatesForCurrentKeyboard(codePoints), prevWordsInfo);
mWordComposer.setCursorPositionWithinWord(
@@ -1590,21 +1591,23 @@ public final class InputLogic {
}
/**
- * Get the nth previous word before the cursor as context for the suggestion process.
+ * Get information fo previous words from the nth previous word before the cursor as context
+ * for the suggestion process.
* @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.
+ * @return the information of previous words
*/
// TODO: Make this private
- public CharSequence getNthPreviousWordForSuggestion(
+ public PrevWordsInfo getPrevWordsInfoFromNthPreviousWordForSuggestion(
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(spacingAndPunctuations, nthPreviousWord);
+ // word information from textview.
+ return mConnection.getPrevWordsInfoFromNthPreviousWord(
+ spacingAndPunctuations, nthPreviousWord);
} else {
- return LastComposedWord.NOT_A_COMPOSED_WORD == mLastComposedWord ? null
- : mLastComposedWord.mCommittedWord;
+ return LastComposedWord.NOT_A_COMPOSED_WORD == mLastComposedWord ? new PrevWordsInfo()
+ : new PrevWordsInfo(mLastComposedWord.mCommittedWord.toString());
}
}
@@ -1972,8 +1975,8 @@ public final class InputLogic {
suggestedWords);
// Use the 2nd previous word as the previous word because the 1st previous word is the word
// to be committed.
- final PrevWordsInfo prevWordsInfo = new PrevWordsInfo(mConnection.getNthPreviousWord(
- settingsValues.mSpacingAndPunctuations, 2));
+ final PrevWordsInfo prevWordsInfo = mConnection.getPrevWordsInfoFromNthPreviousWord(
+ settingsValues.mSpacingAndPunctuations, 2);
mConnection.commitText(chosenWordWithSuggestions, 1);
// Add the word to the user history dictionary
performAdditionToUserHistoryDictionary(settingsValues, chosenWord, prevWordsInfo);