Search in sources :

Example 41 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.

the class UserSettings method onResume.

@Override
public void onResume() {
    super.onResume();
    if (!mUserCaps.mEnabled) {
        return;
    }
    final PreferenceScreen screen = getPreferenceScreen();
    mAddUserWhenLockedPreferenceController.updateState(screen.findPreference(mAddUserWhenLockedPreferenceController.getPreferenceKey()));
    if (mShouldUpdateUserList) {
        updateUI();
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen)

Example 42 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.

the class ManagedServiceSettings method updateList.

private void updateList(List<ServiceInfo> services) {
    UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
    final int managedProfileId = Utils.getManagedProfileId(um, UserHandle.myUserId());
    final PreferenceScreen screen = getPreferenceScreen();
    screen.removeAll();
    services.sort(new PackageItemInfo.DisplayNameComparator(mPm));
    for (ServiceInfo service : services) {
        final ComponentName cn = new ComponentName(service.packageName, service.name);
        CharSequence title = null;
        try {
            title = mPm.getApplicationInfoAsUser(service.packageName, 0, UserHandle.myUserId()).loadLabel(mPm);
        } catch (PackageManager.NameNotFoundException e) {
            // unlikely, as we are iterating over live services.
            Log.e(TAG, "can't find package name", e);
        }
        final CharSequence finalTitle = title;
        final String summary = service.loadLabel(mPm).toString();
        final SwitchPreference pref = new AppSwitchPreference(getPrefContext());
        pref.setPersistent(false);
        pref.setIcon(mIconDrawableFactory.getBadgedIcon(service, service.applicationInfo, UserHandle.getUserId(service.applicationInfo.uid)));
        if (title != null && !title.equals(summary)) {
            pref.setTitle(title);
            pref.setSummary(summary);
        } else {
            pref.setTitle(summary);
        }
        pref.setKey(cn.flattenToString());
        pref.setChecked(isServiceEnabled(cn));
        if (managedProfileId != UserHandle.USER_NULL && !mDpm.isNotificationListenerServicePermitted(service.packageName, managedProfileId)) {
            pref.setSummary(R.string.work_profile_notification_access_blocked_summary);
        }
        pref.setOnPreferenceChangeListener((preference, newValue) -> {
            final boolean enable = (boolean) newValue;
            if (finalTitle != null) {
                return setEnabled(cn, finalTitle.toString(), enable);
            } else {
                return setEnabled(cn, null, enable);
            }
        });
        pref.setKey(cn.flattenToString());
        screen.addPreference(pref);
    }
    highlightPreferenceIfNeeded();
}
Also used : AppSwitchPreference(com.android.settingslib.widget.AppSwitchPreference) PreferenceScreen(androidx.preference.PreferenceScreen) AppSwitchPreference(com.android.settingslib.widget.AppSwitchPreference) SwitchPreference(androidx.preference.SwitchPreference) ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) UserManager(android.os.UserManager) PackageItemInfo(android.content.pm.PackageItemInfo) ComponentName(android.content.ComponentName)

Example 43 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.

the class TopLevelSettings method onCreatePreferences.

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    super.onCreatePreferences(savedInstanceState, rootKey);
    final PreferenceScreen screen = getPreferenceScreen();
    if (screen == null) {
        return;
    }
    // Tint the homepage icons
    final int tintColor = Utils.getHomepageIconColor(getContext());
    final int count = screen.getPreferenceCount();
    for (int i = 0; i < count; i++) {
        final Preference preference = screen.getPreference(i);
        if (preference == null) {
            break;
        }
        final Drawable icon = preference.getIcon();
        if (icon != null) {
            icon.setTint(tintColor);
        }
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Preference(androidx.preference.Preference) Drawable(android.graphics.drawable.Drawable)

Example 44 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.

the class ScreenPinningSettings method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final SettingsActivity activity = (SettingsActivity) getActivity();
    activity.setTitle(R.string.screen_pinning_title);
    mLockPatternUtils = new LockPatternUtils(activity);
    mUserManager = activity.getSystemService(UserManager.class);
    addPreferencesFromResource(R.xml.screen_pinning_settings);
    final PreferenceScreen root = getPreferenceScreen();
    mUseScreenLock = root.findPreference(KEY_USE_SCREEN_LOCK);
    mFooterPreference = root.findPreference(KEY_FOOTER);
    mSwitchBar = activity.getSwitchBar();
    mSwitchBar.setTitle(getContext().getString(R.string.app_pinning_main_switch_title));
    mSwitchBar.show();
    mSwitchBar.setChecked(isLockToAppEnabled(getActivity()));
    mSwitchBar.addOnSwitchChangeListener(this);
    updateDisplay();
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) UserManager(android.os.UserManager) LockPatternUtils(com.android.internal.widget.LockPatternUtils) SettingsActivity(com.android.settings.SettingsActivity)

Example 45 with PreferenceScreen

use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.

the class BasePreferenceControllerTest method settingAvailable_disabledOnDisplayPreference_preferenceEnabled.

@Test
public void settingAvailable_disabledOnDisplayPreference_preferenceEnabled() {
    final PreferenceScreen screen = mock(PreferenceScreen.class);
    final Preference preference = new Preference(mContext);
    preference.setEnabled(true);
    when(screen.findPreference(anyString())).thenReturn(preference);
    mPreferenceController.displayPreference(screen);
    assertThat(preference.isEnabled()).isTrue();
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Preference(androidx.preference.Preference) Test(org.junit.Test)

Aggregations

PreferenceScreen (androidx.preference.PreferenceScreen)244 Preference (androidx.preference.Preference)81 Test (org.junit.Test)60 Context (android.content.Context)36 PreferenceManager (androidx.preference.PreferenceManager)36 ContentResolver (android.content.ContentResolver)25 PreferenceCategory (androidx.preference.PreferenceCategory)24 Bundle (android.os.Bundle)20 ArrayList (java.util.ArrayList)20 SwitchPreference (androidx.preference.SwitchPreference)19 Resources (android.content.res.Resources)18 Before (org.junit.Before)17 ListPreference (androidx.preference.ListPreference)14 PackageManager (android.content.pm.PackageManager)13 PreferenceGroup (androidx.preference.PreferenceGroup)13 ApplicationInfo (android.content.pm.ApplicationInfo)9 VisibleForTesting (androidx.annotation.VisibleForTesting)9 List (java.util.List)9 UserManager (android.os.UserManager)8 StorageItemPreference (com.android.settings.deviceinfo.StorageItemPreference)8