Search in sources :

Example 26 with RadioButtonPreference

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

the class NetworkScorerPickerTest method testUpdateCandidates_validScorer.

@Test
public void testUpdateCandidates_validScorer() {
    ComponentName scorer = new ComponentName(TEST_SCORER_PACKAGE_1, TEST_SCORER_CLASS_1);
    NetworkScorerAppData scorerAppData = new NetworkScorerAppData(0, scorer, TEST_SCORER_LABEL_1, null, /* enableUseOpenWifiActivity */
    null);
    when(mNetworkScoreManager.getAllValidScorers()).thenReturn(Lists.newArrayList(scorerAppData));
    when(mNetworkScoreManager.getActiveScorerPackage()).thenReturn(TEST_SCORER_PACKAGE_1);
    ArgumentCaptor<RadioButtonPreference> arg = ArgumentCaptor.forClass(RadioButtonPreference.class);
    mFragment.updateCandidates();
    // The first preference added is the "none" preference and the second is the
    // pref for the test scorer.
    verify(mPreferenceScreen, times(2)).addPreference(arg.capture());
    // Returns the last captured value which is expected to be the test scorer pref.
    RadioButtonPreference pref = arg.getValue();
    assertThat(pref.getTitle()).isEqualTo(TEST_SCORER_LABEL_1);
    assertThat(pref.isChecked()).isTrue();
}
Also used : ComponentName(android.content.ComponentName) NetworkScorerAppData(android.net.NetworkScorerAppData) RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) Test(org.junit.Test)

Example 27 with RadioButtonPreference

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

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

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

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

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

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

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

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)

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