Search in sources :

Example 11 with CandidateInfo

use of com.android.settingslib.widget.CandidateInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NotificationAssistantPickerTest method candidateListHasCorrectCandidate.

@Test
public void candidateListHasCorrectCandidate() {
    List<ServiceInfo> list = new ArrayList<>();
    ServiceInfo serviceInfo = mock(ServiceInfo.class, RETURNS_SMART_NULLS);
    serviceInfo.packageName = TEST_PKG;
    serviceInfo.name = TEST_SRV;
    list.add(serviceInfo);
    mFragment.onServicesReloaded(list);
    List<? extends CandidateInfo> candidates = mFragment.getCandidates();
    boolean found = false;
    for (CandidateInfo c : candidates) {
        if (TEST_CMP.equals(c.getKey())) {
            found = true;
            break;
        }
    }
    if (!found)
        fail();
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) CandidateInfo(com.android.settingslib.widget.CandidateInfo) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 12 with CandidateInfo

use of com.android.settingslib.widget.CandidateInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class RadioButtonPickerFragment method updateCandidates.

@VisibleForTesting
public void updateCandidates() {
    mCandidates.clear();
    final List<? extends CandidateInfo> candidateList = getCandidates();
    if (candidateList != null) {
        for (CandidateInfo info : candidateList) {
            mCandidates.put(info.getKey(), info);
        }
    }
    final String defaultKey = getDefaultKey();
    final String systemDefaultKey = getSystemDefaultKey();
    final PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();
    if (mIllustrationId != 0) {
        addIllustration(screen);
    }
    if (!mAppendStaticPreferences) {
        addStaticPreferences(screen);
    }
    final int customLayoutResId = getRadioButtonPreferenceCustomLayoutResId();
    if (shouldShowItemNone()) {
        final RadioButtonPreference nonePref = new RadioButtonPreference(getPrefContext());
        if (customLayoutResId > 0) {
            nonePref.setLayoutResource(customLayoutResId);
        }
        nonePref.setIcon(R.drawable.ic_remove_circle);
        nonePref.setTitle(R.string.app_list_preference_none);
        nonePref.setChecked(TextUtils.isEmpty(defaultKey));
        nonePref.setOnClickListener(this);
        screen.addPreference(nonePref);
    }
    if (candidateList != null) {
        for (CandidateInfo info : candidateList) {
            RadioButtonPreference pref = new RadioButtonPreference(getPrefContext());
            if (customLayoutResId > 0) {
                pref.setLayoutResource(customLayoutResId);
            }
            bindPreference(pref, info.getKey(), info, defaultKey);
            bindPreferenceExtra(pref, info.getKey(), info, defaultKey, systemDefaultKey);
            screen.addPreference(pref);
        }
    }
    mayCheckOnlyRadioButton();
    if (mAppendStaticPreferences) {
        addStaticPreferences(screen);
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) CandidateInfo(com.android.settingslib.widget.CandidateInfo) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 13 with CandidateInfo

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

the class UsbDefaultFragment method getCandidates.

@Override
protected List<? extends CandidateInfo> getCandidates() {
    List<CandidateInfo> ret = Lists.newArrayList();
    for (final long option : UsbDetailsFunctionsController.FUNCTIONS_MAP.keySet()) {
        final String title = getContext().getString(UsbDetailsFunctionsController.FUNCTIONS_MAP.get(option));
        final String key = UsbBackend.usbFunctionsToString(option);
        // Only show supported functions
        if (mUsbBackend.areFunctionsSupported(option)) {
            ret.add(new CandidateInfo(true) {

                /* enabled */
                @Override
                public CharSequence loadLabel() {
                    return title;
                }

                @Override
                public Drawable loadIcon() {
                    return null;
                }

                @Override
                public String getKey() {
                    return key;
                }
            });
        }
    }
    return ret;
}
Also used : CandidateInfo(com.android.settingslib.widget.CandidateInfo) Drawable(android.graphics.drawable.Drawable)

Example 14 with CandidateInfo

use of com.android.settingslib.widget.CandidateInfo 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 15 with CandidateInfo

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

the class NotificationAssistantPicker method onServicesReloaded.

@Override
public void onServicesReloaded(List<ServiceInfo> services) {
    List<CandidateInfo> list = new ArrayList<>();
    services.sort(new PackageItemInfo.DisplayNameComparator(mPm));
    for (ServiceInfo service : services) {
        if (mContext.getPackageManager().checkPermission(android.Manifest.permission.REQUEST_NOTIFICATION_ASSISTANT_SERVICE, service.packageName) == PackageManager.PERMISSION_GRANTED) {
            final ComponentName cn = new ComponentName(service.packageName, service.name);
            list.add(new DefaultAppInfo(mContext, mPm, mUserId, cn));
        }
    }
    list.add(new CandidateNone(mContext));
    mCandidateInfos = list;
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) CandidateInfo(com.android.settingslib.widget.CandidateInfo) ArrayList(java.util.ArrayList) PackageItemInfo(android.content.pm.PackageItemInfo) ComponentName(android.content.ComponentName) DefaultAppInfo(com.android.settingslib.applications.DefaultAppInfo)

Aggregations

CandidateInfo (com.android.settingslib.widget.CandidateInfo)17 PreferenceScreen (androidx.preference.PreferenceScreen)5 ArrayList (java.util.ArrayList)5 ComponentName (android.content.ComponentName)4 ServiceInfo (android.content.pm.ServiceInfo)4 Test (org.junit.Test)4 Context (android.content.Context)3 RadioButtonPreference (com.android.settingslib.widget.RadioButtonPreference)3 PackageItemInfo (android.content.pm.PackageItemInfo)2 Drawable (android.graphics.drawable.Drawable)2 DefaultAppInfo (com.android.settingslib.applications.DefaultAppInfo)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 AccessibilityServiceInfo (android.accessibilityservice.AccessibilityServiceInfo)1 SpannableString (android.text.SpannableString)1 AccessibilityManager (android.view.accessibility.AccessibilityManager)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1 ToggleableFrameworkFeatureInfo (com.android.internal.accessibility.AccessibilityShortcutController.ToggleableFrameworkFeatureInfo)1 RadioButtonPreferenceWithExtraWidget (com.android.settings.widget.RadioButtonPreferenceWithExtraWidget)1 FooterPreference (com.android.settingslib.widget.FooterPreference)1