Search in sources :

Example 51 with NotificationChannelGroup

use of android.app.NotificationChannelGroup in project robolectric by robolectric.

the class ShadowNotificationManagerTest method createNotificationChannelGroup.

@Test
@Config(minSdk = Build.VERSION_CODES.O)
public void createNotificationChannelGroup() {
    notificationManager.createNotificationChannelGroup(new NotificationChannelGroup("id", "name"));
    assertThat(shadowOf(notificationManager).getNotificationChannelGroups()).hasSize(1);
    NotificationChannelGroup group = (NotificationChannelGroup) shadowOf(notificationManager).getNotificationChannelGroup("id");
    assertThat(group.getName().toString()).isEqualTo("name");
}
Also used : NotificationChannelGroup(android.app.NotificationChannelGroup) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 52 with NotificationChannelGroup

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

the class NotificationUtils method notificationChannelBuild.

/**
 * 如何创建一个NotificationChannel
 */
private void notificationChannelBuild() {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        NotificationChannelGroup group = new NotificationChannelGroup("g0001", "测试分组");
        String channelId = "c00001";
        String channelName = "测试通道";
        int level = NotificationManager.IMPORTANCE_DEFAULT;
        NotificationChannel channel = new NotificationChannel(channelId, channelName, level);
        // 开启指示灯,如果设备有的话。
        channel.enableLights(true);
        // 设置指示灯颜色
        channel.setLightColor(Color.RED);
        // 通道描述
        channel.setDescription("通道描述");
        // 开启震动
        channel.enableVibration(true);
        // 设置震动频率
        channel.setVibrationPattern(new long[] { 100, 200, 400, 300, 100 });
        channel.setGroup(group.getId());
        // 检测是否绕过免打扰模式
        channel.canBypassDnd();
        // 设置绕过免打扰模式
        channel.setBypassDnd(true);
        channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
        // 检测是否显示角标
        channel.canShowBadge();
        // 设置是否显示角标
        channel.setShowBadge(true);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationChannelGroup(android.app.NotificationChannelGroup)

Example 53 with NotificationChannelGroup

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

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

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

the class ChannelListPreferenceController method populateGroupList.

private void populateGroupList() {
    for (NotificationChannelGroup group : mChannelGroupList) {
        PreferenceCategory groupCategory = new PreferenceCategory(mContext);
        groupCategory.setOrderingAsAdded(true);
        mPreference.addPreference(groupCategory);
        if (group.getId() == null) {
            if (mChannelGroupList.size() > 1) {
                groupCategory.setTitle(R.string.notification_channels_other);
            }
            groupCategory.setKey(KEY_GENERAL_CATEGORY);
        } else {
            groupCategory.setTitle(group.getName());
            groupCategory.setKey(group.getId());
            populateGroupToggle(groupCategory, group);
        }
        if (!group.isBlocked()) {
            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, group.isBlocked());
            }
        }
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationChannelGroup(android.app.NotificationChannelGroup) PreferenceCategory(androidx.preference.PreferenceCategory)

Example 55 with NotificationChannelGroup

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

the class NotificationPreferenceControllerTest method isAvailable_notIfChannelBlocked.

@Test
public void isAvailable_notIfChannelBlocked() {
    NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
    NotificationChannelGroup group = mock(NotificationChannelGroup.class);
    when(group.isBlocked()).thenReturn(false);
    NotificationChannel channel = mock(NotificationChannel.class);
    when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
    mController.onResume(appRow, channel, group, null);
    assertFalse(mController.isAvailable());
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationChannelGroup(android.app.NotificationChannelGroup) Test(org.junit.Test)

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