Java Code Examples for android.view.MotionEvent#ACTION_MASK

The following examples show how to use android.view.MotionEvent#ACTION_MASK . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PLManager.java    From panoramagl with Apache License 2.0 6 votes vote down vote up
public boolean onTouchEvent(MotionEvent event) {
    if (mIsRendererCreated && mRenderer.isRunning() && !mIsValidForTransition) {
        if (mGestureDetector.onTouchEvent(event))
            return true;
        switch (event.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_POINTER_DOWN:
                this.touchesBegan(this.getTouches(event), event);
                return true;
            case MotionEvent.ACTION_MOVE:
                this.touchesMoved(this.getTouches(event), event);
                return true;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_POINTER_UP:
                this.touchesEnded(this.getTouches(event), event);
                return true;
        }
    }
    return false;
}
 
Example 2
Source File: ImageViewTouch.java    From fanfouapp-opensource with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onTouchEvent(final MotionEvent event) {
    this.mScaleDetector.onTouchEvent(event);
    if (!this.mScaleDetector.isInProgress()) {
        this.mGestureDetector.onTouchEvent(event);
    }
    final int action = event.getAction();
    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_UP:
        if (getScale() < 1f) {
            zoomTo(1f, 50);
        }
        break;
    }
    return true;
}
 
Example 3
Source File: PongGame.java    From Learning-Java-by-Building-Android-Games-Second-Edition with MIT License 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent motionEvent) {

    // This switch block replaces the
    // if statement from the Sub Hunter game
    switch (motionEvent.getAction() &
            MotionEvent.ACTION_MASK) {

        // The player has put their finger on the screen
        case MotionEvent.ACTION_DOWN:

            // If the game was paused unpause
            mPaused = false;

            // Where did the touch happen
            if(motionEvent.getX() > mScreenX / 2){
                // On the right hand side
                mBat.setMovementState(mBat.RIGHT);
            }
            else{
                // On the left hand side
                mBat.setMovementState(mBat.LEFT);
            }

            break;

        // The player lifted their finger
        // from anywhere on screen.
        // It is possible to create bugs by using
        // multiple fingers. We will use more
        // complicated and robust touch handling
        // in later projects
        case MotionEvent.ACTION_UP:

            // Stop the bat moving
            mBat.setMovementState(mBat.STOPPED);
            break;
    }
    return true;
}
 
Example 4
Source File: StickyListHeadersListView.java    From Swface with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    int action = ev.getAction() & MotionEvent.ACTION_MASK;
    if (action == MotionEvent.ACTION_DOWN) {
        mDownY = ev.getY();
        mHeaderOwnsTouch = mHeader != null && mDownY <= mHeader.getHeight() + mHeaderOffset;
    }

    boolean handled;
    if (mHeaderOwnsTouch) {
        if (mHeader != null && Math.abs(mDownY - ev.getY()) <= mTouchSlop) {
            handled = mHeader.dispatchTouchEvent(ev);
        } else {
            if (mHeader != null) {
                MotionEvent cancelEvent = MotionEvent.obtain(ev);
                cancelEvent.setAction(MotionEvent.ACTION_CANCEL);
                mHeader.dispatchTouchEvent(cancelEvent);
                cancelEvent.recycle();
            }

            MotionEvent downEvent = MotionEvent.obtain(ev.getDownTime(), ev.getEventTime(), ev.getAction(), ev.getX(), mDownY, ev.getMetaState());
            downEvent.setAction(MotionEvent.ACTION_DOWN);
            handled = mList.dispatchTouchEvent(downEvent);
            downEvent.recycle();
            mHeaderOwnsTouch = false;
        }
    } else {
        handled = mList.dispatchTouchEvent(ev);
    }

    return handled;
}
 
