类android.view.MotionEvent源码实例Demo

下面列出了怎么用android.view.MotionEvent的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: ar-drawing-java   文件: DrawAR.java
/**
 * onTouchEvent handles saving the lastTouch screen position and setting bTouchDown and bNewStroke
 * AtomicBooleans to trigger addPoint and addStroke on the GL Thread to be called
 */
@Override
public boolean onTouchEvent(MotionEvent tap) {
    this.mDetector.onTouchEvent(tap);

    if (tap.getAction() == MotionEvent.ACTION_DOWN ) {
        lastTouch.set(new Vector2f(tap.getX(), tap.getY()));
        bTouchDown.set(true);
        bNewStroke.set(true);
        return true;
    } else if (tap.getAction() == MotionEvent.ACTION_MOVE || tap.getAction() == MotionEvent.ACTION_POINTER_DOWN) {
        lastTouch.set(new Vector2f(tap.getX(), tap.getY()));
        bTouchDown.set(true);
        return true;
    } else if (tap.getAction() == MotionEvent.ACTION_UP || tap.getAction() == MotionEvent.ACTION_CANCEL) {
        bTouchDown.set(false);
        lastTouch.set(new Vector2f(tap.getX(), tap.getY()));
        return true;
    }

    return super.onTouchEvent(tap);
}
 
源代码2 项目: spline   文件: SaturationValuePicker.java
@Override
public boolean onTouchEvent(MotionEvent event) {
    float x = event.getX() - mPadding;
    float y = event.getY() - mPadding;

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            // Reject touches in the padding region
            if (x < 0 || y < 0 || x > mWidth + mInset * 2 || y > mHeight + mInset * 2) {
                return false;
            }
        case MotionEvent.ACTION_MOVE:
            setSaturation(getSaturationForX(x - mInset));
            setValue(getValueForY(y - mInset));
            break;
    }

    return true;
}
 
源代码3 项目: NewFastFrame   文件: SuperRecyclerView.java
@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
    if (mRefreshEnabled) {
        final int action = MotionEventCompat.getActionMasked(e);
        final int actionIndex = MotionEventCompat.getActionIndex(e);
        switch (action) {
            case MotionEvent.ACTION_DOWN: {
                mActivePointerId = MotionEventCompat.getPointerId(e, 0);
                mLastTouchX = (int) (MotionEventCompat.getX(e, actionIndex) + 0.5f);
                mLastTouchY = (int) (MotionEventCompat.getY(e, actionIndex) + 0.5f);
            }
            break;
            case MotionEvent.ACTION_POINTER_DOWN: {
                mActivePointerId = MotionEventCompat.getPointerId(e, actionIndex);
                mLastTouchX = (int) (MotionEventCompat.getX(e, actionIndex) + 0.5f);
                mLastTouchY = (int) (MotionEventCompat.getY(e, actionIndex) + 0.5f);
            }
            break;
            case MotionEventCompat.ACTION_POINTER_UP: {
                onPointerUp(e);
            }
            break;
        }
    }
    return super.onInterceptTouchEvent(e);
}
 
源代码4 项目: dynamiclistview   文件: DynamicListLayout.java
public void setEvent(MotionEvent event, Listener listener) {
    float y = event.getY();

    if (savedY == 0)
        savedY = y;

    if (Math.abs(savedY - y) < 10)
        return;

    ScrollDirection nowDirection = savedY > event.getY() ? ScrollDirection.DOWN : ScrollDirection.UP;

    if (nowDirection != this.scrollDirection && listener != null)
        listener.onScrollDirectionChanged(DynamicListLayout.this, mDynamicListView, nowDirection);

    this.scrollDirection = nowDirection;
    this.savedY = event.getY();
}
 
源代码5 项目: AndroidSwipeLayout   文件: SwipeLayout.java
@Override
public boolean onDoubleTap(MotionEvent e) {
    if (mDoubleClickListener != null) {
        View target;
        View bottom = getCurrentBottomView();
        View surface = getSurfaceView();
        if (bottom != null && e.getX() > bottom.getLeft() && e.getX() < bottom.getRight()
                && e.getY() > bottom.getTop() && e.getY() < bottom.getBottom()) {
            target = bottom;
        } else {
            target = surface;
        }
        mDoubleClickListener.onDoubleClick(SwipeLayout.this, target == surface);
    }
    return true;
}
 
