Search in sources :

Example 11 with BytesResult

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

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 12 with BytesResult

use of android.text.format.Formatter.BytesResult in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class PublicVolumeSettings method update.

public void update() {
    if (!isVolumeValid()) {
        getActivity().finish();
        return;
    }
    getActivity().setTitle(mStorageManager.getBestVolumeDescription(mVolume));
    final Context context = getActivity();
    final PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();
    if (mVolume.isMountedReadable()) {
        addPreference(mSummary);
        final File file = mVolume.getPath();
        final long totalBytes = file.getTotalSpace();
        final long freeBytes = file.getFreeSpace();
        final long usedBytes = totalBytes - freeBytes;
        final BytesResult result = Formatter.formatBytes(getResources(), usedBytes, 0);
        mSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large), result.value, result.units));
        mSummary.setSummary(getString(R.string.storage_volume_used, Formatter.formatFileSize(context, totalBytes)));
        mSummary.setPercent((int) ((usedBytes * 100) / totalBytes));
    }
    if (mVolume.getState() == VolumeInfo.STATE_UNMOUNTED) {
        addPreference(mMount);
    }
    if (!mDisk.isNonRemovable() && mVolume.isMountedReadable()) {
        getButtonBar().setVisibility(View.VISIBLE);
    }
    addPreference(mFormatPublic);
    if (mDisk.isAdoptable() && mIsPermittedToAdopt) {
        addPreference(mFormatPrivate);
    }
}
Also used : Context(android.content.Context) PreferenceScreen(android.support.v7.preference.PreferenceScreen) BytesResult(android.text.format.Formatter.BytesResult) File(java.io.File)

Example 13 with BytesResult

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

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 14 with BytesResult

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

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