當前位置: 首頁>>代碼示例>>Java>>正文


Java MotionEvent.ACTION_CANCEL屬性代碼示例

本文整理匯總了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;
}
 
開發者ID:yangchong211,項目名稱:YCEventConflict,代碼行數:23,代碼來源:PullToZoomBaseView.java

示例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;
}
 
開發者ID:ymqq,項目名稱:CommonFramework,代碼行數:24,代碼來源:RefreshRecyclerView.java

示例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);
}
 
開發者ID:treasure-lau,項目名稱:Linphone4Android,代碼行數:24,代碼來源:LinphoneOverlay.java

示例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);
}
 
開發者ID:sdrausty,項目名稱:buildAPKsApps,代碼行數:32,代碼來源:Slider.java

示例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;
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:31,代碼來源:StylusEventHelper.java

示例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;
}
 
開發者ID:michelelacorte,項目名稱:FlickLauncher,代碼行數:40,代碼來源:TransformingTouchDelegate.java

示例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;
}
 
開發者ID:Zhaoss,項目名稱:WeiXinRecordedDemo,代碼行數:27,代碼來源:RecordedButton.java

示例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);
}
 
開發者ID:leobert-lan,項目名稱:UiLib,代碼行數:13,代碼來源:AutoLooperBanner.java

示例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;
}
 
開發者ID:erguotou520,項目名稱:weex-uikit,代碼行數:12,代碼來源:WXGesture.java

示例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);
}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:36,代碼來源:TouchAreaView.java

示例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);
}
 
開發者ID:mangestudio,項目名稱:GCSApp,代碼行數:28,代碼來源:VersionedGestureDetector.java

示例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;
}
 
開發者ID:dibakarece,項目名稱:DMAudioStreamer,代碼行數:41,代碼來源:Slider.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:51,代碼來源:SwipeLayout.java

示例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;
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:72,代碼來源:ContextLinkCell.java

示例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);
    }
 
開發者ID:teisun,項目名稱:SunmiUI,代碼行數:62,代碼來源:FlexibleScrollView.java


注:本文中的android.view.MotionEvent.ACTION_CANCEL屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。