private void updateDxDy(MotionEvent ev, int directionFlags, int pointerIndex) {
  final float x = ev.getX(pointerIndex);
  final float y = ev.getY(pointerIndex);
  // Calculate the distance moved
  dX = x - initialTouchX;
  dY = y - initialTouchY;
  if ((directionFlags & LEFT) == 0) {
    dX = Math.max(0, dX);
  }
  if ((directionFlags & RIGHT) == 0) {
    dX = Math.min(0, dX);
  }
  if ((directionFlags & UP) == 0) {
    dY = Math.max(0, dY);
  }
  if ((directionFlags & DOWN) == 0) {
    dY = Math.min(0, dY);
  }
}
 
/**
 * to be called to process the events
 *
 * @param event
 * @return true if there was a tap event. otherwise returns false.
 */
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        lastDown = System.currentTimeMillis();
        lastPoint = new PointF(event.getX(), event.getY());
    } else if (lastDown > 0 && event.getAction() == MotionEvent.ACTION_MOVE) {
        if (Math.abs(event.getX() - lastPoint.x) > 60
                || Math.abs(event.getY() - lastPoint.y) > 60) {
            lastDown = 0;
        }
    } else if (event.getAction() == MotionEvent.ACTION_UP) {
        if (System.currentTimeMillis() - lastDown < 400) {
            return true;
        }
    }
    return false;
}
 
源代码8 项目: AndroidPdfViewerV2   文件: DragPinchManager.java
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
    OnTapListener onTapListener = pdfView.getOnTapListener();
    if (onTapListener == null || !onTapListener.onTap(e)) {
        ScrollHandle ps = pdfView.getScrollHandle();
        if (ps != null && !pdfView.documentFitsView()) {
            if (!ps.shown()) {
                ps.show();
            } else {
                ps.hide();
            }
        }
    }
    pdfView.performClick();
    return true;
}
 
源代码9 项目: smart-farmer-android   文件: CleanEditText.java
/**
 * @说明:isInnerWidth, isInnerHeight为ture,触摸点在删除图标之内,则视为点击了删除图标
 * event.getX() 获取相对应自身左上角的X坐标
 * event.getY() 获取相对应自身左上角的Y坐标
 * getWidth() 获取控件的宽度
 * getHeight() 获取控件的高度
 * getTotalPaddingRight() 获取删除图标左边缘到控件右边缘的距离
 * getPaddingRight() 获取删除图标右边缘到控件右边缘的距离
 * isInnerWidth:
 * getWidth() - getTotalPaddingRight() 计算删除图标左边缘到控件左边缘的距离
 * getWidth() - getPaddingRight() 计算删除图标右边缘到控件左边缘的距离
 * isInnerHeight:
 * distance 删除图标顶部边缘到控件顶部边缘的距离
 * distance + height 删除图标底部边缘到控件顶部边缘的距离
 **/
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_UP) {
        if (getCompoundDrawables()[2] != null) {
            int x = (int) event.getX();
            int y = (int) event.getY();
            Rect rect = getCompoundDrawables()[2].getBounds();
            int height = rect.height();
            int distance = (getHeight() - height) / 2;
            boolean isInnerWidth = x > (getWidth() - getTotalPaddingRight()) && x < (getWidth() - getPaddingRight());
            boolean isInnerHeight = y > distance && y < (distance + height);
            if (isInnerWidth && isInnerHeight) {
                this.setText("");
            }
        }
    }
    return super.onTouchEvent(event);
}
 
源代码10 项目: PinchToZoom   文件: ImageMatrixTouchHandler.java
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
	if (mode == DRAG) {
		if (flingDuration > 0 && !isAnimating()) {
			float factor = ((float) flingDuration / 1000f) * flingExaggeration;
			float[] values = corrector.getValues();
			float dx = (velocityX * factor) * values[Matrix.MSCALE_X];
			float dy = (velocityY * factor) * values[Matrix.MSCALE_Y];
			PropertyValuesHolder flingX = PropertyValuesHolder.ofFloat(FlingAnimatorHandler.PROPERTY_TRANSLATE_X, values[Matrix.MTRANS_X], values[Matrix.MTRANS_X] + dx);
			PropertyValuesHolder flingY = PropertyValuesHolder.ofFloat(FlingAnimatorHandler.PROPERTY_TRANSLATE_Y, values[Matrix.MTRANS_Y], values[Matrix.MTRANS_Y] + dy);
			valueAnimator = ValueAnimator.ofPropertyValuesHolder(flingX, flingY);
			valueAnimator.setDuration(flingDuration);
			valueAnimator.addUpdateListener(new FlingAnimatorHandler(corrector));
			valueAnimator.setInterpolator(new DecelerateInterpolator());
			valueAnimator.start();
			return true;
		}
	}
	return super.onFling(e1, e2, velocityX, velocityY);
}
 
