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.android.gallery3d.v5.filtershow.category.CategoryView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    boolean ret = super.onTouchEvent(event);
    FilterShowActivity activity = (FilterShowActivity) getContext();

    if (event.getActionMasked() == MotionEvent.ACTION_UP) {
        activity.startTouchAnimation(this, event.getX(), event.getY());
    }// www .  j a v  a 2  s  . co  m
    if (!canBeRemoved()) {
        return ret;
    }
    if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
        mStartTouchY = event.getY();
        mStartTouchX = event.getX();
    }
    if (event.getActionMasked() == MotionEvent.ACTION_UP) {
        setTranslationX(0);
        setTranslationY(0);
    }
    if (event.getActionMasked() == MotionEvent.ACTION_MOVE) {
        float delta = event.getY() - mStartTouchY;
        if (getOrientation() == CategoryView.VERTICAL) {
            delta = event.getX() - mStartTouchX;
        }
        if (Math.abs(delta) > mDeleteSlope) {
            activity.setHandlesSwipeForView(this, mStartTouchX, mStartTouchY);
        }
    }
    return true;
}

From source file:com.baoyz.dribble.widget.SuperRecyclerView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent e) {

    boolean b = super.onInterceptTouchEvent(e);

    int actionMasked = MotionEventCompat.getActionMasked(e);
    switch (actionMasked) {
    case MotionEvent.ACTION_DOWN:
        mDownX = e.getX();
        mDownY = e.getY();//from   w  w w  .j a v a  2s. c o m
        mInterceptTouch = false;
        break;
    case MotionEvent.ACTION_MOVE:
        float offsetX = e.getX() - mDownX;
        if (!b && Math.abs(offsetX) > mTouchDistance)
            mInterceptTouch = true;
        break;
    }

    if (mInterceptTouch)
        return false;

    return b;
}

From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterListView.java

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {

    final float x = ev.getX();
    final float y = ev.getY();
    final int action = ev.getAction();

    if (action == MotionEvent.ACTION_DOWN && touchTarget == null && stickyWrapper != null
            && isStickyViewTouched(stickyWrapper.view, x, y)) {
        touchTarget = stickyWrapper.view;
        touchPt.x = x;/*from w w  w  . j  a  v a 2  s .c  om*/
        touchPt.y = y;

        downEvent = MotionEvent.obtain(ev);
    }

    if (touchTarget != null) {
        if (isStickyViewTouched(touchTarget, x, y)) {
            // forward event to header view
            touchTarget.dispatchTouchEvent(ev);
        }

        if (action == MotionEvent.ACTION_UP) {
            super.dispatchTouchEvent(ev);
            clearTouchTarget();

        } else if (action == MotionEvent.ACTION_CANCEL) {
            clearTouchTarget();

        } else if (action == MotionEvent.ACTION_MOVE) {
            if (Math.abs(y - touchPt.y) > touchSlop) {

                MotionEvent event = MotionEvent.obtain(ev);
                event.setAction(MotionEvent.ACTION_CANCEL);
                touchTarget.dispatchTouchEvent(event);
                event.recycle();

                super.dispatchTouchEvent(downEvent);
                super.dispatchTouchEvent(ev);
                clearTouchTarget();

            }
        }

        return true;
    }

    return super.dispatchTouchEvent(ev);
}

From source file:cn.edu.zafu.easemob.CoverFlowLib.VelocityViewPager.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    // give all the events to the gesture detector. I'm returning true here so the viewpager doesn't
    // get any events at all, I'm sure you could adjust this to make that not true.
    mGestureDetector.onTouchEvent(event);

    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        downX = event.getX();
    } else if (event.getAction() == MotionEvent.ACTION_UP) {
        onUp(event.getX() - downX);//from   w  ww .j av  a 2  s  .co  m
    }
    return true;
}

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

