Search in sources :

Example 16 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project android_packages_apps_Settings by omnirom.

the class ChannelListPreferenceControllerTest method setUp.

@Before
public void setUp() throws Exception {
    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    mContext = instrumentation.getTargetContext();
    instrumentation.runOnMainSync(() -> {
        mBackend = new NotificationBackend();
        mAppRow = mBackend.loadAppRow(mContext, mContext.getPackageManager(), mContext.getApplicationInfo());
        mController = new ChannelListPreferenceController(mContext, mBackend);
        mController.onResume(mAppRow, null, null, null, null, null);
        mPreferenceManager = new PreferenceManager(mContext);
        mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
        mGroupList = new PreferenceCategory(mContext);
        mPreferenceScreen.addPreference(mGroupList);
    });
}
Also used : NotificationBackend(com.android.settings.notification.NotificationBackend) PreferenceCategory(androidx.preference.PreferenceCategory) Instrumentation(android.app.Instrumentation) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 17 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project android_packages_apps_Settings by omnirom.

the class ConversationListPreferenceControllerTest method testPopulateList_hideIfNoConversations.

@Test
public void testPopulateList_hideIfNoConversations() {
    PreferenceCategory outerContainer = mock(PreferenceCategory.class);
    mController.populateList(new ArrayList<>(), outerContainer);
    verify(outerContainer).setVisible(false);
    verify(outerContainer, never()).addPreference(any());
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) Test(org.junit.Test)

Example 18 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project android_packages_apps_Settings by omnirom.

the class ConversationListPreferenceControllerTest method populateConversations.

@Test
public void populateConversations() {
    PreferenceCategory container = mock(PreferenceCategory.class);
    ConversationChannelWrapper ccw = new ConversationChannelWrapper();
    ccw.setNotificationChannel(mock(NotificationChannel.class));
    ccw.setPkg("pkg");
    ccw.setUid(1);
    ccw.setShortcutInfo(mock(ShortcutInfo.class));
    ConversationChannelWrapper ccwDemoted = new ConversationChannelWrapper();
    NotificationChannel demoted = new NotificationChannel("a", "a", 2);
    demoted.setDemoted(true);
    ccwDemoted.setNotificationChannel(demoted);
    ccwDemoted.setPkg("pkg");
    ccwDemoted.setUid(1);
    ccwDemoted.setShortcutInfo(mock(ShortcutInfo.class));
    ArrayList<ConversationChannelWrapper> list = new ArrayList<>();
    list.add(ccw);
    list.add(ccwDemoted);
    mController.populateConversations(list, container);
    verify(container, times(1)).addPreference(any());
}
Also used : NotificationChannel(android.app.NotificationChannel) ShortcutInfo(android.content.pm.ShortcutInfo) PreferenceCategory(androidx.preference.PreferenceCategory) ConversationChannelWrapper(android.service.notification.ConversationChannelWrapper) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 19 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project android_packages_apps_Settings by omnirom.

the class ConversationListPreferenceControllerTest method testPopulateList_validConversations.

@Test
public void testPopulateList_validConversations() {
    final PreferenceManager preferenceManager = new PreferenceManager(mContext);
    PreferenceScreen ps = preferenceManager.createPreferenceScreen(mContext);
    PreferenceCategory outerContainer = spy(new PreferenceCategory(mContext));
    ps.addPreference(outerContainer);
    ConversationChannelWrapper ccw = new ConversationChannelWrapper();
    ccw.setNotificationChannel(mock(NotificationChannel.class));
    ccw.setPkg("pkg");
    ccw.setUid(1);
    ccw.setShortcutInfo(mock(ShortcutInfo.class));
    ArrayList<ConversationChannelWrapper> list = new ArrayList<>();
    list.add(ccw);
    mController.populateList(list, outerContainer);
    verify(outerContainer, times(1)).addPreference(any());
}
Also used : NotificationChannel(android.app.NotificationChannel) PreferenceScreen(androidx.preference.PreferenceScreen) ShortcutInfo(android.content.pm.ShortcutInfo) PreferenceCategory(androidx.preference.PreferenceCategory) ConversationChannelWrapper(android.service.notification.ConversationChannelWrapper) ArrayList(java.util.ArrayList) PreferenceManager(androidx.preference.PreferenceManager) Test(org.junit.Test)

Example 20 with PreferenceCategory

use of androidx.preference.PreferenceCategory in project android_packages_apps_Settings by omnirom.

the class RecentConversationsPreferenceControllerTest method testRemoveConversation.

@Test
public void testRemoveConversation() throws Exception {
    ShortcutInfo si = mock(ShortcutInfo.class);
    when(si.getId()).thenReturn("person");
    when(si.getPackage()).thenReturn("pkg");
    ConversationChannel ccw = new ConversationChannel(si, 6, new NotificationChannel("hi", "channel", 4), new NotificationChannelGroup("hi", "group"), 7, false);
    RecentConversationPreference pref = (RecentConversationPreference) mController.createConversationPref(new PreferenceCategory(mContext), ccw, 100);
    final View view = View.inflate(mContext, pref.getLayoutResource(), null);
    PreferenceViewHolder holder = spy(PreferenceViewHolder.createInstanceForTests(view));
    View delete = View.inflate(mContext, pref.getSecondTargetResId(), null);
    when(holder.findViewById(pref.getClearId())).thenReturn(delete);
    pref.onBindViewHolder(holder);
    pref.getClearView().performClick();
    verify(mPs).removeRecentConversation(si.getPackage(), UserHandle.getUserId(ccw.getUid()), si.getId());
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationChannelGroup(android.app.NotificationChannelGroup) ShortcutInfo(android.content.pm.ShortcutInfo) ConversationChannel(android.app.people.ConversationChannel) PreferenceCategory(androidx.preference.PreferenceCategory) View(android.view.View) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) Test(org.junit.Test)

Aggregations

PreferenceCategory (androidx.preference.PreferenceCategory)111 Preference (androidx.preference.Preference)38 PreferenceManager (androidx.preference.PreferenceManager)24 Before (org.junit.Before)24 PreferenceScreen (androidx.preference.PreferenceScreen)22 Test (org.junit.Test)19 SwitchPreference (androidx.preference.SwitchPreference)13 NotificationChannel (android.app.NotificationChannel)11 ArrayList (java.util.ArrayList)11 NotificationChannelGroup (android.app.NotificationChannelGroup)9 ShortcutInfo (android.content.pm.ShortcutInfo)9 Context (android.content.Context)8 ConversationChannel (android.app.people.ConversationChannel)7 View (android.view.View)7 PreferenceViewHolder (androidx.preference.PreferenceViewHolder)7 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)7 ListPreference (androidx.preference.ListPreference)6 ComponentName (android.content.ComponentName)5 ContentResolver (android.content.ContentResolver)5 Bundle (android.os.Bundle)5