├── .gitignore
├── CardStack
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── wenchao
│ │ └── card_stack
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── wenchao
│ │ ├── animation
│ │ ├── AnimatorListenerAdapter.java
│ │ └── RelativeLayoutParamsEvaluator.java
│ │ └── cardstack
│ │ ├── CardAnimator.java
│ │ ├── CardStack.java
│ │ ├── CardUtils.java
│ │ ├── DefaultStackEventListener.java
│ │ └── DragGestureDetector.java
│ └── res
│ ├── drawable-hdpi
│ └── ic_launcher.png
│ ├── drawable-mdpi
│ └── ic_launcher.png
│ ├── drawable-xhdpi
│ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ └── ic_launcher.png
│ └── values
│ ├── attrs.xml
│ └── strings.xml
├── DemoApp
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── wxj
│ │ └── swipeablecardstack
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── wxj
│ │ └── swipeablecardstack
│ │ ├── CardsDataAdapter.java
│ │ └── MyActivity.java
│ └── res
│ ├── drawable-hdpi
│ └── ic_launcher.png
│ ├── drawable-mdpi
│ └── ic_launcher.png
│ ├── drawable-xhdpi
│ └── ic_launcher.png
│ ├── drawable-xxhdpi
│ └── ic_launcher.png
│ ├── layout
│ ├── activity_my.xml
│ └── card_content.xml
│ ├── menu
│ └── my.xml
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── License.md
├── README.md
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── pics
├── image.png
└── image2.png
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Eclipse
2 | .project
3 | .metadata
4 | tmp/**
5 | tmp/**/*
6 | *.tmp
7 | *.bak
8 | *~.nib
9 | .classpath
10 | .settings/
11 | .loadpath
12 | **/bin/*
13 | **/gen/*
14 | testData
15 | testCache
16 | server.config
17 |
18 | # Locally stored "Eclipse launch configurations"
19 | *.launch
20 |
21 | # Android
22 | # built application files
23 | *.apk
24 |
25 | # Local configuration file (sdk path, etc)
26 | local.properties
27 |
28 | # Other
29 | .DS_Store
30 |
31 | # Android Studio
32 | .idea
33 | *.iml
34 | *.ipr
35 | *.iws
36 | gen-external-apklibs
37 |
38 | # Gradle
39 | .gradle
40 | build
--------------------------------------------------------------------------------
/CardStack/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Log Files
26 | *.log
27 |
28 | # Android Studio Navigation editor temp files
29 | .navigation/
30 |
31 | # Android Studio
32 | .idea
33 | *.iml
34 | *.ipr
35 | *.iws
--------------------------------------------------------------------------------
/CardStack/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release'
3 |
4 | android {
5 | compileSdkVersion 23
6 | buildToolsVersion '23.0.2'
7 |
8 | defaultConfig {
9 | minSdkVersion 14
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | compileOptions {
15 | sourceCompatibility JavaVersion.VERSION_1_6
16 | targetCompatibility JavaVersion.VERSION_1_6
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | compile fileTree(dir: 'libs', include: ['*.jar'])
28 | compile 'com.android.support:appcompat-v7:23.1.1'
29 | }
30 |
31 | //./gradlew clean build bintrayUpload -PbintrayUser=BINTRAY_USERNAME -PbintrayKey=BINTRAY_KEY -PdryRun=false
32 | publish {
33 | userOrg = 'juanpablo'
34 | groupId = 'com.wenchao'
35 | artifactId = 'cardstack'
36 | version = '1.0.0'
37 | description = 'A tinder like swipeable card stack component'
38 | website = 'https://github.com/juanpabloprado/AndroidSwipeableCardStack'
39 | issueTracker = "https://github.com/wenchaojiang/AndroidSwipeableCardStack/issues"
40 | repository = "https://github.com/juanpabloprado/AndroidSwipeableCardStack.git"
41 | }
--------------------------------------------------------------------------------
/CardStack/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/CardStack/src/androidTest/java/com/wenchao/card_stack/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.wenchao.card_stack;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/CardStack/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/CardStack/src/main/java/com/wenchao/animation/AnimatorListenerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.wenchao.animation;
2 |
3 | import android.animation.Animator;
4 | import android.animation.Animator.AnimatorListener;
5 |
6 | public abstract class AnimatorListenerAdapter implements AnimatorListener {
7 | @Override
8 | public void onAnimationCancel(Animator arg0) {
9 |
10 | }
11 |
12 | @Override
13 | public void onAnimationEnd(Animator arg0) {
14 |
15 | }
16 |
17 | @Override
18 | public void onAnimationRepeat(Animator arg0) {
19 |
20 | }
21 |
22 | @Override
23 | public void onAnimationStart(Animator arg0) {
24 |
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/CardStack/src/main/java/com/wenchao/animation/RelativeLayoutParamsEvaluator.java:
--------------------------------------------------------------------------------
1 | package com.wenchao.animation;
2 |
3 | import android.animation.TypeEvaluator;
4 | import android.widget.RelativeLayout.LayoutParams
5 | ;
6 |
7 | import com.wenchao.cardstack.CardUtils;
8 |
9 | public class RelativeLayoutParamsEvaluator implements TypeEvaluator {
10 |
11 | @Override
12 | public LayoutParams evaluate(float fraction, LayoutParams start,
13 | LayoutParams end) {
14 |
15 | LayoutParams result = CardUtils.cloneParams(start);
16 | result.leftMargin += ((end.leftMargin-start.leftMargin)*fraction);
17 | result.rightMargin += ((end.rightMargin-start.rightMargin)*fraction);
18 | result.topMargin += ((end.topMargin-start.topMargin)*fraction);
19 | result.bottomMargin += ((end.bottomMargin-start.bottomMargin)*fraction);
20 | return result;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/CardStack/src/main/java/com/wenchao/cardstack/CardAnimator.java:
--------------------------------------------------------------------------------
1 | package com.wenchao.cardstack;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.Random;
6 |
7 | import com.wenchao.animation.RelativeLayoutParamsEvaluator;
8 |
9 | import android.animation.Animator;
10 | import android.animation.Animator.AnimatorListener;
11 | import android.animation.AnimatorListenerAdapter;
12 | import android.animation.AnimatorSet;
13 | import android.animation.ValueAnimator;
14 | import android.graphics.Color;
15 | import android.view.MotionEvent;
16 | import android.view.View;
17 | import android.view.ViewGroup;
18 | import android.widget.RelativeLayout;
19 | import android.widget.RelativeLayout.LayoutParams;
20 |
21 |
22 | import static com.wenchao.cardstack.CardUtils.*;
23 |
24 | public class CardAnimator{
25 | private static final String DEBUG_TAG = "CardAnimator";
26 | private static final int REMOTE_DISTANCE = 1000;
27 | private int mBackgroundColor;
28 | public ArrayList mCardCollection;
29 | private float mRotation;
30 | private HashMap mLayoutsMap;
31 | private RelativeLayout.LayoutParams[] mRemoteLayouts = new RelativeLayout.LayoutParams[4];
32 | private RelativeLayout.LayoutParams baseLayout;
33 | private int mStackMargin=20;
34 |
35 | public CardAnimator(ArrayList viewCollection, int backgroundColor){
36 | mCardCollection = viewCollection;
37 | mBackgroundColor = backgroundColor;
38 | setup();
39 |
40 | }
41 | private void setup(){
42 | mLayoutsMap = new HashMap();
43 |
44 | for(View v : mCardCollection){
45 | //setup basic layout
46 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) v.getLayoutParams();
47 | params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
48 | params.width = LayoutParams.MATCH_PARENT;
49 | params.height = LayoutParams.MATCH_PARENT;
50 |
51 | if(mBackgroundColor != -1) {
52 | v.setBackgroundColor(mBackgroundColor);
53 | }
54 |
55 | v.setLayoutParams(params);
56 | }
57 |
58 | baseLayout = (RelativeLayout.LayoutParams)mCardCollection.get(0).getLayoutParams();
59 | baseLayout = cloneParams(baseLayout);
60 |
61 | initLayout();
62 |
63 | for (View v : mCardCollection){
64 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) v.getLayoutParams();
65 | RelativeLayout.LayoutParams paramsCopy = cloneParams(params);
66 | mLayoutsMap.put(v, paramsCopy);
67 | }
68 |
69 | setupRemotes();
70 |
71 | }
72 |
73 | public void initLayout(){
74 | int size = mCardCollection.size();
75 | for(View v : mCardCollection){
76 | int index = mCardCollection.indexOf(v);
77 | if(index!=0){
78 | index-=1;
79 | }
80 | LayoutParams params = cloneParams(baseLayout);
81 | v.setLayoutParams(params);
82 |
83 | scale(v, -(size - index - 1) * 5);
84 | move(v, index * mStackMargin, 0);
85 | v.setRotation(0);
86 | }
87 | }
88 |
89 | private void setupRemotes(){
90 | View topView = getTopView();
91 | mRemoteLayouts[0] = getMoveParams(topView, REMOTE_DISTANCE, -REMOTE_DISTANCE);
92 | mRemoteLayouts[1] = getMoveParams(topView, REMOTE_DISTANCE, REMOTE_DISTANCE);
93 | mRemoteLayouts[2] = getMoveParams(topView, -REMOTE_DISTANCE, -REMOTE_DISTANCE);
94 | mRemoteLayouts[3] = getMoveParams(topView, -REMOTE_DISTANCE, REMOTE_DISTANCE);
95 |
96 | }
97 |
98 | private View getTopView(){
99 | return mCardCollection.get(mCardCollection.size()-1);
100 | }
101 |
102 | private void moveToBack(View child)
103 | {
104 | final ViewGroup parent = (ViewGroup)child.getParent();
105 | if (null != parent) {
106 | parent.removeView(child);
107 | parent.addView(child, 0);
108 | }
109 | }
110 |
111 | private void reorder(){
112 | View temp = getTopView();
113 | //RelativeLayout.LayoutParams tempLp = mLayoutsMap.get(mCardCollection.get(0));
114 | //mLayoutsMap.put(temp,tempLp);
115 | moveToBack(temp);
116 |
117 | for(int i=(mCardCollection.size()-1); i>0; i--){
118 | //View next = mCardCollection.get(i);
119 | //RelativeLayout.LayoutParams lp = mLayoutsMap.get(next);
120 | //mLayoutsMap.remove(next);
121 | View current = mCardCollection.get(i-1);
122 | //current replace next
123 | mCardCollection.set(i,current);
124 | //mLayoutsMap.put(current,lp);
125 |
126 | }
127 | mCardCollection.set(0,temp);
128 |
129 | temp = getTopView();
130 |
131 | }
132 |
133 | public void discard(int direction,final AnimatorListener al){
134 | AnimatorSet as = new AnimatorSet();
135 | ArrayList aCollection = new ArrayList();
136 |
137 |
138 | final View topView = getTopView();
139 | RelativeLayout.LayoutParams topParams = (RelativeLayout.LayoutParams) topView.getLayoutParams();
140 | RelativeLayout.LayoutParams layout = cloneParams(topParams);
141 | ValueAnimator discardAnim = ValueAnimator.ofObject(new RelativeLayoutParamsEvaluator(),layout, mRemoteLayouts[direction]);
142 |
143 | discardAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
144 | @Override
145 | public void onAnimationUpdate(ValueAnimator value) {
146 | topView.setLayoutParams((LayoutParams)value.getAnimatedValue());
147 | }
148 | });
149 |
150 | discardAnim.setDuration(250);
151 | aCollection.add(discardAnim);
152 |
153 | for(int i = 0; i< mCardCollection.size();i++){
154 | final View v = mCardCollection.get(i);
155 |
156 | if(v==topView) continue;
157 | final View nv = mCardCollection.get(i+1);
158 | RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) v.getLayoutParams();
159 | RelativeLayout.LayoutParams endLayout = cloneParams(layoutParams);
160 | ValueAnimator layoutAnim = ValueAnimator.ofObject(new RelativeLayoutParamsEvaluator(),endLayout,mLayoutsMap.get(nv));
161 | layoutAnim.setDuration(250);
162 | layoutAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
163 | @Override
164 | public void onAnimationUpdate(ValueAnimator value) {
165 | v.setLayoutParams((LayoutParams)value.getAnimatedValue());
166 | }
167 | });
168 | aCollection.add(layoutAnim);
169 | }
170 |
171 | as.addListener(new AnimatorListenerAdapter(){
172 |
173 |
174 | @Override
175 | public void onAnimationEnd(Animator animation) {
176 | reorder();
177 | if(al != null){
178 | al.onAnimationEnd(animation);
179 | }
180 | mLayoutsMap = new HashMap();
181 | for (View v : mCardCollection){
182 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) v.getLayoutParams();
183 | RelativeLayout.LayoutParams paramsCopy = cloneParams(params);
184 | mLayoutsMap.put(v, paramsCopy);
185 | }
186 |
187 | }
188 |
189 | });
190 |
191 |
192 | as.playTogether(aCollection);
193 | as.start();
194 |
195 |
196 | }
197 |
198 | public void reverse(MotionEvent e1, MotionEvent e2){
199 | final View topView = getTopView();
200 | ValueAnimator rotationAnim = ValueAnimator.ofFloat(mRotation, 0f);
201 | rotationAnim.setDuration(250);
202 | rotationAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
203 | @Override
204 | public void onAnimationUpdate(ValueAnimator v) {
205 | topView.setRotation(((Float) (v.getAnimatedValue())).floatValue());
206 | }
207 | });
208 |
209 | rotationAnim.start();
210 |
211 | for(final View v : mCardCollection){
212 | RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) v.getLayoutParams();
213 | RelativeLayout.LayoutParams endLayout = cloneParams(layoutParams);
214 | ValueAnimator layoutAnim = ValueAnimator.ofObject(new RelativeLayoutParamsEvaluator(),endLayout,mLayoutsMap.get(v));
215 | layoutAnim.setDuration(250);
216 | layoutAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
217 | @Override
218 | public void onAnimationUpdate(ValueAnimator value) {
219 | v.setLayoutParams((LayoutParams)value.getAnimatedValue());
220 | }
221 | });
222 | layoutAnim.start();
223 | }
224 |
225 | }
226 |
227 | public void drag(MotionEvent e1, MotionEvent e2, float distanceX,
228 | float distanceY){
229 |
230 | View topView = getTopView();
231 |
232 | float rotation_coefficient = 20f;
233 |
234 | RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) topView.getLayoutParams();
235 | RelativeLayout.LayoutParams topViewLayouts = mLayoutsMap.get(topView);
236 | int x_diff = (int)((e2.getRawX()-e1.getRawX()));
237 | int y_diff = (int)((e2.getRawY()-e1.getRawY()));
238 |
239 | layoutParams.leftMargin = topViewLayouts.leftMargin+ x_diff;
240 | layoutParams.rightMargin = topViewLayouts.rightMargin - x_diff;
241 | layoutParams.topMargin = topViewLayouts.topMargin + y_diff;
242 | layoutParams.bottomMargin = topViewLayouts.bottomMargin - y_diff;
243 |
244 | mRotation = (x_diff/rotation_coefficient);
245 | topView.setRotation(mRotation);
246 | topView.setLayoutParams(layoutParams);
247 |
248 | //animate secondary views.
249 | for(View v : mCardCollection){
250 | int index = mCardCollection.indexOf(v);
251 | if(v!=getTopView() && index != 0){
252 | LayoutParams l = scaleFrom(v, mLayoutsMap.get(v), (int) (Math.abs(x_diff) * 0.05));
253 | moveFrom(v, l, 0, (int) (Math.abs(x_diff) * 0.1));
254 | }
255 | }
256 | }
257 |
258 | public void setStackMargin(int margin) {
259 | mStackMargin = margin;
260 | initLayout();
261 | }
262 |
263 |
264 |
265 | }
266 |
--------------------------------------------------------------------------------
/CardStack/src/main/java/com/wenchao/cardstack/CardStack.java:
--------------------------------------------------------------------------------
1 | package com.wenchao.cardstack;
2 |
3 | import android.content.res.TypedArray;
4 | import java.util.ArrayList;
5 | import java.util.Queue;
6 |
7 | import android.animation.Animator;
8 | import android.animation.AnimatorListenerAdapter;
9 | import android.content.Context;
10 | import android.util.AttributeSet;
11 | import android.view.LayoutInflater;
12 | import android.view.MotionEvent;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.widget.ArrayAdapter;
16 | import android.widget.FrameLayout;
17 | import android.widget.RelativeLayout;
18 | import android.database.DataSetObserver;
19 |
20 |
21 | public class CardStack extends RelativeLayout {
22 | private int mColor = -1;
23 | private int mIndex = 0;
24 | private int mNumVisible = 4;
25 | private ArrayAdapter> mAdapter;
26 | private OnTouchListener mOnTouchListener;
27 | private CardAnimator mCardAnimator;
28 | //private Queue mIdleStack = new Queue;
29 |
30 |
31 |
32 | private CardEventListener mEventListener = new DefaultStackEventListener(300);
33 | private int mContentResource = 0;
34 |
35 |
36 | public interface CardEventListener{
37 | //section
38 | // 0 | 1
39 | //--------
40 | // 2 | 3
41 | // swipe distance, most likely be used with height and width of a view ;
42 |
43 | boolean swipeEnd(int section,float distance);
44 | boolean swipeStart(int section,float distance);
45 | boolean swipeContinue(int section, float distanceX,float distanceY );
46 | void discarded(int mIndex, int direction);
47 | void topCardTapped();
48 | }
49 |
50 | public void discardTop(final int direction){
51 | mCardAnimator.discard(direction, new AnimatorListenerAdapter() {
52 | @Override
53 | public void onAnimationEnd(Animator arg0) {
54 | mCardAnimator.initLayout();
55 | mIndex++;
56 | mEventListener.discarded(mIndex, direction);
57 |
58 | //mIndex = mIndex%mAdapter.getCount();
59 | loadLast();
60 |
61 | viewCollection.get(0).setOnTouchListener(null);
62 | viewCollection.get(viewCollection.size() - 1).setOnTouchListener(mOnTouchListener);
63 | }
64 | });
65 | }
66 |
67 | public int getCurrIndex(){
68 | //sync?
69 | return mIndex;
70 | }
71 |
72 | //only necessary when I need the attrs from xml, this will be used when inflating layout
73 | public CardStack(Context context, AttributeSet attrs) {
74 | super(context, attrs);
75 |
76 | if (attrs != null) {
77 | TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.CardStack);
78 | mColor = array.getColor(R.styleable.CardStack_backgroundColor, mColor);
79 | array.recycle();
80 | }
81 |
82 | //String sMyValue = attrs.getAttributeValue( "http://schemas.android.com/apk/res/android", "padding" );
83 | //get attrs assign minVisiableNum
84 | for(int i = 0; i viewCollection = new ArrayList();
221 | public CardStack(Context context) {
222 | super(context);
223 | }
224 |
225 | public void setAdapter(final ArrayAdapter> adapter){
226 | if(mAdapter != null){
227 | mAdapter.unregisterDataSetObserver(mOb);
228 | }
229 | mAdapter = adapter;
230 | adapter.registerDataSetObserver(mOb);
231 |
232 | loadData();
233 | }
234 |
235 | public ArrayAdapter getAdapter() {
236 | return mAdapter;
237 | }
238 |
239 | private void loadData(){
240 | for(int i=mNumVisible-1 ; i>=0 ; i--) {
241 | ViewGroup parent = (ViewGroup) viewCollection.get(i);
242 | int index = (mIndex + mNumVisible - 1) - i;
243 | if (index > mAdapter.getCount() - 1) {
244 | parent.setVisibility(View.GONE);
245 | }else{
246 | View child = mAdapter.getView(index, getContentView(), this);
247 | parent.addView(child);
248 | parent.setVisibility(View.VISIBLE);
249 | }
250 | }
251 | }
252 |
253 | private View getContentView(){
254 | View contentView = null;
255 | if(mContentResource != 0) {
256 | LayoutInflater lf = LayoutInflater.from(getContext());
257 | contentView = lf.inflate(mContentResource,null);
258 | }
259 | return contentView;
260 |
261 | }
262 |
263 | private void loadLast(){
264 | ViewGroup parent = (ViewGroup)viewCollection.get(0);
265 |
266 | int lastIndex = (mNumVisible - 1)+ mIndex;
267 | if(lastIndex > mAdapter.getCount() -1 ){
268 | parent.setVisibility(View.GONE);
269 | return;
270 | }
271 |
272 | View child = mAdapter.getView( lastIndex, getContentView(), parent);
273 | parent.removeAllViews();
274 | parent.addView(child);
275 | }
276 |
277 | public int getStackSize() {
278 | return mNumVisible;
279 | }
280 | }
281 |
--------------------------------------------------------------------------------
/CardStack/src/main/java/com/wenchao/cardstack/CardUtils.java:
--------------------------------------------------------------------------------
1 | package com.wenchao.cardstack;
2 |
3 | import android.util.Log;
4 | import android.view.View;
5 | import android.widget.RelativeLayout;
6 | import android.widget.RelativeLayout.LayoutParams;
7 |
8 | public class CardUtils {
9 | final static int DIRECTION_TOP_LEFT = 0;
10 | final static int DIRECTION_TOP_RIGHT = 1;
11 | final static int DIRECTION_BOTTOM_LEFT = 2;
12 | final static int DIRECTION_BOTTOM_RIGHT = 3;
13 |
14 | public static void scale(View v, int pixel){
15 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)v.getLayoutParams();
16 | params.leftMargin -= pixel;
17 | params.rightMargin -= pixel;
18 | params.topMargin -= pixel;
19 | params.bottomMargin -= pixel;
20 | v.setLayoutParams(params);
21 | }
22 |
23 | public static LayoutParams getMoveParams(View v, int upDown,int leftRight){
24 | RelativeLayout.LayoutParams original = (RelativeLayout.LayoutParams)v.getLayoutParams();
25 | //RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(original);
26 | RelativeLayout.LayoutParams params = cloneParams(original);
27 | params.leftMargin += leftRight;
28 | params.rightMargin -= leftRight;
29 | params.topMargin -= upDown;
30 | params.bottomMargin += upDown;
31 | return params;
32 | }
33 |
34 | public static void move(View v, int upDown,int leftRight){
35 | RelativeLayout.LayoutParams params = getMoveParams(v,upDown,leftRight);
36 | v.setLayoutParams(params);
37 | }
38 |
39 | public static LayoutParams scaleFrom(View v, LayoutParams params, int pixel) {
40 | Log.d("pixel", "onScroll: " + pixel);
41 | params = cloneParams(params);
42 | params.leftMargin -= pixel;
43 | params.rightMargin -= pixel;
44 | params.topMargin -= pixel;
45 | params.bottomMargin -= pixel;
46 | Log.d("pixel", "onScroll: " + pixel);
47 | v.setLayoutParams(params);
48 |
49 | return params;
50 | }
51 |
52 | public static LayoutParams moveFrom(View v, LayoutParams params, int leftRight, int upDown) {
53 | params = cloneParams(params);
54 | params.leftMargin += leftRight;
55 | params.rightMargin -= leftRight;
56 | params.topMargin -= upDown;
57 | params.bottomMargin += upDown;
58 | v.setLayoutParams(params);
59 |
60 | return params;
61 | }
62 |
63 | //a copy method for RelativeLayout.LayoutParams for backward compartibility
64 | public static RelativeLayout.LayoutParams cloneParams(RelativeLayout.LayoutParams params){
65 | RelativeLayout.LayoutParams copy = new RelativeLayout.LayoutParams(params.width,params.height);
66 | copy.leftMargin = params.leftMargin;
67 | copy.topMargin = params.topMargin;
68 | copy.rightMargin = params.rightMargin;
69 | copy.bottomMargin = params.bottomMargin;
70 | int[] rules = params.getRules();
71 | for (int i = 0 ; i< rules.length; i++ ){
72 | copy.addRule(i,rules[i]);
73 | }
74 | //copy.setMarginStart(params.getMarginStart());
75 | //copy.setMarginEnd(params.getMarginEnd());
76 |
77 | return copy;
78 | }
79 |
80 | public static float distance(float x1, float y1, float x2, float y2) {
81 |
82 | return (float) Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
83 | }
84 |
85 | public static int direction(float x1, float y1, float x2, float y2) {
86 | if(x2>x1){//RIGHT
87 | if(y2>y1){//BOTTOM
88 | return DIRECTION_BOTTOM_RIGHT;
89 | }else{//TOP
90 | return DIRECTION_TOP_RIGHT;
91 | }
92 | }else{//LEFT
93 | if(y2>y1){//BOTTOM
94 | return DIRECTION_BOTTOM_LEFT;
95 | }else{//TOP
96 | return DIRECTION_TOP_LEFT;
97 | }
98 | }
99 | }
100 |
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/CardStack/src/main/java/com/wenchao/cardstack/DefaultStackEventListener.java:
--------------------------------------------------------------------------------
1 | package com.wenchao.cardstack;
2 |
3 | public class DefaultStackEventListener implements CardStack.CardEventListener {
4 |
5 | private float mThreshold;
6 |
7 | public DefaultStackEventListener(int i) {
8 | mThreshold = i;
9 | }
10 |
11 | @Override
12 | public boolean swipeEnd(int section, float distance) {
13 | return distance > mThreshold;
14 | }
15 |
16 | @Override
17 | public boolean swipeStart(int section, float distance) {
18 |
19 | return false;
20 | }
21 |
22 | @Override
23 | public boolean swipeContinue(int section, float distanceX, float distanceY) {
24 | return false;
25 | }
26 |
27 | @Override
28 | public void discarded(int mIndex,int direction) {
29 |
30 | }
31 |
32 | @Override
33 | public void topCardTapped() {
34 |
35 | }
36 |
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/CardStack/src/main/java/com/wenchao/cardstack/DragGestureDetector.java:
--------------------------------------------------------------------------------
1 | package com.wenchao.cardstack;
2 |
3 | import android.content.Context;
4 | import android.support.v4.view.GestureDetectorCompat;
5 | import android.support.v4.view.MotionEventCompat;
6 | import android.util.Log;
7 | import android.view.GestureDetector;
8 | import android.view.MotionEvent;
9 |
10 |
11 | //detect both tap and drag
12 | public class DragGestureDetector {
13 | public static String DEBUG_TAG = "DragGestureDetector";
14 | private GestureDetectorCompat mGestureDetector;
15 | private DragListener mListener;
16 | private boolean mStarted = false;
17 | private MotionEvent mOriginalEvent;
18 | public interface DragListener {
19 | boolean onDragStart(MotionEvent e1, MotionEvent e2, float distanceX,
20 | float distanceY);
21 | boolean onDragContinue(MotionEvent e1, MotionEvent e2, float distanceX,
22 | float distanceY);
23 | boolean onDragEnd(MotionEvent e1, MotionEvent e2);
24 |
25 | boolean onTapUp();
26 | }
27 |
28 | public DragGestureDetector(Context context, DragListener myDragListener){
29 | mGestureDetector = new GestureDetectorCompat(context,new MyGestureListener());
30 | mListener = myDragListener;
31 | }
32 |
33 | public void onTouchEvent(MotionEvent event){
34 | mGestureDetector.onTouchEvent(event);
35 | int action = MotionEventCompat.getActionMasked(event);
36 | switch(action) {
37 | case (MotionEvent.ACTION_UP) :
38 | Log.d(DEBUG_TAG,"Action was UP");
39 | if(mStarted) {
40 | mListener.onDragEnd(mOriginalEvent, event);
41 | }
42 | mStarted = false;
43 | case (MotionEvent.ACTION_DOWN) :
44 | //need to set this, quick tap will not generate drap event, so the
45 | //originalEvent may be null for case action_up
46 | //which lead to null pointer
47 | mOriginalEvent = event;
48 | }
49 | }
50 |
51 | class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
52 | public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
53 | float distanceY) {
54 | if(mListener == null) return true;
55 | if(!mStarted){
56 | mListener.onDragStart(e1,e2,distanceX,distanceY);
57 | mStarted = true;
58 | }
59 | else{
60 | mListener.onDragContinue(e1,e2,distanceX,distanceY);
61 | }
62 | mOriginalEvent = e1;
63 | return true;
64 | }
65 |
66 | @Override
67 | public boolean onSingleTapUp(MotionEvent e) {
68 |
69 | return mListener.onTapUp();
70 | }
71 | }
72 |
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/CardStack/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codemaster730/AndroidSwipeableCardStack/54b3df6143917690501bc491b37ad31518115277/CardStack/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CardStack/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codemaster730/AndroidSwipeableCardStack/54b3df6143917690501bc491b37ad31518115277/CardStack/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CardStack/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codemaster730/AndroidSwipeableCardStack/54b3df6143917690501bc491b37ad31518115277/CardStack/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CardStack/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codemaster730/AndroidSwipeableCardStack/54b3df6143917690501bc491b37ad31518115277/CardStack/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/CardStack/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/CardStack/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SwipeableCardStack
3 |
4 |
--------------------------------------------------------------------------------
/DemoApp/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Log Files
26 | *.log
27 |
28 | # Android Studio Navigation editor temp files
29 | .navigation/
30 |
31 | # Android Studio
32 | .idea
33 | *.iml
34 | *.ipr
35 | *.iws
--------------------------------------------------------------------------------
/DemoApp/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion '23.0.2'
6 |
7 | defaultConfig {
8 | applicationId "wxj.swipeablecardstack"
9 | minSdkVersion 19
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | repositories {
23 | flatDir {
24 | dirs 'libs'
25 | }
26 | }
27 |
28 |
29 | dependencies {
30 | compile fileTree(dir: 'libs', include: ['*.jar'])
31 | //compile(name:'android-card-stack-0.1.0', ext:'aar')
32 | //http://stackoverflow.com/questions/21170395/how-to-include-a-library-module-dependency-in-an-android-studio-project
33 | compile project(":CardStack")
34 | compile 'com.android.support:appcompat-v7:23.1.1'
35 | compile "com.android.support:cardview-v7:23.1.1"
36 | }
37 |
--------------------------------------------------------------------------------
/DemoApp/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Applications/Android Studio.app/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/DemoApp/src/androidTest/java/wxj/swipeablecardstack/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package wxj.swipeablecardstack;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/DemoApp/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/DemoApp/src/main/java/wxj/swipeablecardstack/CardsDataAdapter.java:
--------------------------------------------------------------------------------
1 | package wxj.swipeablecardstack;
2 |
3 | import android.content.Context;
4 |
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.ArrayAdapter;
8 | import android.widget.ImageView;
9 | import android.widget.TextView;
10 |
11 | public class CardsDataAdapter extends ArrayAdapter {
12 |
13 | public CardsDataAdapter(Context context) {
14 | super(context, R.layout.card_content);
15 | }
16 |
17 | @Override
18 | public View getView(int position, final View contentView, ViewGroup parent){
19 | TextView v = (TextView)(contentView.findViewById(R.id.content));
20 | v.setText(getItem(position));
21 | return contentView;
22 | }
23 |
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/DemoApp/src/main/java/wxj/swipeablecardstack/MyActivity.java:
--------------------------------------------------------------------------------
1 | package wxj.swipeablecardstack;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 |
9 | import com.wenchao.cardstack.CardStack;
10 |
11 |
12 | public class MyActivity extends Activity {
13 | private CardStack mCardStack;
14 | private CardsDataAdapter mCardAdapter;
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_my);
20 |
21 | mCardStack = (CardStack)findViewById(R.id.container);
22 |
23 | mCardStack.setContentResource(R.layout.card_content);
24 | mCardStack.setStackMargin(20);
25 |
26 | mCardAdapter = new CardsDataAdapter(getApplicationContext());
27 | mCardAdapter.add("test1");
28 | mCardAdapter.add("test2");
29 | mCardAdapter.add("test3");
30 | mCardAdapter.add("test4");
31 | mCardAdapter.add("test5");
32 |
33 | mCardStack.setAdapter(mCardAdapter);
34 |
35 | if(mCardStack.getAdapter() != null) {
36 | Log.i("MyActivity", "Card Stack size: " + mCardStack.getAdapter().getCount());
37 | }
38 | }
39 |
40 |
41 | @Override
42 | public boolean onCreateOptionsMenu(Menu menu) {
43 | // Inflate the menu; this adds items to the action bar if it is present.
44 | getMenuInflater().inflate(R.menu.my, menu);
45 | return true;
46 | }
47 |
48 | @Override
49 | public boolean onOptionsItemSelected(MenuItem item) {
50 | // Handle action bar item clicks here. The action bar will
51 | // automatically handle clicks on the Home/Up button, so long
52 | // as you specify a parent activity in AndroidManifest.xml.
53 | int id = item.getItemId();
54 | if (id == R.id.action_settings) {
55 | return true;
56 | }
57 | return super.onOptionsItemSelected(item);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/DemoApp/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codemaster730/AndroidSwipeableCardStack/54b3df6143917690501bc491b37ad31518115277/DemoApp/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/DemoApp/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codemaster730/AndroidSwipeableCardStack/54b3df6143917690501bc491b37ad31518115277/DemoApp/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/DemoApp/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codemaster730/AndroidSwipeableCardStack/54b3df6143917690501bc491b37ad31518115277/DemoApp/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/DemoApp/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codemaster730/AndroidSwipeableCardStack/54b3df6143917690501bc491b37ad31518115277/DemoApp/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/DemoApp/src/main/res/layout/activity_my.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/DemoApp/src/main/res/layout/card_content.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/DemoApp/src/main/res/menu/my.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/DemoApp/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/DemoApp/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/DemoApp/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | SwipeableCardStack
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/DemoApp/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/License.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 wenchao jiang
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | AndroidSwipeableCardStack
2 | =========================
3 | [](https://android-arsenal.com/details/1/2724)
4 |
5 |
6 | Change log:
7 | Now it is compatible with api level 14
8 | Investigating compatibility with api level 13
9 |
10 |
11 |
12 | 
13 |
14 |
15 |
16 | A tinder like swipeable card stack component. Provide "swipe to like" effects. Easy to customize card views.
17 |
18 |
19 | See youtube demo : https://www.youtube.com/watch?v=YsMnLJeouf8&feature=youtu.be
20 | A Demo App is also included in the source.
21 |
22 |
23 | Installation
24 | ---
25 | Use jitpack
26 | ```groovy
27 | repositories {
28 | maven { url "https://jitpack.io" }
29 | }
30 |
31 | dependencies {
32 | compile 'com.github.wenchaojiang:AndroidSwipeableCardStack:0.1.4'
33 | }
34 | ```
35 | OR manually
36 |
37 | 1. Download released .aar file
38 | [Download current release] (https://github.com/wenchaojiang/AndroidSwipeableCardStack/releases/)
39 |
40 | 2. put it into your project lib dir, "libs" for example.
41 |
42 | 3. put following lines to your gradle.build file
43 | ```groovy
44 | repositories {
45 | flatDir {
46 | dirs 'libs'
47 | }
48 | }
49 |
50 | dependencies {
51 | compile(name:'android-card-stack-0.1.0', ext:'aar')
52 | }
53 | ```
54 |
55 | Configuration
56 | -----
57 |
58 |
59 | Put CardStack in your layout file
60 |
61 | ```xml
62 |
70 | ```
71 |
72 | Create your card view layout file.
73 |
74 | Example: card_layout.xml, contain only a TextView
75 | ```xml
76 |
77 |
80 |
85 |
86 |
87 | ```
88 |
89 | Implement your own adapter for the card stack. The CardStack will accept ArrayAdapter.
90 | The Following example extends a simple ArrayAdapter, overriding ```getView()``` to supply your customized card layout
91 |
92 | ```java
93 | public class CardsDataAdapter extends ArrayAdapter {
94 |
95 | @Override
96 | public View getView(int position, final View contentView, ViewGroup parent){
97 | //supply the layout for your card
98 | TextView v = (TextView)(contentView.findViewById(R.id.content));
99 | v.setText(getItem(position));
100 | return contentView;
101 | }
102 |
103 | }
104 | ```
105 | Get the CardStack instance in your activity
106 |
107 | ```java
108 | protected void onCreate(Bundle savedInstanceState) {
109 | super.onCreate(savedInstanceState);
110 | setContentView(R.layout.activity_my);
111 |
112 | mCardStack = (CardStack)findViewById(R.id.container);
113 |
114 | mCardStack.setContentResource(R.layout.card_content);
115 | mCardStack.setStackMargin(20);
116 |
117 | }
118 | ```
119 |
120 | Finally, set the adapter
121 |
122 |
123 | ```java
124 | mCardAdapter = new CardsDataAdapter(getApplicationContext(),0);
125 | mCardAdapter.add("test1");
126 | mCardAdapter.add("test2");
127 | mCardAdapter.add("test3");
128 | mCardAdapter.add("test4");
129 | mCardAdapter.add("test5");
130 |
131 | mCardStack.setAdapter(mCardAdapter);
132 | ```
133 |
134 |
135 | Listening to card stack event
136 | ----
137 | implement CardStack.CardEventListener, and set it as listener ```mCardStack.setListener(yourListener); ```
138 |
139 | ```java
140 | Class YourListener extends CardStack.CardEventListener{
141 | //implement card event interface
142 | @Override
143 | public boolean swipeEnd(int direction, float distance) {
144 | //if "return true" the dismiss animation will be triggered
145 | //if false, the card will move back to stack
146 | //distance is finger swipe distance in dp
147 |
148 | //the direction indicate swipe direction
149 | //there are four directions
150 | // 0 | 1
151 | // ----------
152 | // 2 | 3
153 |
154 | return (distance>300)? true : false;
155 | }
156 |
157 | @Override
158 | public boolean swipeStart(int direction, float distance) {
159 |
160 | return true;
161 | }
162 |
163 | @Override
164 | public boolean swipeContinue(int direction, float distanceX, float distanceY) {
165 |
166 | return true;
167 | }
168 |
169 | @Override
170 | public void discarded(int id, int direction) {
171 | //this callback invoked when dismiss animation is finished.
172 | }
173 |
174 | @Override
175 | public void topCardTapped() {
176 | //this callback invoked when a top card is tapped by user.
177 | }
178 | }
179 | ```
180 |
181 |
182 | TODO
183 | ----
184 |
185 | 1. deploy to maven central
186 | 2. compatibility with api level 13
187 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.5.0'
9 | classpath 'com.novoda:bintray-release:0.3.4'
10 | }
11 | }
12 |
13 | allprojects {
14 | repositories {
15 | jcenter()
16 | }
17 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Settings specified in this file will override any Gradle settings
5 | # configured through the IDE.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codemaster730/AndroidSwipeableCardStack/54b3df6143917690501bc491b37ad31518115277/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Oct 22 08:45:38 BST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/pics/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codemaster730/AndroidSwipeableCardStack/54b3df6143917690501bc491b37ad31518115277/pics/image.png
--------------------------------------------------------------------------------
/pics/image2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codemaster730/AndroidSwipeableCardStack/54b3df6143917690501bc491b37ad31518115277/pics/image2.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':DemoApp', ':CardStack'
2 |
--------------------------------------------------------------------------------