@Override
public boolean onTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mMotionPosition = pointToPosition((int) ev.getX(), (int) ev.getY());
        break;/*from  w w  w  . jav a  2 s.co  m*/
    }
    return super.onTouchEvent(ev);
}

From source file:it.angrydroids.epub3reader.TextSelectionSupport.java

@Override
public boolean onTouch(View v, MotionEvent event) {

    final Context ctx = mActivity;
    float xPoint = getDensityIndependentValue(event.getX(), ctx) / getDensityIndependentValue(mScale, ctx);
    float yPoint = getDensityIndependentValue(event.getY(), ctx) / getDensityIndependentValue(mScale, ctx);

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        final String startTouchUrl = String.format("javascript:android.selection.startTouch(%f, %f);", xPoint,
                yPoint);// w ww. j  a  va2 s  .  c om
        mLastTouchX = xPoint;
        mLastTouchY = yPoint;
        mWebView.loadUrl(startTouchUrl);
        break;
    case MotionEvent.ACTION_UP:
        if (!mScrolling) {
            endSelectionMode();
            //
            // Fixes 4.4 double selection
            // See:
            // http://stackoverflow.com/questions/20391783/how-to-avoid-default-selection-on-long-press-in-android-kitkat-4-4
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                return false;
            }
        }
        mScrollDiffX = 0;
        mScrollDiffY = 0;
        mScrolling = false;
        //
        // Fixes 4.4 double selection
        // See:
        // http://stackoverflow.com/questions/20391783/how-to-avoid-default-selection-on-long-press-in-android-kitkat-4-4
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            return true;
        }
        break;
    case MotionEvent.ACTION_MOVE:
        mScrollDiffX += (xPoint - mLastTouchX);
        mScrollDiffY += (yPoint - mLastTouchY);
        mLastTouchX = xPoint;
        mLastTouchY = yPoint;
        if (Math.abs(mScrollDiffX) > SCROLLING_THRESHOLD || Math.abs(mScrollDiffY) > SCROLLING_THRESHOLD) {
            mScrolling = true;
        }
        break;
    }

    return false;
}

From source file:com.android.andryyu.lifehelper.widget.RippleView.java

/**
 * Launch Ripple animation for the current view with a MotionEvent
 *
 * @param event MotionEvent registered by the Ripple gesture listener
 *///from   w w w.ja v a  2  s  .  c o  m
public void animateRipple(MotionEvent event) {
    createAnimation(event.getX(), event.getY());
}

From source file:com.baiiu.commontool.view.SwipeBackLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    boolean handled = false;
    ensureTarget();/*  w  w w  . ja  va 2 s  .com*/
    mLeft = (int) ev.getX();

    if (isEnabled()) {
        handled = viewDragHelper.shouldInterceptTouchEvent(ev);
    } else {
        viewDragHelper.cancel();
    }
    return !handled ? super.onInterceptTouchEvent(ev) : handled;
}

From source file:cn.smile.widget.SwipeBackLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    boolean handled = false;
    ensureTarget();/*from w ww. j  ava2 s. co m*/
    if (isEnabled()) {
        if (ev.getX() < 100)//x<100,??
            handled = viewDragHelper.shouldInterceptTouchEvent(ev);
    } else {
        viewDragHelper.cancel();
    }
    return !handled ? super.onInterceptTouchEvent(ev) : handled;
}

From source file:com.easemob.helpdeskdemo.ui.SatisfactionActivity.java

private boolean isShouldHideInput(View v, MotionEvent event) {
    if (v != null && (v instanceof EditText)) {
        int[] leftTop = { 0, 0 };
        // ??location?
        v.getLocationInWindow(leftTop);//from   w w w . j  a  va 2s. c om
        int left = leftTop[0];
        int top = leftTop[1];
        int bottom = top + v.getHeight();
        int right = left + v.getWidth();
        if (event.getX() > left && event.getX() < right && event.getY() > top && event.getY() < bottom) {
            // ?EditText
            return false;
        } else {
            return true;
        }
    }
    return false;
}