Skip to content

Instantly share code, notes, and snippets.

@kaiwinter
Created March 9, 2016 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaiwinter/b277d4ccc2dfb3c15eb6 to your computer and use it in GitHub Desktop.
Save kaiwinter/b277d4ccc2dfb3c15eb6 to your computer and use it in GitHub Desktop.
Having multiple TouchDelegates for one parent
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