Example usage for android.view MotionEvent getY

List of usage examples for android.view MotionEvent getY

Introduction

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

Prototype

public final float getY(int pointerIndex) 

Source Link

Document

Returns the Y coordinate of this event for the given pointer index (use #getPointerId(int) to find the pointer identifier for this index).

Usage

From source file:au.gov.ga.worldwind.androidremote.client.Remote.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (controlling) {
        velocityTracker.addMovement(event);
        velocityTracker.computeCurrentVelocity(1);

        boolean down = event.getActionMasked() == MotionEvent.ACTION_DOWN
                || event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN;
        boolean up = event.getActionMasked() == MotionEvent.ACTION_UP
                || event.getActionMasked() == MotionEvent.ACTION_POINTER_UP;
        Finger[] fingers = new Finger[event.getPointerCount()];
        for (int i = 0; i < event.getPointerCount(); i++) {
            fingers[i] = new Finger(event.getPointerId(i), event.getX(i), event.getY(i),
                    velocityTracker.getXVelocity(i), velocityTracker.getYVelocity(i),
                    !(event.getActionIndex() == i && up));
        }/*from w w  w.  j a  v a  2  s  .  c om*/

        FingerMessage<?> message = up ? new UpMessage(fingers)
                : down ? new DownMessage(fingers) : new MoveMessage(fingers);
        communicator.sendMessage(message);
    }
    return super.onTouchEvent(event);
}

From source file:ch.tutti.android.bottomsheet.ResolverDrawerLayout.java

private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = ev.getActionIndex();
    final int pointerId = ev.getPointerId(pointerIndex);
    if (pointerId == mActivePointerId) {
        // This was our active pointer going up. Choose a new
        // active pointer and adjust accordingly.
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mInitialTouchX = ev.getX(newPointerIndex);
        mInitialTouchY = mLastTouchY = ev.getY(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
    }/*from   w w w .ja  v  a 2  s  . c  om*/
}

From source file:android.support.v7.widget.ForwardingListener.java

/**
 * Observes motion events and determines when to start forwarding.
 *
 * @param srcEvent motion event in source view coordinates
 * @return true to start forwarding motion events, false otherwise
 *///from ww  w .j av  a  2s. c  om
private boolean onTouchObserved(MotionEvent srcEvent) {
    final View src = mSrc;
    if (!src.isEnabled()) {
        return false;
    }

    final int actionMasked = MotionEventCompat.getActionMasked(srcEvent);
    switch (actionMasked) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = srcEvent.getPointerId(0);

        if (mDisallowIntercept == null) {
            mDisallowIntercept = new DisallowIntercept();
        }
        src.postDelayed(mDisallowIntercept, mTapTimeout);

        if (mTriggerLongPress == null) {
            mTriggerLongPress = new TriggerLongPress();
        }
        src.postDelayed(mTriggerLongPress, mLongPressTimeout);
        break;
    case MotionEvent.ACTION_MOVE:
        final int activePointerIndex = srcEvent.findPointerIndex(mActivePointerId);
        if (activePointerIndex >= 0) {
            final float x = srcEvent.getX(activePointerIndex);
            final float y = srcEvent.getY(activePointerIndex);

            // Has the pointer moved outside of the view?
            if (!pointInView(src, x, y, mScaledTouchSlop)) {
                clearCallbacks();

                // Don't let the parent intercept our events.
                src.getParent().requestDisallowInterceptTouchEvent(true);
                return true;
            }
        }
        break;
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        clearCallbacks();
        break;
    }

    return false;
}

From source file:org.cocos2dx.lib.TextInputWraper.java

private void dumpEvent(MotionEvent event) {
    String names[] = { "DOWN", "UP", "MOVE", "CANCEL", "OUTSIDE", "POINTER_DOWN", "POINTER_UP", "7?", "8?",
            "9?" };
    StringBuilder sb = new StringBuilder();
    int action = event.getAction();
    int actionCode = action & MotionEvent.ACTION_MASK;
    sb.append("event ACTION_").append(names[actionCode]);
    if (actionCode == MotionEvent.ACTION_POINTER_DOWN || actionCode == MotionEvent.ACTION_POINTER_UP) {
        sb.append("(pid ").append(action >> MotionEvent.ACTION_POINTER_ID_SHIFT);
        sb.append(")");
    }//  w ww .j  a va2  s . com
    sb.append("[");
    for (int i = 0; i < event.getPointerCount(); i++) {
        sb.append("#").append(i);
        sb.append("(pid ").append(event.getPointerId(i));
        sb.append(")=").append((int) event.getX(i));
        sb.append(",").append((int) event.getY(i));
        if (i + 1 < event.getPointerCount())
            sb.append(";");
    }
    sb.append("]");
    Log.d(TAG, sb.toString());
}

