Search in sources :

Example 21 with PreferenceCategory

use of android.support.v7.preference.PreferenceCategory in project android_packages_apps_Settings by LineageOS.

the class LocationSettings method addLocationServices.

/**
 * Add the settings injected by external apps into the "App Settings" category. Hides the
 * category if there are no injected settings.
 *
 * Reloads the settings whenever receives
 * {@link SettingInjectorService#ACTION_INJECTED_SETTING_CHANGED}.
 */
private void addLocationServices(Context context, PreferenceScreen root, boolean lockdownOnLocationAccess) {
    PreferenceCategory categoryLocationServices = (PreferenceCategory) root.findPreference(KEY_LOCATION_SERVICES);
    injector = new SettingsInjector(context);
    // If location access is locked down by device policy then we only show injected settings
    // for the primary profile.
    final Context prefContext = categoryLocationServices.getContext();
    final List<Preference> locationServices = injector.getInjectedSettings(prefContext, lockdownOnLocationAccess ? UserHandle.myUserId() : UserHandle.USER_CURRENT);
    mReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Received settings change intent: " + intent);
            }
            injector.reloadStatusMessages();
        }
    };
    IntentFilter filter = new IntentFilter();
    filter.addAction(SettingInjectorService.ACTION_INJECTED_SETTING_CHANGED);
    context.registerReceiver(mReceiver, filter);
    if (locationServices.size() > 0) {
        addPreferencesSorted(locationServices, categoryLocationServices);
    } else {
        // If there's no item to display, remove the whole category.
        root.removePreference(categoryLocationServices);
    }
}
Also used : Context(android.content.Context) IntentFilter(android.content.IntentFilter) PreferenceCategory(android.support.v7.preference.PreferenceCategory) DimmableIconPreference(com.android.settings.DimmableIconPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) Preference(android.support.v7.preference.Preference) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Example 22 with PreferenceCategory

use of android.support.v7.preference.PreferenceCategory in project android_packages_apps_Settings by LineageOS.

the class AppNotificationSettings method updateDependents.

protected void updateDependents(boolean banned) {
    for (PreferenceCategory category : mChannelGroups) {
        setVisible(category, !banned);
    }
    if (mDeletedChannels != null) {
        setVisible(mDeletedChannels, !banned);
    }
    setVisible(mBlockedDesc, banned);
    setVisible(mBadge, !banned);
    if (mShowLegacyChannelConfig) {
        setVisible(mImportanceToggle, !banned);
        setVisible(mPriority, checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) || (checkCanBeVisible(NotificationManager.IMPORTANCE_LOW) && mDndVisualEffectsSuppressed));
        setVisible(mVisibilityOverride, !banned && checkCanBeVisible(NotificationManager.IMPORTANCE_LOW) && isLockScreenSecure());
    }
    if (mAppLink != null) {
        setVisible(mAppLink, !banned);
    }
    if (mAppRow.systemApp && !mAppRow.banned) {
        setVisible(mBlockBar, false);
    }
}
Also used : PreferenceCategory(android.support.v7.preference.PreferenceCategory)

Example 23 with PreferenceCategory

use of android.support.v7.preference.PreferenceCategory in project android_packages_apps_Settings by LineageOS.

the class AppNotificationSettings method populateChannelList.

private void populateChannelList() {
    if (!mChannelGroups.isEmpty()) {
        // If there's anything in mChannelGroups, we've called populateChannelList twice.
        // Clear out existing channels and log.
        Log.w(TAG, "Notification channel group posted twice to settings - old size " + mChannelGroups.size() + ", new size " + mChannelGroupList.size());
        for (Preference p : mChannelGroups) {
            getPreferenceScreen().removePreference(p);
        }
    }
    if (mChannelGroupList.isEmpty()) {
        PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
        groupCategory.setTitle(R.string.notification_channels);
        groupCategory.setKey(KEY_GENERAL_CATEGORY);
        getPreferenceScreen().addPreference(groupCategory);
        mChannelGroups.add(groupCategory);
        Preference empty = new Preference(getPrefContext());
        empty.setTitle(R.string.no_channels);
        empty.setEnabled(false);
        groupCategory.addPreference(empty);
    } else {
        for (NotificationChannelGroup group : mChannelGroupList) {
            PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
            if (group.getId() == null) {
                groupCategory.setTitle(mChannelGroupList.size() > 1 ? R.string.notification_channels_other : R.string.notification_channels);
                groupCategory.setKey(KEY_GENERAL_CATEGORY);
            } else {
                groupCategory.setTitle(group.getName());
                groupCategory.setKey(group.getId());
            }
            groupCategory.setOrderingAsAdded(true);
            getPreferenceScreen().addPreference(groupCategory);
            mChannelGroups.add(groupCategory);
            final List<NotificationChannel> channels = group.getChannels();
            Collections.sort(channels, mChannelComparator);
            int N = channels.size();
            for (int i = 0; i < N; i++) {
                final NotificationChannel channel = channels.get(i);
                populateSingleChannelPrefs(groupCategory, channel);
            }
        }
        int deletedChannelCount = mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid);
        if (deletedChannelCount > 0 && getPreferenceScreen().findPreference(KEY_DELETED) == null) {
            mDeletedChannels = new FooterPreference(getPrefContext());
            mDeletedChannels.setSelectable(false);
            mDeletedChannels.setTitle(getResources().getQuantityString(R.plurals.deleted_channels, deletedChannelCount, deletedChannelCount));
            mDeletedChannels.setEnabled(false);
            mDeletedChannels.setKey(KEY_DELETED);
            mDeletedChannels.setOrder(ORDER_LAST);
            getPreferenceScreen().addPreference(mDeletedChannels);
        }
    }
    updateDependents(mAppRow.banned);
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationChannelGroup(android.app.NotificationChannelGroup) LayoutPreference(com.android.settings.applications.LayoutPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) FooterPreference(com.android.settingslib.widget.FooterPreference) Preference(android.support.v7.preference.Preference) PreferenceCategory(android.support.v7.preference.PreferenceCategory) FooterPreference(com.android.settingslib.widget.FooterPreference)

