Skip to content

Commit

Permalink
Started Readme and changed Listview for MaterialListView
Browse files Browse the repository at this point in the history
  • Loading branch information
dexafree committed Jul 24, 2014
1 parent 8fe8ed1 commit ae88416
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 8 deletions.
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# MaterialList
MaterialList is an Android library created to help all Android developers get the beautiful CardViews that Google shows at its [official design specifications](http://www.google.com/design/spec/components/cards.html#cards-usage).

Provided as a ListView extension, it can receive a list of Cards (stored in a CardList, provided by the library) and show them accordingly to the android style and design patterns.

It also has been developed while keeping extensibility in mind, which meens that you are able to create your own card layouts and add them to the CardList without any pain (see examples below).

## Cards provided
These are the cards that the library offers by default:
* **SmallImageCard**
![SmallImageCard](http://i.imgur.com/f5LLorA.png)

* **BigImageCard**
![BigImageCard](http://i.imgur.com/yW7uBNy.png)

* **BasicImageButtonsCard**
![BasicImageButtonsCard](http://i.imgur.com/ENxUGAw.png)

* **BasicButtonsCard**
![BasicButtonsCard](http://i.imgur.com/19xt1FX.png)

* **BigImageButtonsCard**
![BigImageButtonsCard](http://i.imgur.com/vr4vP6o.png)

## How to use
First of all, you'll need to declare a MaterialListView in your layout:
```xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin">

<com.dexafree.materiallistviewexample.view.MaterialListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/material_listview"/>

</RelativeLayout>
```

After that, get it on your code by simply making a findViewById query.

```java
mListView = (MaterialListView) findViewById(R.id.material_listview);
```

Then, create your CardList, fill it with Cards, create the adapter and you're ready to go:

```java
CardList cardsList = new CardList();

// Fill your CardsList

MaterialListViewAdapter adapter = new MaterialListViewAdapter(mContext, cardsList);

mListView.setMaterialListViewAdapter(adapter);
```

## Dismissing the cards
One of the features I've always loved is the SwipeToDismiss gesture.
MaterialList brings you this feature, and in order to
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ protected void onCreate(Bundle savedInstanceState) {
MaterialListViewAdapter adapter = new MaterialListViewAdapter(this, cardsList);

mListView.setMaterialListViewAdapter(adapter);
mListView.setDefaultListeners();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ListView;

import com.dexafree.materiallistviewexample.view.MaterialListView;
import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.AnimatorListenerAdapter;
import com.nineoldandroids.animation.ValueAnimator;
Expand All @@ -29,7 +31,7 @@ public class SwipeDismissListener implements View.OnTouchListener {
private long mAnimationTime;

// Fixed properties
private ListView mListView;
private MaterialListView mListView;
private OnDismissCallback mCallback;
private int mViewWidth = 1; // 1 and not 0 to prevent dividing by zero

Expand All @@ -52,12 +54,12 @@ public interface OnDismissCallback {
* Called when the user has indicated they she would like to dismiss one or more list item
* positions.
*
* @param listView The originating {@link ListView}.
* @param listView The originating {@link MaterialListView}.
* @param reverseSortedPositions An array of positions to dismiss, sorted in descending
* order for convenience.
*/
void onDismiss(ListView listView, int[] reverseSortedPositions);
boolean canDismiss(ListView listView, int position);
void onDismiss(MaterialListView listView, int[] reverseSortedPositions);
boolean canDismiss(MaterialListView listView, int position);
}

/**
Expand All @@ -67,7 +69,7 @@ public interface OnDismissCallback {
* @param callback The callback to trigger when the user has indicated that she would like to
* dismiss one or more list items.
*/
public SwipeDismissListener(ListView listView, OnDismissCallback callback) {
public SwipeDismissListener(MaterialListView listView, OnDismissCallback callback) {
ViewConfiguration vc = ViewConfiguration.get(listView.getContext());
mSlop = vc.getScaledTouchSlop();
mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public void setMaterialListViewAdapter (MaterialListViewAdapter adapter) {
setAdapter (mAdapter);
setDivider (null);
setDividerHeight (8);
setDefaultListeners();
}

public MaterialListViewAdapter getMaterialListViewAdapter(){
return mAdapter;
}

public void setOnDismissCallback (SwipeDismissListener.OnDismissCallback callback) {
Expand All @@ -41,21 +46,22 @@ public void setOnDismissCallback (SwipeDismissListener.OnDismissCallback callbac
}

public void setDefaultListeners () {

SwipeDismissListener touchListener =
new SwipeDismissListener(
this,
new SwipeDismissListener.OnDismissCallback () {

@Override
public void onDismiss (ListView listView, int[] reverseSortedPositions) {
public void onDismiss (MaterialListView listView, int[] reverseSortedPositions) {
for (int position : reverseSortedPositions) {
mAdapter.remove(mAdapter.getItem(position));
}
mAdapter.notifyDataSetChanged();
}

@Override
public boolean canDismiss (ListView listView, int position){
public boolean canDismiss (MaterialListView listView, int position){
return true;
}
});
Expand Down

0 comments on commit ae88416

Please sign in to comment.