Commits

Anonymous committed f707491

Internationalize bytes and percentages.

Bug: 7545890
Change-Id: I634fafe9d61a2ebbf7a0cc56d8255457ee9fe1b2

Comments (0)

Files changed (2)

src/com/android/settings/fuelgauge/PowerUsageDetail.java

 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Process;
-import android.os.UserHandle;
 import android.preference.PreferenceActivity;
 import android.provider.Settings;
 import android.text.TextUtils;
+import android.text.format.Formatter;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
                 switch (mTypes[i]) {
                     case R.string.usage_type_data_recv:
                     case R.string.usage_type_data_send:
-                        value = Utils.formatBytes(getActivity(), mValues[i]);
+                        final long bytes = (long) (mValues[i]);
+                        value = Formatter.formatFileSize(getActivity(), bytes);
                         break;
                     case R.string.usage_type_no_coverage:
-                        value = String.format("%d%%", (int) Math.floor(mValues[i]));
+                        final int percentage = (int) Math.floor(mValues[i]);
+                        value = getActivity().getString(R.string.percentage, percentage);
                         break;
                     case R.string.usage_type_gps:
                         mUsesGps = true;

src/com/android/settings/fuelgauge/Utils.java

         }
         return sb.toString();
     }
-
-    /**
-     * Formats data size in KB, MB, from the given bytes.
-     * @param context the application context
-     * @param bytes data size in bytes
-     * @return the formatted size such as 4.52 MB or 245 KB or 332 bytes
-     */
-    public static String formatBytes(Context context, double bytes) {
-        // TODO: I18N
-        if (bytes > 1000 * 1000) {
-            return String.format("%.2f MB", ((int) (bytes / 1000)) / 1000f);
-        } else if (bytes > 1024) {
-            return String.format("%.2f KB", ((int) (bytes / 10)) / 100f);
-        } else {
-            return String.format("%d bytes", (int) bytes);
-        }
-    }
 }