Example 24 with PreferenceCategory

use of android.support.v7.preference.PreferenceCategory in project android_packages_apps_Settings by LineageOS.

the class AppNotificationSettings method populateSingleChannelPrefs.

private void populateSingleChannelPrefs(PreferenceCategory groupCategory, final NotificationChannel channel) {
    MasterSwitchPreference channelPref = new MasterSwitchPreference(getPrefContext());
    channelPref.setSwitchEnabled(mSuspendedAppsAdmin == null && isChannelBlockable(mAppRow.systemApp, channel) && isChannelConfigurable(channel));
    channelPref.setKey(channel.getId());
    channelPref.setTitle(channel.getName());
    channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE);
    channelPref.setSummary(getImportanceSummary(channel));
    Bundle channelArgs = new Bundle();
    channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
    channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg);
    channelArgs.putString(Settings.EXTRA_CHANNEL_ID, channel.getId());
    Intent channelIntent = Utils.onBuildStartFragmentIntent(getActivity(), ChannelNotificationSettings.class.getName(), channelArgs, null, R.string.notification_channel_title, null, false, getMetricsCategory());
    channelPref.setIntent(channelIntent);
    channelPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object o) {
            boolean value = (Boolean) o;
            int importance = value ? IMPORTANCE_LOW : IMPORTANCE_NONE;
            channel.setImportance(importance);
            channel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE);
            channelPref.setSummary(getImportanceSummary(channel));
            mBackend.updateChannel(mPkg, mUid, channel);
            return true;
        }
    });
    groupCategory.addPreference(channelPref);
}
Also used : MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) LayoutPreference(com.android.settings.applications.LayoutPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) FooterPreference(com.android.settingslib.widget.FooterPreference) Preference(android.support.v7.preference.Preference) Bundle(android.os.Bundle) Intent(android.content.Intent)

Example 25 with PreferenceCategory

use of android.support.v7.preference.PreferenceCategory in project android_packages_apps_Settings by LineageOS.

the class EnterpriseSetDefaultAppsListPreferenceController method updateUi.

private void updateUi() {
    final Context prefContext = mParent.getPreferenceManager().getContext();
    final PreferenceScreen screen = mParent.getPreferenceScreen();
    if (screen == null) {
        return;
    }
    if (!mEnterprisePrivacyFeatureProvider.isInCompMode() && mUsers.size() == 1) {
        createPreferences(prefContext, screen, mApps.get(0));
    } else {
        for (int i = 0; i < mUsers.size(); i++) {
            final UserInfo userInfo = mUsers.get(i);
            final PreferenceCategory category = new PreferenceCategory(prefContext);
            screen.addPreference(category);
            if (userInfo.isManagedProfile()) {
                category.setTitle(R.string.managed_device_admin_title);
            } else {
                category.setTitle(R.string.personal_device_admin_title);
            }
            category.setOrder(i);
            createPreferences(prefContext, category, mApps.get(i));
        }
    }
}
Also used : Context(android.content.Context) PreferenceScreen(android.support.v7.preference.PreferenceScreen) PreferenceCategory(android.support.v7.preference.PreferenceCategory) UserInfo(android.content.pm.UserInfo)

Aggregations

PreferenceCategory (android.support.v7.preference.PreferenceCategory)166 Preference (android.support.v7.preference.Preference)105 PreferenceScreen (android.support.v7.preference.PreferenceScreen)75 Intent (android.content.Intent)35 Context (android.content.Context)34 SwitchPreference (android.support.v14.preference.SwitchPreference)31 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)27 ArrayList (java.util.ArrayList)24 ComponentName (android.content.ComponentName)22 ListPreference (android.support.v7.preference.ListPreference)18 Bundle (android.os.Bundle)16 PreferenceGroup (android.support.v7.preference.PreferenceGroup)14 DimmableIconPreference (com.android.settings.DimmableIconPreference)14 ContentResolver (android.content.ContentResolver)13 LayoutPreference (com.android.settings.applications.LayoutPreference)13 PreferenceManager (android.support.v7.preference.PreferenceManager)12 MasterSwitchPreference (com.android.settings.widget.MasterSwitchPreference)12 FooterPreference (com.android.settingslib.widget.FooterPreference)12 Test (org.junit.Test)12 Activity (android.app.Activity)9