本文整理汇总了Java中android.support.v4.view.MotionEventCompat.ACTION_MASK属性的典型用法代码示例。如果您正苦于以下问题:Java MotionEventCompat.ACTION_MASK属性的具体用法?Java MotionEventCompat.ACTION_MASK怎么用?Java MotionEventCompat.ACTION_MASK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.support.v4.view.MotionEventCompat
的用法示例。
在下文中一共展示了MotionEventCompat.ACTION_MASK属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent event) {
if (mVirtualCount == 0 || !isEnabled()) {
return super.onTouchEvent(event);
}
if (event.getAction() == MotionEvent.ACTION_DOWN && event.getEdgeFlags() != 0) {
return false;
}
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
}
mVelocityTracker.addMovement(event);
final int action = event.getAction() & MotionEventCompat.ACTION_MASK;
if (action == MotionEvent.ACTION_MOVE) {
handleTouchActionMove(event);
} else {
if (action == MotionEvent.ACTION_DOWN) {
handleTouchActionDown(event);
}
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
handleTouchActionUp(event);
}
}
return true;
}
示例2: onInterceptTouchEvent
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (mVirtualCount == 0 || !isEnabled()) {
mIsBeingDragged = false;
} else {
final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
if (action == MotionEvent.ACTION_MOVE) {
handleTouchActionMove(ev);
} else {
if (action == MotionEvent.ACTION_DOWN) {
handleTouchActionDown(ev);
}
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
handleTouchActionUp(ev);
}
}
}
return mIsBeingDragged;
}
示例3: onInterceptTouchEvent
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (!isEnabled()) {
return false;
}
switch (MotionEventCompat.getActionMasked(ev) & MotionEventCompat.ACTION_MASK) {
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
viewDragHelper.cancel();
return false;
case MotionEvent.ACTION_DOWN:
int index = MotionEventCompat.getActionIndex(ev);
activePointerId = MotionEventCompat.getPointerId(ev, index);
if (activePointerId == INVALID_VIEW_POINTER) {
return false;
}
break;
default:
break;
}
boolean interceptTap = viewDragHelper.isViewUnder(dragView, (int) ev.getX(), (int) ev.getY());
return viewDragHelper.shouldInterceptTouchEvent(ev) || interceptTap;
}
示例4: onTouchEvent
/**
* Override method to dispatch touch event to the dragged view.
*
* @param ev captured.
* @return true if the touch event is realized over the drag or second view.
*/
@Override
public boolean onTouchEvent(MotionEvent ev) {
int actionMasked = MotionEventCompat.getActionMasked(ev);
if ((actionMasked & MotionEventCompat.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
activePointerId = MotionEventCompat.getPointerId(ev, actionMasked);
}
if (activePointerId == INVALID_VIEW_POINTER) {
return false;
}
viewDragHelper.processTouchEvent(ev);
if (isClosed()) {
return false;
}
boolean isDragViewHit = isViewHit(dragView, (int) ev.getX(), (int) ev.getY());
boolean isSecondViewHit = isViewHit(secondView, (int) ev.getX(), (int) ev.getY());
analyzeTouchToMaximizeIfNeeded(ev, isDragViewHit);
if (isMaximized()) {
dragView.dispatchTouchEvent(ev);
} else {
dragView.dispatchTouchEvent(cloneMotionEventWithAction(ev, MotionEvent.ACTION_CANCEL));
}
return isDragViewHit || isSecondViewHit;
}
示例5: onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction() & MotionEventCompat.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
mLastMotionX = mInitialMotionX = event.getX();
mLastMotionY = mInitialMotionY = event.getY();
break;
case MotionEvent.ACTION_MOVE:
float x = event.getX();
float xDiff = Math.abs(x - mInitialMotionX);
float y = event.getY();
float yDiff = Math.abs(y - mInitialMotionY);
if (yDiff > mTouchSlop && yDiff * 0.5f > xDiff) {//垂直方向
scrollBy(0, -(int) (y - mLastMotionY + 0.5f));
int distance = y >= mInitialMotionY ? mScrollDownHeight : mScrollUpHeight;
if(mScrollListener != null) {
float percent = yDiff / distance > 0.99 ? 1 : yDiff / distance;
mScrollListener.onScrolling(percent);
}
}
mLastMotionX = event.getX();
mLastMotionY = event.getY();
break;
case MotionEvent.ACTION_UP:
x = event.getX();
xDiff = Math.abs(x - mInitialMotionX);
y = event.getY();
yDiff = Math.abs(y - mInitialMotionY);
if (yDiff > mTouchSlop && yDiff * 0.5f > xDiff) {//垂直方向
FlingRunnable runnable = new FlingRunnable(yDiff, y - mInitialMotionY < 0);
runnable.start();
}
break;
}
return super.onTouchEvent(event);
}
示例6: onInterceptTouchEvent
/**
* Override method to intercept only touch events over the drag view and to cancel the drag when
* the action associated to the MotionEvent is equals to ACTION_CANCEL or ACTION_UP.
*
* @param ev captured.
* @return true if the view is going to process the touch event or false if not.
*/
@Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
if (!isEnabled())
{
return false;
}
switch (MotionEventCompat.getActionMasked(ev) & MotionEventCompat.ACTION_MASK)
{
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
viewDragHelper.cancel();
return false;
case MotionEvent.ACTION_DOWN:
int index = MotionEventCompat.getActionIndex(ev);
activePointerId = MotionEventCompat.getPointerId(ev, index);
if (activePointerId == INVALID_POINTER)
{
return false;
}
break;
default:
break;
}
boolean interceptTap = viewDragHelper.isViewUnder(dragView, (int) ev.getX(), (int) ev.getY());
return viewDragHelper.shouldInterceptTouchEvent(ev) || interceptTap;
}
示例7: onTouchEvent
/**
* Override method to dispatch touch event to the dragged view.
*
* @param ev captured.
* @return true if the touch event is realized over the drag or second view.
*/
@Override
public boolean onTouchEvent(MotionEvent ev)
{
int actionMasked = MotionEventCompat.getActionMasked(ev);
if ((actionMasked & MotionEventCompat.ACTION_MASK) == MotionEvent.ACTION_DOWN)
{
activePointerId = MotionEventCompat.getPointerId(ev, actionMasked);
}
if (activePointerId == INVALID_POINTER)
{
return false;
}
viewDragHelper.processTouchEvent(ev);
if (isClosed())
{
return false;
}
boolean isDragViewHit = isViewHit(dragView, (int) ev.getX(), (int) ev.getY());
boolean isSecondViewHit = isViewHit(secondView, (int) ev.getX(), (int) ev.getY());
analyzeTouchToMaximizeIfNeeded(ev, isDragViewHit);
if (isMaximized())
{
dragView.dispatchTouchEvent(ev);
}
else
{
dragView.dispatchTouchEvent(cloneMotionEventWithAction(ev, MotionEvent.ACTION_CANCEL));
}
return isDragViewHit || isSecondViewHit;
}
示例8: onTouchEvent
public boolean onTouchEvent(MotionEvent ev) {
if (super.onTouchEvent(ev)) {
return true;
}
if (this.mViewPager == null || this.mViewPager.getAdapter().getCount() == 0) {
return false;
}
int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
switch (action) {
case 0:
this.mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
this.mLastMotionX = ev.getX();
break;
case 1:
case 3:
if (!this.mIsDragging) {
int count = this.mViewPager.getAdapter().getCount();
int width = getWidth();
float halfWidth = ((float) width) / 2.0f;
float sixthWidth = ((float) width) / 6.0f;
if (this.mCurrentPage > 0 && ev.getX() < halfWidth - sixthWidth) {
if (action != 3) {
this.mViewPager.setCurrentItem(this.mCurrentPage - 1);
}
return true;
} else if (this.mCurrentPage < count - 1 && ev.getX() > halfWidth + sixthWidth) {
if (action != 3) {
this.mViewPager.setCurrentItem(this.mCurrentPage + 1);
}
return true;
}
}
this.mIsDragging = false;
this.mActivePointerId = -1;
if (this.mViewPager.isFakeDragging()) {
this.mViewPager.endFakeDrag();
break;
}
break;
case 2:
float x = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, this.mActivePointerId));
float deltaX = x - this.mLastMotionX;
if (!this.mIsDragging && Math.abs(deltaX) > ((float) this.mTouchSlop)) {
this.mIsDragging = true;
}
if (this.mIsDragging) {
this.mLastMotionX = x;
if (this.mViewPager.isFakeDragging() || this.mViewPager.beginFakeDrag()) {
this.mViewPager.fakeDragBy(deltaX);
break;
}
}
break;
case 5:
int index = MotionEventCompat.getActionIndex(ev);
this.mLastMotionX = MotionEventCompat.getX(ev, index);
this.mActivePointerId = MotionEventCompat.getPointerId(ev, index);
break;
case 6:
int pointerIndex = MotionEventCompat.getActionIndex(ev);
if (MotionEventCompat.getPointerId(ev, pointerIndex) == this.mActivePointerId) {
this.mActivePointerId = MotionEventCompat.getPointerId(ev, pointerIndex == 0 ? 1 : 0);
}
this.mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, this.mActivePointerId));
break;
}
return true;
}
示例9: onInterceptTouchEvent
@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;
}
示例10: onInterceptTouchEvent
@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;
}
示例11: onInterceptTouchEvent
@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;
}