Merge "Fix an issue on changing the keyboard locale between spellchecking supported language to non-supported language"
This commit is contained in:
committed by
Android (Google) Code Review
commit
6d29d143d9
@@ -109,7 +109,7 @@ public class SpellChecker implements SpellCheckerSessionListener {
|
|||||||
mIds = new int[size];
|
mIds = new int[size];
|
||||||
mSpellCheckSpans = new SpellCheckSpan[size];
|
mSpellCheckSpans = new SpellCheckSpan[size];
|
||||||
|
|
||||||
setLocale(mTextView.getTextServicesLocale());
|
setLocale(mTextView.getSpellCheckerLocale());
|
||||||
|
|
||||||
mCookie = hashCode();
|
mCookie = hashCode();
|
||||||
}
|
}
|
||||||
@@ -120,6 +120,7 @@ public class SpellChecker implements SpellCheckerSessionListener {
|
|||||||
mTextServicesManager = (TextServicesManager) mTextView.getContext().
|
mTextServicesManager = (TextServicesManager) mTextView.getContext().
|
||||||
getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE);
|
getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE);
|
||||||
if (!mTextServicesManager.isSpellCheckerEnabled()
|
if (!mTextServicesManager.isSpellCheckerEnabled()
|
||||||
|
|| mCurrentLocale == null
|
||||||
|| mTextServicesManager.getCurrentSpellCheckerSubtype(true) == null) {
|
|| mTextServicesManager.getCurrentSpellCheckerSubtype(true) == null) {
|
||||||
mSpellCheckerSession = null;
|
mSpellCheckerSession = null;
|
||||||
} else {
|
} else {
|
||||||
@@ -146,8 +147,10 @@ public class SpellChecker implements SpellCheckerSessionListener {
|
|||||||
|
|
||||||
resetSession();
|
resetSession();
|
||||||
|
|
||||||
|
if (locale != null) {
|
||||||
// Change SpellParsers' wordIterator locale
|
// Change SpellParsers' wordIterator locale
|
||||||
mWordIterator = new WordIterator(locale);
|
mWordIterator = new WordIterator(locale);
|
||||||
|
}
|
||||||
|
|
||||||
// This class is the listener for locale change: warn other locale-aware objects
|
// This class is the listener for locale change: warn other locale-aware objects
|
||||||
mTextView.onLocaleChanged();
|
mTextView.onLocaleChanged();
|
||||||
@@ -222,9 +225,9 @@ public class SpellChecker implements SpellCheckerSessionListener {
|
|||||||
if (DBG) {
|
if (DBG) {
|
||||||
Log.d(TAG, "Start spell-checking: " + start + ", " + end);
|
Log.d(TAG, "Start spell-checking: " + start + ", " + end);
|
||||||
}
|
}
|
||||||
final Locale locale = mTextView.getTextServicesLocale();
|
final Locale locale = mTextView.getSpellCheckerLocale();
|
||||||
final boolean isSessionActive = isSessionActive();
|
final boolean isSessionActive = isSessionActive();
|
||||||
if (mCurrentLocale == null || (!(mCurrentLocale.equals(locale)))) {
|
if (locale == null || mCurrentLocale == null || (!(mCurrentLocale.equals(locale)))) {
|
||||||
setLocale(locale);
|
setLocale(locale);
|
||||||
// Re-check the entire text
|
// Re-check the entire text
|
||||||
start = 0;
|
start = 0;
|
||||||
|
|||||||
@@ -511,7 +511,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
|
|
||||||
private InputFilter[] mFilters = NO_FILTERS;
|
private InputFilter[] mFilters = NO_FILTERS;
|
||||||
|
|
||||||
private volatile Locale mCurrentTextServicesLocaleCache;
|
private volatile Locale mCurrentSpellCheckerLocaleCache;
|
||||||
private final ReentrantLock mCurrentTextServicesLocaleLock = new ReentrantLock();
|
private final ReentrantLock mCurrentTextServicesLocaleLock = new ReentrantLock();
|
||||||
|
|
||||||
// It is possible to have a selection even when mEditor is null (programmatically set, like when
|
// It is possible to have a selection even when mEditor is null (programmatically set, like when
|
||||||
@@ -7825,27 +7825,46 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
(isTextSelectable() && mText instanceof Spannable && isEnabled());
|
(isTextSelectable() && mText instanceof Spannable && isEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Locale getTextServicesLocale(boolean allowNullLocale) {
|
||||||
|
// Start fetching the text services locale asynchronously.
|
||||||
|
updateTextServicesLocaleAsync();
|
||||||
|
// If !allowNullLocale and there is no cached text services locale, just return the default
|
||||||
|
// locale.
|
||||||
|
return (mCurrentSpellCheckerLocaleCache == null && !allowNullLocale) ? Locale.getDefault()
|
||||||
|
: mCurrentSpellCheckerLocaleCache;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a temporary method. Future versions may support multi-locale text.
|
* This is a temporary method. Future versions may support multi-locale text.
|
||||||
* Caveat: This method may not return the latest text services locale, but this should be
|
* Caveat: This method may not return the latest text services locale, but this should be
|
||||||
* acceptable and it's more important to make this method asynchronous.
|
* acceptable and it's more important to make this method asynchronous.
|
||||||
*
|
*
|
||||||
* @return The locale that should be used for a word iterator and a spell checker
|
* @return The locale that should be used for a word iterator
|
||||||
* in this TextView, based on the current spell checker settings,
|
* in this TextView, based on the current spell checker settings,
|
||||||
* the current IME's locale, or the system default locale.
|
* the current IME's locale, or the system default locale.
|
||||||
|
* Please note that a word iterator in this TextView is different from another word iterator
|
||||||
|
* used by SpellChecker.java of TextView. This method should be used for the former.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
// TODO: Support multi-locale
|
// TODO: Support multi-locale
|
||||||
// TODO: Update the text services locale immediately after the keyboard locale is switched
|
// TODO: Update the text services locale immediately after the keyboard locale is switched
|
||||||
// by catching intent of keyboard switch event
|
// by catching intent of keyboard switch event
|
||||||
public Locale getTextServicesLocale() {
|
public Locale getTextServicesLocale() {
|
||||||
if (mCurrentTextServicesLocaleCache == null) {
|
return getTextServicesLocale(false /* allowNullLocale */);
|
||||||
// If there is no cached text services locale, just return the default locale.
|
|
||||||
mCurrentTextServicesLocaleCache = Locale.getDefault();
|
|
||||||
}
|
}
|
||||||
// Start fetching the text services locale asynchronously.
|
|
||||||
updateTextServicesLocaleAsync();
|
/**
|
||||||
return mCurrentTextServicesLocaleCache;
|
* This is a temporary method. Future versions may support multi-locale text.
|
||||||
|
* Caveat: This method may not return the latest spell checker locale, but this should be
|
||||||
|
* acceptable and it's more important to make this method asynchronous.
|
||||||
|
*
|
||||||
|
* @return The locale that should be used for a spell checker in this TextView,
|
||||||
|
* based on the current spell checker settings, the current IME's locale, or the system default
|
||||||
|
* locale.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public Locale getSpellCheckerLocale() {
|
||||||
|
return getTextServicesLocale(true /* allowNullLocale */);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTextServicesLocaleAsync() {
|
private void updateTextServicesLocaleAsync() {
|
||||||
@@ -7864,14 +7883,16 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateTextServicesLocaleLocked() {
|
private void updateTextServicesLocaleLocked() {
|
||||||
Locale locale = Locale.getDefault();
|
|
||||||
final TextServicesManager textServicesManager = (TextServicesManager)
|
final TextServicesManager textServicesManager = (TextServicesManager)
|
||||||
mContext.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE);
|
mContext.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE);
|
||||||
final SpellCheckerSubtype subtype = textServicesManager.getCurrentSpellCheckerSubtype(true);
|
final SpellCheckerSubtype subtype = textServicesManager.getCurrentSpellCheckerSubtype(true);
|
||||||
|
final Locale locale;
|
||||||
if (subtype != null) {
|
if (subtype != null) {
|
||||||
locale = SpellCheckerSubtype.constructLocaleFromString(subtype.getLocale());
|
locale = SpellCheckerSubtype.constructLocaleFromString(subtype.getLocale());
|
||||||
|
} else {
|
||||||
|
locale = null;
|
||||||
}
|
}
|
||||||
mCurrentTextServicesLocaleCache = locale;
|
mCurrentSpellCheckerLocaleCache = locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onLocaleChanged() {
|
void onLocaleChanged() {
|
||||||
|
|||||||
Reference in New Issue
Block a user