Example 5
Source File: TwoLevelSmoothRefreshLayout.java    From SmoothRefreshLayout with MIT License 5 votes vote down vote up
@Override
protected boolean processDispatchTouchEvent(MotionEvent ev) {
    if (mAutoHintCanBeInterrupted) {
        mNeedFilterRefreshEvent = false;
        mDurationToStayAtHint = 0;
        final int action = ev.getAction() & MotionEvent.ACTION_MASK;
        if (action == MotionEvent.ACTION_DOWN) removeCallbacks(mDelayToBackToTopRunnable);
    }
    return super.processDispatchTouchEvent(ev);
}
 
Example 6
Source File: BaseGestureDetector.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
/**
* All gesture detectors need to be called through this method to be able to
* detect gestures. This method delegates work to handler methods
* (handleStartProgressEvent, handleInProgressEvent) implemented in
* extending classes.
* 
* @param event
* @return
*/
  public boolean onTouchEvent(MotionEvent event){
  	final int actionCode = event.getAction() & MotionEvent.ACTION_MASK;
  	if (!mGestureInProgress) {
  		handleStartProgressEvent(actionCode, event);
  	} else {
  		handleInProgressEvent(actionCode, event);
  	}
  	return true;
  }
 
Example 7
Source File: ScrollAndScaleView.java    From kAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            touch = true;
            break;
        case MotionEvent.ACTION_MOVE:
            if (event.getPointerCount() == 1) {
                //长按之后移动
                if (isLongPress || !isClosePress) {
                    onLongPress(event);
                }
            }
            break;
        case MotionEvent.ACTION_POINTER_UP:
            invalidate();
            break;
        case MotionEvent.ACTION_UP:
            if (!isClosePress) {
                isLongPress = false;
            }
            touch = false;
            invalidate();
            break;
        case MotionEvent.ACTION_CANCEL:
            if (!isClosePress) {
                isLongPress = false;
            }
            touch = false;
            invalidate();
            break;
    }
    mMultipleTouch = event.getPointerCount() > 1;
    this.mDetector.onTouchEvent(event);
    this.mScaleDetector.onTouchEvent(event);
    return true;
}
 
Example 8
Source File: DrawView.java    From 8bitartist with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouch(View arg0, MotionEvent me) {
    if (!touchEnabled) {
        return false;
    }

    switch (me.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_MOVE:
            // Find where the touch event, which is in pixels, maps
            // to our 10x10 grid. (0,0) is in the upper left, (9, 9)
            // is in the lower right.
            int gridX = (int) Math.floor(1.0 * me.getX() / mHeightInPixels
                    * GRID_SIZE);
            int gridY = (int) Math.floor(1.0 * me.getY() / mHeightInPixels
                    * GRID_SIZE);

            Log.d(TAG, "You touched " + gridX + " " + gridY + "/" + me.getY());

            if (gridX < GRID_SIZE && gridY < GRID_SIZE && gridX >= 0
                    && gridY >= 0) {

                short oldColor = grid[gridX][gridY];
                grid[gridX][gridY] = mSelectedColor;

                // Don't double-draw or send messages where the color does not change
                boolean notSameSpot = (lastGridX != gridX) || (lastGridY != gridY);
                boolean notSameColor = oldColor != mSelectedColor;
                if (notSameSpot && notSameColor) {
                    mListener.onDrawEvent(gridX, gridY, mSelectedColor);
                    lastGridX = gridX;
                    lastGridY = gridY;
                }
            }

            return true;
    }

    return false;
}
 
Example 9
Source File: FreeScrollingTextField.java    From CodeEditor with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (isFocused()) {
        _navMethod.onTouchEvent(event);
    } else {
        if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP
                && isPointInView((int) event.getX(), (int) event.getY())) {
            // somehow, the framework does not automatically change the focus
            // to this view when it is touched
            requestFocus();
        }
    }
    return true;
}
 
Example 10
Source File: MinuteChartView.java    From KChartView with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
    this.mDetector.onTouchEvent(event);
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            break;
        case MotionEvent.ACTION_MOVE:
            //一个点的时候滑动
            if (event.getPointerCount() == 1) {
                //长按之后移动
                if (isLongPress) {
                    calculateSelectedX(event.getX());
                    invalidate();
                }
            }
            break;
        case MotionEvent.ACTION_UP:
            isLongPress = false;
            invalidate();
            break;
        case MotionEvent.ACTION_CANCEL:
            isLongPress = false;
            invalidate();
            break;
    }
    return true;
}
 
