- Use SharedPreference to cache the size info
- Improve the flicker problem on Documents & other preference
- The jobs are destroied on onPause to prevent the jobs being
restarting when back to Storage page
- Enable progress bar animation for each storage item
Bug: 191117970
Test: manual test
1) The loading spinner will be shown when entering Storage page
at first time.
2) Back to Settings homepage and switch back to Storage page, the
loading spinner shouldn't be shown.
3) Click each preference in the Storage page and switch between these
pages, the size info should be updated if something removed and the
order of preference shouldn't be changed.
Change-Id: I75533742a025dc61116207285a894ee728d0af68
Merged-In: I75533742a025dc61116207285a894ee728d0af68
(cherry picked from commit 77775a66f2
)
79 lines
2.3 KiB
Java
79 lines
2.3 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.util.AttributeSet;
|
|
import android.widget.ProgressBar;
|
|
|
|
import androidx.preference.Preference;
|
|
import androidx.preference.PreferenceViewHolder;
|
|
|
|
import com.android.settings.R;
|
|
import com.android.settings.deviceinfo.storage.StorageUtils;
|
|
|
|
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);
|
|
}
|
|
|
|
public void setStorageSize(long size, long total) {
|
|
mStorageSize = size;
|
|
setSummary(StorageUtils.getStorageSizeLabel(getContext(), 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, true /* animate */);
|
|
}
|
|
|
|
@Override
|
|
public void onBindViewHolder(PreferenceViewHolder view) {
|
|
mProgressBar = (ProgressBar) view.findViewById(android.R.id.progress);
|
|
updateProgressBar();
|
|
super.onBindViewHolder(view);
|
|
}
|
|
}
|