Merge "Support ellipsizing LocaleHelper.getDisplayLocaleList()" into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
fe524c0e24
@@ -67,7 +67,8 @@ public class TextUtils {
|
|||||||
private static final String TAG = "TextUtils";
|
private static final String TAG = "TextUtils";
|
||||||
|
|
||||||
/* package */ static final char[] ELLIPSIS_NORMAL = { '\u2026' }; // this is "..."
|
/* package */ static final char[] ELLIPSIS_NORMAL = { '\u2026' }; // this is "..."
|
||||||
private static final String ELLIPSIS_STRING = new String(ELLIPSIS_NORMAL);
|
/** {@hide} */
|
||||||
|
public static final String ELLIPSIS_STRING = new String(ELLIPSIS_NORMAL);
|
||||||
|
|
||||||
/* package */ static final char[] ELLIPSIS_TWO_DOTS = { '\u2025' }; // this is ".."
|
/* package */ static final char[] ELLIPSIS_TWO_DOTS = { '\u2025' }; // this is ".."
|
||||||
private static final String ELLIPSIS_TWO_DOTS_STRING = new String(ELLIPSIS_TWO_DOTS);
|
private static final String ELLIPSIS_TWO_DOTS_STRING = new String(ELLIPSIS_TWO_DOTS);
|
||||||
|
|||||||
@@ -16,9 +16,11 @@
|
|||||||
|
|
||||||
package com.android.internal.app;
|
package com.android.internal.app;
|
||||||
|
|
||||||
|
import android.annotation.IntRange;
|
||||||
import android.icu.text.ListFormatter;
|
import android.icu.text.ListFormatter;
|
||||||
import android.icu.util.ULocale;
|
import android.icu.util.ULocale;
|
||||||
import android.os.LocaleList;
|
import android.os.LocaleList;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import java.text.Collator;
|
import java.text.Collator;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@@ -153,16 +155,34 @@ public class LocaleHelper {
|
|||||||
* @param locales the list of locales whose names is to be displayed.
|
* @param locales the list of locales whose names is to be displayed.
|
||||||
* @param displayLocale the locale in which to display the names.
|
* @param displayLocale the locale in which to display the names.
|
||||||
* If this is null, it will use the default locale.
|
* If this is null, it will use the default locale.
|
||||||
|
* @param maxLocales maximum number of locales to display. Generates ellipsis after that.
|
||||||
* @return the locale aware list of locale names
|
* @return the locale aware list of locale names
|
||||||
*/
|
*/
|
||||||
public static String getDisplayLocaleList(LocaleList locales, Locale displayLocale) {
|
public static String getDisplayLocaleList(
|
||||||
|
LocaleList locales, Locale displayLocale, @IntRange(from=1) int maxLocales) {
|
||||||
|
|
||||||
final Locale dispLocale = displayLocale == null ? Locale.getDefault() : displayLocale;
|
final Locale dispLocale = displayLocale == null ? Locale.getDefault() : displayLocale;
|
||||||
|
|
||||||
int localeCount = locales.size();
|
final boolean ellipsisNeeded = locales.size() > maxLocales;
|
||||||
final String[] localeNames = new String[localeCount];
|
final int localeCount, listCount;
|
||||||
|
if (ellipsisNeeded) {
|
||||||
|
localeCount = maxLocales;
|
||||||
|
listCount = maxLocales + 1; // One extra slot for the ellipsis
|
||||||
|
} else {
|
||||||
|
listCount = localeCount = locales.size();
|
||||||
|
}
|
||||||
|
final String[] localeNames = new String[listCount];
|
||||||
for (int i = 0; i < localeCount; i++) {
|
for (int i = 0; i < localeCount; i++) {
|
||||||
localeNames[i] = LocaleHelper.getDisplayName(locales.get(i), dispLocale, false);
|
localeNames[i] = LocaleHelper.getDisplayName(locales.get(i), dispLocale, false);
|
||||||
}
|
}
|
||||||
|
if (ellipsisNeeded) {
|
||||||
|
// Theoretically, we want to extract this from ICU's Resource Bundle for
|
||||||
|
// "Ellipsis/final", which seems to have different strings than the normal ellipsis for
|
||||||
|
// Hong Kong Traditional Chinese (zh_Hant_HK) and Dzongkha (dz). But that has two
|
||||||
|
// problems: it's expensive to extract it, and in case the output string becomes
|
||||||
|
// automatically ellipsized, it can result in weird output.
|
||||||
|
localeNames[maxLocales] = TextUtils.ELLIPSIS_STRING;
|
||||||
|
}
|
||||||
|
|
||||||
ListFormatter lfn = ListFormatter.getInstance(dispLocale);
|
ListFormatter lfn = ListFormatter.getInstance(dispLocale);
|
||||||
return lfn.format((Object[]) localeNames);
|
return lfn.format((Object[]) localeNames);
|
||||||
|
|||||||
Reference in New Issue
Block a user