Created
February 24, 2017 01:00
-
-
Save ifucolo/1c0103c5141c17a6375610c808954a0f to your computer and use it in GitHub Desktop.
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 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