Created
March 9, 2016 19:16
-
-
Save kaiwinter/b277d4ccc2dfb3c15eb6 to your computer and use it in GitHub Desktop.
Having multiple TouchDelegates for one parent
This file contains 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 final class TouchDelegateComposite extends TouchDelegate { | |
private final List<TouchDelegate> delegates = new ArrayList<>(); | |
private static final Rect EMPTY_RECT = new Rect(); | |
public TouchDelegateComposite(View view) { | |
super(EMPTY_RECT, view); | |
} | |
public void addDelegate(TouchDelegate delegate) { | |
delegates.add(delegate); | |
} | |
@Override | |
public boolean onTouchEvent(MotionEvent event) { | |
boolean res = false; | |
for (TouchDelegate delegate : delegates) { | |
event.setLocation(event.getX(), event.getY()); | |
res = delegate.onTouchEvent(event) || res; | |
} | |
return res; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment