Loading res/values/dimens.xml +1 −0 Original line number Diff line number Diff line Loading @@ -348,6 +348,7 @@ <dimen name="contextual_half_card_padding_top">12dp</dimen> <dimen name="contextual_half_card_padding_bottom">16dp</dimen> <dimen name="contextual_half_card_title_margin_top">12dp</dimen> <dimen name="contextual_card_preallocated_height">0dp</dimen> <!-- Homepage dismissal cards size and padding --> <dimen name="contextual_card_dismissal_margin_top">12dp</dimen> Loading src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java +4 −5 Original line number Diff line number Diff line Loading @@ -50,7 +50,7 @@ import java.util.stream.Collectors; public class ContextualCardLoader extends AsyncLoaderCompat<List<ContextualCard>> { @VisibleForTesting static final int DEFAULT_CARD_COUNT = 3; static final int DEFAULT_CARD_COUNT = 1; @VisibleForTesting static final String CONTEXTUAL_CARD_COUNT = "contextual_card_count"; static final int CARD_CONTENT_LOADER_ID = 1; Loading Loading @@ -131,7 +131,7 @@ public class ContextualCardLoader extends AsyncLoaderCompat<List<ContextualCard> final List<ContextualCard> visibleCards = new ArrayList<>(); final List<ContextualCard> hiddenCards = new ArrayList<>(); final int maxCardCount = getCardCount(); final int maxCardCount = getCardCount(mContext); eligibleCards.forEach(card -> { if (card.getCategory() != STICKY_VALUE) { return; Loading Loading @@ -177,11 +177,10 @@ public class ContextualCardLoader extends AsyncLoaderCompat<List<ContextualCard> return visibleCards; } @VisibleForTesting int getCardCount() { static int getCardCount(Context context) { // Return the card count if Settings.Global has KEY_CONTEXTUAL_CARD_COUNT key, // otherwise return the default one. return Settings.Global.getInt(mContext.getContentResolver(), return Settings.Global.getInt(context.getContentResolver(), CONTEXTUAL_CARD_COUNT, DEFAULT_CARD_COUNT); } Loading src/com/android/settings/homepage/contextualcards/ContextualCardManager.java +4 −0 Original line number Diff line number Diff line Loading @@ -122,6 +122,10 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo Log.w(TAG, "Legacy suggestion contextual card enabled, skipping contextual cards."); return; } if (ContextualCardLoader.getCardCount(mContext) <= 0) { Log.w(TAG, "Card count is zero, skipping contextual cards."); return; } mStartTime = System.currentTimeMillis(); final CardContentLoaderCallbacks cardContentLoaderCallbacks = new CardContentLoaderCallbacks(mContext); Loading src/com/android/settings/homepage/contextualcards/ContextualCardsAdapter.java +19 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,10 @@ package com.android.settings.homepage.contextualcards; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; import android.content.Context; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; Loading Loading @@ -131,7 +134,22 @@ public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.Vi diffResult.dispatchUpdatesTo(this); } if (mRecyclerView != null && previouslyEmpty && !nowEmpty) { if (mRecyclerView == null) { return; } // When no card gets displayed either because a card's condition no longer meets // or when it's dismissed, the height should be rearranged. if (mContextualCards.isEmpty()) { final ViewGroup.LayoutParams params = mRecyclerView.getLayoutParams(); if (params.height != WRAP_CONTENT) { Log.d(TAG, "mContextualCards is empty. Set the RV to wrap_content"); params.height = WRAP_CONTENT; mRecyclerView.setLayoutParams(params); } } if (previouslyEmpty && !nowEmpty) { // Adding items to empty list, should animate. mRecyclerView.scheduleLayoutAnimation(); } Loading src/com/android/settings/homepage/contextualcards/ContextualCardsFragment.java +35 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.settings.homepage.contextualcards; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; import static com.android.settings.homepage.contextualcards.ContextualCardsAdapter.SPAN_COUNT; import android.app.settings.SettingsEnums; Loading @@ -34,6 +36,7 @@ import androidx.annotation.VisibleForTesting; import androidx.loader.app.LoaderManager; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; import com.android.settings.R; import com.android.settings.core.InstrumentedFragment; Loading Loading @@ -105,8 +108,20 @@ public class ContextualCardsFragment extends InstrumentedFragment implements final View rootView = inflater.inflate(R.layout.settings_homepage, container, false); mCardsContainer = rootView.findViewById(R.id.card_container); mLayoutManager = new GridLayoutManager(getActivity(), SPAN_COUNT, GridLayoutManager.VERTICAL, false /* reverseLayout */); GridLayoutManager.VERTICAL, false /* reverseLayout */) { @Override public void onLayoutCompleted(RecyclerView.State state) { super.onLayoutCompleted(state); // Once cards finish laying out, make the RV back to wrap content for flexibility. final ViewGroup.LayoutParams params = mCardsContainer.getLayoutParams(); if (params.height != WRAP_CONTENT) { params.height = WRAP_CONTENT; mCardsContainer.setLayoutParams(params); } } }; mCardsContainer.setLayoutManager(mLayoutManager); preAllocateHeight(context); mContextualCardsAdapter = new ContextualCardsAdapter(context, this /* lifecycleOwner */, mContextualCardManager); mCardsContainer.setItemAnimator(null); Loading Loading @@ -159,6 +174,25 @@ public class ContextualCardsFragment extends InstrumentedFragment implements FeatureFactory.getFactory(context).getSlicesFeatureProvider().newUiSession(); } private void preAllocateHeight(Context context) { final int cardCount = ContextualCardLoader.getCardCount(context); if (cardCount != 1) { // only pre-allocate space when card count is one Log.d(TAG, "Skip height pre-allocating. card count = " + cardCount); return; } final int preAllocatedHeight = getResources().getDimensionPixelSize( R.dimen.contextual_card_preallocated_height); if (preAllocatedHeight == 0) { return; } final ViewGroup.LayoutParams params = mCardsContainer.getLayoutParams(); params.height = preAllocatedHeight; mCardsContainer.setLayoutParams(params); } /** * Receiver for updating UI session when home key or recent app key is pressed. */ Loading Loading
res/values/dimens.xml +1 −0 Original line number Diff line number Diff line Loading @@ -348,6 +348,7 @@ <dimen name="contextual_half_card_padding_top">12dp</dimen> <dimen name="contextual_half_card_padding_bottom">16dp</dimen> <dimen name="contextual_half_card_title_margin_top">12dp</dimen> <dimen name="contextual_card_preallocated_height">0dp</dimen> <!-- Homepage dismissal cards size and padding --> <dimen name="contextual_card_dismissal_margin_top">12dp</dimen> Loading
src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java +4 −5 Original line number Diff line number Diff line Loading @@ -50,7 +50,7 @@ import java.util.stream.Collectors; public class ContextualCardLoader extends AsyncLoaderCompat<List<ContextualCard>> { @VisibleForTesting static final int DEFAULT_CARD_COUNT = 3; static final int DEFAULT_CARD_COUNT = 1; @VisibleForTesting static final String CONTEXTUAL_CARD_COUNT = "contextual_card_count"; static final int CARD_CONTENT_LOADER_ID = 1; Loading Loading @@ -131,7 +131,7 @@ public class ContextualCardLoader extends AsyncLoaderCompat<List<ContextualCard> final List<ContextualCard> visibleCards = new ArrayList<>(); final List<ContextualCard> hiddenCards = new ArrayList<>(); final int maxCardCount = getCardCount(); final int maxCardCount = getCardCount(mContext); eligibleCards.forEach(card -> { if (card.getCategory() != STICKY_VALUE) { return; Loading Loading @@ -177,11 +177,10 @@ public class ContextualCardLoader extends AsyncLoaderCompat<List<ContextualCard> return visibleCards; } @VisibleForTesting int getCardCount() { static int getCardCount(Context context) { // Return the card count if Settings.Global has KEY_CONTEXTUAL_CARD_COUNT key, // otherwise return the default one. return Settings.Global.getInt(mContext.getContentResolver(), return Settings.Global.getInt(context.getContentResolver(), CONTEXTUAL_CARD_COUNT, DEFAULT_CARD_COUNT); } Loading
src/com/android/settings/homepage/contextualcards/ContextualCardManager.java +4 −0 Original line number Diff line number Diff line Loading @@ -122,6 +122,10 @@ public class ContextualCardManager implements ContextualCardLoader.CardContentLo Log.w(TAG, "Legacy suggestion contextual card enabled, skipping contextual cards."); return; } if (ContextualCardLoader.getCardCount(mContext) <= 0) { Log.w(TAG, "Card count is zero, skipping contextual cards."); return; } mStartTime = System.currentTimeMillis(); final CardContentLoaderCallbacks cardContentLoaderCallbacks = new CardContentLoaderCallbacks(mContext); Loading
src/com/android/settings/homepage/contextualcards/ContextualCardsAdapter.java +19 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,10 @@ package com.android.settings.homepage.contextualcards; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; import android.content.Context; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; Loading Loading @@ -131,7 +134,22 @@ public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.Vi diffResult.dispatchUpdatesTo(this); } if (mRecyclerView != null && previouslyEmpty && !nowEmpty) { if (mRecyclerView == null) { return; } // When no card gets displayed either because a card's condition no longer meets // or when it's dismissed, the height should be rearranged. if (mContextualCards.isEmpty()) { final ViewGroup.LayoutParams params = mRecyclerView.getLayoutParams(); if (params.height != WRAP_CONTENT) { Log.d(TAG, "mContextualCards is empty. Set the RV to wrap_content"); params.height = WRAP_CONTENT; mRecyclerView.setLayoutParams(params); } } if (previouslyEmpty && !nowEmpty) { // Adding items to empty list, should animate. mRecyclerView.scheduleLayoutAnimation(); } Loading
src/com/android/settings/homepage/contextualcards/ContextualCardsFragment.java +35 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.settings.homepage.contextualcards; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; import static com.android.settings.homepage.contextualcards.ContextualCardsAdapter.SPAN_COUNT; import android.app.settings.SettingsEnums; Loading @@ -34,6 +36,7 @@ import androidx.annotation.VisibleForTesting; import androidx.loader.app.LoaderManager; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; import com.android.settings.R; import com.android.settings.core.InstrumentedFragment; Loading Loading @@ -105,8 +108,20 @@ public class ContextualCardsFragment extends InstrumentedFragment implements final View rootView = inflater.inflate(R.layout.settings_homepage, container, false); mCardsContainer = rootView.findViewById(R.id.card_container); mLayoutManager = new GridLayoutManager(getActivity(), SPAN_COUNT, GridLayoutManager.VERTICAL, false /* reverseLayout */); GridLayoutManager.VERTICAL, false /* reverseLayout */) { @Override public void onLayoutCompleted(RecyclerView.State state) { super.onLayoutCompleted(state); // Once cards finish laying out, make the RV back to wrap content for flexibility. final ViewGroup.LayoutParams params = mCardsContainer.getLayoutParams(); if (params.height != WRAP_CONTENT) { params.height = WRAP_CONTENT; mCardsContainer.setLayoutParams(params); } } }; mCardsContainer.setLayoutManager(mLayoutManager); preAllocateHeight(context); mContextualCardsAdapter = new ContextualCardsAdapter(context, this /* lifecycleOwner */, mContextualCardManager); mCardsContainer.setItemAnimator(null); Loading Loading @@ -159,6 +174,25 @@ public class ContextualCardsFragment extends InstrumentedFragment implements FeatureFactory.getFactory(context).getSlicesFeatureProvider().newUiSession(); } private void preAllocateHeight(Context context) { final int cardCount = ContextualCardLoader.getCardCount(context); if (cardCount != 1) { // only pre-allocate space when card count is one Log.d(TAG, "Skip height pre-allocating. card count = " + cardCount); return; } final int preAllocatedHeight = getResources().getDimensionPixelSize( R.dimen.contextual_card_preallocated_height); if (preAllocatedHeight == 0) { return; } final ViewGroup.LayoutParams params = mCardsContainer.getLayoutParams(); params.height = preAllocatedHeight; mCardsContainer.setLayoutParams(params); } /** * Receiver for updating UI session when home key or recent app key is pressed. */ Loading