Example 11
Source File: DragSortListView.java    From biermacht with Apache License 2.0 5 votes vote down vote up
private void saveTouchCoords(MotionEvent ev) {
  int action = ev.getAction() & MotionEvent.ACTION_MASK;
  if (action != MotionEvent.ACTION_DOWN) {
    mLastX = mX;
    mLastY = mY;
  }
  mX = (int) ev.getX();
  mY = (int) ev.getY();
  if (action == MotionEvent.ACTION_DOWN) {
    mLastX = mX;
    mLastY = mY;
  }
  mOffsetX = (int) ev.getRawX() - mX;
  mOffsetY = (int) ev.getRawY() - mY;
}
 
Example 12
Source File: PopupWindow.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * Called when a touch screen event was not handled by any of the views
 * under it. This is most useful to process touch events that happen outside
 * of your window bounds, where there is no view to receive it.
 * 
 * @param event The touch screen event being processed.
 * @return Return true if you have consumed the event, false if you haven't.
 *         The default implementation will cancel the dialog when a touch
 *         happens outside of the window bounds.
 */
@Override
public boolean onTouch(View v, MotionEvent event) {
	final boolean outOfBounds = isOutOfBounds(event);
    if (mShowing && shouldCloseOnTouch(event)) {
        hide();
        return true;
    } else if (mShowing && !outOfBounds &&
    		   (event.getActionMasked() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
    	onUserInteraction();
    }
    
    return false;
}
 
Example 13
Source File: NumberPicker.java    From zen4android with MIT License 5 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    final int action = event.getAction() & MotionEvent.ACTION_MASK;
    switch (action) {
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            removeAllCallbacks();
            break;
    }
    return super.dispatchTouchEvent(event);
}
 
Example 14
Source File: PinchImageView.java    From LLApp with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
    super.onTouchEvent(event);
    int action = event.getAction() & MotionEvent.ACTION_MASK;
    //最后一个点抬起或者取消,结束所有模式
    if(action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
        //如果之前是缩放模式,还需要触发一下缩放结束动画
        if (mPinchMode == PINCH_MODE_SCALE) {
            scaleEnd();
        }
        mPinchMode = PINCH_MODE_FREE;
    } else if (action == MotionEvent.ACTION_POINTER_UP) {
        //多个手指情况下抬起一个手指,此时需要是缩放模式才触发
        if (mPinchMode == PINCH_MODE_SCALE) {
            //抬起的点如果大于2,那么缩放模式还有效,但是有可能初始点变了,重新测量初始点
            if (event.getPointerCount() > 2) {
                //如果还没结束缩放模式,但是第一个点抬起了,那么让第二个点和第三个点作为缩放控制点
                if (event.getAction() >> 8 == 0) {
                    saveScaleContext(event.getX(1), event.getY(1), event.getX(2), event.getY(2));
                    //如果还没结束缩放模式,但是第二个点抬起了,那么让第一个点和第三个点作为缩放控制点
                } else if (event.getAction() >> 8 == 1) {
                    saveScaleContext(event.getX(0), event.getY(0), event.getX(2), event.getY(2));
                }
            }
            //如果抬起的点等于2,那么此时只剩下一个点,也不允许进入单指模式,因为此时可能图片没有在正确的位置上
        }
        //第一个点按下,开启滚动模式,记录开始滚动的点
    } else if (action == MotionEvent.ACTION_DOWN) {
        //在矩阵动画过程中不允许启动滚动模式
        if (!(mScaleAnimator != null && mScaleAnimator.isRunning())) {
            //停止所有动画
            cancelAllAnimator();
            //切换到滚动模式
            mPinchMode = PINCH_MODE_SCROLL;
            //保存触发点用于move计算差值
            mLastMovePoint.set(event.getX(), event.getY());
        }
        //非第一个点按下,关闭滚动模式,开启缩放模式,记录缩放模式的一些初始数据
    } else if (action == MotionEvent.ACTION_POINTER_DOWN) {
        //停止所有动画
        cancelAllAnimator();
        //切换到缩放模式
        mPinchMode = PINCH_MODE_SCALE;
        //保存缩放的两个手指
        saveScaleContext(event.getX(0), event.getY(0), event.getX(1), event.getY(1));
    } else if (action == MotionEvent.ACTION_MOVE) {
        if (!(mScaleAnimator != null && mScaleAnimator.isRunning())) {
            //在滚动模式下移动
            if (mPinchMode == PINCH_MODE_SCROLL) {
                //每次移动产生一个差值累积到图片位置上
                scrollBy(event.getX() - mLastMovePoint.x, event.getY() - mLastMovePoint.y);
                //记录新的移动点
                mLastMovePoint.set(event.getX(), event.getY());
                //在缩放模式下移动
            } else if (mPinchMode == PINCH_MODE_SCALE && event.getPointerCount() > 1) {
                //两个缩放点间的距离
                float distance = MathUtils.getDistance(event.getX(0), event.getY(0), event.getX(1), event.getY(1));
                //保存缩放点中点
                float[] lineCenter = MathUtils.getCenterPoint(event.getX(0), event.getY(0), event.getX(1), event.getY(1));
                mLastMovePoint.set(lineCenter[0], lineCenter[1]);
                //处理缩放
                scale(mScaleCenter, mScaleBase, distance, mLastMovePoint);
            }
        }
    }
    //无论如何都处理各种外部手势
    mGestureDetector.onTouchEvent(event);
    return true;
}
 
