Search in sources :

Example 46 with NotificationChannelGroup

use of android.app.NotificationChannelGroup in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NotificationChannelSlice method getDisplayableChannels.

private List<NotificationChannel> getDisplayableChannels(NotificationBackend.AppRow appRow) {
    final List<NotificationChannelGroup> channelGroupList = mNotificationBackend.getGroups(appRow.pkg, appRow.uid).getList();
    final List<NotificationChannel> channels = channelGroupList.stream().flatMap(group -> group.getChannels().stream().filter(channel -> isChannelEnabled(group, channel, appRow))).collect(Collectors.toList());
    // Pack the notification channel with notification sent state for sorting.
    final List<NotificationChannelState> channelStates = new ArrayList<>();
    for (NotificationChannel channel : channels) {
        NotificationsSentState sentState = appRow.sentByChannel.get(channel.getId());
        if (sentState == null) {
            sentState = new NotificationsSentState();
        }
        channelStates.add(new NotificationChannelState(sentState, channel));
    }
    // Sort the notification channels with notification sent count by descending.
    return channelStates.stream().sorted(CHANNEL_STATE_COMPARATOR).map(state -> state.getNotificationChannel()).limit(DEFAULT_EXPANDED_ROW_COUNT).collect(Collectors.toList());
}
Also used : NotificationChannel(android.app.NotificationChannel) Bundle(android.os.Bundle) EXTRA_TOGGLE_STATE(android.app.slice.Slice.EXTRA_TOGGLE_STATE) PackageManager(android.content.pm.PackageManager) ListBuilder(androidx.slice.builders.ListBuilder) Uri(android.net.Uri) TimeoutException(java.util.concurrent.TimeoutException) PendingIntent(android.app.PendingIntent) Drawable(android.graphics.drawable.Drawable) SubSettings(com.android.settings.SubSettings) Future(java.util.concurrent.Future) NotificationChannel(android.app.NotificationChannel) Log(android.util.Log) R(com.android.settings.R) SliceAction(androidx.slice.builders.SliceAction) Collectors(java.util.stream.Collectors) CustomSliceable(com.android.settings.slices.CustomSliceable) VisibleForTesting(com.android.internal.annotations.VisibleForTesting) List(java.util.List) Application(android.app.Application) Utils(com.android.settings.Utils) RestrictedLockUtilsInternal(com.android.settingslib.RestrictedLockUtilsInternal) NotificationBackend(com.android.settings.notification.NotificationBackend) AppNotificationSettings(com.android.settings.notification.AppNotificationSettings) IMPORTANCE_NONE(android.app.NotificationManager.IMPORTANCE_NONE) Context(android.content.Context) Slice(androidx.slice.Slice) Intent(android.content.Intent) NotificationsSentState(com.android.settings.notification.NotificationBackend.NotificationsSentState) PackageInfo(android.content.pm.PackageInfo) ArrayList(java.util.ArrayList) AppInfoBase(com.android.settings.applications.AppInfoBase) IMPORTANCE_LOW(android.app.NotificationManager.IMPORTANCE_LOW) ChannelNotificationSettings(com.android.settings.notification.ChannelNotificationSettings) AppAndNotificationDashboardFragment(com.android.settings.applications.AppAndNotificationDashboardFragment) UserHandle(android.os.UserHandle) SliceBroadcastReceiver(com.android.settings.slices.SliceBroadcastReceiver) Settings(android.provider.Settings) SliceBuilderUtils(com.android.settings.slices.SliceBuilderUtils) SubSettingLauncher(com.android.settings.core.SubSettingLauncher) RestrictedLockUtils(com.android.settingslib.RestrictedLockUtils) SettingsEnums(android.app.settings.SettingsEnums) TextUtils(android.text.TextUtils) NotificationChannelGroup(android.app.NotificationChannelGroup) ApplicationsState(com.android.settingslib.applications.ApplicationsState) ThreadUtils(com.android.settingslib.utils.ThreadUtils) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) IconCompat(androidx.core.graphics.drawable.IconCompat) CustomSliceRegistry(com.android.settings.slices.CustomSliceRegistry) Comparator(java.util.Comparator) NotificationChannelGroup(android.app.NotificationChannelGroup) NotificationsSentState(com.android.settings.notification.NotificationBackend.NotificationsSentState) ArrayList(java.util.ArrayList)

