diff options
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/settings/SdCardSettings.java | 25 | ||||
-rw-r--r-- | src/com/android/settings/deviceinfo/Memory.java | 21 |
2 files changed, 4 insertions, 42 deletions
diff --git a/src/com/android/settings/SdCardSettings.java b/src/com/android/settings/SdCardSettings.java index 6033c4296..67f3550c0 100644 --- a/src/com/android/settings/SdCardSettings.java +++ b/src/com/android/settings/SdCardSettings.java @@ -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() { diff --git a/src/com/android/settings/deviceinfo/Memory.java b/src/com/android/settings/deviceinfo/Memory.java index 75a84b719..53e2a69c9 100644 --- a/src/com/android/settings/deviceinfo/Memory.java +++ b/src/com/android/settings/deviceinfo/Memory.java @@ -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); } } |