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/BinaryDictionary.java107
-rw-r--r--java/src/com/android/inputmethod/latin/ExpandableDictionary.java3
-rw-r--r--java/src/com/android/inputmethod/latin/InputLanguageSelection.java10
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java120
-rw-r--r--java/src/com/android/inputmethod/latin/LatinImeLogger.java2
-rw-r--r--java/src/com/android/inputmethod/latin/SubtypeSwitcher.java2
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java43
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java2
8 files changed, 112 insertions, 177 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 7ee0d77e5..af08742d3 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -1,12 +1,12 @@
/*
* Copyright (C) 2008 The Android Open Source Project
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -17,13 +17,9 @@
package com.android.inputmethod.latin;
import android.content.Context;
+import android.content.res.AssetFileDescriptor;
import android.util.Log;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.channels.Channels;
import java.util.Arrays;
/**
@@ -48,21 +44,18 @@ public class BinaryDictionary extends Dictionary {
private int mDicTypeId;
private int mNativeDict;
- private int mDictLength;
+ private long mDictLength;
private final int[] mInputCodes = new int[MAX_WORD_LENGTH * MAX_ALTERNATIVES];
private final char[] mOutputChars = new char[MAX_WORD_LENGTH * MAX_WORDS];
private final char[] mOutputChars_bigrams = new char[MAX_WORD_LENGTH * MAX_BIGRAMS];
private final int[] mFrequencies = new int[MAX_WORDS];
private final int[] mFrequencies_bigrams = new int[MAX_BIGRAMS];
- // Keep a reference to the native dict direct buffer in Java to avoid
- // unexpected deallocation of the direct buffer.
- private ByteBuffer mNativeDictDirectBuffer;
static {
try {
System.loadLibrary("jni_latinime2");
} catch (UnsatisfiedLinkError ule) {
- Log.e("BinaryDictionary", "Could not load native library jni_latinime2");
+ Log.e(TAG, "Could not load native library jni_latinime");
}
}
@@ -71,91 +64,46 @@ public class BinaryDictionary extends Dictionary {
* @param context application context for reading resources
* @param resId the resource containing the raw binary dictionary
*/
- public BinaryDictionary(Context context, int[] resId, int dicTypeId) {
- if (resId != null && resId.length > 0 && resId[0] != 0) {
+ public BinaryDictionary(Context context, int resId, int dicTypeId) {
+ if (resId != 0) {
loadDictionary(context, resId);
}
mDicTypeId = dicTypeId;
}
- /**
- * Create a dictionary from a byte buffer. This is used for testing.
- * @param context application context for reading resources
- * @param byteBuffer a ByteBuffer containing the binary dictionary
- */
- public BinaryDictionary(Context context, ByteBuffer byteBuffer, int dicTypeId) {
- if (byteBuffer != null) {
- if (byteBuffer.isDirect()) {
- mNativeDictDirectBuffer = byteBuffer;
- } else {
- mNativeDictDirectBuffer = ByteBuffer.allocateDirect(byteBuffer.capacity());
- byteBuffer.rewind();
- mNativeDictDirectBuffer.put(byteBuffer);
- }
- mDictLength = byteBuffer.capacity();
- mNativeDict = openNative(mNativeDictDirectBuffer,
- TYPED_LETTER_MULTIPLIER, FULL_WORD_FREQ_MULTIPLIER,
- MAX_WORD_LENGTH, MAX_WORDS, MAX_ALTERNATIVES);
- }
- mDicTypeId = dicTypeId;
- }
-
- private native int openNative(ByteBuffer bb, int typedLetterMultiplier,
- int fullWordMultiplier, int maxWordLength, int maxWords, int maxAlternatives);
+ private native int openNative(String sourceDir, long dictOffset, long dictSize,
+ int typedLetterMultiplier, int fullWordMultiplier, int maxWordLength,
+ int maxWords, int maxAlternatives);
private native void closeNative(int dict);
private native boolean isValidWordNative(int nativeData, char[] word, int wordLength);
- private native int getSuggestionsNative(int dict, int[] inputCodes, int codesSize,
+ private native int getSuggestionsNative(int dict, int[] inputCodes, int codesSize,
char[] outputChars, int[] frequencies,
int[] nextLettersFrequencies, int nextLettersSize);
private native int getBigramsNative(int dict, char[] prevWord, int prevWordLength,
int[] inputCodes, int inputCodesLength, char[] outputChars, int[] frequencies,
int maxWordLength, int maxBigrams, int maxAlternatives);
- private final void loadDictionary(Context context, int[] resId) {
- InputStream[] is = null;
+ private final void loadDictionary(Context context, int resId) {
try {
- // merging separated dictionary into one if dictionary is separated
- int total = 0;
- is = new InputStream[resId.length];
- for (int i = 0; i < resId.length; i++) {
- is[i] = context.getResources().openRawResource(resId[i]);
- total += is[i].available();
- }
-
- mNativeDictDirectBuffer =
- ByteBuffer.allocateDirect(total).order(ByteOrder.nativeOrder());
- int got = 0;
- for (int i = 0; i < resId.length; i++) {
- got += Channels.newChannel(is[i]).read(mNativeDictDirectBuffer);
- }
- if (got != total) {
- Log.e(TAG, "Read " + got + " bytes, expected " + total);
- } else {
- mNativeDict = openNative(mNativeDictDirectBuffer,
- TYPED_LETTER_MULTIPLIER, FULL_WORD_FREQ_MULTIPLIER,
- MAX_WORD_LENGTH, MAX_WORDS, MAX_ALTERNATIVES);
- mDictLength = total;
- }
- } catch (IOException e) {
- Log.w(TAG, "No available memory for binary dictionary");
- } finally {
- try {
- if (is != null) {
- for (int i = 0; i < is.length; i++) {
- is[i].close();
- }
- }
- } catch (IOException e) {
- Log.w(TAG, "Failed to close input stream");
+ final AssetFileDescriptor afd = context.getResources().openRawResourceFd(resId);
+ if (afd == null) {
+ Log.e(TAG, "Found the resource but it is compressed. resId=" + resId);
+ return;
}
+ mNativeDict = openNative(context.getApplicationInfo().sourceDir,
+ afd.getStartOffset(), afd.getLength(),
+ TYPED_LETTER_MULTIPLIER, FULL_WORD_FREQ_MULTIPLIER,
+ MAX_WORD_LENGTH, MAX_WORDS, MAX_ALTERNATIVES);
+ mDictLength = afd.getLength();
+ } catch (android.content.res.Resources.NotFoundException e) {
+ Log.e(TAG, "Could not find the resource. resId=" + resId);
+ return;
}
}
-
@Override
public void getBigrams(final WordComposer codes, final CharSequence previousWord,
final WordCallback callback, int[] nextLettersFrequencies) {
-
char[] chars = previousWord.toString().toCharArray();
Arrays.fill(mOutputChars_bigrams, (char) 0);
Arrays.fill(mFrequencies_bigrams, 0);
@@ -225,8 +173,8 @@ public class BinaryDictionary extends Dictionary {
return isValidWordNative(mNativeDict, chars, chars.length);
}
- public int getSize() {
- return mDictLength; // This value is initialized on the call to openNative()
+ public long getSize() {
+ return mDictLength; // This value is initialized in loadDictionary()
}
@Override
@@ -234,6 +182,7 @@ public class BinaryDictionary extends Dictionary {
if (mNativeDict != 0) {
closeNative(mNativeDict);
mNativeDict = 0;
+ mDictLength = 0;
}
}
diff --git a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java
index bc08df042..0fc86c335 100644
--- a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java
@@ -146,7 +146,7 @@ public class ExpandableDictionary extends Dictionary {
public Context getContext() {
return mContext;
}
-
+
public int getMaxWordLength() {
return MAX_WORD_LENGTH;
}
@@ -158,6 +158,7 @@ public class ExpandableDictionary extends Dictionary {
private void addWordRec(NodeArray children, final String word, final int depth,
final int frequency, Node parentNode) {
final int wordLength = word.length();
+ if (wordLength <= depth) return;
final char c = word.charAt(depth);
// Does children have the current character?
final int childrenLength = children.mLength;
diff --git a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java b/java/src/com/android/inputmethod/latin/InputLanguageSelection.java
index 27e0fbe4a..faee38eda 100644
--- a/java/src/com/android/inputmethod/latin/InputLanguageSelection.java
+++ b/java/src/com/android/inputmethod/latin/InputLanguageSelection.java
@@ -99,15 +99,15 @@ public class InputLanguageSelection extends PreferenceActivity {
}
private boolean hasDictionary(Locale locale) {
- Resources res = getResources();
- Configuration conf = res.getConfiguration();
- Locale saveLocale = conf.locale;
+ final Resources res = getResources();
+ final Configuration conf = res.getConfiguration();
+ final Locale saveLocale = conf.locale;
boolean haveDictionary = false;
conf.locale = locale;
res.updateConfiguration(conf, res.getDisplayMetrics());
- int[] dictionaries = LatinIME.getDictionary(res);
- BinaryDictionary bd = new BinaryDictionary(this, dictionaries, Suggest.DIC_MAIN);
+ int mainDicResId = LatinIME.getMainDictionaryResourceId(res);
+ BinaryDictionary bd = new BinaryDictionary(this, mainDicResId, Suggest.DIC_MAIN);
// Is the dictionary larger than a placeholder? Arbitrarily chose a lower limit of
// 4000-5000 words, whereas the LARGE_DICTIONARY is about 20000+ words.
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index c44410449..88261b60e 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -347,49 +347,19 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
/**
- * Loads a dictionary or multiple separated dictionary
- * @return returns array of dictionary resource ids
+ * Returns a main dictionary resource id
+ * @return main dictionary resource id
*/
- public static int[] getDictionary(Resources res) {
+ public static int getMainDictionaryResourceId(Resources res) {
+ final String MAIN_DIC_NAME = "main";
String packageName = LatinIME.class.getPackage().getName();
- XmlResourceParser xrp = res.getXml(R.xml.dictionary);
- ArrayList<Integer> dictionaries = new ArrayList<Integer>();
-
- try {
- int current = xrp.getEventType();
- while (current != XmlPullParser.END_DOCUMENT) {
- if (current == XmlPullParser.START_TAG) {
- String tag = xrp.getName();
- if (tag != null) {
- if (tag.equals("part")) {
- String dictFileName = xrp.getAttributeValue(null, "name");
- dictionaries.add(res.getIdentifier(dictFileName, "raw", packageName));
- }
- }
- }
- xrp.next();
- current = xrp.getEventType();
- }
- } catch (XmlPullParserException e) {
- Log.e(TAG, "Dictionary XML parsing failure");
- } catch (IOException e) {
- Log.e(TAG, "Dictionary XML IOException");
- }
-
- int count = dictionaries.size();
- int[] dict = new int[count];
- for (int i = 0; i < count; i++) {
- dict[i] = dictionaries.get(i);
- }
-
- return dict;
+ return res.getIdentifier(MAIN_DIC_NAME, "raw", packageName);
}
private void initSuggest() {
updateAutoTextEnabled();
String locale = mSubtypeSwitcher.getInputLocaleStr();
- Resources orig = getResources();
Locale savedLocale = mSubtypeSwitcher.changeSystemLocale(new Locale(locale));
if (mSuggest != null) {
mSuggest.close();
@@ -397,40 +367,35 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final SharedPreferences prefs = mPrefs;
mQuickFixes = prefs.getBoolean(Settings.PREF_QUICK_FIXES, true);
- int[] dictionaries = getDictionary(orig);
- mSuggest = new Suggest(this, dictionaries);
+ final Resources res = mResources;
+ int mainDicResId = getMainDictionaryResourceId(res);
+ mSuggest = new Suggest(this, mainDicResId);
loadAndSetAutoCorrectionThreshold(prefs);
- if (mUserDictionary != null) mUserDictionary.close();
+
mUserDictionary = new UserDictionary(this, locale);
- if (mContactsDictionary == null) {
- mContactsDictionary = new ContactsDictionary(this, Suggest.DIC_CONTACTS);
- }
- if (mAutoDictionary != null) {
- mAutoDictionary.close();
- }
- mAutoDictionary = new AutoDictionary(this, this, locale, Suggest.DIC_AUTO);
- if (mUserBigramDictionary != null) {
- mUserBigramDictionary.close();
- }
- mUserBigramDictionary = new UserBigramDictionary(this, this, locale, Suggest.DIC_USER);
- mSuggest.setUserBigramDictionary(mUserBigramDictionary);
mSuggest.setUserDictionary(mUserDictionary);
+
+ mContactsDictionary = new ContactsDictionary(this, Suggest.DIC_CONTACTS);
mSuggest.setContactsDictionary(mContactsDictionary);
+
+ mAutoDictionary = new AutoDictionary(this, this, locale, Suggest.DIC_AUTO);
mSuggest.setAutoDictionary(mAutoDictionary);
+
+ mUserBigramDictionary = new UserBigramDictionary(this, this, locale, Suggest.DIC_USER);
+ mSuggest.setUserBigramDictionary(mUserBigramDictionary);
+
updateCorrectionMode();
- mWordSeparators = mResources.getString(R.string.word_separators);
- mSentenceSeparators = mResources.getString(R.string.sentence_separators);
+ mWordSeparators = res.getString(R.string.word_separators);
+ mSentenceSeparators = res.getString(R.string.sentence_separators);
mSubtypeSwitcher.changeSystemLocale(savedLocale);
}
@Override
public void onDestroy() {
- if (mUserDictionary != null) {
- mUserDictionary.close();
- }
- if (mContactsDictionary != null) {
- mContactsDictionary.close();
+ if (mSuggest != null) {
+ mSuggest.close();
+ mSuggest = null;
}
unregisterReceiver(mReceiver);
mVoiceConnector.destroy();
@@ -811,11 +776,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override
public void onDisplayCompletions(CompletionInfo[] applicationSpecifiedCompletions) {
if (DEBUG) {
- Log.i("foo", "Received completions:");
+ Log.i(TAG, "Received completions:");
final int count = (applicationSpecifiedCompletions != null)
? applicationSpecifiedCompletions.length : 0;
for (int i = 0; i < count; i++) {
- Log.i("foo", " #" + i + ": " + applicationSpecifiedCompletions[i]);
+ Log.i(TAG, " #" + i + ": " + applicationSpecifiedCompletions[i]);
}
}
if (mApplicationSpecifiedCompletionOn) {
@@ -859,10 +824,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override
public boolean onEvaluateFullscreenMode() {
- DisplayMetrics dm = getResources().getDisplayMetrics();
+ final Resources res = mResources;
+ DisplayMetrics dm = res.getDisplayMetrics();
float displayHeight = dm.heightPixels;
// If the display is more than X inches high, don't go to fullscreen mode
- float dimen = getResources().getDimension(R.dimen.max_height_for_fullscreen);
+ float dimen = res.getDimension(R.dimen.max_height_for_fullscreen);
if (displayHeight > dimen) {
return false;
} else {
@@ -1048,8 +1014,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
return mOptionsDialog != null && mOptionsDialog.isShowing();
}
- // Implementation of KeyboardViewListener
-
+ // Implementation of {@link KeyboardActionListener}.
@Override
public void onCodeInput(int primaryCode, int[] keyCodes, int x, int y) {
long when = SystemClock.uptimeMillis();
@@ -1132,7 +1097,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
ic.commitText(text, 1);
ic.endBatchEdit();
mKeyboardSwitcher.updateShiftState();
- mKeyboardSwitcher.onKey(0); // dummy key code.
+ mKeyboardSwitcher.onKey(Keyboard.CODE_DUMMY);
mJustReverted = false;
mJustAddedAutoSpace = false;
mEnteredText = text;
@@ -1141,6 +1106,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override
public void onCancelInput() {
// User released a finger outside any key
+ mKeyboardSwitcher.onCancelInput();
}
private void handleBackspace() {
@@ -1486,7 +1452,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
private void showSuggestions(WordComposer word) {
- // long startTime = System.currentTimeMillis(); // TIME MEASUREMENT!
// TODO Maybe need better way of retrieving previous word
CharSequence prevWord = EditingUtils.getPreviousWord(getCurrentInputConnection(),
mWordSeparators);
@@ -1498,9 +1463,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
boolean correctionAvailable = !mInputTypeNoAutoCorrect && !mJustReverted
&& mSuggest.hasMinimalCorrection();
- CharSequence typedWord = word.getTypedWord();
+ final CharSequence typedWord = word.getTypedWord();
// If we're in basic correct
- boolean typedWordValid = mSuggest.isValidWord(typedWord) ||
+ final boolean typedWordValid = mSuggest.isValidWord(typedWord) ||
(preferCapitalization()
&& mSuggest.isValidWord(typedWord.toString().toLowerCase()));
if (mCorrectionMode == Suggest.CORRECTION_FULL
@@ -1511,7 +1476,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
correctionAvailable &= !word.isMostlyCaps();
correctionAvailable &= !TextEntryState.isCorrecting();
- if (builder.size() > 1 || mCandidateView.isShowingAddToDictionaryHint()) {
+ // Basically, we update the suggestion strip only when suggestion count > 1. However,
+ // there is an exception: We update the suggestion strip whenever typed word's length
+ // is 1, regardless of suggestion count. Actually, in most cases, suggestion count is 1
+ // when typed word's length is 1, but we do always need to clear the previous state when
+ // the user starts typing a word (i.e. typed word's length == 1).
+ if (typedWord.length() == 1 || builder.size() > 1
+ || mCandidateView.isShowingAddToDictionaryHint()) {
builder.setTypedWordValid(typedWordValid).setHasMinimalSuggestion(correctionAvailable);
} else {
final SuggestedWords previousSuggestions = mCandidateView.getSuggestions();
@@ -1588,8 +1559,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
LatinImeLogger.logOnManualSuggestion(
"", suggestion.toString(), index, suggestions.mWords);
final char primaryCode = suggestion.charAt(0);
- onCodeInput(primaryCode, new int[]{primaryCode}, KeyboardView.NOT_A_TOUCH_COORDINATE,
- KeyboardView.NOT_A_TOUCH_COORDINATE);
+ onCodeInput(primaryCode, new int[] { primaryCode },
+ KeyboardActionListener.NOT_A_TOUCH_COORDINATE,
+ KeyboardActionListener.NOT_A_TOUCH_COORDINATE);
if (ic != null) {
ic.endBatchEdit();
}
@@ -1841,7 +1813,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void sendSpace() {
sendKeyChar((char)Keyboard.CODE_SPACE);
mKeyboardSwitcher.updateShiftState();
- //onKey(KEY_SPACE[0], KEY_SPACE);
}
public boolean preferCapitalization() {
@@ -1879,7 +1850,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} else if (Settings.PREF_RECORRECTION_ENABLED.equals(key)) {
mReCorrectionEnabled = sharedPreferences.getBoolean(
Settings.PREF_RECORRECTION_ENABLED,
- getResources().getBoolean(R.bool.default_recorrection_enabled));
+ mResources.getBoolean(R.bool.default_recorrection_enabled));
}
}
@@ -2011,11 +1982,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
private void updateSuggestionVisibility(SharedPreferences prefs) {
+ final Resources res = mResources;
final String suggestionVisiblityStr = prefs.getString(
Settings.PREF_SHOW_SUGGESTIONS_SETTING,
- mResources.getString(R.string.prefs_suggestion_visibility_default_value));
+ res.getString(R.string.prefs_suggestion_visibility_default_value));
for (int visibility : SUGGESTION_VISIBILITY_VALUE_ARRAY) {
- if (suggestionVisiblityStr.equals(mResources.getString(visibility))) {
+ if (suggestionVisiblityStr.equals(res.getString(visibility))) {
mSuggestionVisibility = visibility;
break;
}
diff --git a/java/src/com/android/inputmethod/latin/LatinImeLogger.java b/java/src/com/android/inputmethod/latin/LatinImeLogger.java
index de194d21b..aaecfffdd 100644
--- a/java/src/com/android/inputmethod/latin/LatinImeLogger.java
+++ b/java/src/com/android/inputmethod/latin/LatinImeLogger.java
@@ -72,6 +72,6 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
public static void onSetKeyboard(Keyboard kb) {
}
- public static void onPrintAllUsabilityStudtyLogs() {
+ public static void onPrintAllUsabilityStudyLogs() {
}
}
diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
index 3539f9fa6..8d45d5b38 100644
--- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
+++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java
@@ -42,6 +42,7 @@ import java.util.Locale;
import java.util.Map;
public class SubtypeSwitcher {
+ // TODO: This should be configurable by resource
// This flag indicates if we support language switching by swipe on space bar.
// We may or may not draw the current language on space bar regardless of this flag.
// @@@
@@ -105,6 +106,7 @@ public class SubtypeSwitcher {
mSystemLocale = null;
mInputLocale = null;
mInputLocaleStr = null;
+ // Mode is initialized to KEYBOARD_MODE, in case that LatinIME can't obtain currentSubtype
mMode = KEYBOARD_MODE;
mAllEnabledSubtypesOfCurrentInputMethod = null;
// TODO: Voice input should be created here
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 236590284..9ea9c2f3e 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -1,12 +1,12 @@
/*
* Copyright (C) 2008 The Android Open Source Project
- *
+ *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -22,12 +22,11 @@ import android.text.TextUtils;
import android.util.Log;
import android.view.View;
-import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
/**
- * This class loads a dictionary and provides a list of suggestions for a given sequence of
+ * This class loads a dictionary and provides a list of suggestions for a given sequence of
* characters. This includes corrections and completions.
*/
public class Suggest implements Dictionary.WordCallback {
@@ -103,16 +102,11 @@ public class Suggest implements Dictionary.WordCallback {
private int mCorrectionMode = CORRECTION_BASIC;
- public Suggest(Context context, int[] dictionaryResId) {
+ public Suggest(Context context, int dictionaryResId) {
mMainDict = new BinaryDictionary(context, dictionaryResId, DIC_MAIN);
initPool();
}
- public Suggest(Context context, ByteBuffer byteBuffer) {
- mMainDict = new BinaryDictionary(context, byteBuffer, DIC_MAIN);
- initPool();
- }
-
private void initPool() {
for (int i = 0; i < mPrefMaxSuggestions; i++) {
StringBuilder sb = new StringBuilder(getApproxMaxWordLength());
@@ -154,7 +148,7 @@ public class Suggest implements Dictionary.WordCallback {
public void setContactsDictionary(Dictionary userDictionary) {
mContactsDictionary = userDictionary;
}
-
+
public void setAutoDictionary(Dictionary autoDictionary) {
mAutoDictionary = autoDictionary;
}
@@ -232,7 +226,7 @@ public class Suggest implements Dictionary.WordCallback {
if (!TextUtils.isEmpty(prevWordForBigram)) {
CharSequence lowerPrevWord = prevWordForBigram.toString().toLowerCase();
- if (mMainDict.isValidWord(lowerPrevWord)) {
+ if (mMainDict != null && mMainDict.isValidWord(lowerPrevWord)) {
prevWordForBigram = lowerPrevWord;
}
if (mUserBigramDictionary != null) {
@@ -383,7 +377,7 @@ public class Suggest implements Dictionary.WordCallback {
return mHaveCorrection;
}
- private boolean compareCaseInsensitive(final String mLowerOriginalWord,
+ private boolean compareCaseInsensitive(final String mLowerOriginalWord,
final char[] word, final int offset, final int length) {
final int originalLength = mLowerOriginalWord.length();
if (originalLength == length && Character.isUpperCase(word[offset])) {
@@ -456,7 +450,7 @@ public class Suggest implements Dictionary.WordCallback {
System.arraycopy(priorities, pos, priorities, pos + 1, prefMaxSuggestions - pos - 1);
priorities[pos] = freq;
int poolSize = mStringPool.size();
- StringBuilder sb = poolSize > 0 ? (StringBuilder) mStringPool.remove(poolSize - 1)
+ StringBuilder sb = poolSize > 0 ? (StringBuilder) mStringPool.remove(poolSize - 1)
: new StringBuilder(getApproxMaxWordLength());
sb.setLength(0);
if (mIsAllUpperCase) {
@@ -510,7 +504,7 @@ public class Suggest implements Dictionary.WordCallback {
|| (mAutoDictionary != null && mAutoDictionary.isValidWord(word))
|| (mContactsDictionary != null && mContactsDictionary.isValidWord(word));
}
-
+
private void collectGarbage(ArrayList<CharSequence> suggestions, int prefMaxSuggestions) {
int poolSize = mStringPool.size();
int garbageSize = suggestions.size();
@@ -531,6 +525,23 @@ public class Suggest implements Dictionary.WordCallback {
public void close() {
if (mMainDict != null) {
mMainDict.close();
+ mMainDict = null;
+ }
+ if (mUserDictionary != null) {
+ mUserDictionary.close();
+ mUserDictionary = null;
+ }
+ if (mUserBigramDictionary != null) {
+ mUserBigramDictionary.close();
+ mUserBigramDictionary = null;
+ }
+ if (mContactsDictionary != null) {
+ mContactsDictionary.close();
+ mContactsDictionary = null;
+ }
+ if (mAutoDictionary != null) {
+ mAutoDictionary.close();
+ mAutoDictionary = null;
}
}
}
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index 0e0cba9b3..56ad6c7aa 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -307,7 +307,7 @@ public class Utils {
break;
}
UsabilityStudyLogUtils.getInstance().write(inputChar + "\t" + x + "\t" + y);
- LatinImeLogger.onPrintAllUsabilityStudtyLogs();
+ LatinImeLogger.onPrintAllUsabilityStudyLogs();
}
public void write(final String log) {