Skip to content

Instantly share code, notes, and snippets.

@jsaund
Last active May 24, 2018 09:22
Show Gist options
  • Select an option

  • Save jsaund/d01fcc5322d60ad225dff7ce65c5a547 to your computer and use it in GitHub Desktop.

Select an option

Save jsaund/d01fcc5322d60ad225dff7ce65c5a547 to your computer and use it in GitHub Desktop.
Contrived example of using the share operator
public void touchEventHandler(@NotNull View view) {
final Observable<MotionEvent> motionEventObservable = RxView.touches(view).share();
// Capture down events
final Observable<MotionEvent> downEventsObservable = motionEventObservable
.filter(event -> event.getAction() == MotionEvent.ACTION_DOWN);
// Capture up events
final Observable<MotionEvent> upEventsObservable = motionEventObservable
.filter(event -> event.getAction() == MotionEvent.ACTION_UP);
// Show a red circle at the position where the down event ocurred
subscriptions.add(downEventsObservable.subscribe(event ->
view.showCircle(event.getX(), event.getY(), Color.RED)));
// Show a blue circle at the position where the up event ocurred
subscriptions.add(upEventsObservable.subscribe(event ->
view.showCircle(event.getX(), event.getY(), Color.BLUE)));
}
@azmym
Copy link
Copy Markdown

azmym commented May 24, 2018

would you please clarify what is "subscriptions", I can't find in documentation something with that name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment