Example usage for android.view MotionEvent getHistorySize

List of usage examples for android.view MotionEvent getHistorySize

Introduction

In this page you can find the example usage for android.view MotionEvent getHistorySize.

Prototype

public final int getHistorySize() 

Source Link

Document

Returns the number of historical points in this event.

Usage

From source file:processing.core.PApplet.java

protected void enqueueMotionEvent(MotionEvent event) {
    synchronized (motionLock) {
        // on first run, allocate array for motion events
        if (motionEventQueue == null) {
            motionEventQueue = new PMotionEvent[20];
            for (int i = 0; i < motionEventQueue.length; i++) {
                motionEventQueue[i] = new PMotionEvent();
            }// w ww  .j a  v a  2 s . co m
        }
        // allocate more PMotionEvent objects if we're out
        int historyCount = event.getHistorySize();
        // println("motion: " + motionEventCount + " " + historyCount + " "
        // + motionEventQueue.length);
        if (motionEventCount + historyCount >= motionEventQueue.length) {
            int atLeast = motionEventCount + historyCount + 1;
            PMotionEvent[] temp = new PMotionEvent[max(atLeast, motionEventCount << 1)];
            if (PApplet.DEBUG) {
                println("motion: " + motionEventCount + " " + historyCount + " " + motionEventQueue.length);
                println("allocating " + temp.length + " entries for motion events");
            }
            System.arraycopy(motionEventQueue, 0, temp, 0, motionEventCount);
            motionEventQueue = temp;
            for (int i = motionEventCount; i < motionEventQueue.length; i++) {
                motionEventQueue[i] = new PMotionEvent();
            }
        }

        // this will be the last event in the list
        PMotionEvent pme = motionEventQueue[motionEventCount + historyCount];
        pme.setAction(event.getAction());
        pme.setNumPointers(event.getPointerCount());
        pme.setPointers(event);

        // historical events happen before the 'current' values
        if (pme.action == MotionEvent.ACTION_MOVE && historyCount > 0) {
            for (int i = 0; i < historyCount; i++) {
                PMotionEvent hist = motionEventQueue[motionEventCount++];
                hist.setAction(event.getAction());
                hist.setNumPointers(event.getPointerCount());
                hist.setPointers(event, i);
            }
        }

        // now step over the last one that we used to assign 'pme'
        // if historyCount is 0, this just steps over the last
        motionEventCount++;
    }
}