From 1071192156a37f1820ff4cab2a43441e70948cb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Sch=C3=A4ttgen?= Date: Mon, 17 Dec 2018 23:28:56 +0100 Subject: [PATCH] Add animation to recyclerview --- .../me/impy/aegis/ui/views/EntryListView.java | 28 ++++++++++++++++--- .../res/anim/item_animation_fall_down.xml | 26 +++++++++++++++++ .../res/anim/layout_animation_fall_down.xml | 7 +++++ .../res/layout/fragment_entry_list_view.xml | 1 + 4 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/anim/item_animation_fall_down.xml create mode 100644 app/src/main/res/anim/layout_animation_fall_down.xml diff --git a/app/src/main/java/me/impy/aegis/ui/views/EntryListView.java b/app/src/main/java/me/impy/aegis/ui/views/EntryListView.java index 41e573de..2b2a9027 100644 --- a/app/src/main/java/me/impy/aegis/ui/views/EntryListView.java +++ b/app/src/main/java/me/impy/aegis/ui/views/EntryListView.java @@ -1,5 +1,6 @@ package me.impy.aegis.ui.views; +import android.content.Context; import android.graphics.PorterDuff; import android.os.Bundle; import androidx.fragment.app.Fragment; @@ -9,6 +10,8 @@ import androidx.recyclerview.widget.ItemTouchHelper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.animation.AnimationUtils; +import android.view.animation.LayoutAnimationController; import java.util.List; @@ -23,6 +26,7 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener { private Listener _listener; private SimpleItemTouchHelperCallback _touchCallback; + private RecyclerView _rvKeyProfiles; private PeriodProgressBar _progressBar; private boolean _showProgress; @@ -44,14 +48,18 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener { _progressBar.getProgressDrawable().setColorFilter(primaryColorId, PorterDuff.Mode.SRC_IN); // set up the recycler view - RecyclerView rvKeyProfiles = view.findViewById(R.id.rvKeyProfiles); + _rvKeyProfiles = view.findViewById(R.id.rvKeyProfiles); LinearLayoutManager mLayoutManager = new LinearLayoutManager(view.getContext()); - rvKeyProfiles.setLayoutManager(mLayoutManager); + _rvKeyProfiles.setLayoutManager(mLayoutManager); _touchCallback = new SimpleItemTouchHelperCallback(_adapter); ItemTouchHelper touchHelper = new ItemTouchHelper(_touchCallback); - touchHelper.attachToRecyclerView(rvKeyProfiles); - rvKeyProfiles.setAdapter(_adapter); + touchHelper.attachToRecyclerView(_rvKeyProfiles); + _rvKeyProfiles.setAdapter(_adapter); + int resId = R.anim.layout_animation_fall_down; + LayoutAnimationController animation = AnimationUtils.loadLayoutAnimation(getContext(), resId); + _rvKeyProfiles.setLayoutAnimation(animation); + _refresher = new UiRefresher(new UiRefresher.Listener() { @Override public void onRefresh() { @@ -71,6 +79,8 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener { _adapter.setGroupFilter(group); _touchCallback.setIsLongPressDragEnabled(group == null); checkPeriodUniformity(); + + runLayoutAnimation(_rvKeyProfiles); } public void refresh(boolean hard) { @@ -165,6 +175,16 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener { checkPeriodUniformity(); } + private void runLayoutAnimation(final RecyclerView recyclerView) { + final Context context = recyclerView.getContext(); + final LayoutAnimationController controller = + AnimationUtils.loadLayoutAnimation(context, R.anim.layout_animation_fall_down); + + recyclerView.setLayoutAnimation(controller); + recyclerView.getAdapter().notifyDataSetChanged(); + recyclerView.scheduleLayoutAnimation(); + } + public interface Listener { void onEntryClick(DatabaseEntry entry); void onEntryMove(DatabaseEntry entry1, DatabaseEntry entry2); diff --git a/app/src/main/res/anim/item_animation_fall_down.xml b/app/src/main/res/anim/item_animation_fall_down.xml new file mode 100644 index 00000000..3b3afcd6 --- /dev/null +++ b/app/src/main/res/anim/item_animation_fall_down.xml @@ -0,0 +1,26 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/anim/layout_animation_fall_down.xml b/app/src/main/res/anim/layout_animation_fall_down.xml new file mode 100644 index 00000000..3085503a --- /dev/null +++ b/app/src/main/res/anim/layout_animation_fall_down.xml @@ -0,0 +1,7 @@ + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_entry_list_view.xml b/app/src/main/res/layout/fragment_entry_list_view.xml index 003a0e3e..fbd6dede 100644 --- a/app/src/main/res/layout/fragment_entry_list_view.xml +++ b/app/src/main/res/layout/fragment_entry_list_view.xml @@ -19,5 +19,6 @@ android:layout_height="0dp" android:scrollbars="vertical" android:id="@+id/rvKeyProfiles" + android:layoutAnimation="@anim/layout_animation_fall_down" android:layout_weight="1"/>