Example usage for android.view MotionEvent getHistoricalY

List of usage examples for android.view MotionEvent getHistoricalY

Introduction

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

Prototype

public final float getHistoricalY(int pos) 

Source Link

Document

#getHistoricalY(int,int) for the first pointer index (may be an arbitrary pointer identifier).

Usage

From source file:de.hs_bremen.aurora_hunter.ui.views.KpIndexChartView.java

public boolean onTouch(View view, MotionEvent event) {
    if (event.getAction() != MotionEvent.ACTION_UP) {
        for (int i = 0; i < event.getHistorySize(); i++) {
            Point point = new Point();
            point.x = event.getHistoricalX(i);
            point.y = event.getHistoricalY(i);
            // points.add(point);
        }// ww  w.ja  va 2  s.com
        invalidate();
        return true;
    }
    return super.onTouchEvent(event);
}

From source file:com.ichi2.anki.Whiteboard.java

/**
 * Handle touch screen motion events./*from   w  w  w  . j av a2  s .c o m*/
 * 
 * @param event The motion event.
 * @return True if the event was handled, false otherwise.
 */
public boolean handleTouchEvent(MotionEvent event) {
    float x = event.getX();
    float y = event.getY();

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        touchStart(x, y);
        invalidate();
        return true;
    case MotionEvent.ACTION_MOVE:
        for (int i = 0; i < event.getHistorySize(); i++) {
            touchMove(event.getHistoricalX(i), event.getHistoricalY(i));
        }
        touchMove(x, y);
        invalidate();
        return true;
    case MotionEvent.ACTION_UP:
        touchUp();
        invalidate();
        return true;
    default:
        return false;
    }
}

From source file:com.ylw.split.splitview.view.SplitView3.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        initDragView(vTop, event);//www.j av  a2  s.c om
        initDragView(vCenter, event);
        initDragView(vBottom, event);
    }
    if (event.getHistorySize() > 0) { //Touch
        if (dragView == vTop) { //vTop
            if (event.getY() > event.getHistoricalY(0)) { //?
                if (vTop.getScrollY() == 0) {
                    return mDragger.shouldInterceptTouchEvent(event);
                } else {
                    return false;
                }
            } else if (event.getY() < event.getHistoricalY(0)) { //?
                if (vTop.getTop() > 0) {
                    return mDragger.shouldInterceptTouchEvent(event);
                } else {
                    return false;
                }
            } else if (event.getY() == event.getHistoricalY(0)) {
                Log.d(TAG, "onInterceptTouchEvent - " + "event.getY() == event.getHistoricalY(0)");
                return false;
            }
        } else if (dragView == vBottom) { //vBottom
            if (event.getY() > event.getHistoricalY(0)) { //?
                // ?webView?
                int ci = vBottom.getCurrentItem();
                WebView webView = (WebView) vBottom.findViewById(ci);
                if (webView.getScrollY() == 0) {
                    return mDragger.shouldInterceptTouchEvent(event);
                } else {
                    return false;
                }
            } else {
                return false;
            }
        } else if (dragView == vCenter) {
            return mDragger.shouldInterceptTouchEvent(event);
        }
    }
    return mDragger.shouldInterceptTouchEvent(event);
}

From source file:com.p3authentication.preferences.Prefs.java

@SuppressWarnings("static-access")
@Override/*from  w  w w. ja va2  s.  c o  m*/
public boolean onTouch(View v, MotionEvent event) {
    // TODO Auto-generated method stub
    int action = event.getAction();
    int N = event.getHistorySize();
    if (action == event.ACTION_DOWN) {
        calibrator.setColorFilter(Color.BLACK);
        for (int i = 0; i < N; i++) {
            calibrate(event.getHistoricalX(i), event.getHistoricalY(i), event.getHistoricalPressure(i),
                    event.getHistoricalSize(i));
        }
        calibrate(event.getX(), event.getY(), event.getPressure(), event.getSize());
    } else if (action == event.ACTION_UP) {
        Float temp = Collections.max(CalList);
        temp = (float) Math.ceil((Double.parseDouble(Float.valueOf(temp).toString())) / 10);
        LargeValue = temp * 10;
        calibrator.setColorFilter(Color.GREEN);
        // Largest.setText(String.valueOf(LargeValue));

    }

    return true;
}

From source file:com.hippo.widget.lockpattern.LockPatternView.java

