DO NOT MERGE LocaleSpan makes Han disambiguation easy!
Cherry-pick of I7f1b0d49a2ece957a7b9b5d65d48385bf2c2a668 from master. I've also provided TextView.setTextLocale() for use in single-language TextViews. Change-Id: I5692859bfd2aafc284172454d943afc250b22535
This commit is contained in:
@@ -22503,6 +22503,17 @@ package android.text.style {
|
|||||||
method public abstract void chooseHeight(java.lang.CharSequence, int, int, int, int, android.graphics.Paint.FontMetricsInt, android.text.TextPaint);
|
method public abstract void chooseHeight(java.lang.CharSequence, int, int, int, int, android.graphics.Paint.FontMetricsInt, android.text.TextPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class LocaleSpan extends android.text.style.MetricAffectingSpan implements android.text.ParcelableSpan {
|
||||||
|
ctor public LocaleSpan(java.util.Locale);
|
||||||
|
ctor public LocaleSpan(android.os.Parcel);
|
||||||
|
method public int describeContents();
|
||||||
|
method public java.util.Locale getLocale();
|
||||||
|
method public int getSpanTypeId();
|
||||||
|
method public void updateDrawState(android.text.TextPaint);
|
||||||
|
method public void updateMeasureState(android.text.TextPaint);
|
||||||
|
method public void writeToParcel(android.os.Parcel, int);
|
||||||
|
}
|
||||||
|
|
||||||
public class MaskFilterSpan extends android.text.style.CharacterStyle implements android.text.style.UpdateAppearance {
|
public class MaskFilterSpan extends android.text.style.CharacterStyle implements android.text.style.UpdateAppearance {
|
||||||
ctor public MaskFilterSpan(android.graphics.MaskFilter);
|
ctor public MaskFilterSpan(android.graphics.MaskFilter);
|
||||||
method public android.graphics.MaskFilter getMaskFilter();
|
method public android.graphics.MaskFilter getMaskFilter();
|
||||||
@@ -29303,6 +29314,7 @@ package android.widget {
|
|||||||
method public static int getTextColor(android.content.Context, android.content.res.TypedArray, int);
|
method public static int getTextColor(android.content.Context, android.content.res.TypedArray, int);
|
||||||
method public final android.content.res.ColorStateList getTextColors();
|
method public final android.content.res.ColorStateList getTextColors();
|
||||||
method public static android.content.res.ColorStateList getTextColors(android.content.Context, android.content.res.TypedArray);
|
method public static android.content.res.ColorStateList getTextColors(android.content.Context, android.content.res.TypedArray);
|
||||||
|
method public java.util.Locale getTextLocale();
|
||||||
method public float getTextScaleX();
|
method public float getTextScaleX();
|
||||||
method public float getTextSize();
|
method public float getTextSize();
|
||||||
method public int getTotalPaddingBottom();
|
method public int getTotalPaddingBottom();
|
||||||
@@ -29405,6 +29417,7 @@ package android.widget {
|
|||||||
method public void setTextIsSelectable(boolean);
|
method public void setTextIsSelectable(boolean);
|
||||||
method public final void setTextKeepState(java.lang.CharSequence);
|
method public final void setTextKeepState(java.lang.CharSequence);
|
||||||
method public final void setTextKeepState(java.lang.CharSequence, android.widget.TextView.BufferType);
|
method public final void setTextKeepState(java.lang.CharSequence, android.widget.TextView.BufferType);
|
||||||
|
method public void setTextLocale(java.util.Locale);
|
||||||
method public void setTextScaleX(float);
|
method public void setTextScaleX(float);
|
||||||
method public void setTextSize(float);
|
method public void setTextSize(float);
|
||||||
method public void setTextSize(int, float);
|
method public void setTextSize(int, float);
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import android.text.style.CharacterStyle;
|
|||||||
import android.text.style.EasyEditSpan;
|
import android.text.style.EasyEditSpan;
|
||||||
import android.text.style.ForegroundColorSpan;
|
import android.text.style.ForegroundColorSpan;
|
||||||
import android.text.style.LeadingMarginSpan;
|
import android.text.style.LeadingMarginSpan;
|
||||||
|
import android.text.style.LocaleSpan;
|
||||||
import android.text.style.MetricAffectingSpan;
|
import android.text.style.MetricAffectingSpan;
|
||||||
import android.text.style.QuoteSpan;
|
import android.text.style.QuoteSpan;
|
||||||
import android.text.style.RelativeSizeSpan;
|
import android.text.style.RelativeSizeSpan;
|
||||||
@@ -587,6 +588,8 @@ public class TextUtils {
|
|||||||
public static final int SUGGESTION_RANGE_SPAN = 21;
|
public static final int SUGGESTION_RANGE_SPAN = 21;
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public static final int EASY_EDIT_SPAN = 22;
|
public static final int EASY_EDIT_SPAN = 22;
|
||||||
|
/** @hide */
|
||||||
|
public static final int LOCALE_SPAN = 23;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flatten a CharSequence and whatever styles can be copied across processes
|
* Flatten a CharSequence and whatever styles can be copied across processes
|
||||||
@@ -754,6 +757,10 @@ public class TextUtils {
|
|||||||
readSpan(p, sp, new EasyEditSpan());
|
readSpan(p, sp, new EasyEditSpan());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case LOCALE_SPAN:
|
||||||
|
readSpan(p, sp, new LocaleSpan(p));
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("bogus span encoding " + kind);
|
throw new RuntimeException("bogus span encoding " + kind);
|
||||||
}
|
}
|
||||||
|
|||||||
84
core/java/android/text/style/LocaleSpan.java
Normal file
84
core/java/android/text/style/LocaleSpan.java
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package android.text.style;
|
||||||
|
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.text.ParcelableSpan;
|
||||||
|
import android.text.TextPaint;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the {@link Locale} of the text to which the span is attached.
|
||||||
|
*/
|
||||||
|
public class LocaleSpan extends MetricAffectingSpan implements ParcelableSpan {
|
||||||
|
private final Locale mLocale;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a LocaleSpan.
|
||||||
|
* @param locale The {@link Locale} of the text to which the span is
|
||||||
|
* attached.
|
||||||
|
*/
|
||||||
|
public LocaleSpan(Locale locale) {
|
||||||
|
mLocale = locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocaleSpan(Parcel src) {
|
||||||
|
mLocale = new Locale(src.readString(), src.readString(), src.readString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSpanTypeId() {
|
||||||
|
return TextUtils.LOCALE_SPAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeString(mLocale.getLanguage());
|
||||||
|
dest.writeString(mLocale.getCountry());
|
||||||
|
dest.writeString(mLocale.getVariant());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@link Locale}.
|
||||||
|
*
|
||||||
|
* @return The {@link Locale} for this span.
|
||||||
|
*/
|
||||||
|
public Locale getLocale() {
|
||||||
|
return mLocale;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDrawState(TextPaint ds) {
|
||||||
|
apply(ds, mLocale);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateMeasureState(TextPaint paint) {
|
||||||
|
apply(paint, mLocale);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void apply(Paint paint, Locale locale) {
|
||||||
|
paint.setTextLocale(locale);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2202,6 +2202,27 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
|
|||||||
appearance.recycle();
|
appearance.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the default {@link Locale} of the text in this TextView.
|
||||||
|
* @return the default {@link Locale} of the text in this TextView.
|
||||||
|
*/
|
||||||
|
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.
|
||||||
|
*
|
||||||
|
* @param locale the {@link Locale} for drawing text, must not be null.
|
||||||
|
*
|
||||||
|
* @see Paint#setTextLocale
|
||||||
|
*/
|
||||||
|
public void setTextLocale(Locale locale) {
|
||||||
|
mTextPaint.setTextLocale(locale);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the size (in pixels) of the default text size in this TextView.
|
* @return the size (in pixels) of the default text size in this TextView.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user