Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DrawingView extends View {
- /** Last saved X-coordinate */
- private float pX;
- /** Last saved Y-coordinate*/
- private float pY;
- private DrawingViewInterface mInterface;
- public void setViewListener(DrawingViewInterface interface1) {
- mInterface = interface1;
- }
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- int action = event.getAction();
- switch (action) {
- case MotionEvent.ACTION_DOWN:
- path.moveTo(event.getX(), event.getY());
- pX = event.getX();
- pY = event.getY();
- break;
- case MotionEvent.ACTION_MOVE:
- path.quadTo(pX, pY, event.getX(), event.getY());
- pX = event.getX();
- pY = event.getY();
- break;
- case MotionEvent.ACTION_UP:
- cacheCanvas.drawPath(path, paint);
- path.reset();
- mInterface.onActionFinished(pX, pY);
- break;
- }
- invalidate();
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment