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() 

Source Link

Document

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

Usage

From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java

@Override
public boolean onTouchEvent(MotionEvent me) {
    try {/*from   w  w  w .j  a v a2 s  . c  om*/
        killOnError(); // ?  ?

        //  ? x, y  
        float xPress = me.getX();
        float yPress = me.getY();

        // ?? ??  ?? ? ?? 
        if (me.getAction() == MotionEvent.ACTION_UP) {
            dataView.clickEvent(xPress, yPress);
        }

        return true;

    } catch (Exception ex) { //  
        //doError(ex);
        ex.printStackTrace();
        return super.onTouchEvent(me);
    }
}

From source file:android.widget.Gallery.java

@Override
public boolean onDown(MotionEvent e) {

    // Kill any existing fling/scroll
    mFlingRunnable.stop(false);/*from w  w w.  j a  va2s  .  c  o  m*/

    // Get the item's view that was touched
    mDownTouchPosition = pointToPosition((int) e.getX(), (int) e.getY());

    if (mDownTouchPosition >= 0) {
        mDownTouchView = getChildAt(mDownTouchPosition - mFirstPosition);
        mDownTouchView.setPressed(true);
    }

    // Reset the multiple-scroll tracking state
    mIsFirstScroll = true;

    // Must return true to get matching events for this down event.
    return true;
}

