Interface which provides required information for expanding item.
23 | *Implement this interface on your sub-class of the {@link android.support.v7.widget.RecyclerView.ViewHolder}.
24 | */ 25 | public interface ExpandableItemViewHolder { 26 | /** 27 | * Sets the state flags value for expanding item 28 | * 29 | * @param flags Bitwise OR of these flags; 30 | * - {@link ExpandableItemConstants#STATE_FLAG_IS_GROUP} 31 | * - {@link ExpandableItemConstants#STATE_FLAG_IS_CHILD} 32 | * - {@link ExpandableItemConstants#STATE_FLAG_IS_EXPANDED} 33 | * - {@link ExpandableItemConstants#STATE_FLAG_IS_UPDATED} 34 | */ 35 | void setExpandStateFlags(@ExpandableItemStateFlags int flags); 36 | 37 | /** 38 | * Gets the state flags value for expanding item 39 | * 40 | * @return Bitwise OR of these flags; 41 | * - {@link ExpandableItemConstants#STATE_FLAG_IS_GROUP} 42 | * - {@link ExpandableItemConstants#STATE_FLAG_IS_CHILD} 43 | * - {@link ExpandableItemConstants#STATE_FLAG_IS_EXPANDED} 44 | * - {@link ExpandableItemConstants#STATE_FLAG_IS_UPDATED} 45 | */ 46 | @ExpandableItemStateFlags 47 | int getExpandStateFlags(); 48 | } 49 | -------------------------------------------------------------------------------- /expandableListview/src/main/java/com/h6ah4i/android/widget/advrecyclerview/swipeable/SwipeReactionUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Haruki Hasegawa 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 | package com.h6ah4i.android.widget.advrecyclerview.swipeable; 18 | 19 | class SwipeReactionUtils { 20 | public static int extractLeftReaction(int type) { 21 | return ((type >>> InternalConstants.BIT_SHIFT_AMOUNT_LEFT) & InternalConstants.REACTION_CAPABILITY_MASK); 22 | } 23 | 24 | public static int extractUpReaction(int type) { 25 | return ((type >>> InternalConstants.BIT_SHIFT_AMOUNT_UP) & InternalConstants.REACTION_CAPABILITY_MASK); 26 | } 27 | 28 | public static int extractRightReaction(int type) { 29 | return ((type >>> InternalConstants.BIT_SHIFT_AMOUNT_RIGHT) & InternalConstants.REACTION_CAPABILITY_MASK); 30 | } 31 | 32 | public static int extractDownReaction(int type) { 33 | return ((type >>> InternalConstants.BIT_SHIFT_AMOUNT_DOWN) & InternalConstants.REACTION_CAPABILITY_MASK); 34 | } 35 | 36 | public static boolean canSwipeLeft(int reactionType) { 37 | return (extractLeftReaction(reactionType) == InternalConstants.REACTION_CAN_SWIPE); 38 | } 39 | 40 | public static boolean canSwipeUp(int reactionType) { 41 | return (extractUpReaction(reactionType) == InternalConstants.REACTION_CAN_SWIPE); 42 | } 43 | 44 | public static boolean canSwipeRight(int reactionType) { 45 | return (extractRightReaction(reactionType) == InternalConstants.REACTION_CAN_SWIPE); 46 | } 47 | 48 | public static boolean canSwipeDown(int reactionType) { 49 | return (extractDownReaction(reactionType) == InternalConstants.REACTION_CAN_SWIPE); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/res/layout/list_group_item.xml: -------------------------------------------------------------------------------- 1 | 16 |
13 |
14 |
15 |
16 | ### Demonstration video on YouTube
17 |
18 |
19 |
20 |
21 |
22 | ---
23 |
24 | Target platforms
25 | ---
26 |
27 | - API level 15 or later
28 |
29 |
30 | Latest version
31 | ---
32 |
33 | - Version 0.5.0 (May. 30, 2016) ([RELEASE NOTES](./RELEASE-NOTES.md))
34 |
35 | * Support library v23.0.2 was used
36 | * Android Advanced RecyclerView library was used
37 |
38 |
39 | Getting started
40 | ---
41 |
42 | This project provides an Expandable RecyclerView with group items that can be individually expanded to show its children in a two-dimensional scrolling grid.
43 |
44 |
45 | Usage
46 | ---
47 | [Expandable Grid Item]
48 | Each GridRowHolder object receives a data array from RecyclerView adapter to display in a grid row. Then it breaks up the layout of its row in rectangular cells of equal size. Each cell displays a piece of data and can be selected by user.
49 |
50 | Please check the implementation of simple example.
51 |
52 | - [Expandable Grid Item] (https://github.com/Armani2015/expandable-recyclerview-with-gridlayout/blob/master/app/src/main/java/com/armani2015/android/adapters/ExpandableGridItemAdapter.java)
53 |
54 |
55 | License ("Expandable RecyclerView With Grid Layout")
56 | ---
57 |
58 | This project is licensed under the [Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).
59 |
60 | See [`LICENSE`](LICENSE) for full of the license text.
61 |
62 | Copyright (C) 2016 Fabrice Thilaw
63 |
64 | Licensed under the Apache License, Version 2.0 (the "License");
65 | you may not use this file except in compliance with the License.
66 | You may obtain a copy of the License at
67 |
68 | http://www.apache.org/licenses/LICENSE-2.0
69 |
70 | Unless required by applicable law or agreed to in writing, software
71 | distributed under the License is distributed on an "AS IS" BASIS,
72 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
73 | See the License for the specific language governing permissions and
74 | limitations under the License.
75 |
76 | # expandable-recyclerview-with-gridlayout
77 |
--------------------------------------------------------------------------------
/app/src/main/java/com/armani2015/android/common/widget/ExpandableItemIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2015 Haruki Hasegawa
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 | package com.armani2015.android.common.widget;
18 |
19 | import android.content.Context;
20 | import android.os.Build;
21 | import android.os.Parcelable;
22 | import android.util.AttributeSet;
23 | import android.util.SparseArray;
24 | import android.widget.FrameLayout;
25 |
26 | public class ExpandableItemIndicator extends FrameLayout {
27 | static abstract class Impl {
28 | public abstract void onInit(Context context, AttributeSet attrs, int defStyleAttr, ExpandableItemIndicator thiz);
29 |
30 | public abstract void setExpandedState(boolean isExpanded, boolean animate);
31 | }
32 |
33 | private Impl mImpl;
34 |
35 | public ExpandableItemIndicator(Context context) {
36 | super(context);
37 | onInit(context, null, 0);
38 | }
39 |
40 | public ExpandableItemIndicator(Context context, AttributeSet attrs) {
41 | super(context, attrs);
42 | onInit(context, attrs, 0);
43 | }
44 |
45 | public ExpandableItemIndicator(Context context, AttributeSet attrs, int defStyleAttr) {
46 | super(context, attrs, defStyleAttr);
47 | onInit(context, attrs, defStyleAttr);
48 | }
49 |
50 | protected void onInit(Context context, AttributeSet attrs, int defStyleAttr) {
51 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
52 | // NOTE: VectorDrawable only supports API level 21 or later
53 | mImpl = new ExpandableItemIndicatorImplAnim();
54 | } else {
55 | mImpl = new ExpandableItemIndicatorImplNoAnim();
56 | }
57 | mImpl.onInit(context, attrs, defStyleAttr, this);
58 | }
59 |
60 | @Override
61 | protected void dispatchSaveInstanceState(SparseArrayCalled when item is swiped.
36 | **Note that do not change the data set and do not call notifyDataXXX() methods inside of this method.*
37 | * 38 | * @param holder The ViewHolder which is associated to the swiped item. 39 | * @param position The position of the item within the adapter's data set. 40 | * @param result The result code of user's swipe operation. 41 | * {@link SwipeableItemConstants#RESULT_CANCELED}, 42 | * {@link SwipeableItemConstants#RESULT_SWIPED_LEFT}, 43 | * {@link SwipeableItemConstants#RESULT_SWIPED_UP}, 44 | * {@link SwipeableItemConstants#RESULT_SWIPED_RIGHT} or 45 | * {@link SwipeableItemConstants#RESULT_SWIPED_DOWN} 46 | * @return Reaction type of after swiping. 47 | * One of the {@link SwipeableItemConstants#AFTER_SWIPE_REACTION_DEFAULT}, 48 | * {@link SwipeableItemConstants#AFTER_SWIPE_REACTION_MOVE_TO_SWIPED_DIRECTION} or 49 | * {@link SwipeableItemConstants#AFTER_SWIPE_REACTION_REMOVE_ITEM}. 50 | */ 51 | @SwipeableItemAfterReactions 52 | int onSwipeItem(T holder, int position, int result); 53 | 54 | /** 55 | *Called after {@link #onSwipeItem(android.support.v7.widget.RecyclerView.ViewHolder, int, int)} method.
56 | *You can update the data set and call notifyDataXXX() methods inside of this method.
57 | * 58 | * @param holder The ViewHolder which is associated to the swiped item. 59 | * @param position The position of the item within the adapter's data set. 60 | * @param result The result code of user's swipe operation. 61 | * {@link SwipeableItemConstants#RESULT_CANCELED}, 62 | * {@link SwipeableItemConstants#RESULT_SWIPED_LEFT}, 63 | * {@link SwipeableItemConstants#RESULT_SWIPED_UP}, 64 | * {@link SwipeableItemConstants#RESULT_SWIPED_RIGHT} or 65 | * {@link SwipeableItemConstants#RESULT_SWIPED_DOWN} 66 | * @param reaction Reaction type. One of the {@link SwipeableItemConstants#AFTER_SWIPE_REACTION_DEFAULT}, 67 | * {@link SwipeableItemConstants#AFTER_SWIPE_REACTION_MOVE_TO_SWIPED_DIRECTION} or 68 | * {@link SwipeableItemConstants#AFTER_SWIPE_REACTION_REMOVE_ITEM}. 69 | */ 70 | void onPerformAfterSwipeReaction(T holder, int position, @SwipeableItemResults int result, @SwipeableItemAfterReactions int reaction); 71 | } 72 | -------------------------------------------------------------------------------- /expandableListview/src/main/java/com/h6ah4i/android/widget/advrecyclerview/event/RecyclerViewOnScrollEventDistributor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015 Haruki Hasegawa 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 | package com.h6ah4i.android.widget.advrecyclerview.event; 18 | 19 | import android.support.v7.widget.RecyclerView; 20 | 21 | import java.lang.ref.WeakReference; 22 | 23 | /** 24 | * Deprecated. 25 | * 26 | * Please use {@link RecyclerView#addOnScrollListener(RecyclerView.OnScrollListener)} and {@link RecyclerView#removeOnScrollListener(RecyclerView.OnScrollListener)} instead. 27 | */ 28 | @Deprecated 29 | public class RecyclerViewOnScrollEventDistributor extends BaseRecyclerViewEventDistributor