Skip to content

Instantly share code, notes, and snippets.

@ifucolo
Created February 24, 2017 01:00
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 ifucolo/1c0103c5141c17a6375610c808954a0f to your computer and use it in GitHub Desktop.
Save ifucolo/1c0103c5141c17a6375610c808954a0f to your computer and use it in GitHub Desktop.
public class FrameTouch extends FrameLayout implements ScaleGestureDetector.OnScaleGestureListener {
GestureDetectorCompat detector;
ScaleGestureDetector scaleDetector;
FrameOnTouch frameOnTouch;
@Override
public boolean onScale(ScaleGestureDetector detector) {
return true;
}
@Override
public boolean onScaleBegin(ScaleGestureDetector detector) {
return true;
}
@Override
public void onScaleEnd(ScaleGestureDetector detector) {
}
public interface FrameOnTouch {
void onFrameTouchUp();
void onScrollMovie(float x, float y);
}
public FrameTouch(Context context) {
super(context);
detector = new GestureDetectorCompat(context, new MyGestureListener());
}
public FrameTouch(Context context, AttributeSet attrs) {
super(context, attrs);
detector = new GestureDetectorCompat(context, new MyGestureListener());
scaleDetector = new ScaleGestureDetector(context, this);
}
public void setFrameOnTouch(FrameOnTouch frameOnTouch) {
this.frameOnTouch = frameOnTouch;
}
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP)
frameOnTouch.onFrameTouchUp();
super.dispatchTouchEvent(event);
return detector.onTouchEvent(event);
}
private class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
frameOnTouch.onScrollMovie(distanceX, distanceY);
return super.onScroll(e1, e2, distanceX, distanceY);
}
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return super.onSingleTapUp(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment