Search in sources :

Example 26 with RadioButtonPreference

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();
}
Also used : RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference) Test(org.junit.Test)

Example 27 with RadioButtonPreference

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();
}
Also used : RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference) Test(org.junit.Test)

Example 28 with RadioButtonPreference

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));
                }
            }
        }
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Preference(androidx.preference.Preference) RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference) RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference)

Example 29 with RadioButtonPreference

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);
}
Also used : DefaultAppInfo(com.android.settingslib.applications.DefaultAppInfo) RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference) Test(org.junit.Test)

Example 30 with RadioButtonPreference

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;
}
Also used : AppOpsManager(android.app.AppOpsManager) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) MetricsFeatureProvider(com.android.settingslib.core.instrumentation.MetricsFeatureProvider) Drawable(android.graphics.drawable.Drawable) ShadowActivityManager(com.android.settings.testutils.shadow.ShadowActivityManager) MockitoAnnotations(org.mockito.MockitoAnnotations) ReflectionHelpers(org.robolectric.util.ReflectionHelpers) AppUtils(com.android.settingslib.applications.AppUtils) Mockito.doAnswer(org.mockito.Mockito.doAnswer) After(org.junit.After) RecyclerView(androidx.recyclerview.widget.RecyclerView) Mockito.doReturn(org.mockito.Mockito.doReturn) R(com.android.settings.R) EXTRA_SHOW_FRAGMENT_ARGUMENTS(com.android.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS) RuntimeEnvironment(org.robolectric.RuntimeEnvironment) FooterPreference(com.android.settingslib.widget.FooterPreference) RobolectricTestRunner(org.robolectric.RobolectricTestRunner) SettingsActivity(com.android.settings.SettingsActivity) EntityHeaderController(com.android.settings.widget.EntityHeaderController) ApplicationInfo(android.content.pm.ApplicationInfo) ShadowEntityHeaderController(com.android.settings.testutils.shadow.ShadowEntityHeaderController) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Context(android.content.Context) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) LayoutPreference(com.android.settingslib.widget.LayoutPreference) Mock(org.mockito.Mock) Pair(android.util.Pair) RunWith(org.junit.runner.RunWith) Config(org.robolectric.annotation.Config) Intent(android.content.Intent) Mockito.spy(org.mockito.Mockito.spy) LoaderManager(androidx.loader.app.LoaderManager) FragmentActivity(androidx.fragment.app.FragmentActivity) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) UserHandle(android.os.UserHandle) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Before(org.junit.Before) Answers(org.mockito.Answers) SettingsEnums(android.app.settings.SettingsEnums) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ApplicationsState(com.android.settingslib.applications.ApplicationsState) Truth.assertThat(com.google.common.truth.Truth.assertThat) InstantAppDataProvider(com.android.settingslib.applications.instantapps.InstantAppDataProvider) Preference(androidx.preference.Preference) Mockito.verify(org.mockito.Mockito.verify) FakeFeatureFactory(com.android.settings.testutils.FakeFeatureFactory) RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference) BatteryStats(android.os.BatteryStats) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) Drawable(android.graphics.drawable.Drawable) ApplicationInfo(android.content.pm.ApplicationInfo) Intent(android.content.Intent) FooterPreference(com.android.settingslib.widget.FooterPreference) LayoutPreference(com.android.settingslib.widget.LayoutPreference) Preference(androidx.preference.Preference) RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference) UserHandle(android.os.UserHandle) RecyclerView(androidx.recyclerview.widget.RecyclerView) FooterPreference(com.android.settingslib.widget.FooterPreference) SettingsActivity(com.android.settings.SettingsActivity) RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference) Before(org.junit.Before)

Aggregations

RadioButtonPreference (com.android.settingslib.widget.RadioButtonPreference)52 Test (org.junit.Test)27 Before (org.junit.Before)8 DefaultAppInfo (com.android.settingslib.applications.DefaultAppInfo)6 PreferenceScreen (androidx.preference.PreferenceScreen)5 CandidateInfo (com.android.settingslib.widget.CandidateInfo)3 Preference (androidx.preference.Preference)2 PreferenceCategory (androidx.preference.PreferenceCategory)2 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)2 FooterPreference (com.android.settingslib.widget.FooterPreference)2 AppOpsManager (android.app.AppOpsManager)1 SettingsEnums (android.app.settings.SettingsEnums)1 Context (android.content.Context)1 Intent (android.content.Intent)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageManager (android.content.pm.PackageManager)1 Resources (android.content.res.Resources)1 Drawable (android.graphics.drawable.Drawable)1 BatteryStats (android.os.BatteryStats)1 Bundle (android.os.Bundle)1