use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.
the class ZenAccessSettings method reloadList.
private void reloadList() {
if (mContext.getSystemService(UserManager.class).isManagedProfile(UserHandle.myUserId())) {
Log.w(TAG, "DND access cannot be enabled in a work profile");
return;
}
final PreferenceScreen screen = getPreferenceScreen();
screen.removeAll();
final ArrayList<ApplicationInfo> apps = new ArrayList<>();
final Set<String> requesting = ZenAccessController.getPackagesRequestingNotificationPolicyAccess();
if (!requesting.isEmpty()) {
final List<ApplicationInfo> installed = mPkgMan.getInstalledApplications(0);
if (installed != null) {
for (ApplicationInfo app : installed) {
if (requesting.contains(app.packageName)) {
apps.add(app);
}
}
}
}
ArraySet<String> autoApproved = new ArraySet<>();
autoApproved.addAll(mNoMan.getEnabledNotificationListenerPackages());
autoApproved.addAll(ZenAccessController.getPackagesWithManageNotifications());
Collections.sort(apps, new PackageItemInfo.DisplayNameComparator(mPkgMan));
for (ApplicationInfo app : apps) {
final String pkg = app.packageName;
final CharSequence label = app.loadLabel(mPkgMan);
final AppPreference pref = new AppPreference(getPrefContext());
pref.setKey(pkg);
pref.setIcon(app.loadIcon(mPkgMan));
pref.setTitle(label);
if (autoApproved.contains(pkg)) {
// Auto approved, user cannot do anything. Hard code summary and disable preference.
pref.setEnabled(false);
pref.setSummary(getString(R.string.zen_access_disabled_package_warning));
} else {
// Not auto approved, update summary according to notification backend.
pref.setSummary(getPreferenceSummary(pkg));
}
pref.setOnPreferenceClickListener(preference -> {
AppInfoBase.startAppInfoFragment(ZenAccessDetails.class, /* fragment */
R.string.manage_zen_access_title, /* titleRes */
pkg, app.uid, this, /* source */
-1, /* requestCode */
getMetricsCategory());
return true;
});
screen.addPreference(pref);
}
}
use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.
the class ZenCustomRuleCallsSettings method updatePreferences.
@Override
public void updatePreferences() {
super.updatePreferences();
PreferenceScreen screen = getPreferenceScreen();
Preference footerPreference = screen.findPreference(FooterPreference.KEY_FOOTER);
footerPreference.setTitle(mContext.getResources().getString(R.string.zen_mode_custom_calls_footer, mRule.getName()));
}
use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.
the class ZenCustomRuleSettingsBase method updatePreferences.
public void updatePreferences() {
mRule = mBackend.getAutomaticZenRule(mId);
final PreferenceScreen screen = getPreferenceScreen();
String categoryKey = getPreferenceCategoryKey();
if (categoryKey != null) {
Preference prefCategory = screen.findPreference(categoryKey);
if (prefCategory != null) {
prefCategory.setTitle(mContext.getResources().getString(com.android.settings.R.string.zen_mode_custom_behavior_category_title, mRule.getName()));
}
}
for (AbstractPreferenceController controller : mControllers) {
AbstractZenCustomRulePreferenceController zenRuleController = (AbstractZenCustomRulePreferenceController) controller;
zenRuleController.onResume(mRule, mId);
zenRuleController.displayPreference(screen);
updatePreference(zenRuleController);
}
}
use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.
the class HandsFreeProfileOutputPreferenceControllerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mAudioManager = mContext.getSystemService(AudioManager.class);
mShadowAudioManager = ShadowAudioManager.getShadow();
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager;
mLocalBluetoothManager = Utils.getLocalBtManager(mContext);
when(mLocalBluetoothManager.getEventManager()).thenReturn(mBluetoothEventManager);
when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
when(mLocalBluetoothProfileManager.getHeadsetProfile()).thenReturn(mHeadsetProfile);
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
mBluetoothManager = new BluetoothManager(mContext);
mBluetoothAdapter = mBluetoothManager.getAdapter();
mBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_1));
when(mBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME_1);
when(mBluetoothDevice.isConnected()).thenReturn(true);
mSecondBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2));
when(mSecondBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME_2);
when(mSecondBluetoothDevice.isConnected()).thenReturn(true);
mLeftBluetoothHapDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_3));
when(mLeftBluetoothHapDevice.getName()).thenReturn(TEST_HAP_DEVICE_NAME_1);
when(mLeftBluetoothHapDevice.isConnected()).thenReturn(true);
mRightBluetoothHapDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_4));
when(mRightBluetoothHapDevice.getName()).thenReturn(TEST_HAP_DEVICE_NAME_2);
when(mRightBluetoothHapDevice.isConnected()).thenReturn(true);
mController = new HandsFreeProfileOutputPreferenceController(mContext, TEST_KEY);
mScreen = spy(new PreferenceScreen(mContext, null));
mPreference = new ListPreference(mContext);
mProfileConnectedDevices = new ArrayList<>();
mHearingAidActiveDevices = new ArrayList<>(2);
when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
when(mScreen.getContext()).thenReturn(mContext);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mScreen.addPreference(mPreference);
mController.displayPreference(mScreen);
mController.setCallback(mAudioSwitchPreferenceCallback);
}
use of androidx.preference.PreferenceScreen in project android_packages_apps_Settings by omnirom.
the class WifiDisplaySettings method update.
private void update(int changes) {
boolean invalidateOptions = false;
// Update settings.
if ((changes & CHANGE_SETTINGS) != 0) {
mWifiDisplayOnSetting = Settings.Global.getInt(getContentResolver(), Settings.Global.WIFI_DISPLAY_ON, 0) != 0;
mWifiDisplayCertificationOn = Settings.Global.getInt(getContentResolver(), Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON, 0) != 0;
mWpsConfig = Settings.Global.getInt(getContentResolver(), Settings.Global.WIFI_DISPLAY_WPS_CONFIG, WpsInfo.INVALID);
// The wifi display enabled setting may have changed.
invalidateOptions = true;
}
// Update wifi display state.
if ((changes & CHANGE_WIFI_DISPLAY_STATUS) != 0) {
mWifiDisplayStatus = mDisplayManager.getWifiDisplayStatus();
// The wifi display feature state may have changed.
invalidateOptions = true;
}
// Rebuild the routes.
final PreferenceScreen preferenceScreen = getPreferenceScreen();
preferenceScreen.removeAll();
// Add all known remote display routes.
final int routeCount = mRouter.getRouteCount();
for (int i = 0; i < routeCount; i++) {
MediaRouter.RouteInfo route = mRouter.getRouteAt(i);
if (route.matchesTypes(MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY)) {
preferenceScreen.addPreference(createRoutePreference(route));
}
}
// Additional features for wifi display routes.
if (mWifiDisplayStatus != null && mWifiDisplayStatus.getFeatureState() == WifiDisplayStatus.FEATURE_STATE_ON) {
// Add all unpaired wifi displays.
for (WifiDisplay display : mWifiDisplayStatus.getDisplays()) {
if (!display.isRemembered() && display.isAvailable() && !display.equals(mWifiDisplayStatus.getActiveDisplay())) {
preferenceScreen.addPreference(new UnpairedWifiDisplayPreference(getPrefContext(), display));
}
}
// Add the certification menu if enabled in developer options.
if (mWifiDisplayCertificationOn) {
buildCertificationMenu(preferenceScreen);
}
}
// Invalidate menu options if needed.
if (invalidateOptions) {
getActivity().invalidateOptionsMenu();
}
}
Aggregations