Skip to content

Commit

Permalink
adding usage instructions to README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Wittchen committed Mar 6, 2016
1 parent 5a8a34c commit 36578f7
Showing 1 changed file with 96 additions and 2 deletions.
98 changes: 96 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,105 @@ Usage

### Listener

TBD.
**Step 1**: Create `Swipe` attribute in the `Activiy`:

```java
private Swipe swipe;
```

**Step 2**: Initialize `Swipe` object and add listener:

```java
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
info = (TextView) findViewById(R.id.info);

swipe = new Swipe();
swipe.addListener(new SwipeListener() {
@Override public void onSwipingLeft(final MotionEvent event) {
info.setText("SWIPING_LEFT");
}

@Override public void onSwipedLeft(final MotionEvent event) {
info.setText("SWIPED_LEFT");
}

@Override public void onSwipingRight(final MotionEvent event) {
info.setText("SWIPING_RIGHT");
}

@Override public void onSwipedRight(final MotionEvent event) {
info.setText("SWIPED_RIGHT");
}

@Override public void onSwipingUp(final MotionEvent event) {
info.setText("SWIPING_UP");
}

@Override public void onSwipedUp(final MotionEvent event) {
info.setText("SWIPED_UP");
}

@Override public void onSwipingDown(final MotionEvent event) {
info.setText("SWIPING_DOWN");
}

@Override public void onSwipedDown(final MotionEvent event) {
info.setText("SWIPED_DOWN");
}
});
}
```

**Step 3**: override `dispatchTouchEvent(MotionEvent event)`:

```java
@Override public boolean dispatchTouchEvent(MotionEvent event) {
swipe.dispatchTouchEvent(event);
return super.dispatchTouchEvent(event);
}
```

### RxJava

TBD.
**Step 1**: Create `Swipe` attribute and `Subscription` in the `Activiy`:

```java
private Swipe swipe;
private Subscription subscription;
```

**Step 2**: Initialize `Swipe` object and subscribe `Observable`:

```java
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
info = (TextView) findViewById(R.id.info);

swipe = new Swipe();

subscription = swipe.observe()
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<SwipeEvent>() {
@Override public void call(final SwipeEvent swipeEvent) {
info.setText(swipeEvent.toString());
}
});
}
```

**Step 3**: override `dispatchTouchEvent(MotionEvent event)`:

```java
@Override public boolean dispatchTouchEvent(MotionEvent event) {
swipe.dispatchTouchEvent(event);
return super.dispatchTouchEvent(event);
}
```

Example
-------
Expand Down

0 comments on commit 36578f7

Please sign in to comment.