From source file:edu.sfsu.cs.orange.ocr.CaptureActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    checkFirstLaunch();// w ww. j a v  a 2s.  c  o m

    if (isFirstLaunch) {
        setDefaultPreferences();
    }

    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.capture);
    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    cameraButtonView = findViewById(R.id.camera_button_view);
    resultView = findViewById(R.id.result_view);

    statusViewBottom = (TextView) findViewById(R.id.status_view_bottom);
    registerForContextMenu(statusViewBottom);
    statusViewTop = (TextView) findViewById(R.id.status_view_top);
    registerForContextMenu(statusViewTop);

    handler = null;
    lastResult = null;
    hasSurface = false;
    beepManager = new BeepManager(this);

    // Camera shutter button
    if (DISPLAY_SHUTTER_BUTTON) {
        shutterButton = (ShutterButton) findViewById(R.id.shutter_button);
        shutterButton.setOnShutterButtonListener(this);
    }

    ocrResultView = (TextView) findViewById(R.id.ocr_result_text_view);
    registerForContextMenu(ocrResultView);
    translationView = (TextView) findViewById(R.id.translation_text_view);
    registerForContextMenu(translationView);

    progressView = (View) findViewById(R.id.indeterminate_progress_indicator_view);

    cameraManager = new CameraManager(getApplication());
    viewfinderView.setCameraManager(cameraManager);

    // Set listener to change the size of the viewfinder rectangle.
    viewfinderView.setOnTouchListener(new View.OnTouchListener() {
        int lastX = -1;
        int lastY = -1;

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                lastX = -1;
                lastY = -1;
                return true;
            case MotionEvent.ACTION_MOVE:
                int currentX = (int) event.getX();
                int currentY = (int) event.getY();

                try {
                    Rect rect = cameraManager.getFramingRect();

                    final int BUFFER = 50;
                    final int BIG_BUFFER = 60;
                    if (lastX >= 0) {
                        // Adjust the size of the viewfinder rectangle. Check if the touch event occurs in the corner areas first, because the regions overlap.
                        if (((currentX >= rect.left - BIG_BUFFER && currentX <= rect.left + BIG_BUFFER)
                                || (lastX >= rect.left - BIG_BUFFER && lastX <= rect.left + BIG_BUFFER))
                                && ((currentY <= rect.top + BIG_BUFFER && currentY >= rect.top - BIG_BUFFER)
                                        || (lastY <= rect.top + BIG_BUFFER
                                                && lastY >= rect.top - BIG_BUFFER))) {
                            // Top left corner: adjust both top and left sides
                            cameraManager.adjustFramingRect(2 * (lastX - currentX), 2 * (lastY - currentY));
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.right - BIG_BUFFER && currentX <= rect.right + BIG_BUFFER)
                                || (lastX >= rect.right - BIG_BUFFER && lastX <= rect.right + BIG_BUFFER))
                                && ((currentY <= rect.top + BIG_BUFFER && currentY >= rect.top - BIG_BUFFER)
                                        || (lastY <= rect.top + BIG_BUFFER
                                                && lastY >= rect.top - BIG_BUFFER))) {
                            // Top right corner: adjust both top and right sides
                            cameraManager.adjustFramingRect(2 * (currentX - lastX), 2 * (lastY - currentY));
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.left - BIG_BUFFER && currentX <= rect.left + BIG_BUFFER)
                                || (lastX >= rect.left - BIG_BUFFER && lastX <= rect.left + BIG_BUFFER))
                                && ((currentY <= rect.bottom + BIG_BUFFER
                                        && currentY >= rect.bottom - BIG_BUFFER)
                                        || (lastY <= rect.bottom + BIG_BUFFER
                                                && lastY >= rect.bottom - BIG_BUFFER))) {
                            // Bottom left corner: adjust both bottom and left sides
                            cameraManager.adjustFramingRect(2 * (lastX - currentX), 2 * (currentY - lastY));
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.right - BIG_BUFFER && currentX <= rect.right + BIG_BUFFER)
                                || (lastX >= rect.right - BIG_BUFFER && lastX <= rect.right + BIG_BUFFER))
                                && ((currentY <= rect.bottom + BIG_BUFFER
                                        && currentY >= rect.bottom - BIG_BUFFER)
                                        || (lastY <= rect.bottom + BIG_BUFFER
                                                && lastY >= rect.bottom - BIG_BUFFER))) {
                            // Bottom right corner: adjust both bottom and right sides
                            cameraManager.adjustFramingRect(2 * (currentX - lastX), 2 * (currentY - lastY));
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.left - BUFFER && currentX <= rect.left + BUFFER)
                                || (lastX >= rect.left - BUFFER && lastX <= rect.left + BUFFER))
                                && ((currentY <= rect.bottom && currentY >= rect.top)
                                        || (lastY <= rect.bottom && lastY >= rect.top))) {
                            // Adjusting left side: event falls within BUFFER pixels of left side, and between top and bottom side limits
                            cameraManager.adjustFramingRect(2 * (lastX - currentX), 0);
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.right - BUFFER && currentX <= rect.right + BUFFER)
                                || (lastX >= rect.right - BUFFER && lastX <= rect.right + BUFFER))
                                && ((currentY <= rect.bottom && currentY >= rect.top)
                                        || (lastY <= rect.bottom && lastY >= rect.top))) {
                            // Adjusting right side: event falls within BUFFER pixels of right side, and between top and bottom side limits
                            cameraManager.adjustFramingRect(2 * (currentX - lastX), 0);
                            viewfinderView.removeResultText();
                        } else if (((currentY <= rect.top + BUFFER && currentY >= rect.top - BUFFER)
                                || (lastY <= rect.top + BUFFER && lastY >= rect.top - BUFFER))
                                && ((currentX <= rect.right && currentX >= rect.left)
                                        || (lastX <= rect.right && lastX >= rect.left))) {
                            // Adjusting top side: event falls within BUFFER pixels of top side, and between left and right side limits
                            cameraManager.adjustFramingRect(0, 2 * (lastY - currentY));
                            viewfinderView.removeResultText();
                        } else if (((currentY <= rect.bottom + BUFFER && currentY >= rect.bottom - BUFFER)
                                || (lastY <= rect.bottom + BUFFER && lastY >= rect.bottom - BUFFER))
                                && ((currentX <= rect.right && currentX >= rect.left)
                                        || (lastX <= rect.right && lastX >= rect.left))) {
                            // Adjusting bottom side: event falls within BUFFER pixels of bottom side, and between left and right side limits
                            cameraManager.adjustFramingRect(0, 2 * (currentY - lastY));
                            viewfinderView.removeResultText();
                        }
                    }
                } catch (NullPointerException e) {
                    Log.e(TAG, "Framing rect not available", e);
                }
                v.invalidate();
                lastX = currentX;
                lastY = currentY;
                return true;
            case MotionEvent.ACTION_UP:
                lastX = -1;
                lastY = -1;
                return true;
            }
            return false;
        }
    });

    isEngineReady = false;
    aq = new AQuery(this);
    beerQuery = new BeerQuery();

}

