You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/**151 * Creates a new {@link LocaleList}.152 *153 * <p>For empty lists of {@link Locale} items it is better to use {@link #getEmptyLocaleList()},154 * which returns a pre-constructed empty list.</p>155 *156 * @throws NullPointerException if any of the input locales is <code>null</code>.157 * @throws IllegalArgumentException if any of the input locales repeat.158 */159publicLocaleList(@NonNullLocale... list) {
160if (list.length == 0) {
161mList = sEmptyList;
162mStringRepresentation = "";
163 } else {
164finalLocale[] localeList = newLocale[list.length];
165finalHashSet<Locale> seenLocales = newHashSet<Locale>();
166finalStringBuildersb = newStringBuilder();
167for (inti = 0; i < list.length; i++) {
168finalLocalel = list[i];
169if (l == null) {
170thrownewNullPointerException("list[" + i + "] is null");
171 } elseif (seenLocales.contains(l)) {
172thrownewIllegalArgumentException("list[" + i + "] is a repetition");
173 } else {
174finalLocalelocaleClone = (Locale) l.clone();
175localeList[i] = localeClone;
176sb.append(localeClone.toLanguageTag());
177if (i < list.length - 1) {
178sb.append(',');
179 }
180seenLocales.add(localeClone);
181 }
182 }
183mList = localeList;
184mStringRepresentation = sb.toString();
185 }
186 }
これで、重複するLanguageTagならどうなんだろう?
IllegalArgumentExceptionでました。そりゃそうですよね。
/**259 * Generates a new LocaleList with the given language tags.260 *261 * @param list The language tags to be included as a single {@link String} separated by commas.262 * @return A new instance with the {@link Locale} items identified by the given tags.263 */264@NonNull265publicstaticLocaleListforLanguageTags(@NullableStringlist) {
266if (list == null || list.equals("")) {
267returngetEmptyLocaleList();
268 } else {
269finalString[] tags = list.split(",");
270finalLocale[] localeArray = newLocale[tags.length];
271for (inti = 0; i < localeArray.length; i++) {
272localeArray[i] = Locale.forLanguageTag(tags[i]);
273 }
274returnnewLocaleList(localeArray);
275 }
276 }
2877/**2878 * Get the default {@link LocaleList} of the text in this TextView.2879 * @return the default {@link LocaleList} of the text in this TextView.2880 */2881@NonNull@Size(min=1)
2882publicLocaleListgetTextLocales() {
2883returnmTextPaint.getTextLocales();
2884 }
TextView(2/2)
TextViewに対して、Drawする際のLocaleListを指定できたりする模様。
PaintクラスでもsetTextLocalesを読んでいるので、そちらにまで行ってみます。
/**2905 * Set the default {@link LocaleList} of the text in this TextView to the given value.2906 *2907 * This value is used to choose appropriate typefaces for ambiguous characters (typically used2908 * for CJK locales to disambiguate Hanzi/Kanji/Hanja characters). It also affects2909 * other aspects of text display, including line breaking.2910 *2911 * @param locales the {@link LocaleList} for drawing text, must not be null or empty.2912 *2913 * @see Paint#setTextLocales2914 */2915publicvoidsetTextLocales(@NonNull@Size(min=1) LocaleListlocales) {
2916mLocalesChanged = true;
2917mTextPaint.setTextLocales(locales);
2918if (mLayout != null) {
2919nullLayouts();
2920requestLayout();
2921invalidate();
2922 }
2923 }
29242925@Override2926protectedvoidonConfigurationChanged(ConfigurationnewConfig) {
2927super.onConfigurationChanged(newConfig);
2928if (!mLocalesChanged) {
2929mTextPaint.setTextLocales(LocaleList.getDefault());
2930if (mLayout != null) {
2931nullLayouts();
2932requestLayout();
2933invalidate();
2934 }
2935 }
2936 }
2937
Paint
LocaleListに中国語が含まれていたら、中華フォントでレンダリングすると。
日本語が含まれていたら、日本語でレンダリングすると。
どっちもあったらその順番でどっちのフォントでレンダリングするか決めると。
/**1331 * Set the text locale list.1332 *1333 * The text locale list affects how the text is drawn for some languages.1334 *1335 * For example, if the locale list contains {@link Locale#CHINESE} or {@link Locale#CHINA},1336 * then the text renderer will prefer to draw text using a Chinese font. Likewise,1337 * if the locale list contains {@link Locale#JAPANESE} or {@link Locale#JAPAN}, then the text1338 * renderer will prefer to draw text using a Japanese font. If the locale list contains both,1339 * the order those locales appear in the list is considered for deciding the font.1340 *1341 * This distinction is important because Chinese and Japanese text both use many1342 * of the same Unicode code points but their appearance is subtly different for1343 * each language.1344 *1345 * By default, the text locale list is initialized to a one-member list just containing the1346 * system locales. This assumes that the text to be rendered will most likely be in the user's1347 * preferred language.1348 *1349 * If the actual language or languages of the text is/are known, then they can be provided to1350 * the text renderer using this method. The text renderer may attempt to guess the1351 * language script based on the contents of the text to be drawn independent of1352 * the text locale here. Specifying the text locales just helps it do a better1353 * job in certain ambiguous cases.1354 *1355 * @param locales the paint's locale list for drawing text, must not be null or empty.1356 */1357publicvoidsetTextLocales(@NonNull@Size(min=1) LocaleListlocales) {
1358if (locales == null || locales.isEmpty()) {
1359thrownewIllegalArgumentException("locales cannot be null or empty");
1360 }
1361if (locales.equals(mLocales)) return;
1362mLocales = locales;
1363syncTextLocalesWithMinikin();
1364 }
13651366privatevoidsyncTextLocalesWithMinikin() {
1367finalStringlanguageTags = mLocales.toLanguageTags();
1368finalIntegerminikinLangListId;
1369synchronized (sCacheLock) {
1370minikinLangListId = sMinikinLangListIdCache.get(languageTags);
1371if (minikinLangListId == null) {
1372finalintnewID = nSetTextLocales(mNativePaint, languageTags);
1373sMinikinLangListIdCache.put(languageTags, newID);
1374return;
1375 }
1376 }
1377nSetTextLocalesByMinikinLangListId(mNativePaint, minikinLangListId.intValue());
1378 }