Search in sources :

Example 91 with RadioButtonPreference

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

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 92 with RadioButtonPreference

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

the class ChannelImportanceSettings method createPreferenceHierarchy.

private PreferenceScreen createPreferenceHierarchy() {
    PreferenceScreen root = getPreferenceScreen();
    if (root != null) {
        root.removeAll();
    }
    addPreferencesFromResource(R.xml.notification_importance);
    root = getPreferenceScreen();
    for (int i = 0; i < root.getPreferenceCount(); i++) {
        Preference pref = root.getPreference(i);
        if (pref instanceof RadioButtonPreference) {
            RadioButtonPreference radioPref = (RadioButtonPreference) pref;
            radioPref.setOnClickListener(this);
            mImportances.add(radioPref);
        }
    }
    switch(mChannel.getImportance()) {
        case IMPORTANCE_MIN:
            updateRadioButtons(KEY_IMPORTANCE_MIN);
            break;
        case IMPORTANCE_LOW:
            updateRadioButtons(KEY_IMPORTANCE_LOW);
            break;
        case IMPORTANCE_DEFAULT:
            updateRadioButtons(KEY_IMPORTANCE_DEFAULT);
            break;
        case IMPORTANCE_HIGH:
        case IMPORTANCE_MAX:
            updateRadioButtons(KEY_IMPORTANCE_HIGH);
            break;
    }
    return root;
}
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 93 with RadioButtonPreference

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

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 94 with RadioButtonPreference

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

the class NetworkScorerPickerTest method testOnRadioButtonClicked_success.

@Test
public void testOnRadioButtonClicked_success() {
    RadioButtonPreference pref = new RadioButtonPreference(mContext);
    pref.setKey(TEST_SCORER_PACKAGE_1);
    when(mPreferenceScreen.getPreference(anyInt())).thenReturn(pref);
    when(mPreferenceScreen.getPreferenceCount()).thenReturn(1);
    when(mNetworkScoreManager.setActiveScorer(TEST_SCORER_PACKAGE_1)).thenReturn(true);
    when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(TEST_SCORER_PACKAGE_2);
    mFragment.onRadioButtonClicked(pref);
    verify(mNetworkScoreManager).setActiveScorer(TEST_SCORER_PACKAGE_1);
    assertThat(pref.isChecked()).isTrue();
}
Also used : RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) Test(org.junit.Test)

Example 95 with RadioButtonPreference

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

the class NetworkScorerPickerTest method testOnRadioButtonClicked_currentScorer_doNothing.

@Test
public void testOnRadioButtonClicked_currentScorer_doNothing() {
    RadioButtonPreference pref = new RadioButtonPreference(mContext);
    pref.setKey(TEST_SCORER_PACKAGE_1);
    pref.setChecked(true);
    when(mPreferenceScreen.getPreference(anyInt())).thenReturn(pref);
    when(mPreferenceScreen.getPreferenceCount()).thenReturn(1);
    when(mNetworkScoreManager.setActiveScorer(TEST_SCORER_PACKAGE_1)).thenReturn(true);
    when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(TEST_SCORER_PACKAGE_1);
    mFragment.onRadioButtonClicked(pref);
    verify(mNetworkScoreManager, never()).setActiveScorer(any());
    assertThat(pref.isChecked()).isTrue();
}
Also used : RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) Test(org.junit.Test)

Aggregations

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