OSDN Git Service

Animate contextual cards in after loading.
authorFan Zhang <zhfan@google.com>
Fri, 26 Oct 2018 18:34:00 +0000 (11:34 -0700)
committerFan Zhang <zhfan@google.com>
Fri, 26 Oct 2018 19:49:35 +0000 (19:49 +0000)
After initial loading, all cards slide down per material guideline.

Test: visual
Change-Id: I115e086a43fc9a2d4b4da3acad20be689fdee09d

res/anim/item_animation_fall_down.xml [new file with mode: 0644]
res/anim/layout_animation_fall_down.xml [new file with mode: 0644]
res/layout/settings_homepage.xml
src/com/android/settings/homepage/contextualcards/ContextualCardsAdapter.java

diff --git a/res/anim/item_animation_fall_down.xml b/res/anim/item_animation_fall_down.xml
new file mode 100644 (file)
index 0000000..df2451c
--- /dev/null
@@ -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>
\ No newline at end of file
diff --git a/res/anim/layout_animation_fall_down.xml b/res/anim/layout_animation_fall_down.xml
new file mode 100644 (file)
index 0000000..f39735c
--- /dev/null
@@ -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"/>
\ No newline at end of file
index 0ba3609..bd54717 100644 (file)
@@ -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"
index 7938227..865d242 100644 (file)
@@ -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();
+        }
     }
 }