Search in sources :

Example 56 with RadioButtonPreference

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

the class WebViewAppPickerTest method testSuccessfulClickChangesProvider.

private void testSuccessfulClickChangesProvider() {
    when(mWvusWrapper.getValidWebViewApplicationInfos(any())).thenReturn(Collections.singletonList(createApplicationInfo(PACKAGE_NAME)));
    when(mWvusWrapper.setWebViewProvider(eq(PACKAGE_NAME))).thenReturn(true);
    RadioButtonPreference defaultPackagePref = mock(RadioButtonPreference.class);
    when(defaultPackagePref.getKey()).thenReturn(PACKAGE_NAME);
    mPicker.onRadioButtonClicked(defaultPackagePref);
    verify(mWvusWrapper, times(1)).setWebViewProvider(eq(PACKAGE_NAME));
    verify(mPicker, times(1)).updateCheckedState(PACKAGE_NAME);
    verify(mWvusWrapper, never()).showInvalidChoiceToast(any());
}
Also used : RadioButtonPreference(com.android.settings.widget.RadioButtonPreference)

Example 57 with RadioButtonPreference

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

the class WebViewAppPickerTest method testFailingClickUpdatesSetting.

private void testFailingClickUpdatesSetting() {
    when(mWvusWrapper.getValidWebViewApplicationInfos(any())).thenReturn(Collections.singletonList(createApplicationInfo(PACKAGE_NAME)));
    when(mWvusWrapper.setWebViewProvider(eq(PACKAGE_NAME))).thenReturn(false);
    RadioButtonPreference defaultPackagePref = mock(RadioButtonPreference.class);
    when(defaultPackagePref.getKey()).thenReturn(PACKAGE_NAME);
    mPicker.onRadioButtonClicked(defaultPackagePref);
    verify(mWvusWrapper, times(1)).setWebViewProvider(eq(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 58 with RadioButtonPreference

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

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(androidx.preference.PreferenceScreen) RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) Preference(androidx.preference.Preference) RadioButtonPreference(com.android.settings.widget.RadioButtonPreference)

Example 59 with RadioButtonPreference

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

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(androidx.preference.PreferenceScreen) NetworkScorerAppData(android.net.NetworkScorerAppData) RadioButtonPreference(com.android.settings.widget.RadioButtonPreference) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 60 with RadioButtonPreference

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

the class UsbDetailsFunctionsController method refresh.

@Override
protected void refresh(boolean connected, long functions, int powerRole, int dataRole) {
    if (!connected || dataRole != DATA_ROLE_DEVICE) {
        mProfilesContainer.setEnabled(false);
    } else {
        // Functions are only available in device mode
        mProfilesContainer.setEnabled(true);
    }
    RadioButtonPreference pref;
    for (long option : FUNCTIONS_MAP.keySet()) {
        int title = FUNCTIONS_MAP.get(option);
        pref = getProfilePreference(UsbBackend.usbFunctionsToString(option), title);
        // Only show supported options
        if (mUsbBackend.areFunctionsSupported(option)) {
            pref.setChecked(functions == option);
        } else {
            mProfilesContainer.removePreference(pref);
        }
    }
}
Also used : RadioButtonPreference(com.android.settings.widget.RadioButtonPreference)

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