diff --git a/res/layout/storage_summary.xml b/res/layout/storage_summary.xml deleted file mode 100644 index ce03b546a42..00000000000 --- a/res/layout/storage_summary.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - diff --git a/res/values/strings.xml b/res/values/strings.xml index 1eaa222fd08..1884279bdd3 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -3540,8 +3540,6 @@ ^1 ^2 - - Used of %1$s %1$s is mounted diff --git a/src/com/android/settings/deviceinfo/PublicVolumeSettings.java b/src/com/android/settings/deviceinfo/PublicVolumeSettings.java index 5315347afbc..f7dd85ab67a 100644 --- a/src/com/android/settings/deviceinfo/PublicVolumeSettings.java +++ b/src/com/android/settings/deviceinfo/PublicVolumeSettings.java @@ -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); } diff --git a/src/com/android/settings/deviceinfo/StorageSummaryPreference.java b/src/com/android/settings/deviceinfo/StorageSummaryPreference.java deleted file mode 100644 index 72b67de1ddd..00000000000 --- a/src/com/android/settings/deviceinfo/StorageSummaryPreference.java +++ /dev/null @@ -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); - } -} diff --git a/src/com/android/settings/deviceinfo/storage/StorageUsageProgressBarPreferenceController.java b/src/com/android/settings/deviceinfo/storage/StorageUsageProgressBarPreferenceController.java index cfee6a435b7..766035307e9 100644 --- a/src/com/android/settings/deviceinfo/storage/StorageUsageProgressBarPreferenceController.java +++ b/src/com/android/settings/deviceinfo/storage/StorageUsageProgressBarPreferenceController.java @@ -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); - } } diff --git a/src/com/android/settings/deviceinfo/storage/StorageUtils.java b/src/com/android/settings/deviceinfo/storage/StorageUtils.java index 9b52fe803b1..f59c8ab50d1 100644 --- a/src/com/android/settings/deviceinfo/storage/StorageUtils.java +++ b/src/com/android/settings/deviceinfo/storage/StorageUtils.java @@ -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); + } }