本文整理汇总了Java中android.support.v4.view.MotionEventCompat.getY方法的典型用法代码示例。如果您正苦于以下问题:Java MotionEventCompat.getY方法的具体用法?Java MotionEventCompat.getY怎么用?Java MotionEventCompat.getY使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.view.MotionEventCompat
的用法示例。
在下文中一共展示了MotionEventCompat.getY方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateDxDy
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private void updateDxDy(MotionEvent ev, int directionFlags, int pointerIndex) {
float x = MotionEventCompat.getX(ev, pointerIndex);
float y = MotionEventCompat.getY(ev, pointerIndex);
this.mDx = x - this.mInitialTouchX;
this.mDy = y - this.mInitialTouchY;
if ((directionFlags & 4) == 0) {
this.mDx = Math.max(0.0f, this.mDx);
}
if ((directionFlags & 8) == 0) {
this.mDx = Math.min(0.0f, this.mDx);
}
if ((directionFlags & 1) == 0) {
this.mDy = Math.max(0.0f, this.mDy);
}
if ((directionFlags & 2) == 0) {
this.mDy = Math.min(0.0f, this.mDy);
}
}
示例2: findSwipedView
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private ViewHolder findSwipedView(MotionEvent motionEvent) {
final RecyclerView.LayoutManager lm = mRecyclerView.getLayoutManager();
if (mActivePointerId == ACTIVE_POINTER_ID_NONE) {
return null;
}
final int pointerIndex = MotionEventCompat.findPointerIndex(motionEvent, mActivePointerId);
final float dx = MotionEventCompat.getX(motionEvent, pointerIndex) - mInitialTouchX;
final float dy = MotionEventCompat.getY(motionEvent, pointerIndex) - mInitialTouchY;
final float absDx = Math.abs(dx);
final float absDy = Math.abs(dy);
if (absDx < mSlop && absDy < mSlop) {
return null;
}
if (absDx > absDy && lm.canScrollHorizontally()) {
return null;
} else if (absDy > absDx && lm.canScrollVertically()) {
return null;
}
View child = findChildView(motionEvent);
if (child == null) {
return null;
}
return mRecyclerView.getChildViewHolder(child);
}
示例3: updateDxDy
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private void updateDxDy(MotionEvent ev, int directionFlags, int pointerIndex) {
final float x = MotionEventCompat.getX(ev, pointerIndex);
final float y = MotionEventCompat.getY(ev, pointerIndex);
// Calculate the distance moved
mDx = x - mInitialTouchX;
mDy = y - mInitialTouchY;
if ((directionFlags & LEFT) == 0) {
mDx = Math.max(0, mDx);
}
if ((directionFlags & RIGHT) == 0) {
mDx = Math.min(0, mDx);
}
if ((directionFlags & UP) == 0) {
mDy = Math.max(0, mDy);
}
if ((directionFlags & DOWN) == 0) {
mDy = Math.min(0, mDy);
}
}
示例4: onLongPress
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
@Override
public void onLongPress(MotionEvent e) {
View child = findChildView(e);
if (child != null) {
ViewHolder vh = mRecyclerView.getChildViewHolder(child);
if (vh != null) {
if (!mCallback.hasDragFlag(mRecyclerView, vh)) {
return;
}
int pointerId = MotionEventCompat.getPointerId(e, 0);
// Long press is deferred.
// Check w/ active pointer id to avoid selecting after motion
// event is canceled.
if (pointerId == mActivePointerId) {
final int index = MotionEventCompat
.findPointerIndex(e, mActivePointerId);
final float x = MotionEventCompat.getX(e, index);
final float y = MotionEventCompat.getY(e, index);
mInitialTouchX = x;
mInitialTouchY = y;
mDx = mDy = 0f;
if (DEBUG) {
Log.d(TAG,
"onlong press: x:" + mInitialTouchX + ",y:" + mInitialTouchY);
}
if (mCallback.isLongPressDragEnabled()) {
select(vh, ACTION_STATE_DRAG);
}
}
}
}
}
示例5: onInterceptTouchEvent
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
mScroller.forceFinished(true);
int type = MotionEventCompat.getActionMasked(ev);
float currentX = MotionEventCompat.getX(ev, 0);
float currentY = MotionEventCompat.getY(ev, 0);
switch (type) {
case MotionEvent.ACTION_DOWN:
downX = currentX;
downY = currentY;
float x = firstView.getX() + firstView.getMeasuredWidth() / 2.0f;
float y = firstView.getY() + firstView.getMeasuredHeight() / 2.0f;
lastAngle = (float) getRelativeAngle(x, y);
break;
case MotionEvent.ACTION_MOVE:
float distance = getDistance(downX, downY, currentX, currentY);
if (distance > ViewConfiguration.getTouchSlop()) {
return true;
}
break;
case MotionEvent.ACTION_UP:
break;
}
return false;
}
示例6: getMotionEventY
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private float getMotionEventY(MotionEvent ev, int activePointerId) {
final int index = MotionEventCompat.findPointerIndex(ev, activePointerId);
if (index < 0) {
return -1;
}
return MotionEventCompat.getY(ev, index);
}
示例7: saveLastMotion
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private void saveLastMotion(MotionEvent ev) {
int pointerCount = MotionEventCompat.getPointerCount(ev);
for (int i = 0; i < pointerCount; i++) {
int pointerId = MotionEventCompat.getPointerId(ev, i);
float x = MotionEventCompat.getX(ev, i);
float y = MotionEventCompat.getY(ev, i);
this.mLastMotionX[pointerId] = x;
this.mLastMotionY[pointerId] = y;
}
}
示例8: saveLastMotion
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private void saveLastMotion(MotionEvent ev) {
final int pointerCount = MotionEventCompat.getPointerCount(ev);
for (int i = 0; i < pointerCount; i++) {
final int pointerId = MotionEventCompat.getPointerId(ev, i);
final float x = MotionEventCompat.getX(ev, i);
final float y = MotionEventCompat.getY(ev, i);
mLastMotionX[pointerId] = x;
mLastMotionY[pointerId] = y;
}
}
示例9: getMotionEventY
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private float getMotionEventY(MotionEvent ev, int activePointerId) {
final int index = MotionEventCompat.findPointerIndex(ev,
activePointerId);
if (index < 0) {
return -1;
}
return MotionEventCompat.getY(ev, index);
}
示例10: onSecondaryPointerUp
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private void onSecondaryPointerUp(MotionEvent ev) {
int pointerIndex = (ev.getAction() & MotionEventCompat.ACTION_POINTER_INDEX_MASK) >> 8;
if (MotionEventCompat.getPointerId(ev, pointerIndex) == this.mActivePointerId) {
int newPointerIndex = pointerIndex == 0 ? 1 : 0;
this.mLastMotionY = (int) MotionEventCompat.getY(ev, newPointerIndex);
this.mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
if (this.mVelocityTracker != null) {
this.mVelocityTracker.clear();
}
}
}
示例11: checkSelectForSwipe
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private boolean checkSelectForSwipe(int action, MotionEvent motionEvent, int pointerIndex) {
if (this.mSelected != null || action != 2 || this.mActionState == 2 || !this.mCallback.isItemViewSwipeEnabled()) {
return false;
}
if (this.mRecyclerView.getScrollState() == 1) {
return false;
}
ViewHolder vh = findSwipedView(motionEvent);
if (vh == null) {
return false;
}
int swipeFlags = (65280 & this.mCallback.getAbsoluteMovementFlags(this.mRecyclerView, vh)) >> 8;
if (swipeFlags == 0) {
return false;
}
float x = MotionEventCompat.getX(motionEvent, pointerIndex);
float dx = x - this.mInitialTouchX;
float dy = MotionEventCompat.getY(motionEvent, pointerIndex) - this.mInitialTouchY;
float absDx = Math.abs(dx);
float absDy = Math.abs(dy);
if (absDx < ((float) this.mSlop) && absDy < ((float) this.mSlop)) {
return false;
}
if (absDx > absDy) {
if (dx < 0.0f && (swipeFlags & 4) == 0) {
return false;
}
if (dx > 0.0f && (swipeFlags & 8) == 0) {
return false;
}
} else if (dy < 0.0f && (swipeFlags & 1) == 0) {
return false;
} else {
if (dy > 0.0f && (swipeFlags & 2) == 0) {
return false;
}
}
this.mDy = 0.0f;
this.mDx = 0.0f;
this.mActivePointerId = MotionEventCompat.getPointerId(motionEvent, 0);
select(vh, 1);
return true;
}
示例12: getMotionEventY
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private float getMotionEventY(MotionEvent ev, int activePointerId) {
final int index = MotionEventCompat.findPointerIndex(ev, activePointerId);
if (index < 0) return -1;
return MotionEventCompat.getY(ev, index);
}
示例13: onInterceptTouchEvent
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) {
if (this.mTouchSlop < 0) {
this.mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop();
}
if (ev.getAction() == 2 && this.mIsBeingDragged) {
return true;
}
int y;
switch (MotionEventCompat.getActionMasked(ev)) {
case 0:
this.mIsBeingDragged = false;
int x = (int) ev.getX();
y = (int) ev.getY();
if (canDragView(child) && parent.isPointInChildBounds(child, x, y)) {
this.mLastMotionY = y;
this.mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
ensureVelocityTracker();
break;
}
case 1:
case 3:
this.mIsBeingDragged = false;
this.mActivePointerId = -1;
if (this.mVelocityTracker != null) {
this.mVelocityTracker.recycle();
this.mVelocityTracker = null;
break;
}
break;
case 2:
int activePointerId = this.mActivePointerId;
if (activePointerId != -1) {
int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
if (pointerIndex != -1) {
y = (int) MotionEventCompat.getY(ev, pointerIndex);
if (Math.abs(y - this.mLastMotionY) > this.mTouchSlop) {
this.mIsBeingDragged = true;
this.mLastMotionY = y;
break;
}
}
}
break;
}
if (this.mVelocityTracker != null) {
this.mVelocityTracker.addMovement(ev);
}
return this.mIsBeingDragged;
}
示例14: onInterceptTouchEvent
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
public boolean onInterceptTouchEvent(MotionEvent ev) {
boolean z = false;
int action = ev.getAction();
if (action == 2 && this.mIsBeingDragged) {
return true;
}
int y;
switch (action & 255) {
case 0:
y = (int) ev.getY();
if (!inChild((int) ev.getX(), y)) {
this.mIsBeingDragged = false;
recycleVelocityTracker();
break;
}
this.mLastMotionY = y;
this.mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
initOrResetVelocityTracker();
this.mVelocityTracker.addMovement(ev);
this.mScroller.computeScrollOffset();
if (!this.mScroller.isFinished()) {
z = true;
}
this.mIsBeingDragged = z;
startNestedScroll(2);
break;
case 1:
case 3:
this.mIsBeingDragged = false;
this.mActivePointerId = -1;
recycleVelocityTracker();
if (this.mScroller.springBack(getScrollX(), getScrollY(), 0, 0, 0, getScrollRange())) {
ViewCompat.postInvalidateOnAnimation(this);
}
stopNestedScroll();
break;
case 2:
int activePointerId = this.mActivePointerId;
if (activePointerId != -1) {
int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
if (pointerIndex != -1) {
y = (int) MotionEventCompat.getY(ev, pointerIndex);
if (Math.abs(y - this.mLastMotionY) > this.mTouchSlop && (getNestedScrollAxes() & 2) == 0) {
this.mIsBeingDragged = true;
this.mLastMotionY = y;
initVelocityTrackerIfNotExists();
this.mVelocityTracker.addMovement(ev);
this.mNestedYOffset = 0;
ViewParent parent = getParent();
if (parent != null) {
parent.requestDisallowInterceptTouchEvent(true);
break;
}
}
}
Log.e(TAG, "Invalid pointerId=" + activePointerId + " in onInterceptTouchEvent");
break;
}
break;
case 6:
onSecondaryPointerUp(ev);
break;
}
return this.mIsBeingDragged;
}
示例15: onInterceptTouchEvent
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
@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;
}