Add ASM enabled/disabled text to the Storage settings.

Bug: 33199077
Test: Settings Robo Tests
Change-Id: I86897c63b584d3c8be171723367a6b4e060684f3
This commit is contained in:
Daniel Nishi
2017-01-10 15:58:26 -08:00
parent b465005c29
commit a3494347e4
5 changed files with 118 additions and 36 deletions

View File

@@ -17,58 +17,71 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical" android:gravity="center_vertical"
android:background="?android:attr/selectableItemBackground"> android:orientation="horizontal" >
<LinearLayout android:layout_width="wrap_content" <LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:layout_weight="1"
android:minHeight="?android:attr/listPreferredItemHeightSmall" android:enabled="false"
android:gravity="center_vertical" android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:orientation="vertical"
android:paddingStart="@dimen/preference_no_icon_padding_start" android:paddingStart="@dimen/preference_no_icon_padding_start"
android:paddingEnd="@dimen/storage_summary_padding_end" android:paddingEnd="@dimen/storage_summary_padding_end"
android:paddingTop="16dip" android:paddingTop="16dp"
android:paddingBottom="16dip" android:paddingBottom="16dp" >
android:enabled="false">
<TextView <TextView
android:id="@android:id/title" 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:layout_height="wrap_content"
android:singleLine="true" android:singleLine="true"
android:textAlignment="viewStart" android:textAlignment="viewStart"
android:textAppearance="@android:style/TextAppearance.Material.Subhead" android:textAppearance="@android:style/TextAppearance.Material.Subhead"
android:textColor="?android:attr/colorAccent" android:textColor="?android:attr/colorAccent"
android:textSize="36sp" android:textSize="36sp" />
android:ellipsize="marquee"
android:fadingEdge="horizontal" />
<TextView <TextView
android:id="@android:id/summary" android:id="@android:id/summary"
android:layout_marginStart="4dp" android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:maxLines="10"
android:textAlignment="viewStart" android:textAlignment="viewStart"
android:textAppearance="@android:style/TextAppearance.Material.Body1" android:textAppearance="@android:style/TextAppearance.Material.Body1" />
android:maxLines="10" />
<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 <Button
android:id="@+id/deletion_helper_button" android:id="@+id/deletion_helper_button"
android:theme="@style/FreeUpStorageButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@android:id/summary" 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> </LinearLayout>
<com.android.settings.widget.DonutView <com.android.settings.widget.DonutView
android:id="@+id/donut" android:id="@+id/donut"
android:layout_width="100dp" android:layout_width="100dp"
android:layout_height="100dp" android:layout_height="100dp"
android:layout_marginEnd="48dp"
android:gravity="end|center_vertical"
android:minWidth="58dp"
android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" />
android:minWidth="58dip"
android:gravity="end|center_vertical"/>
</LinearLayout> </LinearLayout>

View File

@@ -8029,4 +8029,13 @@
<!-- The percent of storage used by a storage volume. Exposed inside of a donut graph. [CHAR LIMIT=4]--> <!-- 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> <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> </resources>

View File

@@ -438,9 +438,4 @@
<style name="AppActionPrimaryButton" parent="android:Widget.Material.Button.Colored"/> <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> </resources>

View File

@@ -18,17 +18,27 @@ package com.android.settings.deviceinfo.storage;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Typeface;
import android.os.storage.StorageManager; import android.os.storage.StorageManager;
import android.provider.Settings;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder; 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.AttributeSet;
import android.util.MathUtils; import android.util.MathUtils;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.widget.DonutView; import com.android.settings.widget.DonutView;
import java.util.Locale;
/** /**
* StorageSummaryDonutPreference is a preference which summarizes the used and remaining storage left * 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. * on a given storage volume. It is visualized with a donut graphing the % used.
@@ -68,6 +78,23 @@ public class StorageSummaryDonutPreference extends Preference implements View.On
if (deletionHelperButton != null) { if (deletionHelperButton != null) {
deletionHelperButton.setOnClickListener(this); 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 @Override
@@ -77,4 +104,16 @@ public class StorageSummaryDonutPreference extends Preference implements View.On
getContext().startActivity(intent); 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);
}
}
} }

View File

@@ -22,9 +22,14 @@ import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
import android.os.storage.VolumeInfo; import android.os.storage.VolumeInfo;
import android.provider.Settings;
import android.support.v7.preference.PreferenceViewHolder;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner; import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig; import com.android.settings.TestConfig;
import com.android.settingslib.deviceinfo.StorageVolumeProvider; import com.android.settingslib.deviceinfo.StorageVolumeProvider;
@@ -41,11 +46,10 @@ import java.io.File;
@RunWith(SettingsRobolectricTestRunner.class) @RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) @Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class StorageSummaryDonutPreferenceControllerTest { public class StorageSummaryDonutPreferenceControllerTest {
private static String KEY = "pref";
private Context mContext; private Context mContext;
private StorageSummaryDonutPreferenceController mController; private StorageSummaryDonutPreferenceController mController;
private StorageSummaryDonutPreference mPreference; private StorageSummaryDonutPreference mPreference;
private PreferenceViewHolder mHolder;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@@ -54,7 +58,11 @@ public class StorageSummaryDonutPreferenceControllerTest {
mPreference = new StorageSummaryDonutPreference(mContext); mPreference = new StorageSummaryDonutPreference(mContext);
LayoutInflater inflater = LayoutInflater.from(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 @Test
@@ -91,4 +99,22 @@ public class StorageSummaryDonutPreferenceControllerTest {
assertThat(mPreference.getTitle().toString()).isEqualTo("9.00KB used"); assertThat(mPreference.getTitle().toString()).isEqualTo("9.00KB used");
assertThat(mPreference.getSummary().toString()).isEqualTo("1.00KB free"); 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");
}
} }