Add ASM enabled/disabled text to the Storage settings.
Bug: 33199077
Test: Settings Robo Tests
Change-Id: I86897c63b584d3c8be171723367a6b4e060684f3
diff --git a/res/layout/storage_summary_donut.xml b/res/layout/storage_summary_donut.xml
index d9ead9c..eadb6e5 100644
--- a/res/layout/storage_summary_donut.xml
+++ b/res/layout/storage_summary_donut.xml
@@ -15,60 +15,73 @@
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- android:gravity="center_vertical"
- android:background="?android:attr/selectableItemBackground">
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:background="?android:attr/selectableItemBackground"
+ android:gravity="center_vertical"
+ android:orientation="horizontal" >
- <LinearLayout android:layout_width="wrap_content"
- 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="@dimen/storage_summary_padding_end"
- android:paddingTop="16dip"
- android:paddingBottom="16dip"
- android:enabled="false">
+ <LinearLayout
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:enabled="false"
+ android:gravity="center_vertical"
+ android:minHeight="?android:attr/listPreferredItemHeightSmall"
+ android:orientation="vertical"
+ android:paddingStart="@dimen/preference_no_icon_padding_start"
+ android:paddingEnd="@dimen/storage_summary_padding_end"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp" >
<TextView
android:id="@android:id/title"
- android:layout_width="wrap_content"
+ android:ellipsize="marquee"
+ android:fadingEdge="horizontal"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAlignment="viewStart"
android:textAppearance="@android:style/TextAppearance.Material.Subhead"
android:textColor="?android:attr/colorAccent"
- android:textSize="36sp"
- android:ellipsize="marquee"
- android:fadingEdge="horizontal" />
+ android:textSize="36sp" />
<TextView
android:id="@android:id/summary"
- android:layout_marginStart="4dp"
- android:layout_width="wrap_content"
+ android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:layout_marginStart="4dp"
+ android:layout_marginEnd="4dp"
+ android:maxLines="10"
android:textAlignment="viewStart"
- android:textAppearance="@android:style/TextAppearance.Material.Body1"
- android:maxLines="10" />
+ android:textAppearance="@android:style/TextAppearance.Material.Body1" />
+
+ <TextView
+ android:id="@+id/storage_manager_indicator"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="4dp"
+ android:layout_marginEnd="4dp"
+ android:textAlignment="viewStart"
+ android:textAppearance="@android:style/TextAppearance.Material.Body1"/>
<Button
android:id="@+id/deletion_helper_button"
- android:theme="@style/FreeUpStorageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@android:id/summary"
- android:text="@string/storage_menu_free"/>
+ android:text="@string/storage_menu_free"
+ style="@android:style/@Widget.Material.Button.Colored" />
</LinearLayout>
<com.android.settings.widget.DonutView
android:id="@+id/donut"
android:layout_width="100dp"
android:layout_height="100dp"
+ android:layout_marginEnd="48dp"
+ android:gravity="end|center_vertical"
+ android:minWidth="58dp"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
- android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
- android:minWidth="58dip"
- android:gravity="end|center_vertical"/>
+ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" />
</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 73c7e3b..47dd09b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -8029,4 +8029,13 @@
<!-- The percent of storage used by a storage volume. Exposed inside of a donut graph. [CHAR LIMIT=4]-->
<string name="storage_percent_used"><xliff:g id="percent" example="50%">%1$s</xliff:g>%%</string>
+ <!-- Indicates if the automatic storage manager is enabled or not. [CHAR_LIMIT=40] -->
+ <string name="storage_manager_indicator">Storage Manager: <xliff:g id="status" example="on">^1</xliff:g></string>
+
+ <!-- Off status for the automatic storage manager. [CHAR_LIMIT=10] -->
+ <string name="storage_manager_indicator_off">Off</string>
+
+ <!-- On status for the automatic storage manager. [CHAR_LIMIT=10] -->
+ <string name="storage_manager_indicator_on">On</string>
+
</resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index a4a679b..29cb390 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -438,9 +438,4 @@
<style name="AppActionPrimaryButton" parent="android:Widget.Material.Button.Colored"/>
- <style name="FreeUpStorageButton">
- <item name="android:buttonStyle">@android:style/Widget.Material.Button</item>
- <item name="android:colorButtonNormal">#fff</item>
- </style>
-
</resources>
diff --git a/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreference.java b/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreference.java
index 9e39034..12e76b2 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreference.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreference.java
@@ -18,17 +18,27 @@
import android.content.Context;
import android.content.Intent;
+import android.graphics.Typeface;
import android.os.storage.StorageManager;
+import android.provider.Settings;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
+import android.text.SpannableString;
+import android.text.Spanned;
+import android.text.TextPaint;
+import android.text.TextUtils;
+import android.text.style.StyleSpan;
import android.util.AttributeSet;
import android.util.MathUtils;
import android.view.View;
import android.widget.Button;
+import android.widget.TextView;
import com.android.settings.R;
import com.android.settings.widget.DonutView;
+import java.util.Locale;
+
/**
* 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.
@@ -68,6 +78,23 @@
if (deletionHelperButton != null) {
deletionHelperButton.setOnClickListener(this);
}
+
+ final TextView storageManagerText =
+ (TextView) view.findViewById(R.id.storage_manager_indicator);
+ if (storageManagerText != null) {
+ Context context = getContext();
+ final SpannableString templateSs = new SpannableString(
+ context.getString(R.string.storage_manager_indicator));
+ boolean isStorageManagerEnabled = Settings.Secure.getInt(context.getContentResolver(),
+ Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 0) != 0;
+ String value = isStorageManagerEnabled ?
+ context.getString(R.string.storage_manager_indicator_on) :
+ context.getString(R.string.storage_manager_indicator_off);
+ Locale locale = storageManagerText.getTextLocale();
+ final SpannableString ss = new SpannableString(value.toUpperCase(locale));
+ ss.setSpan(new BoldLinkSpan(), 0, value.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ storageManagerText.setText(TextUtils.expandTemplate(templateSs, ss));
+ }
}
@Override
@@ -77,4 +104,16 @@
getContext().startActivity(intent);
}
}
+
+ private static class BoldLinkSpan extends StyleSpan {
+ public BoldLinkSpan() {
+ super(Typeface.BOLD);
+ }
+
+ @Override
+ public void updateDrawState(TextPaint ds) {
+ super.updateDrawState(ds);
+ ds.setColor(ds.linkColor);
+ }
+ }
}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java
index 848616a..fa0851e 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceControllerTest.java
@@ -22,9 +22,14 @@
import android.content.Context;
import android.os.storage.VolumeInfo;
+import android.provider.Settings;
+import android.support.v7.preference.PreferenceViewHolder;
import android.view.LayoutInflater;
+import android.view.View;
import android.widget.LinearLayout;
+import android.widget.TextView;
+import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settingslib.deviceinfo.StorageVolumeProvider;
@@ -41,11 +46,10 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class StorageSummaryDonutPreferenceControllerTest {
- private static String KEY = "pref";
-
private Context mContext;
private StorageSummaryDonutPreferenceController mController;
private StorageSummaryDonutPreference mPreference;
+ private PreferenceViewHolder mHolder;
@Before
public void setUp() throws Exception {
@@ -54,7 +58,11 @@
mPreference = new StorageSummaryDonutPreference(mContext);
LayoutInflater inflater = LayoutInflater.from(mContext);
- inflater.inflate(mPreference.getLayoutResource(), new LinearLayout(mContext), false);
+ final View view =
+ inflater.inflate(
+ mPreference.getLayoutResource(), new LinearLayout(mContext), false);
+
+ mHolder = new PreferenceViewHolder(view);
}
@Test
@@ -91,4 +99,22 @@
assertThat(mPreference.getTitle().toString()).isEqualTo("9.00KB used");
assertThat(mPreference.getSummary().toString()).isEqualTo("1.00KB free");
}
+
+ @Test
+ public void testAutomaticStorageManagerLabelOff() throws Exception {
+ mPreference.onBindViewHolder(mHolder);
+ TextView asmTextView = (TextView) mHolder.findViewById(R.id.storage_manager_indicator);
+ assertThat(asmTextView.getText().toString()).isEqualTo("Storage Manager: OFF");
+ }
+
+ @Test
+ public void testAutomaticStorageManagerLabelOn() throws Exception {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.AUTOMATIC_STORAGE_MANAGER_ENABLED, 1);
+
+ mPreference.onBindViewHolder(mHolder);
+
+ TextView asmTextView = (TextView) mHolder.findViewById(R.id.storage_manager_indicator);
+ assertThat(asmTextView.getText().toString()).isEqualTo("Storage Manager: ON");
+ }
}