diff --git a/res/values/strings.xml b/res/values/strings.xml index 02bc5dd917d..1d69657ce36 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -2919,6 +2919,8 @@ 1080p FHD+ 1440p QHD+ + + Switching your resolution might cause some apps currently running to close. Colors diff --git a/src/com/android/settings/display/ScreenResolutionFragment.java b/src/com/android/settings/display/ScreenResolutionFragment.java index 31957723752..3b08ae7f00b 100644 --- a/src/com/android/settings/display/ScreenResolutionFragment.java +++ b/src/com/android/settings/display/ScreenResolutionFragment.java @@ -36,7 +36,9 @@ import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.widget.RadioButtonPickerFragment; import com.android.settingslib.search.SearchIndexable; import com.android.settingslib.widget.CandidateInfo; +import com.android.settingslib.widget.FooterPreference; import com.android.settingslib.widget.IllustrationPreference; +import com.android.settingslib.widget.SelectorWithWidgetPreference; import java.util.ArrayList; import java.util.HashSet; @@ -55,6 +57,7 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment { private Display mDefaultDisplay; private String[] mScreenResolutionOptions; private Set mResolutions; + private String[] mScreenResolutionSummaries; private IllustrationPreference mImagePreference; @@ -67,6 +70,8 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment { mResources = context.getResources(); mScreenResolutionOptions = mResources.getStringArray(R.array.config_screen_resolution_options_strings); + mScreenResolutionSummaries = + mResources.getStringArray(R.array.config_screen_resolution_summaries_strings); mResolutions = getAllSupportedResolution(); mImagePreference = new IllustrationPreference(context); } @@ -80,6 +85,24 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment { protected void addStaticPreferences(PreferenceScreen screen) { updateIllustrationImage(mImagePreference); screen.addPreference(mImagePreference); + + final FooterPreference footerPreference = new FooterPreference(screen.getContext()); + footerPreference.setTitle(R.string.screen_resolution_footer); + footerPreference.setSelectable(false); + footerPreference.setLayoutResource(R.layout.preference_footer); + screen.addPreference(footerPreference); + } + + @Override + public void bindPreferenceExtra( + SelectorWithWidgetPreference pref, + String key, + CandidateInfo info, + String defaultKey, + String systemDefaultKey) { + final ScreenResolutionCandidateInfo candidateInfo = (ScreenResolutionCandidateInfo) info; + final CharSequence summary = candidateInfo.loadSummary(); + if (summary != null) pref.setSummary(summary); } @Override @@ -90,6 +113,7 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment { candidates.add( new ScreenResolutionCandidateInfo( mScreenResolutionOptions[i], + mScreenResolutionSummaries[i], mScreenResolutionOptions[i], true /* enabled */)); } @@ -134,9 +158,9 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment { /** Get the key corresponding to the resolution. */ @VisibleForTesting String getKeyForResolution(int width) { - return width == FHD_WIDTH - ? mScreenResolutionOptions[FHD_INDEX] - : width == QHD_WIDTH ? mScreenResolutionOptions[QHD_INDEX] : null; + return width == FHD_WIDTH ? mScreenResolutionOptions[FHD_INDEX] + : width == QHD_WIDTH ? mScreenResolutionOptions[QHD_INDEX] + : null; } @Override @@ -175,13 +199,17 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment { return SettingsEnums.SCREEN_RESOLUTION; } - static class ScreenResolutionCandidateInfo extends CandidateInfo { + /** This is an extension of the CandidateInfo class, which adds summary information. */ + public static class ScreenResolutionCandidateInfo extends CandidateInfo { private final CharSequence mLabel; + private final CharSequence mSummary; private final String mKey; - ScreenResolutionCandidateInfo(CharSequence label, String key, boolean enabled) { + ScreenResolutionCandidateInfo( + CharSequence label, CharSequence summary, String key, boolean enabled) { super(enabled); mLabel = label; + mSummary = summary; mKey = key; } @@ -190,6 +218,11 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment { return mLabel; } + /** It is the summary for radio options. */ + public CharSequence loadSummary() { + return mSummary; + } + @Override public Drawable loadIcon() { return null; diff --git a/tests/unit/src/com/android/settings/display/ScreenResolutionFragmentTest.java b/tests/unit/src/com/android/settings/display/ScreenResolutionFragmentTest.java index 225a1d9a216..b7d37df0d19 100644 --- a/tests/unit/src/com/android/settings/display/ScreenResolutionFragmentTest.java +++ b/tests/unit/src/com/android/settings/display/ScreenResolutionFragmentTest.java @@ -18,6 +18,7 @@ package com.android.settings.display; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; @@ -28,6 +29,8 @@ import androidx.test.annotation.UiThreadTest; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; +import com.android.settingslib.widget.SelectorWithWidgetPreference; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -87,4 +90,19 @@ public class ScreenResolutionFragmentTest { verify(mFragment).setDisplayMode(QHD_WIDTH); } + + @Test + @UiThreadTest + public void bindPreferenceExtra_setSummary() { + mFragment.onAttach(mContext); + SelectorWithWidgetPreference preference = new SelectorWithWidgetPreference(mContext); + ScreenResolutionFragment.ScreenResolutionCandidateInfo candidates = + mock(ScreenResolutionFragment.ScreenResolutionCandidateInfo.class); + CharSequence summary = "test summary"; + doReturn(summary).when(candidates).loadSummary(); + + mFragment.bindPreferenceExtra(preference, "com.example.test", candidates, null, null); + + assertThat(preference.getSummary().toString().contentEquals(summary)).isTrue(); + } }