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:
@@ -126,6 +126,7 @@ public abstract class DefaultAppPickerFragment extends InstrumentedPreferenceFra
|
|||||||
pref.setOnClickListener(this);
|
pref.setOnClickListener(this);
|
||||||
screen.addPreference(pref);
|
screen.addPreference(pref);
|
||||||
}
|
}
|
||||||
|
mayCheckOnlyRadioButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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() {
|
protected boolean shouldShowItemNone() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -106,6 +106,18 @@ public class DefaultAppPickerFragmentTest {
|
|||||||
mFragment.onRadioButtonClicked(pref);
|
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 {
|
public static class TestFragment extends DefaultAppPickerFragment {
|
||||||
|
|
||||||
boolean setDefaultAppKeyCalled;
|
boolean setDefaultAppKeyCalled;
|
||||||
|
Reference in New Issue
Block a user