From source file:com.android.incallui.widget.multiwaveview.GlowPadView.java

private void handleDown(MotionEvent event) {
    int actionIndex = event.getActionIndex();
    float eventX = event.getX(actionIndex);
    float eventY = event.getY(actionIndex);
    switchToState(STATE_START, eventX, eventY);
    if (!trySwitchToFirstTouchState(eventX, eventY)) {
        mDragging = false;/*from  ww  w  .j ava 2s  .  c o m*/
    } else {
        mPointerId = event.getPointerId(actionIndex);
        updateGlowPosition(eventX, eventY);
    }
}

From source file:com.inmobi.ultrapush.AnalyzeActivity.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (isInGraphView(event.getX(0), event.getY(0))) {
        this.mDetector.onTouchEvent(event);
        if (isMeasure) {
            measureEvent(event);//w  w w . j  a  v  a2s .c o  m
        } else {
            scaleEvent(event);
        }
        invalidateGraphView();
        // Go to scaling mode when user release finger in measure mode.
        if (event.getActionMasked() == MotionEvent.ACTION_UP) {
            if (isMeasure) {
                switchMeasureAndScaleMode();
            }
        }
    } else {
        // When finger is outside the plot, hide the cursor and go to scaling mode.
        if (isMeasure) {
            graphView.hideCursor();
            switchMeasureAndScaleMode();
        }
    }
    return super.onTouchEvent(event);
}

From source file:org.medcare.Dicom.DicomActivity.java

/** Determine the space between the first two fingers */
private float spacing(MotionEvent event) {
    float x = event.getX(0) - event.getX(1);
    float y = event.getY(0) - event.getY(1);
    return FloatMath.sqrt(x * x + y * y);
}

From source file:org.medcare.Dicom.DicomActivity.java

/** Calculate the mid point of the first two fingers */
private void midPoint(PointF point, MotionEvent event) {
    float x = event.getX(0) + event.getX(1);
    float y = event.getY(0) + event.getY(1);
    point.set(x / 2, y / 2);/*  w  w  w  . ja va  2 s  . c  o m*/
}

From source file:com.android.incallui.widget.multiwaveview.GlowPadView.java

private void handleUp(MotionEvent event) {
    if (DEBUG && mDragging)
        Log.v(TAG, "** Handle RELEASE");
    int actionIndex = event.getActionIndex();
    if (event.getPointerId(actionIndex) == mPointerId) {
        switchToState(STATE_FINISH, event.getX(actionIndex), event.getY(actionIndex));
    }//w  w  w .ja v  a 2s .c  o  m
}

From source file:com.inmobi.ultrapush.AnalyzeActivity.java

private void scaleEvent(MotionEvent event) {
    if (event.getAction() != MotionEvent.ACTION_MOVE) {
        xShift0 = INIT;//w  w w.j  a  v  a 2s .  co  m
        yShift0 = INIT;
        isPinching = false;
        //      Log.i(TAG, "scaleEvent(): Skip event " + event.getAction());
        return;
    }
    //    Log.i(TAG, "scaleEvent(): switch " + event.getAction());
    switch (event.getPointerCount()) {
    case 2:
        if (isPinching) {
            graphView.setShiftScale(event.getX(0), event.getY(0), event.getX(1), event.getY(1));
        } else {
            graphView.setShiftScaleBegin(event.getX(0), event.getY(0), event.getX(1), event.getY(1));
        }
        isPinching = true;
        break;
    case 1:
        float x = event.getX(0);
        float y = event.getY(0);
        graphView.getLocationInWindow(windowLocation);
        //        Log.i(TAG, "scaleEvent(): xy=" + x + " " + y + "  wc = " + wc[0] + " " + wc[1]);
        if (isPinching || xShift0 == INIT) {
            xShift0 = graphView.getXShift();
            x0 = x;
            yShift0 = graphView.getYShift();
            y0 = y;
        } else {
            // when close to the axis, scroll that axis only
            if (x0 < windowLocation[0] + 50) {
                graphView.setYShift(yShift0 + (y0 - y) / graphView.getCanvasHeight() / graphView.getYZoom());
            } else if (y0 < windowLocation[1] + 50) {
                graphView.setXShift(xShift0 + (x0 - x) / graphView.getCanvasWidth() / graphView.getXZoom());
            } else {
                graphView.setXShift(xShift0 + (x0 - x) / graphView.getCanvasWidth() / graphView.getXZoom());
                graphView.setYShift(yShift0 + (y0 - y) / graphView.getCanvasHeight() / graphView.getYZoom());
            }
        }
        isPinching = false;
        break;
    default:
        Log.v(TAG, "Invalid touch count");
        break;
    }
}