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:com.lib.imagesee.GalleryViewPager.java
@Override public boolean onInterceptTouchEvent(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()); }//from www . j a v a2 s . c o m } else { try { super.onInterceptTouchEvent(event); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { startX = event.getX(); startY = event.getY(); } float[] difference = handleMotionEvent(event); if (mCurrentView.pagerCanScroll()) { try { return super.onInterceptTouchEvent(event); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (difference != null && mCurrentView.onRightSide && difference[0] < 0) // move right { try { return super.onInterceptTouchEvent(event); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) // move left { try { return super.onInterceptTouchEvent(event); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) { try { return super.onInterceptTouchEvent(event); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return false; }
From source file:com.csounds.examples.tests.SynthActivity.java
/** Called when the activity is first created. */ @Override/* w w w . j a v a 2s . c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); for (int i = 0; i < touchIds.length; i++) { touchIds[i] = -1; touchX[i] = -1; touchY[i] = -1; } multiTouchView = new View(this); setContentView(R.layout.synth2); multiTouchView = (RelativeLayout) findViewById(R.id.synth); octPlusButton = (Button) findViewById(R.id.plusoctavebutton); octMinusButton = (Button) findViewById(R.id.minusoctavebutton); diode4 = (ToggleButton) findViewById(R.id.diode4); diode3 = (ToggleButton) findViewById(R.id.diode3); LcdScreenView lcd = (LcdScreenView) findViewById(R.id.lcd_screen); new DrumMachineLcdUpdater(lcd.getModel()); this.createLoadListener((View) lcd); keyboardLayout = (RelativeLayout) findViewById(R.id.keyboard); keyboardLayout.setOnTouchListener(new OnTouchListener() { /* (non-Javadoc) * @see android.view.View.OnTouchListener#onTouch(android.view.View, android.view.MotionEvent) */ public boolean onTouch(View v, MotionEvent event) { final int action = event.getAction() & MotionEvent.ACTION_MASK; float[] touchArrayDown = new float[2]; switch (action) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: for (int i = 0; i < event.getPointerCount(); i++) { int pointerId = event.getPointerId(i); int id = getTouchId(pointerId); if (id == -1) { id = getTouchIdAssignment(); if (id != -1) { touchIds[id] = pointerId; touchX[id] = event.getX(i) / keyboardLayout.getWidth(); touchY[id] = 1 - (event.getY(i) / keyboardLayout.getHeight()); //TODO calculte interval Y if (touchXPtr[id] != null) { //TODO swtich touchid // Log.d("touchXtouchY","touchX[id]) " + touchX[id] + " touchY[id]) " + touchY[id] + " multitouchview width " + multiTouchView.getWidth() + " multitouchview width " + multiTouchView.getHeight()); // Log.d("touchXtouchY","keyboardLayout width " + keyboardLayout.getWidth() + " keyboardLayout width " + keyboardLayout.getHeight()); // get the key from the touch coordinates float[] touchArray = new float[2]; touchArray = evaluateTouchKey(touchX[id], touchY[id]); touchArrayDown[0] = touchX[id]; touchArrayDown[1] = touchY[id]; touchX[id] = touchArray[0]; touchY[id] = touchArray[1]; // Log.d("touchXtouchY","touchX[id]) " + touchX[id] + " touchY[id]) " + touchY[id]); touchXPtr[id].SetValue(0, touchX[id]); touchYPtr[id].SetValue(0, touchY[id]); csoundObj.sendScore(String.format("i1.%d 0 -2 %d", id, id)); } } } } break; case MotionEvent.ACTION_MOVE: for (int i = 0; i < event.getPointerCount(); i++) { int pointerId = event.getPointerId(i); int id = getTouchId(pointerId); if (id != -1) { touchIds[id] = pointerId; touchX[id] = event.getX(i) / keyboardLayout.getWidth(); touchY[id] = 1 - (event.getY(i) / keyboardLayout.getHeight()); //TODO calculte interval Y if (touchXPtr[id] != null) { //TODO swtich touchid // Log.d("aaa","touchX[id]) " + touchX[id] + " touchY[id]) " + touchY[id] + " multitouchview width " + multiTouchView.getWidth() + " multitouchview width " + multiTouchView.getHeight()); // Log.d("aaa","keyboardLayout width " + keyboardLayout.getWidth() + " keyboardLayout width " + keyboardLayout.getHeight()); // get the key from the touch coordinates float[] touchArray = new float[2]; touchArray = evaluateTouchKey(touchX[id], touchY[id]); touchX[id] = touchArray[0]; touchY[id] = touchArray[1]; // Log.d("touchXtouchY","touchX[id]) " + touchX[id] + " touchY[id]) " + touchY[id]); touchXPtr[id].SetValue(0, touchX[id]); touchYPtr[id].SetValue(0, touchY[id]); csoundObj.sendScore(String.format("i1.%d 0 -2 %d", id, id)); } } } break; case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_UP: { int activePointerIndex = event.getActionIndex(); int pointerId = event.getPointerId(activePointerIndex); int id = getTouchId(pointerId); if (id != -1) { touchIds[id] = -1; csoundObj.sendScore(String.format("i-1.%d 0 0 %d", id, id)); } //write file /* System.out.println(String.format( "i1.%d 0 -2 %d", id, id)); writeToFile(String.format( "i1.%d 0 -2 %d", id, id)); */ } break; } return true; } }); OnTouchListener octBtnOk = new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (octNbr < 12) octNbr += 12; break; } return false; } }; octPlusButton.setOnTouchListener(octBtnOk); OnTouchListener octBtnMinus = new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (octNbr > -36) octNbr -= 12; break; } return false; } }; octMinusButton.setOnTouchListener(octBtnMinus); String csd = getResourceFileAsString(R.raw.multitouch_xy_kx); File f = createTempFile(csd); csoundObj.addBinding(this); csoundObj.startCsound(f); // initknobs(); initSeekBar(diode3, diode4); }
From source file:com.bottomsheetbehavior.ReactNestedScrollView.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!mScrollEnabled) { return false; }/*from w w w .j a v a2 s. c o m*/ int action = ev.getAction() & MotionEvent.ACTION_MASK; if (action == MotionEvent.ACTION_UP && mDragging) { ReactNestedScrollViewHelper.emitScrollEndDragEvent(this); mDragging = false; disableFpsListener(); } return super.onTouchEvent(ev); }
From source file:dg.shenm233.drag2expandview.Drag2ExpandView.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { final int action = ev.getAction(); final float x = ev.getX(); final float y = ev.getY(); int maskAction = action & MotionEvent.ACTION_MASK; if (maskAction == MotionEvent.ACTION_DOWN) { mLetScrollableViewHandle = false; mPreviousDownX = x;// w w w . j a va 2 s .co m mPreviousDownY = y; } else if (maskAction == MotionEvent.ACTION_MOVE) { if (!isViewUnder(mScrollableView, (int) x, (int) y)) { return super.dispatchTouchEvent(ev); } if (mScrollableViewHelper.getScrollableViewScrollPosition(mScrollableView, mIsUpSliding) > 0) { mLetScrollableViewHandle = true; return super.dispatchTouchEvent(ev); } } // default return super.dispatchTouchEvent(ev); }
From source file:it.sephiroth.android.library.imagezoom.ScaleGestureDetector.java
public boolean onTouchEvent(final MotionEvent event) { final int action = event.getAction(); final boolean handled = true; if (!mGestureInProgress) { switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_POINTER_DOWN: { // We have a new multi-finger gesture // as orientation can change, query the metrics in touch // down final DisplayMetrics metrics = mContext.getResources().getDisplayMetrics(); mRightSlopEdge = metrics.widthPixels - mEdgeSlop; mBottomSlopEdge = metrics.heightPixels - mEdgeSlop; // Be paranoid in case we missed an event reset();/*from w w w.ja v a2 s . c o m*/ mPrevEvent = MotionEvent.obtain(event); mTimeDelta = 0; setContext(event); // Check if we have a sloppy gesture. If so, delay // the beginning of the gesture until we're sure that's // what the user wanted. Sloppy gestures can happen if the // edge of the user's hand is touching the screen, for // example. final float edgeSlop = mEdgeSlop; final float rightSlop = mRightSlopEdge; final float bottomSlop = mBottomSlopEdge; final float x0 = event.getRawX(); final float y0 = event.getRawY(); final float x1 = getRawX(event, 1); final float y1 = getRawY(event, 1); final boolean p0sloppy = x0 < edgeSlop || y0 < edgeSlop || x0 > rightSlop || y0 > bottomSlop; final boolean p1sloppy = x1 < edgeSlop || y1 < edgeSlop || x1 > rightSlop || y1 > bottomSlop; if (p0sloppy && p1sloppy) { mFocusX = -1; mFocusY = -1; mSloppyGesture = true; } else if (p0sloppy) { mFocusX = MotionEventCompat.getX(event, 1); mFocusY = MotionEventCompat.getY(event, 1); mSloppyGesture = true; } else if (p1sloppy) { mFocusX = MotionEventCompat.getX(event, 0); mFocusY = MotionEventCompat.getY(event, 0); mSloppyGesture = true; } else { mGestureInProgress = mListener.onScaleBegin(this); } } break; case MotionEvent.ACTION_MOVE: if (mSloppyGesture) { // Initiate sloppy gestures if we've moved outside of // the slop area. final float edgeSlop = mEdgeSlop; final float rightSlop = mRightSlopEdge; final float bottomSlop = mBottomSlopEdge; final float x0 = event.getRawX(); final float y0 = event.getRawY(); final float x1 = getRawX(event, 1); final float y1 = getRawY(event, 1); final boolean p0sloppy = x0 < edgeSlop || y0 < edgeSlop || x0 > rightSlop || y0 > bottomSlop; final boolean p1sloppy = x1 < edgeSlop || y1 < edgeSlop || x1 > rightSlop || y1 > bottomSlop; if (p0sloppy && p1sloppy) { mFocusX = -1; mFocusY = -1; } else if (p0sloppy) { mFocusX = MotionEventCompat.getX(event, 1); mFocusY = MotionEventCompat.getY(event, 1); } else if (p1sloppy) { mFocusX = MotionEventCompat.getX(event, 0); mFocusY = MotionEventCompat.getY(event, 0); } else { mSloppyGesture = false; mGestureInProgress = mListener.onScaleBegin(this); } } break; case MotionEvent.ACTION_POINTER_UP: if (mSloppyGesture) { // Set focus point to the remaining finger final int id = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT == 0 ? 1 : 0; mFocusX = event.getX(id); mFocusY = event.getY(id); } break; } } else { // Transform gesture in progress - attempt to handle it switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_POINTER_UP: // Gesture ended setContext(event); // Set focus point to the remaining finger final int id = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT == 0 ? 1 : 0; mFocusX = event.getX(id); mFocusY = event.getY(id); if (!mSloppyGesture) { mListener.onScaleEnd(this); } reset(); break; case MotionEvent.ACTION_CANCEL: if (!mSloppyGesture) { mListener.onScaleEnd(this); } reset(); break; case MotionEvent.ACTION_MOVE: setContext(event); // Only accept the event if our relative pressure is within // a certain limit - this can help filter shaky data as a // finger is lifted. if (mCurrPressure / mPrevPressure > PRESSURE_THRESHOLD) { final boolean updatePrevious = mListener.onScale(this); if (updatePrevious) { mPrevEvent.recycle(); mPrevEvent = MotionEvent.obtain(event); } } break; } } return handled; }
From source file:com.mediatek.galleryfeature.stereo.segment.ImageShow.java
@Override public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); int action = event.getAction(); action = action & MotionEvent.ACTION_MASK; mGestureDetector.onTouchEvent(event); mScaleGestureDetector.onTouchEvent(event); if (mInteractionMode == InteractionMode.SCALE) { return true; }//from ww w .j a v a 2 s . c o m int ex = (int) event.getX(); int ey = (int) event.getY(); if (action == MotionEvent.ACTION_DOWN) { mInteractionMode = InteractionMode.MOVE; mTouchDown.x = ex; mTouchDown.y = ey; System.currentTimeMillis(); mMasterImage.setOriginalTranslation(mMasterImage.getTranslation()); } if (action == MotionEvent.ACTION_MOVE && mInteractionMode == InteractionMode.MOVE) { mTouch.x = ex; mTouch.y = ey; float scaleFactor = mMasterImage.getScaleFactor(); if (scaleFactor > 1 && (!ENABLE_ZOOMED_COMPARISON || event.getPointerCount() == 2)) { float translateX = (mTouch.x - mTouchDown.x) / scaleFactor; float translateY = (mTouch.y - mTouchDown.y) / scaleFactor; Point originalTranslation = mMasterImage.getOriginalTranslation(); Point translation = mMasterImage.getTranslation(); translation.x = (int) (originalTranslation.x + translateX); translation.y = (int) (originalTranslation.y + translateY); mMasterImage.setTranslation(translation); } } if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_OUTSIDE) { mInteractionMode = InteractionMode.NONE; mTouchDown.x = 0; mTouchDown.y = 0; mTouch.x = 0; mTouch.y = 0; if (mMasterImage.getScaleFactor() <= 1) { mMasterImage.setScaleFactor(1); mMasterImage.resetTranslation(); } } float scaleFactor = mMasterImage.getScaleFactor(); Point translation = mMasterImage.getTranslation(); constrainTranslation(translation, scaleFactor); mMasterImage.setTranslation(translation); invalidate(); return true; }
From source file:nz.ac.otago.psyanlab.common.designer.program.stage.StageView.java
@Override public boolean onTouchEvent(MotionEvent event) { if (!isEnabled()) { // Ignore touch events if not enabled. return false; }/* w w w .ja va 2s . c o m*/ final int action = event.getAction(); final int pointerCount = event.getPointerCount(); final Handler handler = getHandler(); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_POINTER_DOWN: { // Throw away event if we have already seen at least this many // fingers before. if (mMaxFingersDown > pointerCount) { return true; } if (handler != null) { handler.removeCallbacks(mPendingCheckForTap); handler.removeCallbacks(mPendingCheckForLongPress); } mPendingCheckForTap = new CheckForTap(); postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); mMaxFingersDown = pointerCount; mMotionPosition = INVALID_POSITION; updateMotionCoords(event, pointerCount); mTouchMode = TOUCH_MODE_DOWN; return true; } case MotionEvent.ACTION_DOWN: { mMaxFingersDown = pointerCount; if (mPendingCheckForTap == null) { mPendingCheckForTap = new CheckForTap(); } postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); updateMotionCoords(event, pointerCount); mMotionPosition = pointToPosition(mMotionX.get(0).intValue(), mMotionY.get(0).intValue()); mTouchMode = TOUCH_MODE_DOWN; return true; } case MotionEvent.ACTION_MOVE: { if (mMaxFingersDown == 1 && mMotionPosition != NO_MATCHED_CHILD && mMotionPosition == pointToPosition((int) event.getX(), (int) event.getY())) { // Ignore movement in single touch mode until the user has // moved out of the prop hit area. return true; } boolean moveIsOverSlop = false; int touchSlop = mMaxFingersDown > 1 ? mTouchSlop * 6 : mTouchSlop; for (int pointerIndex = 0; pointerIndex < pointerCount; pointerIndex++) { int pointerId = event.getPointerId(pointerIndex); moveIsOverSlop = moveIsOverSlop || Math.abs(event.getY(pointerIndex) - mMotionY.get(pointerId)) > touchSlop || Math.abs(event.getX(pointerIndex) - mMotionX.get(pointerId)) > touchSlop; } if (mTouchMode != TOUCH_MODE_AT_REST && moveIsOverSlop) { // Too much movement to be a tap event. mTouchMode = TOUCH_MODE_AT_REST; final View child = getChildAt(mMotionPosition); if (child != null) { child.setPressed(false); } setPressed(false); if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } mMotionPosition = NO_MATCHED_CHILD; updateSelectorState(); invalidate(); } return true; } case MotionEvent.ACTION_UP: { if (mTouchMode == TOUCH_MODE_FINISHED_LONG_PRESS) { return true; } if (mTouchMode == TOUCH_MODE_AT_REST) { break; } // Handle stage multi-touch. if (mMotionPosition == NO_MATCHED_CHILD) { if (mPerformPropClick == null) { mPerformPropClick = new PerformClick(); } final PerformClick performPropClick = mPerformPropClick; performPropClick.mClickMotionPosition = mMotionPosition; performPropClick.rememberWindowAttachCount(); if (mTouchMode != TOUCH_MODE_DOWN || mTouchMode != TOUCH_MODE_TAP) { if (handler != null) { handler.removeCallbacks( mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress); } if (!mDataChanged) { // Got here so must be a tap. The long press would // have triggered inside the delayed runnable. mTouchMode = TOUCH_MODE_TAP; positionSelector(this); setPressed(true); updateSelectorState(); invalidate(); resetSelectorTransition(getVirtualFingers()); if (mTouchModeReset != null) { removeCallbacks(mTouchModeReset); } mTouchModeReset = new Runnable() { @Override public void run() { mTouchMode = TOUCH_MODE_AT_REST; setPressed(false); if (!mDataChanged) { performPropClick.run(); } updateSelectorState(); invalidate(); } }; postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration()); } else { mTouchMode = TOUCH_MODE_AT_REST; } } else if (!mDataChanged) { performPropClick.run(); } } else { // Handle touch on child. final View child = getChildAt(mMotionPosition); if (child != null && !child.hasFocusable()) { if (mTouchMode != TOUCH_MODE_DOWN) { child.setPressed(false); } if (mPerformPropClick == null) { mPerformPropClick = new PerformClick(); } final PerformClick performPropClick = mPerformPropClick; performPropClick.mClickMotionPosition = mMotionPosition; performPropClick.rememberWindowAttachCount(); if (mTouchMode != TOUCH_MODE_DOWN || mTouchMode != TOUCH_MODE_TAP) { if (handler != null) { handler.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress); } if (!mDataChanged) { // Got here so must be a tap. The long press // would // have triggered inside the delayed runnable. mTouchMode = TOUCH_MODE_TAP; child.setPressed(true); positionSelector(child); setPressed(true); updateSelectorState(); invalidate(); resetSelectorTransition(getVirtualFingers()); if (mTouchModeReset != null) { removeCallbacks(mTouchModeReset); } mTouchModeReset = new Runnable() { @Override public void run() { mTouchMode = TOUCH_MODE_AT_REST; child.setPressed(false); setPressed(false); updateSelectorState(); invalidate(); if (!mDataChanged) { performPropClick.run(); } } }; postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration()); } else { mTouchMode = TOUCH_MODE_AT_REST; updateSelectorState(); invalidate(); } } else if (!mDataChanged) { performPropClick.run(); } } } return true; } } return true; }
From source file:dg.shenm233.drag2expandview.Drag2ExpandView.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!mLetScrollableViewHandle) { mViewDragHelper.processTouchEvent(ev); if (mViewDragHelper.getViewDragState() == ViewDragHelper.STATE_DRAGGING) { return true; }/* w ww. j ava 2s .co m*/ } final float x = ev.getX(); final float y = ev.getY(); boolean isDragViewUnder = isViewUnder(mDragView, (int) x, (int) y); final int action = ev.getAction(); int maskAction = action & MotionEvent.ACTION_MASK; if (maskAction == MotionEvent.ACTION_DOWN) { mPreviousDownX = x; mPreviousDownY = y; } else if (maskAction == MotionEvent.ACTION_UP) { float dx = mPreviousDownX - x; float dy = mPreviousDownY - y; int slop = mViewDragHelper.getTouchSlop(); if (dx * dx + dy * dy < slop * slop && isDragViewUnder) { if (mViewState == STATE_COLLAPSE) { smoothSlideViewTo(mAnchorOffset); //expand } else { smoothSlideViewTo(0.0f); // collapse } } } return isDragViewUnder; }
From source file:com.funzio.pure2D.demo.particles.NovaActivity.java
@Override public boolean onTouch(final View v, final MotionEvent event) { final int action = event.getAction() & MotionEvent.ACTION_MASK; // null check if (mNovaFactory == null) { return false; }/*from ww w . j a va2s . c o m*/ if (action == MotionEvent.ACTION_DOWN) { mStage.queueEvent(new Runnable() { @Override public void run() { final int pointerCount = event.getPointerCount(); for (int i = 0; i < pointerCount; i++) { // for demo, limit the number of emitters if (mScene.getNumGrandChildren() < mNovaFactory.getPoolSize()) { addObject(event.getX(i), mDisplaySize.y - event.getY(i)); } } } }); } return true; }
From source file:com.facebook.react.views.scroll.ReactHorizontalScrollView.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!mScrollEnabled) { return false; }//ww w . j av a 2 s . c o m mVelocityHelper.calculateVelocity(ev); int action = ev.getAction() & MotionEvent.ACTION_MASK; if (action == MotionEvent.ACTION_UP && mDragging) { float velocityX = mVelocityHelper.getXVelocity(); float velocityY = mVelocityHelper.getYVelocity(); ReactScrollViewHelper.emitScrollEndDragEvent(this, velocityX, velocityY); mDragging = false; // After the touch finishes, we may need to do some scrolling afterwards either as a result // of a fling or because we need to page align the content handlePostTouchScrolling(Math.round(velocityX), Math.round(velocityY)); } return super.onTouchEvent(ev); }