Example 47 with NotificationChannelGroup

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

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) ColorSelectPreference(org.omnirom.omnigears.preference.ColorSelectPreference) RestrictedSwitchPreference(com.android.settingslib.RestrictedSwitchPreference) SeekBarPreference(org.omnirom.omnigears.preference.SeekBarPreference) MasterSwitchPreference(com.android.settings.widget.MasterSwitchPreference) FooterPreference(com.android.settingslib.widget.FooterPreference) Preference(android.support.v7.preference.Preference) SwitchPreference(android.support.v14.preference.SwitchPreference) PreferenceCategory(android.support.v7.preference.PreferenceCategory) FooterPreference(com.android.settingslib.widget.FooterPreference)

Example 48 with NotificationChannelGroup

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

the class NotificationHelper method createNotificationChannelsForAccount.

public static void createNotificationChannelsForAccount(AccountEntity account, 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_BOOST + account.getIdentifier(), CHANNEL_FAVOURITE + account.getIdentifier() };
        int[] channelNames = { R.string.notification_channel_mention_name, R.string.notification_channel_follow_name, R.string.notification_channel_boost_name, R.string.notification_channel_favourite_name };
        int[] channelDescriptions = { R.string.notification_channel_mention_descriptions, R.string.notification_channel_follow_description, R.string.notification_channel_boost_description, R.string.notification_channel_favourite_description };
        List<NotificationChannel> channels = new ArrayList<>(4);
        NotificationChannelGroup channelGroup = new NotificationChannelGroup(account.getIdentifier(), account.getFullName());
        // noinspection ConstantConditions
        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);
        }
        // noinspection ConstantConditions
        notificationManager.createNotificationChannels(channels);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationChannelGroup(android.app.NotificationChannelGroup) NotificationManager(android.app.NotificationManager) ArrayList(java.util.ArrayList)

Example 49 with NotificationChannelGroup

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

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

use of android.app.NotificationChannelGroup in project Conversations by siacs.

the class NotificationService method initializeChannels.

