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

Commit 03dfa509 authored by Matthew Fritze's avatar Matthew Fritze
Browse files

Replace dynamic summary text for SettingPref

All SettingPrefs that have dynamic summaries are replaced
by placeholder text. Changes are for:
- Battery Saver "Turn on automatically"
- Notification "Dock speaker plays"
- Notification "Emergency tone"

Bug: 36101902
Test: make RunSettingsRoboTests
Change-Id: Ic2556055c155989015dbef6b507d3e3b45b779b5
parent 8fc602fe
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -22,6 +22,6 @@
    <DropDownPreference
            android:key="turn_on_automatically"
            android:title="@string/battery_saver_turn_on_automatically_title"
            android:summary="%s" />
            android:summary="@string/summary_placeholder" />

</PreferenceScreen>
+2 −2
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@
        <DropDownPreference
          android:key="dock_audio_media"
          android:title="@string/dock_audio_media_title"
          android:summary="%s" />
          android:summary="@string/summary_placeholder" />

        <!-- Boot sounds -->
        <SwitchPreference
@@ -135,7 +135,7 @@
        <DropDownPreference
          android:key="emergency_tone"
          android:title="@string/emergency_tone_title"
          android:summary="%s" />
          android:summary="@string/summary_placeholder" />

        <com.android.settingslib.RestrictedPreference
          android:key="cell_broadcast_settings"
+0 −1
Original line number Diff line number Diff line
@@ -99,7 +99,6 @@ public class BatterySaverSettings extends SettingsPreferenceFragment
            }
        };
        mTriggerPref.init(this);

        mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
    }

+13 −0
Original line number Diff line number Diff line
@@ -121,6 +121,19 @@ public class SettingPref {
        if (mTwoState != null) {
            mTwoState.setChecked(val != 0);
        } else if (mDropDown != null) {
            if (mValues != null) {
                int index = 0;
                for (int len = mValues.length; index < len; index++) {
                    if (mValues[index] == val) {
                        break;
                    }
                }

                if (index < mValues.length) {
                    CharSequence entry = mDropDown.getEntries()[index];
                    mDropDown.setSummary(entry);
                }
            }
            mDropDown.setValue(Integer.toString(val));
        }
    }
+67 −0
Original line number Diff line number Diff line
package com.android.settings.notification;

import android.content.res.Resources;

import android.content.Context;
import android.provider.Settings;
import android.support.v7.preference.DropDownPreference;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;

@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SettingPrefTest {

    @Test
    public void update_setsDropDownSummaryText() {
        Context context = RuntimeEnvironment.application;
        String testSetting = "test_setting";
        int[] values = new int[] {1,2,3};
        String[] entries = new String[] {"one", "two", "three"};
        SettingPref settingPref =
                spy(new SettingPref(SettingPref.TYPE_GLOBAL, "key", testSetting, 0, values) {
                    @Override
                    protected String getCaption(Resources res, int value) {
                        return "temp";
                    }
                });
        DropDownPreference dropdownPref = spy(new DropDownPreference(context));
        dropdownPref.setEntries(entries);
        settingPref.mDropDown = dropdownPref;
        Settings.Global.putInt(context.getContentResolver(), testSetting, values[2]);

        settingPref.update(context);

        assertThat(settingPref.mDropDown.getSummary()).isEqualTo(entries[2]);
    }

    @Test
    public void update_setsDropDownSummaryText_noMatch_noError() {
        Context context = RuntimeEnvironment.application;
        String testSetting = "test_setting";
        int[] values = new int[] {1,2,3};
        String[] entries = new String[] {"one", "two", "three"};
        SettingPref settingPref =
                spy(new SettingPref(SettingPref.TYPE_GLOBAL, "key", testSetting, 0, values) {
                    @Override
                    protected String getCaption(Resources res, int value) {
                        return "temp";
                    }
                });
        DropDownPreference dropdownPref = spy(new DropDownPreference(context));
        dropdownPref.setEntries(entries);
        settingPref.mDropDown = dropdownPref;
        Settings.Global.putInt(context.getContentResolver(), testSetting, -1);

        settingPref.update(context);

        assertThat(settingPref.mDropDown.getSummary()).isNull();
    }
}