use of com.android.settingslib.widget.RadioButtonPreference in project android_packages_apps_Settings by omnirom.
the class RadioButtonPickerFragmentTest method clickPreference_shouldConfirm.
@Test
public void clickPreference_shouldConfirm() {
final RadioButtonPreference pref = new RadioButtonPreference(RuntimeEnvironment.application);
pref.setKey("TEST");
mFragment.onRadioButtonClicked(pref);
assertThat(mFragment.setDefaultKeyCalled).isTrue();
}
use of com.android.settingslib.widget.RadioButtonPreference in project android_packages_apps_Settings by omnirom.
the class RadioButtonPickerFragmentTest method displaySingleOption_shouldSelectRadioButton.
@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();
}
use of com.android.settingslib.widget.RadioButtonPreference in project android_packages_apps_Settings by omnirom.
the class RadioButtonPickerFragment method updateCheckedState.
public void updateCheckedState(String selectedKey) {
final PreferenceScreen screen = getPreferenceScreen();
if (screen != null) {
final int count = screen.getPreferenceCount();
for (int i = 0; i < count; i++) {
final Preference pref = screen.getPreference(i);
if (pref instanceof RadioButtonPreference) {
final RadioButtonPreference radioPref = (RadioButtonPreference) pref;
final boolean newCheckedState = TextUtils.equals(pref.getKey(), selectedKey);
if (radioPref.isChecked() != newCheckedState) {
radioPref.setChecked(TextUtils.equals(pref.getKey(), selectedKey));
}
}
}
}
}
use of com.android.settingslib.widget.RadioButtonPreference in project android_packages_apps_Settings by omnirom.
the class DefaultAppPickerFragmentTest method clickPreference_hasConfirmation_shouldShowConfirmation.
@Test
public void clickPreference_hasConfirmation_shouldShowConfirmation() {
mFragment.onAttach((Context) mActivity);
final RadioButtonPreference pref = new RadioButtonPreference(RuntimeEnvironment.application);
pref.setKey("TEST");
doReturn("confirmation_text").when(mFragment).getConfirmationMessage(any(DefaultAppInfo.class));
doReturn(mActivity).when(mFragment).getActivity();
mFragment.onRadioButtonClicked(pref);
}
use of com.android.settingslib.widget.RadioButtonPreference in project android_packages_apps_Settings by omnirom.
the class AdvancedPowerUsageDetailTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getPackageName()).thenReturn("foo");
mFeatureFactory = FakeFeatureFactory.setupForTest();
mMetricsFeatureProvider = mFeatureFactory.metricsFeatureProvider;
mFragment = spy(new AdvancedPowerUsageDetail());
doReturn(mContext).when(mFragment).getContext();
doReturn(mActivity).when(mFragment).getActivity();
doReturn(SUMMARY).when(mFragment).getString(anyInt());
doReturn(APP_LABEL).when(mBundle).getString(nullable(String.class));
when(mFragment.getArguments()).thenReturn(mBundle);
doReturn(mLoaderManager).when(mFragment).getLoaderManager();
when(mFeatureFactory.powerUsageFeatureProvider.isChartGraphEnabled(mContext)).thenReturn(true);
ShadowEntityHeaderController.setUseMock(mEntityHeaderController);
doReturn(mEntityHeaderController).when(mEntityHeaderController).setRecyclerView(nullable(RecyclerView.class), nullable(Lifecycle.class));
doReturn(mEntityHeaderController).when(mEntityHeaderController).setButtonActions(anyInt(), anyInt());
doReturn(mEntityHeaderController).when(mEntityHeaderController).setIcon(nullable(Drawable.class));
doReturn(mEntityHeaderController).when(mEntityHeaderController).setIcon(nullable(ApplicationsState.AppEntry.class));
doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(String.class));
doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(String.class));
doReturn(mEntityHeaderController).when(mEntityHeaderController).setLabel(nullable(ApplicationsState.AppEntry.class));
doReturn(mEntityHeaderController).when(mEntityHeaderController).setSummary(nullable(String.class));
when(mBatteryEntry.getUid()).thenReturn(UID);
when(mBatteryEntry.getLabel()).thenReturn(APP_LABEL);
when(mBatteryEntry.getTimeInBackgroundMs()).thenReturn(BACKGROUND_TIME_MS);
when(mBatteryEntry.getTimeInForegroundMs()).thenReturn(FOREGROUND_TIME_MS);
mBatteryEntry.iconId = ICON_ID;
mFragment.mHeaderPreference = mHeaderPreference;
mFragment.mState = mState;
mFragment.enableTriState = true;
mFragment.mBatteryUtils = new BatteryUtils(RuntimeEnvironment.application);
mFragment.mBatteryOptimizeUtils = mBatteryOptimizeUtils;
mAppEntry.info = mock(ApplicationInfo.class);
mTestActivity = spy(new SettingsActivity());
doReturn(mPackageManager).when(mTestActivity).getPackageManager();
doReturn(mPackageManager).when(mActivity).getPackageManager();
doReturn(mAppOpsManager).when(mTestActivity).getSystemService(Context.APP_OPS_SERVICE);
mBatteryUtils = spy(new BatteryUtils(mContext));
doReturn(FOREGROUND_SERVICE_TIME_US).when(mBatteryUtils).getForegroundServiceTotalTimeUs(any(BatteryStats.Uid.class), anyLong());
final ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
Answer<Void> callable = invocation -> {
mBundle = captor.getValue().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
System.out.println("mBundle = " + mBundle);
return null;
};
doAnswer(callable).when(mActivity).startActivityAsUser(captor.capture(), nullable(UserHandle.class));
doAnswer(callable).when(mActivity).startActivity(captor.capture());
mForegroundPreference = new Preference(mContext);
mBackgroundPreference = new Preference(mContext);
mFooterPreference = new FooterPreference(mContext);
mRestrictedPreference = new RadioButtonPreference(mContext);
mOptimizePreference = new RadioButtonPreference(mContext);
mUnrestrictedPreference = new RadioButtonPreference(mContext);
mFragment.mForegroundPreference = mForegroundPreference;
mFragment.mBackgroundPreference = mBackgroundPreference;
mFragment.mFooterPreference = mFooterPreference;
mFragment.mRestrictedPreference = mRestrictedPreference;
mFragment.mOptimizePreference = mOptimizePreference;
mFragment.mUnrestrictedPreference = mUnrestrictedPreference;
}
Aggregations