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:com.android.cts.uiautomator.TestGenericDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    View rootView = inflater.inflate(R.layout.test_results_detail_fragment, container, false);
    if (mItem != null) {
        ((TextView) rootView.findViewById(R.id.testResultsTextView)).setText(mItem.mName);
    }//from  ww  w. j  a  v a2s.  co m

    // listen to touch events to verify the multiPointerGesture APIs
    // Since API Level 18
    rootView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
                // Reset any collected touch coordinate results on the primary touch down
                resetTouchResults();
                // collect this event
                collectStartAction(event, v, 0);
                break;

            case MotionEvent.ACTION_POINTER_DOWN:
                // collect this event
                collectStartAction(event, v, getPointerIndex(event));
                break;

            case MotionEvent.ACTION_POINTER_UP:
                // collect this event
                collectEndAction(event, v, getPointerIndex(event));
                break;

            case MotionEvent.ACTION_UP:
                // collect this event
                collectEndAction(event, v, 0);
                // on the primary touch up display results collected for all pointers
                displayTouchResults();
                break;
            }
            return true;
        }
    });

    return rootView;
}

From source file:com.shenma.yueba.view.imageshow.GalleryViewPager.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        super.onTouchEvent(event);
    }/*from   w ww.  ja v a 2 s.  co  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;
}

From source file:com.uroad.widget.GalleryViewPager.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        super.onTouchEvent(event);
    }//  ww  w. j  a  v  a2 s  .com

    float[] difference = handleMotionEvent(event);

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

    return false;
}

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

@Override
public boolean onTouchEvent(MotionEvent event) {
    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        super.onTouchEvent(event);
    }// www  .  ja  v a2s  .  c om

    float[] difference = handleMotionEvent(event);

    if (mCurrentView.pagerCanScroll()) {
        try {
            return super.onTouchEvent(event);
        } catch (Exception e) {

        }
    } 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;
}

From source file:cn.kylinhuang.play.view.CommonGestures.java

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

    if (null == event)
        return false;

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

    if (event.getPointerCount() > 1) {
        try {//from   ww  w.  j a  v  a 2s .c  o m
            if (mScaleDetector != null && mScaleDetector.onTouchEvent(event))
                return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

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

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_UP:
        mListener.onGestureEnd();
        break;
    }

    return true;
}

From source file:paulscode.android.mupen64plusae.game.GameDrawerLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    // Only intercept this touch event if it is not directly over a touchscreen input
    // (So the game sidebar is never accidentally triggered)

    int action = event.getAction();
    int actionCode = action & MotionEvent.ACTION_MASK;
    long currentEventTime = System.currentTimeMillis();

    boolean upAction = (actionCode == MotionEvent.ACTION_UP || actionCode == MotionEvent.ACTION_CANCEL
            || actionCode == MotionEvent.ACTION_POINTER_UP);

    // If the touch ended along the left edge, ignore edge swipes for a little while
    if (upAction) {
        int actionIndex = MotionEventCompat.getActionIndex(event);
        int xLocation = (int) event.getX(actionIndex);
        if (xLocation < 10)
            mLastEdgeTime = currentEventTime;
    }//w ww.  java 2 s . c  o m

    if (ignore.contains(event)) {
        if (upAction)
            ignore.remove(event);
        return false;
    } else if (actionCode == MotionEvent.ACTION_POINTER_DOWN
            || (actionCode == MotionEvent.ACTION_DOWN && currentEventTime - mLastEdgeTime < 250)) {
        // Ignore secondary inputs and inputs too close to the most recent one (0.25 seconds)
        ignore.add(event);
        return false;
    } else if (actionCode == MotionEvent.ACTION_DOWN && !isDrawerOpen(GravityCompat.START)
            && mTouchMap != null) {
        for (int i = 0; i < event.getPointerCount(); i++) {
            int xLocation = (int) event.getX(i);
            int yLocation = (int) event.getY(i);

            // See if it touches the d-pad or the C buttons,
            // as they are small enough to interfere with left edge swipes
            // (fortunately placing the C buttons on the left is unusual)
            int buttonIndex = mTouchMap.getButtonPress(xLocation, yLocation);
            if (buttonIndex != TouchMap.UNMAPPED) {
                if ("dpad".equals(TouchMap.ASSET_NAMES.get(buttonIndex))
                        || "groupC".equals(TouchMap.ASSET_NAMES.get(buttonIndex))) {
                    ignore.add(event);
                    return false;
                }
            }

            // See if it touches the analog stick
            Point point = mTouchMap.getAnalogDisplacement(xLocation, yLocation);

            int dX = point.x;
            int dY = point.y;
            float displacement = (float) Math.sqrt((dX * dX) + (dY * dY));

            // Add a slightly larger hit area around the analog stick,
            // by artificially shrinking the size of the displacement
            displacement = displacement * 0.9f;

            if (mTouchMap.isInCaptureRange(displacement)) {
                ignore.add(event);
                return false;
            }
        }
    }

    // Let the parent DrawerLayout deal with it
    try {
        return super.onInterceptTouchEvent(event);
    } catch (Exception ex) {
        // For some reason this is very prone to crashing here when using multitouch:
        // android.support.v4.widget.ViewDragHelper.shouldInterceptTouchEvent
        // But fortunately this is very unimportant, so we can safely ignore it
        // The source code is here if you want to attempt a fix:
        // https://github.com/android/platform_frameworks_support/blob/master/v4/java/android/support/v4/widget/ViewDragHelper.java
        return false;
    }
}

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

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    try {/*from  w ww  .j av  a2 s  . co  m*/
        if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
            super.onInterceptTouchEvent(event);
        }

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

        float[] difference = handleMotionEvent(event);

        if (difference != null && difference.length > 0 && mCurrentView.getOnRightSide() && difference[0] < 0) {
            return super.onInterceptTouchEvent(event);
        } else if (difference != null && difference.length > 0 && mCurrentView.getOnLeftSide()
                && difference[0] > 0) {
            return super.onInterceptTouchEvent(event);
        } else if ((difference == null || difference.length == 0)
                && (mCurrentView.getOnLeftSide() || mCurrentView.getOnRightSide())) {
            return super.onInterceptTouchEvent(event);
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }

    return false;
}

