Search in sources :

Example 41 with Tile

use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by omnirom.

the class SummaryLoaderTest method SetUp.

@Before
public void SetUp() {
    MockitoAnnotations.initMocks(this);
    mFeatureFactory = FakeFeatureFactory.setupForTest(mContext);
    mTile = new Tile();
    mTile.summary = SUMMARY_1;
    mCallbackInvoked = false;
    final Activity activity = Robolectric.buildActivity(Activity.class).get();
    final List<DashboardCategory> categories = new ArrayList<>();
    mSummaryLoader = new SummaryLoader(activity, categories);
    mSummaryLoader.setSummaryConsumer(new SummaryLoader.SummaryConsumer() {

        @Override
        public void notifySummaryChanged(Tile tile) {
            mCallbackInvoked = true;
        }
    });
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) ArrayList(java.util.ArrayList) Tile(com.android.settingslib.drawer.Tile) Activity(android.app.Activity) Before(org.junit.Before)

Example 42 with Tile

use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by omnirom.

the class SummaryLoaderTest method testUpdateSummaryToCache_hasCache_shouldUpdate.

@Test
public void testUpdateSummaryToCache_hasCache_shouldUpdate() {
    final String testSummary = "test_summary";
    final DashboardCategory category = new DashboardCategory();
    final Tile tile = new Tile();
    tile.key = "123";
    tile.intent = new Intent();
    category.addTile(tile);
    when(mFeatureFactory.dashboardFeatureProvider.getDashboardKeyForTile(tile)).thenReturn(tile.key);
    mSummaryLoader.updateSummaryIfNeeded(tile, testSummary);
    tile.summary = null;
    mSummaryLoader.updateSummaryToCache(category);
    assertThat(tile.summary).isEqualTo(testSummary);
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) Tile(com.android.settingslib.drawer.Tile) Intent(android.content.Intent) Test(org.junit.Test)

Example 43 with Tile

use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by omnirom.

the class DashboardAdapterTest method makeSuggestions.

private List<Tile> makeSuggestions(String... pkgNames) {
    final List<Tile> suggestions = new ArrayList<>();
    for (String pkgName : pkgNames) {
        Tile suggestion = new Tile();
        suggestion.intent = new Intent("action");
        suggestion.intent.setComponent(new ComponentName(pkgName, "cls"));
        suggestions.add(suggestion);
    }
    return suggestions;
}
Also used : ArrayList(java.util.ArrayList) Tile(com.android.settingslib.drawer.Tile) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Example 44 with Tile

use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by omnirom.

the class DashboardAdapterTest method testSuggestionDismissed_notOnlySuggestion_updateSuggestionOnly.

@Test
public void testSuggestionDismissed_notOnlySuggestion_updateSuggestionOnly() {
    final DashboardAdapter adapter = spy(new DashboardAdapter(mContext, null, null, null, null));
    final List<Tile> suggestions = makeSuggestions("pkg1", "pkg2", "pkg3");
    adapter.setCategoriesAndSuggestions(null, /* category */
    suggestions);
    final RecyclerView data = mock(RecyclerView.class);
    when(data.getResources()).thenReturn(mResources);
    when(data.getContext()).thenReturn(mContext);
    when(mResources.getDisplayMetrics()).thenReturn(mock(DisplayMetrics.class));
    final View itemView = mock(View.class);
    when(itemView.findViewById(R.id.data)).thenReturn(data);
    final DashboardAdapter.SuggestionAndConditionContainerHolder holder = new DashboardAdapter.SuggestionAndConditionContainerHolder(itemView);
    adapter.onBindConditionAndSuggestion(holder, DashboardAdapter.SUGGESTION_CONDITION_HEADER_POSITION);
    final DashboardData dashboardData = adapter.mDashboardData;
    // clear interactions tracking
    reset(adapter);
    final Tile suggestionToRemove = suggestions.get(1);
    adapter.onSuggestionDismissed(suggestionToRemove);
    assertThat(adapter.mDashboardData).isEqualTo(dashboardData);
    assertThat(suggestions.size()).isEqualTo(2);
    assertThat(suggestions.contains(suggestionToRemove)).isFalse();
    verify(adapter, never()).notifyDashboardDataChanged(any());
}
Also used : Tile(com.android.settingslib.drawer.Tile) RecyclerView(android.support.v7.widget.RecyclerView) DisplayMetrics(android.util.DisplayMetrics) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Test(org.junit.Test)

Example 45 with Tile

use of com.android.settingslib.drawer.Tile in project android_packages_apps_Settings by omnirom.

the class DashboardAdapterTest method testSuggestionDismissed_moreThanTwoSuggestions_defaultMode_shouldNotCrash.

@Test
public void testSuggestionDismissed_moreThanTwoSuggestions_defaultMode_shouldNotCrash() {
    final RecyclerView data = new RecyclerView(RuntimeEnvironment.application);
    final View itemView = mock(View.class);
    when(itemView.findViewById(R.id.data)).thenReturn(data);
    final DashboardAdapter.SuggestionAndConditionContainerHolder holder = new DashboardAdapter.SuggestionAndConditionContainerHolder(itemView);
    final List<Tile> suggestions = makeSuggestions("pkg1", "pkg2", "pkg3", "pkg4");
    final DashboardAdapter adapter = spy(new DashboardAdapter(mContext, null, /*savedInstance */
    null, /* conditions */
    null, /* suggestionParser */
    null));
    adapter.setCategoriesAndSuggestions(null, /* category */
    suggestions);
    adapter.onBindConditionAndSuggestion(holder, DashboardAdapter.SUGGESTION_CONDITION_HEADER_POSITION);
    // default mode, only displaying 2 suggestions
    adapter.onSuggestionDismissed(suggestions.get(1));
    // verify operations that access the lists will not cause ConcurrentModificationException
    assertThat(holder.data.getAdapter().getItemCount()).isEqualTo(1);
    adapter.setCategoriesAndSuggestions(null, /* category */
    suggestions);
// should not crash
}
Also used : Tile(com.android.settingslib.drawer.Tile) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Test(org.junit.Test)

Aggregations

Tile (com.android.settingslib.drawer.Tile)466 Test (org.junit.Test)309 Intent (android.content.Intent)158 Bundle (android.os.Bundle)117 Preference (android.support.v7.preference.Preference)108 DashboardCategory (com.android.settingslib.drawer.DashboardCategory)102 ComponentName (android.content.ComponentName)98 ArrayList (java.util.ArrayList)79 Context (android.content.Context)71 UserHandle (android.os.UserHandle)32 Activity (android.app.Activity)31 RecyclerView (android.support.v7.widget.RecyclerView)31 View (android.view.View)31 Icon (android.graphics.drawable.Icon)30 VisibleForTesting (android.support.annotation.VisibleForTesting)30 PackageManager (android.content.pm.PackageManager)25 TypedArray (android.content.res.TypedArray)24 ViewGroup (android.view.ViewGroup)24 RemoteViews (android.widget.RemoteViews)24 SettingsActivity (com.android.settings.SettingsActivity)24