Skip to content

Commit 1a5f387

Browse files
Ken WakasaAndroid (Google) Code Review
authored andcommitted
Merge "Revert "Don't update the text services locale in the main thread"" into jb-mr1-dev
2 parents ba683ef + 72fa0b3 commit 1a5f387

File tree

1 file changed

+1
-38
lines changed

1 file changed

+1
-38
lines changed

core/java/android/widget/TextView.java

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import android.graphics.Typeface;
3434
import android.graphics.drawable.Drawable;
3535
import android.inputmethodservice.ExtractEditText;
36-
import android.os.AsyncTask;
3736
import android.os.Bundle;
3837
import android.os.Handler;
3938
import android.os.Message;
@@ -133,7 +132,6 @@
133132
import java.lang.ref.WeakReference;
134133
import java.util.ArrayList;
135134
import java.util.Locale;
136-
import java.util.concurrent.locks.ReentrantLock;
137135

138136
/**
139137
* Displays text to the user and optionally allows them to edit it. A TextView
@@ -380,9 +378,6 @@ static class Drawables {
380378

381379
private InputFilter[] mFilters = NO_FILTERS;
382380

383-
private volatile Locale mCurrentTextServicesLocaleCache;
384-
private final ReentrantLock mCurrentTextServicesLocaleLock = new ReentrantLock();
385-
386381
// It is possible to have a selection even when mEditor is null (programmatically set, like when
387382
// a link is pressed). These highlight-related fields do not go in mEditor.
388383
int mHighlightColor = 0x6633B5E5;
@@ -456,8 +451,6 @@ public TextView(Context context, AttributeSet attrs, int defStyle) {
456451
final Resources res = getResources();
457452
final CompatibilityInfo compat = res.getCompatibilityInfo();
458453

459-
updateTextServicesLocaleAsync();
460-
461454
mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
462455
mTextPaint.density = res.getDisplayMetrics().density;
463456
mTextPaint.setCompatibilityScaling(compat.applicationScale);
@@ -7682,51 +7675,21 @@ boolean textCanBeSelected() {
76827675

76837676
/**
76847677
* 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.
76877678
*
76887679
* @return The locale that should be used for a word iterator and a spell checker
76897680
* in this TextView, based on the current spell checker settings,
76907681
* the current IME's locale, or the system default locale.
76917682
* @hide
76927683
*/
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
76967684
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() {
77227685
Locale locale = Locale.getDefault();
77237686
final TextServicesManager textServicesManager = (TextServicesManager)
77247687
mContext.getSystemService(Context.TEXT_SERVICES_MANAGER_SERVICE);
77257688
final SpellCheckerSubtype subtype = textServicesManager.getCurrentSpellCheckerSubtype(true);
77267689
if (subtype != null) {
77277690
locale = SpellCheckerSubtype.constructLocaleFromString(subtype.getLocale());
77287691
}
7729-
mCurrentTextServicesLocaleCache = locale;
7692+
return locale;
77307693
}
77317694

77327695
void onLocaleChanged() {

0 commit comments

Comments
 (0)