Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd87e941 authored by Roozbeh Pournader's avatar Roozbeh Pournader
Browse files

Fix and deprecate TextUtils.join(Iterable<CharSequence>).

There seems to be only one caller of this signature, and even that is
in a deprecated method, so it should be safe to deprecate this.

The new implementation uses ICU for the format string and so removes
the need for a localized string, although it's still a hack and is
probably slower. It's added here since we may actually want to clean
it up later and use it for an improved simple list formatter.

Bug: 6823087
Change-Id: I2aa1af9b170e41da840d9d7bc663df06fb96d136
parent 501b619e
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -18,7 +18,9 @@ package android.text;

import android.annotation.Nullable;
import android.content.res.Resources;
import android.icu.impl.ICUResourceBundle;
import android.icu.util.ULocale;
import android.icu.util.UResourceBundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.SystemProperties;
@@ -284,13 +286,23 @@ public class TextUtils {
    }

    /**
     * Returns list of multiple {@link CharSequence} joined into a single
     * {@link CharSequence} separated by localized delimiter such as ", ".
     * @deprecated use {@link android.icu.text.ListFormatter} instead.
     *
     * @hide
     */
    @Deprecated
    public static CharSequence join(Iterable<CharSequence> list) {
        final CharSequence delimiter = Resources.getSystem().getText(R.string.list_delimeter);
        final ICUResourceBundle icuBundle = (ICUResourceBundle) UResourceBundle.
                getBundleInstance(ICUResourceBundle.ICU_BASE_NAME);
        final String listMiddlePattern =
                icuBundle.getStringWithFallback("listPattern/standard/middle");
        // The returned pattern is something like "{0}, {1}", from which we want
        // to extract the ", " part.
        final int firstClosingBrace = listMiddlePattern.indexOf('}');
        final int lastOpeningBrace = listMiddlePattern.lastIndexOf('{');
        final CharSequence delimiter = listMiddlePattern.substring(
                firstClosingBrace+1, lastOpeningBrace);

        return join(delimiter, list);
    }

+0 −3
Original line number Diff line number Diff line
@@ -3374,9 +3374,6 @@
    <!-- Title for a dialog showing possible activities for sharing in ShareActionProvider [CHAR LIMIT=25] -->
    <string name="share_action_provider_share_with">Share with</string>

    <!-- Delimeter used between each item in a textual list; for example "Alpha, Beta". [CHAR LIMIT=3] -->
    <string name="list_delimeter">", "</string>

    <!-- STK sending DTMF, SMS, USSD, SS -->
    <string name="sending">Sending\u2026</string>

+0 −1
Original line number Diff line number Diff line
@@ -450,7 +450,6 @@
  <java-symbol type="string" name="delete" />
  <java-symbol type="string" name="deleteText" />
  <java-symbol type="string" name="grant_permissions_header_text" />
  <java-symbol type="string" name="list_delimeter" />
  <java-symbol type="string" name="menu_delete_shortcut_label" />
  <java-symbol type="string" name="menu_enter_shortcut_label" />
  <java-symbol type="string" name="menu_space_shortcut_label" />