Merge "Update storage usage progress bar summary text" into sc-dev

This commit is contained in:
TreeHugger Robot
2021-04-19 07:41:24 +00:00
committed by Android (Google) Code Review
2 changed files with 8 additions and 16 deletions

View File

@@ -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></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> used</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"><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> <string name="storage_total_summary"><xliff:g id="number" example="128">%1$s</xliff:g> <xliff:g id="unit" example="KB">%2$s</xliff:g> total</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>

View File

@@ -26,7 +26,6 @@ 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;
@@ -108,23 +107,16 @@ public class StorageUsageProgressBarPreferenceController extends BasePreferenceC
@Override @Override
public void updateState(Preference preference) { public void updateState(Preference preference) {
final Formatter.BytesResult usedResult = getBytesResult(mUsedBytes);
mUsageProgressBarPreference.setUsageSummary( mUsageProgressBarPreference.setUsageSummary(
mContext.getString(R.string.storage_usage_summary, getStorageSummary(R.string.storage_usage_summary, mUsedBytes));
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(
mContext.getString(R.string.storage_total_summary, percentageString, getStorageSummary(R.string.storage_total_summary, mTotalBytes));
totalResult.value, totalResult.units));
mUsageProgressBarPreference.setPercent(mUsedBytes, mTotalBytes); mUsageProgressBarPreference.setPercent(mUsedBytes, mTotalBytes);
} }
private Formatter.BytesResult getBytesResult(long bytes) { private String getStorageSummary(int resId, long bytes) {
return Formatter.formatBytes(mContext.getResources(), bytes, Formatter.FLAG_SHORTER); final Formatter.BytesResult result = Formatter.formatBytes(mContext.getResources(),
bytes, Formatter.FLAG_SHORTER);
return mContext.getString(resId, result.value, result.units);
} }
} }