Update storage usage progress bar summary text
Shows a simplified version, e.g., 24GB / 32% used of 64 GB Bug: 174964885 Test: manual visual Change-Id: I39cdc5efa1d562c339525fa23456c71b726b9e1a
This commit is contained in:
@@ -11814,9 +11814,9 @@
|
|||||||
<string name="storage_percent_full">used</string>
|
<string name="storage_percent_full">used</string>
|
||||||
|
|
||||||
<!-- Summary of a single storage volume used space. [CHAR LIMIT=24] -->
|
<!-- Summary of a single storage volume used space. [CHAR LIMIT=24] -->
|
||||||
<string name="storage_usage_summary"><xliff:g id="number" example="128">%1$s</xliff:g> <xliff:g id="unit" example="KB">%2$s</xliff:g> used</string>
|
<string name="storage_usage_summary"><xliff:g id="number" example="128">%1$s</xliff:g> <xliff:g id="unit" example="KB">%2$s</xliff:g></string>
|
||||||
<!-- Summary of a single storage volume total space. [CHAR LIMIT=24] -->
|
<!-- Summary of a single storage volume total space. [CHAR LIMIT=24] -->
|
||||||
<string name="storage_total_summary">Total <xliff:g id="number" example="128">%1$s</xliff:g> <xliff:g id="unit" example="KB">%2$s</xliff:g></string>
|
<string name="storage_total_summary"><xliff:g id="percentage" example="54%">%1$s</xliff:g> used of <xliff:g id="number" example="128">%2$s</xliff:g> <xliff:g id="unit" example="KB">%3$s</xliff:g></string>
|
||||||
|
|
||||||
<!-- Label for button allow user to remove the instant app from the device. -->
|
<!-- Label for button allow user to remove the instant app from the device. -->
|
||||||
<string name="clear_instant_app_data">Clear app</string>
|
<string name="clear_instant_app_data">Clear app</string>
|
||||||
|
@@ -26,6 +26,7 @@ import androidx.preference.Preference;
|
|||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settingslib.utils.ThreadUtils;
|
import com.android.settingslib.utils.ThreadUtils;
|
||||||
import com.android.settingslib.widget.UsageProgressBarPreference;
|
import com.android.settingslib.widget.UsageProgressBarPreference;
|
||||||
@@ -101,24 +102,29 @@ public class StorageUsageProgressBarPreferenceController extends BasePreferenceC
|
|||||||
if (mUsageProgressBarPreference == null) {
|
if (mUsageProgressBarPreference == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ThreadUtils.postOnMainThread(() ->
|
ThreadUtils.postOnMainThread(() -> updateState(mUsageProgressBarPreference));
|
||||||
updateState(mUsageProgressBarPreference)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void updateState(Preference preference) {
|
||||||
|
final Formatter.BytesResult usedResult = getBytesResult(mUsedBytes);
|
||||||
mUsageProgressBarPreference.setUsageSummary(
|
mUsageProgressBarPreference.setUsageSummary(
|
||||||
getStorageSummary(R.string.storage_usage_summary, mUsedBytes));
|
mContext.getString(R.string.storage_usage_summary,
|
||||||
|
usedResult.value, usedResult.units));
|
||||||
|
|
||||||
|
final String percentageString = mTotalBytes == 0L
|
||||||
|
? Utils.formatPercentage(0)
|
||||||
|
: Utils.formatPercentage((mUsedBytes * 100) / mTotalBytes, true /* round */);
|
||||||
|
final Formatter.BytesResult totalResult = getBytesResult(mTotalBytes);
|
||||||
mUsageProgressBarPreference.setTotalSummary(
|
mUsageProgressBarPreference.setTotalSummary(
|
||||||
getStorageSummary(R.string.storage_total_summary, mTotalBytes));
|
mContext.getString(R.string.storage_total_summary, percentageString,
|
||||||
|
totalResult.value, totalResult.units));
|
||||||
|
|
||||||
mUsageProgressBarPreference.setPercent(mUsedBytes, mTotalBytes);
|
mUsageProgressBarPreference.setPercent(mUsedBytes, mTotalBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getStorageSummary(int resId, long bytes) {
|
private Formatter.BytesResult getBytesResult(long bytes) {
|
||||||
final Formatter.BytesResult result = Formatter.formatBytes(mContext.getResources(),
|
return Formatter.formatBytes(mContext.getResources(), bytes, Formatter.FLAG_SHORTER);
|
||||||
bytes, 0);
|
|
||||||
return mContext.getString(resId, result.value, result.units);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user