下面列出了android.view.MotionEvent#ACTION_DOWN 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void handleStartProgressEvent(int actionCode, MotionEvent event){
switch (actionCode) {
case MotionEvent.ACTION_DOWN:
resetState(); // In case we missed an UP/CANCEL event
mPrevEvent = MotionEvent.obtain(event);
mTimeDelta = 0;
updateStateByEvent(event);
break;
case MotionEvent.ACTION_MOVE:
mGestureInProgress = mListener.onMoveBegin(this);
break;
}
}
@Override
protected void handleStartProgressEvent(int actionCode, MotionEvent event) {
switch (actionCode) {
case MotionEvent.ACTION_DOWN:
resetState(); // In case we missed an UP/CANCEL event
mPrevEvent = MotionEvent.obtain(event);
mTimeDelta = 0;
updateStateByEvent(event);
break;
case MotionEvent.ACTION_MOVE:
mGestureInProgress = mListener.onMoveBegin(this);
break;
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
// Check for clickable state and do nothing if disabled
if (!this.isClickable()) {
this.isSelected = false;
return super.onTouchEvent(event);
}
// Set selected state based on Motion Event
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
this.isSelected = true;
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_SCROLL:
case MotionEvent.ACTION_OUTSIDE:
case MotionEvent.ACTION_CANCEL:
this.isSelected = false;
break;
}
// Redraw image and return super type
this.invalidate();
return super.dispatchTouchEvent(event);
}
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
float touchX = event.getX();
float touchY = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touch_start(touchX, touchY);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
touch_move(touchX, touchY);
invalidate();
break;
case MotionEvent.ACTION_UP:
touch_up();
invalidate();
break;
default:
return false;
}
return true;
}
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
return true; //TODO why?
case MotionEvent.ACTION_MOVE:
removeAddTagView();
break;
case MotionEvent.ACTION_UP:
addTagCourseView((int) event.getX(), (int) event.getY());
break;
}
return super.onTouchEvent(event);
}
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
initTransform(event, -1);
return true;
case MotionEvent.ACTION_POINTER_DOWN:
initTransform(event, -1);
return true;
case MotionEvent.ACTION_MOVE:
transform(event);
return true;
case MotionEvent.ACTION_POINTER_UP:
initTransform(event,
// ignore the pointer that has gone up
event.getActionIndex());
return true;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
return true;
}
return super.onTouchEvent(event);
}
@Override
public boolean onTouchEvent(MotionEvent motionEvent) {
float x = motionEvent.getX();
float y = motionEvent.getX();
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
AndroidUtilities.runOnUIThread(longPressed, LONG_PRESS_TIME);
pressed = true;
processRelease = true;
setHighlighted(true);
break;
case MotionEvent.ACTION_UP:
setHighlighted(false);
AndroidUtilities.cancelRunOnUIThread(longPressed);
if (processRelease && x >= 0 && y >= 0 && x <= getMeasuredWidth() && y <= getMeasuredHeight()) {
delegate.shutterReleased();
}
break;
case MotionEvent.ACTION_MOVE:
if (x < 0 || y < 0 || x > getMeasuredWidth() || y > getMeasuredHeight()) {
AndroidUtilities.cancelRunOnUIThread(longPressed);
if (state == State.RECORDING) {
setHighlighted(false);
delegate.shutterCancel();
setState(State.DEFAULT, true);
}
}
break;
case MotionEvent.ACTION_CANCEL:
setHighlighted(false);
pressed = false;
}
return true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float eventX = event.getX();
float eventY = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
path.moveTo(eventX, eventY);
return true;
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
// When the hardware tracks events faster than they are delivered,
// the event will contain a history of those skipped points.
int historySize = event.getHistorySize();
for (int i = 0; i < historySize; i++) {
float historicalX = event.getHistoricalX(i);
float historicalY = event.getHistoricalY(i);
path.lineTo(historicalX, historicalY);
}
path.lineTo(eventX, eventY);
break;
default:
return false;
}
// Schedules a repaint.
invalidate();
return true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (singleLineEllipsis && getScrollX() > 0 && event.getAction() == MotionEvent.ACTION_DOWN && event.getX() < getPixel(4 * 5) && event.getY() > getHeight() - extraPaddingBottom - innerPaddingBottom && event.getY() < getHeight() - innerPaddingBottom) {
setSelection(0);
return false;
}
return super.onTouchEvent(event);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getPointerCount() > 1) {
return false;
}
float x = event.getX() - rectF.left;
float y = event.getY() - rectF.top;
if (!interacting && y < -AndroidUtilities.dp(10)) {
return false;
}
int action = event.getActionMasked();
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) {
if (interacting && delegate != null) {
delegate.onFinishedColorPicking();
getContext().getSharedPreferences("paint", Activity.MODE_PRIVATE).edit().putFloat("last_color_location", location).commit();
}
interacting = false;
wasChangingWeight = changingWeight;
changingWeight = false;
setDragging(false, true);
} else if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE) {
if (!interacting) {
interacting = true;
if (delegate != null) {
delegate.onBeganColorPicking();
}
}
float colorLocation = Math.max(0.0f, Math.min(1.0f, x / rectF.width()));
setLocation(colorLocation);
setDragging(true, true);
if (y < -AndroidUtilities.dp(10)) {
changingWeight = true;
float weightLocation = (-y - AndroidUtilities.dp(10)) / AndroidUtilities.dp(190);
weightLocation = Math.max(0.0f, Math.min(1.0f, weightLocation));
setWeight(weightLocation);
}
if (delegate != null) {
delegate.onColorValueChanged();
}
return true;
}
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (!mEnabled)
return false;
final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
if (DEBUG)
if (action == MotionEvent.ACTION_DOWN)
Log.v(TAG, "Received ACTION_DOWN");
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP
|| (action != MotionEvent.ACTION_DOWN && mIsUnableToDrag)) {
endDrag();
return false;
}
switch (action) {
case MotionEvent.ACTION_MOVE:
determineDrag(ev);
break;
case MotionEvent.ACTION_DOWN:
int index = MotionEventCompat.getActionIndex(ev);
mActivePointerId = MotionEventCompat.getPointerId(ev, index);
if (mActivePointerId == INVALID_POINTER)
break;
mLastMotionX = mInitialMotionX = MotionEventCompat.getX(ev, index);
mLastMotionY = MotionEventCompat.getY(ev, index);
if (thisTouchAllowed(ev)) {
mIsBeingDragged = false;
mIsUnableToDrag = false;
if (isMenuOpen() && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) {
mQuickReturn = true;
}
} else {
mIsUnableToDrag = true;
}
break;
case MotionEventCompat.ACTION_POINTER_UP:
onSecondaryPointerUp(ev);
break;
}
if (!mIsBeingDragged) {
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
}
mVelocityTracker.addMovement(ev);
}
return mIsBeingDragged || mQuickReturn;
}
@Override
public boolean onTouch(final View view, MotionEvent motionEvent) {
TinderStackLayout tinderStackLayout = ((TinderStackLayout)view.getParent());
TinderCardView topCard = (TinderCardView) tinderStackLayout.getChildAt(tinderStackLayout.getChildCount()-1);
if(topCard.equals(view)){
switch(motionEvent.getAction()){
case MotionEvent.ACTION_DOWN:
oldX = motionEvent.getX();
oldY = motionEvent.getY();
// cancel any current animations
view.clearAnimation();
return true;
case MotionEvent.ACTION_UP:
if(isCardBeyondLeftBoundary(view)){
RxBus.getInstance().send(new TopCardMovedEvent(-(screenWidth)));
dismissCard(view, -(screenWidth * 2));
} else if(isCardBeyondRightBoundary(view)){
RxBus.getInstance().send(new TopCardMovedEvent(screenWidth));
dismissCard(view, (screenWidth * 2));
} else {
RxBus.getInstance().send(new TopCardMovedEvent(0));
resetCard(view);
}
return true;
case MotionEvent.ACTION_MOVE:
newX = motionEvent.getX();
newY = motionEvent.getY();
dX = newX - oldX;
dY = newY - oldY;
float posX = view.getX() + dX;
RxBus.getInstance().send(new TopCardMovedEvent(posX));
// Set new position
view.setX(view.getX() + dX);
view.setY(view.getY() + dY);
setCardRotation(view, view.getX());
updateAlphaOfBadges(posX);
return true;
default :
return super.onTouchEvent(motionEvent);
}
}
return super.onTouchEvent(motionEvent);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = MotionEventCompat.getActionMasked(ev);
if (!isEnabled() || !isTouchEnabled() || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) {
mDragHelper.cancel();
return super.onInterceptTouchEvent(ev);
}
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
mDragHelper.cancel();
return false;
}
final float x = ev.getX();
final float y = ev.getY();
switch (action) {
case MotionEvent.ACTION_DOWN: {
mIsUnableToDrag = false;
mInitialMotionX = x;
mInitialMotionY = y;
break;
}
case MotionEvent.ACTION_MOVE: {
final float adx = Math.abs(x - mInitialMotionX);
final float ady = Math.abs(y - mInitialMotionY);
final int dragSlop = mDragHelper.getTouchSlop();
// Handle any horizontal scrolling on the drag view.
if (mIsUsingDragViewTouchEvents && adx > dragSlop && ady < dragSlop) {
return super.onInterceptTouchEvent(ev);
}
if ((ady > dragSlop && adx > ady) || !isDragViewUnder((int)mInitialMotionX, (int)mInitialMotionY)) {
mDragHelper.cancel();
mIsUnableToDrag = true;
return false;
}
break;
}
}
return mDragHelper.shouldInterceptTouchEvent(ev);
}
/**
* Handles the SDL Touch Event to keep track of pointer status and returns the appropriate
* Android MotionEvent according to this events status
* @param touchType The SDL TouchType that was received from the module
* @param touchEvent The SDL TouchEvent that was received from the module
* @return the correct native Android MotionEvent action to dispatch
*/
synchronized int getMotionEventAction(TouchType touchType, TouchEvent touchEvent){
eventTime = 0;
int motionEventAction = -1;
switch (touchType){
case BEGIN:
if(pointers.size() == 0){
//The motion event has just begun
motionEventAction = MotionEvent.ACTION_DOWN;
downTime = SystemClock.uptimeMillis();
downTimeOnHMI = touchEvent.getTimestamps().get(touchEvent.getTimestamps().size() - 1);
eventTime = downTime;
} else{
motionEventAction = MotionEvent.ACTION_POINTER_DOWN | pointers.size() << MotionEvent.ACTION_POINTER_INDEX_SHIFT;
eventTime = downTime + touchEvent.getTimestamps().get(touchEvent.getTimestamps().size() - 1) - downTimeOnHMI;
}
pointers.add(new Pointer(touchEvent.getId()));
break;
case MOVE:
motionEventAction = MotionEvent.ACTION_MOVE;
eventTime = downTime + touchEvent.getTimestamps().get(touchEvent.getTimestamps().size() - 1) - downTimeOnHMI;
break;
case END:
if(pointers.size() <= 1){
//The motion event has just ended
motionEventAction = MotionEvent.ACTION_UP;
} else {
int pointerIndex = pointers.indexOf(getPointerById(touchEvent.getId()));
if (pointerIndex != -1) {
motionEventAction = MotionEvent.ACTION_POINTER_UP | pointerIndex << MotionEvent.ACTION_POINTER_INDEX_SHIFT;
} else {
motionEventAction = MotionEvent.ACTION_UP;
}
}
eventTime = downTime + touchEvent.getTimestamps().get(touchEvent.getTimestamps().size() - 1) - downTimeOnHMI;
break;
case CANCEL:
//Assuming this cancels the entire event
motionEventAction = MotionEvent.ACTION_CANCEL;
eventTime = downTime + touchEvent.getTimestamps().get(touchEvent.getTimestamps().size() - 1) - downTimeOnHMI;
break;
default:
break;
}
return motionEventAction;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (!isEnabled()) {
return false;
}
final int action = event.getAction() & MotionEvent.ACTION_MASK;
if (action != MotionEvent.ACTION_DOWN) {
return false;
}
removeAllCallbacks();
// Make sure we support flinging inside scrollables.
getParent().requestDisallowInterceptTouchEvent(true);
if (isHorizontalMode()) {
mLastDownOrMoveEventX = mLastDownEventX = event.getX();
if (!mFlingScroller.isFinished()) {
mFlingScroller.forceFinished(true);
mAdjustScroller.forceFinished(true);
onScrollerFinished(mFlingScroller);
onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
} else if (!mAdjustScroller.isFinished()) {
mFlingScroller.forceFinished(true);
mAdjustScroller.forceFinished(true);
onScrollerFinished(mAdjustScroller);
} else if (mLastDownEventX >= mLeftDividerLeft
&& mLastDownEventX <= mRightDividerRight) {
if (mOnClickListener != null) {
mOnClickListener.onClick(this);
}
} else if (mLastDownEventX < mLeftDividerLeft) {
postChangeCurrentByOneFromLongPress(false);
} else if (mLastDownEventX > mRightDividerRight) {
postChangeCurrentByOneFromLongPress(true);
}
} else {
mLastDownOrMoveEventY = mLastDownEventY = event.getY();
if (!mFlingScroller.isFinished()) {
mFlingScroller.forceFinished(true);
mAdjustScroller.forceFinished(true);
onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
} else if (!mAdjustScroller.isFinished()) {
mFlingScroller.forceFinished(true);
mAdjustScroller.forceFinished(true);
} else if (mLastDownEventY >= mTopDividerTop
&& mLastDownEventY <= mBottomDividerBottom) {
if (mOnClickListener != null) {
mOnClickListener.onClick(this);
}
} else if (mLastDownEventY < mTopDividerTop) {
postChangeCurrentByOneFromLongPress(false);
} else if (mLastDownEventY > mBottomDividerBottom) {
postChangeCurrentByOneFromLongPress(true);
}
}
return true;
}
public boolean onTouchEvent(android.view.MotionEvent ev) {
if (super.onTouchEvent(ev)) {
return true;
}
if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
return false;
}
final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
switch (action) {
case MotionEvent.ACTION_DOWN:
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
mLastMotionX = ev.getX();
break;
case MotionEvent.ACTION_MOVE: {
final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
final float x = MotionEventCompat.getX(ev, activePointerIndex);
final float deltaX = x - mLastMotionX;
if (!mIsDragging) {
if (Math.abs(deltaX) > mTouchSlop) {
mIsDragging = true;
}
}
if (mIsDragging) {
mLastMotionX = x;
if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
mViewPager.fakeDragBy(deltaX);
}
}
break;
}
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
if (!mIsDragging) {
final int count = mViewPager.getAdapter().getCount();
final int width = getWidth();
final float halfWidth = width / 2f;
final float sixthWidth = width / 6f;
if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) {
if (action != MotionEvent.ACTION_CANCEL) {
mViewPager.setCurrentItem(mCurrentPage - 1);
}
return true;
} else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) {
if (action != MotionEvent.ACTION_CANCEL) {
mViewPager.setCurrentItem(mCurrentPage + 1);
}
return true;
}
}
mIsDragging = false;
mActivePointerId = INVALID_POINTER;
if (mViewPager.isFakeDragging())
mViewPager.endFakeDrag();
break;
case MotionEventCompat.ACTION_POINTER_DOWN: {
final int index = MotionEventCompat.getActionIndex(ev);
mLastMotionX = MotionEventCompat.getX(ev, index);
mActivePointerId = MotionEventCompat.getPointerId(ev, index);
break;
}
case MotionEventCompat.ACTION_POINTER_UP:
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
if (pointerId == mActivePointerId) {
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
}
mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
break;
}
return true;
}
public boolean onInterceptTouchEvent(MotionEvent ev) {
this.ensureTarget();
int action = ev.getActionMasked();
if (!this.mRefreshing && this.mReturningToStart && action == 0) {
this.mReturningToStart = false;
}
if (this.isEnabled() && !this.mReturningToStart && !this.canChildScrollUp()) {
switch (action) {
case MotionEvent.ACTION_DOWN:
this.mLastMotionY = this.mInitialMotionY = ev.getY();
this.mActivePointerId = ev.getPointerId(0);
this.mIsBeingDragged = false;
this.mCurrPercentage = 0.0F;
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
this.mIsBeingDragged = false;
this.mCurrPercentage = 0.0F;
this.mActivePointerId = INVALID_POINTER;
break;
case MotionEvent.ACTION_MOVE:
if (this.mActivePointerId == INVALID_POINTER) {
Log.e(LOG_TAG, "Got ACTION_MOVE event but don't have an active pointer id.");
return false;
}
int pointerIndex = ev.findPointerIndex(this.mActivePointerId);
if (pointerIndex < 0) {
Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id.");
return false;
}
float y = ev.getY(pointerIndex);
float yDiff = y - this.mInitialMotionY;
if (yDiff > (float) this.mTouchSlop) {
this.mLastMotionY = y;
this.mIsBeingDragged = true;
}
case MotionEvent.ACTION_OUTSIDE:
case MotionEvent.ACTION_POINTER_DOWN:
default:
break;
case MotionEvent.ACTION_POINTER_UP:
this.onSecondaryPointerUp(ev);
}
return this.mIsBeingDragged;
} else {
return false;
}
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (mChildView == null || mDisableBounce)
return super.onTouchEvent(ev);
switch (ev.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
mStart = isHorizontal ? ev.getX() : ev.getY();
break;
case MotionEvent.ACTION_MOVE:
float now, delta;
int dampingDelta;
now = isHorizontal ? ev.getX() : ev.getY();
delta = mStart - now;
dampingDelta = (int) (delta / calculateDamping());
mStart = now;
boolean onePointerTouch = true;
if (mPreDelta <= 0 && dampingDelta > 0) {
onePointerTouch = false;
} else if (mPreDelta >= 0 && dampingDelta < 0) {
onePointerTouch = false;
}
mPreDelta = dampingDelta;
if (onePointerTouch && canMove(dampingDelta)) {
mOverScrolledDistance += dampingDelta;
if (isHorizontal) {
mChildView.setTranslationX(-mOverScrolledDistance);
} else {
mChildView.setTranslationY(-mOverScrolledDistance);
}
if (mOverScrollListener != null) {
mOverScrollListener.onOverScrolling(mOverScrolledDistance <= 0, Math.abs(mOverScrolledDistance));
}
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
mPreDelta = 0;
mOverScrolledDistance = 0;
cancelAnimator();
if (isHorizontal) {
mAnimator = ObjectAnimator.ofFloat(mChildView, View.TRANSLATION_X, 0);
} else {
mAnimator = ObjectAnimator.ofFloat(mChildView, View.TRANSLATION_Y, 0);
}
mAnimator.setDuration(mBounceDelay).setInterpolator(mInterpolator);
if (mOverScrollListener != null) {
mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float value = (float) animation.getAnimatedValue();
mOverScrollListener.onOverScrolling(value <= 0, Math.abs((int) value));
}
});
}
mAnimator.start();
break;
}
return super.onTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN: {
mVelocityTracker = VelocityTracker.obtain();
mVelocityTracker.addMovement(ev);
mLastTouchX = getActiveX(ev);
mLastTouchY = getActiveY(ev);
mIsDragging = false;
break;
}
case MotionEvent.ACTION_MOVE: {
final float x = getActiveX(ev);
final float y = getActiveY(ev);
final float dx = x - mLastTouchX, dy = y - mLastTouchY;
if (!mIsDragging) {
// Use Pythagoras to see if drag length is larger than
// touch slop
mIsDragging = Math.sqrt((dx * dx) + (dy * dy)) >= mTouchSlop;
}
if (mIsDragging) {
mListener.onDrag(dx, dy);
mLastTouchX = x;
mLastTouchY = y;
if (null != mVelocityTracker) {
mVelocityTracker.addMovement(ev);
}
}
break;
}
case MotionEvent.ACTION_CANCEL: {
// Recycle Velocity Tracker
if (null != mVelocityTracker) {
mVelocityTracker.recycle();
mVelocityTracker = null;
}
break;
}
case MotionEvent.ACTION_UP: {
if (mIsDragging) {
if (null != mVelocityTracker) {
mLastTouchX = getActiveX(ev);
mLastTouchY = getActiveY(ev);
// Compute velocity within the last 1000ms
mVelocityTracker.addMovement(ev);
mVelocityTracker.computeCurrentVelocity(1000);
final float vX = mVelocityTracker.getXVelocity(), vY = mVelocityTracker.getYVelocity();
// If the velocity is greater than minVelocity, call
// listener
if (Math.max(Math.abs(vX), Math.abs(vY)) >= mMinimumVelocity) {
mListener.onFling(mLastTouchX, mLastTouchY, -vX, -vY);
}
}
}
// Recycle Velocity Tracker
if (null != mVelocityTracker) {
mVelocityTracker.recycle();
mVelocityTracker = null;
}
break;
}
}
return true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (singleLineEllipsis && getScrollX() > 0 && event.getAction() == MotionEvent.ACTION_DOWN && event.getX() < getPixel(4 * 5) && event.getY() > getHeight() - extraPaddingBottom - innerPaddingBottom && event.getY() < getHeight() - innerPaddingBottom) {
setSelection(0);
return false;
}
if (hasFocus() && showClearButton) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (insideClearButton(event)) {
clearButtonTouched = true;
clearButtonClicking = true;
return true;
}
case MotionEvent.ACTION_MOVE:
if (clearButtonClicking && !insideClearButton(event)) {
clearButtonClicking = false;
}
if (clearButtonTouched) {
return true;
}
break;
case MotionEvent.ACTION_UP:
if (clearButtonClicking) {
if (!TextUtils.isEmpty(getText())) {
setText(null);
}
clearButtonClicking = false;
}
if (clearButtonTouched) {
clearButtonTouched = false;
return true;
}
clearButtonTouched = false;
break;
case MotionEvent.ACTION_CANCEL:
clearButtonTouched = false;
clearButtonClicking = false;
break;
}
}
return super.onTouchEvent(event);
}