From source file:com.android.widget.SlidingPaneLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    if (!mCanSlide || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) {
        mDragHelper.cancel();/*  w w w . j a  va  2 s . com*/
        return super.onInterceptTouchEvent(ev);
    }

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        mDragHelper.cancel();
        return false;
    }

    float x, y;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mIsUnableToDrag = false;
        x = ev.getX();
        y = ev.getY();
        mInitialMotionX = x;
        mInitialMotionY = y;
        break;
    case MotionEvent.ACTION_MOVE:
        x = ev.getX();
        y = ev.getY();
        final float adx = Math.abs(x - mInitialMotionX);
        final float ady = Math.abs(y - mInitialMotionY);
        final int slop = mDragHelper.getTouchSlop();
        if (ady > slop && adx > ady) {
            mDragHelper.cancel();
            mIsUnableToDrag = true;
            return false;
        }
    }

    final boolean interceptForDrag = mDragHelper.shouldInterceptTouchEvent(ev)
            // Intercept touch events only in the overhang area.
            && (ev.getY() <= mSlideOffset * mSlideRange + mOverhangSize && mState != STATE_OPENED_ENTIRELY);

    return interceptForDrag;
}

From source file:com.example.SmartBoard.DrawingView.java

public void onTouchTextMode(MotionEvent event) {
    int eventaction = event.getAction();

    int X = (int) event.getX();
    int Y = (int) event.getY();
    textPosX = X;//  w  w w . ja v  a 2 s. c  om
    textPosY = Y;

    if (isPlaced()) {
        return;
    }
    finished = true;

    // redraw the canvas
    invalidate();

    return;

}

From source file:com.example.SmartBoard.DrawingView.java

public void onTouchTextResizeEvent(MotionEvent event) {
    int eventaction = event.getAction();

    int X = (int) event.getX();
    int Y = (int) event.getY();
    textResizePosX = X;// www  .  j  av a 2 s. c o  m
    textResizePosY = Y;

    JSONObject touchedObject = getTouchedObject(X, Y);
    if (touchedObject != null) {

        try {

            //for text
            if (touchedObject.optString("type").compareTo("Text") == 0) {
                touchedObject.put("size", textViewSize);
                Bitmap bm = textToBitmap(touchedObject.optString("text"), touchedObject.optInt("color"),
                        touchedObject.optInt("x"), touchedObject.optInt("y"), textViewSize);
                touchedObject.put("textBitmap", mqtt.bitmapToString(bm));
            }
            mqtt.publishObject(touchedObject);
        } catch (JSONException e) {

        }
        invalidate();
    }
}

From source file:com.example.SmartBoard.DrawingView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    //detect user touch
    float touchX = event.getX();
    float touchY = event.getY();
    //System.out.println("X"+touchX);
    // System.out.println("Y"+touchY);

    if (rectMode) {
        onTouchRectangleMode(event);//from  w  w w.j  av  a2s .c om
        return true;
    } else if (circleMode) {
        onTouchCircleMode(event);
        return true;
    } else if (lineMode) {
        onTouchLineMode(event);
        return true;
    } else if (textMode) {
        onTouchTextMode(event);
        return true;
    } else if (dragMode) {
        onTouchDragEvent(event);
        return true;
    } else if (removeObjectMode) {
        onRemoveObjectEvent(event);
        return true;
    } else if (colorDropperMode) {
        onTouchColorDropperMode(event);
        return true;
    } else if (textSizeMode) {
        onTouchTextResizeEvent(event);
        return true;
    }

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        drawPath.moveTo(touchX, touchY);
        break;
    case MotionEvent.ACTION_MOVE:
        drawPath.lineTo(touchX, touchY);
        break;
    case MotionEvent.ACTION_UP:
        drawCanvas.drawPath(drawPath, drawPaint);
        drawPath.reset();
        break;
    default:
        return false;
    }
    //System.out.println(mqtt);

    invalidate();
    mqtt.publish(touchX, touchY, event.getAction(), paintColor, mode, strokeWidth);

    return true;
}

From source file:android.support.design.widget.BottomSheetBehavior.java

