am a78edb54: Merge change 4127 into donut

Merge commit 'a78edb54182da5881f2f1e6bc76ae027a9a6f3e3'

* commit 'a78edb54182da5881f2f1e6bc76ae027a9a6f3e3':
  Make the SD Card settings use the system file size formatter.
This commit is contained in:
Android (Google) Code Review
2009-06-15 10:11:46 -07:00
committed by The Android Open Source Project
2 changed files with 4 additions and 42 deletions

View File

@@ -27,6 +27,7 @@ import android.os.Environment;
import android.os.IMountService;
import android.os.ServiceManager;
import android.os.StatFs;
import android.text.format.Formatter;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
@@ -146,29 +147,7 @@ public class SdCardSettings extends Activity
}
private String formatSize(long size) {
String suffix = null;
// add K or M suffix if size is greater than 1K or 1M
if (size >= 1024) {
suffix = "K";
size /= 1024;
if (size >= 1024) {
suffix = "M";
size /= 1024;
}
}
StringBuilder resultBuffer = new StringBuilder(Long.toString(size));
int commaOffset = resultBuffer.length() - 3;
while (commaOffset > 0) {
resultBuffer.insert(commaOffset, ',');
commaOffset -= 3;
}
if (suffix != null)
resultBuffer.append(suffix);
return resultBuffer.toString();
return Formatter.formatFileSize(this, size);
}
OnClickListener mMassStorageListener = new OnClickListener() {

View File

@@ -31,6 +31,7 @@ import android.os.StatFs;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.text.format.Formatter;
import android.util.Log;
import com.android.settings.R;
@@ -194,25 +195,7 @@ public class Memory extends PreferenceActivity {
}
private String formatSize(long size) {
String suffix = null;
// add KB or MB suffix if size is greater than 1K or 1M
if (size >= 1024) {
suffix = " KB";
size /= 1024;
if (size >= 1024) {
suffix = " MB";
size /= 1024;
}
}
DecimalFormat formatter = new DecimalFormat();
formatter.setGroupingSize(3);
String result = formatter.format(size);
if (suffix != null)
result = result + suffix;
return result;
return Formatter.formatFileSize(this, size);
}
}