private void handleActionMove(MotionEvent event) {
    // Handle all recent motion events so we don't skip any cells even when the device
    // is busy...
    final float radius = mPathWidth;
    final int historySize = event.getHistorySize();
    mTmpInvalidateRect.setEmpty();/*from w w  w .  ja va2  s .  c  om*/
    boolean invalidateNow = false;
    for (int i = 0; i < historySize + 1; i++) {
        final float x = i < historySize ? event.getHistoricalX(i) : event.getX();
        final float y = i < historySize ? event.getHistoricalY(i) : event.getY();
        Cell hitCell = detectAndAddHit(x, y);
        final int patternSize = mPattern.size();
        if (hitCell != null && patternSize == 1) {
            mPatternInProgress = true;
            notifyPatternStarted();
        }
        // note current x and y for rubber banding of in progress patterns
        final float dx = Math.abs(x - mInProgressX);
        final float dy = Math.abs(y - mInProgressY);
        if (dx > DRAG_THRESHHOLD || dy > DRAG_THRESHHOLD) {
            invalidateNow = true;
        }

        if (mPatternInProgress && patternSize > 0) {
            final ArrayList<Cell> pattern = mPattern;
            final Cell lastCell = pattern.get(patternSize - 1);
            float lastCellCenterX = getCenterXForColumn(lastCell.column);
            float lastCellCenterY = getCenterYForRow(lastCell.row);

            // Adjust for drawn segment from last cell to (x,y). Radius accounts for line width.
            float left = Math.min(lastCellCenterX, x) - radius;
            float right = Math.max(lastCellCenterX, x) + radius;
            float top = Math.min(lastCellCenterY, y) - radius;
            float bottom = Math.max(lastCellCenterY, y) + radius;

            // Invalidate between the pattern's new cell and the pattern's previous cell
            if (hitCell != null) {
                final float width = mSquareWidth * 0.5f;
                final float height = mSquareHeight * 0.5f;
                final float hitCellCenterX = getCenterXForColumn(hitCell.column);
                final float hitCellCenterY = getCenterYForRow(hitCell.row);

                left = Math.min(hitCellCenterX - width, left);
                right = Math.max(hitCellCenterX + width, right);
                top = Math.min(hitCellCenterY - height, top);
                bottom = Math.max(hitCellCenterY + height, bottom);
            }

            // Invalidate between the pattern's last cell and the previous location
            mTmpInvalidateRect.union(Math.round(left), Math.round(top), Math.round(right), Math.round(bottom));
        }
    }
    mInProgressX = event.getX();
    mInProgressY = event.getY();

    // To save updates, we only invalidate if the user moved beyond a certain amount.
    if (invalidateNow) {
        mInvalidate.union(mTmpInvalidateRect);
        invalidate(mInvalidate);
        mInvalidate.set(mTmpInvalidateRect);
    }
}

From source file:co.adrianblan.fastbrush.MyGLSurfaceView.java

@Override
public boolean onTouchEvent(MotionEvent e) {
    // MotionEvent reports input details from the touch screen
    // and other input controls. In this case, you are only
    // interested in events where the touch position changed.

    switch (e.getAction()) {

    case MotionEvent.ACTION_DOWN:
        if (mVelocityTracker == null) {
            mVelocityTracker = VelocityTracker.obtain();
        } else {/*from  ww  w .j  a v a 2s.  c o  m*/
            mVelocityTracker.clear();
        }

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.touchHasStarted();
            }
        });

        // No break is intentional

    case MotionEvent.ACTION_MOVE:

        mVelocityTracker.addMovement(e);

        // Compute velocity in pixels per second
        mVelocityTracker.computeCurrentVelocity(1);

        final ArrayList<TouchData> touchDataList = new ArrayList<>(e.getHistorySize() + 1);
        Vector2 viewportPosition;

        Vector2 viewportVelocity = new Vector2(
                VelocityTrackerCompat.getXVelocity(mVelocityTracker, e.getActionIndex()),
                VelocityTrackerCompat.getYVelocity(mVelocityTracker, e.getActionIndex()));

        // Add previous touch coordinates
        for (int i = 0; i < e.getHistorySize(); i++) {
            viewportPosition = new Vector2(e.getHistoricalX(i), e.getHistoricalY(i));

            touchDataList.add(new TouchData(mRenderer.viewportToWorld(viewportPosition), viewportVelocity,
                    e.getHistoricalSize(i), e.getHistoricalPressure(i)));
        }

        // Add current touch coordinates
        viewportPosition = new Vector2(e.getX(), e.getY());
        touchDataList.add(new TouchData(mRenderer.viewportToWorld(viewportPosition), viewportVelocity,
                e.getSize(), e.getPressure()));

        // Ensure we call switchMode() on the OpenGL thread.
        // queueEvent() is a method of GLSurfaceView that will do this for us.
        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.addTouchData(touchDataList);
            }
        });

        requestRender();
        break;

    case MotionEvent.ACTION_UP:

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.touchHasEnded();
            }
        });
        requestRender();
        break;
    }
    return true;
}

From source file:com.rexmtorres.android.patternlock.PatternLockView.java

