Loading core/java/android/widget/TextView.java +38 −1 Original line number Original line Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.graphics.RectF; import android.graphics.Typeface; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable; import android.inputmethodservice.ExtractEditText; import android.inputmethodservice.ExtractEditText; import android.os.AsyncTask; import android.os.Bundle; import android.os.Bundle; import android.os.Handler; import android.os.Handler; import android.os.Message; import android.os.Message; Loading Loading @@ -132,6 +133,7 @@ import java.io.IOException; import java.lang.ref.WeakReference; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.ArrayList; import java.util.Locale; import java.util.Locale; import java.util.concurrent.locks.ReentrantLock; /** /** * Displays text to the user and optionally allows them to edit it. A TextView * Displays text to the user and optionally allows them to edit it. A TextView Loading Loading @@ -378,6 +380,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener private InputFilter[] mFilters = NO_FILTERS; private InputFilter[] mFilters = NO_FILTERS; private volatile Locale mCurrentTextServicesLocaleCache; 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 // a link is pressed). These highlight-related fields do not go in mEditor. // a link is pressed). These highlight-related fields do not go in mEditor. int mHighlightColor = 0x6633B5E5; int mHighlightColor = 0x6633B5E5; Loading Loading @@ -451,6 +456,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener final Resources res = getResources(); final Resources res = getResources(); final CompatibilityInfo compat = res.getCompatibilityInfo(); final CompatibilityInfo compat = res.getCompatibilityInfo(); updateTextServicesLocaleAsync(); mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); mTextPaint.density = res.getDisplayMetrics().density; mTextPaint.density = res.getDisplayMetrics().density; mTextPaint.setCompatibilityScaling(compat.applicationScale); mTextPaint.setCompatibilityScaling(compat.applicationScale); Loading Loading @@ -7675,13 +7682,43 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener /** /** * 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 * 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 and a spell checker * 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. * @hide * @hide */ */ // TODO: Support multi-locale // TODO: Update the text services locale immediately after the keyboard locale is switched // by catching intent of keyboard switch event public Locale getTextServicesLocale() { public Locale getTextServicesLocale() { if (mCurrentTextServicesLocaleCache == null) { // 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; } private void updateTextServicesLocaleAsync() { AsyncTask.execute(new Runnable() { @Override public void run() { if (mCurrentTextServicesLocaleLock.tryLock()) { try { updateTextServicesLocaleLocked(); } finally { mCurrentTextServicesLocaleLock.unlock(); } } } }); } private void updateTextServicesLocaleLocked() { Locale locale = Locale.getDefault(); 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); Loading @@ -7689,7 +7726,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (subtype != null) { if (subtype != null) { locale = SpellCheckerSubtype.constructLocaleFromString(subtype.getLocale()); locale = SpellCheckerSubtype.constructLocaleFromString(subtype.getLocale()); } } return locale; mCurrentTextServicesLocaleCache = locale; } } void onLocaleChanged() { void onLocaleChanged() { Loading Loading
core/java/android/widget/TextView.java +38 −1 Original line number Original line Diff line number Diff line Loading @@ -33,6 +33,7 @@ import android.graphics.RectF; import android.graphics.Typeface; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable; import android.inputmethodservice.ExtractEditText; import android.inputmethodservice.ExtractEditText; import android.os.AsyncTask; import android.os.Bundle; import android.os.Bundle; import android.os.Handler; import android.os.Handler; import android.os.Message; import android.os.Message; Loading Loading @@ -132,6 +133,7 @@ import java.io.IOException; import java.lang.ref.WeakReference; import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.ArrayList; import java.util.Locale; import java.util.Locale; import java.util.concurrent.locks.ReentrantLock; /** /** * Displays text to the user and optionally allows them to edit it. A TextView * Displays text to the user and optionally allows them to edit it. A TextView Loading Loading @@ -378,6 +380,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener private InputFilter[] mFilters = NO_FILTERS; private InputFilter[] mFilters = NO_FILTERS; private volatile Locale mCurrentTextServicesLocaleCache; 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 // a link is pressed). These highlight-related fields do not go in mEditor. // a link is pressed). These highlight-related fields do not go in mEditor. int mHighlightColor = 0x6633B5E5; int mHighlightColor = 0x6633B5E5; Loading Loading @@ -451,6 +456,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener final Resources res = getResources(); final Resources res = getResources(); final CompatibilityInfo compat = res.getCompatibilityInfo(); final CompatibilityInfo compat = res.getCompatibilityInfo(); updateTextServicesLocaleAsync(); mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); mTextPaint.density = res.getDisplayMetrics().density; mTextPaint.density = res.getDisplayMetrics().density; mTextPaint.setCompatibilityScaling(compat.applicationScale); mTextPaint.setCompatibilityScaling(compat.applicationScale); Loading Loading @@ -7675,13 +7682,43 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener /** /** * 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 * 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 and a spell checker * 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. * @hide * @hide */ */ // TODO: Support multi-locale // TODO: Update the text services locale immediately after the keyboard locale is switched // by catching intent of keyboard switch event public Locale getTextServicesLocale() { public Locale getTextServicesLocale() { if (mCurrentTextServicesLocaleCache == null) { // 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; } private void updateTextServicesLocaleAsync() { AsyncTask.execute(new Runnable() { @Override public void run() { if (mCurrentTextServicesLocaleLock.tryLock()) { try { updateTextServicesLocaleLocked(); } finally { mCurrentTextServicesLocaleLock.unlock(); } } } }); } private void updateTextServicesLocaleLocked() { Locale locale = Locale.getDefault(); 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); Loading @@ -7689,7 +7726,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (subtype != null) { if (subtype != null) { locale = SpellCheckerSubtype.constructLocaleFromString(subtype.getLocale()); locale = SpellCheckerSubtype.constructLocaleFromString(subtype.getLocale()); } } return locale; mCurrentTextServicesLocaleCache = locale; } } void onLocaleChanged() { void onLocaleChanged() { Loading