List of usage examples for android.util ArraySet remove
@Override public boolean remove(Object object)
From source file:com.android.packageinstaller.permission.ui.PermissionAppsFragment.java
@Override public void onPermissionsLoaded(PermissionApps permissionApps) { Context context = getPreferenceManager().getContext(); if (context == null) { return;// ww w .j a va 2 s . c o m } boolean isTelevision = DeviceUtils.isTelevision(context); PreferenceScreen screen = getPreferenceScreen(); ArraySet<String> preferencesToRemove = new ArraySet<>(); for (int i = 0, n = screen.getPreferenceCount(); i < n; i++) { preferencesToRemove.add(screen.getPreference(i).getKey()); } if (mExtraScreen != null) { for (int i = 0, n = mExtraScreen.getPreferenceCount(); i < n; i++) { preferencesToRemove.add(mExtraScreen.getPreference(i).getKey()); } } for (PermissionApp app : permissionApps.getApps()) { if (!Utils.shouldShowPermission(app)) { continue; } String key = app.getKey(); preferencesToRemove.remove(key); Preference existingPref = screen.findPreference(key); if (existingPref == null && mExtraScreen != null) { existingPref = mExtraScreen.findPreference(key); } boolean isSystemApp = Utils.isSystem(app, mLauncherPkgs); if (isSystemApp && !isTelevision && !mShowSystem) { if (existingPref != null) { screen.removePreference(existingPref); } continue; } if (existingPref != null) { // If existing preference - only update its state. if (app.isPolicyFixed()) { existingPref.setSummary(getString(R.string.permission_summary_enforced_by_policy)); } existingPref.setPersistent(false); existingPref.setEnabled(!app.isPolicyFixed()); if (existingPref instanceof SwitchPreference) { ((SwitchPreference) existingPref).setChecked(app.areRuntimePermissionsGranted()); } continue; } SwitchPreference pref = new SwitchPreference(context); pref.setOnPreferenceChangeListener(this); pref.setKey(app.getKey()); pref.setIcon(app.getIcon()); pref.setTitle(app.getLabel()); if (app.isPolicyFixed()) { pref.setSummary(getString(R.string.permission_summary_enforced_by_policy)); } pref.setPersistent(false); pref.setEnabled(!app.isPolicyFixed()); pref.setChecked(app.areRuntimePermissionsGranted()); if (isSystemApp && isTelevision) { if (mExtraScreen == null) { mExtraScreen = getPreferenceManager().createPreferenceScreen(context); } mExtraScreen.addPreference(pref); } else { screen.addPreference(pref); } } if (mExtraScreen != null) { preferencesToRemove.remove(KEY_SHOW_SYSTEM_PREFS); Preference pref = screen.findPreference(KEY_SHOW_SYSTEM_PREFS); if (pref == null) { pref = new Preference(context); pref.setKey(KEY_SHOW_SYSTEM_PREFS); pref.setIcon(Utils.applyTint(context, R.drawable.ic_toc, android.R.attr.colorControlNormal)); pref.setTitle(R.string.preference_show_system_apps); pref.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { SystemAppsFragment frag = new SystemAppsFragment(); setPermissionName(frag, getArguments().getString(Intent.EXTRA_PERMISSION_NAME)); frag.setTargetFragment(PermissionAppsFragment.this, 0); getFragmentManager().beginTransaction().replace(android.R.id.content, frag) .addToBackStack("SystemApps").commit(); return true; } }); screen.addPreference(pref); } int grantedCount = 0; for (int i = 0, n = mExtraScreen.getPreferenceCount(); i < n; i++) { if (((SwitchPreference) mExtraScreen.getPreference(i)).isChecked()) { grantedCount++; } } pref.setSummary(getString(R.string.app_permissions_group_summary, grantedCount, mExtraScreen.getPreferenceCount())); } for (String key : preferencesToRemove) { Preference pref = screen.findPreference(key); if (pref != null) { screen.removePreference(pref); } else if (mExtraScreen != null) { pref = mExtraScreen.findPreference(key); if (pref != null) { mExtraScreen.removePreference(pref); } } } setLoading(false /* loading */, true /* animate */); if (mOnPermissionsLoadedListener != null) { mOnPermissionsLoadedListener.onPermissionsLoaded(permissionApps); } }