Author: Huajian Jiang
25 | * Date: 2017/8/6
26 | * Email: developer.huajianjiang@gmail.com
27 | */
28 | public class PatchedRecyclerView extends RecyclerView {
29 | private static final String TAG = PatchedRecyclerView.class.getSimpleName();
30 | protected ContextMenu.ContextMenuInfo mContextMenuInfo;
31 |
32 | private Adapter mAdapter;
33 | private EmptyDataObserver mObserver;
34 | private View mEmptyView;
35 |
36 | public PatchedRecyclerView(Context context) {
37 | this(context,null);
38 | }
39 |
40 | public PatchedRecyclerView(Context context, @Nullable AttributeSet attrs)
41 | {
42 | this(context, attrs, 0);
43 | }
44 |
45 | public PatchedRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
46 | super(context, attrs, defStyle);
47 |
48 | TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.PatchedRecyclerView);
49 | boolean nestedScrollingEnabled = ta
50 | .getBoolean(R.styleable.PatchedRecyclerView_nestedScrollingEnabled, true);
51 | boolean hasFixedSize = ta.getBoolean(R.styleable.PatchedRecyclerView_hasFixedSize, false);
52 | int orientation =
53 | ta.getInt(R.styleable.PatchedRecyclerView_orientation, OrientationHelper.VERTICAL);
54 | ta.recycle();
55 |
56 | LayoutManager layoutManager = getLayoutManager();
57 | if (layoutManager instanceof LinearLayoutManager) {
58 | LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
59 | int currOrientation = linearLayoutManager.getOrientation();
60 | if (currOrientation != orientation) {
61 | linearLayoutManager.setOrientation(orientation);
62 | }
63 | }
64 |
65 | setHasFixedSize(hasFixedSize);
66 | setNestedScrollingEnabled(nestedScrollingEnabled);
67 | setFocusable(nestedScrollingEnabled);
68 | }
69 |
70 | @Override
71 | public void setAdapter(Adapter adapter) {
72 | if (mAdapter != null && mObserver != null) {
73 | mAdapter.unregisterAdapterDataObserver(mObserver);
74 | }
75 |
76 | mAdapter = adapter;
77 |
78 | if (mAdapter != null && mEmptyView != null) {
79 | mAdapter.registerAdapterDataObserver(getObserver());
80 | }
81 |
82 | super.setAdapter(adapter);
83 | }
84 |
85 | public void setEmptyView(View emptyView) {
86 | if (mEmptyView != null) {
87 | mEmptyView.setVisibility(GONE);
88 | if (mAdapter != null && mObserver != null) {
89 | mAdapter.unregisterAdapterDataObserver(mObserver);
90 | }
91 | }
92 |
93 | mEmptyView = emptyView;
94 |
95 | if (mAdapter != null && mEmptyView != null) {
96 | mAdapter.registerAdapterDataObserver(getObserver());
97 | }
98 |
99 | updateEmptyStatus(shouldShowEmptyView());
100 | }
101 |
102 | private boolean shouldShowEmptyView() {
103 | return mAdapter == null || mAdapter.getItemCount() == 0;
104 | }
105 |
106 | private void updateEmptyStatus(boolean empty) {
107 | if (empty) {
108 | if (mEmptyView == null) {
109 | setVisibility(View.VISIBLE);
110 | } else {
111 | setVisibility(View.GONE);
112 | mEmptyView.setVisibility(VISIBLE);
113 | }
114 | } else {
115 | if (mEmptyView != null) mEmptyView.setVisibility(GONE);
116 | setVisibility(View.VISIBLE);
117 | }
118 | }
119 |
120 | private EmptyDataObserver getObserver() {
121 | if (mObserver == null) {
122 | mObserver = new EmptyDataObserver();
123 | }
124 | return mObserver;
125 | }
126 |
127 |
128 | private class EmptyDataObserver extends RecyclerView.AdapterDataObserver {
129 | @Override
130 | public void onChanged() {
131 | updateEmptyStatus(shouldShowEmptyView());
132 | }
133 |
134 | @Override
135 | public void onItemRangeChanged(int positionStart, int itemCount) {onChanged();}
136 |
137 | @Override
138 | public void onItemRangeChanged(int positionStart, int itemCount, Object payload) {onChanged();}
139 |
140 | @Override
141 | public void onItemRangeInserted(int positionStart, int itemCount) {onChanged();}
142 |
143 | @Override
144 | public void onItemRangeRemoved(int positionStart, int itemCount) {onChanged();}
145 |
146 | @Override
147 | public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) {onChanged();}
148 | }
149 |
150 | protected ContextMenu.ContextMenuInfo createContextMenuInfo(View targetView, int position,
151 | long id)
152 | {
153 | return new RecyclerViewContextMenuInfo(targetView, position, id);
154 | }
155 |
156 | @Override
157 | public boolean showContextMenu() {
158 | return showContextMenuInternal(Float.NaN, Float.NaN, false);
159 | }
160 |
161 | @Override
162 | @TargetApi(Build.VERSION_CODES.N)
163 | @RequiresApi(Build.VERSION_CODES.N)
164 | public boolean showContextMenu(float x, float y) {
165 | return showContextMenuInternal(x, y, true);
166 | }
167 |
168 | private boolean showContextMenuInternal(float x, float y, boolean useOffsets) {
169 | View child = findChildViewUnder(x, y);
170 | if (child != null) {
171 | mContextMenuInfo = createContextMenuInfo(child, getChildAdapterPosition(child),
172 | getChildItemId(child));
173 | if (useOffsets && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
174 | return super.showContextMenuForChild(child, x, y);
175 | } else {
176 | return super.showContextMenuForChild(child);
177 | }
178 | }
179 |
180 | if (useOffsets && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
181 | return super.showContextMenu(x, y);
182 | } else {
183 | return super.showContextMenu();
184 | }
185 | }
186 |
187 | @Override
188 | public boolean showContextMenuForChild(View originalView) {
189 | return showContextMenuForChildInternal(originalView, Float.NaN, Float.NaN, false);
190 | }
191 |
192 | @Override
193 | @TargetApi(Build.VERSION_CODES.N)
194 | @RequiresApi(Build.VERSION_CODES.N)
195 | public boolean showContextMenuForChild(View originalView, float x, float y) {
196 | return showContextMenuForChildInternal(originalView, x, y, true);
197 | }
198 |
199 | private boolean showContextMenuForChildInternal(View originalView, float x, float y,
200 | boolean useOffsets)
201 | {
202 | View child = findContainingItemView(originalView);
203 | final int childAdapterPos = getChildAdapterPosition(child);
204 | if (childAdapterPos == RecyclerView.NO_POSITION) return false;
205 | ViewParent parent = getParent();
206 | if (parent == null) return false;
207 | mContextMenuInfo = createContextMenuInfo(child, childAdapterPos, getChildItemId(child));
208 | if (useOffsets && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
209 | return parent.showContextMenuForChild(originalView, x, y);
210 | } else {
211 | return parent.showContextMenuForChild(originalView);
212 | }
213 | }
214 |
215 | @Override
216 | protected ContextMenu.ContextMenuInfo getContextMenuInfo() {
217 | return mContextMenuInfo;
218 | }
219 |
220 |
221 | public static class RecyclerViewContextMenuInfo implements ContextMenu.ContextMenuInfo {
222 | /**
223 | * 上下文菜单锚点 View,也就是 RecyclerView 的直接 childView
224 | */
225 | public View targetView;
226 | /**
227 | * 构建上下文菜单的 RecyclerView 的直接 childView 的位置
228 | */
229 | public int position;
230 | /**
231 | * RecyclerView 的直接 childView 的 row id
232 | */
233 | public long id;
234 |
235 | RecyclerViewContextMenuInfo(View targetView, int position, long id) {
236 | this.targetView = targetView;
237 | this.position = position;
238 | this.id = id;
239 | }
240 |
241 | @Override
242 | public String toString() {
243 | String vId = "0x" + Integer.toHexString(targetView.getId());
244 | return "RecyclerViewContextMenuInfo{" + "targetView=" + String.format("%1$s", vId) +
245 | ", position=" + position + ", id=" + id + '}';
246 | }
247 | }
248 |
249 | }
250 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/github/huajianjiang/expandablerecyclerview/sample/MultipleRvFragment.java:
--------------------------------------------------------------------------------
1 | package com.github.huajianjiang.expandablerecyclerview.sample;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v4.app.DialogFragment;
8 | import android.support.v4.app.Fragment;
9 | import android.support.v7.widget.DefaultItemAnimator;
10 | import android.support.v7.widget.RecyclerView;
11 | import android.util.Log;
12 | import android.view.ContextMenu;
13 | import android.view.LayoutInflater;
14 | import android.view.Menu;
15 | import android.view.MenuInflater;
16 | import android.view.MenuItem;
17 | import android.view.View;
18 | import android.view.ViewGroup;
19 | import android.widget.ImageView;
20 |
21 | import com.github.huajianjiang.expandablerecyclerview.sample.adapter.MyAdapter;
22 | import com.github.huajianjiang.expandablerecyclerview.sample.anim.CircularRevealItemAnimator;
23 | import com.github.huajianjiang.expandablerecyclerview.sample.model.MyParent;
24 | import com.github.huajianjiang.expandablerecyclerview.sample.util.AppUtil;
25 | import com.github.huajianjiang.expandablerecyclerview.util.Logger;
26 | import com.github.huajianjiang.expandablerecyclerview.widget.ExpandableAdapter;
27 | import com.github.huajianjiang.expandablerecyclerview.widget.ExpandableRecyclerView;
28 | import com.github.huajianjiang.expandablerecyclerview.widget.ParentViewHolder;
29 |
30 | import java.lang.reflect.InvocationTargetException;
31 | import java.lang.reflect.Method;
32 | import java.util.ArrayList;
33 | import java.util.List;
34 |
35 | import static com.github.huajianjiang.expandablerecyclerview.sample.SingleRvFragment.KEY_DATA;
36 | import static com.github.huajianjiang.expandablerecyclerview.sample.SingleRvFragment.REQUEST_RESULT;
37 |
38 | /**
39 | * @author HuaJian Jiang.
40 | * Date 2017/1/23.
41 | */
42 | public class MultipleRvFragment extends Fragment {
43 | private static final String TAG = MultipleRvFragment.class.getSimpleName();
44 | private MyAdapter mAdapter;
45 | private RecyclerView.ItemAnimator mItemAnimator;
46 | private PresenterImpl mIPresenter;
47 | private ArrayList mData;
48 |
49 | @Override
50 | public void onCreate(@Nullable Bundle savedInstanceState) {
51 | super.onCreate(savedInstanceState);
52 | setHasOptionsMenu(true);
53 | setRetainInstance(true);
54 | }
55 |
56 | @Nullable
57 | @Override
58 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
59 | @Nullable Bundle savedInstanceState)
60 | {
61 | return inflater.inflate(R.layout.fragment_multiple_rv, container, false);
62 | }
63 |
64 |
65 | @Override
66 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
67 | super.onActivityCreated(savedInstanceState);
68 | // 保存 ExpandableRecyclerView 状态
69 | if (savedInstanceState != null) {
70 | Logger.e(TAG, "<<<<<<<<<<<<<<<<<< Restore Data >>>>>>>>>>>>>>>>>");
71 | mData = savedInstanceState.getParcelableArrayList(KEY_DATA);
72 | } else {
73 | mData = AppUtil.getListData();
74 | }
75 | init(getView());
76 | mAdapter.onRestoreInstanceState(savedInstanceState);
77 | }
78 |
79 | private void init(View rootView) {
80 | mAdapter = new MyAdapter(getActivity(), mData);
81 | mAdapter.setExpandCollapseMode(ExpandableAdapter.ExpandCollapseMode.MODE_DEFAULT);
82 | mAdapter.addParentExpandableStateChangeListener(new ParentExpandableStateChangeListener());
83 | mAdapter.addParentExpandCollapseListener(new ParentExpandCollapseListener());
84 |
85 | RecyclerView rv_top= (RecyclerView) rootView.findViewById(R.id.rv_top);
86 | rv_top.setAdapter(mAdapter);
87 | rv_top.addItemDecoration(mAdapter.getItemDecoration());
88 | mItemAnimator =
89 | AppUtil.checkLollipop() ? new CircularRevealItemAnimator() : new DefaultItemAnimator();
90 | rv_top.setItemAnimator(mItemAnimator);
91 |
92 | RecyclerView rv_bottom = (RecyclerView) rootView.findViewById(R.id.rv_bottom);
93 | rv_bottom.setAdapter(mAdapter);
94 | rv_bottom.addItemDecoration(mAdapter.getItemDecoration());
95 |
96 | mIPresenter = new PresenterImpl(mAdapter, mData);
97 |
98 | registerForContextMenu(rv_top);
99 | registerForContextMenu(rv_bottom);
100 | }
101 |
102 | private class ParentExpandableStateChangeListener
103 | implements ExpandableAdapter.OnParentExpandableStateChangeListener
104 | {
105 | @Override
106 | public void onParentExpandableStateChanged(RecyclerView rv, ParentViewHolder pvh,
107 | int position, boolean expandable)
108 | {
109 | Logger.e(TAG, "onParentExpandableStateChanged=" + position + "," + rv.getTag());
110 | if (pvh == null) return;
111 | ImageView arrow = pvh.getView(R.id.arrow);
112 | if (expandable && arrow.getVisibility() != View.VISIBLE) {
113 | arrow.setVisibility(View.VISIBLE);
114 | arrow.setRotation(pvh.isExpanded() ? 180 : 0);
115 | } else if (!expandable && arrow.getVisibility() == View.VISIBLE) {
116 | arrow.setVisibility(View.GONE);
117 | }
118 | }
119 | }
120 |
121 | private class ParentExpandCollapseListener
122 | implements ExpandableAdapter.OnParentExpandCollapseListener
123 | {
124 | @Override
125 | public void onParentExpanded(RecyclerView rv, ParentViewHolder pvh, int position,
126 | boolean pendingCause, boolean byUser)
127 | {
128 | Logger.e(TAG, "onParentExpanded=" + position + "," + rv.getTag() + ",byUser=" + byUser);
129 | if (pvh == null) return;
130 | ImageView arrow = pvh.getView(R.id.arrow);
131 | if (arrow.getVisibility() != View.VISIBLE) return;
132 | float currRotate = arrow.getRotation();
133 | //重置为从0开始旋转
134 | if (currRotate == 360) {
135 | arrow.setRotation(0);
136 | }
137 | if (pendingCause) {
138 | arrow.setRotation(180);
139 | } else {
140 | arrow.animate()
141 | .rotation(180)
142 | .setDuration(mItemAnimator.getAddDuration() + 180)
143 | .start();
144 | }
145 | }
146 |
147 | @Override
148 | public void onParentCollapsed(RecyclerView rv, ParentViewHolder pvh, int position,
149 | boolean pendingCause, boolean byUser)
150 | {
151 | Logger.e(TAG,
152 | "onParentCollapsed=" + position + ",tag=" + rv.getTag() + ",byUser=" + byUser);
153 |
154 | if (pvh == null) return;
155 | final ImageView arrow = pvh.getView(R.id.arrow);
156 | if (arrow.getVisibility() != View.VISIBLE) return;
157 | final float currRotate = arrow.getRotation();
158 | float rotate = 360;
159 | //未展开完全并且当前旋转角度小于180,逆转回去
160 | if (currRotate < 180) {
161 | rotate = 0;
162 | }
163 | if (pendingCause) {
164 | arrow.setRotation(rotate);
165 | } else {
166 | arrow.animate().rotation(rotate)
167 | .setDuration(mItemAnimator.getRemoveDuration() + 180).start();
168 | }
169 | }
170 | }
171 |
172 | @Override
173 | public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo)
174 | {
175 | getActivity().getMenuInflater().inflate(R.menu.menu_main, menu);
176 | }
177 |
178 | @Override
179 | public boolean onContextItemSelected(MenuItem item) {
180 | ExpandableRecyclerView.ExpandableRecyclerViewContextMenuInfo menuInfo =
181 | (ExpandableRecyclerView.ExpandableRecyclerViewContextMenuInfo) item.getMenuInfo();
182 | Logger.e(TAG, menuInfo.toString());
183 | return true;
184 | }
185 |
186 | @Override
187 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
188 | inflater.inflate(R.menu.menu_main, menu);
189 | }
190 |
191 | @Override
192 | public boolean onOptionsItemSelected(MenuItem item) {
193 | int id = item.getItemId();
194 | switch (id) {
195 | case R.id.action_test:
196 | DialogFragment dialog = (DialogFragment) getChildFragmentManager()
197 | .findFragmentByTag("dialog");
198 | if (dialog == null) dialog = new MyDialog();
199 | dialog.setTargetFragment(this, REQUEST_RESULT);
200 | dialog.show(getChildFragmentManager(), "dialog");
201 | break;
202 | case R.id.action_refresh:
203 | mAdapter.notifyAllChanged();
204 | break;
205 | case R.id.action_toggle_expandable_1:
206 | mAdapter.toggleExpandable(1);
207 | break;
208 | case R.id.action_expand_all:
209 | mAdapter.expandAllParents();
210 | break;
211 | case R.id.action_collapse_all:
212 | mAdapter.collapseAllParents();
213 | break;
214 | case R.id.action_expand_1:
215 | mAdapter.expandParent(1);
216 | break;
217 | case R.id.action_collapse_1:
218 | mAdapter.collapseParent(1);
219 | break;
220 | }
221 | return super.onOptionsItemSelected(item);
222 | }
223 |
224 | @Override
225 | public void onActivityResult(int requestCode, int resultCode, Intent data) {
226 | if (resultCode != Activity.RESULT_OK) return;
227 | if (requestCode == REQUEST_RESULT) {
228 | ArrayList requests = data.getStringArrayListExtra(MyDialog.REQUEST);
229 | Log.e(TAG, "requests=" + requests.toString());
230 | final int requestCount = requests.size();
231 | for (int i = 0; i < requestCount; i++) {
232 | String request = requests.get(i);
233 | String[] requestSplit = request.split(",");
234 | String method = requestSplit[0];
235 | final int argsCount = requestSplit.length - 1;
236 | try {
237 | Object[] args = new Object[argsCount];
238 | Class>[] argTypes = new Class>[argsCount];
239 | for (int k = 0; k < argsCount; k++) {
240 | argTypes[k] = int.class;
241 | try {
242 | args[k] = Integer.valueOf(requestSplit[k + 1]);
243 | } catch (NumberFormatException e) {
244 | AppUtil.showToast(getContext(), "Test failed,please check input format");
245 | return;
246 | }
247 | }
248 | Method m = IPresenter.class.getDeclaredMethod(method, argTypes);
249 | Log.e(TAG, "method=" + m.toString());
250 | m.setAccessible(true);
251 | m.invoke(mIPresenter,args);
252 | } catch (NoSuchMethodException e) {
253 | e.printStackTrace();
254 | AppUtil.showToast(getContext(), "Test failed,please check input format");
255 | } catch (IllegalAccessException e) {
256 | e.printStackTrace();
257 | AppUtil.showToast(getContext(), "Test failed,please check input format");
258 | } catch (InvocationTargetException e) {
259 | e.printStackTrace();
260 | AppUtil.showToast(getContext(), "Test failed,please check input format");
261 | }
262 | }
263 | }
264 | }
265 |
266 | @Override
267 | public void onSaveInstanceState(Bundle outState) {
268 | super.onSaveInstanceState(outState);
269 | Logger.e(TAG, "<<<<<<<<<<<<<<<<<< Save Data >>>>>>>>>>>>>>>>>");
270 | outState.putParcelableArrayList(KEY_DATA, mData);
271 | mAdapter.onSaveInstanceState(outState);
272 | }
273 | }
274 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/github/huajianjiang/expandablerecyclerview/sample/SingleRvFragment.java:
--------------------------------------------------------------------------------
1 | package com.github.huajianjiang.expandablerecyclerview.sample;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Build;
6 | import android.os.Bundle;
7 | import android.support.annotation.Nullable;
8 | import android.support.v4.app.DialogFragment;
9 | import android.support.v4.app.Fragment;
10 | import android.support.v4.view.OnApplyWindowInsetsListener;
11 | import android.support.v4.view.ViewCompat;
12 | import android.support.v4.view.WindowInsetsCompat;
13 | import android.support.v7.widget.DefaultItemAnimator;
14 | import android.support.v7.widget.RecyclerView;
15 | import android.util.Log;
16 | import android.view.ContextMenu;
17 | import android.view.LayoutInflater;
18 | import android.view.Menu;
19 | import android.view.MenuInflater;
20 | import android.view.MenuItem;
21 | import android.view.View;
22 | import android.view.ViewGroup;
23 | import android.widget.ImageView;
24 |
25 | import com.github.huajianjiang.expandablerecyclerview.sample.adapter.MyAdapter;
26 | import com.github.huajianjiang.expandablerecyclerview.sample.anim.CircularRevealItemAnimator;
27 | import com.github.huajianjiang.expandablerecyclerview.sample.model.MyParent;
28 | import com.github.huajianjiang.expandablerecyclerview.sample.util.AppUtil;
29 |
30 | import com.github.huajianjiang.expandablerecyclerview.util.Logger;
31 | import com.github.huajianjiang.expandablerecyclerview.widget.ExpandableAdapter;
32 | import com.github.huajianjiang.expandablerecyclerview.widget.ExpandableRecyclerView;
33 | import com.github.huajianjiang.expandablerecyclerview.widget.ParentViewHolder;
34 |
35 | import java.lang.reflect.InvocationTargetException;
36 | import java.lang.reflect.Method;
37 | import java.util.ArrayList;
38 | import java.util.List;
39 |
40 | /**
41 | * Created by jhj_Plus on 2016/9/2.
42 | */
43 | public class SingleRvFragment extends Fragment {
44 | public static final int REQUEST_RESULT = 1;
45 | private static final String TAG = "SingleRvFragment";
46 | public static final String KEY_DATA = "data";
47 | private ExpandableRecyclerView mRv;
48 | private MyAdapter mAdapter;
49 | private RecyclerView.ItemAnimator mItemAnimator;
50 | private PresenterImpl mIPresenter;
51 | private ArrayList mData;
52 |
53 | @Override
54 | public void onCreate(@Nullable Bundle savedInstanceState) {
55 | super.onCreate(savedInstanceState);
56 | setHasOptionsMenu(true);
57 | setRetainInstance(true);
58 | }
59 |
60 | @Nullable
61 | @Override
62 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
63 | @Nullable Bundle savedInstanceState)
64 | {
65 | return inflater.inflate(R.layout.fragment_single_rv, container, false);
66 | }
67 |
68 | @Override
69 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
70 | super.onActivityCreated(savedInstanceState);
71 | // 保存 ExpandableRecyclerView 状态
72 | if (savedInstanceState != null) {
73 | Logger.e(TAG, "<<<<<<<<<<<<<<<<<< Restore Data >>>>>>>>>>>>>>>>>");
74 | mData = savedInstanceState.getParcelableArrayList(KEY_DATA);
75 | } else {
76 | mData = AppUtil.getListData();
77 | }
78 | init(getView());
79 | mAdapter.onRestoreInstanceState(savedInstanceState);
80 | }
81 |
82 | private void init(View rootView) {
83 | mRv = (ExpandableRecyclerView) rootView.findViewById(R.id.rv);
84 | mAdapter = new MyAdapter(getActivity(), mData);
85 | mAdapter.setExpandCollapseMode(ExpandableAdapter.ExpandCollapseMode.MODE_DEFAULT);
86 |
87 | mItemAnimator = AppUtil.checkLollipop() ? new CircularRevealItemAnimator()
88 | : new DefaultItemAnimator();
89 |
90 | mAdapter.addParentExpandableStateChangeListener(new ParentExpandableStateChangeListener());
91 | mAdapter.addParentExpandCollapseListener(new ParentExpandCollapseListener());
92 | mRv.setAdapter(mAdapter);
93 | mRv.addItemDecoration(mAdapter.getItemDecoration());
94 | mRv.setItemAnimator(mItemAnimator);
95 |
96 | // mRv.setPadding(0, 0, 0, Res.getNavigationBarHeight(getContext()));
97 |
98 | mAdapter.parentLongClickTargets(R.id.parent)
99 | .listenParentLongClick(new ExpandableAdapter.OnParentLongClickListener() {
100 | @Override
101 | public boolean onParentLongClick(RecyclerView parent, View view) {
102 | final int childAdapterPos =
103 | parent.getChildAdapterPosition(parent.findContainingItemView(view));
104 | AppUtil.showToast(getContext(), "Parent LongClick =>" + "pos=" +
105 | mAdapter.getParentPosition(
106 | childAdapterPos) + ",adapterPos=" +
107 | childAdapterPos);
108 | return false;
109 | }
110 | })
111 | .parentClickTargets(R.id.android)
112 | .listenParentClick(new ExpandableAdapter.OnParentClickListener() {
113 | @Override
114 | public void onParentClick(RecyclerView parent, View view) {
115 | if (view.getId() == R.id.android) {
116 | AppUtil.showToast(getContext(), view.getTag().toString());
117 | }
118 | }
119 | });
120 |
121 | mAdapter.childLongClickTargets(R.id.child)
122 | .listenChildLongClick(new ExpandableAdapter.OnChildLongClickListener() {
123 | @Override
124 | public boolean onChildLongClick(RecyclerView parent, View view) {
125 | AppUtil.showToast(getContext(), "Child LongClick");
126 | return false;
127 | }
128 | })
129 | .childClickTargets(R.id.android)
130 | .listenChildClick(new ExpandableAdapter.OnChildClickListener() {
131 | @Override
132 | public void onChildClick(RecyclerView parent, View view) {
133 | if (view.getId() == R.id.android) {
134 | AppUtil.showToast(getContext(), view.getTag().toString());
135 | }
136 | }
137 | });
138 |
139 | mIPresenter = new PresenterImpl(mAdapter, mData);
140 |
141 | registerForContextMenu(mRv);
142 |
143 | }
144 |
145 | @Override
146 | public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo)
147 | {
148 | getActivity().getMenuInflater().inflate(R.menu.context, menu);
149 | }
150 |
151 | @Override
152 | public boolean onContextItemSelected(MenuItem item) {
153 | ExpandableRecyclerView.ExpandableRecyclerViewContextMenuInfo menuInfo =
154 | (ExpandableRecyclerView.ExpandableRecyclerViewContextMenuInfo) item.getMenuInfo();
155 | Logger.e(TAG, menuInfo.toString());
156 | return true;
157 | }
158 |
159 | @Override
160 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
161 | inflater.inflate(R.menu.menu_main, menu);
162 | }
163 |
164 | @Override
165 | public boolean onOptionsItemSelected(MenuItem item) {
166 | MyAdapter adapter = (MyAdapter) mRv.getAdapter();
167 | int id = item.getItemId();
168 | switch (id) {
169 | case R.id.action_test:
170 | DialogFragment dialog =
171 | (DialogFragment) getChildFragmentManager().findFragmentByTag("dialog");
172 | if (dialog == null) dialog = new MyDialog();
173 | dialog.setTargetFragment(this, REQUEST_RESULT);
174 | dialog.show(getChildFragmentManager(), "dialog");
175 | break;
176 | case R.id.action_refresh:
177 | adapter.notifyAllChanged();
178 | break;
179 | case R.id.action_toggle_expandable_1:
180 | adapter.toggleExpandable(1);
181 | break;
182 | case R.id.action_expand_all:
183 | adapter.expandAllParents();
184 | break;
185 | case R.id.action_collapse_all:
186 | adapter.collapseAllParents();
187 | break;
188 | case R.id.action_expand_1:
189 | adapter.expandParent(1);
190 | break;
191 | case R.id.action_collapse_1:
192 | adapter.collapseParent(1);
193 | break;
194 | }
195 | return super.onOptionsItemSelected(item);
196 | }
197 |
198 | @Override
199 | public void onActivityResult(int requestCode, int resultCode, Intent data) {
200 | if (resultCode != Activity.RESULT_OK) return;
201 | if (requestCode == REQUEST_RESULT) {
202 | ArrayList requests = data.getStringArrayListExtra(MyDialog.REQUEST);
203 | Log.e(TAG, "requests=" + requests.toString());
204 | final int requestCount = requests.size();
205 | for (int i = 0; i < requestCount; i++) {
206 | String request = requests.get(i);
207 | String[] requestSplit = request.split(",");
208 | String method = requestSplit[0];
209 | final int argsCount = requestSplit.length - 1;
210 | try {
211 | Object[] args = new Object[argsCount];
212 | Class>[] argTypes = new Class>[argsCount];
213 | for (int k = 0; k < argsCount; k++) {
214 | argTypes[k] = int.class;
215 | try {
216 | args[k] = Integer.valueOf(requestSplit[k + 1]);
217 | } catch (NumberFormatException e) {
218 | AppUtil.showToast(getContext(),
219 | "Test failed,please check input format");
220 | return;
221 | }
222 | }
223 | Method m = IPresenter.class.getDeclaredMethod(method, argTypes);
224 | Log.e(TAG, "method=" + m.toString());
225 | m.setAccessible(true);
226 | m.invoke(mIPresenter, args);
227 | } catch (NoSuchMethodException e) {
228 | e.printStackTrace();
229 | AppUtil.showToast(getContext(), "Test failed,please check input format");
230 | } catch (IllegalAccessException e) {
231 | e.printStackTrace();
232 | AppUtil.showToast(getContext(), "Test failed,please check input format");
233 | } catch (InvocationTargetException e) {
234 | e.printStackTrace();
235 | AppUtil.showToast(getContext(), "Test failed,please check input format");
236 | }
237 | }
238 | }
239 | }
240 |
241 | @Override
242 | public void onSaveInstanceState(Bundle outState) {
243 | super.onSaveInstanceState(outState);
244 | Logger.e(TAG, "<<<<<<<<<<<<<<<<<< Save Data >>>>>>>>>>>>>>>>>");
245 | outState.putParcelableArrayList(KEY_DATA, mData);
246 | mAdapter.onSaveInstanceState(outState);
247 | }
248 |
249 | private class ParentExpandableStateChangeListener
250 | implements ExpandableAdapter.OnParentExpandableStateChangeListener
251 | {
252 | @Override
253 | public void onParentExpandableStateChanged(RecyclerView rv, ParentViewHolder pvh,
254 | int position, boolean expandable)
255 | {
256 | Logger.e(TAG, "onParentExpandableStateChanged=" + position + "," + rv.getTag());
257 | if (pvh == null) return;
258 | final ImageView arrow = pvh.getView(R.id.arrow);
259 | if (expandable && arrow.getVisibility() != View.VISIBLE) {
260 | arrow.setVisibility(View.VISIBLE);
261 | arrow.setRotation(pvh.isExpanded() ? 180 : 0);
262 | } else if (!expandable && arrow.getVisibility() == View.VISIBLE) {
263 | arrow.setVisibility(View.GONE);
264 | }
265 | }
266 | }
267 |
268 | private class ParentExpandCollapseListener
269 | implements ExpandableAdapter.OnParentExpandCollapseListener
270 | {
271 | @Override
272 | public void onParentExpanded(RecyclerView rv, ParentViewHolder pvh, int position,
273 | boolean pendingCause, boolean byUser)
274 | {
275 | Logger.e(TAG, "onParentExpanded=" + position + "," + rv.getTag() + ",byUser=" + byUser);
276 | if (pvh == null) return;
277 | ImageView arrow = pvh.getView(R.id.arrow);
278 | if (arrow.getVisibility() != View.VISIBLE) return;
279 | float currRotate = arrow.getRotation();
280 | //重置为从0开始旋转
281 | if (currRotate == 360) {
282 | arrow.setRotation(0);
283 | }
284 | if (pendingCause) {
285 | arrow.setRotation(180);
286 | } else {
287 | arrow.animate()
288 | .rotation(180)
289 | .setDuration(mItemAnimator.getAddDuration() + 180)
290 | .start();
291 | }
292 |
293 | // if (byUser) {
294 | // int scrollToPos =
295 | // pvh.getAdapterPosition() + ((MyParent) pvh.getParent()).getChildCount();
296 | // rv.scrollToPosition(scrollToPos);
297 | // }
298 | }
299 |
300 | @Override
301 | public void onParentCollapsed(RecyclerView rv, ParentViewHolder pvh, int position,
302 | boolean pendingCause, boolean byUser)
303 | {
304 | Logger.e(TAG,
305 | "onParentCollapsed=" + position + ",tag=" + rv.getTag() + ",byUser=" + byUser);
306 |
307 | if (pvh == null) return;
308 | ImageView arrow = pvh.getView(R.id.arrow);
309 | if (arrow.getVisibility() != View.VISIBLE) return;
310 | float currRotate = arrow.getRotation();
311 | float rotate = 360;
312 | //未展开完全并且当前旋转角度小于180,逆转回去
313 | if (currRotate < 180) {
314 | rotate = 0;
315 | }
316 | if (pendingCause) {
317 | arrow.setRotation(rotate);
318 | } else {
319 | arrow.animate()
320 | .rotation(rotate)
321 | .setDuration(mItemAnimator.getRemoveDuration() + 180)
322 | .start();
323 | }
324 | }
325 | }
326 |
327 | }
328 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/github/huajianjiang/expandablerecyclerview/sample/anim/CircularRevealItemAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2017 HuaJian Jiang
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *
16 | */
17 |
18 | package com.github.huajianjiang.expandablerecyclerview.sample.anim;
19 |
20 | import android.animation.Animator;
21 | import android.animation.AnimatorListenerAdapter;
22 | import android.os.Build;
23 | import android.support.annotation.NonNull;
24 | import android.support.annotation.RequiresApi;
25 | import android.support.v4.animation.AnimatorCompatHelper;
26 | import android.support.v4.view.ViewCompat;
27 | import android.support.v4.view.ViewPropertyAnimatorCompat;
28 | import android.support.v4.view.ViewPropertyAnimatorListener;
29 | import android.support.v7.widget.RecyclerView;
30 | import android.support.v7.widget.SimpleItemAnimator;
31 | import android.view.View;
32 | import android.view.ViewAnimationUtils;
33 |
34 | import com.github.huajianjiang.expandablerecyclerview.util.Logger;
35 |
36 | import java.util.ArrayList;
37 | import java.util.List;
38 |
39 | /**
40 | * @author HuaJian Jiang.
41 | * Date 2017/1/2.
42 | *
43 | * just simply modify add/remove animation to CircularReveal animation which only support api 21 and later
44 | */
45 | public class CircularRevealItemAnimator extends SimpleItemAnimator {
46 | private static final String TAG = CircularRevealItemAnimator.class.getSimpleName();
47 | private static final boolean DEBUG = false;
48 |
49 | private ArrayList mPendingRemovals = new ArrayList<>();
50 | private ArrayList mPendingAdditions = new ArrayList<>();
51 | private ArrayList mPendingMoves = new ArrayList<>();
52 | private ArrayList mPendingChanges = new ArrayList<>();
53 |
54 | ArrayList> mAdditionsList = new ArrayList<>();
55 | ArrayList> mMovesList = new ArrayList<>();
56 | ArrayList> mChangesList = new ArrayList<>();
57 |
58 | ArrayList mAddAnimations = new ArrayList<>();
59 | ArrayList mMoveAnimations = new ArrayList<>();
60 | ArrayList mRemoveAnimations = new ArrayList<>();
61 | ArrayList mChangeAnimations = new ArrayList<>();
62 |
63 | private static class MoveInfo {
64 | public RecyclerView.ViewHolder holder;
65 | public int fromX, fromY, toX, toY;
66 |
67 | MoveInfo(RecyclerView.ViewHolder holder, int fromX, int fromY, int toX, int toY) {
68 | this.holder = holder;
69 | this.fromX = fromX;
70 | this.fromY = fromY;
71 | this.toX = toX;
72 | this.toY = toY;
73 | }
74 | }
75 |
76 | private static class ChangeInfo {
77 | public RecyclerView.ViewHolder oldHolder, newHolder;
78 | public int fromX, fromY, toX, toY;
79 | private ChangeInfo(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder) {
80 | this.oldHolder = oldHolder;
81 | this.newHolder = newHolder;
82 | }
83 |
84 | ChangeInfo(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder,
85 | int fromX, int fromY, int toX, int toY) {
86 | this(oldHolder, newHolder);
87 | this.fromX = fromX;
88 | this.fromY = fromY;
89 | this.toX = toX;
90 | this.toY = toY;
91 | }
92 |
93 | @Override
94 | public String toString() {
95 | return "ChangeInfo{" +
96 | "oldHolder=" + oldHolder +
97 | ", newHolder=" + newHolder +
98 | ", fromX=" + fromX +
99 | ", fromY=" + fromY +
100 | ", toX=" + toX +
101 | ", toY=" + toY +
102 | '}';
103 | }
104 | }
105 |
106 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
107 | @Override
108 | public void runPendingAnimations() {
109 | boolean removalsPending = !mPendingRemovals.isEmpty();
110 | boolean movesPending = !mPendingMoves.isEmpty();
111 | boolean changesPending = !mPendingChanges.isEmpty();
112 | boolean additionsPending = !mPendingAdditions.isEmpty();
113 | if (!removalsPending && !movesPending && !additionsPending && !changesPending) {
114 | // nothing to animate
115 | return;
116 | }
117 | // First, remove stuff
118 | for (RecyclerView.ViewHolder holder : mPendingRemovals) {
119 | animateRemoveImpl(holder);
120 | }
121 | mPendingRemovals.clear();
122 | // Next, move stuff
123 | if (movesPending) {
124 | final ArrayList moves = new ArrayList<>();
125 | moves.addAll(mPendingMoves);
126 | mMovesList.add(moves);
127 | mPendingMoves.clear();
128 | Runnable mover = new Runnable() {
129 | @Override
130 | public void run() {
131 | for (CircularRevealItemAnimator.MoveInfo moveInfo : moves) {
132 | animateMoveImpl(moveInfo.holder, moveInfo.fromX, moveInfo.fromY,
133 | moveInfo.toX, moveInfo.toY);
134 | }
135 | moves.clear();
136 | mMovesList.remove(moves);
137 | }
138 | };
139 | if (removalsPending) {
140 | View view = moves.get(0).holder.itemView;
141 | ViewCompat.postOnAnimationDelayed(view, mover, getRemoveDuration());
142 | } else {
143 | mover.run();
144 | }
145 | }
146 | // Next, change stuff, to run in parallel with move animations
147 | if (changesPending) {
148 | final ArrayList changes = new ArrayList<>();
149 | changes.addAll(mPendingChanges);
150 | mChangesList.add(changes);
151 | mPendingChanges.clear();
152 | Runnable changer = new Runnable() {
153 | @Override
154 | public void run() {
155 | for (CircularRevealItemAnimator.ChangeInfo change : changes) {
156 | animateChangeImpl(change);
157 | }
158 | changes.clear();
159 | mChangesList.remove(changes);
160 | }
161 | };
162 | if (removalsPending) {
163 | RecyclerView.ViewHolder holder = changes.get(0).oldHolder;
164 | ViewCompat.postOnAnimationDelayed(holder.itemView, changer, getRemoveDuration());
165 | } else {
166 | changer.run();
167 | }
168 | }
169 | // Next, add stuff
170 | if (additionsPending) {
171 | final ArrayList additions = new ArrayList<>();
172 | additions.addAll(mPendingAdditions);
173 | mAdditionsList.add(additions);
174 | mPendingAdditions.clear();
175 | Runnable adder = new Runnable() {
176 | @Override
177 | public void run() {
178 | for (RecyclerView.ViewHolder holder : additions) {
179 | animateAddImpl(holder);
180 | }
181 | additions.clear();
182 | mAdditionsList.remove(additions);
183 | }
184 | };
185 | if (removalsPending || movesPending || changesPending) {
186 | long removeDuration = removalsPending ? getRemoveDuration() : 0;
187 | long moveDuration = movesPending ? getMoveDuration() : 0;
188 | long changeDuration = changesPending ? getChangeDuration() : 0;
189 | long totalDelay = removeDuration + Math.max(moveDuration, changeDuration);
190 | View view = additions.get(0).itemView;
191 | ViewCompat.postOnAnimationDelayed(view, adder, totalDelay);
192 | } else {
193 | adder.run();
194 | }
195 | }
196 | }
197 |
198 | @Override
199 | public boolean animateRemove(final RecyclerView.ViewHolder holder) {
200 | resetAnimation(holder);
201 | mPendingRemovals.add(holder);
202 | return true;
203 | }
204 |
205 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
206 | private void animateRemoveImpl(final RecyclerView.ViewHolder holder) {
207 | final View view = holder.itemView;
208 | // final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
209 | mRemoveAnimations.add(holder);
210 | // get the center for the clipping circle
211 | int cx = (view.getLeft() + view.getRight()) / 2;
212 | int cy = view.getHeight() / 2;
213 |
214 | // get the initial radius for the clipping circle
215 | int initialRadius = view.getWidth();
216 |
217 | // create the animation (the final radius is zero)
218 | final Animator anim =
219 | ViewAnimationUtils.createCircularReveal(view, cx, cy, initialRadius, 0);
220 | anim.setDuration(getRemoveDuration());
221 | // make the view invisible when the animation is done
222 | anim.addListener(new AnimatorListenerAdapter() {
223 |
224 | @Override
225 | public void onAnimationStart(Animator animation) {
226 | dispatchAddStarting(holder);
227 | }
228 |
229 | @Override
230 | public void onAnimationEnd(Animator animation) {
231 | anim.removeListener(this);
232 | view.setVisibility(View.VISIBLE);
233 | dispatchRemoveFinished(holder);
234 | mRemoveAnimations.remove(holder);
235 | dispatchFinishedWhenDone();
236 | }
237 | });
238 |
239 | // start the animation
240 | anim.start();
241 | // animation.setDuration(getRemoveDuration())
242 | // .alpha(0).setListener(new CircularRevealItemAnimator.VpaListenerAdapter() {
243 | // @Override
244 | // public void onAnimationStart(View view) {
245 | // dispatchRemoveStarting(holder);
246 | // }
247 | //
248 | // @Override
249 | // public void onAnimationEnd(View view) {
250 | // animation.setListener(null);
251 | // ViewCompat.setAlpha(view, 1);
252 | // dispatchRemoveFinished(holder);
253 | // mRemoveAnimations.remove(holder);
254 | // dispatchFinishedWhenDone();
255 | // }
256 | // }).start();
257 | }
258 |
259 | @Override
260 | public boolean animateAdd(final RecyclerView.ViewHolder holder) {
261 | Logger.e(TAG, "<<>" + holder);
262 | resetAnimation(holder);
263 | // ViewCompat.setAlpha(holder.itemView, 0);
264 | holder.itemView.setVisibility(View.GONE);
265 | mPendingAdditions.add(holder);
266 | return true;
267 | }
268 |
269 | void animateAddImpl(final RecyclerView.ViewHolder holder) {
270 | Logger.e(TAG, "<<>" + holder);
271 | final View view = holder.itemView;
272 | // final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
273 | mAddAnimations.add(holder);
274 | // get the center for the clipping circle
275 | int cx = (view.getLeft() + view.getRight()) / 2;
276 | int cy = view.getHeight() / 2;
277 |
278 | Logger.e(TAG, "cx=" + cx + ",cy=" + cy);
279 |
280 | // get the final radius for the clipping circle
281 | int finalRadius = Math.max(view.getWidth(), view.getHeight());
282 |
283 | Logger.e(TAG,"width="+view.getWidth()+",height="+view.getHeight()+",finalRadius="+finalRadius);
284 |
285 | // create the animator for this view (the start radius is zero)
286 | final Animator anim =
287 | ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
288 | anim.setDuration(getAddDuration());
289 | anim.addListener(new AnimatorListenerAdapter() {
290 | @Override
291 | public void onAnimationStart(Animator animation) {
292 | dispatchAddStarting(holder);
293 | }
294 |
295 | @Override
296 | public void onAnimationCancel(Animator animation) {
297 | view.setVisibility(View.VISIBLE);
298 | }
299 |
300 | @Override
301 | public void onAnimationEnd(Animator animation) {
302 | anim.removeListener(this);
303 | dispatchAddFinished(holder);
304 | mAddAnimations.remove(holder);
305 | dispatchFinishedWhenDone();
306 | }
307 | });
308 | // make the view visible and start the animation
309 | view.setVisibility(View.VISIBLE);
310 | anim.start();
311 | // animation.alpha(1).setDuration(getAddDuration()).
312 | // setListener(new CircularRevealItemAnimator.VpaListenerAdapter() {
313 | // @Override
314 | // public void onAnimationStart(View view) {
315 | // dispatchAddStarting(holder);
316 | // }
317 | // @Override
318 | // public void onAnimationCancel(View view) {
319 | // ViewCompat.setAlpha(view, 1);
320 | // }
321 | //
322 | // @Override
323 | // public void onAnimationEnd(View view) {
324 | // animation.setListener(null);
325 | // dispatchAddFinished(holder);
326 | // mAddAnimations.remove(holder);
327 | // dispatchFinishedWhenDone();
328 | // }
329 | // }).start();
330 | }
331 |
332 | @Override
333 | public boolean animateMove(final RecyclerView.ViewHolder holder, int fromX, int fromY,
334 | int toX, int toY) {
335 | final View view = holder.itemView;
336 | fromX += ViewCompat.getTranslationX(holder.itemView);
337 | fromY += ViewCompat.getTranslationY(holder.itemView);
338 | resetAnimation(holder);
339 | int deltaX = toX - fromX;
340 | int deltaY = toY - fromY;
341 | if (deltaX == 0 && deltaY == 0) {
342 | dispatchMoveFinished(holder);
343 | return false;
344 | }
345 | if (deltaX != 0) {
346 | ViewCompat.setTranslationX(view, -deltaX);
347 | }
348 | if (deltaY != 0) {
349 | ViewCompat.setTranslationY(view, -deltaY);
350 | }
351 | mPendingMoves.add(new CircularRevealItemAnimator.MoveInfo(holder, fromX, fromY, toX, toY));
352 | return true;
353 | }
354 |
355 | void animateMoveImpl(final RecyclerView.ViewHolder holder, int fromX, int fromY, int toX, int toY) {
356 | final View view = holder.itemView;
357 | final int deltaX = toX - fromX;
358 | final int deltaY = toY - fromY;
359 | if (deltaX != 0) {
360 | ViewCompat.animate(view).translationX(0);
361 | }
362 | if (deltaY != 0) {
363 | ViewCompat.animate(view).translationY(0);
364 | }
365 | // TODO: make EndActions end listeners instead, since end actions aren't called when
366 | // vpas are canceled (and can't end them. why?)
367 | // need listener functionality in VPACompat for this. Ick.
368 | final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
369 | mMoveAnimations.add(holder);
370 | animation.setDuration(getMoveDuration()).setListener(new CircularRevealItemAnimator.VpaListenerAdapter() {
371 | @Override
372 | public void onAnimationStart(View view) {
373 | dispatchMoveStarting(holder);
374 | }
375 | @Override
376 | public void onAnimationCancel(View view) {
377 | if (deltaX != 0) {
378 | ViewCompat.setTranslationX(view, 0);
379 | }
380 | if (deltaY != 0) {
381 | ViewCompat.setTranslationY(view, 0);
382 | }
383 | }
384 | @Override
385 | public void onAnimationEnd(View view) {
386 | animation.setListener(null);
387 | dispatchMoveFinished(holder);
388 | mMoveAnimations.remove(holder);
389 | dispatchFinishedWhenDone();
390 | }
391 | }).start();
392 | }
393 |
394 | @Override
395 | public boolean animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder,
396 | int fromX, int fromY, int toX, int toY) {
397 | if (oldHolder == newHolder) {
398 | // Don't know how to run change animations when the same view holder is re-used.
399 | // run a move animation to handle position changes.
400 | return animateMove(oldHolder, fromX, fromY, toX, toY);
401 | }
402 | final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
403 | final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
404 | final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
405 | resetAnimation(oldHolder);
406 | int deltaX = (int) (toX - fromX - prevTranslationX);
407 | int deltaY = (int) (toY - fromY - prevTranslationY);
408 | // recover prev translation state after ending animation
409 | ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
410 | ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
411 | ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
412 | if (newHolder != null) {
413 | // carry over translation values
414 | resetAnimation(newHolder);
415 | ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
416 | ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
417 | ViewCompat.setAlpha(newHolder.itemView, 0);
418 | }
419 | mPendingChanges.add(new CircularRevealItemAnimator.ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
420 | return true;
421 | }
422 |
423 | void animateChangeImpl(final CircularRevealItemAnimator.ChangeInfo changeInfo) {
424 | final RecyclerView.ViewHolder holder = changeInfo.oldHolder;
425 | final View view = holder == null ? null : holder.itemView;
426 | final RecyclerView.ViewHolder newHolder = changeInfo.newHolder;
427 | final View newView = newHolder != null ? newHolder.itemView : null;
428 | if (view != null) {
429 | final ViewPropertyAnimatorCompat oldViewAnim = ViewCompat.animate(view).setDuration(
430 | getChangeDuration());
431 | mChangeAnimations.add(changeInfo.oldHolder);
432 | oldViewAnim.translationX(changeInfo.toX - changeInfo.fromX);
433 | oldViewAnim.translationY(changeInfo.toY - changeInfo.fromY);
434 | oldViewAnim.alpha(0).setListener(new CircularRevealItemAnimator.VpaListenerAdapter() {
435 | @Override
436 | public void onAnimationStart(View view) {
437 | dispatchChangeStarting(changeInfo.oldHolder, true);
438 | }
439 |
440 | @Override
441 | public void onAnimationEnd(View view) {
442 | oldViewAnim.setListener(null);
443 | ViewCompat.setAlpha(view, 1);
444 | ViewCompat.setTranslationX(view, 0);
445 | ViewCompat.setTranslationY(view, 0);
446 | dispatchChangeFinished(changeInfo.oldHolder, true);
447 | mChangeAnimations.remove(changeInfo.oldHolder);
448 | dispatchFinishedWhenDone();
449 | }
450 | }).start();
451 | }
452 | if (newView != null) {
453 | final ViewPropertyAnimatorCompat newViewAnimation = ViewCompat.animate(newView);
454 | mChangeAnimations.add(changeInfo.newHolder);
455 | newViewAnimation.translationX(0).translationY(0).setDuration(getChangeDuration()).
456 | alpha(1).setListener(new CircularRevealItemAnimator.VpaListenerAdapter() {
457 | @Override
458 | public void onAnimationStart(View view) {
459 | dispatchChangeStarting(changeInfo.newHolder, false);
460 | }
461 | @Override
462 | public void onAnimationEnd(View view) {
463 | newViewAnimation.setListener(null);
464 | ViewCompat.setAlpha(newView, 1);
465 | ViewCompat.setTranslationX(newView, 0);
466 | ViewCompat.setTranslationY(newView, 0);
467 | dispatchChangeFinished(changeInfo.newHolder, false);
468 | mChangeAnimations.remove(changeInfo.newHolder);
469 | dispatchFinishedWhenDone();
470 | }
471 | }).start();
472 | }
473 | }
474 |
475 | private void endChangeAnimation(List infoList, RecyclerView.ViewHolder item) {
476 | for (int i = infoList.size() - 1; i >= 0; i--) {
477 | CircularRevealItemAnimator.ChangeInfo changeInfo = infoList.get(i);
478 | if (endChangeAnimationIfNecessary(changeInfo, item)) {
479 | if (changeInfo.oldHolder == null && changeInfo.newHolder == null) {
480 | infoList.remove(changeInfo);
481 | }
482 | }
483 | }
484 | }
485 |
486 | private void endChangeAnimationIfNecessary(CircularRevealItemAnimator.ChangeInfo changeInfo) {
487 | if (changeInfo.oldHolder != null) {
488 | endChangeAnimationIfNecessary(changeInfo, changeInfo.oldHolder);
489 | }
490 | if (changeInfo.newHolder != null) {
491 | endChangeAnimationIfNecessary(changeInfo, changeInfo.newHolder);
492 | }
493 | }
494 | private boolean endChangeAnimationIfNecessary(CircularRevealItemAnimator.ChangeInfo changeInfo, RecyclerView.ViewHolder item) {
495 | boolean oldItem = false;
496 | if (changeInfo.newHolder == item) {
497 | changeInfo.newHolder = null;
498 | } else if (changeInfo.oldHolder == item) {
499 | changeInfo.oldHolder = null;
500 | oldItem = true;
501 | } else {
502 | return false;
503 | }
504 | // ViewCompat.setAlpha(item.itemView, 1);
505 | item.itemView.setVisibility(View.VISIBLE);
506 | ViewCompat.setTranslationX(item.itemView, 0);
507 | ViewCompat.setTranslationY(item.itemView, 0);
508 | dispatchChangeFinished(item, oldItem);
509 | return true;
510 | }
511 |
512 | @Override
513 | public void endAnimation(RecyclerView.ViewHolder item) {
514 | final View view = item.itemView;
515 | // this will trigger end callback which should set properties to their target values.
516 | ViewCompat.animate(view).cancel();
517 | // TODO if some other animations are chained to end, how do we cancel them as well?
518 | for (int i = mPendingMoves.size() - 1; i >= 0; i--) {
519 | CircularRevealItemAnimator.MoveInfo moveInfo = mPendingMoves.get(i);
520 | if (moveInfo.holder == item) {
521 | ViewCompat.setTranslationY(view, 0);
522 | ViewCompat.setTranslationX(view, 0);
523 | dispatchMoveFinished(item);
524 | mPendingMoves.remove(i);
525 | }
526 | }
527 | endChangeAnimation(mPendingChanges, item);
528 | if (mPendingRemovals.remove(item)) {
529 | // ViewCompat.setAlpha(view, 1);
530 | view.setVisibility(View.VISIBLE);
531 | dispatchRemoveFinished(item);
532 | }
533 | if (mPendingAdditions.remove(item)) {
534 | // ViewCompat.setAlpha(view, 1);
535 | view.setVisibility(View.VISIBLE);
536 | dispatchAddFinished(item);
537 | }
538 |
539 | for (int i = mChangesList.size() - 1; i >= 0; i--) {
540 | ArrayList changes = mChangesList.get(i);
541 | endChangeAnimation(changes, item);
542 | if (changes.isEmpty()) {
543 | mChangesList.remove(i);
544 | }
545 | }
546 | for (int i = mMovesList.size() - 1; i >= 0; i--) {
547 | ArrayList moves = mMovesList.get(i);
548 | for (int j = moves.size() - 1; j >= 0; j--) {
549 | CircularRevealItemAnimator.MoveInfo moveInfo = moves.get(j);
550 | if (moveInfo.holder == item) {
551 | ViewCompat.setTranslationY(view, 0);
552 | ViewCompat.setTranslationX(view, 0);
553 | dispatchMoveFinished(item);
554 | moves.remove(j);
555 | if (moves.isEmpty()) {
556 | mMovesList.remove(i);
557 | }
558 | break;
559 | }
560 | }
561 | }
562 | for (int i = mAdditionsList.size() - 1; i >= 0; i--) {
563 | ArrayList additions = mAdditionsList.get(i);
564 | if (additions.remove(item)) {
565 | // ViewCompat.setAlpha(view, 1);
566 | view.setVisibility(View.VISIBLE);
567 | dispatchAddFinished(item);
568 | if (additions.isEmpty()) {
569 | mAdditionsList.remove(i);
570 | }
571 | }
572 | }
573 |
574 | // animations should be ended by the cancel above.
575 | //noinspection PointlessBooleanExpression,ConstantConditions
576 | if (mRemoveAnimations.remove(item) && DEBUG) {
577 | throw new IllegalStateException("after animation is cancelled, item should not be in "
578 | + "mRemoveAnimations list");
579 | }
580 |
581 | //noinspection PointlessBooleanExpression,ConstantConditions
582 | if (mAddAnimations.remove(item) && DEBUG) {
583 | throw new IllegalStateException("after animation is cancelled, item should not be in "
584 | + "mAddAnimations list");
585 | }
586 |
587 | //noinspection PointlessBooleanExpression,ConstantConditions
588 | if (mChangeAnimations.remove(item) && DEBUG) {
589 | throw new IllegalStateException("after animation is cancelled, item should not be in "
590 | + "mChangeAnimations list");
591 | }
592 |
593 | //noinspection PointlessBooleanExpression,ConstantConditions
594 | if (mMoveAnimations.remove(item) && DEBUG) {
595 | throw new IllegalStateException("after animation is cancelled, item should not be in "
596 | + "mMoveAnimations list");
597 | }
598 | dispatchFinishedWhenDone();
599 | }
600 |
601 | private void resetAnimation(RecyclerView.ViewHolder holder) {
602 | AnimatorCompatHelper.clearInterpolator(holder.itemView);
603 | endAnimation(holder);
604 | }
605 |
606 | @Override
607 | public boolean isRunning() {
608 | return (!mPendingAdditions.isEmpty() ||
609 | !mPendingChanges.isEmpty() ||
610 | !mPendingMoves.isEmpty() ||
611 | !mPendingRemovals.isEmpty() ||
612 | !mMoveAnimations.isEmpty() ||
613 | !mRemoveAnimations.isEmpty() ||
614 | !mAddAnimations.isEmpty() ||
615 | !mChangeAnimations.isEmpty() ||
616 | !mMovesList.isEmpty() ||
617 | !mAdditionsList.isEmpty() ||
618 | !mChangesList.isEmpty());
619 | }
620 |
621 | /**
622 | * Check the state of currently pending and running animations. If there are none
623 | * pending/running, call {@link #dispatchAnimationsFinished()} to notify any
624 | * listeners.
625 | */
626 | void dispatchFinishedWhenDone() {
627 | if (!isRunning()) {
628 | dispatchAnimationsFinished();
629 | }
630 | }
631 |
632 | @Override
633 | public void endAnimations() {
634 | int count = mPendingMoves.size();
635 | for (int i = count - 1; i >= 0; i--) {
636 | CircularRevealItemAnimator.MoveInfo item = mPendingMoves.get(i);
637 | View view = item.holder.itemView;
638 | ViewCompat.setTranslationY(view, 0);
639 | ViewCompat.setTranslationX(view, 0);
640 | dispatchMoveFinished(item.holder);
641 | mPendingMoves.remove(i);
642 | }
643 | count = mPendingRemovals.size();
644 | for (int i = count - 1; i >= 0; i--) {
645 | RecyclerView.ViewHolder item = mPendingRemovals.get(i);
646 | dispatchRemoveFinished(item);
647 | mPendingRemovals.remove(i);
648 | }
649 | count = mPendingAdditions.size();
650 | for (int i = count - 1; i >= 0; i--) {
651 | RecyclerView.ViewHolder item = mPendingAdditions.get(i);
652 | View view = item.itemView;
653 | // ViewCompat.setAlpha(view, 1);
654 | view.setVisibility(View.VISIBLE);
655 | dispatchAddFinished(item);
656 | mPendingAdditions.remove(i);
657 | }
658 | count = mPendingChanges.size();
659 | for (int i = count - 1; i >= 0; i--) {
660 | endChangeAnimationIfNecessary(mPendingChanges.get(i));
661 | }
662 | mPendingChanges.clear();
663 | if (!isRunning()) {
664 | return;
665 | }
666 |
667 | int listCount = mMovesList.size();
668 | for (int i = listCount - 1; i >= 0; i--) {
669 | ArrayList moves = mMovesList.get(i);
670 | count = moves.size();
671 | for (int j = count - 1; j >= 0; j--) {
672 | CircularRevealItemAnimator.MoveInfo moveInfo = moves.get(j);
673 | RecyclerView.ViewHolder item = moveInfo.holder;
674 | View view = item.itemView;
675 | ViewCompat.setTranslationY(view, 0);
676 | ViewCompat.setTranslationX(view, 0);
677 | dispatchMoveFinished(moveInfo.holder);
678 | moves.remove(j);
679 | if (moves.isEmpty()) {
680 | mMovesList.remove(moves);
681 | }
682 | }
683 | }
684 | listCount = mAdditionsList.size();
685 | for (int i = listCount - 1; i >= 0; i--) {
686 | ArrayList additions = mAdditionsList.get(i);
687 | count = additions.size();
688 | for (int j = count - 1; j >= 0; j--) {
689 | RecyclerView.ViewHolder item = additions.get(j);
690 | View view = item.itemView;
691 | // ViewCompat.setAlpha(view, 1);
692 | view.setVisibility(View.VISIBLE);
693 | dispatchAddFinished(item);
694 | additions.remove(j);
695 | if (additions.isEmpty()) {
696 | mAdditionsList.remove(additions);
697 | }
698 | }
699 | }
700 | listCount = mChangesList.size();
701 | for (int i = listCount - 1; i >= 0; i--) {
702 | ArrayList changes = mChangesList.get(i);
703 | count = changes.size();
704 | for (int j = count - 1; j >= 0; j--) {
705 | endChangeAnimationIfNecessary(changes.get(j));
706 | if (changes.isEmpty()) {
707 | mChangesList.remove(changes);
708 | }
709 | }
710 | }
711 |
712 | cancelAll(mRemoveAnimations);
713 | cancelAll(mMoveAnimations);
714 | cancelAll(mAddAnimations);
715 | cancelAll(mChangeAnimations);
716 |
717 | dispatchAnimationsFinished();
718 | }
719 |
720 | void cancelAll(List viewHolders) {
721 | for (int i = viewHolders.size() - 1; i >= 0; i--) {
722 | ViewCompat.animate(viewHolders.get(i).itemView).cancel();
723 | }
724 | }
725 |
726 | /**
727 | * {@inheritDoc}
728 | *
729 | * If the payload list is not empty, DefaultItemAnimator returns true.
730 | * When this is the case:
731 | *
732 | *
If you override {@link #animateChange(RecyclerView.ViewHolder, RecyclerView.ViewHolder, int, int, int, int)}, both
733 | * ViewHolder arguments will be the same instance.
734 | *
735 | *
736 | * If you are not overriding {@link #animateChange(RecyclerView.ViewHolder, RecyclerView.ViewHolder, int, int, int, int)},
737 | * then DefaultItemAnimator will call {@link #animateMove(RecyclerView.ViewHolder, int, int, int, int)} and
738 | * run a move animation instead.
739 | *
740 | *
741 | */
742 | @Override
743 | public boolean canReuseUpdatedViewHolder(@NonNull RecyclerView.ViewHolder viewHolder,
744 | @NonNull List