Animate contextual cards in after loading.
After initial loading, all cards slide down per material guideline. Test: visual Change-Id: I115e086a43fc9a2d4b4da3acad20be689fdee09d
This commit is contained in:
42
res/anim/item_animation_fall_down.xml
Normal file
42
res/anim/item_animation_fall_down.xml
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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>
|
22
res/anim/layout_animation_fall_down.xml
Normal file
22
res/anim/layout_animation_fall_down.xml
Normal file
@@ -0,0 +1,22 @@
|
||||
<?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"/>
|
@@ -24,7 +24,8 @@
|
||||
<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"
|
||||
|
@@ -43,6 +43,8 @@ public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
||||
private final List<ContextualCard> mContextualCards;
|
||||
private final LifecycleOwner mLifecycleOwner;
|
||||
|
||||
private RecyclerView mRecyclerView;
|
||||
|
||||
public ContextualCardsAdapter(Context context, LifecycleOwner lifecycleOwner,
|
||||
ContextualCardManager manager) {
|
||||
mContext = context;
|
||||
@@ -89,6 +91,7 @@ public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
||||
@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;
|
||||
@@ -109,6 +112,8 @@ public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
||||
@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();
|
||||
@@ -119,5 +124,10 @@ public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
||||
mContextualCards.addAll(contextualCards);
|
||||
diffResult.dispatchUpdatesTo(this);
|
||||
}
|
||||
|
||||
if (mRecyclerView != null && previouslyEmpty && !nowEmpty) {
|
||||
// Adding items to empty list, should animate.
|
||||
mRecyclerView.scheduleLayoutAnimation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user