private void handleActionMove(MotionEvent event) {
    // Handle all recent motion events so we don't skip any cells even when the device
    // is busy...
    final float radius = mPathWidth;
    final int historySize = event.getHistorySize();
    mTmpInvalidateRect.setEmpty();// w  w w. ja  v  a2s  . co m
    boolean invalidateNow = false;
    for (int i = 0; i < historySize + 1; i++) {
        final float x = i < historySize ? event.getHistoricalX(i) : event.getX();
        final float y = i < historySize ? event.getHistoricalY(i) : event.getY();
        Cell hitCell = detectAndAddHit(x, y);
        final int patternSize = mPattern.size();
        if (hitCell != null && patternSize == 1) {
            setPatternInProgress(true);
            notifyPatternStarted();
        }
        // note current x and y for rubber banding of in progress patterns
        final float dx = Math.abs(x - mInProgressX);
        final float dy = Math.abs(y - mInProgressY);
        if (dx > DRAG_THRESHHOLD || dy > DRAG_THRESHHOLD) {
            invalidateNow = true;
        }
        if (mPatternInProgress && patternSize > 0) {
            final ArrayList<Cell> pattern = mPattern;
            final Cell lastCell = pattern.get(patternSize - 1);
            float lastCellCenterX = getCenterXForColumn(lastCell.column);
            float lastCellCenterY = getCenterYForRow(lastCell.row);
            // Adjust for drawn segment from last cell to (x,y). Radius accounts for line width.
            float left = Math.min(lastCellCenterX, x) - radius;
            float right = Math.max(lastCellCenterX, x) + radius;
            float top = Math.min(lastCellCenterY, y) - radius;
            float bottom = Math.max(lastCellCenterY, y) + radius;
            // Invalidate between the pattern's new cell and the pattern's previous cell
            if (hitCell != null) {
                final float width = mSquareWidth * 0.5f;
                final float height = mSquareHeight * 0.5f;
                final float hitCellCenterX = getCenterXForColumn(hitCell.column);
                final float hitCellCenterY = getCenterYForRow(hitCell.row);
                left = Math.min(hitCellCenterX - width, left);
                right = Math.max(hitCellCenterX + width, right);
                top = Math.min(hitCellCenterY - height, top);
                bottom = Math.max(hitCellCenterY + height, bottom);
            }
            // Invalidate between the pattern's last cell and the previous location
            mTmpInvalidateRect.union(Math.round(left), Math.round(top), Math.round(right), Math.round(bottom));
        }
    }
    mInProgressX = event.getX();
    mInProgressY = event.getY();
    // To save updates, we only invalidate if the user moved beyond a certain amount.
    if (invalidateNow) {
        mInvalidate.union(mTmpInvalidateRect);
        invalidate(mInvalidate);
        mInvalidate.set(mTmpInvalidateRect);
    }
}

From source file:io.authme.sdk.widget.LockPatternView.java

private void handleActionMove(MotionEvent event) {
    // Handle all recent motion events so we don't skip any cells even when
    // the device
    // is busy...
    final float radius = mPathWidth;
    final int historySize = event.getHistorySize();
    mTmpInvalidateRect.setEmpty();//  www  .  j av  a2s  . c o m
    boolean invalidateNow = false;
    for (int i = 0; i < historySize + 1; i++) {
        final float x = i < historySize ? event.getHistoricalX(i) : event.getX();
        final float y = i < historySize ? event.getHistoricalY(i) : event.getY();
        Cell hitCell = detectAndAddHit(x, y);
        final int patternSize = mPattern.size();
        if (hitCell != null && patternSize == 1) {
            mPatternInProgress = true;
            notifyPatternStarted();
        }
        // note current x and y for rubber banding of in progress patterns
        final float dx = Math.abs(x - mInProgressX);
        final float dy = Math.abs(y - mInProgressY);
        if (dx > DRAG_THRESHHOLD || dy > DRAG_THRESHHOLD) {
            invalidateNow = true;
        }

        if (mPatternInProgress && patternSize > 0) {
            final ArrayList<Cell> pattern = mPattern;
            final Cell lastCell = pattern.get(patternSize - 1);
            float lastCellCenterX = getCenterXForColumn(lastCell.column);
            float lastCellCenterY = getCenterYForRow(lastCell.row);

            // Adjust for drawn segment from last cell to (x,y). Radius
            // accounts for line width.
            float left = Math.min(lastCellCenterX, x) - radius;
            float right = Math.max(lastCellCenterX, x) + radius;
            float top = Math.min(lastCellCenterY, y) - radius;
            float bottom = Math.max(lastCellCenterY, y) + radius;

            // Invalidate between the pattern's new cell and the pattern's
            // previous cell
            if (hitCell != null) {
                final float width = mSquareWidth * 0.5f;
                final float height = mSquareHeight * 0.5f;
                final float hitCellCenterX = getCenterXForColumn(hitCell.column);
                final float hitCellCenterY = getCenterYForRow(hitCell.row);

                left = Math.min(hitCellCenterX - width, left);
                right = Math.max(hitCellCenterX + width, right);
                top = Math.min(hitCellCenterY - height, top);
                bottom = Math.max(hitCellCenterY + height, bottom);
            }

            // Invalidate between the pattern's last cell and the previous
            // location
            mTmpInvalidateRect.union(Math.round(left), Math.round(top), Math.round(right), Math.round(bottom));
        }
    }
    mInProgressX = event.getX();
    mInProgressY = event.getY();

    // To save updates, we only invalidate if the user moved beyond a
    // certain amount.
    if (invalidateNow) {
        mInvalidate.union(mTmpInvalidateRect);
        invalidate(mInvalidate);
        mInvalidate.set(mTmpInvalidateRect);
    }
}

