Page 120

Android Programming Cookbook

} } break; case MotionEvent.ACTION_CANCEL: { onScaleMove = false; mActivePointers.remove(pointerId); onTouchListener.onRelease(); break; } case MotionEvent.ACTION_POINTER_DOWN: onScaleMove = true; onTouchListener.onSecondFingerOnLayout(); PointF f = new PointF(); f.x = event.getX(pointerIndex); f.y = event.getY(pointerIndex); mActivePointers.put(pointerId, f); return false; } return super.dispatchTouchEvent(event); }

public interface OnTouchListener { void onTouch(); void onRelease(); void onPinchIn(); void onPinchOut(); void onMove(); void onTwoFingersDrag(); void onSecondFingerOnLayout(); } }

Let’s see in detail the code above. We have made a custom OnTouchListener interface that our custom layout is going to implement. public interface OnTouchListener { void onTouch(); void onRelease(); void onPinchIn(); void onPinchOut(); void onMove(); void onTwoFingersDrag(); void onSecondFingerOnLayout(); } public void setTouchListener(OnTouchListener onTouchListener) {

112 / 143

SKY MAGZ  
SKY MAGZ  

This is Yahya Christian School Magazine

Advertisement