List of usage examples for android.view MotionEvent ACTION_DOWN
int ACTION_DOWN
To view the source code for android.view MotionEvent ACTION_DOWN.
Click Source Link
From source file:com.anysoftkeyboard.keyboards.views.CandidateView.java
@Override public boolean onTouchEvent(@NonNull MotionEvent me) { if (mGestureDetector.onTouchEvent(me)) { return true; }/*from w w w . j a v a 2 s .c om*/ int action = me.getAction(); final int x = (int) me.getX(); final int y = (int) me.getY(); mTouchX = x; switch (action) { case MotionEvent.ACTION_DOWN: invalidate(); break; case MotionEvent.ACTION_MOVE: if (y <= 0) { // Fling up!? //Fling up should be a hacker's way to delete words (user dictionary words) if (mSelectedString != null) { Logger.d(TAG, "Fling up from candidates view. Deleting word at index %d, which is %s", mSelectedIndex, mSelectedString); mService.removeFromUserDictionary(mSelectedString.toString()); clear(); } } break; case MotionEvent.ACTION_UP: if (!mScrolled) { if (mSelectedString != null) { if (mShowingAddToDictionary) { final CharSequence word = mSuggestions.get(0); if (word.length() >= 2 && !mNoticing) { Logger.d(TAG, "User wants to add the word '%s' to the user-dictionary.", word); boolean added = mService.addWordToDictionary(word.toString()); if (!added) { Logger.w(TAG, "Failed to add word to user-dictionary!"); } } } else if (!mNoticing) { mService.pickSuggestionManually(mSelectedIndex, mSelectedString); } else if (mSelectedIndex == 1 && !TextUtils.isEmpty(mJustAddedWord)) { // 1 is the index of "Remove?" Logger.d(TAG, "User wants to remove an added word '%s'", mJustAddedWord); mService.removeFromUserDictionary(mJustAddedWord.toString()); } } } invalidate(); break; } return true; }
From source file:com.android.deskclock.alarms.AlarmActivity.java
@Override public boolean onTouch(View view, MotionEvent motionEvent) { if (mAlarmHandled) { LogUtils.v(LOGTAG, "onTouch ignored: %s", motionEvent); return false; }// w w w . ja v a 2 s . co m final int[] contentLocation = { 0, 0 }; mContentView.getLocationOnScreen(contentLocation); final float x = motionEvent.getRawX() - contentLocation[0]; final float y = motionEvent.getRawY() - contentLocation[1]; final int alarmLeft = mAlarmButton.getLeft() + mAlarmButton.getPaddingLeft(); final int alarmRight = mAlarmButton.getRight() - mAlarmButton.getPaddingRight(); final float snoozeFraction, dismissFraction; if (mContentView.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { snoozeFraction = getFraction(alarmRight, mSnoozeButton.getLeft(), x); dismissFraction = getFraction(alarmLeft, mDismissButton.getRight(), x); } else { snoozeFraction = getFraction(alarmLeft, mSnoozeButton.getRight(), x); dismissFraction = getFraction(alarmRight, mDismissButton.getLeft(), x); } setAnimatedFractions(snoozeFraction, dismissFraction); switch (motionEvent.getActionMasked()) { case MotionEvent.ACTION_DOWN: LogUtils.v(LOGTAG, "onTouch started: %s", motionEvent); // Stop the pulse, allowing the last pulse to finish. mPulseAnimator.setRepeatCount(0); break; case MotionEvent.ACTION_UP: LogUtils.v(LOGTAG, "onTouch ended: %s", motionEvent); if (snoozeFraction == 1.0f) { snooze(); } else if (dismissFraction == 1.0f) { dismiss(); } else { if (snoozeFraction > 0.0f || dismissFraction > 0.0f) { // Animate back to the initial state. AnimatorUtils.reverse(mAlarmAnimator, mSnoozeAnimator, mDismissAnimator); } else if (mAlarmButton.getTop() <= y && y <= mAlarmButton.getBottom()) { // User touched the alarm button, hint the dismiss action hintDismiss(); } // Restart the pulse. mPulseAnimator.setRepeatCount(ValueAnimator.INFINITE); if (!mPulseAnimator.isStarted()) { mPulseAnimator.start(); } } break; case MotionEvent.ACTION_CANCEL: resetAnimations(); break; default: break; } return true; }
From source file:bk.vinhdo.taxiads.utils.view.SlidingLayer.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!mEnabled) { return false; }//w w w . j av a 2 s . c om final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mIsDragging = false; mIsUnableToDrag = false; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } return false; } if (action != MotionEvent.ACTION_DOWN) { if (mIsDragging) { return true; } else if (mIsUnableToDrag) { return false; } } switch (action) { case MotionEvent.ACTION_MOVE: final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER) { break; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId); if (pointerIndex == -1) { mActivePointerId = INVALID_POINTER; break; } final float x = MotionEventCompat.getX(ev, pointerIndex); final float dx = x - mLastX; final float xDiff = Math.abs(dx); final float y = MotionEventCompat.getY(ev, pointerIndex); final float dy = y - mLastY; final float yDiff = Math.abs(y - mLastY); if (mOnInteractListener != null) { boolean isControlled = mOnInteractListener.onInterceptActionMove(x, y); if (isControlled) { break; } } if (xDiff > mTouchSlop && xDiff > yDiff && allowDragingX(dx, mInitialX)) { mIsDragging = true; mLastX = x; setDrawingCacheEnabled(true); } else if (yDiff > mTouchSlop && yDiff > xDiff && allowDragingY(dy, mInitialY)) { mIsDragging = true; mLastY = y; setDrawingCacheEnabled(true); } break; case MotionEvent.ACTION_DOWN: mActivePointerId = ev.getAction() & (Build.VERSION.SDK_INT >= 8 ? MotionEvent.ACTION_POINTER_INDEX_MASK : MotionEventCompat.ACTION_POINTER_INDEX_MASK); mLastX = mInitialX = MotionEventCompat.getX(ev, mActivePointerId); mLastY = mInitialY = MotionEventCompat.getY(ev, mActivePointerId); if (allowSlidingFromHereX(ev, mInitialX)) { mIsDragging = false; mIsUnableToDrag = false; // If nobody else got the focus we use it to close the layer return super.onInterceptTouchEvent(ev); } else if (allowSlidingFromHereY(ev, mInitialY)) { mIsDragging = false; mIsUnableToDrag = false; // If nobody else got the focus we use it to close the layer return super.onInterceptTouchEvent(ev); } else { mIsUnableToDrag = true; } break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; } if (!mIsDragging) { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); } return mIsDragging; }
From source file:com.android.inputmethod.keyboard.emoji.EmojiPalettesView.java
/** * Called from {@link EmojiPageKeyboardView} through {@link android.view.View.OnTouchListener} * interface to handle touch events from View-based elements such as the space bar. * Note that this method is used only for observing {@link MotionEvent#ACTION_DOWN} to trigger * {@link KeyboardActionListener#onPressKey}. {@link KeyboardActionListener#onReleaseKey} will * be covered by {@link #onClick} as long as the event is not canceled. *//*from ww w . j a v a 2 s. com*/ @Override public boolean onTouch(final View v, final MotionEvent event) { if (event.getActionMasked() != MotionEvent.ACTION_DOWN) { return false; } final Object tag = v.getTag(); if (!(tag instanceof Integer)) { return false; } final int code = (Integer) tag; mKeyboardActionListener.onPressKey(code, 0 /* repeatCount */, true /* isSinglePointer */); // It's important to return false here. Otherwise, {@link #onClick} and touch-down visual // feedback stop working. return false; }
From source file:android.support.v7.widget.FastScroller.java
@Override public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent ev) { final boolean handled; if (mState == STATE_VISIBLE) { boolean insideVerticalThumb = isPointInsideVerticalThumb(ev.getX(), ev.getY()); boolean insideHorizontalThumb = isPointInsideHorizontalThumb(ev.getX(), ev.getY()); if (ev.getAction() == MotionEvent.ACTION_DOWN && (insideVerticalThumb || insideHorizontalThumb)) { if (insideHorizontalThumb) { mDragState = DRAG_X;//from ww w . java2 s . c o m mHorizontalDragX = (int) ev.getX(); } else if (insideVerticalThumb) { mDragState = DRAG_Y; mVerticalDragY = (int) ev.getY(); } setState(STATE_DRAGGING); handled = true; } else { handled = false; } } else if (mState == STATE_DRAGGING) { handled = true; } else { handled = false; } return handled; }
From source file:com.am.pullview.swiperefresh.SwipeRefreshLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { final int action = event.getAction(); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: mCurrPercentage = 0;/*from w w w . j av a2 s. co m*/ mDownEvent = MotionEvent.obtain(event); mPrevY = mDownEvent.getY(); break; case MotionEvent.ACTION_MOVE: if (mDownEvent != null && !mReturningToStart) { final float eventY = event.getY(); float yDiff = eventY - mDownEvent.getY(); if (yDiff > mTouchSlop) { // User velocity passed min velocity; trigger a refresh if (yDiff > mDistanceToTriggerSync) { // User movement passed distance; trigger a refresh startRefresh(); handled = true; break; } else { // Just track the user's movement setTriggerPercentage( mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync)); float offsetTop = yDiff; if (mPrevY > eventY) { offsetTop = yDiff - mTouchSlop; } updateContentOffsetTop((int) (offsetTop)); if (mPrevY > eventY && (mTarget.getTop() < mTouchSlop)) { // If the user puts the view back at the top, we // don't need to. This shouldn't be considered // cancelling the gesture as the user can restart from the top. removeCallbacks(mCancel); } else { updatePositionTimeout(); } mPrevY = event.getY(); handled = true; } } } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (mDownEvent != null) { mDownEvent.recycle(); mDownEvent = null; } break; } return handled; }
From source file:android.widget.PinnedHeaderListView.java
@Override public boolean onInterceptTouchEvent(final MotionEvent ev) { mHeaderTouched = false;//from w ww. j av a2 s . c o m if (super.onInterceptTouchEvent(ev)) return true; if (mScrollState == SCROLL_STATE_IDLE) { final int y = (int) ev.getY(); final int x = (int) ev.getX(); for (int i = mSize; --i >= 0;) { final PinnedHeader header = mHeaders[i]; // For RTL layouts, this also takes into account that the scrollbar is on the left // side. final int padding = getPaddingLeft(); if (header.visible && header.y <= y && header.y + header.height > y && x >= padding && padding + header.view.getWidth() >= x) { mHeaderTouched = true; if (mScrollToSectionOnHeaderTouch && ev.getAction() == MotionEvent.ACTION_DOWN) return smoothScrollToPartition(i); else return true; } } } return false; }
From source file:cn.sdgundam.comicatsdgo.extension.SwipeRefreshLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { final int action = event.getAction(); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: mCurrPercentage = 0;// ww w .j av a 2 s. c om mDownEvent = MotionEvent.obtain(event); mPrevY = mDownEvent.getY(); break; case MotionEvent.ACTION_MOVE: if (mDownEvent != null && !mReturningToStart) { final float eventY = event.getY(); float yDiff = eventY - mDownEvent.getY(); if (yDiff > mTouchSlop) { // User velocity passed min velocity; trigger a refresh if (yDiff > mDistanceToTriggerSync) { // User movement passed distance; trigger a refresh startRefresh(); break; } else { // Just track the user's movement setTriggerPercentage( mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync)); float offsetTop = yDiff; if (mPrevY > eventY) { offsetTop = yDiff - mTouchSlop; } updateContentOffsetTop((int) (offsetTop)); if (mPrevY > eventY && (mTarget.getTop() < mTouchSlop)) { // If the user puts the view back at the top, we // don't need to. This shouldn't be considered // cancelling the gesture as the user can restart from the top. removeCallbacks(mCancel); } // else { // updatePositionTimeout(); // } mPrevY = event.getY(); } } } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (mDownEvent != null) { mDownEvent.recycle(); mDownEvent = null; updatePositionImmediately(); } break; } return handled; }
From source file:com.android.launcher3.BubbleTextView.java
@Override public boolean onTouchEvent(MotionEvent event) { // Call the superclass onTouchEvent first, because sometimes it changes the state to // isPressed() on an ACTION_UP boolean result = super.onTouchEvent(event); // Check for a stylus button press, if it occurs cancel any long press checks. if (mStylusEventHelper.onMotionEvent(event)) { mLongPressHelper.cancelLongPress(); result = true;/* w w w. ja va2 s . c o m*/ } switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // So that the pressed outline is visible immediately on setStayPressed(), // we pre-create it on ACTION_DOWN (it takes a small but perceptible amount of time // to create it) if (!mDeferShadowGenerationOnTouch && mPressedBackground == null) { mPressedBackground = mOutlineHelper.createMediumDropShadow(this); } // If we're in a stylus button press, don't check for long press. if (!mStylusEventHelper.inStylusButtonPressed()) { mLongPressHelper.postCheckForLongPress(); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: // If we've touched down and up on an item, and it's still not "pressed", then // destroy the pressed outline if (!isPressed()) { mPressedBackground = null; } mLongPressHelper.cancelLongPress(); break; case MotionEvent.ACTION_MOVE: if (!Utilities.pointInView(this, event.getX(), event.getY(), mSlop)) { mLongPressHelper.cancelLongPress(); } break; } return result; }