Add summary and footer message for the ScreenResolutionFragment.

Bug: b/199559703
Test: Check resolution switch UI in Settings app
      atest SettingsUnitTests:ScreenResolutionControllerTest
      atest SettingsUnitTests:ScreenResolutionFragmentTest
Change-Id: Iee1e74d3d4de81500b2abe62bc7e9bd69f55452c
(cherry picked from commit d633cd6b32)
Merged-In: Iee1e74d3d4de81500b2abe62bc7e9bd69f55452c
This commit is contained in:
Amy Hsu
2022-02-18 21:06:12 +08:00
parent 27ad4dcf23
commit 372bbdcf9c
3 changed files with 58 additions and 5 deletions

View File

@@ -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>

View File

@@ -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<Point> 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;

View File

@@ -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();
}
}