Search in sources :

Example 16 with PreferenceScreen

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);
    }
}
Also used : ArraySet(android.util.ArraySet) PreferenceScreen(androidx.preference.PreferenceScreen) AppPreference(com.android.settingslib.widget.AppPreference) ApplicationInfo(android.content.pm.ApplicationInfo) ArrayList(java.util.ArrayList) UserManager(android.os.UserManager) PackageItemInfo(android.content.pm.PackageItemInfo)

Example 17 with PreferenceScreen

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()));
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) Preference(androidx.preference.Preference) FooterPreference(com.android.settingslib.widget.FooterPreference)

Example 18 with PreferenceScreen

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);
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) AbstractPreferenceController(com.android.settingslib.core.AbstractPreferenceController) Preference(androidx.preference.Preference)

Example 19 with PreferenceScreen

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);
}
Also used : AudioManager(android.media.AudioManager) ShadowAudioManager(com.android.settings.testutils.shadow.ShadowAudioManager) PreferenceScreen(androidx.preference.PreferenceScreen) LocalBluetoothManager(com.android.settingslib.bluetooth.LocalBluetoothManager) BluetoothManager(android.bluetooth.BluetoothManager) ListPreference(androidx.preference.ListPreference) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 20 with PreferenceScreen

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();
    }
}
Also used : PreferenceScreen(androidx.preference.PreferenceScreen) RouteInfo(android.media.MediaRouter.RouteInfo) WifiDisplay(android.hardware.display.WifiDisplay) MediaRouter(android.media.MediaRouter)

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