From source file:com.android.nobug.view.pattern.PatternView.java

private void handleActionMove(MotionEvent event) {

    // Handle all recent motion events so we don't skip any cells even when the device
    // is busy...
    final float radius = mPathWidth;
    final int historySize = event.getHistorySize();
    mTmpInvalidateRect.setEmpty();//from  w ww .  j  a  va  2 s.c  o m
    boolean invalidateNow = false;
    for (int i = 0; i < historySize + 1; i++) {
        final float x = i < historySize ? event.getHistoricalX(i) : event.getX();
        final float y = i < historySize ? event.getHistoricalY(i) : event.getY();
        Cell hitCell = detectAndAddHit(x, y);
        final int patternSize = mPattern.size();
        if (hitCell != null && patternSize == 1) {
            setPatternInProgress(true);
            notifyPatternStarted();
        }
        // note current x and y for rubber banding of in progress patterns
        final float dx = Math.abs(x - mInProgressX);
        final float dy = Math.abs(y - mInProgressY);
        if (dx > DRAG_THRESHOLD || dy > DRAG_THRESHOLD) {
            invalidateNow = true;
        }

        if (mPatternInProgress && patternSize > 0) {
            final ArrayList<Cell> pattern = mPattern;
            final Cell lastCell = pattern.get(patternSize - 1);
            float lastCellCenterX = getCenterXForColumn(lastCell.column);
            float lastCellCenterY = getCenterYForRow(lastCell.row);

            // Adjust for drawn segment from last cell to (x,y). Radius accounts for line width.
            float left = Math.min(lastCellCenterX, x) - radius;
            float right = Math.max(lastCellCenterX, x) + radius;
            float top = Math.min(lastCellCenterY, y) - radius;
            float bottom = Math.max(lastCellCenterY, y) + radius;

            // Invalidate between the pattern's new cell and the pattern's previous cell
            if (hitCell != null) {
                final float width = mSquareWidth * 0.5f;
                final float height = mSquareHeight * 0.5f;
                final float hitCellCenterX = getCenterXForColumn(hitCell.column);
                final float hitCellCenterY = getCenterYForRow(hitCell.row);

                left = Math.min(hitCellCenterX - width, left);
                right = Math.max(hitCellCenterX + width, right);
                top = Math.min(hitCellCenterY - height, top);
                bottom = Math.max(hitCellCenterY + height, bottom);
            }

            // Invalidate between the pattern's last cell and the previous location
            mTmpInvalidateRect.union(Math.round(left), Math.round(top), Math.round(right), Math.round(bottom));
        }
    }
    mInProgressX = event.getX();
    mInProgressY = event.getY();

    // To save updates, we only invalidate if the user moved beyond a certain amount.
    if (invalidateNow) {
        mInvalidate.union(mTmpInvalidateRect);
        invalidate(mInvalidate);
        mInvalidate.set(mTmpInvalidateRect);
    }
}

From source file:com.example.androidannotationtesttwo.widget.swiptlistview.SwipeListView.java

/**
 * adjust header padding according to motion event
 * /*from w ww.  ja v  a  2  s.  c  o  m*/
 * @param ev
 */
private void adjustHeaderPadding(MotionEvent ev) {
    // adjust header padding according to motion event history
    int pointerCount = ev.getHistorySize();
    if (isVerticalFadingEdgeEnabled()) {
        setVerticalScrollBarEnabled(false);
    }
    for (int i = 0; i < pointerCount; i++) {
        if (currentHeaderStatus == HEADER_STATUS_DROP_DOWN_TO_LOAD
                || currentHeaderStatus == HEADER_STATUS_RELEASE_TO_LOAD) {
            headerLayout.setPadding(headerLayout.getPaddingLeft(),
                    (int) (((ev.getHistoricalY(i) - actionDownPointY) - headerOriginalHeight)
                            / headerPaddingTopRate),
                    headerLayout.getPaddingRight(), headerLayout.getPaddingBottom());
        }
    }
}