Search in sources :

Example 36 with RadioButtonPreference

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

the class PreventRingingGesturePreferenceController method makeRadioPreference.

private RadioButtonPreference makeRadioPreference(String key, int titleId) {
    RadioButtonPreference pref = new RadioButtonPreference(mPreferenceCategory.getContext());
    pref.setKey(key);
    pref.setTitle(titleId);
    pref.setOnClickListener(this);
    mPreferenceCategory.addPreference(pref);
    return pref;
}
Also used : RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference)

Example 37 with RadioButtonPreference

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

the class SystemNavigationGestureSettings method updateCandidates.

@Override
public void updateCandidates() {
    final String defaultKey = getDefaultKey();
    final String systemDefaultKey = getSystemDefaultKey();
    final PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();
    screen.addPreference(mVideoPreference);
    final List<? extends CandidateInfo> candidateList = getCandidates();
    if (candidateList == null) {
        return;
    }
    for (CandidateInfo info : candidateList) {
        RadioButtonPreference pref = new RadioButtonPreference(getPrefContext());
        bindPreference(pref, info.getKey(), info, defaultKey);
        bindPreferenceExtra(pref, info.getKey(), info, defaultKey, systemDefaultKey);
        screen.addPreference(pref);
    }
    mayCheckOnlyRadioButton();
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) CandidateInfo(com.android.settingslib.widget.CandidateInfo) RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference)

Example 38 with RadioButtonPreference

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

the class UsbDetailsDataRoleControllerTest method onClickDeviceAndRefresh_success_shouldClearSubtext.

@Test
public void onClickDeviceAndRefresh_success_shouldClearSubtext() {
    mDetailsDataRoleController.displayPreference(mScreen);
    when(mUsbBackend.getDataRole()).thenReturn(DATA_ROLE_HOST);
    final RadioButtonPreference devicePref = getRadioPreference(DATA_ROLE_DEVICE);
    devicePref.performClick();
    verify(mUsbBackend).setDataRole(DATA_ROLE_DEVICE);
    assertThat(devicePref.getSummary()).isEqualTo(mContext.getString(R.string.usb_switching));
    mDetailsDataRoleController.refresh(false, /* connected */
    UsbManager.FUNCTION_NONE, POWER_ROLE_NONE, DATA_ROLE_NONE);
    mDetailsDataRoleController.refresh(true, /* connected */
    UsbManager.FUNCTION_NONE, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
    assertThat(devicePref.getSummary()).isEqualTo("");
}
Also used : RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference) Test(org.junit.Test)

Example 39 with RadioButtonPreference

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

the class ScreenTimeoutSettings method updateCandidates.

@Override
public void updateCandidates() {
    final String defaultKey = getDefaultKey();
    final PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();
    final List<? extends CandidateInfo> candidateList = getCandidates();
    if (candidateList == null) {
        return;
    }
    for (CandidateInfo info : candidateList) {
        RadioButtonPreference pref = new RadioButtonPreference(getPrefContext());
        bindPreference(pref, info.getKey(), info, defaultKey);
        screen.addPreference(pref);
    }
    final long selectedTimeout = Long.parseLong(defaultKey);
    final long maxTimeout = getMaxScreenTimeout(getContext());
    if (!candidateList.isEmpty() && (selectedTimeout > maxTimeout)) {
        // The selected time out value is longer than the max timeout allowed by the admin.
        // Select the largest value from the list by default.
        final RadioButtonPreference preferenceWithLargestTimeout = (RadioButtonPreference) screen.getPreference(candidateList.size() - 1);
        preferenceWithLargestTimeout.setChecked(true);
    }
    mPrivacyPreference = new FooterPreference(mContext);
    mPrivacyPreference.setIcon(R.drawable.ic_privacy_shield_24dp);
    mPrivacyPreference.setTitle(R.string.adaptive_sleep_privacy);
    mPrivacyPreference.setSelectable(false);
    mPrivacyPreference.setLayoutResource(R.layout.preference_footer);
    if (isScreenAttentionAvailable(getContext())) {
        mAdaptiveSleepPermissionController.addToScreen(screen);
        mAdaptiveSleepCameraStatePreferenceController.addToScreen(screen);
        mAdaptiveSleepBatterySaverPreferenceController.addToScreen(screen);
        mAdaptiveSleepController.addToScreen(screen);
        screen.addPreference(mPrivacyPreference);
    }
    if (mAdmin != null) {
        setupDisabledFooterPreference();
        screen.addPreference(mDisableOptionsPreference);
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) CandidateInfo(com.android.settingslib.widget.CandidateInfo) SpannableString(android.text.SpannableString) FooterPreference(com.android.settingslib.widget.FooterPreference) RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference)

Example 40 with RadioButtonPreference

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

the class BugReportHandlerPickerTest method testClickingItemFail.

private void testClickingItemFail() {
    when(mBugReportHandlerUtil.getValidBugReportHandlerInfos(any())).thenReturn(Collections.singletonList(Pair.create(createApplicationInfo(PACKAGE_NAME), USER_ID)));
    when(mBugReportHandlerUtil.setCurrentBugReportHandlerAppAndUser(any(), eq(PACKAGE_NAME), eq(USER_ID))).thenReturn(false);
    RadioButtonPreference defaultPackagePref = mock(RadioButtonPreference.class);
    when(defaultPackagePref.getKey()).thenReturn(BugReportHandlerPicker.getKey(PACKAGE_NAME, USER_ID));
    mPicker.onRadioButtonClicked(defaultPackagePref);
    verify(mBugReportHandlerUtil, times(1)).setCurrentBugReportHandlerAppAndUser(any(), eq(PACKAGE_NAME), eq(USER_ID));
    // 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(mBugReportHandlerUtil, times(1)).showInvalidChoiceToast(any());
}
Also used : RadioButtonPreference(com.android.settingslib.widget.RadioButtonPreference)

Aggregations

RadioButtonPreference (com.android.settingslib.widget.RadioButtonPreference)52 Test (org.junit.Test)27 Before (org.junit.Before)8 DefaultAppInfo (com.android.settingslib.applications.DefaultAppInfo)6 PreferenceScreen (androidx.preference.PreferenceScreen)5 CandidateInfo (com.android.settingslib.widget.CandidateInfo)3 Preference (androidx.preference.Preference)2 PreferenceCategory (androidx.preference.PreferenceCategory)2 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)2 FooterPreference (com.android.settingslib.widget.FooterPreference)2 AppOpsManager (android.app.AppOpsManager)1 SettingsEnums (android.app.settings.SettingsEnums)1 Context (android.content.Context)1 Intent (android.content.Intent)1 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageManager (android.content.pm.PackageManager)1 Resources (android.content.res.Resources)1 Drawable (android.graphics.drawable.Drawable)1 BatteryStats (android.os.BatteryStats)1 Bundle (android.os.Bundle)1