# SwipeDeck2
**Repository Path**: OrganizationStudy/SwipeDeck2
## Basic Information
- **Project Name**: SwipeDeck2
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-07-12
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# SwipeDeck2
## A Tinder style Swipeable deck view for Android

## A Message To Developers
This is an almost complete re write of the first swipe deck, hopefully this one will be less bug prone and easier to update.
this is a very early release so i'm relying on your bug reports and feature suggestions to get this ready for prime time.
## Installation
In your repositories and dependencies section add these parameters:
```groovy
dependencies {
compile 'com.daprlabs.aaron:swipedeck:2.0.3'
}
```
Sync Gradle and import Swipe-Deck into your project
```java
import com.daprlabs.aaron.swipedeck.SwipeDeck;
```
## Example
Start by defining a card view.
Note that you can use any view type of your choice, cardviews provide you with access to shadows
plus they look good. If you decide to use another view I recommend adding a drop shadow and perhaps a border.
Here we have a pretty ordinary card view defined in XML:
```xml
```
Next Swipe Deck takes an adapter in much the same way as other adapter views:
```java
public class SwipeDeckAdapter extends BaseAdapter {
private List data;
private Context context;
public SwipeDeckAdapter(List data, Context context) {
this.data = data;
this.context = context;
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int position) {
return data.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater = getLayoutInflater();
// normally use a viewholder
v = inflater.inflate(R.layout.test_card2, parent, false);
}
ImageView imageView = (ImageView) v.findViewById(R.id.offer_image);
Picasso.with(context).load(R.drawable.food).fit().centerCrop().into(imageView);
TextView textView = (TextView) v.findViewById(R.id.sample_text);
String item = (String)getItem(position);
textView.setText(item);
v.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("Layer type: ", Integer.toString(v.getLayerType()));
Log.i("Hardware Accel type:", Integer.toString(View.LAYER_TYPE_HARDWARE));
}
});
return v;
}
}
```
Now we add a swipe deck to our layout:
```xml
```
I've included some modified layouts (SwipeFrameLayout, SwipeRelativeLayout etc) for ease of use, but you can use any layout you desire. However you may not get the desired outcome unless you set android:clipChildren="false" on your containing layout. If you choose not to do this cards will be clipped as they move outside their view boundary.
Now we simply give our card deck an adapter and perhaps a callback from our Activity:
```java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cardStack = (SwipeDeck) findViewById(R.id.swipe_deck);
testData = new ArrayList<>();
testData.add("0");
testData.add("1");
testData.add("2");
testData.add("3");
testData.add("4");
adapter = new SwipeDeckAdapter(testData, this);
if(cardStack != null){
cardStack.setAdapter(adapter);
}
cardStack.setCallback(new SwipeDeck.SwipeDeckCallback() {
@Override
public void cardSwipedLeft(int positionInAdapter) {
Log.i("MainActivity", "card was swiped left, position in adapter: " + positionInAdapter);
}
@Override
public void cardSwipedRight(int positoinInAdapter) {
Log.i("MainActivity", "card was swiped right, position in adapter: " + positoinInAdapter);
}
});
cardStack.setLeftImage(R.id.left_image);
cardStack.setRightImage(R.id.right_image);
//example of buttons triggering events on the deck
Button btn = (Button) findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cardStack.swipeTopCardLeft(180);
}
});
Button btn2 = (Button) findViewById(R.id.button2);
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cardStack.swipeTopCardRight(180);
}
});
Button btn3 = (Button) findViewById(R.id.button3);
btn3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
testData.add("a sample string.");
adapter.notifyDataSetChanged();
}
});
}
```
# ScreenShots


