Example usage for android.view MotionEvent getX

List of usage examples for android.view MotionEvent getX

Introduction

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

Prototype

public final float getX() 

Source Link

Document

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

Usage

From source file:com.albedinsky.android.support.ui.HorizontalPullHelper.java

/**
 */
@Override
boolean hasTouchChanged(MotionEvent event) {
    return event.getX() != mTouchLastX;
}

From source file:ms.sujinkim.com.test.MjpegViewGestureDetector.java

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    boolean value = false;
    try {//from w ww . j a  v a2s . co m
        if (Math.abs(e1.getY() - e2.getY()) < FLING_MAX_OFF_PATH) {
            if (e1.getX() - e2.getX() > FLING_MIN_DISTANCE && Math.abs(velocityX) > FLING_VELOCITY_THRESHOLD) {
                onFlingLeft(e1.getX() - e2.getX());
            } else if (e2.getX() - e1.getX() > FLING_MIN_DISTANCE
                    && Math.abs(velocityX) > FLING_VELOCITY_THRESHOLD) {
                onFlingRight(e2.getX() - e1.getX());
            }
            value = true;
        } else if (Math.abs(e1.getX() - e2.getX()) < FLING_MAX_OFF_PATH) {
            if (e1.getY() - e2.getY() > FLING_MIN_DISTANCE && Math.abs(velocityY) > FLING_VELOCITY_THRESHOLD) {
                onFlingUp(e1.getY() - e2.getY());
            } else if (e2.getY() - e1.getY() > FLING_MIN_DISTANCE
                    && Math.abs(velocityY) > FLING_VELOCITY_THRESHOLD) {
                onFlingDown(e2.getY() - e1.getY());
            }
            value = true;
        }
    } catch (Exception e) {
        /* Do nothing */
    }
    return value;
}

From source file:com.albedinsky.android.support.ui.HorizontalPullHelper.java

/**
 * Updates a value of the last touch X coordinate from the specified motion <var>event</var>.
 *
 * @param event The motion event from which to obtain X coordinate.
 */// w ww.  ja  va 2 s  .  c  o  m
private void updateTouchLastX(MotionEvent event) {
    this.mTouchLastX = event.getX();
}

From source file:android.support.v13.view.DragStartHelper.java

/**
 * Handle a touch event./*from  w w  w  . j  a va 2 s  .  c o m*/
 * @param v The view the touch event has been dispatched to.
 * @param event The MotionEvent object containing full information about
 *        the event.
 * @return True if the listener has consumed the event, false otherwise.
 */
public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
        mLastTouchX = (int) event.getX();
        mLastTouchY = (int) event.getY();
    }
    if (event.getAction() == MotionEvent.ACTION_MOVE
            && MotionEventCompat.isFromSource(event, InputDeviceCompat.SOURCE_MOUSE)
            && (MotionEventCompat.getButtonState(event) & MotionEventCompat.BUTTON_PRIMARY) != 0) {
        return mListener.onDragStart(v, this);
    }
    return false;
}

From source file:cn.goodjobs.common.view.photodraweeview.ScaleDragDetector.java

private float getActiveX(MotionEvent ev) {
    try {/*from  www  .j a v  a 2s.  c  o m*/
        return MotionEventCompat.getX(ev, mActivePointerIndex);
    } catch (Exception e) {
        return ev.getX();
    }
}

From source file:com.albedinsky.android.support.ui.HorizontalPullHelper.java

/**
 *///from w ww .  jav  a 2  s .  com
@Override
float computePullOffset(MotionEvent event) {
    final float delta = event.getX() - mTouchLastX;
    final float absDelta = Math.abs(delta);
    // Remove the shaking effect during slow pull.
    switch (mState) {
    case STATE_PULLING_AT_START:
        if ((mExpandingPull && delta < 0 && absDelta < mMinDeltaToChangePullDirection)
                || (!mExpandingPull && delta > 0 && absDelta < mMinDeltaToChangePullDirection)) {
            this.mExpandingPull = mTouchLastX < event.getX();
            return 0;
        }
        this.mExpandingPull = mTouchLastX < event.getX();
        break;
    case STATE_PULLING_AT_END:
        if ((mExpandingPull && delta > 0 && absDelta < mMinDeltaToChangePullDirection)
                || (!mExpandingPull && delta < 0 && absDelta < mMinDeltaToChangePullDirection)) {
            this.mExpandingPull = mTouchLastX > event.getX();
            return 0;
        }
        this.mExpandingPull = mTouchLastX > event.getX();
    }
    return Math.min(absDelta, mMaxPullDelta) * (delta > 0 ? 1 : -1);
}

From source file:com.nextgis.maplibui.formcontrol.Sign.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {

    float x = event.getX();
    float y = event.getY();

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if (!mNotInitialized)
            touchStart(x, y);/*from  w w  w  .j  ava 2s .c  om*/
        break;

    case MotionEvent.ACTION_MOVE:
        if (!mNotInitialized) {
            touchMove(x, y);
            postInvalidate();
        }
        break;

    case MotionEvent.ACTION_UP:
        int posX = getWidth() - mClearImageSize - mClearBuff;
        //Log.d(Constants.TAG, "x: " + event.getX() + " y: " + event.getY() + " posX: " + posX + " posY: " + mClearBuff);
        if (event.getX() > posX && event.getY() < mClearImageSize + mClearBuff) {
            onClearSign();
        } else if (!mNotInitialized) {
            touchUp();
            invalidate();
        }
        break;

    default:
        break;
    }

    return true;
}

From source file:com.android.hareime.accessibility.AccessibleKeyboardViewProxy.java

/**
 * Receives hover events when accessibility is turned on in SDK versions ICS
 * and higher./*from w w w .j av  a 2 s.c om*/
 *
 * @param event The hover event.
 * @return {@code true} if the event is handled
 */
public boolean dispatchHoverEvent(MotionEvent event, PointerTracker tracker) {
    final int x = (int) event.getX();
    final int y = (int) event.getY();
    final Key key = tracker.getKeyOn(x, y);
    final Key previousKey = mLastHoverKey;

    mLastHoverKey = key;

    switch (event.getAction()) {
    case MotionEvent.ACTION_HOVER_EXIT:
        // Make sure we're not getting an EXIT event because the user slid
        // off the keyboard area, then force a key press.
        if (pointInView(x, y) && (key != null)) {
            getAccessibilityNodeProvider().simulateKeyPress(key);
        }
        //$FALL-THROUGH$
    case MotionEvent.ACTION_HOVER_ENTER:
        return onHoverKey(key, event);
    case MotionEvent.ACTION_HOVER_MOVE:
        if (key != previousKey) {
            return onTransitionKey(key, previousKey, event);
        } else {
            return onHoverKey(key, event);
        }
    }

    return false;
}

From source file:com.albedinsky.android.support.ui.HorizontalPullHelper.java

/**
 */// ww w  . jav a 2  s.co  m
@Override
boolean shouldExpandPull(MotionEvent event) {
    switch (mState) {
    case STATE_PULLING_AT_START:
        return event.getX() > mTouchLastX;
    case STATE_PULLING_AT_END:
        return event.getX() < mTouchLastX;
    }
    return false;
}

From source file:com.albedinsky.android.support.ui.HorizontalPullHelper.java

/**
 *///from  w w w. jav  a  2 s. c o  m
@Override
boolean shouldCollapsePull(MotionEvent event) {
    switch (mState) {
    case STATE_PULLING_AT_START:
        return event.getX() < mTouchLastX;
    case STATE_PULLING_AT_END:
        return event.getX() > mTouchLastX;
    }
    return false;
}