Skip to content

Commit f616dbb

Browse files
committed
Launcher3: Show actual memory without rounding up
Signed-off-by: Pranav Vashi <[email protected]>
1 parent 80c477c commit f616dbb

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

Diff for: quickstep/src/com/android/quickstep/views/MemInfoView.java

+13-23
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import android.content.Intent;
2525
import android.os.Handler;
2626
import android.os.Looper;
27+
import android.text.format.Formatter;
2728
import android.util.AttributeSet;
2829
import android.util.FloatProperty;
2930
import android.view.Gravity;
@@ -74,12 +75,18 @@ public void setValue(MemInfoView view, float v) {
7475

7576
private String mMemInfoText;
7677

78+
private ActivityManager.MemoryInfo memInfo;
79+
80+
private Context mContext;
81+
7782
public MemInfoView(Context context, AttributeSet attrs) {
7883
super(context, attrs);
7984

85+
mContext = context;
8086
mAlpha = new MultiValueAlpha(this, 2);
8187
mAlpha.setUpdateVisibility(true);
8288
mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
89+
memInfo = new ActivityManager.MemoryInfo();
8390
mHandler = new Handler(Looper.getMainLooper());
8491
mWorker = new MemInfoWorker();
8592

@@ -132,24 +139,6 @@ else if (mDp.isTaskbarPresent && !((mode == THREE_BUTTONS) || (mode == TWO_BUTTO
132139
lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
133140
}
134141

135-
private String unitConvert(long valueMiB, boolean alignToGB) {
136-
BigDecimal rawVal = new BigDecimal(valueMiB);
137-
138-
if (alignToGB)
139-
return rawVal.divide(GB2MB, 0, RoundingMode.UP) + " GB";
140-
141-
if (valueMiB > UNIT_CONVERT_THRESHOLD)
142-
return rawVal.divide(GB2MB, 1, RoundingMode.HALF_UP) + " GB";
143-
else
144-
return rawVal + " MB";
145-
}
146-
147-
private void updateMemInfoText(long availMemMiB, long totalMemMiB) {
148-
String text = String.format(mMemInfoText,
149-
unitConvert(availMemMiB, false), unitConvert(totalMemMiB, true));
150-
setText(text);
151-
}
152-
153142
public void setListener(Context context) {
154143
setOnClickListener(view -> {
155144
Intent intent = new Intent(Intent.ACTION_MAIN);
@@ -162,12 +151,13 @@ public void setListener(Context context) {
162151
private class MemInfoWorker implements Runnable {
163152
@Override
164153
public void run() {
165-
ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
166154
mActivityManager.getMemoryInfo(memInfo);
167-
long availMemMiB = memInfo.availMem / (1024 * 1024);
168-
long totalMemMiB = memInfo.totalMem / (1024 * 1024);
169-
updateMemInfoText(availMemMiB, totalMemMiB);
170-
155+
String availResult = Formatter.formatShortFileSize(mContext,
156+
(long) memInfo.availMem);
157+
String totalResult = Formatter.formatShortFileSize(mContext,
158+
(long) memInfo.totalMem);
159+
String text = String.format(mMemInfoText, availResult, totalResult);
160+
setText(text);
171161
mHandler.postDelayed(this, 1000);
172162
}
173163
}

0 commit comments

Comments
 (0)