├── library
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ └── values
│ │ │ ├── ids.xml
│ │ │ └── attrs.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── tjerkw
│ │ └── slideexpandable
│ │ └── library
│ │ ├── SlideExpandableListAdapter.java
│ │ ├── ExpandCollapseAnimation.java
│ │ ├── ActionSlideExpandableListView.java
│ │ ├── WrapperListAdapterImpl.java
│ │ ├── SlideExpandableListView.java
│ │ └── AbstractSlideExpandableListAdapter.java
├── build.gradle
└── project.properties
├── settings.gradle
├── raw
├── screenshot0.png
├── screenshot1.png
├── screenshot2.png
├── example-screens.png
└── example-screens.psd
├── sample
├── src
│ └── main
│ │ ├── res
│ │ ├── drawable
│ │ │ └── icon.png
│ │ ├── values
│ │ │ └── strings.xml
│ │ └── layout
│ │ │ ├── single_expandable_list.xml
│ │ │ └── expandable_list_item.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── tjerkw
│ │ └── slideexpandable
│ │ └── sample
│ │ └── ExampleActivity.java
├── build.gradle
└── project.properties
├── .travis.yml
├── .gitignore
├── README.md
└── LICENSE.txt
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':library'
--------------------------------------------------------------------------------
/raw/screenshot0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tjerkw/Android-SlideExpandableListView/HEAD/raw/screenshot0.png
--------------------------------------------------------------------------------
/raw/screenshot1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tjerkw/Android-SlideExpandableListView/HEAD/raw/screenshot1.png
--------------------------------------------------------------------------------
/raw/screenshot2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tjerkw/Android-SlideExpandableListView/HEAD/raw/screenshot2.png
--------------------------------------------------------------------------------
/raw/example-screens.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tjerkw/Android-SlideExpandableListView/HEAD/raw/example-screens.png
--------------------------------------------------------------------------------
/raw/example-screens.psd:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tjerkw/Android-SlideExpandableListView/HEAD/raw/example-screens.psd
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tjerkw/Android-SlideExpandableListView/HEAD/sample/src/main/res/drawable/icon.png
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | SlideExpandable Example
4 |
5 |
--------------------------------------------------------------------------------
/library/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/single_expandable_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
13 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 |
3 | before_install:
4 | - sudo apt-get update
5 | - sudo apt-get install -qq libstdc++6:i386 lib32z1
6 | - export COMPONENTS=build-tools-19.1.0,android-19
7 | - curl -L https://raw.github.com/embarkmobile/android-sdk-installer/version-1/android-sdk-installer | bash /dev/stdin --install=$COMPONENTS
8 | - source ~/.android-sdk-installer/env
9 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:0.8.+'
7 | }
8 | }
9 |
10 | apply plugin: 'android-library'
11 |
12 | dependencies {
13 | compile project(':library')
14 | }
15 |
16 | android {
17 | compileSdkVersion 19
18 | buildToolsVersion = '19.0.1'
19 | }
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:0.11.+'
7 | }
8 | }
9 |
10 | apply plugin: 'android-library'
11 |
12 | group='com.tjerkw.slideexpandable'
13 | archivesBaseName='library'
14 | version = '1.0'
15 |
16 | android {
17 | compileSdkVersion 19
18 | buildToolsVersion = '19.1.0'
19 | }
20 |
--------------------------------------------------------------------------------
/library/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=android-8
12 | android.library=true
13 |
--------------------------------------------------------------------------------
/sample/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=android-4
12 | android.library.reference.1=../library
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #IntelliJ IDEA
2 | .idea
3 | *.iml
4 | *.ipr
5 | *.iws
6 | out
7 | gen-external-apklibs
8 |
9 | #Gradke
10 | .gradle
11 | build
12 |
13 | #OSX
14 | .DS_Store
15 |
16 | #Android generated
17 | bin
18 | gen
19 |
20 | # files for the dex VM
21 | *.dex
22 |
23 | # Java class files
24 | *.class
25 |
26 | # generated files
27 | bin/
28 | gen/
29 |
30 | # Local configuration file (sdk path, etc)
31 | local.properties
32 |
33 | #Eclipse
34 | .project
35 | **.settings
36 | .classpath
37 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
14 |
17 |
18 |
20 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/library/src/main/java/com/tjerkw/slideexpandable/library/SlideExpandableListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.tjerkw.slideexpandable.library;
2 |
3 | import android.view.View;
4 | import android.widget.ListAdapter;
5 |
6 | /**
7 | * ListAdapter that adds sliding functionality to a list.
8 | * Uses R.id.expandalbe_toggle_button and R.id.expandable id's if no
9 | * ids are given in the contructor.
10 | *
11 | * @author tjerk
12 | * @date 6/13/12 8:04 AM
13 | */
14 | public class SlideExpandableListAdapter extends AbstractSlideExpandableListAdapter {
15 | private int toggle_button_id;
16 | private int expandable_view_id;
17 |
18 | public SlideExpandableListAdapter(ListAdapter wrapped, int toggle_button_id, int expandable_view_id) {
19 | super(wrapped);
20 | this.toggle_button_id = toggle_button_id;
21 | this.expandable_view_id = expandable_view_id;
22 | }
23 |
24 | public SlideExpandableListAdapter(ListAdapter wrapped) {
25 | this(wrapped, R.id.expandable_toggle_button, R.id.expandable);
26 | }
27 |
28 | @Override
29 | public View getExpandToggleButton(View parent) {
30 | return parent.findViewById(toggle_button_id);
31 | }
32 |
33 | @Override
34 | public View getExpandableView(View parent) {
35 | return parent.findViewById(expandable_view_id);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/expandable_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
12 |
13 |
18 |
19 |
27 |
28 |
29 |
30 |
36 |
37 |
43 |
44 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/library/src/main/java/com/tjerkw/slideexpandable/library/ExpandCollapseAnimation.java:
--------------------------------------------------------------------------------
1 | package com.tjerkw.slideexpandable.library;
2 |
3 | import android.util.Log;
4 | import android.view.View;
5 | import android.view.animation.Animation;
6 | import android.view.animation.Transformation;
7 | import android.widget.LinearLayout;
8 |
9 | /**
10 | * Animation that either expands or collapses a view by sliding it down to make it visible.
11 | * Or by sliding it up so it will hide. It will look like it slides behind the view above.
12 | *
13 | * @auther tjerk
14 | * @date 6/9/12 4:58 PM
15 | */
16 | public class ExpandCollapseAnimation extends Animation {
17 | private View mAnimatedView;
18 | private int mEndHeight;
19 | private int mType;
20 | public final static int COLLAPSE = 1;
21 | public final static int EXPAND = 0;
22 | private LinearLayout.LayoutParams mLayoutParams;
23 |
24 | /**
25 | * Initializes expand collapse animation, has two types, collapse (1) and expand (0).
26 | * @param view The view to animate
27 | * @param type The type of animation: 0 will expand from gone and 0 size to visible and layout size defined in xml.
28 | * 1 will collapse view and set to gone
29 | */
30 | public ExpandCollapseAnimation(View view, int type) {
31 |
32 | mAnimatedView = view;
33 | mEndHeight = mAnimatedView.getMeasuredHeight();
34 | mLayoutParams = ((LinearLayout.LayoutParams) view.getLayoutParams());
35 | mType = type;
36 | if(mType == EXPAND) {
37 |
38 | mLayoutParams.bottomMargin = -mEndHeight;
39 | } else {
40 |
41 | mLayoutParams.bottomMargin = 0;
42 | }
43 | view.setVisibility(View.VISIBLE);
44 | }
45 |
46 | @Override
47 | protected void applyTransformation(float interpolatedTime, Transformation t) {
48 |
49 | super.applyTransformation(interpolatedTime, t);
50 | if (interpolatedTime < 1.0f) {
51 | if(mType == EXPAND) {
52 | mLayoutParams.bottomMargin = -mEndHeight + (int) (mEndHeight * interpolatedTime);
53 | } else {
54 | mLayoutParams.bottomMargin = - (int) (mEndHeight * interpolatedTime);
55 | }
56 | Log.d("ExpandCollapseAnimation", "anim height " + mLayoutParams.bottomMargin);
57 | mAnimatedView.requestLayout();
58 | } else {
59 | if(mType == EXPAND) {
60 | mLayoutParams.bottomMargin = 0;
61 | mAnimatedView.requestLayout();
62 | } else {
63 | mLayoutParams.bottomMargin = -mEndHeight;
64 | mAnimatedView.setVisibility(View.GONE);
65 | mAnimatedView.requestLayout();
66 | }
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/library/src/main/java/com/tjerkw/slideexpandable/library/ActionSlideExpandableListView.java:
--------------------------------------------------------------------------------
1 | package com.tjerkw.slideexpandable.library;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.ListAdapter;
8 |
9 | /**
10 | * A more specific expandable listview in which the expandable area
11 | * consist of some buttons which are context actions for the item itself.
12 | *
13 | * It handles event binding for those buttons and allow for adding
14 | * a listener that will be invoked if one of those buttons are pressed.
15 | *
16 | * @author tjerk
17 | * @date 6/26/12 7:01 PM
18 | */
19 | public class ActionSlideExpandableListView extends SlideExpandableListView {
20 | private OnActionClickListener listener;
21 | private int[] buttonIds = null;
22 |
23 | public ActionSlideExpandableListView(Context context) {
24 | super(context);
25 | }
26 |
27 | public ActionSlideExpandableListView(Context context, AttributeSet attrs) {
28 | super(context, attrs);
29 | }
30 |
31 | public ActionSlideExpandableListView(Context context, AttributeSet attrs, int defStyle) {
32 | super(context, attrs, defStyle);
33 | }
34 |
35 | public void setItemActionListener(OnActionClickListener listener, int ... buttonIds) {
36 | this.listener = listener;
37 | this.buttonIds = buttonIds;
38 | }
39 |
40 | /**
41 | * Interface for callback to be invoked whenever an action is clicked in
42 | * the expandle area of the list item.
43 | */
44 | public interface OnActionClickListener {
45 | /**
46 | * Called when an action item is clicked.
47 | *
48 | * @param itemView the view of the list item
49 | * @param clickedView the view clicked
50 | * @param position the position in the listview
51 | */
52 | public void onClick(View itemView, View clickedView, int position);
53 | }
54 |
55 | public void setAdapter(ListAdapter adapter) {
56 | super.setAdapter(new WrapperListAdapterImpl(adapter) {
57 |
58 | @Override
59 | public View getView(final int position, View view, ViewGroup viewGroup) {
60 | final View listView = wrapped.getView(position, view, viewGroup);
61 | // add the action listeners
62 | if(buttonIds != null && listView!=null) {
63 | for(int id : buttonIds) {
64 | View buttonView = listView.findViewById(id);
65 | if(buttonView!=null) {
66 | buttonView.findViewById(id).setOnClickListener(new OnClickListener() {
67 | @Override
68 | public void onClick(View view) {
69 | if(listener!=null) {
70 | listener.onClick(listView, view, position);
71 | }
72 | }
73 | });
74 | }
75 | }
76 | }
77 | return listView;
78 | }
79 | });
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/library/src/main/java/com/tjerkw/slideexpandable/library/WrapperListAdapterImpl.java:
--------------------------------------------------------------------------------
1 | package com.tjerkw.slideexpandable.library;
2 |
3 | import android.database.DataSetObserver;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.BaseAdapter;
7 | import android.widget.ListAdapter;
8 | import android.widget.WrapperListAdapter;
9 |
10 | /**
11 | * Implementation of a WrapperListAdapter interface
12 | * in which each method delegates to the wrapped adapter.
13 | *
14 | * Extend this class if you only want to change a
15 | * few methods of the wrapped adapter.
16 | *
17 | * The wrapped adapter is available to subclasses as the "wrapped" field.
18 | *
19 | * @author tjerk
20 | * @date 6/9/12 4:41 PM
21 | */
22 | public abstract class WrapperListAdapterImpl extends BaseAdapter implements WrapperListAdapter {
23 | protected final ListAdapter wrapped;
24 |
25 | public WrapperListAdapterImpl(ListAdapter wrapped) {
26 | this.wrapped = wrapped;
27 | }
28 |
29 | @Override
30 | public ListAdapter getWrappedAdapter() {
31 | return wrapped;
32 | }
33 |
34 | @Override
35 | public boolean areAllItemsEnabled() {
36 | return wrapped.areAllItemsEnabled();
37 | }
38 |
39 | @Override
40 | public boolean isEnabled(int i) {
41 | return wrapped.isEnabled(i);
42 | }
43 |
44 | @Override
45 | public void registerDataSetObserver(DataSetObserver dataSetObserver) {
46 | wrapped.registerDataSetObserver(dataSetObserver);
47 | }
48 |
49 | @Override
50 | public void unregisterDataSetObserver(DataSetObserver dataSetObserver) {
51 | wrapped.unregisterDataSetObserver(dataSetObserver);
52 | }
53 |
54 | @Override
55 | public int getCount() {
56 | return wrapped.getCount();
57 | }
58 |
59 | @Override
60 | public Object getItem(int i) {
61 | return wrapped.getItem(i);
62 | }
63 |
64 | @Override
65 | public long getItemId(int i) {
66 | return wrapped.getItemId(i);
67 | }
68 |
69 | @Override
70 | public boolean hasStableIds() {
71 | return wrapped.hasStableIds();
72 | }
73 |
74 | @Override
75 | public View getView(int position, View view, ViewGroup viewGroup) {
76 | return wrapped.getView(position, view, viewGroup);
77 | }
78 |
79 | @Override
80 | public int getItemViewType(int i) {
81 | return wrapped.getItemViewType(i);
82 | }
83 |
84 | @Override
85 | public int getViewTypeCount() {
86 | return wrapped.getViewTypeCount();
87 | }
88 |
89 | @Override
90 | public boolean isEmpty() {
91 | return wrapped.isEmpty();
92 | }
93 |
94 | @Override
95 | public void notifyDataSetChanged() {
96 | if (wrapped instanceof BaseAdapter) {
97 | ((BaseAdapter)wrapped).notifyDataSetChanged();
98 | }
99 | }
100 |
101 | @Override
102 | public void notifyDataSetInvalidated() {
103 | if (wrapped instanceof BaseAdapter) {
104 | ((BaseAdapter)wrapped).notifyDataSetInvalidated();
105 | }
106 | }
107 |
108 | }
109 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/tjerkw/slideexpandable/sample/ExampleActivity.java:
--------------------------------------------------------------------------------
1 | package com.tjerkw.slideexpandable.sample;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.*;
7 | import com.tjerkw.slideexpandable.library.ActionSlideExpandableListView;
8 | import com.tjerkw.slideexpandable.library.SlideExpandableListAdapter;
9 |
10 | /**
11 | * This example shows a expandable listview
12 | * with a more button per list item which expands the expandable area.
13 | *
14 | * In the expandable area there are two buttons A and B which can be click.
15 | *
16 | * The events for these buttons are handled here in this Activity.
17 | *
18 | * @author tjerk
19 | * @date 6/13/12 7:33 AM
20 | */
21 | public class ExampleActivity extends Activity {
22 |
23 | @Override
24 | public void onCreate(Bundle savedData) {
25 |
26 | super.onCreate(savedData);
27 | // set the content view for this activity, check the content view xml file
28 | // to see how it refers to the ActionSlideExpandableListView view.
29 | this.setContentView(R.layout.single_expandable_list);
30 | // get a reference to the listview, needed in order
31 | // to call setItemActionListener on it
32 | ActionSlideExpandableListView list = (ActionSlideExpandableListView)this.findViewById(R.id.list);
33 |
34 | // fill the list with data
35 | list.setAdapter(buildDummyData());
36 |
37 | // listen for events in the two buttons for every list item.
38 | // the 'position' var will tell which list item is clicked
39 | list.setItemActionListener(new ActionSlideExpandableListView.OnActionClickListener() {
40 |
41 | @Override
42 | public void onClick(View listView, View buttonview, int position) {
43 |
44 | /**
45 | * Normally you would put a switch
46 | * statement here, and depending on
47 | * view.getId() you would perform a
48 | * different action.
49 | */
50 | String actionName = "";
51 | if(buttonview.getId()==R.id.buttonA) {
52 | actionName = "buttonA";
53 | } else {
54 | actionName = "ButtonB";
55 | }
56 | /**
57 | * For testing sake we just show a toast
58 | */
59 | Toast.makeText(
60 | ExampleActivity.this,
61 | "Clicked Action: "+actionName+" in list item "+position,
62 | Toast.LENGTH_SHORT
63 | ).show();
64 | }
65 |
66 | // note that we also add 1 or more ids to the setItemActionListener
67 | // this is needed in order for the listview to discover the buttons
68 | }, R.id.buttonA, R.id.buttonB);
69 | }
70 |
71 | /**
72 | * Builds dummy data for the test.
73 | * In a real app this would be an adapter
74 | * for your data. For example a CursorAdapter
75 | */
76 | public ListAdapter buildDummyData() {
77 | final int SIZE = 20;
78 | String[] values = new String[SIZE];
79 | for(int i=0;i(
83 | this,
84 | R.layout.expandable_list_item,
85 | R.id.text,
86 | values
87 | );
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/library/src/main/java/com/tjerkw/slideexpandable/library/SlideExpandableListView.java:
--------------------------------------------------------------------------------
1 | package com.tjerkw.slideexpandable.library;
2 |
3 | import android.os.Parcelable;
4 | import android.util.AttributeSet;
5 | import android.view.View;
6 | import android.widget.AdapterView;
7 | import android.widget.ListAdapter;
8 | import android.widget.ListView;
9 | import android.content.Context;
10 | import android.widget.WrapperListAdapter;
11 |
12 | /**
13 | * Simple subclass of listview which does nothing more than wrap
14 | * any ListAdapter in a SlideExpandalbeListAdapter
15 | */
16 | class SlideExpandableListView extends ListView {
17 | private SlideExpandableListAdapter adapter;
18 |
19 | public SlideExpandableListView(Context context) {
20 | super(context);
21 | }
22 |
23 | public SlideExpandableListView(Context context, AttributeSet attrs) {
24 | super(context, attrs);
25 | }
26 |
27 | public SlideExpandableListView(Context context, AttributeSet attrs, int defStyle) {
28 | super(context, attrs, defStyle);
29 | }
30 |
31 | /**
32 | * Collapses the currently open view.
33 | *
34 | * @return true if a view was collapsed, false if there was no open view.
35 | */
36 | public boolean collapse() {
37 | if(adapter!=null) {
38 | return adapter.collapseLastOpen();
39 | }
40 | return false;
41 | }
42 |
43 | public void setAdapter(ListAdapter adapter) {
44 | this.adapter = new SlideExpandableListAdapter(adapter);
45 | super.setAdapter(this.adapter);
46 | }
47 |
48 | public void setAdapter(ListAdapter adapter, int toggle_button_id, int expandable_view_id) {
49 | this.adapter = new SlideExpandableListAdapter(adapter, toggle_button_id, expandable_view_id);
50 | super.setAdapter(this.adapter);
51 | }
52 |
53 | /**
54 | * Registers a OnItemClickListener for this listview which will
55 | * expand the item by default. Any other OnItemClickListener will be overriden.
56 | *
57 | * To undo call setOnItemClickListener(null)
58 | *
59 | * Important: This method call setOnItemClickListener, so the value will be reset
60 | */
61 | public void enableExpandOnItemClick() {
62 | this.setOnItemClickListener(new OnItemClickListener() {
63 | @Override
64 | public void onItemClick(AdapterView> adapterView, View view, int i, long l) {
65 | if (adapter != null) {
66 | adapter.getExpandToggleButton(view).performClick();
67 | }
68 | }
69 | });
70 | }
71 |
72 |
73 | @Override
74 | public Parcelable onSaveInstanceState() {
75 | return adapter.onSaveInstanceState(super.onSaveInstanceState());
76 | }
77 |
78 | @Override
79 | public void onRestoreInstanceState(Parcelable state) {
80 | if(!(state instanceof AbstractSlideExpandableListAdapter.SavedState)) {
81 | super.onRestoreInstanceState(state);
82 | return;
83 | }
84 |
85 | AbstractSlideExpandableListAdapter.SavedState ss = (AbstractSlideExpandableListAdapter.SavedState)state;
86 | super.onRestoreInstanceState(ss.getSuperState());
87 |
88 | if (adapter != null) {
89 | adapter.onRestoreInstanceState(ss);
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SlideExpandableListView for Android
2 |
3 | 
4 |
5 | Not happy with the Android ExpandableListView android offers? Want something like the Spotify app. This library allows you to have custom listview in wich each list item has an area that will slide-out once the users clicks on a certain button.
6 |
7 | ## Features
8 |
9 | * Provides a better ExpandableListView usable for normal ListView's
10 | * Animates by default
11 | * Easy to use
12 |
13 | Repository at .
14 |
15 | ## Usage
16 |
17 | ### Layout
18 |
19 | Use a normal list view in your layout.
20 | You may also use a ListActivity or ListFragment
21 |
22 | ``` xml
23 |
27 | ```
28 |
29 | The list item view should have a toggle button (Button view), and a target view that will be expanded.
30 | By default the expandable view will be hidden. An when a user clicks the toggle button the
31 | expandalbe view will slide out and be visible.
32 |
33 | For example here below we have R.id.expandable_toggle_button Button view.
34 | And a R.id.expandable LinearLayout which will be expanded.
35 | Note that the expandable view does not have to be a LinearLayout,
36 | it can be any subclass of View.
37 |
38 | ``` xml
39 |
40 |
44 |
48 |
49 |
54 |
55 |
56 |
64 |
65 |
66 |
67 |
68 |
74 |
75 |
76 |
81 |
82 |
88 |
89 |
90 |
91 | ```
92 |
93 | ### Wrap your ListAdapter
94 |
95 | In order to provide the functionality you simply wrap your list adapter in a SlideExpandableListAdapter.
96 | The adapter gets the ids to the more button, and the expandable view as parameters. This allows the adapter
97 | to find those views.
98 |
99 | ``` java
100 | ListView list = ... your list view
101 | ListAdapter adapter = ... your list adapter
102 | // now simply wrap the adapter
103 | // and indicate the ids of your toggle button
104 | // and expandable view
105 | list.setAdapter(
106 | new SlideExpandableListAdapter(
107 | adapter,
108 | R.id.expandable_toggle_button,
109 | R.id.expandable
110 | )
111 | );
112 | ```
113 |
114 | ### Use the SlideExpandableListView or ActionSlideExpandableListView
115 |
116 | In order to simplify the usage of this library, you can also use the mentioned ListViews directly in your
117 | layout xml file. The view itself will make sure the ListAdapter is wrapped in a SlideExpandableListAdapter.
118 |
119 | See the sample app for usage information.
120 |
121 | ### Including In Your Project
122 |
123 | Add the library as a gradle dependency to your project.
124 |
125 | ## Pull Requests
126 |
127 | If you have any contributions I am gladly to review them and use them if they make sense.
128 |
129 | ## Changelog
130 |
131 | ### v1.1.0
132 |
133 | * Added ActionSlideExpandableListView for easier event listening, see the sample app
134 | * Updated the sample app to also contain event handling logic (Solved issue #3)
135 | * Solved the issue with random views being expanded, due to recycling of views was not properly handled
136 | * Solved more issues #1 #2
137 |
138 | ### v1.0.0
139 |
140 | * First release!
141 |
142 | ## Acknowledgments
143 |
144 | * [TjerkWolterink] (http://about.me/tjerkw), about me (https://github.com/tjerkw), my linked in (http://www.linkedin.com/in/tjerkwolterink)
145 | * [Udinic] (https://github.com/Udinic/SmallExamples/tree/master/ExpandAnimationExample), his blog (http://udinic.wordpress.com/2011/09/03/expanding-listview-items/) contains the initial idea
146 |
147 | ## License
148 |
149 | Licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html)
150 |
151 | [](http://githalytics.com/tjerkw/Android-SlideExpandableListView)
152 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/library/src/main/java/com/tjerkw/slideexpandable/library/AbstractSlideExpandableListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.tjerkw.slideexpandable.library;
2 |
3 | import java.util.BitSet;
4 | import android.graphics.Rect;
5 | import android.os.Parcel;
6 | import android.os.Parcelable;
7 | import android.util.SparseIntArray;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.view.animation.Animation;
11 | import android.view.animation.Animation.AnimationListener;
12 | import android.widget.LinearLayout;
13 | import android.widget.ListAdapter;
14 | import android.widget.ListView;
15 |
16 | /**
17 | * Wraps a ListAdapter to give it expandable list view functionality.
18 | * The main thing it does is add a listener to the getToggleButton
19 | * which expands the getExpandableView for each list item.
20 | *
21 | * @author tjerk
22 | * @date 6/9/12 4:41 PM
23 | */
24 | public abstract class AbstractSlideExpandableListAdapter extends WrapperListAdapterImpl {
25 | /**
26 | * Reference to the last expanded list item.
27 | * Since lists are recycled this might be null if
28 | * though there is an expanded list item
29 | */
30 | private View lastOpen = null;
31 | /**
32 | * The position of the last expanded list item.
33 | * If -1 there is no list item expanded.
34 | * Otherwise it points to the position of the last expanded list item
35 | */
36 | private int lastOpenPosition = -1;
37 |
38 | /**
39 | * Default Animation duration
40 | * Set animation duration with @see setAnimationDuration
41 | */
42 | private int animationDuration = 330;
43 |
44 | /**
45 | * A list of positions of all list items that are expanded.
46 | * Normally only one is expanded. But a mode to expand
47 | * multiple will be added soon.
48 | *
49 | * If an item onj position x is open, its bit is set
50 | */
51 | private BitSet openItems = new BitSet();
52 | /**
53 | * We remember, for each collapsable view its height.
54 | * So we dont need to recalculate.
55 | * The height is calculated just before the view is drawn.
56 | */
57 | private final SparseIntArray viewHeights = new SparseIntArray(10);
58 |
59 | /**
60 | * Will point to the ListView
61 | */
62 | private ViewGroup parent;
63 |
64 | public AbstractSlideExpandableListAdapter(ListAdapter wrapped) {
65 | super(wrapped);
66 | }
67 |
68 | private OnItemExpandCollapseListener expandCollapseListener;
69 |
70 | /**
71 | * Sets a listener which gets call on item expand or collapse
72 | *
73 | * @param listener
74 | * the listener which will be called when an item is expanded or
75 | * collapsed
76 | */
77 | public void setItemExpandCollapseListener(
78 | OnItemExpandCollapseListener listener) {
79 | expandCollapseListener = listener;
80 | }
81 |
82 | public void removeItemExpandCollapseListener() {
83 | expandCollapseListener = null;
84 | }
85 |
86 | /**
87 | * Interface for callback to be invoked whenever an item is expanded or
88 | * collapsed in the list view.
89 | */
90 | public interface OnItemExpandCollapseListener {
91 | /**
92 | * Called when an item is expanded.
93 | *
94 | * @param itemView
95 | * the view of the list item
96 | * @param position
97 | * the position in the list view
98 | */
99 | public void onExpand(View itemView, int position);
100 |
101 | /**
102 | * Called when an item is collapsed.
103 | *
104 | * @param itemView
105 | * the view of the list item
106 | * @param position
107 | * the position in the list view
108 | */
109 | public void onCollapse(View itemView, int position);
110 |
111 | }
112 |
113 | private void notifiyExpandCollapseListener(int type, View view, int position) {
114 | if (expandCollapseListener != null) {
115 | if (type == ExpandCollapseAnimation.EXPAND) {
116 | expandCollapseListener.onExpand(view, position);
117 | } else if (type == ExpandCollapseAnimation.COLLAPSE) {
118 | expandCollapseListener.onCollapse(view, position);
119 | }
120 | }
121 |
122 | }
123 |
124 |
125 | @Override
126 | public View getView(int position, View view, ViewGroup viewGroup) {
127 | this.parent = viewGroup;
128 | view = wrapped.getView(position, view, viewGroup);
129 | enableFor(view, position);
130 | return view;
131 | }
132 |
133 | /**
134 | * This method is used to get the Button view that should
135 | * expand or collapse the Expandable View.
136 | *
137 | * Normally it will be implemented as:
138 | *
141 | *
142 | * A listener will be attached to the button which will
143 | * either expand or collapse the expandable view
144 | *
145 | * @see #getExpandableView(View)
146 | * @param parent the list view item
147 | * @ensure return!=null
148 | * @return a child of parent which is a button
149 | */
150 | public abstract View getExpandToggleButton(View parent);
151 |
152 | /**
153 | * This method is used to get the view that will be hidden
154 | * initially and expands or collapse when the ExpandToggleButton
155 | * is pressed @see getExpandToggleButton
156 | *
157 | * Normally it will be implemented as:
158 | *