* commit '05407e77e060e8b62a197065538e44a2b0cf8e38': Internationalize bytes and percentages.
This commit is contained in:
@@ -34,10 +34,10 @@ import android.graphics.drawable.Drawable;
|
||||
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;
|
||||
@@ -310,10 +310,12 @@ public class PowerUsageDetail extends Fragment implements Button.OnClickListener
|
||||
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;
|
||||
|
@@ -64,21 +64,4 @@ public class Utils {
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user