More storage UI updates.

Storage volumes now have headers with larger fonts and progress bars
to show used versus free space.  Updated Memory to use new formatting
template, and Data Usage to use consistent display logic.

Allocate a unique color for each private volume, and yell when a
volume is running low on space.  Update private volume details to
launch into MediaStore-backed storage backends in a management mode,
and only show detailed items when hosting emulated storage.  Show
details dialog about "Other" and user storage items.

Shortcut into single private volume when it's the only device.  Add
real eject icon.

Bug: 21756698, 20275574, 21326612
Change-Id: If3ecd1d912d3e709c09d3e4da24f368e04dd3f9d
This commit is contained in:
Jeff Sharkey
2015-06-15 21:08:56 -07:00
parent edb7b0d9a9
commit 2597625fd9
17 changed files with 576 additions and 280 deletions

View File

@@ -17,12 +17,17 @@
package com.android.settings.deviceinfo;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.preference.Preference;
import android.text.format.Formatter;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.android.settings.R;
@@ -38,32 +43,53 @@ public class StorageVolumePreference extends Preference {
private final StorageManager mStorageManager;
private final VolumeInfo mVolume;
public StorageVolumePreference(Context context, VolumeInfo volume) {
private int mColor;
private int mUsedPercent = -1;
public StorageVolumePreference(Context context, VolumeInfo volume, int color) {
super(context);
mStorageManager = context.getSystemService(StorageManager.class);
mVolume = volume;
mColor = color;
setLayoutResource(R.layout.storage_volume);
setKey(volume.getId());
setTitle(mStorageManager.getBestVolumeDescription(volume));
Drawable icon;
if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(volume.getId())) {
icon = context.getDrawable(R.drawable.ic_settings_storage);
} else {
icon = context.getDrawable(R.drawable.ic_sim_sd);
}
if (volume.isMountedReadable()) {
// TODO: move statfs() to background thread
final File path = volume.getPath();
final long usedBytes = path.getTotalSpace() - path.getFreeSpace();
final long freeBytes = path.getFreeSpace();
final long totalBytes = path.getTotalSpace();
final long usedBytes = totalBytes - freeBytes;
final String used = Formatter.formatFileSize(context, usedBytes);
final String total = Formatter.formatFileSize(context, path.getTotalSpace());
final String total = Formatter.formatFileSize(context, totalBytes);
setSummary(context.getString(R.string.storage_volume_summary, used, total));
mUsedPercent = (int) ((usedBytes * 100) / totalBytes);
if (freeBytes < mStorageManager.getStorageLowBytes(path)) {
mColor = StorageSettings.COLOR_WARNING;
icon = context.getDrawable(R.drawable.ic_warning_24dp);
}
} else {
setSummary(volume.getStateDescription());
mUsedPercent = -1;
}
// TODO: better icons
if (VolumeInfo.ID_PRIVATE_INTERNAL.equals(volume.getId())) {
setIcon(context.getDrawable(R.drawable.ic_settings_storage));
} else {
setIcon(context.getDrawable(R.drawable.ic_sim_sd));
}
icon.mutate();
icon.setTint(mColor);
setIcon(icon);
if (volume.getType() == VolumeInfo.TYPE_PUBLIC
&& volume.isMountedReadable()) {
@@ -73,12 +99,21 @@ public class StorageVolumePreference extends Preference {
@Override
protected void onBindView(View view) {
final TextView unmount = (TextView) view.findViewById(R.id.unmount);
final ImageView unmount = (ImageView) view.findViewById(R.id.unmount);
if (unmount != null) {
unmount.setText("\u23CF");
unmount.getDrawable().setTint(Color.parseColor("#8a000000"));
unmount.setOnClickListener(mUnmountListener);
}
final ProgressBar progress = (ProgressBar) view.findViewById(android.R.id.progress);
if (mVolume.getType() == VolumeInfo.TYPE_PRIVATE && mUsedPercent != -1) {
progress.setVisibility(View.VISIBLE);
progress.setProgress(mUsedPercent);
progress.setProgressTintList(ColorStateList.valueOf(mColor));
} else {
progress.setVisibility(View.GONE);
}
super.onBindView(view);
}