Fix UI problems of PublicVolumeSettings
This change replaces StorageSummaryPreference with UsageProgressBarPreference. Bug: 215325625 Test: manual visual 1. Disable 'Files by Google' 2. Settings -> Storage -> select SD card -> Files 3. Option menu -> Storage Settings Change-Id: I5db8c5971429ccd444d6d898b1df2c09363455b0
This commit is contained in:
@@ -1,60 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:minHeight="?android:attr/listPreferredItemHeightSmall"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:paddingStart="@dimen/preference_no_icon_padding_start"
|
|
||||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
|
||||||
android:paddingTop="16dip"
|
|
||||||
android:paddingBottom="16dip"
|
|
||||||
android:background="?android:attr/selectableItemBackground">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@android:id/title"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:ellipsize="marquee"
|
|
||||||
android:fadingEdge="horizontal"
|
|
||||||
android:fontFamily="@*android:string/config_headlineFontFamily"
|
|
||||||
android:singleLine="true"
|
|
||||||
android:textAlignment="viewStart"
|
|
||||||
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Subhead"
|
|
||||||
android:textColor="?android:attr/colorAccent"
|
|
||||||
android:textSize="36sp"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@android:id/summary"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textAlignment="viewStart"
|
|
||||||
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Body1"
|
|
||||||
android:maxLines="10" />
|
|
||||||
|
|
||||||
<ProgressBar
|
|
||||||
android:id="@android:id/progress"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="8dp"
|
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:layout_marginBottom="8dp"
|
|
||||||
android:visibility="gone"
|
|
||||||
android:max="100"
|
|
||||||
style="?android:attr/progressBarStyleHorizontal" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
@@ -3540,8 +3540,6 @@
|
|||||||
|
|
||||||
<!-- Summary of a single storage volume used space. [CHAR LIMIT=24] -->
|
<!-- Summary of a single storage volume used space. [CHAR LIMIT=24] -->
|
||||||
<string name="storage_size_large"><xliff:g id="number" example="128">^1</xliff:g><small><small> <xliff:g id="unit" example="KB">^2</xliff:g></small></small></string>
|
<string name="storage_size_large"><xliff:g id="number" example="128">^1</xliff:g><small><small> <xliff:g id="unit" example="KB">^2</xliff:g></small></small></string>
|
||||||
<!-- Summary of a single storage volume total space. [CHAR LIMIT=48]-->
|
|
||||||
<string name="storage_volume_used">Used of <xliff:g id="total" example="32GB">%1$s</xliff:g></string>
|
|
||||||
|
|
||||||
<!-- Toast informing that storage mount operation was successful. [CHAR LIMIT=64]-->
|
<!-- Toast informing that storage mount operation was successful. [CHAR LIMIT=64]-->
|
||||||
<string name="storage_mount_success"><xliff:g id="name" example="SD card">%1$s</xliff:g> is mounted</string>
|
<string name="storage_mount_success"><xliff:g id="name" example="SD card">%1$s</xliff:g> is mounted</string>
|
||||||
|
@@ -28,8 +28,6 @@ import android.os.storage.StorageManager;
|
|||||||
import android.os.storage.VolumeInfo;
|
import android.os.storage.VolumeInfo;
|
||||||
import android.os.storage.VolumeRecord;
|
import android.os.storage.VolumeRecord;
|
||||||
import android.provider.DocumentsContract;
|
import android.provider.DocumentsContract;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.text.format.Formatter;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@@ -40,8 +38,10 @@ import androidx.preference.PreferenceScreen;
|
|||||||
import com.android.internal.util.Preconditions;
|
import com.android.internal.util.Preconditions;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
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.MountTask;
|
||||||
import com.android.settings.deviceinfo.storage.StorageUtils.UnmountTask;
|
import com.android.settings.deviceinfo.storage.StorageUtils.UnmountTask;
|
||||||
|
import com.android.settingslib.widget.UsageProgressBarPreference;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -59,7 +59,7 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
|
|||||||
private VolumeInfo mVolume;
|
private VolumeInfo mVolume;
|
||||||
private DiskInfo mDisk;
|
private DiskInfo mDisk;
|
||||||
|
|
||||||
private StorageSummaryPreference mSummary;
|
private UsageProgressBarPreference mSummary;
|
||||||
|
|
||||||
private Preference mMount;
|
private Preference mMount;
|
||||||
private Preference mFormatPublic;
|
private Preference mFormatPublic;
|
||||||
@@ -114,7 +114,7 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
|
|||||||
addPreferencesFromResource(R.xml.device_info_storage_volume);
|
addPreferencesFromResource(R.xml.device_info_storage_volume);
|
||||||
getPreferenceScreen().setOrderingAsAdded(true);
|
getPreferenceScreen().setOrderingAsAdded(true);
|
||||||
|
|
||||||
mSummary = new StorageSummaryPreference(getPrefContext());
|
mSummary = new UsageProgressBarPreference(getPrefContext());
|
||||||
|
|
||||||
mMount = buildAction(R.string.storage_menu_mount);
|
mMount = buildAction(R.string.storage_menu_mount);
|
||||||
mUnmount = new Button(getActivity());
|
mUnmount = new Button(getActivity());
|
||||||
@@ -162,12 +162,10 @@ public class PublicVolumeSettings extends SettingsPreferenceFragment {
|
|||||||
final long freeBytes = file.getFreeSpace();
|
final long freeBytes = file.getFreeSpace();
|
||||||
final long usedBytes = totalBytes - freeBytes;
|
final long usedBytes = totalBytes - freeBytes;
|
||||||
|
|
||||||
final Formatter.BytesResult result = Formatter.formatBytes(getResources(), usedBytes,
|
mSummary.setUsageSummary(StorageUtils.getStorageSummary(
|
||||||
0);
|
context, R.string.storage_usage_summary, usedBytes));
|
||||||
mSummary.setTitle(TextUtils.expandTemplate(getText(R.string.storage_size_large),
|
mSummary.setTotalSummary(StorageUtils.getStorageSummary(
|
||||||
result.value, result.units));
|
context, R.string.storage_total_summary, totalBytes));
|
||||||
mSummary.setSummary(getString(R.string.storage_volume_used,
|
|
||||||
Formatter.formatFileSize(context, totalBytes)));
|
|
||||||
mSummary.setPercent(usedBytes, totalBytes);
|
mSummary.setPercent(usedBytes, totalBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -18,7 +18,6 @@ package com.android.settings.deviceinfo.storage;
|
|||||||
|
|
||||||
import android.app.usage.StorageStatsManager;
|
import android.app.usage.StorageStatsManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.format.Formatter;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
@@ -113,16 +112,10 @@ public class StorageUsageProgressBarPreferenceController extends BasePreferenceC
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mIsUpdateStateFromSelectedStorageEntry = false;
|
mIsUpdateStateFromSelectedStorageEntry = false;
|
||||||
mUsageProgressBarPreference.setUsageSummary(
|
mUsageProgressBarPreference.setUsageSummary(StorageUtils.getStorageSummary(
|
||||||
getStorageSummary(R.string.storage_usage_summary, mUsedBytes));
|
mContext, R.string.storage_usage_summary, mUsedBytes));
|
||||||
mUsageProgressBarPreference.setTotalSummary(
|
mUsageProgressBarPreference.setTotalSummary(StorageUtils.getStorageSummary(
|
||||||
getStorageSummary(R.string.storage_total_summary, mTotalBytes));
|
mContext, R.string.storage_total_summary, mTotalBytes));
|
||||||
mUsageProgressBarPreference.setPercent(mUsedBytes, 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -199,7 +199,7 @@ public class StorageUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Shows information about system storage. */
|
/** Shows information about system storage. */
|
||||||
public static class SystemInfoFragment extends InstrumentedDialogFragment {
|
public static class SystemInfoFragment extends InstrumentedDialogFragment {
|
||||||
/** Shows the fragment. */
|
/** Shows the fragment. */
|
||||||
public static void show(Fragment parent) {
|
public static void show(Fragment parent) {
|
||||||
@@ -224,4 +224,11 @@ public class StorageUtils {
|
|||||||
.create();
|
.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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user