Search in sources :

Example 6 with BytesResult

use of android.text.format.Formatter.BytesResult in project android_frameworks_base by DirtyUnicorns.

the class FormatterTest method testFormatBytes.

@SmallTest
public void testFormatBytes() {
    setLocale(Locale.ENGLISH);
    checkFormatBytes(0, true, "0", 0);
    checkFormatBytes(0, false, "0", 0);
    checkFormatBytes(1, true, "1", 1);
    checkFormatBytes(1, false, "1", 1);
    checkFormatBytes(12, true, "12", 12);
    checkFormatBytes(12, false, "12", 12);
    checkFormatBytes(123, true, "123", 123);
    checkFormatBytes(123, false, "123", 123);
    checkFormatBytes(812, true, "812", 812);
    checkFormatBytes(812, false, "812", 812);
    checkFormatBytes(912, true, "0.89", 911);
    checkFormatBytes(912, false, "0.89", 911);
    checkFormatBytes(9123, true, "8.9", 9113);
    checkFormatBytes(9123, false, "8.91", 9123);
    checkFormatBytes(9123000, true, "8.7", 9122611);
    checkFormatBytes(9123000, false, "8.70", 9122611);
    checkFormatBytes(-1, true, "-1", -1);
    checkFormatBytes(-1, false, "-1", -1);
    checkFormatBytes(-912, true, "-0.89", -911);
    checkFormatBytes(-912, false, "-0.89", -911);
    // Missing FLAG_CALCULATE_ROUNDED case.
    BytesResult r = Formatter.formatBytes(getContext().getResources(), 1, 0);
    assertEquals("1", r.value);
    // Didn't pass FLAG_CALCULATE_ROUNDED
    assertEquals(0, r.roundedBytes);
    // Make sure it works on different locales.
    setLocale(new Locale("es", "ES"));
    checkFormatBytes(9123000, false, "8,70", 9122611);
}
Also used : Locale(java.util.Locale) BytesResult(android.text.format.Formatter.BytesResult) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 7 with BytesResult

use of android.text.format.Formatter.BytesResult in project android_frameworks_base by crdroidandroid.

the class FormatterTest method checkFormatBytes.

private void checkFormatBytes(long bytes, boolean useShort, String expectedString, long expectedRounded) {
    BytesResult r = Formatter.formatBytes(getContext().getResources(), bytes, Formatter.FLAG_CALCULATE_ROUNDED | (useShort ? Formatter.FLAG_SHORTER : 0));
    assertEquals(expectedString, r.value);
    assertEquals(expectedRounded, r.roundedBytes);
}
Also used : BytesResult(android.text.format.Formatter.BytesResult)

Example 8 with BytesResult

use of android.text.format.Formatter.BytesResult in project android_frameworks_base by AOSPA.

the class FormatterTest method testFormatBytes.

@SmallTest
public void testFormatBytes() {
    setLocale(Locale.ENGLISH);
    checkFormatBytes(0, true, "0", 0);
    checkFormatBytes(0, false, "0", 0);
    checkFormatBytes(1, true, "1", 1);
    checkFormatBytes(1, false, "1", 1);
    checkFormatBytes(12, true, "12", 12);
    checkFormatBytes(12, false, "12", 12);
    checkFormatBytes(123, true, "123", 123);
    checkFormatBytes(123, false, "123", 123);
    checkFormatBytes(812, true, "812", 812);
    checkFormatBytes(812, false, "812", 812);
    checkFormatBytes(912, true, "0.89", 911);
    checkFormatBytes(912, false, "0.89", 911);
    checkFormatBytes(9123, true, "8.9", 9113);
    checkFormatBytes(9123, false, "8.91", 9123);
    checkFormatBytes(9123000, true, "8.7", 9122611);
    checkFormatBytes(9123000, false, "8.70", 9122611);
    checkFormatBytes(-1, true, "-1", -1);
    checkFormatBytes(-1, false, "-1", -1);
    checkFormatBytes(-912, true, "-0.89", -911);
    checkFormatBytes(-912, false, "-0.89", -911);
    // Missing FLAG_CALCULATE_ROUNDED case.
    BytesResult r = Formatter.formatBytes(getContext().getResources(), 1, 0);
    assertEquals("1", r.value);
    // Didn't pass FLAG_CALCULATE_ROUNDED
    assertEquals(0, r.roundedBytes);
    // Make sure it works on different locales.
    setLocale(new Locale("es", "ES"));
    checkFormatBytes(9123000, false, "8,70", 9122611);
}
Also used : Locale(java.util.Locale) BytesResult(android.text.format.Formatter.BytesResult) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 9 with BytesResult

