Checke radio on default app screen if there's 1 option only

Change-Id: Ib091eb033ce541dc6a6d97ef45a15a5eb957e405
Fix: 34746591
Test: make RunSettingsRoboTests -j40
This commit is contained in:
Fan Zhang
2017-02-08 12:52:48 -08:00
parent 2470b1e142
commit 4be105e9f4
2 changed files with 25 additions and 0 deletions

View File

@@ -126,6 +126,7 @@ public abstract class DefaultAppPickerFragment extends InstrumentedPreferenceFra
pref.setOnClickListener(this);
screen.addPreference(pref);
}
mayCheckOnlyRadioButton();
}
@Override
@@ -163,6 +164,18 @@ public abstract class DefaultAppPickerFragment extends InstrumentedPreferenceFra
}
}
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
void mayCheckOnlyRadioButton() {
final PreferenceScreen screen = getPreferenceScreen();
// If there is only 1 thing on screen, select it.
if (screen != null && screen.getPreferenceCount() == 1) {
final Preference onlyPref = screen.getPreference(0);
if (onlyPref instanceof RadioButtonPreference) {
((RadioButtonPreference) onlyPref).setChecked(true);
}
}
}
protected boolean shouldShowItemNone() {
return false;
}

View File

@@ -106,6 +106,18 @@ public class DefaultAppPickerFragmentTest {
mFragment.onRadioButtonClicked(pref);
}
@Test
public void displaySingleOption_shouldSelectRadioButton() {
final RadioButtonPreference pref =
new RadioButtonPreference(RuntimeEnvironment.application);
when(mScreen.getPreferenceCount()).thenReturn(1);
when(mScreen.getPreference(0)).thenReturn(pref);
mFragment.mayCheckOnlyRadioButton();
assertThat(pref.isChecked()).isTrue();
}
public static class TestFragment extends DefaultAppPickerFragment {
boolean setDefaultAppKeyCalled;