@RequiresApi(api = Build.VERSION_CODES.O)
void initializeChannels() {
    final Context c = mXmppConnectionService;
    final NotificationManager notificationManager = c.getSystemService(NotificationManager.class);
    if (notificationManager == null) {
        return;
    }
    notificationManager.deleteNotificationChannel("export");
    notificationManager.deleteNotificationChannel("incoming_calls");
    notificationManager.createNotificationChannelGroup(new NotificationChannelGroup("status", c.getString(R.string.notification_group_status_information)));
    notificationManager.createNotificationChannelGroup(new NotificationChannelGroup("chats", c.getString(R.string.notification_group_messages)));
    notificationManager.createNotificationChannelGroup(new NotificationChannelGroup("calls", c.getString(R.string.notification_group_calls)));
    final NotificationChannel foregroundServiceChannel = new NotificationChannel("foreground", c.getString(R.string.foreground_service_channel_name), NotificationManager.IMPORTANCE_MIN);
    foregroundServiceChannel.setDescription(c.getString(R.string.foreground_service_channel_description, c.getString(R.string.app_name)));
    foregroundServiceChannel.setShowBadge(false);
    foregroundServiceChannel.setGroup("status");
    notificationManager.createNotificationChannel(foregroundServiceChannel);
    final NotificationChannel errorChannel = new NotificationChannel("error", c.getString(R.string.error_channel_name), NotificationManager.IMPORTANCE_LOW);
    errorChannel.setDescription(c.getString(R.string.error_channel_description));
    errorChannel.setShowBadge(false);
    errorChannel.setGroup("status");
    notificationManager.createNotificationChannel(errorChannel);
    final NotificationChannel videoCompressionChannel = new NotificationChannel("compression", c.getString(R.string.video_compression_channel_name), NotificationManager.IMPORTANCE_LOW);
    videoCompressionChannel.setShowBadge(false);
    videoCompressionChannel.setGroup("status");
    notificationManager.createNotificationChannel(videoCompressionChannel);
    final NotificationChannel exportChannel = new NotificationChannel("backup", c.getString(R.string.backup_channel_name), NotificationManager.IMPORTANCE_LOW);
    exportChannel.setShowBadge(false);
    exportChannel.setGroup("status");
    notificationManager.createNotificationChannel(exportChannel);
    final NotificationChannel incomingCallsChannel = new NotificationChannel(INCOMING_CALLS_NOTIFICATION_CHANNEL, c.getString(R.string.incoming_calls_channel_name), NotificationManager.IMPORTANCE_HIGH);
    incomingCallsChannel.setSound(null, null);
    incomingCallsChannel.setShowBadge(false);
    incomingCallsChannel.setLightColor(LED_COLOR);
    incomingCallsChannel.enableLights(true);
    incomingCallsChannel.setGroup("calls");
    incomingCallsChannel.setBypassDnd(true);
    incomingCallsChannel.enableVibration(false);
    notificationManager.createNotificationChannel(incomingCallsChannel);
    final NotificationChannel ongoingCallsChannel = new NotificationChannel("ongoing_calls", c.getString(R.string.ongoing_calls_channel_name), NotificationManager.IMPORTANCE_LOW);
    ongoingCallsChannel.setShowBadge(false);
    ongoingCallsChannel.setGroup("calls");
    notificationManager.createNotificationChannel(ongoingCallsChannel);
    final NotificationChannel messagesChannel = new NotificationChannel("messages", c.getString(R.string.messages_channel_name), NotificationManager.IMPORTANCE_HIGH);
    messagesChannel.setShowBadge(true);
    messagesChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT).build());
    messagesChannel.setLightColor(LED_COLOR);
    final int dat = 70;
    final long[] pattern = { 0, 3 * dat, dat, dat };
    messagesChannel.setVibrationPattern(pattern);
    messagesChannel.enableVibration(true);
    messagesChannel.enableLights(true);
    messagesChannel.setGroup("chats");
    notificationManager.createNotificationChannel(messagesChannel);
    final NotificationChannel silentMessagesChannel = new NotificationChannel("silent_messages", c.getString(R.string.silent_messages_channel_name), NotificationManager.IMPORTANCE_LOW);
    silentMessagesChannel.setDescription(c.getString(R.string.silent_messages_channel_description));
    silentMessagesChannel.setShowBadge(true);
    silentMessagesChannel.setLightColor(LED_COLOR);
    silentMessagesChannel.enableLights(true);
    silentMessagesChannel.setGroup("chats");
    notificationManager.createNotificationChannel(silentMessagesChannel);
    final NotificationChannel quietHoursChannel = new NotificationChannel("quiet_hours", c.getString(R.string.title_pref_quiet_hours), NotificationManager.IMPORTANCE_LOW);
    quietHoursChannel.setShowBadge(true);
    quietHoursChannel.setLightColor(LED_COLOR);
    quietHoursChannel.enableLights(true);
    quietHoursChannel.setGroup("chats");
    quietHoursChannel.enableVibration(false);
    quietHoursChannel.setSound(null, null);
    notificationManager.createNotificationChannel(quietHoursChannel);
    final NotificationChannel deliveryFailedChannel = new NotificationChannel("delivery_failed", c.getString(R.string.delivery_failed_channel_name), NotificationManager.IMPORTANCE_DEFAULT);
    deliveryFailedChannel.setShowBadge(false);
    deliveryFailedChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).setUsage(AudioAttributes.USAGE_NOTIFICATION_COMMUNICATION_INSTANT).build());
    deliveryFailedChannel.setGroup("chats");
    notificationManager.createNotificationChannel(deliveryFailedChannel);
}
Also used : Context(android.content.Context) NotificationChannel(android.app.NotificationChannel) NotificationChannelGroup(android.app.NotificationChannelGroup) NotificationManager(android.app.NotificationManager) Builder(androidx.core.app.NotificationCompat.Builder) RequiresApi(androidx.annotation.RequiresApi)

Aggregations

NotificationChannelGroup (android.app.NotificationChannelGroup)80 NotificationChannel (android.app.NotificationChannel)54 Test (org.junit.Test)53 NotificationBackend (com.android.settings.notification.NotificationBackend)21 ArrayList (java.util.ArrayList)12 ConversationChannel (android.app.people.ConversationChannel)10 ShortcutInfo (android.content.pm.ShortcutInfo)10 PreferenceCategory (androidx.preference.PreferenceCategory)9 TargetApi (android.annotation.TargetApi)8 Preference (android.support.v7.preference.Preference)6 PreferenceCategory (android.support.v7.preference.PreferenceCategory)6 Preference (androidx.preference.Preference)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 PreferenceGroup (androidx.preference.PreferenceGroup)3