Skip to content

chenlin030922/ReSwipeCard

Repository files navigation

ReSwipeCard

This project is no longer maintained, feel free to pull request if you have some fixs.

plz start the project if u feel nice xD

version log

1.0.1 :fix some bugs

ReSwipeCard is based on CardSwipeLayout

中文说明

Introduction:

  • Solve the conflict between scroll and click

  • support for defining directions to slide

  • support for defining directions to slide out

  • support for defining durations to slide out

  • support for looping the card or not

  • support for defining the way to stack the cards

  • support for defining the numbers of the stacked card

  • support for sliding card automatically

below is the demo of this projec ,you could install the app-debug.apk to see on the mobile:

gif


How to use:

//don't use RecyclerView on your project
dependencies {
    compile ('lin.jerrylin0322.reswipecard:reswipecard:1.0.1')
}
//already use RecyclerView on your project
dependencies {
    compile ('lin.jerrylin0322.reswipecard:reswipecard:1.0.1') {
                exclude module:'recyclerview-v7' }
}

maven:

<dependency>
  <groupId>lin.jerrylin0322.reswipecard</groupId>
  <artifactId>reswipecard</artifactId>
  <version>1.0.1</version>
  <type>pom</type>
</dependency>

in Java:

 CardSetting setting=new CardSetting();
        setting.setSwipeListener(new OnSwipeCardListener<CardBean>() {
            @Override
            public void onSwiping(RecyclerView.ViewHolder viewHolder, float dx, float dy, int direction) {
                switch (direction) {
                    case ReItemTouchHelper.DOWN:
                        Log.e("aaa", "swiping direction=down");
                        break;
                    case ReItemTouchHelper.UP:
                        Log.e("aaa", "swiping direction=up");
                        break;
                    case ReItemTouchHelper.LEFT:
                        Log.e("aaa", "swiping direction=left");
                        break;
                    case ReItemTouchHelper.RIGHT:
                        Log.e("aaa", "swiping direction=right");
                        break;
                }
            }

            @Override
            public void onSwipedOut(RecyclerView.ViewHolder viewHolder, CardBean o, int direction) {
                switch (direction) {
                    case ReItemTouchHelper.DOWN:
                        Toast.makeText(NormalActivity.this, "swipe down out", Toast.LENGTH_SHORT).show();
                        break;
                    case ReItemTouchHelper.UP:
                        Toast.makeText(NormalActivity.this, "swipe up out ", Toast.LENGTH_SHORT).show();
                        break;
                    case ReItemTouchHelper.LEFT:
                        Toast.makeText(NormalActivity.this, "swipe left out", Toast.LENGTH_SHORT).show();
                        break;
                    case ReItemTouchHelper.RIGHT:
                        Toast.makeText(NormalActivity.this, "swipe right out", Toast.LENGTH_SHORT).show();
                        break;
                }
            }

            @Override
            public void onSwipedClear() {
                Toast.makeText(NormalActivity.this, "cards are consumed", Toast.LENGTH_SHORT).show();
            }
        });
        CardTouchHelperCallback helperCallback = new CardTouchHelperCallback(mRecyclerView, list,setting);
        mReItemTouchHelper = new ReItemTouchHelper(helperCallback);
        CardLayoutManager layoutManager = new CardLayoutManager(mReItemTouchHelper, setting);
        mRecyclerView.setLayoutManager(layoutManager);
        CardAdapter cardAdapter = new CardAdapter(list);
 		mRecyclerView.setAdapter(cardAdapter);

You need to use SwipeTouchLayout as the root node in your adapter's xml item:

<?xml version="1.0" encoding="utf-8"?>
<com.lin.cardlib.SwipeTouchLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                  xmlns:app="http://schemas.android.com/apk/res-auto"
                                  android:layout_width="wrap_content"
                                  android:layout_height="wrap_content"
                                  android:paddingBottom="30dp">

  ...

</com.lin.cardlib.SwipeTouchLayout>

CardSetting

All parameters are defined onCardSetting.

The direction for sliding:

public int getSwipeDirection() {
        return ReItemTouchHelper.LEFT | ReItemTouchHelper.RIGHT
                | ReItemTouchHelper.UP |ReItemTouchHelper.DOWN;
    }

If you don't need the left slide,just remove from the above,and the effect is like below:

gif

The direction for sliding out:

    public int couldSwipeOutDirection() {
        return ReItemTouchHelper.LEFT | ReItemTouchHelper.RIGHT
                | ReItemTouchHelper.UP |ReItemTouchHelper.DOWN;
    }

If you don't need the top slide out,just remove from the above,and the effect is like below:

gif

The way to stack the cards:

CardConfig.java
public int getStackDirection() {
        return  ReItemTouchHelper.DOWN;
    }

All ways to stack the cards:

Alt text

Whether needs to loop thr card

 public boolean isLoopCard() {
        return true;
    }

The example for not looping the card:

gif

Sliding out the card automatically:

//direction=ReItemTouchHelper.LEFT or ReItemTouchHelper.RIGHT .etc
mReItemTouchHelper.swipeManually(direction);

The degressive scale value for every card(first card is 1f,second card is 0.9f ...)

    public float getCardScale() {
        return DEFAULT_SCALE;
    }

The count for show cards:

  public int getShowCount() {
        return DEFAULT_SHOW_ITEM;
    }

Max rotate value when sliding card:

   public float getCardRotateDegree() {
        return DEFAULT_ROTATE_DEGREE;
    }

The offset value for every card(first card is 0,second card is DEFAULT_TRANSLATE_Y,third card is DEFAULT_TRANSLATE_Y*2 ...)

 public int getCardTranslateDistance() {
        return DEFAULT_TRANSLATE_Y;
    }

Need to open the haveware acceleration:

    public boolean enableHardWare() {
        return true;
    }

The duration for sliding out:

    public int getSwipeOutAnimDuration() {
        return 400;
    }

Decide the Distance for notifing the card to slided out,default is the RecyclerView's width'*0.3f:

    public float getSwipeThreshold() {
        return 0.3f;
    }

If you have any problem ,talk to me through Issues


License

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

About

a light lib for swipe the cards implemented by RecyclerView

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages