Search in sources :

Example 1 with NotificationChannelGroup

use of android.app.NotificationChannelGroup 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 2 with NotificationChannelGroup

use of android.app.NotificationChannelGroup in project android_packages_apps_Settings by DirtyUnicorns.

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 3 with NotificationChannelGroup

use of android.app.NotificationChannelGroup in project platform_packages_apps_Settings by BlissRoms.

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 4 with NotificationChannelGroup

use of android.app.NotificationChannelGroup in project AgileDev by LZ9.

the class NotificationActivity method initNotificationChannel.

/**
 * 初始化通知通道
 */
private void initNotificationChannel() {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        NotificationChannelGroup group = new NotificationChannelGroup(NOTIFI_GROUP_ID, "通知组");
        // 设置通知组
        NotificationUtils.create(getContext()).createNotificationChannelGroup(group);
        List<NotificationChannel> channels = new ArrayList<>();
        channels.add(getMainChannel());
        channels.add(getDownloadChannel());
        // 设置频道
        NotificationUtils.create(getContext()).createNotificationChannels(channels);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationChannelGroup(android.app.NotificationChannelGroup) ArrayList(java.util.ArrayList)

Example 5 with NotificationChannelGroup

use of android.app.NotificationChannelGroup in project Tusky by Vavassor.

the class NotificationHelper method createNotificationChannelsForAccount.

public static void createNotificationChannelsForAccount(@NonNull AccountEntity account, @NonNull Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        String[] channelIds = new String[] { CHANNEL_MENTION + account.getIdentifier(), CHANNEL_FOLLOW + account.getIdentifier(), CHANNEL_FOLLOW_REQUEST + account.getIdentifier(), CHANNEL_BOOST + account.getIdentifier(), CHANNEL_FAVOURITE + account.getIdentifier(), CHANNEL_POLL + account.getIdentifier(), CHANNEL_SUBSCRIPTIONS + account.getIdentifier() };
        int[] channelNames = { R.string.notification_mention_name, R.string.notification_follow_name, R.string.notification_follow_request_name, R.string.notification_boost_name, R.string.notification_favourite_name, R.string.notification_poll_name, R.string.notification_subscription_name };
        int[] channelDescriptions = { R.string.notification_mention_descriptions, R.string.notification_follow_description, R.string.notification_follow_request_description, R.string.notification_boost_description, R.string.notification_favourite_description, R.string.notification_poll_description, R.string.notification_subscription_description };
        List<NotificationChannel> channels = new ArrayList<>(6);
        NotificationChannelGroup channelGroup = new NotificationChannelGroup(account.getIdentifier(), account.getFullName());
        notificationManager.createNotificationChannelGroup(channelGroup);
        for (int i = 0; i < channelIds.length; i++) {
            String id = channelIds[i];
            String name = context.getString(channelNames[i]);
            String description = context.getString(channelDescriptions[i]);
            int importance = NotificationManager.IMPORTANCE_DEFAULT;
            NotificationChannel channel = new NotificationChannel(id, name, importance);
            channel.setDescription(description);
            channel.enableLights(true);
            channel.setLightColor(0xFF2B90D9);
            channel.enableVibration(true);
            channel.setShowBadge(true);
            channel.setGroup(account.getIdentifier());
            channels.add(channel);
        }
        notificationManager.createNotificationChannels(channels);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationChannelGroup(android.app.NotificationChannelGroup) NotificationManager(android.app.NotificationManager) ArrayList(java.util.ArrayList)

Aggregations

NotificationChannelGroup (android.app.NotificationChannelGroup)46 NotificationChannel (android.app.NotificationChannel)31 Test (org.junit.Test)20 TargetApi (android.annotation.TargetApi)8 Preference (android.support.v7.preference.Preference)6 PreferenceCategory (android.support.v7.preference.PreferenceCategory)6 LayoutPreference (com.android.settings.applications.LayoutPreference)6 MasterSwitchPreference (com.android.settings.widget.MasterSwitchPreference)6 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)6 FooterPreference (com.android.settingslib.widget.FooterPreference)6 NotificationManager (android.app.NotificationManager)5 Notification (android.app.Notification)4 AudioAttributes (android.media.AudioAttributes)4 ArrayList (java.util.ArrayList)4 Context (android.content.Context)2 Uri (android.net.Uri)2 RequiresApi (androidx.annotation.RequiresApi)2 Preference (androidx.preference.Preference)2 JSONObject (org.json.JSONObject)2 Application (android.app.Application)1