Loading java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +24 −20 Original line number Diff line number Diff line Loading @@ -60,8 +60,11 @@ public class AndroidSpellCheckerService extends SpellCheckerService { private static final int CAPITALIZE_ALL = 2; // All caps private final static String[] EMPTY_STRING_ARRAY = new String[0]; private final static SuggestionsInfo EMPTY_SUGGESTIONS_INFO = private final static SuggestionsInfo NOT_IN_DICT_EMPTY_SUGGESTIONS = new SuggestionsInfo(0, EMPTY_STRING_ARRAY); private final static SuggestionsInfo IN_DICT_EMPTY_SUGGESTIONS = new SuggestionsInfo(SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY, EMPTY_STRING_ARRAY); private Map<String, DictionaryPool> mDictionaryPools = Collections.synchronizedMap(new TreeMap<String, DictionaryPool>()); private Map<String, Dictionary> mUserDictionaries = Loading Loading @@ -330,7 +333,12 @@ public class AndroidSpellCheckerService extends SpellCheckerService { try { final String text = textInfo.getText(); if (shouldFilterOut(text)) return EMPTY_SUGGESTIONS_INFO; if (shouldFilterOut(text)) { final DictAndProximity dictInfo = mDictionaryPool.takeOrGetNull(); if (null == dictInfo) return NOT_IN_DICT_EMPTY_SUGGESTIONS; return dictInfo.mDictionary.isValidWord(text) ? IN_DICT_EMPTY_SUGGESTIONS : NOT_IN_DICT_EMPTY_SUGGESTIONS; } final SuggestionsGatherer suggestionsGatherer = new SuggestionsGatherer(suggestionsLimit); Loading @@ -353,8 +361,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService { final int capitalizeType = getCapitalizationType(text); boolean isInDict = true; try { final DictAndProximity dictInfo = mDictionaryPool.take(); final DictAndProximity dictInfo = mDictionaryPool.takeOrGetNull(); if (null == dictInfo) return NOT_IN_DICT_EMPTY_SUGGESTIONS; dictInfo.mDictionary.getWords(composer, suggestionsGatherer, dictInfo.mProximityInfo); isInDict = dictInfo.mDictionary.isValidWord(text); Loading @@ -367,10 +375,6 @@ public class AndroidSpellCheckerService extends SpellCheckerService { if (!mDictionaryPool.offer(dictInfo)) { Log.e(TAG, "Can't re-insert a dictionary into its pool"); } } catch (InterruptedException e) { // I don't think this can happen. return EMPTY_SUGGESTIONS_INFO; } final SuggestionsGatherer.Result result = suggestionsGatherer.getResults(text, mService.mTypoThreshold, capitalizeType, mLocale); Loading @@ -396,7 +400,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService { throw e; } else { Log.e(TAG, "Exception while spellcheking: " + e); return EMPTY_SUGGESTIONS_INFO; return NOT_IN_DICT_EMPTY_SUGGESTIONS; } } } Loading java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java +9 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,15 @@ public class DictionaryPool extends LinkedBlockingQueue<DictAndProximity> { } } // Convenience method public DictAndProximity takeOrGetNull() { try { return take(); } catch (InterruptedException e) { return null; } } public void close() { synchronized(this) { mClosed = true; Loading Loading
java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +24 −20 Original line number Diff line number Diff line Loading @@ -60,8 +60,11 @@ public class AndroidSpellCheckerService extends SpellCheckerService { private static final int CAPITALIZE_ALL = 2; // All caps private final static String[] EMPTY_STRING_ARRAY = new String[0]; private final static SuggestionsInfo EMPTY_SUGGESTIONS_INFO = private final static SuggestionsInfo NOT_IN_DICT_EMPTY_SUGGESTIONS = new SuggestionsInfo(0, EMPTY_STRING_ARRAY); private final static SuggestionsInfo IN_DICT_EMPTY_SUGGESTIONS = new SuggestionsInfo(SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY, EMPTY_STRING_ARRAY); private Map<String, DictionaryPool> mDictionaryPools = Collections.synchronizedMap(new TreeMap<String, DictionaryPool>()); private Map<String, Dictionary> mUserDictionaries = Loading Loading @@ -330,7 +333,12 @@ public class AndroidSpellCheckerService extends SpellCheckerService { try { final String text = textInfo.getText(); if (shouldFilterOut(text)) return EMPTY_SUGGESTIONS_INFO; if (shouldFilterOut(text)) { final DictAndProximity dictInfo = mDictionaryPool.takeOrGetNull(); if (null == dictInfo) return NOT_IN_DICT_EMPTY_SUGGESTIONS; return dictInfo.mDictionary.isValidWord(text) ? IN_DICT_EMPTY_SUGGESTIONS : NOT_IN_DICT_EMPTY_SUGGESTIONS; } final SuggestionsGatherer suggestionsGatherer = new SuggestionsGatherer(suggestionsLimit); Loading @@ -353,8 +361,8 @@ public class AndroidSpellCheckerService extends SpellCheckerService { final int capitalizeType = getCapitalizationType(text); boolean isInDict = true; try { final DictAndProximity dictInfo = mDictionaryPool.take(); final DictAndProximity dictInfo = mDictionaryPool.takeOrGetNull(); if (null == dictInfo) return NOT_IN_DICT_EMPTY_SUGGESTIONS; dictInfo.mDictionary.getWords(composer, suggestionsGatherer, dictInfo.mProximityInfo); isInDict = dictInfo.mDictionary.isValidWord(text); Loading @@ -367,10 +375,6 @@ public class AndroidSpellCheckerService extends SpellCheckerService { if (!mDictionaryPool.offer(dictInfo)) { Log.e(TAG, "Can't re-insert a dictionary into its pool"); } } catch (InterruptedException e) { // I don't think this can happen. return EMPTY_SUGGESTIONS_INFO; } final SuggestionsGatherer.Result result = suggestionsGatherer.getResults(text, mService.mTypoThreshold, capitalizeType, mLocale); Loading @@ -396,7 +400,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService { throw e; } else { Log.e(TAG, "Exception while spellcheking: " + e); return EMPTY_SUGGESTIONS_INFO; return NOT_IN_DICT_EMPTY_SUGGESTIONS; } } } Loading
java/src/com/android/inputmethod/latin/spellcheck/DictionaryPool.java +9 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,15 @@ public class DictionaryPool extends LinkedBlockingQueue<DictAndProximity> { } } // Convenience method public DictAndProximity takeOrGetNull() { try { return take(); } catch (InterruptedException e) { return null; } } public void close() { synchronized(this) { mClosed = true; Loading