AndroidSwipeableCardStack


Source link: https://github.com/wenchaojiang/AndroidSwipeableCardStack

AndroidSwipeableCardStack

Change log:

  • provide option to infinitly swipe in a loop
  • card rotation setting
  • card gravity setting
  • undo animation

Thanks for contributions from: https://github.com/raee https://github.com/rebus007

A tinder like swipeable card stack component. Provide "swipe to like" effects. Easy to customize card views.

See youtube demo : https://www.youtube.com/watch?v=YsMnLJeouf8&feature=youtu.be A Demo App is also included in the source.

Installation

Use jitpack

repositories {

 maven {
 url "https://jitpack.io" 
}
 
}
  dependencies {

 compile 'com.github.wenchaojiang:AndroidSwipeableCardStack:0.*.*' 
}

OR manually

  1. Download released .aar file [Download current release] ( https://github.com/wenchaojiang/AndroidSwipeableCardStack/releases/)

  2. put it into your project lib dir, "libs" for example.

  3. put following lines to your gradle.build file

repositories {

  flatDir {

dirs 'libs'
  
}
 
}
  dependencies {

  compile(name:'android-card-stack-0.*.*', ext:'aar') 
}

Configuration

Put CardStack in your layout file

<com.wenchao.cardstack.CardStack

android:id="@+id/container"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:clipChildren="false"

android:clipToPadding="false"

android:gravity="center"

android:padding="10dp"

app:card_enable_loop="true"

app:card_enable_rotation="true"

app:card_gravity="top"

app:card_margin="10dp"

app:card_stack_size="4"/>

Create your card view layout file.

Example: card_layout.xml, contain only a TextView

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="match_parent"
  android:layout_height="match_parent">
  <TextView

android:id="@+id/content"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
  />  </LinearLayout>

Implement your own adapter for the card stack. The CardStack will accept ArrayAdapter. The Following example extends a simple ArrayAdapter, overriding getView() to supply your customized card layout

public class CardsDataAdapter extends ArrayAdapter<String> {

@Override
  public View getView(int position, final View contentView, ViewGroup parent){

//supply the layout for your card

TextView v = (TextView)(contentView.findViewById(R.id.content));

v.setText(getItem(position));

return contentView;
  
}
  
}

Get the CardStack instance in your activity

  protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_my);

 mCardStack = (CardStack)findViewById(R.id.container);

 mCardStack.setContentResource(R.layout.card_content);

mCardStack.setStackMargin(20);

}

Finally, set the adapter

 mCardAdapter = new CardsDataAdapter(getApplicationContext(),0);

  mCardAdapter.add("test1");

  mCardAdapter.add("test2");

  mCardAdapter.add("test3");

  mCardAdapter.add("test4");

  mCardAdapter.add("test5");

 mCardStack.setAdapter(mCardAdapter);

Listening to card stack event

implement CardStack.CardEventListener, and set it as listener mCardStack.setListener(yourListener);

Class YourListener extends CardStack.CardEventListener{

  //implement card event interface
  @Override
  public boolean swipeEnd(int direction, float distance) {

//if "return true" the dismiss animation will be triggered 

//if false, the card will move back to stack

//distance is finger swipe distance in dp

//the direction indicate swipe direction

//there are four directions

//  0  |  1

// ----------

//  2  |  3

return (distance>300)? true : false;
  
}

@Override
  public boolean swipeStart(int direction, float distance) {

  return true;
  
}

@Override
  public boolean swipeContinue(int direction, float distanceX, float distanceY) {

return true;
  
}

@Override
  public void discarded(int id, int direction) {

  //this callback invoked when dismiss animation is finished. 
  
}

 @Override
  public void topCardTapped() {

 //this callback invoked when a top card is tapped by user. 
  
}
 
}

Resources

A lightweight library which helps to create a view stack as a replacement for fragments and activities, provides transitions and persistence.

This library provides you an RTL Spinner with the Material style. You can use it like any regular Spinner. Add RTL floating label text, hint and error messages.

A powerful image picker which support multi mode and huge image.

Dali is an image blur library for Android. It is easy to use, fast and extensible. Dali contains several modules for either static blurring, live blurring and animations. It uses RenderScript internally (although different implementations can be chosen) and is heavily cached to be fast and keeps small memory footprint. It features a lot of additional image filters and may be easily extended and pretty every configuration can be changed.

Under the Hood is a flexible and powerful Android debug view library. It uses a modular template system that can be easily extended to your needs, although coming with many useful elements built-in.

There is a lot of "default" debug data that can be easily embedded (e.g. current runtime-permission status, app version and device info). There are 2 basic themes (dark and light) which can be customized to your needs.

Sticky header view or suspending view for RecyclerView. RecyclerStickyHeaderView is an Android library that makes it easy to integrate section headers stick to the top in RecyclerView.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes