|
33 | 33 | import android.graphics.Typeface; |
34 | 34 | import android.graphics.drawable.Drawable; |
35 | 35 | import android.inputmethodservice.ExtractEditText; |
36 | | -import android.os.AsyncTask; |
37 | 36 | import android.os.Bundle; |
38 | 37 | import android.os.Handler; |
39 | 38 | import android.os.Message; |
|
133 | 132 | import java.lang.ref.WeakReference; |
134 | 133 | import java.util.ArrayList; |
135 | 134 | import java.util.Locale; |
136 | | -import java.util.concurrent.locks.ReentrantLock; |
137 | 135 |
|
138 | 136 | /** |
139 | 137 | * Displays text to the user and optionally allows them to edit it. A TextView |
@@ -380,9 +378,6 @@ static class Drawables { |
380 | 378 |
|
381 | 379 | private InputFilter[] mFilters = NO_FILTERS; |
382 | 380 |
|
383 | | - private volatile Locale mCurrentTextServicesLocaleCache; |
384 | | - private final ReentrantLock mCurrentTextServicesLocaleLock = new ReentrantLock(); |
385 | | - |
386 | 381 | // It is possible to have a selection even when mEditor is null (programmatically set, like when |
387 | 382 | // a link is pressed). These highlight-related fields do not go in mEditor. |
388 | 383 | int mHighlightColor = 0x6633B5E5; |
@@ -456,8 +451,6 @@ public TextView(Context context, AttributeSet attrs, int defStyle) { |
456 | 451 | final Resources res = getResources(); |
457 | 452 | final CompatibilityInfo compat = res.getCompatibilityInfo(); |
458 | 453 |
|
459 | | - updateTextServicesLocaleAsync(); |
460 | | - |
461 | 454 | mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); |
462 | 455 | mTextPaint.density = res.getDisplayMetrics().density; |
463 | 456 | mTextPaint.setCompatibilityScaling(compat.applicationScale); |
@@ -7682,51 +7675,21 @@ boolean textCanBeSelected() { |
7682 | 7675 |
|
7683 | 7676 | /** |
7684 | 7677 | * This is a temporary method. Future versions may support multi-locale text. |
7685 | | - * Caveat: This method may not return the latest text services locale, but this should be |
7686 | | - * acceptable and it's more important to make this method asynchronous. |
7687 | 7678 | * |
7688 | 7679 | * @return The locale that should be used for a word iterator and a spell checker |
7689 | 7680 | * in this TextView, based on the current spell checker settings, |
7690 | 7681 | * the current IME's locale, or the system default locale. |
7691 | 7682 | * @hide |
7692 | 7683 | */ |
7693 | | - // TODO: Support multi-locale |
7694 | | - // TODO: Update the text services locale immediately after the keyboard locale is switched |
7695 | | - // by catching intent of keyboard switch event |
7696 | 7684 | public Locale getTextServicesLocale() { |
7697 | | - if (mCurrentTextServicesLocaleCache == null) { |
7698 | | - // If there is no cached text services locale, just return the default locale. |
7699 | | - mCurrentTextServicesLocaleCache = Locale.getDefault(); |
7700 | | - } |
7701 | | - // Start fetching the text services locale asynchronously. |
7702 | | - updateTextServicesLocaleAsync(); |
7703 | | - return mCurrentTextServicesLocaleCache; |
7704 | | - } |
7705 | | - |
7706 | | - private void updateTextServicesLocaleAsync() { |
7707 | | - AsyncTask.execute(new Runnable() { |
7708 | | - @Override |
7709 | | - public void run() { |
7710 | | - if (mCurrentTextServicesLocaleLock.tryLock()) { |
7711 | | - try { |
7712 | | - updateTextServicesLocaleLocked(); |
7713 | | - } finally { |
7714 | | - mCurrentTextServicesLocaleLock.unlock(); |
7715 | | - } |
7716 | | - } |
7717 | | - } |
7718 | | - }); |
7719 | | - } |
7720 | | - |
7721 | | - private void updateTextServicesLocaleLocked() { |
7722 | 7685 | Locale locale = Locale.getDefault(); |
7723 | 7686 | final TextServicesManager textServicesManager = (TextServicesManager) |
7724 | 7687 | mContext.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE); |
7725 | 7688 | final SpellCheckerSubtype subtype = textServicesManager.getCurrentSpellCheckerSubtype(true); |
7726 | 7689 | if (subtype != null) { |
7727 | 7690 | locale = SpellCheckerSubtype.constructLocaleFromString(subtype.getLocale()); |
7728 | 7691 | } |
7729 | | - mCurrentTextServicesLocaleCache = locale; |
| 7692 | + return locale; |
7730 | 7693 | } |
7731 | 7694 |
|
7732 | 7695 | void onLocaleChanged() { |
|
0 commit comments