Allow appending static preferences to RadioButtonPickerFragment

This makes it so that static preferences can also be added after
the candidates so they can show up on the bottom of the screen.
This is done via a new xml tag for the preference screen that
is usually mostly empty that RaiodButtonPickerFragments use

Test: robotests
Bug: 111450127
Change-Id: I0fe2f480f0ff59b9bf9269e94b33ab4b008b47b8
This commit is contained in:
Salvador Martinez
2018-12-04 14:13:10 -08:00
parent bccad4abd8
commit 42e9d26635
9 changed files with 163 additions and 7 deletions

View File

@@ -18,6 +18,7 @@ package com.android.settings.core;
import static com.android.settings.core.PreferenceXmlParserUtils
.METADATA_ALLOW_DYNAMIC_SUMMARY_IN_SLICE;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_APPEND;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_KEY;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_KEYWORDS;
import static com.android.settings.core.PreferenceXmlParserUtils.METADATA_SEARCHABLE;
@@ -315,6 +316,32 @@ public class PreferenceXmlParserUtilsTest {
}
}
@Test
@Config(qualifiers = "mcc999")
public void extractMetadata_requestAppendProperty_shouldDefaultToFalse()
throws Exception {
final List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
R.xml.display_settings,
MetadataFlag.FLAG_INCLUDE_PREF_SCREEN | MetadataFlag.FLAG_NEED_PREF_APPEND);
for (Bundle bundle : metadata) {
assertThat(bundle.getBoolean(METADATA_APPEND)).isFalse();
}
}
@Test
@Config(qualifiers = "mcc999")
public void extractMetadata_requestAppendProperty_shouldReturnCorrectValue()
throws Exception {
final List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(mContext,
R.xml.battery_saver_schedule_settings,
MetadataFlag.FLAG_INCLUDE_PREF_SCREEN | MetadataFlag.FLAG_NEED_PREF_APPEND);
for (Bundle bundle : metadata) {
assertThat(bundle.getBoolean(METADATA_APPEND)).isTrue();
}
}
/**
* @param resId the ID for the XML preference
* @return an XML resource parser that points to the start tag

View File

@@ -209,6 +209,7 @@ public class ColorModePreferenceFragmentTest {
@Test
public void onCreatePreferences_useNewTitle_shouldAddColorModePreferences() {
when(mFragment.getContext()).thenReturn(RuntimeEnvironment.application);
doNothing().when(mFragment).addPreferencesFromResource(anyInt());
doNothing().when(mFragment).updateCandidates();

View File

@@ -18,6 +18,7 @@ package com.android.settings.widget;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -37,7 +38,9 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
@@ -98,6 +101,26 @@ public class RadioButtonPickerFragmentTest {
assertThat(mFragment.setDefaultKeyCalled).isTrue();
}
@Test
public void staticPreferencesPrepended_addedFirst() {
mFragment.mAppendStaticPreferences = false;
mFragment.updateCandidates();
InOrder inOrder = Mockito.inOrder(mFragment);
inOrder.verify(mFragment).addStaticPreferences(any());
inOrder.verify(mFragment).getRadioButtonPreferenceCustomLayoutResId();
}
@Test
public void staticPreferencesAppended_addedLast() {
mFragment.mAppendStaticPreferences = true;
mFragment.updateCandidates();
InOrder inOrder = Mockito.inOrder(mFragment);
inOrder.verify(mFragment).mayCheckOnlyRadioButton();
inOrder.verify(mFragment).addStaticPreferences(any());
}
@Test
public void shouldHaveNoCustomPreferenceLayout() {
assertThat(mFragment.getRadioButtonPreferenceCustomLayoutResId()).isEqualTo(0);