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

Commit 547b7439 authored by Roozbeh Pournader's avatar Roozbeh Pournader Committed by Android (Google) Code Review
Browse files

Merge "Switch to standard SI prefixes for kilobyte etc"

parents 44a3ef6e 36bd3b86
Loading
Loading
Loading
Loading
+20 −14
Original line number Diff line number Diff line
@@ -65,10 +65,16 @@ public final class Formatter {
    /**
     * Formats a content size to be in the form of bytes, kilobytes, megabytes, etc.
     *
     * If the context has a right-to-left locale, the returned string is wrapped in bidi formatting
     * characters to make sure it's displayed correctly if inserted inside a right-to-left string.
     * (This is useful in cases where the unit strings, like "MB", are left-to-right, but the
     * locale is right-to-left.)
     * <p>As of O, the prefixes are used in their standard meanings in the SI system, so kB = 1000
     * bytes, MB = 1,000,000 bytes, etc.</p>
     *
     * <p class="note">In {@link android.os.Build.VERSION_CODES#N} and earlier, powers of 1024 are
     * used instead, with KB = 1024 bytes, MB = 1,048,576 bytes, etc.</p>
     *
     * <p>If the context has a right-to-left locale, the returned string is wrapped in bidi
     * formatting characters to make sure it's displayed correctly if inserted inside a
     * right-to-left string. (This is useful in cases where the unit strings, like "MB", are
     * left-to-right, but the locale is right-to-left.)</p>
     *
     * @param context Context to use to load the localized units
     * @param sizeBytes size value to be formatted, in bytes
@@ -104,28 +110,28 @@ public final class Formatter {
        long mult = 1;
        if (result > 900) {
            suffix = com.android.internal.R.string.kilobyteShort;
            mult = TrafficStats.KB_IN_BYTES;
            result = result / 1024;
            mult = 1000;
            result = result / 1000;
        }
        if (result > 900) {
            suffix = com.android.internal.R.string.megabyteShort;
            mult = TrafficStats.MB_IN_BYTES;
            result = result / 1024;
            mult *= 1000;
            result = result / 1000;
        }
        if (result > 900) {
            suffix = com.android.internal.R.string.gigabyteShort;
            mult = TrafficStats.GB_IN_BYTES;
            result = result / 1024;
            mult *= 1000;
            result = result / 1000;
        }
        if (result > 900) {
            suffix = com.android.internal.R.string.terabyteShort;
            mult = TrafficStats.TB_IN_BYTES;
            result = result / 1024;
            mult *= 1000;
            result = result / 1000;
        }
        if (result > 900) {
            suffix = com.android.internal.R.string.petabyteShort;
            mult = TrafficStats.PB_IN_BYTES;
            result = result / 1024;
            mult *= 1000;
            result = result / 1000;
        }
        // Note we calculate the rounded long by ourselves, but still let String.format()
        // compute the rounded value. String.format("%f", 0.1) might not return "0.1" due to
+6 −4
Original line number Diff line number Diff line
@@ -20,8 +20,10 @@
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
    <!-- Suffix added to a number to signify size in bytes. -->
    <string name="byteShort">B</string>
    <!-- Suffix added to a number to signify size in kilobytes. -->
    <string name="kilobyteShort">KB</string>
    <!-- Suffix added to a number to signify size in kilobytes (1000 bytes).
        If you retain the Latin script for the localization, please use the lowercase
        'k', as it signifies 1000 bytes as opposed to 1024 bytes. -->
    <string name="kilobyteShort">kB</string>
    <!-- Suffix added to a number to signify size in megabytes. -->
    <string name="megabyteShort">MB</string>
    <!-- Suffix added to a number to signify size in gigabytes. -->
@@ -30,11 +32,11 @@
    <string name="terabyteShort">TB</string>
    <!-- Suffix added to a number to signify size in petabytes. -->
    <string name="petabyteShort">PB</string>
    <!-- Format string used to add a suffix like "KB" or "MB" to a number
    <!-- Format string used to add a suffix like "kB" or "MB" to a number
         to display a size in kilobytes, megabytes, or other size units.
         Some languages (like French) will want to add a space between
         the placeholders. -->
    <string name="fileSizeSuffix"><xliff:g id="number" example="123">%1$s</xliff:g> <xliff:g id="unit" example="KB">%2$s</xliff:g></string>
    <string name="fileSizeSuffix"><xliff:g id="number" example="123">%1$s</xliff:g> <xliff:g id="unit" example="MB">%2$s</xliff:g></string>

    <!-- [CHAR_LIMIT=10] Suffix added to signify duration in days -->
    <string name="durationDays"><xliff:g id="days">%1$d</xliff:g> days</string>