Merge "Add first pass at a new Storage screen."
This commit is contained in:
@@ -23,7 +23,7 @@ import com.android.settings.core.PreferenceController;
|
||||
|
||||
public class ManageStoragePreferenceController extends PreferenceController {
|
||||
|
||||
public static final String KEY_MANAGE_STORAGE = "pref_manage_storage";
|
||||
public static final String KEY_MANAGE_STORAGE = "footer_preference";
|
||||
|
||||
public ManageStoragePreferenceController(Context context) {
|
||||
super(context);
|
||||
|
@@ -17,15 +17,24 @@
|
||||
package com.android.settings.deviceinfo;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.storage.StorageManager;
|
||||
import android.os.storage.VolumeInfo;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.deviceinfo.storage.StorageItemPreferenceController;
|
||||
import com.android.settings.deviceinfo.storage.StorageSummaryDonutPreferenceController;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.widget.FooterPreference;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -33,9 +42,53 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class StorageDashboardFragment extends DashboardFragment {
|
||||
|
||||
private static final String TAG = "StorageDashboardFrag";
|
||||
|
||||
private VolumeInfo mVolume;
|
||||
private long mTotalSize;
|
||||
|
||||
private StorageSummaryDonutPreferenceController mSummaryController;
|
||||
|
||||
private boolean isVolumeValid() {
|
||||
return (mVolume != null) && (mVolume.getType() == VolumeInfo.TYPE_PRIVATE)
|
||||
&& mVolume.isMountedReadable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
final Context context = getActivity();
|
||||
|
||||
// Initialize the storage sizes that we can quickly calc.
|
||||
StorageManager sm = context.getSystemService(StorageManager.class);
|
||||
mVolume = sm.findVolumeById(VolumeInfo.ID_PRIVATE_INTERNAL);
|
||||
if (!isVolumeValid()) {
|
||||
getActivity().finish();
|
||||
return;
|
||||
}
|
||||
|
||||
final long sharedDataSize = mVolume.getPath().getTotalSpace();
|
||||
mTotalSize = sm.getPrimaryStorageSize();
|
||||
long systemSize = mTotalSize - sharedDataSize;
|
||||
|
||||
if (mTotalSize <= 0) {
|
||||
mTotalSize = sharedDataSize;
|
||||
systemSize = 0;
|
||||
}
|
||||
|
||||
final long usedBytes = mTotalSize - mVolume.getPath().getFreeSpace();
|
||||
mSummaryController.updateBytes(usedBytes, mTotalSize);
|
||||
|
||||
// Initialize the footer preference to go to the smart storage management.
|
||||
final FooterPreference pref = mFooterPreferenceMixin.createFooterPreference();
|
||||
pref.setTitle(R.string.storage_menu_manage);
|
||||
pref.setFragment("com.android.settings.deletionhelper.AutomaticStorageManagerSettings");
|
||||
pref.setIcon(R.drawable.ic_settings_storage);
|
||||
pref.setEnabled(true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsProto.MetricsEvent.SETTINGS_STORAGE_CATEGORY;
|
||||
@@ -59,10 +112,25 @@ public class StorageDashboardFragment extends DashboardFragment {
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
final List<PreferenceController> controllers = new ArrayList<>();
|
||||
mSummaryController = new StorageSummaryDonutPreferenceController(context);
|
||||
controllers.add(mSummaryController);
|
||||
controllers.add(new ManageStoragePreferenceController(context));
|
||||
controllers.add(new StorageItemPreferenceController(context, "pref_photos_videos"));
|
||||
controllers.add(new StorageItemPreferenceController(context, "pref_music_audio"));
|
||||
controllers.add(new StorageItemPreferenceController(context, "pref_games"));
|
||||
controllers.add(new StorageItemPreferenceController(context, "pref_other_apps"));
|
||||
controllers.add(new StorageItemPreferenceController(context, "pref_system"));
|
||||
controllers.add(new StorageItemPreferenceController(context, "pref_files"));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View root = super.onCreateView(inflater, container, savedInstanceState);
|
||||
// TODO: Add loader to load the storage sizes for the StorageItemPreferenceControllers.
|
||||
return root;
|
||||
}
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.support.v7.preference.PreferenceViewHolder;
|
||||
import android.text.format.Formatter;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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 com.android.settings.core.PreferenceController;
|
||||
|
||||
/**
|
||||
* StorageItemPreferenceController handles the updating of a single storage preference line item.
|
||||
*/
|
||||
public class StorageItemPreferenceController extends PreferenceController {
|
||||
private static final long NOT_YET_SET = -1;
|
||||
private final String mKey;
|
||||
private long mStorageSize;
|
||||
|
||||
public StorageItemPreferenceController(Context context, String key) {
|
||||
super(context);
|
||||
mKey = key;
|
||||
mStorageSize = NOT_YET_SET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return mKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
if (preference == null || mStorageSize == NOT_YET_SET) {
|
||||
return;
|
||||
}
|
||||
|
||||
StorageItemPreferenceAlternate summary = (StorageItemPreferenceAlternate) preference;
|
||||
summary.setStorageSize(mStorageSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the amount of bytes used by this storage item.
|
||||
*/
|
||||
public void setStorageSize(long size) {
|
||||
mStorageSize = size;
|
||||
}
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.support.v7.preference.PreferenceViewHolder;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.MathUtils;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
/**
|
||||
* StorageSummaryDonutPreference is a preference which summarizes the used and remaining storage left
|
||||
* on a given storage volume. It is visualized with a donut graphing the % used.
|
||||
*/
|
||||
public class StorageSummaryDonutPreference extends Preference {
|
||||
private int mPercent = -1;
|
||||
|
||||
public StorageSummaryDonutPreference(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public StorageSummaryDonutPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
setLayoutResource(R.layout.storage_summary_donut);
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
public void setPercent(long usedBytes, long totalBytes) {
|
||||
if (totalBytes == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
mPercent = MathUtils.constrain((int) ((usedBytes * 100) / totalBytes),
|
||||
(usedBytes > 0) ? 1 : 0, 100);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||
// TODO: Replace the progress bar with a donut.
|
||||
final ProgressBar progress = (ProgressBar) view.findViewById(android.R.id.progress);
|
||||
if (mPercent != -1) {
|
||||
progress.setVisibility(View.VISIBLE);
|
||||
progress.setProgress(mPercent);
|
||||
progress.setScaleY(7f);
|
||||
} else {
|
||||
progress.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
super.onBindViewHolder(view);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
package com.android.settings.deviceinfo.storage;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.Formatter;
|
||||
import android.util.Log;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settings.R;
|
||||
|
||||
/**
|
||||
* StorgaeSummaryPreferenceController updates the donut storage summary preference to have the
|
||||
* correct sizes showing.
|
||||
*/
|
||||
public class StorageSummaryDonutPreferenceController extends PreferenceController {
|
||||
private long mUsedBytes;
|
||||
private long mTotalBytes;
|
||||
|
||||
public StorageSummaryDonutPreferenceController(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
Log.d("dhnishi", "Preference displayed!");
|
||||
StorageSummaryDonutPreference summary = (StorageSummaryDonutPreference)
|
||||
screen.findPreference("pref_summary");
|
||||
summary.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
StorageSummaryDonutPreference summary = (StorageSummaryDonutPreference) preference;
|
||||
final Formatter.BytesResult result = Formatter.formatBytes(mContext.getResources(),
|
||||
mUsedBytes, 0);
|
||||
summary.setTitle(TextUtils.expandTemplate(mContext.getText(R.string.storage_size_large),
|
||||
result.value, result.units));
|
||||
summary.setSummary(mContext.getString(R.string.storage_volume_used,
|
||||
Formatter.formatFileSize(mContext, mTotalBytes)));
|
||||
summary.setEnabled(true);
|
||||
summary.setPercent(mUsedBytes, mTotalBytes);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return "pref_summary";
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the state of the donut preference for the next update.
|
||||
* @param used Total number of used bytes on the summarized volume.
|
||||
* @param total Total number of bytes on the summarized volume.
|
||||
*/
|
||||
public void updateBytes(long used, long total) {
|
||||
mUsedBytes = used;
|
||||
mTotalBytes = total;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user