Merge "Re-add the progress bar for storage preferences."

This commit is contained in:
Daniel Nishi
2017-03-20 22:54:02 +00:00
committed by Android (Google) Code Review
14 changed files with 183 additions and 203 deletions

View File

@@ -114,6 +114,16 @@ public class StorageDashboardFragment extends DashboardFragment
mSummaryController.updateBytes(usedBytes, totalSize);
mPreferenceController.setVolume(mVolume);
mPreferenceController.setSystemSize(systemSize);
mPreferenceController.setTotalSize(totalSize);
for (int i = 0, size = mSecondaryUsers.size(); i < size; i++) {
PreferenceController controller = mSecondaryUsers.get(i);
if (controller instanceof SecondaryUserController) {
SecondaryUserController userController = (SecondaryUserController) controller;
userController.setTotalSize(totalSize);
}
}
}
@Override

View File

@@ -20,6 +20,7 @@ import android.content.Context;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.text.format.Formatter;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ProgressBar;
@@ -28,13 +29,18 @@ import com.android.settings.R;
public class StorageItemPreference extends Preference {
public int userHandle;
private ProgressBar progressBar;
private ProgressBar mProgressBar;
private static final int PROGRESS_MAX = 100;
private int progress = -1;
private int mProgressPercent = -1;
public StorageItemPreference(Context context) {
super(context);
this(context, null);
}
public StorageItemPreference(Context context, AttributeSet attrs) {
super(context, attrs);
setLayoutResource(R.layout.storage_item);
setSummary(R.string.memory_calculating_size);
}
public void setStorageSize(long size, long total) {
@@ -42,30 +48,30 @@ public class StorageItemPreference extends Preference {
? String.valueOf(0)
: Formatter.formatFileSize(getContext(), size));
if (total == 0) {
progress = 0;
mProgressPercent = 0;
} else {
progress = (int)(size * PROGRESS_MAX / total);
mProgressPercent = (int)(size * PROGRESS_MAX / total);
}
updateProgressBar();
}
protected void updateProgressBar() {
if (progressBar == null)
if (mProgressBar == null)
return;
if (progress == -1) {
progressBar.setVisibility(View.GONE);
if (mProgressPercent == -1) {
mProgressBar.setVisibility(View.GONE);
return;
}
progressBar.setVisibility(View.VISIBLE);
progressBar.setMax(PROGRESS_MAX);
progressBar.setProgress(progress);
mProgressBar.setVisibility(View.VISIBLE);
mProgressBar.setMax(PROGRESS_MAX);
mProgressBar.setProgress(mProgressPercent);
}
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
progressBar = (ProgressBar) view.findViewById(android.R.id.progress);
mProgressBar = (ProgressBar) view.findViewById(android.R.id.progress);
updateProgressBar();
super.onBindViewHolder(view);
}

View File

@@ -28,6 +28,7 @@ import android.util.SparseArray;
import com.android.settings.Utils;
import com.android.settings.applications.UserManagerWrapper;
import com.android.settings.core.PreferenceController;
import com.android.settings.deviceinfo.StorageItemPreference;
import java.util.ArrayList;
import java.util.List;
@@ -46,8 +47,9 @@ public class SecondaryUserController extends PreferenceController implements
private static final int SIZE_NOT_SET = -1;
private @NonNull UserInfo mUser;
private @Nullable StorageItemPreferenceAlternate mStoragePreference;
private @Nullable StorageItemPreference mStoragePreference;
private long mSize;
private long mTotalSizeBytes;
/**
* Adds the appropriate controllers to a controller list for handling all secondary users on
@@ -98,14 +100,14 @@ public class SecondaryUserController extends PreferenceController implements
@Override
public void displayPreference(PreferenceScreen screen) {
if (mStoragePreference == null) {
mStoragePreference = new StorageItemPreferenceAlternate(screen.getContext());
mStoragePreference = new StorageItemPreference(screen.getContext());
PreferenceGroup group =
(PreferenceGroup) screen.findPreference(TARGET_PREFERENCE_GROUP_KEY);
mStoragePreference.setTitle(mUser.name);
mStoragePreference.setKey(PREFERENCE_KEY_BASE + mUser.id);
if (mSize != SIZE_NOT_SET) {
mStoragePreference.setStorageSize(mSize);
mStoragePreference.setStorageSize(mSize, mTotalSizeBytes);
}
group.setVisible(true);
group.addPreference(mStoragePreference);
@@ -137,10 +139,18 @@ public class SecondaryUserController extends PreferenceController implements
public void setSize(long size) {
mSize = size;
if (mStoragePreference != null) {
mStoragePreference.setStorageSize(mSize);
mStoragePreference.setStorageSize(mSize, mTotalSizeBytes);
}
}
/**
* Sets the total size for the preference for the progress bar.
* @param totalSizeBytes Total size in bytes.
*/
public void setTotalSize(long totalSizeBytes) {
mTotalSizeBytes = totalSizeBytes;
}
public void handleResult(SparseArray<StorageAsyncLoader.AppsStorageResult> stats) {
int userId = getUser().id;
StorageAsyncLoader.AppsStorageResult result = stats.get(userId);

View File

@@ -1,42 +0,0 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.deviceinfo.storage;
import android.content.Context;
import android.support.v7.preference.Preference;
import android.text.format.Formatter;
import android.util.AttributeSet;
import com.android.settings.R;
public class StorageItemPreferenceAlternate extends Preference {
public StorageItemPreferenceAlternate(Context context) {
this(context, null);
}
public StorageItemPreferenceAlternate(Context context, AttributeSet attrs) {
super(context, attrs);
setLayoutResource(R.layout.storage_item_alternate);
setSummary(R.string.memory_calculating_size);
}
public void setStorageSize(long size) {
setSummary(size == 0
? String.valueOf(0)
: Formatter.formatFileSize(getContext(), size));
}
}

View File

@@ -35,6 +35,7 @@ import com.android.settings.Utils;
import com.android.settings.applications.ManageApplications;
import com.android.settings.core.PreferenceController;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
import com.android.settings.deviceinfo.StorageItemPreference;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.deviceinfo.StorageMeasurement;
import com.android.settingslib.deviceinfo.StorageVolumeProvider;
@@ -71,13 +72,14 @@ public class StorageItemPreferenceController extends PreferenceController {
private VolumeInfo mVolume;
private int mUserId;
private long mSystemSize;
private long mTotalSize;
private StorageItemPreferenceAlternate mPhotoPreference;
private StorageItemPreferenceAlternate mAudioPreference;
private StorageItemPreferenceAlternate mGamePreference;
private StorageItemPreferenceAlternate mAppPreference;
private StorageItemPreferenceAlternate mFilePreference;
private StorageItemPreferenceAlternate mSystemPreference;
private StorageItemPreference mPhotoPreference;
private StorageItemPreference mAudioPreference;
private StorageItemPreference mGamePreference;
private StorageItemPreference mAppPreference;
private StorageItemPreference mFilePreference;
private StorageItemPreference mSystemPreference;
private static final String AUTHORITY_MEDIA = "com.android.providers.media.documents";
@@ -164,37 +166,38 @@ public class StorageItemPreferenceController extends PreferenceController {
@Override
public void displayPreference(PreferenceScreen screen) {
mPhotoPreference = (StorageItemPreferenceAlternate) screen.findPreference(PHOTO_KEY);
mAudioPreference = (StorageItemPreferenceAlternate) screen.findPreference(AUDIO_KEY);
mGamePreference = (StorageItemPreferenceAlternate) screen.findPreference(GAME_KEY);
mAppPreference = (StorageItemPreferenceAlternate) screen.findPreference(OTHER_APPS_KEY);
mSystemPreference = (StorageItemPreferenceAlternate) screen.findPreference(SYSTEM_KEY);
mFilePreference = (StorageItemPreferenceAlternate) screen.findPreference(FILES_KEY);
mPhotoPreference = (StorageItemPreference) screen.findPreference(PHOTO_KEY);
mAudioPreference = (StorageItemPreference) screen.findPreference(AUDIO_KEY);
mGamePreference = (StorageItemPreference) screen.findPreference(GAME_KEY);
mAppPreference = (StorageItemPreference) screen.findPreference(OTHER_APPS_KEY);
mSystemPreference = (StorageItemPreference) screen.findPreference(SYSTEM_KEY);
mFilePreference = (StorageItemPreference) screen.findPreference(FILES_KEY);
}
public void onLoadFinished(StorageAsyncLoader.AppsStorageResult data) {
// TODO(b/35927909): Figure out how to split out apps which are only installed for work
// profiles in order to attribute those app's code bytes only to that profile.
mPhotoPreference.setStorageSize(
data.externalStats.imageBytes + data.externalStats.videoBytes);
mAudioPreference.setStorageSize(data.musicAppsSize + data.externalStats.audioBytes);
mGamePreference.setStorageSize(data.gamesSize);
mAppPreference.setStorageSize(data.otherAppsSize);
data.externalStats.imageBytes + data.externalStats.videoBytes, mTotalSize);
mAudioPreference.setStorageSize(
data.musicAppsSize + data.externalStats.audioBytes, mTotalSize);
mGamePreference.setStorageSize(data.gamesSize, mTotalSize);
mAppPreference.setStorageSize(data.otherAppsSize, mTotalSize);
if (mSystemPreference != null) {
mSystemPreference.setStorageSize(mSystemSize + data.systemSize);
mSystemPreference.setStorageSize(mSystemSize + data.systemSize, mTotalSize);
}
long unattributedBytes = data.externalStats.totalBytes - data.externalStats.audioBytes
- data.externalStats.videoBytes - data.externalStats.imageBytes;
mFilePreference.setStorageSize(unattributedBytes);
mFilePreference.setStorageSize(unattributedBytes, mTotalSize);
}
/**
* Sets the system size for the system size preference.
* @param systemSize the size of the system in bytes
*/
public void setSystemSize(long systemSize) {
mSystemSize = systemSize;
public void setSystemSize(long systemSizeBytes) {
mSystemSize = systemSizeBytes;
}
public void setTotalSize(long totalSizeBytes) {
mTotalSize = totalSizeBytes;
}
/**

View File

@@ -29,6 +29,7 @@ import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.util.Preconditions;
import com.android.settings.Utils;
import com.android.settings.core.PreferenceController;
import com.android.settings.deviceinfo.StorageItemPreference;
import com.android.settings.deviceinfo.StorageProfileFragment;
import com.android.settingslib.drawer.SettingsDrawerActivity;
@@ -38,8 +39,9 @@ import com.android.settingslib.drawer.SettingsDrawerActivity;
public class UserProfileController extends PreferenceController implements
StorageAsyncLoader.ResultHandler {
private static final String PREFERENCE_KEY_BASE = "pref_profile_";
private StorageItemPreferenceAlternate mStoragePreference;
private StorageItemPreference mStoragePreference;
private UserInfo mUser;
private long mTotalSizeBytes;
private final int mPreferenceOrder;
public UserProfileController(Context context, UserInfo info, int preferenceOrder) {
@@ -60,7 +62,7 @@ public class UserProfileController extends PreferenceController implements
@Override
public void displayPreference(PreferenceScreen screen) {
mStoragePreference = new StorageItemPreferenceAlternate(screen.getContext());
mStoragePreference = new StorageItemPreference(screen.getContext());
mStoragePreference.setOrder(mPreferenceOrder);
mStoragePreference.setKey(PREFERENCE_KEY_BASE + mUser.id);
mStoragePreference.setTitle(mUser.name);
@@ -91,16 +93,20 @@ public class UserProfileController extends PreferenceController implements
int userId = mUser.id;
StorageAsyncLoader.AppsStorageResult result = stats.get(userId);
if (result != null) {
setSize(result.externalStats.totalBytes);
setSize(result.externalStats.totalBytes, mTotalSizeBytes);
}
}
/**
* Sets the size for the preference using a byte count.
*/
public void setSize(long size) {
public void setSize(long size, long totalSize) {
if (mStoragePreference != null) {
mStoragePreference.setStorageSize(size);
mStoragePreference.setStorageSize(size, totalSize);
}
}
public void setTotalSize(long totalSize) {
mTotalSizeBytes = totalSize;
}
}