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);
}
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);
}
}
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);
}
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);
}
Aggregations