Example usage for android.view MotionEvent ACTION_MASK

List of usage examples for android.view MotionEvent ACTION_MASK

Introduction

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

Prototype

int ACTION_MASK

To view the source code for android.view MotionEvent ACTION_MASK.

Click Source Link

Document

Bit mask of the parts of the action code that are the action itself.

Usage

From source file:Main.java

public static String getMotionEventString(int action) {
    switch (action) {
    case (MotionEvent.ACTION_DOWN):
        return "action_down";
    case (MotionEvent.ACTION_UP):
        return "action_down";
    case (MotionEvent.ACTION_CANCEL):
        return "action_down";
    case (MotionEvent.ACTION_MOVE):
        return "action_move";
    case (MotionEvent.ACTION_OUTSIDE):
        return "action_outside";
    case (MotionEvent.ACTION_HOVER_ENTER):
        return "action_hover_enter";
    case (MotionEvent.ACTION_HOVER_EXIT):
        return "action_hover_exit";
    case (MotionEvent.ACTION_HOVER_MOVE):
        return "action_hover_move";
    case (MotionEvent.ACTION_MASK):
        return "action_mask";
    }/*w  w  w .ja  v  a 2 s  .c  om*/
    return "unknown action event";
}

From source file:org.telegram.ui.Views.GalleryViewPager.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    try {//from w  ww  . jav  a2s.c  om
        if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
            super.onTouchEvent(event);
        }

        if (mCurrentView == null) {
            return super.onTouchEvent(event);
        }

        float[] difference = handleMotionEvent(event);

        if (difference != null && mCurrentView.getOnRightSide() && difference[0] < 0) {
            return super.onTouchEvent(event);
        } else if (difference != null && mCurrentView.getOnLeftSide() && difference[0] > 0) {
            return super.onTouchEvent(event);
        } else if (difference == null && (mCurrentView.getOnLeftSide() || mCurrentView.getOnRightSide())) {
            return super.onTouchEvent(event);
        }

        return false;
    } catch (Exception e) {
        try {
            getAdapter().notifyDataSetChanged();
        } catch (Exception e2) {
            e2.printStackTrace();
        }
        FileLog.e("tmessages", e);
    }

    return false;
}

From source file:cn.limc.androidcharts.event.SlipGestureDetector.java

public boolean onTouchEvent(MotionEvent event) {
    int pointers = event.getPointerCount();
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    // ?/*from w  w  w .  j a va2 s .  c o m*/
    case MotionEvent.ACTION_DOWN:
        initalX = event.getX();
        if (pointers > 1) {
            touchMode = TOUCH_MODE_MULTI;
        } else {
            touchMode = TOUCH_MODE_SINGLE;
        }
        break;
    case MotionEvent.ACTION_UP:
        startPointA = null;
        startPointB = null;
        break;
    case MotionEvent.ACTION_POINTER_UP:
        startPointA = null;
        startPointB = null;
    case MotionEvent.ACTION_POINTER_DOWN:
        olddistance = calcDistance(event);
        if (olddistance > MIN_DISTANCE) {
            touchMode = TOUCH_MODE_MULTI;
            startPointA = new PointF(event.getX(0), event.getY(0));
            startPointB = new PointF(event.getX(1), event.getY(1));
        }
        return true;
    case MotionEvent.ACTION_MOVE:
        if (touchMode == TOUCH_MODE_SINGLE) {
            final float finalX = event.getX();
            // MotionEvent finalEvent = event;
            if (performLongClick) {
                return super.onTouchEvent(event);
            } else {
                if (finalX - initalX >= mStickScaleValue) {
                    if (onSlipGestureListener != null) {
                        onSlipGestureListener.onMoveRight((ISlipable) instance, event);
                    }
                } else if (initalX - finalX >= mStickScaleValue) {
                    if (onSlipGestureListener != null) {
                        onSlipGestureListener.onMoveLeft((ISlipable) instance, event);
                    }
                }
                initalX = finalX;
                // initalEvent = finalEvent;
                return true;
            }
        } else if (touchMode == TOUCH_MODE_MULTI) {
            newdistance = calcDistance(event);
            if (Math.abs(newdistance - olddistance) > MIN_DISTANCE) {
                if (onZoomGestureListener != null) {
                    if (newdistance > olddistance) {
                        onZoomGestureListener.onZoomIn((IZoomable) instance, event);
                    } else {
                        onZoomGestureListener.onZoomOut((IZoomable) instance, event);
                    }
                }
            }
            olddistance = newdistance;
            return true;
            // startPointA = new PointF(event.getX(), event.getY());
            // startPointB = new PointF(event.getX(1), event.getY(1));
        }
        break;
    }
    return super.onTouchEvent(event);
}

From source file:com.android.audiorecorder.gallery.widget.GalleryViewPager.java

private float[] handleMotionEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        last = new PointF(event.getX(0), event.getY(0));
        break;//from w w  w. java2 s. c o m
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_UP:
        PointF curr = new PointF(event.getX(0), event.getY(0));
        return new float[] { curr.x - last.x, curr.y - last.y };

    }
    return null;
}

From source file:com.xgleng.androiddemo.touchscreen.CommonGestures.java