@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
    if (!child.isShown()) {
        mIgnoreEvents = true;//from  ww  w  .  j av  a 2  s . c o m
        return false;
    }
    int action = MotionEventCompat.getActionMasked(event);
    // Record the velocity
    if (action == MotionEvent.ACTION_DOWN) {
        reset();
    }
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(event);
    switch (action) {
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mTouchingScrollingChild = false;
        mActivePointerId = MotionEvent.INVALID_POINTER_ID;
        // Reset the ignore flag
        if (mIgnoreEvents) {
            mIgnoreEvents = false;
            return false;
        }
        break;
    case MotionEvent.ACTION_DOWN:
        int initialX = (int) event.getX();
        mInitialY = (int) event.getY();
        View scroll = mNestedScrollingChildRef.get();
        if (scroll != null && parent.isPointInChildBounds(scroll, initialX, mInitialY)) {
            mActivePointerId = event.getPointerId(event.getActionIndex());
            mTouchingScrollingChild = true;
        }
        mIgnoreEvents = mActivePointerId == MotionEvent.INVALID_POINTER_ID
                && !parent.isPointInChildBounds(child, initialX, mInitialY);
        break;
    }
    if (!mIgnoreEvents && mViewDragHelper.shouldInterceptTouchEvent(event)) {
        return true;
    }
    // We have to handle cases that the ViewDragHelper does not capture the bottom sheet because
    // it is not the top most view of its parent. This is not necessary when the touch event is
    // happening over the scrolling content as nested scrolling logic handles that case.
    View scroll = mNestedScrollingChildRef.get();
    return action == MotionEvent.ACTION_MOVE && scroll != null && !mIgnoreEvents && mState != STATE_DRAGGING
            && !parent.isPointInChildBounds(scroll, (int) event.getX(), (int) event.getY())
            && Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop();
}

From source file:cn.edu.zafu.easemob.imagecoverflow.CoverFlowView.java

private void touchEnded(MotionEvent event) {
    float pos = (event.getX() / mWidth) * MOVE_POS_MULTIPLE - 5;
    pos /= 2;/*w  w w. j  av  a2s  .  c  o  m*/

    if (mTouchMoved || (mOffset - Math.floor(mOffset)) != 0) {
        mStartOffset += mTouchStartPos - pos;
        mOffset = mStartOffset;

        mVelocity.addMovement(event);

        mVelocity.computeCurrentVelocity(1000);
        double speed = mVelocity.getXVelocity();

        speed = (speed / mWidth) * MOVE_SPEED_MULTIPLE;
        if (speed > MAX_SPEED)
            speed = MAX_SPEED;
        else if (speed < -MAX_SPEED)
            speed = -MAX_SPEED;

        startAnimation(-speed);
    } else {
        Log.e(VIEW_LOG_TAG, " touch ==>" + event.getX() + " , " + event.getY());
        if (mTouchRect != null) {
            if (mTouchRect.contains(event.getX(), event.getY()) && mCoverFlowListener != null
                    && topImageClickEnable && !mLongClickTriggled) {
                final int actuallyPosition = mTopImageIndex;

                mCoverFlowListener.topImageClicked(this, actuallyPosition);
            }
        }
    }

    mVelocity.clear();
    mVelocity.recycle();
}

From source file:com.abslyon.abetterselection.CoverFlow.CoverFlowView.java

private void touchEnded(MotionEvent event) {
    float pos = (event.getX() / mWidth) * MOVE_POS_MULTIPLE - 5;
    pos /= 2;//from  w w w.ja  v  a2s.  c o  m

    if (mTouchMoved || (mOffset - Math.floor(mOffset)) != 0) {
        mStartOffset += mTouchStartPos - pos;
        mOffset = mStartOffset;

        mVelocity.addMovement(event);

        mVelocity.computeCurrentVelocity(1000);
        double speed = mVelocity.getXVelocity();

        speed = (speed / mWidth) * MOVE_SPEED_MULTIPLE;
        if (speed > MAX_SPEED) {
            speed = MAX_SPEED;
        } else if (speed < -MAX_SPEED) {
            speed = -MAX_SPEED;
        }

        startAnimation(-speed);
    } else {
        Log.e(VIEW_LOG_TAG, " touch ==>" + event.getX() + " , " + event.getY());
        if (mTouchRect != null) {
            if (mTouchRect.contains(event.getX(), event.getY()) && mCoverFlowListener != null
                    && topImageClickEnable && !mLongClickTriggled) {
                final int actuallyPosition = mTopImageIndex;

                mCoverFlowListener.topImageClicked(this, actuallyPosition);
            }
        }
    }

    mVelocity.clear();
    mVelocity.recycle();
}