List of usage examples for android.view MotionEvent ACTION_POINTER_DOWN
int ACTION_POINTER_DOWN
To view the source code for android.view MotionEvent ACTION_POINTER_DOWN.
Click Source Link
From source file:org.telegram.ui.Components.ChatAttachAlert.java
private boolean processTouchEvent(MotionEvent event) { if (!pressed && event.getActionMasked() == MotionEvent.ACTION_DOWN || event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) { if (!takingPhoto) { pressed = true;//www . j av a 2s .c om maybeStartDraging = true; lastY = event.getY(); } } else if (pressed) { if (event.getActionMasked() == MotionEvent.ACTION_MOVE) { float newY = event.getY(); float dy = (newY - lastY); if (maybeStartDraging) { if (Math.abs(dy) > AndroidUtilities.getPixelsInCM(0.4f, false)) { maybeStartDraging = false; } } else { cameraView.setTranslationY(cameraView.getTranslationY() + dy); lastY = newY; if (cameraPanel.getTag() == null) { cameraPanel.setTag(1); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(ObjectAnimator.ofFloat(cameraPanel, "alpha", 0.0f), ObjectAnimator.ofFloat(flashModeButton[0], "alpha", 0.0f), ObjectAnimator.ofFloat(flashModeButton[1], "alpha", 0.0f)); animatorSet.setDuration(200); animatorSet.start(); } } } else if (event.getActionMasked() == MotionEvent.ACTION_CANCEL || event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_POINTER_UP) { pressed = false; if (Math.abs(cameraView.getTranslationY()) > cameraView.getMeasuredHeight() / 6.0f) { closeCamera(true); } else { AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(ObjectAnimator.ofFloat(cameraView, "translationY", 0.0f), ObjectAnimator.ofFloat(cameraPanel, "alpha", 1.0f), ObjectAnimator.ofFloat(flashModeButton[0], "alpha", 1.0f), ObjectAnimator.ofFloat(flashModeButton[1], "alpha", 1.0f)); animatorSet.setDuration(250); animatorSet.setInterpolator(interpolator); animatorSet.start(); cameraPanel.setTag(null); } } } return true; }
From source file:com.vuze.android.remote.fragment.TorrentListFragment.java
public void onTouchEvent(MotionEvent event) { if (sideListArea == null) { return;//from w ww .j av a 2 s . c om } int action = event.getAction() & 0xff; if (action != MotionEvent.ACTION_DOWN && action != MotionEvent.ACTION_POINTER_DOWN) { return; } boolean newHasFocus = isViewContains(sideListArea, (int) event.getX(), (int) event.getY()); if ((sidelistIsExpanded == null || sidelistIsExpanded) && !newHasFocus) { //left focus sidelistInFocus = false; expandSideListWidth(false); // uncomment this if you want the sidelist to expand upon touch of // sidelist area // } else if ((sidelistIsExpanded == null || !sidelistIsExpanded) // && newHasFocus) { // expandSideListWidth(true); // sidelistInFocus = true; } }
From source file:com.android.internal.widget.ViewPager.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) { // Don't handle edge touches immediately -- they may actually belong to one of our // descendants. return false; }/*from www . java 2 s .com*/ if (mAdapter == null || mAdapter.getCount() == 0) { // Nothing to present or scroll; nothing to touch. return false; } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); final int action = ev.getAction(); boolean needsInvalidate = false; switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { mScroller.abortAnimation(); mPopulatePending = false; populate(); // Remember where the motion event started mLastMotionX = mInitialMotionX = ev.getX(); mLastMotionY = mInitialMotionY = ev.getY(); mActivePointerId = ev.getPointerId(0); break; } case MotionEvent.ACTION_MOVE: if (!mIsBeingDragged) { final int pointerIndex = ev.findPointerIndex(mActivePointerId); final float x = ev.getX(pointerIndex); final float xDiff = Math.abs(x - mLastMotionX); final float y = ev.getY(pointerIndex); final float yDiff = Math.abs(y - mLastMotionY); if (DEBUG) Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff); if (xDiff > mTouchSlop && xDiff > yDiff) { if (DEBUG) Log.v(TAG, "Starting drag!"); mIsBeingDragged = true; requestParentDisallowInterceptTouchEvent(true); mLastMotionX = x - mInitialMotionX > 0 ? mInitialMotionX + mTouchSlop : mInitialMotionX - mTouchSlop; mLastMotionY = y; setScrollState(SCROLL_STATE_DRAGGING); setScrollingCacheEnabled(true); // Disallow Parent Intercept, just in case ViewParent parent = getParent(); if (parent != null) { parent.requestDisallowInterceptTouchEvent(true); } } } // Not else! Note that mIsBeingDragged can be set above. if (mIsBeingDragged) { // Scroll to follow the motion event final int activePointerIndex = ev.findPointerIndex(mActivePointerId); final float x = ev.getX(activePointerIndex); needsInvalidate |= performDrag(x); } break; case MotionEvent.ACTION_UP: if (mIsBeingDragged) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final int initialVelocity = (int) velocityTracker.getXVelocity(mActivePointerId); mPopulatePending = true; final float scrollStart = getScrollStart(); final float scrolledPages = scrollStart / getPaddedWidth(); final ItemInfo ii = infoForFirstVisiblePage(); final int currentPage = ii.position; final float nextPageOffset; if (isLayoutRtl()) { nextPageOffset = (ii.offset - scrolledPages) / ii.widthFactor; } else { nextPageOffset = (scrolledPages - ii.offset) / ii.widthFactor; } final int activePointerIndex = ev.findPointerIndex(mActivePointerId); final float x = ev.getX(activePointerIndex); final int totalDelta = (int) (x - mInitialMotionX); final int nextPage = determineTargetPage(currentPage, nextPageOffset, initialVelocity, totalDelta); setCurrentItemInternal(nextPage, true, true, initialVelocity); mActivePointerId = INVALID_POINTER; endDrag(); mLeftEdge.onRelease(); mRightEdge.onRelease(); needsInvalidate = true; } break; case MotionEvent.ACTION_CANCEL: if (mIsBeingDragged) { scrollToItem(mCurItem, true, 0, false); mActivePointerId = INVALID_POINTER; endDrag(); mLeftEdge.onRelease(); mRightEdge.onRelease(); needsInvalidate = true; } break; case MotionEvent.ACTION_POINTER_DOWN: { final int index = ev.getActionIndex(); final float x = ev.getX(index); mLastMotionX = x; mActivePointerId = ev.getPointerId(index); break; } case MotionEvent.ACTION_POINTER_UP: onSecondaryPointerUp(ev); mLastMotionX = ev.getX(ev.findPointerIndex(mActivePointerId)); break; } if (needsInvalidate) { postInvalidateOnAnimation(); } return true; }
From source file:processing.core.PApplet.java
/** * Take action based on a motion event. Internally updates mouseX, mouseY, * mousePressed, and mouseEvent. Then it calls the event type with no * params, i.e. mousePressed() or mouseReleased() that the user may have * overloaded to do something more useful. *///from ww w .j a va 2 s . c o m protected void handleMotionEvent(PMotionEvent pme) { pmotionX = emotionX; pmotionY = emotionY; motionX = pme.motionX[0]; motionY = pme.motionY[0]; motionPressure = pme.motionPressure[0]; // replace previous mouseX/Y with the last from the event handlers pmouseX = emouseX; pmouseY = emouseY; mouseX = pme.mouseX[0]; mouseY = pme.mouseY[0]; // this used to only be called on mouseMoved and mouseDragged // change it back if people run into trouble if (firstMotion) { pmouseX = mouseX; pmouseY = mouseY; dmouseX = mouseX; // set it as the first value to be used inside // draw() too dmouseY = mouseY; pmotionX = motionX; pmotionY = motionY; dmotionX = motionX; dmotionY = motionY; firstMotion = false; } if (ppointersX.length < numPointers) { ppointersX = new float[numPointers]; ppointersY = new float[numPointers]; ppointersPressure = new float[numPointers]; } arrayCopy(pointersX, ppointersX); arrayCopy(pointersY, ppointersY); arrayCopy(pointersPressure, ppointersPressure); numPointers = pme.numPointers; if (pointersX.length < numPointers) { pointersX = new float[numPointers]; pointersY = new float[numPointers]; pointersPressure = new float[numPointers]; } arrayCopy(pme.motionX, pointersX); arrayCopy(pme.motionY, pointersY); arrayCopy(pme.motionPressure, pointersPressure); // Triggering the appropriate event methods if (pme.action == MotionEvent.ACTION_DOWN || (!mousePressed && numPointers == 1)) { // First pointer is down mousePressed = true; onePointerGesture = true; twoPointerGesture = false; downMillis = millis(); downX = pointersX[0]; downY = pointersY[0]; mousePressed(); pressEvent(); } else if ((pme.action == MotionEvent.ACTION_POINTER_DOWN && numPointers == 2) || (pme.action == MotionEvent.ACTION_POINTER_2_DOWN) || // 2.3 // seems // to // use // this // action // constant // (supposedly // deprecated) // instead // of // ACTION_POINTER_DOWN (pnumPointers == 1 && numPointers == 2)) { // 2.1 just uses MOVE // as the action // constant, so the // only way to know // we have a new // pointer is to // compare the // counters. // An additional pointer is down (we keep track of multitouch only // for 2 pointers) onePointerGesture = false; twoPointerGesture = true; } else if ((pme.action == MotionEvent.ACTION_POINTER_UP && numPointers == 2) || (pme.action == MotionEvent.ACTION_POINTER_2_UP) || // 2.1 // doesn't // use // the // ACTION_POINTER_UP // constant, // but // this // one, // apparently // deprecated // in // newer // versions // of // the // SDK. (twoPointerGesture && numPointers < 2)) { // Sometimes it seems // that it doesn't // generate the up // event. // A previously detected pointer is up twoPointerGesture = false; // Not doing a 2-pointer gesture anymore, // but neither a 1-pointer. } else if (pme.action == MotionEvent.ACTION_MOVE) { // Pointer motion if (onePointerGesture) { if (mousePressed) { mouseDragged(); dragEvent(); } else { mouseMoved(); moveEvent(); } } else if (twoPointerGesture) { float d0 = PApplet.dist(ppointersX[0], ppointersY[0], ppointersX[1], ppointersY[1]); float d1 = PApplet.dist(pointersX[0], pointersY[0], pointersX[1], pointersY[1]); if (0 < d0 && 0 < d1) { float centerX = 0.5f * (pointersX[0] + pointersX[1]); float centerY = 0.5f * (pointersY[0] + pointersY[1]); zoomEvent(centerX, centerY, d0, d1); } } } else if (pme.action == MotionEvent.ACTION_UP) { // Final pointer is up mousePressed = false; mouseReleased(); float upX = pointersX[0]; float upY = pointersY[0]; float gestureLength = PApplet.dist(downX, downY, upX, upY); int upMillis = millis(); int gestureTime = upMillis - downMillis; if (onePointerGesture) { // First, lets determine if this 1-pointer event is a tap boolean tap = gestureLength <= MAX_TAP_DISP && gestureTime <= MAX_TAP_DURATION; if (tap) { mouseClicked(); tapEvent(downX, downY); } else if (MIN_SWIPE_LENGTH <= gestureLength && gestureTime <= MAX_SWIPE_DURATION) { swipeEvent(downX, downY, upX, upY); } else { mouseReleased(); releaseEvent(); } } else { mouseReleased(); releaseEvent(); } onePointerGesture = twoPointerGesture = false; } else if (pme.action == MotionEvent.ACTION_CANCEL) { // Current gesture is canceled. onePointerGesture = twoPointerGesture = false; mousePressed = false; mouseReleased(); releaseEvent(); } else { // System.out.println("Unknown MotionEvent action: " + action); } pnumPointers = numPointers; if (pme.action == MotionEvent.ACTION_MOVE) { emotionX = motionX; emotionY = motionY; emouseX = mouseX; emouseY = mouseY; } }
From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java
@Override public boolean onTouchEvent(MotionEvent ev) { int action = ev.getAction(); if ((ev.getActionMasked() == MotionEvent.ACTION_DOWN) || (ev.getActionMasked() == MotionEvent.ACTION_UP) || (ev.getActionMasked() == MotionEvent.ACTION_POINTER_UP) || (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN)) { mRecalCenterHour = true;// w ww.j a v a 2 s . co m } if ((mTouchMode & TOUCH_MODE_HSCROLL) == 0) { mScaleGestureDetector.onTouchEvent(ev); } switch (action) { case MotionEvent.ACTION_DOWN: mStartingScroll = true; mHandleActionUp = true; mGestureDetector.onTouchEvent(ev); return true; case MotionEvent.ACTION_MOVE: mGestureDetector.onTouchEvent(ev); return true; case MotionEvent.ACTION_UP: mEdgeEffectTop.onRelease(); mEdgeEffectBottom.onRelease(); mStartingScroll = false; mGestureDetector.onTouchEvent(ev); if (!mHandleActionUp) { mHandleActionUp = true; mViewStartX = 0; invalidate(); return true; } if (mOnFlingCalled) { return true; } // If we were scrolling, then reset the selected hour so that it is visible. if (mScrolling) { mScrolling = false; resetSelectedHour(); invalidate(); } if ((mTouchMode & TOUCH_MODE_HSCROLL) != 0) { mTouchMode = TOUCH_MODE_INITIAL_STATE; if (Math.abs(mViewStartX) > mHorizontalSnapBackThreshold) { // The user has gone beyond the threshold so switch views switchViews(mViewStartX > 0, mViewStartX, mViewWidth, 0); mViewStartX = 0; return true; } else { // Not beyond the threshold so invalidate which will cause // the view to snap back. Also call recalc() to ensure // that we have the correct starting date and title. recalc(); invalidate(); mViewStartX = 0; } } return true; // This case isn't expected to happen. case MotionEvent.ACTION_CANCEL: mGestureDetector.onTouchEvent(ev); mScrolling = false; resetSelectedHour(); return true; default: if (mGestureDetector.onTouchEvent(ev)) { return true; } return super.onTouchEvent(ev); } }
From source file:com.glview.widget.AbsListView.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!isEnabled()) { // A disabled view that is clickable still consumes the touch // events, it just doesn't respond to them. return isClickable() || isLongClickable(); }// w ww.ja va2s . c o m if (mPositionScroller != null) { mPositionScroller.stop(); } if (mIsDetaching || !isAttachedToWindow()) { // Something isn't right. // Since we rely on being attached to get data set change notifications, // don't risk doing anything where we might try to resync and find things // in a bogus state. return false; } startNestedScroll(SCROLL_AXIS_VERTICAL); if (mFastScroll != null) { boolean intercepted = mFastScroll.onTouchEvent(ev); if (intercepted) { return true; } } initVelocityTrackerIfNotExists(); final MotionEvent vtev = MotionEvent.obtain(ev); final int actionMasked = ev.getActionMasked(); if (actionMasked == MotionEvent.ACTION_DOWN) { mNestedYOffset = 0; } vtev.offsetLocation(0, mNestedYOffset); switch (actionMasked) { case MotionEvent.ACTION_DOWN: { onTouchDown(ev); break; } case MotionEvent.ACTION_MOVE: { onTouchMove(ev, vtev); break; } case MotionEvent.ACTION_UP: { onTouchUp(ev); break; } case MotionEvent.ACTION_CANCEL: { onTouchCancel(); break; } case MotionEvent.ACTION_POINTER_UP: { onSecondaryPointerUp(ev); final int x = mMotionX; final int y = mMotionY; final int motionPosition = pointToPosition(x, y); if (motionPosition >= 0) { // Remember where the motion event started final View child = getChildAt(motionPosition - mFirstPosition); mMotionViewOriginalTop = child.getTop(); mMotionPosition = motionPosition; } mLastY = y; break; } case MotionEvent.ACTION_POINTER_DOWN: { // New pointers take over dragging duties final int index = ev.getActionIndex(); final int id = ev.getPointerId(index); final int x = (int) ev.getX(index); final int y = (int) ev.getY(index); mMotionCorrection = 0; mActivePointerId = id; mMotionX = x; mMotionY = y; final int motionPosition = pointToPosition(x, y); if (motionPosition >= 0) { // Remember where the motion event started final View child = getChildAt(motionPosition - mFirstPosition); mMotionViewOriginalTop = child.getTop(); mMotionPosition = motionPosition; } mLastY = y; break; } } if (mVelocityTracker != null) { mVelocityTracker.addMovement(vtev); } vtev.recycle(); return true; }
From source file:com.wb.launcher3.Page.java
public boolean handleMotionEvent(MotionEvent ev) { if (getChildCount() <= 0) { return false; }/*from w w w . j ava2 s . co m*/ acquireVelocityTrackerAndAddMovement(ev); switch (MotionEvent.ACTION_MASK & ev.getAction()) { case MotionEvent.ACTION_POINTER_DOWN: if (ev.getPointerCount() <= 2) { if (!this.mScroller.isFinished()) { this.mScroller.abortAnimation(); } int index = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; float px = ev.getX(index); mLastMotionX = px; mDownMotionX = px; mLastMotionY = ev.getY(index); mLastMotionXRemainder = 0.0F; mTotalMotionX = 0.0F; mActivePointerId = ev.getPointerId(index); mTouchState = TOUCH_STATE_SCROLLING; pageBeginMoving(); } break; case MotionEvent.ACTION_MOVE: if (mTouchState == TOUCH_STATE_SCROLLING) { int pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex >= 0) { float x = ev.getX(pointerIndex); float deltaX = mLastMotionX + mLastMotionXRemainder - x; mTotalMotionX += Math.abs(deltaX); if (Math.abs(deltaX) >= 1.0F) { mTouchX += deltaX; mSmoothingTime = System.nanoTime() / NANOTIME_DIV; if (!mDeferScrollUpdate) { scrollBy((int) deltaX, 0); if (DEBUG) Log.d(TAG, "handleMotionEvent().Scrolling: " + deltaX); } else { invalidate(); } mLastMotionX = x; mLastMotionXRemainder = deltaX - (int) deltaX; } else { awakenScrollBars(); } } } else { determineScrollingStart(ev); } break; case MotionEvent.ACTION_POINTER_UP: if (ev.getPointerCount() > 2) { onOtherPointerUp(ev); break; } if (mTouchState == TOUCH_STATE_SCROLLING) { final int activePointerId = mActivePointerId; final int pointerIndex = ev.findPointerIndex(activePointerId); final float x = ev.getX(pointerIndex); final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int velocityX = (int) velocityTracker.getXVelocity(activePointerId); final int deltaX = (int) (x - mDownMotionX); final int pageWidth = getPageAt(mCurrentPage).getMeasuredWidth(); boolean isSignificantMove = Math.abs(deltaX) > pageWidth * SIGNIFICANT_MOVE_THRESHOLD; mTotalMotionX += Math.abs(mLastMotionX + mLastMotionXRemainder - x); boolean isFling = mTotalMotionX > MIN_LENGTH_FOR_FLING && Math.abs(velocityX) > mFlingThresholdVelocity; boolean returnToOriginalPage = false; if (Math.abs(deltaX) > pageWidth * RETURN_TO_ORIGINAL_PAGE_THRESHOLD && Math.signum(velocityX) != Math.signum(deltaX) && isFling) { returnToOriginalPage = true; } if (TydtechConfig.CYCLE_ROLL_PAGES_ENABLED) { m_moveNextDeltaX = deltaX; m_isSignificantMoveNext = (!returnToOriginalPage && (isSignificantMove || isFling)); } int finalPage; if (((isSignificantMove && deltaX > 0 && !isFling) || (isFling && velocityX > 0)) && mCurrentPage > 0) { finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage - 1; snapToPageWithVelocity(finalPage, velocityX); } else if (((isSignificantMove && deltaX < 0 && !isFling) || (isFling && velocityX < 0)) && mCurrentPage < getChildCount() - 1) { finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage + 1; snapToPageWithVelocity(finalPage, velocityX); } else { snapToDestination(); } } else if (mTouchState == TOUCH_STATE_PREV_PAGE) { int nextPage = Math.max(0, mCurrentPage - 1); if (nextPage != mCurrentPage) { snapToPage(nextPage); } else { snapToDestination(); } } else if (mTouchState == TOUCH_STATE_NEXT_PAGE) { int nextPage = Math.min(getChildCount() - 1, mCurrentPage + 1); if (nextPage != mCurrentPage) { snapToPage(nextPage); } else { snapToDestination(); } } else { snapToDestination(); onUnhandledTap(ev); } mTouchState = TOUCH_STATE_REST; mActivePointerId = INVALID_POINTER; releaseVelocityTracker(); break; case MotionEvent.ACTION_CANCEL: if (mTouchState == TOUCH_STATE_SCROLLING) { snapToDestination(); } mTouchState = TOUCH_STATE_REST; mActivePointerId = INVALID_POINTER; releaseVelocityTracker(); break; } return true; }
From source file:com.example.libwidgettv.bak.AbsListView.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!isEnabled()) { // A disabled view that is clickable still consumes the touch // events, it just doesn't respond to them. return isClickable() || isLongClickable(); }//www . ja va 2s.c om if (mFastScroller != null) { boolean intercepted = mFastScroller.onTouchEvent(ev); if (intercepted) { return true; } } final int action = ev.getAction(); View v; initVelocityTrackerIfNotExists(); mVelocityTracker.addMovement(ev); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { switch (mTouchMode) { case TOUCH_MODE_OVERFLING: { mFlingRunnable.endFling(); if (mPositionScroller != null) { mPositionScroller.stop(); } mTouchMode = TOUCH_MODE_OVERSCROLL; mMotionX = (int) ev.getX(); mMotionY = mLastY = (int) ev.getY(); mMotionCorrection = 0; mActivePointerId = ev.getPointerId(0); mDirection = 0; break; } default: { mActivePointerId = ev.getPointerId(0); final int x = (int) ev.getX(); final int y = (int) ev.getY(); int motionPosition = pointToPosition(x, y); if (!mDataChanged) { if ((mTouchMode != TOUCH_MODE_FLING) && (motionPosition >= 0) && (getAdapter().isEnabled(motionPosition))) { // User clicked on an actual view (and was not stopping // a fling). // It might be a click or a scroll. Assume it is a click // until // proven otherwise mTouchMode = TOUCH_MODE_DOWN; // FIXME Debounce if (mPendingCheckForTap == null) { mPendingCheckForTap = new CheckForTap(); } postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); } else { if (mTouchMode == TOUCH_MODE_FLING) { // Stopped a fling. It is a scroll. createScrollingCache(); mTouchMode = TOUCH_MODE_SCROLL; mMotionCorrection = 0; motionPosition = findMotionRow(y); mFlingRunnable.flywheelTouch(); } } } if (motionPosition >= 0) { // Remember where the motion event started v = getChildAt(motionPosition - mFirstPosition); mMotionViewOriginalTop = v.getTop(); } mMotionX = x; mMotionY = y; mMotionPosition = motionPosition; mLastY = Integer.MIN_VALUE; break; } } // if (performButtonActionOnTouchDown(ev)) { // if (mTouchMode == TOUCH_MODE_DOWN) { // removeCallbacks(mPendingCheckForTap); // } // } break; } case MotionEvent.ACTION_MOVE: { int pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex == -1) { pointerIndex = 0; mActivePointerId = ev.getPointerId(pointerIndex); } final int y = (int) ev.getY(pointerIndex); switch (mTouchMode) { case TOUCH_MODE_DOWN: case TOUCH_MODE_TAP: case TOUCH_MODE_DONE_WAITING: // Check if we have moved far enough that it looks more like a // scroll than a tap startScrollIfNeeded(y); break; case TOUCH_MODE_SCROLL: case TOUCH_MODE_OVERSCROLL: scrollIfNeeded(y); break; } break; } case MotionEvent.ACTION_UP: { switch (mTouchMode) { case TOUCH_MODE_DOWN: case TOUCH_MODE_TAP: case TOUCH_MODE_DONE_WAITING: final int motionPosition = mMotionPosition; final View child = getChildAt(motionPosition - mFirstPosition); final float x = ev.getX(); final boolean inList = x > mListPadding.left && x < getWidth() - mListPadding.right; if (child != null && !child.hasFocusable() && inList) { if (mTouchMode != TOUCH_MODE_DOWN) { child.setPressed(false); } if (mPerformClick == null) { mPerformClick = new PerformClick(); } final AbsListView.PerformClick performClick = mPerformClick; performClick.mClickMotionPosition = motionPosition; performClick.rememberWindowAttachCount(); mResurrectToPosition = motionPosition; if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) { final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress); } mLayoutMode = LAYOUT_NORMAL; if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_TAP; setSelectedPositionInt(mMotionPosition); layoutChildren(); child.setPressed(true); positionSelector(mMotionPosition, child); setPressed(true); if (mSelector != null) { Drawable d = mSelector.getCurrent(); if (d != null && d instanceof TransitionDrawable) { ((TransitionDrawable) d).resetTransition(); } } if (mTouchModeReset != null) { removeCallbacks(mTouchModeReset); } mTouchModeReset = new Runnable() { @Override public void run() { mTouchMode = TOUCH_MODE_REST; child.setPressed(false); setPressed(false); if (!mDataChanged) { performClick.run(); } } }; postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration()); } else { mTouchMode = TOUCH_MODE_REST; updateSelectorState(); } return true; } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { performClick.run(); } } mTouchMode = TOUCH_MODE_REST; updateSelectorState(); break; case TOUCH_MODE_SCROLL: final int childCount = getChildCount(); if (childCount > 0) { final int firstChildTop = getChildAt(0).getTop(); final int lastChildBottom = getChildAt(childCount - 1).getBottom(); final int contentTop = mListPadding.top; final int contentBottom = getHeight() - mListPadding.bottom; if (mFirstPosition == 0 && firstChildTop >= contentTop && mFirstPosition + childCount < mItemCount && lastChildBottom <= getHeight() - contentBottom) { mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); } else { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final int initialVelocity = (int) (velocityTracker.getYVelocity(mActivePointerId) * mVelocityScale); // Fling if we have enough velocity and we aren't at a // boundary. // Since we can potentially overfling more than we can // overscroll, don't // allow the weird behavior where you can scroll to a // boundary then // fling further. if (Math.abs(initialVelocity) > mMinimumVelocity && !((mFirstPosition == 0 && firstChildTop == contentTop - mOverscrollDistance) || (mFirstPosition + childCount == mItemCount && lastChildBottom == contentBottom + mOverscrollDistance))) { if (mFlingRunnable == null) { mFlingRunnable = new FlingRunnable(); } reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING); mFlingRunnable.start(-initialVelocity); } else { mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); if (mFlingRunnable != null) { mFlingRunnable.endFling(); } if (mPositionScroller != null) { mPositionScroller.stop(); } } } } else { mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); } break; case TOUCH_MODE_OVERSCROLL: if (mFlingRunnable == null) { mFlingRunnable = new FlingRunnable(); } final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final int initialVelocity = (int) velocityTracker.getYVelocity(mActivePointerId); reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING); if (Math.abs(initialVelocity) > mMinimumVelocity) { mFlingRunnable.startOverfling(-initialVelocity); } else { mFlingRunnable.startSpringback(); } break; } setPressed(false); // Need to redraw since we probably aren't drawing the selector // anymore invalidate(); final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } recycleVelocityTracker(); mActivePointerId = INVALID_POINTER; if (PROFILE_SCROLLING) { if (mScrollProfilingStarted) { Debug.stopMethodTracing(); mScrollProfilingStarted = false; } } break; } case MotionEvent.ACTION_CANCEL: { switch (mTouchMode) { case TOUCH_MODE_OVERSCROLL: if (mFlingRunnable == null) { mFlingRunnable = new FlingRunnable(); } mFlingRunnable.startSpringback(); break; case TOUCH_MODE_OVERFLING: // Do nothing - let it play out. break; default: mTouchMode = TOUCH_MODE_REST; setPressed(false); View motionView = this.getChildAt(mMotionPosition - mFirstPosition); if (motionView != null) { motionView.setPressed(false); } clearScrollingCache(); final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } recycleVelocityTracker(); } mActivePointerId = INVALID_POINTER; break; } case MotionEvent.ACTION_POINTER_UP: { onSecondaryPointerUp(ev); final int x = mMotionX; final int y = mMotionY; final int motionPosition = pointToPosition(x, y); if (motionPosition >= 0) { // Remember where the motion event started v = getChildAt(motionPosition - mFirstPosition); mMotionViewOriginalTop = v.getTop(); mMotionPosition = motionPosition; } mLastY = y; break; } case MotionEvent.ACTION_POINTER_DOWN: { // New pointers take over dragging duties final int index = ev.getActionIndex(); final int id = ev.getPointerId(index); final int x = (int) ev.getX(index); final int y = (int) ev.getY(index); mMotionCorrection = 0; mActivePointerId = id; mMotionX = x; mMotionY = y; final int motionPosition = pointToPosition(x, y); if (motionPosition >= 0) { // Remember where the motion event started v = getChildAt(motionPosition - mFirstPosition); mMotionViewOriginalTop = v.getTop(); mMotionPosition = motionPosition; } mLastY = y; break; } } return true; }
From source file:com.appunite.list.AbsHorizontalListView.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!isEnabled()) { // A disabled view that is clickable still consumes the touch // events, it just doesn't respond to them. return isClickable() || isLongClickable(); }/* w w w .j ava 2s . co m*/ if (mPositionScroller != null) { mPositionScroller.stop(); } if (!mIsAttached) { // Something isn't right. // Since we rely on being attached to get data set change notifications, // don't risk doing anything where we might try to resync and find things // in a bogus state. return false; } final int action = ev.getAction(); View v; initVelocityTrackerIfNotExists(); mVelocityTracker.addMovement(ev); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { switch (mTouchMode) { case TOUCH_MODE_OVERFLING: { mFlingRunnable.endFling(); if (mPositionScroller != null) { mPositionScroller.stop(); } mTouchMode = TOUCH_MODE_OVERSCROLL; mMotionX = mLastX = (int) ev.getX(); mMotionY = (int) ev.getY(); mMotionCorrection = 0; mActivePointerId = ev.getPointerId(0); mDirection = 0; break; } default: { mActivePointerId = ev.getPointerId(0); final int x = (int) ev.getX(); final int y = (int) ev.getY(); int motionPosition = pointToPosition(x, y); if (!mDataChanged) { if ((mTouchMode != TOUCH_MODE_FLING) && (motionPosition >= 0) && (getAdapter().isEnabled(motionPosition))) { // User clicked on an actual view (and was not stopping a fling). // It might be a click or a scroll. Assume it is a click until // proven otherwise mTouchMode = TOUCH_MODE_DOWN; // FIXME Debounce if (mPendingCheckForTap == null) { mPendingCheckForTap = new CheckForTap(); } postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); } else { if (mTouchMode == TOUCH_MODE_FLING) { // Stopped a fling. It is a scroll. createScrollingCache(); mTouchMode = TOUCH_MODE_SCROLL; mMotionCorrection = 0; motionPosition = findMotionCol(x); mFlingRunnable.flywheelTouch(); } } } if (motionPosition >= 0) { // Remember where the motion event started v = getChildAt(motionPosition - mFirstPosition); mMotionViewOriginalLeft = v.getLeft(); } mMotionX = x; mMotionY = y; mMotionPosition = motionPosition; mLastX = Integer.MIN_VALUE; break; } } if (performButtonActionOnTouchDownUnhide(ev)) { if (mTouchMode == TOUCH_MODE_DOWN) { removeCallbacks(mPendingCheckForTap); } } break; } case MotionEvent.ACTION_MOVE: { int pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex == -1) { pointerIndex = 0; mActivePointerId = ev.getPointerId(pointerIndex); } final int x = (int) ev.getX(pointerIndex); if (mDataChanged) { // Re-sync everything if data has been changed // since the scroll operation can query the adapter. layoutChildren(); } switch (mTouchMode) { case TOUCH_MODE_DOWN: case TOUCH_MODE_TAP: case TOUCH_MODE_DONE_WAITING: // Check if we have moved far enough that it looks more like a // scroll than a tap startScrollIfNeeded(x); break; case TOUCH_MODE_SCROLL: case TOUCH_MODE_OVERSCROLL: scrollIfNeeded(x); break; } break; } case MotionEvent.ACTION_UP: { switch (mTouchMode) { case TOUCH_MODE_DOWN: case TOUCH_MODE_TAP: case TOUCH_MODE_DONE_WAITING: final int motionPosition = mMotionPosition; final View child = getChildAt(motionPosition - mFirstPosition); final float y = ev.getY(); final boolean inList = y > mListPadding.top && y < getHeight() - mListPadding.bottom; if (child != null && !child.hasFocusable() && inList) { if (mTouchMode != TOUCH_MODE_DOWN) { child.setPressed(false); } if (mPerformClick == null) { mPerformClick = new PerformClick(); } final AbsHorizontalListView.PerformClick performClick = mPerformClick; performClick.mClickMotionPosition = motionPosition; performClick.rememberWindowAttachCount(); mResurrectToPosition = motionPosition; if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) { final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress); } mLayoutMode = LAYOUT_NORMAL; if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_TAP; setSelectedPositionInt(mMotionPosition); layoutChildren(); child.setPressed(true); positionSelector(mMotionPosition, child); setPressed(true); if (mSelector != null) { Drawable d = mSelector.getCurrent(); if (d != null && d instanceof TransitionDrawable) { ((TransitionDrawable) d).resetTransition(); } } if (mTouchModeReset != null) { removeCallbacks(mTouchModeReset); } mTouchModeReset = new Runnable() { @Override public void run() { mTouchModeReset = null; mTouchMode = TOUCH_MODE_REST; child.setPressed(false); setPressed(false); if (!mDataChanged) { performClick.run(); } } }; postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration()); } else { mTouchMode = TOUCH_MODE_REST; updateSelectorState(); } return true; } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { performClick.run(); } } mTouchMode = TOUCH_MODE_REST; updateSelectorState(); break; case TOUCH_MODE_SCROLL: final int childCount = getChildCount(); if (childCount > 0) { final int firstChildLeft = getChildAt(0).getLeft(); final int lastChildRight = getChildAt(childCount - 1).getRight(); final int contentLeft = mListPadding.left; final int contentRight = getWidth() - mListPadding.right; if (mFirstPosition == 0 && firstChildLeft >= contentLeft && mFirstPosition + childCount < mItemCount && lastChildRight <= getWidth() - contentRight) { mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); } else { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final int initialVelocity = (int) (velocityTracker.getXVelocity(mActivePointerId) * mVelocityScale); // Fling if we have enough velocity and we aren't at a boundary. // Since we can potentially overfling more than we can overscroll, don't // allow the weird behavior where you can scroll to a boundary then // fling further. if (Math.abs(initialVelocity) > mMinimumVelocity && !((mFirstPosition == 0 && firstChildLeft == contentLeft - mOverscrollDistance) || (mFirstPosition + childCount == mItemCount && lastChildRight == contentRight + mOverscrollDistance))) { if (mFlingRunnable == null) { mFlingRunnable = new FlingRunnable(); } reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING); mFlingRunnable.start(-initialVelocity); } else { mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); if (mFlingRunnable != null) { mFlingRunnable.endFling(); } if (mPositionScroller != null) { mPositionScroller.stop(); } } } } else { mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); } break; case TOUCH_MODE_OVERSCROLL: if (mFlingRunnable == null) { mFlingRunnable = new FlingRunnable(); } final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final int initialVelocity = (int) velocityTracker.getXVelocity(mActivePointerId); reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING); if (Math.abs(initialVelocity) > mMinimumVelocity) { mFlingRunnable.startOverfling(-initialVelocity); } else { mFlingRunnable.startSpringback(); } break; } setPressed(false); if (mEdgeGlowLeft != null) { mEdgeGlowLeft.onRelease(); mEdgeGlowRight.onRelease(); } // Need to redraw since we probably aren't drawing the selector anymore invalidate(); final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } recycleVelocityTracker(); mActivePointerId = INVALID_POINTER; if (PROFILE_SCROLLING) { if (mScrollProfilingStarted) { Debug.stopMethodTracing(); mScrollProfilingStarted = false; } } // FIXME not needed bacaues we could not implement strict span (j.m.) // if (mScrollStrictSpan != null) { // mScrollStrictSpan.finish(); // mScrollStrictSpan = null; // } break; } case MotionEvent.ACTION_CANCEL: { switch (mTouchMode) { case TOUCH_MODE_OVERSCROLL: if (mFlingRunnable == null) { mFlingRunnable = new FlingRunnable(); } mFlingRunnable.startSpringback(); break; case TOUCH_MODE_OVERFLING: // Do nothing - let it play out. break; default: mTouchMode = TOUCH_MODE_REST; setPressed(false); View motionView = this.getChildAt(mMotionPosition - mFirstPosition); if (motionView != null) { motionView.setPressed(false); } clearScrollingCache(); final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } recycleVelocityTracker(); } if (mEdgeGlowLeft != null) { mEdgeGlowLeft.onRelease(); mEdgeGlowRight.onRelease(); } mActivePointerId = INVALID_POINTER; break; } case MotionEvent.ACTION_POINTER_UP: { onSecondaryPointerUp(ev); final int x = mMotionX; final int y = mMotionY; final int motionPosition = pointToPosition(x, y); if (motionPosition >= 0) { // Remember where the motion event started v = getChildAt(motionPosition - mFirstPosition); mMotionViewOriginalLeft = v.getLeft(); mMotionPosition = motionPosition; } mLastX = x; break; } case MotionEvent.ACTION_POINTER_DOWN: { // New pointers take over dragging duties final int index = ev.getActionIndex(); final int id = ev.getPointerId(index); final int x = (int) ev.getX(index); final int y = (int) ev.getY(index); mMotionCorrection = 0; mActivePointerId = id; mMotionX = x; mMotionY = y; final int motionPosition = pointToPosition(x, y); if (motionPosition >= 0) { // Remember where the motion event started v = getChildAt(motionPosition - mFirstPosition); mMotionViewOriginalLeft = v.getLeft(); mMotionPosition = motionPosition; } mLastX = x; break; } } return true; }
From source file:com.wb.launcher3.Page.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { int action = ev.getAction() & MotionEvent.ACTION_MASK; mPointCount = ev.getPointerCount();//added by zxa 1018 for adjust brightness //Log.i("zwb", "zhangwuba ------ luancher dispatchTouchEvent"); boolean enable = (Settings.Secure.getInt(mContext.getContentResolver(), "tyd_gesture_launcher", 1) == 1); boolean gesture = false; if (mPointCount == 2) { int x1 = (int) ev.getX(0); int y1 = (int) ev.getY(0); int x2 = (int) ev.getX(1); int y2 = (int) ev.getY(1); x1Down = x1;/*w w w .ja v a 2 s . com*/ x2Down = x2; y1Down = y1; y2Down = y2; xyD = (int) FloatMath.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); //Log.i("zwb", "zhangwuba ------ xyD = " + xyD); } switch (action) { case MotionEvent.ACTION_DOWN: //Log.i("xyz", "ACTION_DOWN"); tempX = 0; tempY = 0; mOldY = ev.getY(); mOldX = ev.getX(); // mMode = DRAG; break; case MotionEvent.ACTION_POINTER_DOWN: mLastMultiDownDistance = getDistance(ev); //mMode = ZOOM; break; case MotionEvent.ACTION_UP: //added by zxa 1018 for multi touch panel adjust screen light start if (enable) { closebrightnessDialog(); } //added by zxa 1018 for multi touch panel adjust screen light end //mMode = NONE; break; case MotionEvent.ACTION_POINTER_UP: //added by zxa 1018 for multi touch panel adjust screen light start if (enable) { closebrightnessDialog(); } //mMode = NONE; break; case MotionEvent.ACTION_MOVE: int scrollLength = xyD - temp; temp = xyD; if (enable && Math.abs(scrollLength) < 5 && y1Down != (int) mOldY) { adjustBrightness(ev, mPointCount); } /* if (mMode == ZOOM) { double currentLength = getDistance(ev); float length = (float) (currentLength - mLastMultiDownDistance); if (length < SHOW_WORKSPACE_PREVIEW_THRESHOLD) { onMultiZoomIn(length); } else { onMultiZoomOut(length); } }*/ break; } /* if (mMode == ZOOM) { return true; }*/ return super.dispatchTouchEvent(ev); }