public boolean onTouchEvent(MotionEvent event) {
    if (mListener == null)
        return false;

    if (mTapGestureDetector.onTouchEvent(event))
        return true;

    if (event.getPointerCount() > 1) {
        if (mScaleDetector != null && mScaleDetector.onTouchEvent(event)) {
            return true;
        }//from ww w.j a  v a2s.  co m
    }

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_UP:
        mIsFristScroll = true;
        if (mIsScrolling) {
            mListener.onGestureEnd();
            if (Math.abs(event.getY() - mDownY) > Math.abs(event.getX() - mDownX)) {
                mListener.onVerticalScrollEnd();
            } else {
                mListener.onHorizontalScrollEnd();
            }
        }
        break;
    }
    return false;
}

From source file:com.facebook.react.uimanager.events.TouchEvent.java

private void init(int viewTag, long timestampMs, TouchEventType touchEventType, MotionEvent motionEventToCopy,
        float viewX, float viewY) {
    super.init(viewTag, timestampMs);

    short coalescingKey = 0;
    int action = (motionEventToCopy.getAction() & MotionEvent.ACTION_MASK);
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        TouchEventCoalescingKeyHelper.addCoalescingKey(motionEventToCopy.getDownTime());
        break;/*www .j  ava2  s.c o  m*/
    case MotionEvent.ACTION_UP:
        TouchEventCoalescingKeyHelper.removeCoalescingKey(motionEventToCopy.getDownTime());
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
    case MotionEvent.ACTION_POINTER_UP:
        TouchEventCoalescingKeyHelper.incrementCoalescingKey(motionEventToCopy.getDownTime());
        break;
    case MotionEvent.ACTION_MOVE:
        coalescingKey = TouchEventCoalescingKeyHelper.getCoalescingKey(motionEventToCopy.getDownTime());
        break;
    case MotionEvent.ACTION_CANCEL:
        TouchEventCoalescingKeyHelper.removeCoalescingKey(motionEventToCopy.getDownTime());
        break;
    default:
        throw new RuntimeException("Unhandled MotionEvent action: " + action);
    }
    mTouchEventType = touchEventType;
    mMotionEvent = MotionEvent.obtain(motionEventToCopy);
    mCoalescingKey = coalescingKey;
    mViewX = viewX;
    mViewY = viewY;
}

From source file:com.putao.widget.touchgallery.GalleryWidget.GalleryViewPager.java

@TargetApi(Build.VERSION_CODES.ECLAIR)
private float[] handleMotionEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        last = new PointF(event.getX(0), event.getY(0));
        break;//from   w w w .  j ava2s.  c  o m
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_UP:
        PointF curr = new PointF(event.getX(0), event.getY(0));
        return new float[] { curr.x - last.x, curr.y - last.y };
    }
    return null;
}

From source file:cn.dreamtobe.touchgallery.GalleryWidget.GalleryViewPager.java

@TargetApi(Build.VERSION_CODES.ECLAIR)
private float[] handleMotionEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        last = new PointF(event.getX(0), event.getY(0));
        break;/*from  w  w  w  .  jav a  2 s  .c  om*/
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_UP:
        PointF curr = new PointF(event.getX(0), event.getY(0));
        return new float[] { curr.x - last.x, curr.y - last.y };

    }
    return null;
}

From source file:cn.iotguard.GalleryWidget.GalleryViewPager.java

private float[] handleMotionEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        last = new PointF(event.getX(0), event.getY(0));
        ///*from   ww w .j  a  v  a 2 s  .  c om*/
        if (GalleryFileActivity.ll_dibumenu != null
                && GalleryFileActivity.ll_dibumenu.getVisibility() == View.GONE) {
            GalleryFileActivity.ll_dibumenu.setVisibility(View.VISIBLE);
        }
        if (Show_bigpic2.ll_dibumenu != null && Show_bigpic2.ll_dibumenu.getVisibility() == View.GONE) {
            Show_bigpic2.ll_dibumenu.setVisibility(View.VISIBLE);
        }

        //
        if (GalleryFileActivity.timeCount != null) {
            GalleryFileActivity.timeCount.cancel();
        }
        GalleryFileActivity.timeCount = new TimeCount_pic_dibu(Millis.pic_dibus, 1000);
        GalleryFileActivity.timeCount.start();
        System.out.println("pic    ");
        if (Show_bigpic2.timeCount != null) {
            Show_bigpic2.timeCount.cancel();
        }
        Show_bigpic2.timeCount = new TimeCount_pic_dibu_showbigpic2(Millis.pic_dibus, 1000);
        Show_bigpic2.timeCount.start();

        break;
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_UP:
        PointF curr = new PointF(event.getX(0), event.getY(0));
        return new float[] { curr.x - last.x, curr.y - last.y };

    }
    return null;
}

From source file:com.gdestiny.resume.view.touchgallery.GalleryViewPager.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        super.onTouchEvent(event);
    }/*from  ww  w  .  j  av  a 2  s  .  c o m*/

    float[] difference = handleMotionEvent(event);

    if (mCurrentView.pagerCanScroll()) {
        return super.onTouchEvent(event);
    } else {
        if (difference != null && mCurrentView.onRightSide && difference[0] < 0) // move right
        {
            return super.onTouchEvent(event);
        }
        if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) // move left
        {
            return super.onTouchEvent(event);
        }
        if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) {
            return super.onTouchEvent(event);
        }
    }

    return false;
}