源代码11 项目: XRadarView   文件: XRadarView.java
@Override
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            int x = (int) event.getX();
            int y = (int) event.getY();
            for (int i = 0; i < titleRects.size(); i++) {
                Rect rect = titleRects.get(i);
                if (rect != null && rect.contains(x, y)) {
                    if (onTitleClickListener != null) {
                        onTitleClickListener.onTitleClick(XRadarView.this, i, x, y, rect);
                        return true;
                    }
                }
            }
            break;
    }
    return super.onTouchEvent(event);
}
 
源代码12 项目: ncalc   文件: Graph3DView.java
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {

        renderer.stopRotate();
        startX = event.getX();
        startY = event.getY();
        return true;
    } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
        // Moves the trace or derivative

        renderer.move((event.getX() - startX) / width * 360, (event.getY() - startY) / height * 360);
        startX = event.getX();
        startY = event.getY();
        return true;
        //Resets values when users finishes their gesture
    } else if (event.getAction() == MotionEvent.ACTION_UP) {
        pinchDist = -1;
        startX = -1;
        startY = -1;
    }
    return true;
}
 
源代码13 项目: ImagePicker   文件: ImagePickerViewPager.java
@Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
    try
    {
        return super.onInterceptTouchEvent(ev);
    } catch (IllegalArgumentException ex)
    {
        ex.printStackTrace();
    }
    return false;
}
 
源代码14 项目: HeroVideo-master   文件: MediaPlayerView.java
@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (isInPlaybackState() && mMediaController != null) {
        toggleMediaControlsVisiblity();
    }
    return false;
}
 
源代码15 项目: Ticket-Analysis   文件: SuperSwipeRefreshLayout.java
private void onSecondaryPointerUp(MotionEvent ev) {
    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);
    }
}
 
源代码16 项目: AndroidBeautifulSearch   文件: DribSearchView.java
@Override
public boolean onTouch(View v, MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        float mx = event.getX();
        float my = event.getY();
        if (rect.contains(mx, my) && mClickSearchListener != null && mState == SEARCH) {
            mClickSearchListener.onClickSearch();
        }
    }
    if (other != null) {
        return other.onTouch(v, event);
    } else {
        return false;
    }
}
 
源代码17 项目: fangzhuishushenqi   文件: VerticalSeekbar.java
private void trackTouchEvent(MotionEvent event) {
    final int height = getHeight();
    final int top = getPaddingTop();
    final int bottom = getPaddingBottom();
    final int available = height - top - bottom;

    int y = (int) event.getY();

    float scale;
    float progress = 0;

    // 下面是最小值
    if (y > height - bottom) {
        scale = 1.0f;
    } else if (y < top) {
        scale = 0.0f;
    } else {
        scale = (float) (y - top) / (float) available;
        progress = mTouchProgressOffset;
    }

    final int max = getMax();
    progress += scale * max;

    setProgress((int) progress);
    // 便于监听用户触摸改变进度
    mOnSeekBarChangeListener.onProgressChanged(this, (int) progress, true);

}
 
源代码18 项目: android-recipes-app   文件: MotionEventCompat.java
@Override
public float getX(MotionEvent event, int pointerIndex) {
    if (pointerIndex == 0) {
        return event.getX();
    }
    throw new IndexOutOfBoundsException("Pre-Eclair does not support multiple pointers");
}
 
源代码19 项目: ExpressHelper   文件: ViewDragHelper.java
private void saveLastMotion(MotionEvent ev) {
    final int pointerCount = ev.getPointerCount();
    for (int i = 0; i < pointerCount; i++) {
        final int pointerId = ev.getPointerId(i);
        final float x = ev.getX(i);
        final float y = ev.getY(i);
        mLastMotionX[pointerId] = x;
        mLastMotionY[pointerId] = y;
    }
}
 