Example 15
Source File: GalleryViewPager.java    From LoyalNativeSlider with MIT License 4 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {

    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        //super.onInterceptTouchEvent(event);

        float endX = event.getX();
        float endY = event.getY();
        if (isAClick(startX, endX, startY, endY)) {
            if (mOnItemClickListener != null) {
                mOnItemClickListener.onItemClicked(mCurrentView, getCurrentItem());
            }
            //launchFullPhotoActivity(imageUrls);// WE HAVE A CLICK!!
        } else {
            super.onTouchEvent(event);
        }
    }

    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
        startX = event.getX();
        startY = event.getY();
    }

    /*if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP)
    {
        super.onTouchEvent(event);
    }*/

    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;
}
 
Example 16
Source File: DragSortListView.java    From google-authenticator-android with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (mIgnoreTouchEvent) {
        mIgnoreTouchEvent = false;
        return false;
    }

    if (!mDragEnabled) {
        return super.onTouchEvent(ev);
    }

    boolean more = false;

    boolean lastCallWasIntercept = mLastCallWasIntercept;
    mLastCallWasIntercept = false;

    if (!lastCallWasIntercept) {
        saveTouchCoords(ev);
    }

    // if (mFloatView != null) {
    if (mDragState == DRAGGING) {
        onDragTouchEvent(ev);
        more = true; // give us more!
    } else {
        // what if float view is null b/c we dropped in middle
        // of drag touch event?

        // if (mDragState != STOPPED) {
        if (mDragState == IDLE) {
            if (super.onTouchEvent(ev)) {
                more = true;
            }
        }

        int action = ev.getAction() & MotionEvent.ACTION_MASK;

        switch (action) {
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                doActionUpOrCancel();
                break;
            default:
                if (more) {
                    mCancelMethod = ON_TOUCH_EVENT;
                }
        }
    }

    return more;
}
 