From source file:com.community.yuequ.player.CommonGestures.java

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

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

    if (event.getPointerCount() > 1) {
        try {/*from  ww  w . ja  va2s .  co  m*/
            if (mScaleDetector != null && mScaleDetector.onTouchEvent(event))
                return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

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

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_UP:
        mListener.onGestureEnd();
        break;
    }

    return false;
}

From source file:com.wangzhenzhe.library.GalleryWidget.GalleryViewPager.java

@Override
public boolean onTouchEvent(MotionEvent event) {

    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        super.onTouchEvent(event);
    }//from   w  w w  .  j av  a  2s  .  co  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;
}

From source file:com.fishstix.dosboxfree.ButtonLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);
    final int pointerIndex = MotionEventCompat.getActionIndex(ev);//((action & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT);
    final int pId = ev.getPointerId(pointerIndex) + 1;
    KeyEvent evt = null;// w ww . java2  s .  c  om
    Message msg = Message.obtain();
    msg.what = DBMain.HANDLER_SEND_KEYCODE;
    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_DOWN: {
        Log.i("DosBoxTurbo", "button onDown()");
        int x = (int) ev.getX(pointerIndex);//(int) mWrap.getX(ev,pointerIndex);
        int width = getWidth();
        //int y = (int) mWrap.getY(ev,pointerIndex);
        float val = ((float) x / (float) width) * 4f;
        if (val < 1.0) {
            // first button
            if (virtualbutton_hm.indexOfValue(HardCodeWrapper.KEYCODE_VIRTUAL_A) > 0)
                return false;
            evt = new KeyEvent(action, HardCodeWrapper.KEYCODE_VIRTUAL_A);
            virtualbutton_hm.put(pId, HardCodeWrapper.KEYCODE_VIRTUAL_A);
            msg.arg2 = HardCodeWrapper.KEYCODE_VIRTUAL_A;
            mDBLauncher.bButtonA.setBackgroundColor(0x80FF0000);
        } else if (val < 2.0) {
            if (virtualbutton_hm.indexOfValue(HardCodeWrapper.KEYCODE_VIRTUAL_B) > 0)
                return false;
            evt = new KeyEvent(action, HardCodeWrapper.KEYCODE_VIRTUAL_B);
            virtualbutton_hm.put(pId, HardCodeWrapper.KEYCODE_VIRTUAL_B);
            msg.arg2 = HardCodeWrapper.KEYCODE_VIRTUAL_B;
            mDBLauncher.bButtonB.setBackgroundColor(0x80FF0000);
        } else if (val < 3.0) {
            if (virtualbutton_hm.indexOfValue(HardCodeWrapper.KEYCODE_VIRTUAL_C) > 0)
                return false;
            evt = new KeyEvent(action, HardCodeWrapper.KEYCODE_VIRTUAL_C);
            virtualbutton_hm.put(pId, HardCodeWrapper.KEYCODE_VIRTUAL_C);
            msg.arg2 = HardCodeWrapper.KEYCODE_VIRTUAL_C;
            mDBLauncher.bButtonC.setBackgroundColor(0x80FF0000);
        } else {
            if (virtualbutton_hm.indexOfValue(HardCodeWrapper.KEYCODE_VIRTUAL_D) > 0)
                return false;
            evt = new KeyEvent(action, HardCodeWrapper.KEYCODE_VIRTUAL_D);
            virtualbutton_hm.put(pId, HardCodeWrapper.KEYCODE_VIRTUAL_D);
            msg.arg2 = HardCodeWrapper.KEYCODE_VIRTUAL_D;
            mDBLauncher.bButtonD.setBackgroundColor(0x80FF0000);
        }
        msg.obj = evt;
        msg.arg1 = 0;
        mDBLauncher.mSurfaceView.virtButton[pointerIndex] = true;
        mDBLauncher.mSurfaceView.mFilterLongClick = true; // prevent long click listener from getting in the way
        mDBLauncher.mHandler.sendMessage(msg);
        return true;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP: {
        Log.i("DosBoxTurbo", "button onUp()");
        msg.arg2 = virtualbutton_hm.get(pId);
        switch (msg.arg2) {
        case HardCodeWrapper.KEYCODE_VIRTUAL_A:
            mDBLauncher.bButtonA.setBackgroundColor(0x80FFFF00);
            break;
        case HardCodeWrapper.KEYCODE_VIRTUAL_B:
            mDBLauncher.bButtonB.setBackgroundColor(0x80FFFF00);
            break;
        case HardCodeWrapper.KEYCODE_VIRTUAL_C:
            mDBLauncher.bButtonC.setBackgroundColor(0x80FFFF00);
            break;
        case HardCodeWrapper.KEYCODE_VIRTUAL_D:
            mDBLauncher.bButtonD.setBackgroundColor(0x80FFFF00);
            break;
        }
        virtualbutton_hm.delete(pId);
        if (msg.arg2 == 0)
            return false;
        evt = new KeyEvent(action, msg.arg2);
        msg.obj = evt;
        msg.arg1 = 1;
        mDBLauncher.mSurfaceView.virtButton[pointerIndex] = false;
        mDBLauncher.mSurfaceView.mFilterLongClick = false;
        mDBLauncher.mHandler.sendMessage(msg);
        return true;
    }
    }
    return false;
}