From android S, Storage Settings show files of images/videos/audios category instead of installed APP of each category. So it's necessary to change the way to calculate size information. This change also - StorageItemPreference shows changing storage size units instead of fixed GB. It helps UX for categories of only small size files. - Query media provider for size of Documents and others. - Query media provider for size of Trash. Bug: 170918505 Bug: 177892478 Bug: 179871408 Bug: 184379946 Bug: 186077224 Bug: 187128447 Test: atest com.android.settings.deviceinfo atest com.android.settings.deviceinfo.storage make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.deviceinfo make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.deviceinfo.storage manual visual Click each file category to count files size is the same as displayed in Storage Settings. Change-Id: I37c7b3a4b5860323cb55581b23a90f583f4af216
88 lines
2.7 KiB
Java
88 lines
2.7 KiB
Java
/*
|
|
* 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;
|
|
|
|
import android.content.Context;
|
|
import android.text.TextUtils;
|
|
import android.text.format.Formatter;
|
|
import android.util.AttributeSet;
|
|
import android.widget.ProgressBar;
|
|
|
|
import androidx.preference.Preference;
|
|
import androidx.preference.PreferenceViewHolder;
|
|
|
|
import com.android.settings.R;
|
|
|
|
public class StorageItemPreference extends Preference {
|
|
public int userHandle;
|
|
|
|
private static final int UNINITIALIZED = -1;
|
|
|
|
private ProgressBar mProgressBar;
|
|
private static final int PROGRESS_MAX = 100;
|
|
private int mProgressPercent = UNINITIALIZED;
|
|
private long mStorageSize;
|
|
|
|
public StorageItemPreference(Context 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) {
|
|
mStorageSize = size;
|
|
setSummary(getStorageSummary(size));
|
|
|
|
if (total == 0) {
|
|
mProgressPercent = 0;
|
|
} else {
|
|
mProgressPercent = (int)(size * PROGRESS_MAX / total);
|
|
}
|
|
updateProgressBar();
|
|
}
|
|
|
|
public long getStorageSize() {
|
|
return mStorageSize;
|
|
}
|
|
|
|
protected void updateProgressBar() {
|
|
if (mProgressBar == null || mProgressPercent == UNINITIALIZED)
|
|
return;
|
|
|
|
mProgressBar.setMax(PROGRESS_MAX);
|
|
mProgressBar.setProgress(mProgressPercent);
|
|
}
|
|
|
|
@Override
|
|
public void onBindViewHolder(PreferenceViewHolder view) {
|
|
mProgressBar = (ProgressBar) view.findViewById(android.R.id.progress);
|
|
updateProgressBar();
|
|
super.onBindViewHolder(view);
|
|
}
|
|
|
|
private String getStorageSummary(long bytes) {
|
|
final Formatter.BytesResult result = Formatter.formatBytes(getContext().getResources(),
|
|
bytes, Formatter.FLAG_SHORTER);
|
|
return TextUtils.expandTemplate(getContext().getText(R.string.storage_size_large),
|
|
result.value, result.units).toString();
|
|
}
|
|
}
|