Example 17
Source File: SwipeTouchHelper.java    From StackCardsView with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = ev.getAction() & MotionEvent.ACTION_MASK;
    if (mTouchChild == null) {
        return false;
    }
    mVelocityTracker.addMovement(ev);
    switch (action) {
        case MotionEvent.ACTION_DOWN: {
            log(TAG, "onTouchEvent ACTION_DOWN");
            if (!mOnTouchableChild) {
                return false;
            }
            break;
        }
        case MotionEvent.ACTION_MOVE: {
            //子view未消费down事件时,mIsBeingDragged为false
            log(TAG, "onTouchEvent ACTION_MOVE,mActivePointerId=" + mActivePointerId);
            if (mActivePointerId == INVALID_POINTER) {
                log(TAG, "onTouchEvent ACTION_MOVE,INVALID_POINTER");
                break;
            }
            int pointerIndex = ev.findPointerIndex(mActivePointerId);
            float x = ev.getX(pointerIndex);
            float y = ev.getY(pointerIndex);
            if (!mIsBeingDragged) {
                cancelSpringIfNeeded();
                float dx = x - mInitDownX;
                float dy = y - mInitDownY;
                if ((Math.abs(dx) <= mDragSlop && (Math.abs(dy) <= mDragSlop)) || !canDrag(dx, dy)) {
                    mLastX = x;
                    mLastY = y;
                    return false;
                }
                mIsBeingDragged = true;
            }
            performDrag(x - mLastX, y - mLastY);
            mLastX = x;
            mLastY = y;
            break;
        }
        case MotionEvent.ACTION_POINTER_DOWN:
            log(TAG, "onTouchEvent ACTION_POINTER_DOWN");
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP: {
            log(TAG, "onTouchEvent ACTION_UP,mActivePointerId=" + mActivePointerId);
            if (mActivePointerId == INVALID_POINTER) {
                break;
            }
            onTouchRelease();
            break;
        }
        case MotionEvent.ACTION_POINTER_UP: {
            log(TAG, "onTouchEvent ACTION_POINTER_UP,mActivePointerId=" + mActivePointerId);
            int activePointerIndex = ev.findPointerIndex(mActivePointerId);
            if (activePointerIndex == ev.getActionIndex()) {
                onTouchRelease();
            }
            break;
        }
    }
    return true;
}
 
Example 18
Source File: BarLineChartTouchListener.java    From WaveHeartRate with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouch(View v, MotionEvent event) {
    
    if(mode == NONE) {
        mGestureDetector.onTouchEvent(event);
    }
    
    if(!mChart.isDragEnabled()) return true;

    // Handle touch events here...
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            savedMatrix.set(matrix);
            start.set(event.getX(), event.getY());
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            oldDist = spacing(event);
            Log.d("TouchListener", "oldDist=" + oldDist);
            if (oldDist > 10f) { 
                savedMatrix.set(matrix);
                midPoint(mid, event);
                mode = ZOOM;
                mChart.disableScroll();
                Log.d("TouchListener","mode=ZOOM");
            }
            break;

        case MotionEvent.ACTION_UP:
            if (mode == NONE) {
            }
            Log.d("TouchListener","mode=NONE");
            mode = NONE;
            mChart.enableScroll();
            break;
        case MotionEvent.ACTION_POINTER_UP:
            Log.d("TouchListener","mode=POSTZOOM");
            mode = POSTZOOM;
            break;
        case MotionEvent.ACTION_MOVE:
            if (mode == NONE && distance(event.getX(), start.x, event.getY(), start.y) > 25f) {
                savedMatrix.set(matrix);
                start.set(event.getX(), event.getY());
                Log.d("TouchListener","mode=DRAG");
                mode = DRAG;
                mChart.disableScroll();
            } else if (mode == DRAG) {
                matrix.set(savedMatrix);
                matrix.postTranslate(event.getX() - start.x, 0);
            } else if (mode == ZOOM) {
                float newDist = spacing(event);
                Log.d("TouchListener","newDist=" + newDist);
                if (newDist > 10f) {
                    float scale = newDist / oldDist;
                    float[] values = new float[9];
                    matrix.getValues(values);
                    float oldScale = values[0];
                    if ((scale < 1 || oldScale < mChart.getMaxScale())
                            && (scale > 1 || oldScale > MIN_SCALE)) {
                        matrix.set(savedMatrix);
                        matrix.postScale(scale, 1, mid.x, mid.y);
                    }
                }
            }
            else if (mode == LONGPRESS) {
                mChart.disableScroll();
            }
            break;
    }

    // Perform the transformation
    matrix = mChart.refreshTouch(matrix);

    return true; // indicate event was handled
}
 
