Merge "Add summary and footer message for the ScreenResolutionFragment." into tm-dev
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d16a63e..fc2cb54 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2919,6 +2919,8 @@
<string name="screen_resolution_summary_high">1080p FHD+</string>
<!-- Display settings screen, "QHD+" screen resolution summary [CHAR LIMIT=NONE] -->
<string name="screen_resolution_summary_highest">1440p QHD+</string>
+ <!-- The footer message for switch screen resolution [CHAR LIMIT=NONE] -->
+ <string name="screen_resolution_footer">Switching your resolution might cause some apps currently running to close.</string>
<!-- Display settings screen, Color mode settings title [CHAR LIMIT=30] -->
<string name="color_mode_title">Colors</string>
diff --git a/src/com/android/settings/display/ScreenResolutionFragment.java b/src/com/android/settings/display/ScreenResolutionFragment.java
index 3195772..3b08ae7 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.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 @@
private Display mDefaultDisplay;
private String[] mScreenResolutionOptions;
private Set<Point> mResolutions;
+ private String[] mScreenResolutionSummaries;
private IllustrationPreference mImagePreference;
@@ -67,6 +70,8 @@
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 @@
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 @@
candidates.add(
new ScreenResolutionCandidateInfo(
mScreenResolutionOptions[i],
+ mScreenResolutionSummaries[i],
mScreenResolutionOptions[i],
true /* enabled */));
}
@@ -134,9 +158,9 @@
/** 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 @@
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 @@
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 225a1d9..b7d37df 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 @@
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.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 @@
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();
+ }
}