List of usage examples for android.view MotionEvent ACTION_MASK
int ACTION_MASK
To view the source code for android.view MotionEvent ACTION_MASK.
Click Source Link
From source file:org.godotengine.godot.Godot.java
public boolean gotTouchEvent(final MotionEvent event) { final int evcount = event.getPointerCount(); if (evcount == 0) return true; if (mView != null) { final int[] arr = new int[event.getPointerCount() * 3]; for (int i = 0; i < event.getPointerCount(); i++) { arr[i * 3 + 0] = (int) event.getPointerId(i); arr[i * 3 + 1] = (int) event.getX(i); arr[i * 3 + 2] = (int) event.getY(i); }//www . jav a 2 s . c o m final int pointer_idx = event.getPointerId(event.getActionIndex()); //System.out.printf("gaction: %d\n",event.getAction()); final int action = event.getAction() & MotionEvent.ACTION_MASK; mView.queueEvent(new Runnable() { @Override public void run() { switch (action) { case MotionEvent.ACTION_DOWN: { GodotLib.touch(0, 0, evcount, arr); //System.out.printf("action down at: %f,%f\n", event.getX(),event.getY()); } break; case MotionEvent.ACTION_MOVE: { GodotLib.touch(1, 0, evcount, arr); /* for(int i=0;i<event.getPointerCount();i++) { System.out.printf("%d - moved to: %f,%f\n",i, event.getX(i),event.getY(i)); } */ } break; case MotionEvent.ACTION_POINTER_UP: { GodotLib.touch(4, pointer_idx, evcount, arr); //System.out.printf("%d - s.up at: %f,%f\n",pointer_idx, event.getX(pointer_idx),event.getY(pointer_idx)); } break; case MotionEvent.ACTION_POINTER_DOWN: { GodotLib.touch(3, pointer_idx, evcount, arr); //System.out.printf("%d - s.down at: %f,%f\n",pointer_idx, event.getX(pointer_idx),event.getY(pointer_idx)); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { GodotLib.touch(2, 0, evcount, arr); /* for(int i=0;i<event.getPointerCount();i++) { System.out.printf("%d - up! %f,%f\n",i, event.getX(i),event.getY(i)); } */ } break; } } }); } return true; }
From source file:com.example.android.contactslist.ui.chartActivity.ContactDetailChartFragment.java
public void loadChartView() { //Build the chart view mChartMaker = new chartMaker(mContactLookupKey, //contact lookup key getActivity().getContentResolver(), getActivity(), this); mChartView = mChartMaker.getBarChartView(); try {//from www . j av a 2 s . com //add the chart view to the fragment. mChartLayout.addView(mChartView); } catch (Exception e) { } mChartView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { int xDiff; final int action = event.getAction(); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: mChartMaker.xTouchPast = (int) event.getX(); break; case MotionEvent.ACTION_UP: //TODO why is seriesSelection always null in the touch listener SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint(); mChartMaker.xTouchPosition = (int) event.getX(); xDiff = mChartMaker.xTouchPosition - mChartMaker.xTouchPast; if (Math.abs(xDiff) > 75) { if (xDiff > 0) { //choosing the direction of the swipe mChartMaker.adjustChartRange(true); //going left or back } else { mChartMaker.adjustChartRange(false); //going right or forward } //repaint of the chartView is handeled in the callback } if (Math.abs(xDiff) < 20) { if (seriesSelection != null) { Toast.makeText(mContext, "Chart element in series index " + seriesSelection.getSeriesIndex() + " data point index " + seriesSelection.getPointIndex() + " was long pressed", Toast.LENGTH_SHORT).show(); } } break; default: } return true; } }); mChartView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint(); if (seriesSelection == null) { Toast.makeText(mContext, "No chart element was long pressed", Toast.LENGTH_SHORT).show(); return false; // no chart element was long pressed, so let // something // else handle the event } else { Toast.makeText(mContext, "Chart element in series index " + seriesSelection.getSeriesIndex() + " data point index " + seriesSelection.getPointIndex() + " was long pressed", Toast.LENGTH_SHORT).show(); return true; } } }); }
From source file:com.youle.gamebox.ui.view.SlidingPaneLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!mCanSlide) { return super.onTouchEvent(ev); }//from ww w.java 2 s . c om // 2013.12.28 ? if ((ev.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_MOVE) { final float x = ev.getX(); final float y = ev.getY(); final float adx = Math.abs(x - mInitialMotionX); final float ady = Math.abs(y - mInitialMotionY); final int slop = mDragHelper.getTouchSlop(); if (adx > slop && ady > adx) { return true; } } mDragHelper.processTouchEvent(ev); final int action = ev.getAction(); boolean wantTouchEvents = true; switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x; mInitialMotionY = y; break; } case MotionEvent.ACTION_UP: { if (isDimmed(mSlideableView)) { final float x = ev.getX(); final float y = ev.getY(); final float dx = x - mInitialMotionX; final float dy = y - mInitialMotionY; final int slop = mDragHelper.getTouchSlop(); if (dx * dx + dy * dy < slop * slop && mDragHelper.isViewUnder(mSlideableView, (int) x, (int) y)) { // Taps close a dimmed open pane. closePane(mSlideableView, 0); break; } } break; } } return wantTouchEvents; }
From source file:org.androfarsh.widget.DragGridLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { final float x = ev.getX(); final float y = ev.getY(); if (mGestureDetector.onTouchEvent(ev)) { mPrevX = x;//from w w w . j ava2 s . com mPrevY = y; return true; } switch (ev.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: if (mEditMode) { final View child = findIntersectChild(x, y); if (child != null) { if ((mDragNode != null) && (mDragNode.view != child)) { return true; } mPrevX = x; mPrevY = y; stopAnimation(mDragNode != null ? mDragNode.view : null); mDragNode = new Node(child, requestPreferredRect(mTmpRect, child)); Node.scale(mDragNode.currentRect, mScaleFactor); requestFreeCellRegion(child); requestHoveredCells(mDragNode); if (mDragListener != null) { mDragListener.onDrag(mDragNode.view, this); } final Animation animation = new ScaleAnimation((1f - mScaleFactor) + 1f, 1f, (1f - mScaleFactor) + 1f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); animation.setDuration(DURATION); animation.setAnimationListener(new AbstractAnimationListener() { @Override public void onAnimationEnd(Animation animation) { mTmpRect.set(mDragNode.startRect); child.setAnimation(null); child.requestLayout(); invalidate(mTmpRect); } }); requestLayout(); child.startAnimation(animation); return true; } final Cell cell = findCellUnder(x, y); if (cell != null) { mPressedCell = cell; invalidate(); return true; } mEditModeSwitchOff = true; return true; } break; case MotionEvent.ACTION_MOVE: if (mPressedCell != null) { final Cell cell = findCellUnder(x, y); if (mPressedCell != cell) { mPressedCell = null; invalidate(); return true; } } else if (mDragNode != null) { mDragNode.currentRect.offset((int) (x - mPrevX), (int) (y - mPrevY)); if (mDebugMode) { Log.w(VIEW_LOG_TAG, "ACTION_MOVE: x=" + x + " y=" + y + " prevX=" + mPrevX + " prevY=" + mPrevY + " dX=" + (x - mPrevX) + " dY=" + (y - mPrevY)); } requestHoveredCells(mDragNode); boolean dragged = (Math.abs(x - mPrevX) < DELTA) && (Math.abs(y - mPrevY) < DELTA); if (dragged) { requestReorderRevert(); } if (!mHoveredCells.isEmpty() && dragged) { if (!mLoongHoveredRequested) { mLoongHoveredRequested = true; mHandler.sendEmptyMessageDelayed(LONGHOVER_MESSAGE, LONGPRESS_TIMEOUT + TAP_TIMEOUT); } } else if (mLoongHoveredRequested) { mLoongHoveredRequested = false; mHandler.removeMessages(LONGHOVER_MESSAGE); } mPrevX = x; mPrevY = y; requestLayout(); invalidate(); return true; } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: mLoongHoveredRequested = false; mHandler.removeMessages(LONGHOVER_MESSAGE); if (mPressedCell != null) { if (mCellClickListener != null) { mCellClickListener.onClick(new Point(mPressedCell.rect.left, mPressedCell.rect.top), this); } mPressedCell = null; invalidate(); return true; } else if (mDragNode != null) { mDragNode.currentRect.offset((int) (x - mPrevX), (int) (y - mPrevY)); requestHoveredCells(mDragNode); requestReorderRevert(); requestDrop(mDragNode); mPrevX = x; mPrevY = y; mTmpRect.set(mDragNode.currentRect); mTmpRect.union(mDragNode.startRect); final View child = mDragNode.view; final LayoutParams lp = (LayoutParams) child.getLayoutParams(); lp.mX = mDragNode.startRect.left; lp.mY = mDragNode.startRect.top; mNodes.clear(); mDragNode.startRect.offset(lp.leftMargin, lp.topMargin); final AnimationSet animation = new AnimationSet(true); animation.addAnimation(new TranslateAnimation(mDragNode.currentRect.left - mDragNode.startRect.left, 0, mDragNode.currentRect.top - mDragNode.startRect.top, 0)); animation.addAnimation(new ScaleAnimation(mScaleFactor, 1f, mScaleFactor, 1f)); animation.setDuration(DURATION); animation.setAnimationListener(new AbstractAnimationListener() { @Override public void onAnimationEnd(final Animation a) { mDragNode.dispose(); mDragNode = null; child.setAnimation(null); requestLayout(); invalidate(); } }); if (mDragListener != null) { mDragListener.onDrop(mDragNode.view, this); } mDragNode.currentRect.set(mDragNode.startRect); child.requestLayout(); child.startAnimation(animation); invalidate(mTmpRect); return true; } else if (mEditModeSwitchOff) { setEditMode(false); mEditModeSwitchOff = false; return true; } break; } return super.onTouchEvent(ev); }
From source file:com.cyanogenmod.filemanager.ui.widgets.DrawerLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { mLeftDragger.processTouchEvent(ev);/*w w w .j av a 2 s . c om*/ mRightDragger.processTouchEvent(ev); final int action = ev.getAction(); boolean wantTouchEvents = true; switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x; mInitialMotionY = y; mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; break; } case MotionEvent.ACTION_UP: { final float x = ev.getX(); final float y = ev.getY(); boolean peekingOnly = true; final View touchedView = mLeftDragger.findTopChildUnder((int) x, (int) y); if (touchedView != null && isContentView(touchedView)) { final float dx = x - mInitialMotionX; final float dy = y - mInitialMotionY; final int slop = mLeftDragger.getTouchSlop(); if (dx * dx + dy * dy < slop * slop) { // Taps close a dimmed open drawer but only if it isn't locked open. final View openDrawer = findOpenDrawer(); if (openDrawer != null) { peekingOnly = getDrawerLockMode(openDrawer) == LOCK_MODE_LOCKED_OPEN; } } } closeDrawers(peekingOnly); mDisallowInterceptRequested = false; break; } case MotionEvent.ACTION_CANCEL: { closeDrawers(true); mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; break; } } return wantTouchEvents; }
From source file:com.aviary.android.feather.sdk.widget.AviaryWorkspace.java
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = ev.getAction(); if (!isEnabled()) { if (!mScroller.isFinished()) { mScroller.abortAnimation();/*from w w w . j av a2 s . c o m*/ } snapToScreen(mCurrentScreen); return false; // We don't want the events. Let them fall through to the all // apps view. } acquireVelocityTrackerAndAddMovement(ev); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: /* * If being flinged and user touches, stop the fling. isFinished will be * false if being flinged. */ if (!mScroller.isFinished()) { mScroller.abortAnimation(); } // Remember where the motion event started mLastMotionX = ev.getX(); mLastMotionX2 = ev.getX(); mActivePointerId = ev.getPointerId(0); if (mTouchState == TOUCH_STATE_SCROLLING) { enableChildrenCache(mCurrentScreen - 1, mCurrentScreen + 1); } break; case MotionEvent.ACTION_MOVE: if (mTouchState == TOUCH_STATE_SCROLLING) { // Scroll to follow the motion event final int pointerIndex = ev.findPointerIndex(mActivePointerId); final float x = ev.getX(pointerIndex); final float deltaX = mLastMotionX - x; final float deltaX2 = mLastMotionX2 - x; final int mode = mOverScrollMode; mLastMotionX = x; if (deltaX < 0) { mTouchX += deltaX; mSmoothingTime = System.nanoTime() / NANOTIME_DIV; if (mTouchX < 0 && mode != OVER_SCROLL_NEVER) { mTouchX = mLastMotionX = 0; // mLastMotionX = x; if (mEdgeGlowLeft != null && deltaX2 < 0) { mEdgeGlowLeft.onPull((float) deltaX / getWidth()); if (!mEdgeGlowRight.isFinished()) { mEdgeGlowRight.onRelease(); } } } invalidate(); } else if (deltaX > 0) { final int totalWidth = getScreenScrollPositionX(mItemCount - 1); final float availableToScroll = getScreenScrollPositionX(mItemCount) - mTouchX; mSmoothingTime = System.nanoTime() / NANOTIME_DIV; mTouchX += Math.min(availableToScroll, deltaX); if (availableToScroll <= getWidth() && mode != OVER_SCROLL_NEVER) { mTouchX = mLastMotionX = totalWidth; // mLastMotionX = x; if (mEdgeGlowLeft != null && deltaX2 > 0) { mEdgeGlowRight.onPull((float) deltaX / getWidth()); if (!mEdgeGlowLeft.isFinished()) { mEdgeGlowLeft.onRelease(); } } } invalidate(); } else { awakenScrollBars(); } } break; case MotionEvent.ACTION_UP: if (mTouchState == TOUCH_STATE_SCROLLING) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final int velocityX = (int) velocityTracker.getXVelocity(mActivePointerId); final int screenWidth = getWidth(); final int whichScreen = (getScrollX() + (screenWidth / 2)) / screenWidth; final float scrolledPos = (float) getScrollX() / screenWidth; if (velocityX > SNAP_VELOCITY && mCurrentScreen > 0) { // Fling hard enough to move left. // Don't fling across more than one screen at a time. final int bound = scrolledPos < whichScreen ? mCurrentScreen - 1 : mCurrentScreen; snapToScreen(Math.min(whichScreen, bound), velocityX, true); } else if (velocityX < -SNAP_VELOCITY && mCurrentScreen < mItemCount - 1) { // Fling hard enough to move right // Don't fling across more than one screen at a time. final int bound = scrolledPos > whichScreen ? mCurrentScreen + 1 : mCurrentScreen; snapToScreen(Math.max(whichScreen, bound), velocityX, true); } else { snapToScreen(whichScreen, 0, true); } if (mEdgeGlowLeft != null) { mEdgeGlowLeft.onRelease(); mEdgeGlowRight.onRelease(); } } mTouchState = TOUCH_STATE_REST; mActivePointerId = INVALID_POINTER; releaseVelocityTracker(); break; case MotionEvent.ACTION_CANCEL: if (mTouchState == TOUCH_STATE_SCROLLING) { final int screenWidth = getWidth(); final int whichScreen = (getScrollX() + (screenWidth / 2)) / screenWidth; snapToScreen(whichScreen, 0, true); } mTouchState = TOUCH_STATE_REST; mActivePointerId = INVALID_POINTER; releaseVelocityTracker(); if (mEdgeGlowLeft != null) { mEdgeGlowLeft.onRelease(); mEdgeGlowRight.onRelease(); } break; case MotionEvent.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; } return true; }
From source file:com.android.launcher2.PagedView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { /*/*w ww . j a v a 2 s .c o m*/ * This method JUST determines whether we want to intercept the motion. * If we return true, onTouchEvent will be called and we do the actual * scrolling there. */ acquireVelocityTrackerAndAddMovement(ev); // Skip touch handling if there are no pages to swipe if (getChildCount() <= 0) return super.onInterceptTouchEvent(ev); /* * Shortcut the most recurring case: the user is in the dragging * state and he is moving his finger. We want to intercept this * motion. */ final int action = ev.getAction(); if ((action == MotionEvent.ACTION_MOVE) && (mTouchState == TOUCH_STATE_SCROLLING)) { return true; } switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_MOVE: { /* * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check * whether the user has moved far enough from his original down touch. */ if (mActivePointerId != INVALID_POINTER) { determineScrollingStart(ev); break; } // if mActivePointerId is INVALID_POINTER, then we must have missed an ACTION_DOWN // event. in that case, treat the first occurence of a move event as a ACTION_DOWN // i.e. fall through to the next case (don't break) // (We sometimes miss ACTION_DOWN events in Workspace because it ignores all events // while it's small- this was causing a crash before we checked for INVALID_POINTER) } case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); // Remember location of down touch mDownMotionX = x; mLastMotionX = x; mLastMotionY = y; mLastMotionXRemainder = 0; mTotalMotionX = 0; mActivePointerId = ev.getPointerId(0); mAllowLongPress = true; /* * If being flinged and user touches the screen, initiate drag; * otherwise don't. mScroller.isFinished should be false when * being flinged. */ final int xDist = Math.abs(mScroller.getFinalX() - mScroller.getCurrX()); final boolean finishedScrolling = (mScroller.isFinished() || xDist < mTouchSlop); if (finishedScrolling) { mTouchState = TOUCH_STATE_REST; mScroller.abortAnimation(); } else { mTouchState = TOUCH_STATE_SCROLLING; } // check if this can be the beginning of a tap on the side of the pages // to scroll the current page if (mTouchState != TOUCH_STATE_PREV_PAGE && mTouchState != TOUCH_STATE_NEXT_PAGE) { if (getChildCount() > 0) { if (hitsPreviousPage(x, y)) { mTouchState = TOUCH_STATE_PREV_PAGE; } else if (hitsNextPage(x, y)) { mTouchState = TOUCH_STATE_NEXT_PAGE; } } } break; } case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mTouchState = TOUCH_STATE_REST; mAllowLongPress = false; mActivePointerId = INVALID_POINTER; releaseVelocityTracker(); break; case MotionEvent.ACTION_POINTER_UP: onSecondaryPointerUp(ev); releaseVelocityTracker(); break; } /* * The only time we want to intercept motion events is if we are in the * drag mode. */ return mTouchState != TOUCH_STATE_REST; }
From source file:cc.flydev.launcher.Workspace.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { switch (ev.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: mXDown = ev.getX();/*w w w . j av a 2 s.c o m*/ mYDown = ev.getY(); mTouchDownTime = System.currentTimeMillis(); break; case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_UP: if (mTouchState == TOUCH_STATE_REST) { final CellLayout currentPage = (CellLayout) getChildAt(mCurrentPage); if (!currentPage.lastDownOnOccupiedCell()) { onWallpaperTap(ev); } } } return super.onInterceptTouchEvent(ev); }
From source file:com.wb.launcher3.Workspace.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { switch (ev.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: mXDown = ev.getX();//from w ww .ja v a2 s . c o m mYDown = ev.getY(); mTouchDownTime = System.currentTimeMillis(); //*/Added by tyd Greg 2014-03-20,for transition effect if (mTransEffSavedType == KbStyle2TransitionEffect.WKS_TRANSITION_RAND) { mTransEfftype = (int) (Math.random() * KbStyle2TransitionEffect.WKS_TRANSITION_TYPE_MAX); while (mTransEfftype == KbStyle2TransitionEffect.WKS_TRANSITION_RAND) { mTransEfftype = (int) (Math.random() * KbStyle2TransitionEffect.WKS_TRANSITION_TYPE_MAX); } mTransEffLastType = mTransEfftype; } //*/ break; case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_UP: if (mTouchState == TOUCH_STATE_REST) { final CellLayout currentPage = (CellLayout) getChildAt(mCurrentPage); if (!currentPage.lastDownOnOccupiedCell()) { onWallpaperTap(ev); } } } return super.onInterceptTouchEvent(ev); }
From source file:com.klinker.android.launcher.launcher3.Workspace.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!isInOverviewMode()) { mDetector.onTouchEvent(ev);//from ww w . ja va2 s. c o m } switch (ev.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: mXDown = ev.getX(); mYDown = ev.getY(); mTouchDownTime = System.currentTimeMillis(); break; case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_UP: if (mTouchState == TOUCH_STATE_REST) { final CellLayout currentPage = (CellLayout) getChildAt(mCurrentPage); if (currentPage != null) { onWallpaperTap(ev); } } } return super.onInterceptTouchEvent(ev); }