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

Commit 3c626b6c authored by Victor Chang's avatar Victor Chang
Browse files

Add ByteResult.unitsContentDescription field

Bug: 318780411
Test: m droid
Change-Id: Ied8117ca15d60a504070ddd03ee72cf6ade39a94
parent 7e3b5f57
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -56,11 +56,18 @@ public final class Formatter {
    public static class BytesResult {
        public final String value;
        public final String units;
        /**
         * Content description of the {@link #units}.
         * See {@link View#setContentDescription(CharSequence)}
         */
        public final String unitsContentDescription;
        public final long roundedBytes;

        public BytesResult(String value, String units, long roundedBytes) {
        public BytesResult(String value, String units, String unitsContentDescription,
                long roundedBytes) {
            this.value = value;
            this.units = units;
            this.unitsContentDescription = unitsContentDescription;
            this.roundedBytes = roundedBytes;
        }
    }
@@ -271,20 +278,20 @@ public final class Formatter {
        final Locale locale = res.getConfiguration().getLocales().get(0);
        final NumberFormat numberFormatter = getNumberFormatter(locale, rounded.fractionDigits);
        final String formattedNumber = numberFormatter.format(rounded.value);
        final String units;
        if (rounded.units == MeasureUnit.BYTE) {
            // ICU spells out "byte" instead of "B".
            units = getByteSuffixOverride(res);
        } else {
        // Since ICU does not give us access to the pattern, we need to extract the unit string
        // from ICU, which we do by taking out the formatted number out of the formatted string
        // and trimming the result of spaces and controls.
        final String formattedMeasure = formatMeasureShort(
                locale, numberFormatter, rounded.value, rounded.units);
        final String numberRemoved = deleteFirstFromString(formattedMeasure, formattedNumber);
            units = SPACES_AND_CONTROLS.trim(numberRemoved).toString();
        String units = SPACES_AND_CONTROLS.trim(numberRemoved).toString();
        String unitsContentDescription = units;
        if (rounded.units == MeasureUnit.BYTE) {
            // ICU spells out "byte" instead of "B".
            units = getByteSuffixOverride(res);
        }
        return new BytesResult(formattedNumber, units, rounded.roundedBytes);
        return new BytesResult(formattedNumber, units, unitsContentDescription,
                rounded.roundedBytes);
    }

    /**