After initial loading, all cards slide down per material guideline.
Test: visual
Change-Id: I115e086a43fc9a2d4b4da3acad20be689fdee09d
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android"
+ android:duration="500">
+
+ <!-- Move up the view by 20% of it’s own height, and let it fall down to its final position -->
+ <translate
+ android:fromYDelta="-20%"
+ android:toYDelta="0"
+ android:interpolator="@android:anim/decelerate_interpolator"/>
+
+ <!-- Fade in: alpha from 0 to 100% -->
+ <alpha
+ android:fromAlpha="0"
+ android:toAlpha="1"
+ android:interpolator="@android:anim/decelerate_interpolator"/>
+
+ <!-- Shrink from 105% to 100% -->
+ <scale
+ android:fromXScale="105%"
+ android:fromYScale="105%"
+ android:toXScale="100%"
+ android:toYScale="100%"
+ android:pivotX="50%"
+ android:pivotY="50%"
+ android:interpolator="@android:anim/decelerate_interpolator"/>
+</set>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<layoutAnimation
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:animation="@anim/item_animation_fall_down"
+ android:delay="15%"
+ android:animationOrder="normal"/>
\ No newline at end of file
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/card_container"
android:layout_width="match_parent"
- android:layout_height="match_parent"/>
+ android:layout_height="match_parent"
+ android:layoutAnimation="@anim/layout_animation_fall_down"/>
<RelativeLayout
android:id="@+id/suggestion_footer"
private final List<ContextualCard> mContextualCards;
private final LifecycleOwner mLifecycleOwner;
+ private RecyclerView mRecyclerView;
+
public ContextualCardsAdapter(Context context, LifecycleOwner lifecycleOwner,
ContextualCardManager manager) {
mContext = context;
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
+ mRecyclerView = recyclerView;
final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
if (layoutManager instanceof GridLayoutManager) {
final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
@Override
public void onContextualCardUpdated(Map<Integer, List<ContextualCard>> cards) {
final List<ContextualCard> contextualCards = cards.get(ContextualCard.CardType.DEFAULT);
+ final boolean previouslyEmpty = mContextualCards.isEmpty();
+ final boolean nowEmpty = contextualCards == null || contextualCards.isEmpty();
if (contextualCards == null) {
mContextualCards.clear();
notifyDataSetChanged();
mContextualCards.addAll(contextualCards);
diffResult.dispatchUpdatesTo(this);
}
+
+ if (mRecyclerView != null && previouslyEmpty && !nowEmpty) {
+ // Adding items to empty list, should animate.
+ mRecyclerView.scheduleLayoutAnimation();
+ }
}
}