Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8f969665 authored by Daniel Nishi's avatar Daniel Nishi Committed by Android (Google) Code Review
Browse files

Merge "Add ASM enabled/disabled text to the Storage settings."

parents 40cd0492 a3494347
Loading
Loading
Loading
Loading
+40 −27
Original line number Diff line number Diff line
@@ -17,58 +17,71 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
              android:orientation="horizontal"
    android:background="?android:attr/selectableItemBackground"
    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:orientation="vertical"
                  android:minHeight="?android:attr/listPreferredItemHeightSmall"
        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="16dip"
                  android:paddingBottom="16dip"
                  android:enabled="false">
        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_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="4dp"
            android:layout_width="wrap_content"
            android:layout_marginEnd="4dp"
            android:maxLines="10"
            android:textAlignment="viewStart"
            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"
            android:maxLines="10" />
            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>
+9 −0
Original line number Diff line number Diff line
@@ -8033,4 +8033,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>
+0 −5
Original line number Diff line number Diff line
@@ -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>
+39 −0
Original line number Diff line number Diff line
@@ -18,17 +18,27 @@ package com.android.settings.deviceinfo.storage;

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 @@ public class StorageSummaryDonutPreference extends Preference implements View.On
        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 @@ public class StorageSummaryDonutPreference extends Preference implements View.On
            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);
        }
    }
}
+29 −3
Original line number Diff line number Diff line
@@ -22,9 +22,14 @@ import static org.mockito.Mockito.when;

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 @@ import java.io.File;
@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 @@ public class StorageSummaryDonutPreferenceControllerTest {
        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 @@ public class StorageSummaryDonutPreferenceControllerTest {
        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");
    }
}