Search in sources :

Example 16 with CandidateInfo

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

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

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)

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