源代码20 项目: NewsMe   文件: SwipeLayout.java
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
	if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
		start();
	}
	try {
		mDragHelper.processTouchEvent(event);
	} catch (Exception e) {
		e.printStackTrace();
	}
	return true;
}
 
源代码21 项目: Melophile   文件: HomePager.java
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
  if (this.enabled) {
    return super.onInterceptTouchEvent(event);
  }

  return false;
}
 
源代码22 项目: wallpaper   文件: UGallery.java
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
	int keyCode;
	if (isScrollingLeft(e1, e2)) {
		keyCode = KeyEvent.KEYCODE_DPAD_LEFT;
	} else {
		keyCode = KeyEvent.KEYCODE_DPAD_RIGHT;
	}
	onKeyDown(keyCode, null);
	return true;
}
 
源代码23 项目: android-bottomsheet   文件: ResolverDrawerLayout.java
private void resetTouch() {
    mActivePointerId = MotionEvent.INVALID_POINTER_ID;
    mIsDragging = false;
    mOpenOnClick = false;
    mInitialTouchX = mInitialTouchY = mLastTouchY = 0;
    mVelocityTracker.clear();
}
 
源代码24 项目: imsdk-android   文件: PhotoView.java
private boolean onTouchEventInternal(@NonNull MotionEvent event) {
    int touchCount = event.getPointerCount();
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_POINTER_1_DOWN:
        case MotionEvent.ACTION_POINTER_2_DOWN:
            maxTouchCount = Math.max(maxTouchCount, touchCount);
            return true;
        default:
            break;
    }
    return false;
}
 
源代码25 项目: MoeGallery   文件: EclairGestureDetector.java
@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:
            // Ignore deprecation, ACTION_POINTER_ID_MASK and
            // ACTION_POINTER_ID_SHIFT has same value and are deprecated
            // You can have either deprecation or lint target api warning
            final int pointerIndex = Compat.getPointerIndex(ev.getAction());
            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);
}
 
源代码26 项目: YViewPagerDemo   文件: YViewPager.java
private void onSecondaryPointerUpVertical(MotionEvent ev) {
    final int pointerIndex = MotionEventCompat.getActionIndex(ev);
    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;
        mLastMotionY = ev.getY(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();
        }
    }
}
 
源代码27 项目: meizhi   文件: TouchImageView.java
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
    if (doubleTapListener != null) {
        return doubleTapListener.onDoubleTapEvent(e);
    }
    return false;
}
 
源代码28 项目: aurora-imui   文件: ImgBrowserViewPager.java
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
	try {
		return super.onInterceptTouchEvent(ev);
	} catch (IllegalArgumentException e) {
		e.printStackTrace();
		return false;
	}
}
 
源代码29 项目: Indic-Keyboard   文件: InputView.java
public boolean onTouchEvent(final int x, final int y, final MotionEvent me) {
    mReceiverView.getGlobalVisibleRect(mEventReceivingRect);
    // Translate global coordinates to <code>ReceiverView</code> local coordinates.
    me.setLocation(translateX(x), translateY(y));
    mReceiverView.dispatchTouchEvent(me);
    onForwardingEvent(me);
    return true;
}
 
源代码30 项目: ClipCircleHeadLikeQQ   文件: ClipHeaderActivity.java
public boolean onTouch(View v, MotionEvent event) {
    ImageView view = (ImageView) v;
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            savedMatrix.set(matrix);
            // 设置开始点位置
            start.set(event.getX(), event.getY());
            mode = DRAG;
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            oldDist = spacing(event);
            if (oldDist > 10f) {
                savedMatrix.set(matrix);
                midPoint(mid, event);
                mode = ZOOM;
            }
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_POINTER_UP:
            mode = NONE;
            break;
        case MotionEvent.ACTION_MOVE:
            if (mode == DRAG) {
                matrix.set(savedMatrix);
                matrix.postTranslate(event.getX() - start.x, event.getY()
                        - start.y);
            } else if (mode == ZOOM) {
                float newDist = spacing(event);
                if (newDist > 10f) {
                    matrix.set(savedMatrix);
                    float scale = newDist / oldDist;
                    matrix.postScale(scale, scale, mid.x, mid.y);
                }
            }
            break;
    }
    view.setImageMatrix(matrix);
    return true;
}
 
 类所在包
 同包方法