use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by LineageOS.
the class LegalSettings method onCreate.
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.about_legal);
final Activity act = getActivity();
// These are contained in the "container" preference group
PreferenceGroup parentPreference = getPreferenceScreen();
Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_TERMS, Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_LICENSE, Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_COPYRIGHT, Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_WEBVIEW_LICENSE, Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
}
use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by LineageOS.
the class UserSettings method updateUserList.
private void updateUserList() {
if (getActivity() == null)
return;
List<UserInfo> users = mUserManager.getUsers(true);
final Context context = getActivity();
final boolean voiceCapable = Utils.isVoiceCapable(context);
final ArrayList<Integer> missingIcons = new ArrayList<>();
final ArrayList<UserPreference> userPreferences = new ArrayList<>();
int guestId = UserPreference.USERID_GUEST_DEFAULTS;
userPreferences.add(mMePreference);
for (UserInfo user : users) {
if (!user.supportsSwitchToByUser()) {
// e.g. Managed profiles appear under Accounts Settings instead
continue;
}
UserPreference pref;
if (user.id == UserHandle.myUserId()) {
pref = mMePreference;
} else if (user.isGuest()) {
// Skip over Guest. We add generic Guest settings after this loop
guestId = user.id;
continue;
} else {
// With Telephony:
// Secondary user: Settings
// Guest: Settings
// Restricted Profile: There is no Restricted Profile
// Without Telephony:
// Secondary user: Delete
// Guest: Nothing
// Restricted Profile: Settings
final boolean showSettings = mUserCaps.mIsAdmin && (voiceCapable || user.isRestricted());
final boolean showDelete = mUserCaps.mIsAdmin && (!voiceCapable && !user.isRestricted() && !user.isGuest());
pref = new UserPreference(getPrefContext(), null, user.id, showSettings ? this : null, showDelete ? this : null);
pref.setKey("id=" + user.id);
userPreferences.add(pref);
if (user.isAdmin()) {
pref.setSummary(R.string.user_admin);
}
pref.setTitle(user.name);
pref.setSelectable(false);
}
if (pref == null) {
continue;
}
if (!isInitialized(user)) {
if (user.isRestricted()) {
pref.setSummary(R.string.user_summary_restricted_not_set_up);
} else {
pref.setSummary(R.string.user_summary_not_set_up);
}
pref.setOnPreferenceClickListener(this);
pref.setSelectable(true);
} else if (user.isRestricted()) {
pref.setSummary(R.string.user_summary_restricted_profile);
}
if (user.iconPath != null) {
if (mUserIcons.get(user.id) == null) {
// Icon not loaded yet, print a placeholder
missingIcons.add(user.id);
pref.setIcon(getEncircledDefaultIcon());
} else {
setPhotoId(pref, user);
}
} else {
// Icon not available yet, print a placeholder
pref.setIcon(getEncircledDefaultIcon());
}
}
// Add a temporary entry for the user being created
if (mAddingUser) {
UserPreference pref = new UserPreference(getPrefContext(), null, UserPreference.USERID_UNKNOWN, null, null);
pref.setEnabled(false);
pref.setTitle(mAddingUserName);
pref.setIcon(getEncircledDefaultIcon());
userPreferences.add(pref);
}
// Check if Guest tile should be added.
if (!mUserCaps.mIsGuest && (mUserCaps.mCanAddGuest || mUserCaps.mDisallowAddUserSetByAdmin)) {
// Add a virtual Guest user for guest defaults
UserPreference pref = new UserPreference(getPrefContext(), null, UserPreference.USERID_GUEST_DEFAULTS, mUserCaps.mIsAdmin && voiceCapable ? this : null, /* settings icon handler */
null);
pref.setTitle(R.string.user_guest);
pref.setIcon(getEncircledDefaultIcon());
userPreferences.add(pref);
pref.setDisabledByAdmin(mUserCaps.mDisallowAddUser ? mUserCaps.mEnforcedAdmin : null);
int finalGuestId = guestId;
pref.setOnPreferenceClickListener(preference -> {
int id = finalGuestId;
if (id == UserPreference.USERID_GUEST_DEFAULTS) {
UserInfo guest = mUserManager.createGuest(getContext(), preference.getTitle().toString());
if (guest != null) {
id = guest.id;
}
}
try {
ActivityManager.getService().switchUser(id);
} catch (RemoteException e) {
e.rethrowFromSystemServer();
}
return true;
});
}
// Sort list of users by serialNum
Collections.sort(userPreferences, UserPreference.SERIAL_NUMBER_COMPARATOR);
getActivity().invalidateOptionsMenu();
// Load the icons
if (missingIcons.size() > 0) {
loadIconsAsync(missingIcons);
}
PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.removeAll();
// If profiles are supported, userPreferences will be added to the category labeled
// "User & Profiles", otherwise the category is skipped and elements are added directly
// to preferenceScreen
PreferenceGroup groupToAddUsers;
if (mUserCaps.mCanAddRestrictedProfile) {
mUserListCategory.removeAll();
mUserListCategory.setOrder(Preference.DEFAULT_ORDER);
preferenceScreen.addPreference(mUserListCategory);
groupToAddUsers = mUserListCategory;
} else {
groupToAddUsers = preferenceScreen;
}
for (UserPreference userPreference : userPreferences) {
userPreference.setOrder(Preference.DEFAULT_ORDER);
groupToAddUsers.addPreference(userPreference);
}
// Append Add user to the end of the list
if ((mUserCaps.mCanAddUser || mUserCaps.mDisallowAddUserSetByAdmin) && Utils.isDeviceProvisioned(getActivity())) {
boolean moreUsers = mUserManager.canAddMoreUsers();
mAddUser.setOrder(Preference.DEFAULT_ORDER);
preferenceScreen.addPreference(mAddUser);
mAddUser.setEnabled(moreUsers && !mAddingUser);
if (!moreUsers) {
mAddUser.setSummary(getString(R.string.user_add_max_count, getMaxRealUsers()));
} else {
mAddUser.setSummary(null);
}
if (mAddUser.isEnabled()) {
mAddUser.setDisabledByAdmin(mUserCaps.mDisallowAddUser ? mUserCaps.mEnforcedAdmin : null);
}
}
}
use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by LineageOS.
the class SettingsPreferenceFragment method cacheRemoveAllPrefs.
protected void cacheRemoveAllPrefs(PreferenceGroup group) {
mPreferenceCache = new ArrayMap<String, Preference>();
final int N = group.getPreferenceCount();
for (int i = 0; i < N; i++) {
Preference p = group.getPreference(i);
if (TextUtils.isEmpty(p.getKey())) {
continue;
}
mPreferenceCache.put(p.getKey(), p);
}
}
use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by LineageOS.
the class SettingsPreferenceFragment method removePreference.
@VisibleForTesting
boolean removePreference(PreferenceGroup group, String key) {
final int preferenceCount = group.getPreferenceCount();
for (int i = 0; i < preferenceCount; i++) {
final Preference preference = group.getPreference(i);
final String curKey = preference.getKey();
if (TextUtils.equals(curKey, key)) {
return group.removePreference(preference);
}
if (preference instanceof PreferenceGroup) {
if (removePreference((PreferenceGroup) preference, key)) {
return true;
}
}
}
return false;
}
use of android.support.v7.preference.PreferenceGroup in project android_packages_apps_Settings by LineageOS.
the class TrustAgentSettings method updateAgents.
private void updateAgents() {
final Context context = getActivity();
if (mAvailableAgents == null) {
mAvailableAgents = findAvailableTrustAgents();
}
if (mLockPatternUtils == null) {
mLockPatternUtils = new LockPatternUtils(getActivity());
}
loadActiveAgents();
PreferenceGroup category = (PreferenceGroup) getPreferenceScreen().findPreference("trust_agents");
category.removeAll();
final EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(context, DevicePolicyManager.KEYGUARD_DISABLE_TRUST_AGENTS, UserHandle.myUserId());
final int count = mAvailableAgents.size();
for (int i = 0; i < count; i++) {
AgentInfo agent = mAvailableAgents.valueAt(i);
final RestrictedSwitchPreference preference = new RestrictedSwitchPreference(getPrefContext());
preference.useAdminDisabledSummary(true);
agent.preference = preference;
preference.setPersistent(false);
preference.setTitle(agent.label);
preference.setIcon(agent.icon);
preference.setPersistent(false);
preference.setOnPreferenceChangeListener(this);
preference.setChecked(mActiveAgents.contains(agent.component));
if (admin != null && mDpm.getTrustAgentConfiguration(null, agent.component) == null) {
preference.setChecked(false);
preference.setDisabledByAdmin(admin);
}
category.addPreference(agent.preference);
}
}
Aggregations