Merge "Fix UI problems of PublicVolumeSettings"

This commit is contained in:
Arc Wang
2022-01-27 01:32:03 +00:00
committed by Android (Google) Code Review
6 changed files with 20 additions and 146 deletions

View File

@@ -28,8 +28,6 @@ import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.os.storage.VolumeRecord;
import android.provider.DocumentsContract;
import android.text.TextUtils;
import android.text.format.Formatter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
@@ -40,8 +38,10 @@ import androidx.preference.PreferenceScreen;
import com.android.internal.util.Preconditions;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.deviceinfo.storage.StorageUtils;
import com.android.settings.deviceinfo.storage.StorageUtils.MountTask;
import com.android.settings.deviceinfo.storage.StorageUtils.UnmountTask;
import com.android.settingslib.widget.UsageProgressBarPreference;
import java.io.File;
import java.util.Objects;
@@ -59,7 +59,7 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
private VolumeInfo mVolume;
private DiskInfo mDisk;
private StorageSummaryPreference mSummary;
private UsageProgressBarPreference mSummary;
private Preference mMount;
private Preference mFormatPublic;
@@ -114,7 +114,7 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
addPreferencesFromResource(R.xml.device_info_storage_volume);
getPreferenceScreen().setOrderingAsAdded(true);
mSummary = new StorageSummaryPreference(getPrefContext());
mSummary = new UsageProgressBarPreference(getPrefContext());
mMount = buildAction(R.string.storage_menu_mount);
mUnmount = new Button(getActivity());
@@ -162,12 +162,10 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
final long freeBytes = file.getFreeSpace();
final long usedBytes = totalBytes - freeBytes;
final Formatter.BytesResult result = Formatter.formatBytes(getResources(), usedBytes,
0);
mSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large),
result.value, result.units));
mSummary.setSummary(getString(R.string.storage_volume_used,
Formatter.formatFileSize(context, totalBytes)));
mSummary.setUsageSummary(StorageUtils.getStorageSummary(
context, R.string.storage_usage_summary, usedBytes));
mSummary.setTotalSummary(StorageUtils.getStorageSummary(
context, R.string.storage_total_summary, totalBytes));
mSummary.setPercent(usedBytes, totalBytes);
}

View File

@@ -1,62 +0,0 @@
/*
* Copyright (C) 2015 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.graphics.Color;
import android.util.MathUtils;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
public class StorageSummaryPreference extends Preference {
private int mPercent = -1;
public StorageSummaryPreference(Context context) {
super(context);
setLayoutResource(R.layout.storage_summary);
setEnabled(false);
}
public void setPercent(long usedBytes, long totalBytes) {
mPercent = MathUtils.constrain((int) ((usedBytes * 100) / totalBytes),
(usedBytes > 0) ? 1 : 0, 100);
}
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
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);
}
final TextView summary = (TextView) view.findViewById(android.R.id.summary);
summary.setTextColor(Color.parseColor("#8a000000"));
super.onBindViewHolder(view);
}
}

View File

@@ -18,7 +18,6 @@ package com.android.settings.deviceinfo.storage;
import android.app.usage.StorageStatsManager;
import android.content.Context;
import android.text.format.Formatter;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
@@ -113,16 +112,10 @@ public class StorageUsageProgressBarPreferenceController extends BasePreferenceC
return;
}
mIsUpdateStateFromSelectedStorageEntry = false;
mUsageProgressBarPreference.setUsageSummary(
getStorageSummary(R.string.storage_usage_summary, mUsedBytes));
mUsageProgressBarPreference.setTotalSummary(
getStorageSummary(R.string.storage_total_summary, mTotalBytes));
mUsageProgressBarPreference.setUsageSummary(StorageUtils.getStorageSummary(
mContext, R.string.storage_usage_summary, mUsedBytes));
mUsageProgressBarPreference.setTotalSummary(StorageUtils.getStorageSummary(
mContext, R.string.storage_total_summary, mTotalBytes));
mUsageProgressBarPreference.setPercent(mUsedBytes, mTotalBytes);
}
private String getStorageSummary(int resId, long bytes) {
final Formatter.BytesResult result = Formatter.formatBytes(mContext.getResources(),
bytes, Formatter.FLAG_SHORTER);
return mContext.getString(resId, result.value, result.units);
}
}

View File

@@ -199,7 +199,7 @@ public class StorageUtils {
}
}
/* Shows information about system storage. */
/** Shows information about system storage. */
public static class SystemInfoFragment extends InstrumentedDialogFragment {
/** Shows the fragment. */
public static void show(Fragment parent) {
@@ -224,4 +224,11 @@ public class StorageUtils {
.create();
}
}
/** Gets a summary which has a byte size information. */
public static String getStorageSummary(Context context, int resId, long bytes) {
final Formatter.BytesResult result = Formatter.formatBytes(context.getResources(),
bytes, Formatter.FLAG_SHORTER);
return context.getString(resId, result.value, result.units);
}
}