Search in sources :

Example 21 with ContextualCard

use of com.android.settings.homepage.contextualcards.ContextualCard in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ConditionContextualCardControllerTest method getConditionalCards_hasTwoConditionCardsAndExpanded_shouldGetTwoHalfWidthCards.

@Test
public void getConditionalCards_hasTwoConditionCardsAndExpanded_shouldGetTwoHalfWidthCards() {
    mController.setIsExpanded(true);
    final Map<Integer, List<ContextualCard>> conditionalCards = mController.buildConditionalCardsWithFooterOrHeader(generateConditionCards(2));
    assertThat(conditionalCards).hasSize(3);
    assertThat(conditionalCards.get(CardType.CONDITIONAL)).hasSize(2);
    for (ContextualCard card : conditionalCards.get(CardType.CONDITIONAL)) {
        assertThat(card.getViewType()).isEqualTo(ConditionContextualCardRenderer.VIEW_TYPE_HALF_WIDTH);
    }
    assertThat(conditionalCards.get(CardType.CONDITIONAL_HEADER)).isEmpty();
    assertThat(conditionalCards.get(CardType.CONDITIONAL_FOOTER)).isNotEmpty();
}
Also used : ContextualCard(com.android.settings.homepage.contextualcards.ContextualCard) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 22 with ContextualCard

use of com.android.settings.homepage.contextualcards.ContextualCard in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ConditionFooterContextualCardRendererTest method bindView_shouldSetClickListener.

@Test
public void bindView_shouldSetClickListener() {
    final RecyclerView recyclerView = new RecyclerView(mContext);
    recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
    final ContextualCard card = generateConditionFooterContextualCard();
    final View view = LayoutInflater.from(mContext).inflate(card.getViewType(), recyclerView, false);
    final RecyclerView.ViewHolder viewHolder = mRenderer.createViewHolder(view, card.getViewType());
    when(mControllerRendererPool.getController(mContext, ContextualCard.CardType.CONDITIONAL_FOOTER)).thenReturn(mController);
    mRenderer.bindView(viewHolder, card);
    assertThat(viewHolder.itemView).isNotNull();
    assertThat(viewHolder.itemView.hasOnClickListeners()).isTrue();
}
Also used : ContextualCard(com.android.settings.homepage.contextualcards.ContextualCard) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Test(org.junit.Test)

Example 23 with ContextualCard

use of com.android.settings.homepage.contextualcards.ContextualCard in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ConditionHeaderContextualCardRendererTest method bindView_shouldSetClickListener.

@Test
public void bindView_shouldSetClickListener() {
    final RecyclerView recyclerView = new RecyclerView(mActivity);
    recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
    final ContextualCard card = generateConditionHeaderContextualCard();
    final View view = LayoutInflater.from(mActivity).inflate(card.getViewType(), recyclerView, false);
    final RecyclerView.ViewHolder viewHolder = mRenderer.createViewHolder(view, card.getViewType());
    when(mControllerRendererPool.getController(mActivity, ContextualCard.CardType.CONDITIONAL_HEADER)).thenReturn(mController);
    mRenderer.bindView(viewHolder, generateConditionHeaderContextualCard());
    assertThat(viewHolder.itemView).isNotNull();
    assertThat(viewHolder.itemView.hasOnClickListeners()).isTrue();
}
Also used : ContextualCard(com.android.settings.homepage.contextualcards.ContextualCard) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Test(org.junit.Test)

Example 24 with ContextualCard

use of com.android.settings.homepage.contextualcards.ContextualCard in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class LegacySuggestionContextualCardController method loadSuggestions.

private void loadSuggestions() {
    ThreadUtils.postOnBackgroundThread(() -> {
        if (mSuggestionController == null || mCardUpdateListener == null) {
            return;
        }
        final List<Suggestion> suggestions = mSuggestionController.getSuggestions();
        final String suggestionCount = suggestions == null ? "null" : String.valueOf(suggestions.size());
        Log.d(TAG, "Loaded suggests: " + suggestionCount);
        final List<ContextualCard> cards = new ArrayList<>();
        if (suggestions != null) {
            // Convert suggestion to ContextualCard
            for (Suggestion suggestion : suggestions) {
                final LegacySuggestionContextualCard.Builder cardBuilder = new LegacySuggestionContextualCard.Builder();
                if (suggestion.getIcon() != null) {
                    cardBuilder.setIconDrawable(suggestion.getIcon().loadDrawable(mContext));
                }
                cardBuilder.setPendingIntent(suggestion.getPendingIntent()).setSuggestion(suggestion).setName(suggestion.getId()).setTitleText(suggestion.getTitle().toString()).setSummaryText(suggestion.getSummary().toString()).setViewType(LegacySuggestionContextualCardRenderer.VIEW_TYPE);
                cards.add(cardBuilder.build());
            }
        }
        mSuggestions.clear();
        mSuggestions.addAll(cards);
        updateAdapter();
    });
}
Also used : Suggestion(android.service.settings.suggestions.Suggestion) ArrayList(java.util.ArrayList) ContextualCard(com.android.settings.homepage.contextualcards.ContextualCard)

Example 25 with ContextualCard

use of com.android.settings.homepage.contextualcards.ContextualCard in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ContextualCardLogUtils method buildCardListLog.

/**
 * Serialize List of {@link ContextualCard} to string
 */
public static String buildCardListLog(List<ContextualCard> cards) {
    final StringBuilder log = new StringBuilder();
    log.append(cards.size());
    for (ContextualCard card : cards) {
        log.append("|").append(card.getTextSliceUri()).append("|").append(card.getRankingScore());
    }
    return log.toString();
}
Also used : ContextualCard(com.android.settings.homepage.contextualcards.ContextualCard)

Aggregations

ContextualCard (com.android.settings.homepage.contextualcards.ContextualCard)35 Test (org.junit.Test)32 RecyclerView (androidx.recyclerview.widget.RecyclerView)21 View (android.view.View)15 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)10 ArrayList (java.util.ArrayList)6 Button (android.widget.Button)4 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 Suggestion (android.service.settings.suggestions.Suggestion)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 Future (java.util.concurrent.Future)1 TimeoutException (java.util.concurrent.TimeoutException)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1