DO NOT MERGE: Clear cache of the user dictionary when a word is added
This is a backport of Iec2793de3fff7bf15f68f Change-Id: If16d1c48edf084d892da722fb288e467f211b08emain
parent
86ade47236
commit
f1e13f1fb1
|
@ -16,9 +16,12 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin.spellcheck;
|
package com.android.inputmethod.latin.spellcheck;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.database.ContentObserver;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.provider.UserDictionary.Words;
|
||||||
import android.service.textservice.SpellCheckerService;
|
import android.service.textservice.SpellCheckerService;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -490,6 +493,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService
|
||||||
private final AndroidSpellCheckerService mService;
|
private final AndroidSpellCheckerService mService;
|
||||||
|
|
||||||
private final SuggestionsCache mSuggestionsCache = new SuggestionsCache();
|
private final SuggestionsCache mSuggestionsCache = new SuggestionsCache();
|
||||||
|
private final ContentObserver mObserver;
|
||||||
|
|
||||||
private static class SuggestionsParams {
|
private static class SuggestionsParams {
|
||||||
public final String[] mSuggestions;
|
public final String[] mSuggestions;
|
||||||
|
@ -516,10 +520,23 @@ public class AndroidSpellCheckerService extends SpellCheckerService
|
||||||
}
|
}
|
||||||
mUnigramSuggestionsInfoCache.put(query, new SuggestionsParams(suggestions, flags));
|
mUnigramSuggestionsInfoCache.put(query, new SuggestionsParams(suggestions, flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearCache() {
|
||||||
|
mUnigramSuggestionsInfoCache.evictAll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AndroidSpellCheckerSession(final AndroidSpellCheckerService service) {
|
AndroidSpellCheckerSession(final AndroidSpellCheckerService service) {
|
||||||
mService = service;
|
mService = service;
|
||||||
|
final ContentResolver cres = service.getContentResolver();
|
||||||
|
|
||||||
|
mObserver = new ContentObserver(null) {
|
||||||
|
@Override
|
||||||
|
public void onChange(boolean self) {
|
||||||
|
mSuggestionsCache.clearCache();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
cres.registerContentObserver(Words.CONTENT_URI, true, mObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -530,6 +547,12 @@ public class AndroidSpellCheckerService extends SpellCheckerService
|
||||||
mScript = getScriptFromLocale(mLocale);
|
mScript = getScriptFromLocale(mLocale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClose() {
|
||||||
|
final ContentResolver cres = mService.getContentResolver();
|
||||||
|
cres.unregisterContentObserver(mObserver);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns whether the code point is a letter that makes sense for the specified
|
* Returns whether the code point is a letter that makes sense for the specified
|
||||||
* locale for this spell checker.
|
* locale for this spell checker.
|
||||||
|
|
Loading…
Reference in New Issue