本文整理汇总了Java中android.view.MotionEvent.ACTION_CANCEL属性的典型用法代码示例。如果您正苦于以下问题:Java MotionEvent.ACTION_CANCEL属性的具体用法?Java MotionEvent.ACTION_CANCEL怎么用?Java MotionEvent.ACTION_CANCEL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.view.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.ACTION_CANCEL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: performTouchAction
private boolean performTouchAction(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// do nothing
// the init action has been done in the function onInterceptTouchEvent
break;
case MotionEvent.ACTION_MOVE:
if (isPullStart) {
return onPullStartActionMove(event);
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
if (isPullStart) {
return onPullStartActionCancel();
}
break;
default:
break;
}
return false;
}
示例2: onInterceptTouchEvent
@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
int action = e.getAction();
int y = (int) e.getRawY();
switch (action) {
case MotionEvent.ACTION_DOWN:
Log.i("onInterceptTouchEvent", "ACTION_DOWN");
// 这里直接触发onTouchEvent,直接返回true或者false,都会影响事件传递。
onTouchEvent(e);
break;
case MotionEvent.ACTION_MOVE:
Log.i("onInterceptTouchEvent", "ACTION_MOVE");
// Move事件全部拦截,有RecyclerView自己处理。
return true;
case MotionEvent.ACTION_UP:
Log.i("onInterceptTouchEvent", "ACTION_UP");
break;
case MotionEvent.ACTION_CANCEL:
Log.i("onInterceptTouchEvent", "ACTION_CANCEL");
break;
}
Log.i("onInterceptTouchEvent", "false");
return false;
}
示例3: onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent event) {
x = event.getRawX();
y = event.getRawY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touchX = event.getX();
touchY = event.getY();
break;
case MotionEvent.ACTION_MOVE:
if (dragEnabled) {
updateViewPostion();
}
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
touchX = touchY = 0;
dragEnabled = false;
break;
default:
break;
}
return super.onTouchEvent(event);
}
示例4: onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
if (slide.getVisibility() != View.VISIBLE)
break;
if (event.getX() < slide.getLeft() || event.getX() > slide.getRight())
break;
tracking = true;
return true;
case MotionEvent.ACTION_MOVE:
if (!tracking)
break;
slide.offsetLeftAndRight((int)
(event.getX() - slide.getLeft() - getLeft() - slide.getWidth()/2));
if (event.getX() > (getLeft() + getWidth() * COMPLETION)) {
if (listener != null)
listener.onComplete();
reset();
}
return true;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
if (!tracking)
break;
reset();
return true;
}
return super.onTouchEvent(event);
}
示例5: onMotionEvent
public boolean onMotionEvent(MotionEvent event) {
final boolean stylusButtonPressed = isStylusButtonPressed(event);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mIsButtonPressed = stylusButtonPressed;
if (mIsButtonPressed) {
return mListener.onPressed(event);
}
break;
case MotionEvent.ACTION_MOVE:
if (!Utilities.pointInView(mView, event.getX(), event.getY(), mSlop)) {
return false;
}
if (!mIsButtonPressed && stylusButtonPressed) {
mIsButtonPressed = true;
return mListener.onPressed(event);
} else if (mIsButtonPressed && !stylusButtonPressed) {
mIsButtonPressed = false;
return mListener.onReleased(event);
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
if (mIsButtonPressed) {
mIsButtonPressed = false;
return mListener.onReleased(event);
}
break;
}
return false;
}
示例6: onTouchEvent
/**
* Will forward touch events to the delegate view if the event is within the bounds
* specified in the constructor.
*
* @param event The touch event to forward
* @return True if the event was forwarded to the delegate, false otherwise.
*/
public boolean onTouchEvent(MotionEvent event) {
boolean sendToDelegate = false;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mDelegateTargeted = mTouchCheckBounds.contains(event.getX(), event.getY());
if (mDelegateTargeted) {
mWasTouchOutsideBounds = !mBounds.contains(event.getX(), event.getY());
sendToDelegate = true;
}
break;
case MotionEvent.ACTION_MOVE:
sendToDelegate = mDelegateTargeted;
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
sendToDelegate = mDelegateTargeted;
mDelegateTargeted = false;
break;
}
boolean handled = false;
if (sendToDelegate) {
float x = event.getX();
float y = event.getY();
if (mWasTouchOutsideBounds) {
event.setLocation(mBounds.centerX(), mBounds.centerY());
} else {
event.offsetLocation(-mBounds.left, -mBounds.top);
}
handled = mDelegateView.dispatchTouchEvent(event);
event.setLocation(x, y);
}
return handled;
}
示例7: onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()){
case MotionEvent.ACTION_DOWN:
myHandler.sendEmptyMessageDelayed(0, animTime);
downX = event.getX();
downY = event.getY();
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
float upX = event.getX();
float upY = event.getY();
if(myHandler.hasMessages(0)){
myHandler.removeMessages(0);
if (Math.abs(upX - downX) < dp5 && Math.abs(upY - downY) < dp5) {
if(onGestureListener != null) onGestureListener.onClick();
}
}else if(onGestureListener != null && closeMode){
onGestureListener.onLift();
closeButton();
}
break;
}
return true;
}
示例8: dispatchTouchEvent
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
stopAutoPlay();
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
startAutoPlay();
break;
}
return super.dispatchTouchEvent(ev);
}
示例9: isPointerNumChanged
/**
* Tell whether the number of motion event's pointer changed.
* @param event the current motion event
* @return true for number of motion event's pointer changed, otherwise false.
*/
private boolean isPointerNumChanged(MotionEvent event) {
return event.getActionMasked() == MotionEvent.ACTION_DOWN ||
event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN ||
event.getActionMasked() == MotionEvent.ACTION_UP ||
event.getActionMasked() == MotionEvent.ACTION_POINTER_UP ||
event.getActionMasked() == MotionEvent.ACTION_CANCEL;
}
示例10: onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent event) {
// Convert coordinates to our internal coordinate system
xPointer = event.getX();
yPointer = event.getY();
// MLog.d(TAG, xPointer + " " + yPointer);
switch (event.getActionMasked()) {
case MotionEvent.ACTION_CANCEL:
touching = false;
break;
case MotionEvent.ACTION_DOWN:
touching = true;
break;
case MotionEvent.ACTION_UP:
touching = false;
break;
case MotionEvent.ACTION_MOVE:
if (xPointer > 0 && xPointer < mWidth && yPointer > 0 && yPointer < mHeight) {
touching = true;
} else {
touching = false;
}
break;
}
mOnTouchAreaListener.onTouch(this, touching, xPointer, yPointer);
invalidate();
// return touching;
return super.onTouchEvent(event);
}
示例11: onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
mActivePointerId = ev.getPointerId(0);
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
mActivePointerId = INVALID_POINTER_ID;
break;
case MotionEvent.ACTION_POINTER_UP:
final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
final int pointerId = ev.getPointerId(pointerIndex);
if (pointerId == mActivePointerId) {
// This was our active pointer going up. Choose a new
// active pointer and adjust accordingly.
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mActivePointerId = ev.getPointerId(newPointerIndex);
mLastTouchX = ev.getX(newPointerIndex);
mLastTouchY = ev.getY(newPointerIndex);
}
break;
}
mActivePointerIndex = ev.findPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
return super.onTouchEvent(ev);
}
示例12: onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent event) {
isLastTouch = true;
if (isEnabled()) {
if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
if ((event.getX() <= getWidth() && event.getX() >= 0)) {
press = true;
// calculate value
int newValue = 0;
float division = (ball.xFin - ball.xIni) / (max - min);
if (event.getX() > ball.xFin) {
newValue = max;
} else if (event.getX() < ball.xIni) {
newValue = min;
} else {
newValue = min + (int) ((event.getX() - ball.xIni) / division);
}
if (value != newValue) {
value = newValue;
if (onValueChangedListener != null)
onValueChangedListener.onValueChanged(newValue);
}
// move ball indicator
float x = event.getX();
x = (x < ball.xIni) ? ball.xIni : x;
x = (x > ball.xFin) ? ball.xFin : x;
ViewHelper.setX(ball, x);
ball.changeBackground();
} else {
press = false;
isLastTouch = false;
}
} else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
press = false;
}
}
return true;
}
示例13: onInterceptTouchEvent
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (!isSwipeEnabled()) {
return false;
}
if (mClickToClose && getOpenStatus() == Status.Open && isTouchOnSurface(ev)) {
return true;
}
for (SwipeDenier denier : mSwipeDeniers) {
if (denier != null && denier.shouldDenySwipe(ev)) {
return false;
}
}
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
mDragHelper.processTouchEvent(ev);
mIsBeingDragged = false;
sX = ev.getRawX();
sY = ev.getRawY();
//if the swipe is in middle state(scrolling), should intercept the touch
if (getOpenStatus() == Status.Middle) {
mIsBeingDragged = true;
}
break;
case MotionEvent.ACTION_MOVE:
boolean beforeCheck = mIsBeingDragged;
checkCanDrag(ev);
if (mIsBeingDragged) {
ViewParent parent = getParent();
if (parent != null) {
parent.requestDisallowInterceptTouchEvent(true);
}
}
if (!beforeCheck && mIsBeingDragged) {
//let children has one chance to catch the touch, and request the swipe not intercept
//useful when swipeLayout wrap a swipeLayout or other gestural layout
return false;
}
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
mIsBeingDragged = false;
mDragHelper.processTouchEvent(ev);
break;
default://handle other action, such as ACTION_POINTER_DOWN/UP
mDragHelper.processTouchEvent(ev);
}
return mIsBeingDragged;
}
示例14: onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent event) {
if (Build.VERSION.SDK_INT >= 21 && getBackground() != null) {
if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
getBackground().setHotspot(event.getX(), event.getY());
}
}
if (mediaWebpage || delegate == null || inlineResult == null) {
return super.onTouchEvent(event);
}
int x = (int) event.getX();
int y = (int) event.getY();
boolean result = false;
int side = AndroidUtilities.dp(48);
if (documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO || documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC) {
boolean area = letterDrawable.getBounds().contains(x, y);
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (area) {
buttonPressed = true;
invalidate();
result = true;
radialProgress.swapBackground(getDrawableForCurrentState());
}
} else if (buttonPressed) {
if (event.getAction() == MotionEvent.ACTION_UP) {
buttonPressed = false;
playSoundEffect(SoundEffectConstants.CLICK);
didPressedButton();
invalidate();
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
buttonPressed = false;
invalidate();
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
if (!area) {
buttonPressed = false;
invalidate();
}
}
radialProgress.swapBackground(getDrawableForCurrentState());
}
} else {
if (inlineResult != null && inlineResult.content_url != null && inlineResult.content_url.length() > 0) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (letterDrawable.getBounds().contains(x, y)) {
buttonPressed = true;
result = true;
}
} else {
if (buttonPressed) {
if (event.getAction() == MotionEvent.ACTION_UP) {
buttonPressed = false;
playSoundEffect(SoundEffectConstants.CLICK);
delegate.didPressedImage(this);
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
buttonPressed = false;
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
if (!letterDrawable.getBounds().contains(x, y)) {
buttonPressed = false;
}
}
}
}
}
}
if (!result) {
result = super.onTouchEvent(event);
}
return result;
}
示例15: onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent ev) {
initVelocityTrackerIfNotExists();
mVelocityTracker.addMovement(ev);
final int action = ev.getAction();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
mIsBeingDragged = false;
mLastMotionY = (int) ev.getY();
mActivePointerId = ev.getPointerId(0);
break;
case MotionEvent.ACTION_MOVE:
final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
if (activePointerIndex == -1) {
// Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent");
break;
}
final int y = (int) ev.getY(activePointerIndex);
int deltaY = mLastMotionY - y;
if (!mIsBeingDragged && Math.abs(deltaY) > mTouchSlop) {
mIsBeingDragged = true;
if (deltaY > 0) {
deltaY -= mTouchSlop;
} else {
deltaY += mTouchSlop;
}
}
if (mIsBeingDragged) {
// Scroll to follow the motion event
mLastMotionY = y;
mFlexibleEffect.onPull((float) deltaY / getHeight());
if(!mFlexibleEffect.isFinished()){
return true;
}
}
break;
case MotionEvent.ACTION_UP:
if (mIsBeingDragged) {
mActivePointerId = INVALID_POINTER;
mIsBeingDragged = false;
if (mFlexibleEffect != null&&mFlexibleEffect.isPulling()) {
mFlexibleEffect.onAbsorb(-1);
}
final VelocityTracker velocityTracker = mVelocityTracker;
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
currentVelocity = mVelocityTracker.getYVelocity(mActivePointerId);
Log.d(TAG, "currentVelocity:"+mVelocityTracker.getYVelocity(mActivePointerId) );
recycleVelocityTracker();
}
break;
case MotionEvent.ACTION_CANCEL:
break;
}
return super.onTouchEvent(ev);
}