summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuK1337 <priv.luk@gmail.com>2019-08-23 13:03:32 (GMT)
committerLuK1337 <priv.luk@gmail.com>2019-08-23 13:39:11 (GMT)
commit10464b98a3b4cb9d3f6c44a5d8ad05ca04d9d367 (patch)
tree2feb2e1cb98486256a1dbc50fcbd00aca2622c3e
parent42e8dd74cc067f3fb25572446e657fd8dc9d7436 (diff)
downloadframeworks_base-10464b98a3b4cb9d3f6c44a5d8ad05ca04d9d367.zip
frameworks_base-10464b98a3b4cb9d3f6c44a5d8ad05ca04d9d367.tar.gz
frameworks_base-10464b98a3b4cb9d3f6c44a5d8ad05ca04d9d367.tar.bz2
SystemUI: Use matching data usage size formatting between QS and Settings
* Fixes : https://gitlab.com/LineageOS/issues/android/issues/1102 Change-Id: Ie80e19de758f599b1fdedb6d991cbdd86e4f2a47
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/tiles/DataUsageDetailView.java39
1 files changed, 14 insertions, 25 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/DataUsageDetailView.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/DataUsageDetailView.java
index 2b5ef36..c2840cf 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/DataUsageDetailView.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/DataUsageDetailView.java
@@ -20,6 +20,9 @@ import android.annotation.ColorInt;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
+import android.text.BidiFormatter;
+import android.text.format.Formatter;
+import android.text.format.Formatter.BytesResult;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
@@ -38,10 +41,6 @@ import java.text.DecimalFormat;
*/
public class DataUsageDetailView extends LinearLayout {
- private static final double KB = 1000;
- private static final double MB = 1000 * KB;
- private static final double GB = 1000 * MB;
-
private final DecimalFormat FORMAT = new DecimalFormat("#.##");
public DataUsageDetailView(Context context, AttributeSet attrs) {
@@ -74,23 +73,23 @@ public class DataUsageDetailView extends LinearLayout {
titleId = R.string.quick_settings_cellular_detail_data_usage;
bytes = info.usageLevel;
top = res.getString(R.string.quick_settings_cellular_detail_data_warning,
- formatBytes(info.warningLevel));
+ formatDataUsage(info.warningLevel));
} else if (info.usageLevel <= info.limitLevel) {
// over warning, under limit
titleId = R.string.quick_settings_cellular_detail_remaining_data;
bytes = info.limitLevel - info.usageLevel;
top = res.getString(R.string.quick_settings_cellular_detail_data_used,
- formatBytes(info.usageLevel));
+ formatDataUsage(info.usageLevel));
bottom = res.getString(R.string.quick_settings_cellular_detail_data_limit,
- formatBytes(info.limitLevel));
+ formatDataUsage(info.limitLevel));
} else {
// over limit
titleId = R.string.quick_settings_cellular_detail_over_limit;
bytes = info.usageLevel - info.limitLevel;
top = res.getString(R.string.quick_settings_cellular_detail_data_used,
- formatBytes(info.usageLevel));
+ formatDataUsage(info.usageLevel));
bottom = res.getString(R.string.quick_settings_cellular_detail_data_limit,
- formatBytes(info.limitLevel));
+ formatDataUsage(info.limitLevel));
usageColor = Utils.getColorAttr(mContext, android.R.attr.colorError);
}
@@ -101,7 +100,7 @@ public class DataUsageDetailView extends LinearLayout {
final TextView title = findViewById(android.R.id.title);
title.setText(titleId);
final TextView usage = findViewById(R.id.usage_text);
- usage.setText(formatBytes(bytes));
+ usage.setText(formatDataUsage(bytes));
usage.setTextColor(usageColor);
final DataUsageGraph graph = findViewById(R.id.usage_graph);
graph.setLevels(info.limitLevel, info.warningLevel, info.usageLevel);
@@ -123,20 +122,10 @@ public class DataUsageDetailView extends LinearLayout {
}
- private String formatBytes(long bytes) {
- final long b = Math.abs(bytes);
- double val;
- String suffix;
- if (b > 100 * MB) {
- val = b / GB;
- suffix = "GB";
- } else if (b > 100 * KB) {
- val = b / MB;
- suffix = "MB";
- } else {
- val = b / KB;
- suffix = "KB";
- }
- return FORMAT.format(val * (bytes < 0 ? -1 : 1)) + " " + suffix;
+ private CharSequence formatDataUsage(long byteValue) {
+ final BytesResult res = Formatter.formatBytes(mContext.getResources(), byteValue,
+ Formatter.FLAG_IEC_UNITS);
+ return BidiFormatter.getInstance().unicodeWrap(mContext.getString(
+ com.android.internal.R.string.fileSizeSuffix, res.value, res.units));
}
}