use of android.text.format.Formatter.BytesResult in project platform_frameworks_base by android.

the class FormatterTest method checkFormatBytes.

private void checkFormatBytes(long bytes, boolean useShort, String expectedString, long expectedRounded) {
    BytesResult r = Formatter.formatBytes(getContext().getResources(), bytes, Formatter.FLAG_CALCULATE_ROUNDED | (useShort ? Formatter.FLAG_SHORTER : 0));
    assertEquals(expectedString, r.value);
    assertEquals(expectedRounded, r.roundedBytes);
}
Also used : BytesResult(android.text.format.Formatter.BytesResult)

Example 10 with BytesResult

use of android.text.format.Formatter.BytesResult in project platform_frameworks_base by android.

the class FormatterTest method testFormatBytes.

@SmallTest
public void testFormatBytes() {
    setLocale(Locale.ENGLISH);
    checkFormatBytes(0, true, "0", 0);
    checkFormatBytes(0, false, "0", 0);
    checkFormatBytes(1, true, "1", 1);
    checkFormatBytes(1, false, "1", 1);
    checkFormatBytes(12, true, "12", 12);
    checkFormatBytes(12, false, "12", 12);
    checkFormatBytes(123, true, "123", 123);
    checkFormatBytes(123, false, "123", 123);
    checkFormatBytes(812, true, "812", 812);
    checkFormatBytes(812, false, "812", 812);
    checkFormatBytes(912, true, "0.89", 911);
    checkFormatBytes(912, false, "0.89", 911);
    checkFormatBytes(9123, true, "8.9", 9113);
    checkFormatBytes(9123, false, "8.91", 9123);
    checkFormatBytes(9123000, true, "8.7", 9122611);
    checkFormatBytes(9123000, false, "8.70", 9122611);
    checkFormatBytes(-1, true, "-1", -1);
    checkFormatBytes(-1, false, "-1", -1);
    checkFormatBytes(-912, true, "-0.89", -911);
    checkFormatBytes(-912, false, "-0.89", -911);
    // Missing FLAG_CALCULATE_ROUNDED case.
    BytesResult r = Formatter.formatBytes(getContext().getResources(), 1, 0);
    assertEquals("1", r.value);
    // Didn't pass FLAG_CALCULATE_ROUNDED
    assertEquals(0, r.roundedBytes);
    // Make sure it works on different locales.
    setLocale(new Locale("es", "ES"));
    checkFormatBytes(9123000, false, "8,70", 9122611);
}
Also used : Locale(java.util.Locale) BytesResult(android.text.format.Formatter.BytesResult) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

BytesResult (android.text.format.Formatter.BytesResult)14 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 Locale (java.util.Locale)5 Context (android.content.Context)4 PreferenceScreen (android.support.v7.preference.PreferenceScreen)2 File (java.io.File)2 Intent (android.content.Intent)1 UserInfo (android.content.pm.UserInfo)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 DiskInfo (android.os.storage.DiskInfo)1 VolumeInfo (android.os.storage.VolumeInfo)1 VolumeRecord (android.os.storage.VolumeRecord)1 Preference (android.support.v7.preference.Preference)1 PreferenceGroup (android.support.v7.preference.PreferenceGroup)1 MemInfo (com.android.settings.applications.ProcStatsData.MemInfo)1