Created
February 22, 2017 09:11
-
-
Save jsaund/93fe45fdcc8f2dde8ba01ad17dc3e47b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void touchEventHandler(@NotNull View view) { | |
| final ConnectedObservable<MotionEvent> motionEventObservable = RxView.touches(view).publish(); | |
| // 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))); | |
| // Connect the source observable to begin emitting events | |
| subscriptions.add(motionEventObservable.connect()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment