diff options
| author | Roozbeh Pournader <roozbeh@google.com> | 2015-09-01 21:14:11 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-09-01 21:14:11 +0000 |
| commit | 008d6d034ea68a7ccc5b7c454f642fcaaf9dc2cb (patch) | |
| tree | f29dff4272ddc12266117b31f8643b8646aebde2 /core/java/android | |
| parent | 6b49d300346d130d2681cbd3de7165989c3a33f2 (diff) | |
| parent | a23748a9ff9ddc8b490fc31752afa9b955d5e156 (diff) | |
Merge "Add LocaleList support to Paint and TextView."
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/util/LocaleList.java | 22 | ||||
| -rw-r--r-- | core/java/android/widget/TextView.java | 50 |
2 files changed, 61 insertions, 11 deletions
diff --git a/core/java/android/util/LocaleList.java b/core/java/android/util/LocaleList.java index afae9aceda17..379651ef86f8 100644 --- a/core/java/android/util/LocaleList.java +++ b/core/java/android/util/LocaleList.java @@ -16,7 +16,11 @@ package android.util; +import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.Size; + +import com.android.internal.annotations.GuardedBy; import java.util.HashSet; import java.util.Locale; @@ -164,4 +168,22 @@ public final class LocaleList { return new LocaleList(localeArray); } } + + private final static Object sLock = new Object(); + + @GuardedBy("sLock") + private static LocaleList sDefaultLocaleList; + + // TODO: fix this to return the default system locale list once we have that + @NonNull @Size(min=1) + public static LocaleList getDefault() { + Locale defaultLocale = Locale.getDefault(); + synchronized (sLock) { + if (sDefaultLocaleList == null || sDefaultLocaleList.size() != 1 + || !defaultLocale.equals(sDefaultLocaleList.getPrimary())) { + sDefaultLocaleList = new LocaleList(defaultLocale); + } + } + return sDefaultLocaleList; + } } diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 7a6437724e2f..61402abcece7 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -21,6 +21,7 @@ import android.annotation.ColorInt; import android.annotation.DrawableRes; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.Size; import android.annotation.StringRes; import android.annotation.StyleRes; import android.annotation.XmlRes; @@ -103,6 +104,7 @@ import android.text.style.URLSpan; import android.text.style.UpdateAppearance; import android.text.util.Linkify; import android.util.AttributeSet; +import android.util.LocaleList; import android.util.Log; import android.util.TypedValue; import android.view.AccessibilityIterators.TextSegmentIterator; @@ -553,7 +555,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener private final TextPaint mTextPaint; private boolean mUserSetTextScaleX; private Layout mLayout; - private boolean mLocaleChanged = false; + private boolean mLocalesChanged = false; @ViewDebug.ExportedProperty(category = "text") private int mGravity = Gravity.TOP | Gravity.START; @@ -2817,32 +2819,58 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } /** - * Get the default {@link Locale} of the text in this TextView. - * @return the default {@link Locale} of the text in this TextView. + * Get the default primary {@link Locale} of the text in this TextView. This will always be + * the first member of {@link #getTextLocales()}. + * @return the default primary {@link Locale} of the text in this TextView. */ + @NonNull public Locale getTextLocale() { return mTextPaint.getTextLocale(); } /** - * Set the default {@link Locale} of the text in this TextView to the given value. This value - * is used to choose appropriate typefaces for ambiguous characters. Typically used for CJK - * locales to disambiguate Hanzi/Kanji/Hanja characters. + * Get the default {@link LocaleList} of the text in this TextView. + * @return the default {@link LocaleList} of the text in this TextView. + */ + @NonNull @Size(min=1) + public LocaleList getTextLocales() { + return mTextPaint.getTextLocales(); + } + + /** + * Set the default {@link LocaleList} of the text in this TextView to a one-member list + * containing just the given value. * * @param locale the {@link Locale} for drawing text, must not be null. * - * @see Paint#setTextLocale + * @see #setTextLocales */ - public void setTextLocale(Locale locale) { - mLocaleChanged = true; + public void setTextLocale(@NonNull Locale locale) { + mLocalesChanged = true; mTextPaint.setTextLocale(locale); } + /** + * Set the default {@link LocaleList} of the text in this TextView to the given value. + * + * This value is used to choose appropriate typefaces for ambiguous characters (typically used + * for CJK locales to disambiguate Hanzi/Kanji/Hanja characters). It also affects + * other aspects of text display, including line breaking. + * + * @param locales the {@link LocaleList} for drawing text, must not be null or empty. + * + * @see Paint#setTextLocales + */ + public void setTextLocales(@NonNull @Size(min=1) LocaleList locales) { + mLocalesChanged = true; + mTextPaint.setTextLocales(locales); + } + @Override protected void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); - if (!mLocaleChanged) { - mTextPaint.setTextLocale(Locale.getDefault()); + if (!mLocalesChanged) { + mTextPaint.setTextLocales(LocaleList.getDefault()); } } |
