Merge "Storage correctly updates internal storage graph."

This commit is contained in:
Gilles Debunne
2011-07-11 10:10:30 -07:00
committed by Android (Google) Code Review
3 changed files with 15 additions and 18 deletions

View File

@@ -85,12 +85,10 @@ public class Memory extends SettingsPreferenceFragment {
if (!Environment.isExternalStorageEmulated()) { if (!Environment.isExternalStorageEmulated()) {
// External storage is separate from internal storage; need to // External storage is separate from internal storage; need to
// show internal storage as a separate item. // show internal storage as a separate item.
StorageVolumePreferenceCategory storagePreferenceCategory = mInternalStorageVolumePreferenceCategory = new StorageVolumePreferenceCategory(
new StorageVolumePreferenceCategory(getActivity(), mResources, null, getActivity(), mResources, null, mStorageManager, false);
mStorageManager, true); getPreferenceScreen().addPreference(mInternalStorageVolumePreferenceCategory);
mInternalStorageVolumePreferenceCategory = storagePreferenceCategory; mInternalStorageVolumePreferenceCategory.init();
getPreferenceScreen().addPreference(storagePreferenceCategory);
storagePreferenceCategory.init();
} }
StorageVolume[] storageVolumes = mStorageManager.getVolumeList(); StorageVolume[] storageVolumes = mStorageManager.getVolumeList();
@@ -101,12 +99,11 @@ public class Memory extends SettingsPreferenceFragment {
mStorageVolumePreferenceCategories = new StorageVolumePreferenceCategory[length]; mStorageVolumePreferenceCategories = new StorageVolumePreferenceCategory[length];
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
StorageVolume storageVolume = storageVolumes[i]; StorageVolume storageVolume = storageVolumes[i];
StorageVolumePreferenceCategory storagePreferenceCategory = boolean isPrimary = i == 0;
new StorageVolumePreferenceCategory(getActivity(), mResources, storageVolume, mStorageVolumePreferenceCategories[i] = new StorageVolumePreferenceCategory(
mStorageManager, i == 0); // The first volume is the primary volume getActivity(), mResources, storageVolume, mStorageManager, isPrimary);
mStorageVolumePreferenceCategories[i] = storagePreferenceCategory; getPreferenceScreen().addPreference(mStorageVolumePreferenceCategories[i]);
getPreferenceScreen().addPreference(storagePreferenceCategory); mStorageVolumePreferenceCategories[i].init();
storagePreferenceCategory.init();
} }
// only show options menu if we are not using the legacy USB mass storage support // only show options menu if we are not using the legacy USB mass storage support
@@ -132,9 +129,8 @@ public class Memory extends SettingsPreferenceFragment {
StorageEventListener mStorageListener = new StorageEventListener() { StorageEventListener mStorageListener = new StorageEventListener() {
@Override @Override
public void onStorageStateChanged(String path, String oldState, String newState) { public void onStorageStateChanged(String path, String oldState, String newState) {
Log.i(TAG, "Received storage state changed notification that " + Log.i(TAG, "Received storage state changed notification that " + path +
path + " changed state from " + oldState + " changed state from " + oldState + " to " + newState);
" to " + newState);
for (int i = 0; i < mStorageVolumePreferenceCategories.length; i++) { for (int i = 0; i < mStorageVolumePreferenceCategories.length; i++) {
StorageVolumePreferenceCategory svpc = mStorageVolumePreferenceCategories[i]; StorageVolumePreferenceCategory svpc = mStorageVolumePreferenceCategories[i];
if (path.equals(svpc.getStorageVolume().getPath())) { if (path.equals(svpc.getStorageVolume().getPath())) {
@@ -233,6 +229,7 @@ public class Memory extends SettingsPreferenceFragment {
private final BroadcastReceiver mMediaScannerReceiver = new BroadcastReceiver() { private final BroadcastReceiver mMediaScannerReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
// mInternalStorageVolumePreferenceCategory is not affected by the media scanner
for (int i = 0; i < mStorageVolumePreferenceCategories.length; i++) { for (int i = 0; i < mStorageVolumePreferenceCategories.length; i++) {
mStorageVolumePreferenceCategories[i].onMediaScannerFinished(); mStorageVolumePreferenceCategories[i].onMediaScannerFinished();
} }

View File

@@ -549,7 +549,7 @@ public class StorageMeasurement {
/** /**
* TODO remove this method, only used because external SD Card needs a special treatment. * TODO remove this method, only used because external SD Card needs a special treatment.
*/ */
boolean isPrimary() { boolean isExternalSDCard() {
return mIsPrimary; return !mIsPrimary && !mIsInternal;
} }
} }

View File

@@ -311,7 +311,7 @@ public class StorageVolumePreferenceCategory extends PreferenceCategory implemen
mPreferences[TOTAL_SIZE].setSummary(formatSize(totalSize)); mPreferences[TOTAL_SIZE].setSummary(formatSize(totalSize));
if (!mMeasurement.isPrimary()) { if (mMeasurement.isExternalSDCard()) {
// TODO FIXME: external SD card will not report any size. Show used space in bar graph // TODO FIXME: external SD card will not report any size. Show used space in bar graph
final long usedSize = totalSize - availSize; final long usedSize = totalSize - availSize;
mUsageBarPreference.addEntry(usedSize / (float) totalSize, android.graphics.Color.GRAY); mUsageBarPreference.addEntry(usedSize / (float) totalSize, android.graphics.Color.GRAY);