Code example for LinkedList

Methods: getFirst, getLast, size

0
            break; 
        } 
    } 
 
    private int getPointersDown() { 
        return mPointerInfo.size();
    } 
 
    private int getActionIndex(MotionEvent event) {
        return (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
            >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
    } 
 
    private void onTouchStart(MotionEvent event) {
        mLastEventTime = event.getEventTime();
        mPointerInfo.addFirst(PointerInfo.create(event, getActionIndex(event)));
        if (getPointersDown() == 2) { 
            sendScaleGesture(EventType.BEGIN);
        } 
    } 
 
    private void onTouchMove(MotionEvent event) {
        mLastEventTime = event.getEventTime();
        for (int i = 0; i < event.getPointerCount(); i++) {
            PointerInfo pointerInfo = pointerInfoForEventIndex(event, i);
            if (pointerInfo != null) {
                pointerInfo.populate(event, i);
            } 
        } 
 
        if (getPointersDown() == 2) { 
            sendScaleGesture(EventType.CONTINUE);
        } 
    } 
 
    private void onTouchEnd(MotionEvent event) {
        mLastEventTime = event.getEventTime();
 
        int id = event.getPointerId(getActionIndex(event));
        ListIterator<PointerInfo> iterator = mPointerInfo.listIterator();
        while (iterator.hasNext()) {
            PointerInfo pointerInfo = iterator.next();
            if (pointerInfo.getId() != id) {
                continue; 
            } 
 
            // One of the pointers we were tracking was lifted. Remove its info object from the 
            // list, recycle it to avoid GC pauses, and send an onScaleEnd() notification if this 
            // ended the gesture. 
            iterator.remove();
            pointerInfo.recycle();
            if (getPointersDown() == 1) { 
                sendScaleGesture(EventType.END);
            } 
        } 
    } 
 
    /** 
     * Returns the X coordinate of the focus location (the midpoint of the two fingers). If only 
     * one finger is down, returns the location of that finger. 
     */ 
    public float getFocusX() { 
        switch (getPointersDown()) { 
        case 1: 
            return mPointerInfo.getFirst().getCurrent().x;
        case 2: 
            PointerInfo pointerA = mPointerInfo.getFirst(), pointerB = mPointerInfo.getLast();
            return (pointerA.getCurrent().x + pointerB.getCurrent().x) / 2.0f;
        } 
 
        Log.e(LOGTAG, "No gesture taking place in getFocusX()!");
        return 0.0f;