Example 19
Source File: PlayerInputComponent.java    From Learning-Java-by-Building-Android-Games-Second-Edition with MIT License 4 votes vote down vote up
@Override
public void handleInput(MotionEvent event, GameState gameState, ArrayList<Rect> buttons) {
   // In each MotionEvent object, every active pointer is present. Therefore looping through them all for an event on only one of them is obviously wrong.
    // The getActionIndex returns the index in the array of the pointer that performed/trigged the action/method call. So using getX(i) and getY(i) only gets a true result
    // on the button that was actually pressed/removed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    int i = event.getActionIndex();
    int x = (int) event.getX(i);
    int y = (int) event.getY(i);

    switch (event.getAction() & MotionEvent.ACTION_MASK) {

        case MotionEvent.ACTION_UP:
            if (buttons.get(HUD.UP).contains(x,y)
                    || buttons.get(HUD.DOWN).contains(x,y)) {

                // Player has released either up or down
                mTransform.stopVertical();
            }
            break;

        case MotionEvent.ACTION_DOWN:
            if (buttons.get(HUD.UP).contains(x,y)) {
                // Player has pressed up
                mTransform.headUp();
            } else if (buttons.get(HUD.DOWN).contains(x,y)) {
                // Player has pressed down
                mTransform.headDown();
            } else if (buttons.get(HUD.FLIP).contains(x,y)) {
                // Player has released the flip button
                mTransform.flip();
            } else if (buttons.get(HUD.SHOOT).contains(x,y)) {
                mPLS.spawnPlayerLaser(mTransform);
            }
            break;

        case MotionEvent.ACTION_POINTER_UP:
            if (buttons.get(HUD.UP).contains(x, y)
                    || buttons.get(HUD.DOWN).contains(x, y)) {
                // Player has released either up or down
                mTransform.stopVertical();
            }
            break;

        case MotionEvent.ACTION_POINTER_DOWN:
            if (buttons.get(HUD.UP).contains(x, y)) {
                // Player has pressed up
                mTransform.headUp();
            } else if (buttons.get(HUD.DOWN).contains(x, y)) {
                // Player has pressed down
                mTransform.headDown();
            } else if (buttons.get(HUD.FLIP).contains(x, y)) {
                // Player has released the flip button
                mTransform.flip();
            } else if (buttons.get(HUD.SHOOT).contains(x, y)) {
                mPLS.spawnPlayerLaser(mTransform);
            }
            break;
    }
}
 
Example 20
Source File: DragSortListView.java    From onpc with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent ev)
{
    if (mIgnoreTouchEvent)
    {
        mIgnoreTouchEvent = false;
        return false;
    }

    if (!mDragEnabled)
    {
        return super.onTouchEvent(ev);
    }

    boolean more = false;

    boolean lastCallWasIntercept = mLastCallWasIntercept;
    mLastCallWasIntercept = false;

    if (!lastCallWasIntercept)
    {
        saveTouchCoords(ev);
    }

    // if (mFloatView != null) {
    if (mDragState == DRAGGING)
    {
        onDragTouchEvent(ev);
        more = true; // give us more!
    }
    else
    {
        // what if float view is null b/c we dropped in middle
        // of drag touch event?

        // if (mDragState != STOPPED) {
        if (mDragState == IDLE)
        {
            if (super.onTouchEvent(ev))
            {
                more = true;
            }
        }

        int action = ev.getAction() & MotionEvent.ACTION_MASK;

        switch (action)
        {
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            doActionUpOrCancel();
            break;
        default:
            if (more)
            {
                mCancelMethod = ON_TOUCH_EVENT;
            }
        }
    }

    return more;
}