Search in sources :

Example 21 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 22 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 23 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 24 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 25 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)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