Search in sources :

Example 6 with RadioButtonPreference

use of com.android.settings.widget.RadioButtonPreference in project android_packages_apps_Settings by LineageOS.

the class WebViewAppPickerTest method testWebViewVersionAddedAfterLabel.

/**
 * Ensure that the version name of a WebView package is displayed after its name in the
 * preference title.
 */
@Test
public void testWebViewVersionAddedAfterLabel() throws PackageManager.NameNotFoundException {
    PackageItemInfo mockPackageItemInfo = mock(PackageItemInfo.class);
    mockPackageItemInfo.packageName = DEFAULT_PACKAGE_NAME;
    when(mockPackageItemInfo.loadLabel(any())).thenReturn("myPackage");
    DefaultAppInfo webviewAppInfo = mPicker.createDefaultAppInfo(mPackageManager, mockPackageItemInfo, "");
    PackageInfo packageInfo = new PackageInfo();
    packageInfo.versionName = "myVersionName";
    PackageManager pm = mock(PackageManager.class);
    when(pm.getPackageInfo(eq(DEFAULT_PACKAGE_NAME), anyInt())).thenReturn(packageInfo);
    when(mPackageManager.getPackageManager()).thenReturn(pm);
    RadioButtonPreference mockPreference = mock(RadioButtonPreference.class);
    mPicker.bindPreference(mockPreference, DEFAULT_PACKAGE_NAME, webviewAppInfo, null);
    mPicker.bindPreferenceExtra(mockPreference, DEFAULT_PACKAGE_NAME, webviewAppInfo, null, null);
    verify(mockPreference, times(1)).setTitle(eq("myPackage myVersionName"));
    verify(mockPreference, times(1)).setTitle(any());
}
Also used : PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) PackageItemInfo(android.content.pm.PackageItemInfo) DefaultAppInfo(com.android.settings.applications.defaultapps.DefaultAppInfo) RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) Test(org.junit.Test)

Example 7 with RadioButtonPreference

use of com.android.settings.widget.RadioButtonPreference in project android_packages_apps_Settings by LineageOS.

the class WebViewAppPickerTest method testFailingClickUpdatesSetting.

private void testFailingClickUpdatesSetting() {
    when(mWvusWrapper.getValidWebViewApplicationInfos(any())).thenReturn(Arrays.asList(createApplicationInfo(DEFAULT_PACKAGE_NAME)));
    when(mWvusWrapper.setWebViewProvider(eq(DEFAULT_PACKAGE_NAME))).thenReturn(false);
    RadioButtonPreference defaultPackagePref = mock(RadioButtonPreference.class);
    when(defaultPackagePref.getKey()).thenReturn(DEFAULT_PACKAGE_NAME);
    mPicker.onRadioButtonClicked(defaultPackagePref);
    verify(mWvusWrapper, times(1)).setWebViewProvider(eq(DEFAULT_PACKAGE_NAME));
    // Ensure we update the list of packages when we click a non-valid package - the list must
    // have changed, otherwise this click wouldn't fail.
    verify(mPicker, times(1)).updateCandidates();
    verify(mWvusWrapper, times(1)).showInvalidChoiceToast(any());
}
Also used : RadioButtonPreference(com.android.settings.widget.RadioButtonPreference)

Example 8 with RadioButtonPreference

use of com.android.settings.widget.RadioButtonPreference in project android_packages_apps_Settings by omnirom.

the class NetworkScorerPicker method updateCheckedState.

private void updateCheckedState(String selectedKey) {
    final PreferenceScreen screen = getPreferenceScreen();
    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;
            radioPref.setChecked(TextUtils.equals(pref.getKey(), selectedKey));
        }
    }
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) Preference(android.support.v7.preference.Preference) RadioButtonPreference(com.android.settings.widget.RadioButtonPreference)

Example 9 with RadioButtonPreference

use of com.android.settings.widget.RadioButtonPreference in project android_packages_apps_Settings by omnirom.

the class NetworkScorerPicker method updateCandidates.

@VisibleForTesting
public void updateCandidates() {
    final PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();
    final List<NetworkScorerAppData> scorers = mNetworkScoreManager.getAllValidScorers();
    final String defaultAppKey = getActiveScorerPackage();
    final RadioButtonPreference nonePref = new RadioButtonPreference(getPrefContext());
    nonePref.setTitle(R.string.network_scorer_picker_none_preference);
    if (scorers.isEmpty()) {
        nonePref.setChecked(true);
    } else {
        nonePref.setKey(null);
        nonePref.setChecked(TextUtils.isEmpty(defaultAppKey));
        nonePref.setOnClickListener(this);
    }
    screen.addPreference(nonePref);
    final int numScorers = scorers.size();
    for (int i = 0; i < numScorers; i++) {
        final RadioButtonPreference pref = new RadioButtonPreference(getPrefContext());
        final NetworkScorerAppData appData = scorers.get(i);
        final String appKey = appData.getRecommendationServicePackageName();
        pref.setTitle(appData.getRecommendationServiceLabel());
        pref.setKey(appKey);
        pref.setChecked(TextUtils.equals(defaultAppKey, appKey));
        pref.setOnClickListener(this);
        screen.addPreference(pref);
    }
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) NetworkScorerAppData(android.net.NetworkScorerAppData) RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) VisibleForTesting(android.support.annotation.VisibleForTesting)

Example 10 with RadioButtonPreference

use of com.android.settings.widget.RadioButtonPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class PreventRingingGesturePreferenceControllerTest method testRadioButtonClicked_mute.

@Test
public void testRadioButtonClicked_mute() {
    RadioButtonPreference rbPref = new RadioButtonPreference(mContext);
    rbPref.setKey(PreventRingingGesturePreferenceController.KEY_MUTE);
    Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE, Settings.Secure.VOLUME_HUSH_OFF);
    mController.onRadioButtonClicked(rbPref);
    assertThat(Settings.Secure.VOLUME_HUSH_MUTE).isEqualTo(Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE, Settings.Secure.VOLUME_HUSH_OFF));
}
Also used : RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) Test(org.junit.Test)

Aggregations

RadioButtonPreference (com.android.settings.widget.RadioButtonPreference)109 Test (org.junit.Test)68 NetworkScorerAppData (android.net.NetworkScorerAppData)18 PreferenceScreen (android.support.v7.preference.PreferenceScreen)14 ComponentName (android.content.ComponentName)12 DefaultAppInfo (com.android.settingslib.applications.DefaultAppInfo)12 Preference (android.support.v7.preference.Preference)10 DefaultAppInfo (com.android.settings.applications.defaultapps.DefaultAppInfo)10 VisibleForTesting (android.support.annotation.VisibleForTesting)4 PreferenceCategory (androidx.preference.PreferenceCategory)4 PreferenceScreen (androidx.preference.PreferenceScreen)4 Before (org.junit.Before)4 PackageInfo (android.content.pm.PackageInfo)2 PackageItemInfo (android.content.pm.PackageItemInfo)2 PackageManager (android.content.pm.PackageManager)2 Resources (android.content.res.Resources)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2 Preference (androidx.preference.Preference)2 PreferenceManager (androidx.preference.PreferenceManager)2 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)2