本文整理汇总了Java中android.support.v4.view.MotionEventCompat.getX方法的典型用法代码示例。如果您正苦于以下问题:Java MotionEventCompat.getX方法的具体用法?Java MotionEventCompat.getX怎么用?Java MotionEventCompat.getX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.view.MotionEventCompat
的用法示例。
在下文中一共展示了MotionEventCompat.getX方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onLongPress
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
public void onLongPress(MotionEvent e) {
View child = ItemTouchHelper.this.findChildView(e);
if (child != null) {
ViewHolder vh = ItemTouchHelper.this.mRecyclerView.getChildViewHolder(child);
if (vh != null && ItemTouchHelper.this.mCallback.hasDragFlag(ItemTouchHelper.this.mRecyclerView, vh) && MotionEventCompat.getPointerId(e, 0) == ItemTouchHelper.this.mActivePointerId) {
int index = MotionEventCompat.findPointerIndex(e, ItemTouchHelper.this.mActivePointerId);
float x = MotionEventCompat.getX(e, index);
float y = MotionEventCompat.getY(e, index);
ItemTouchHelper.this.mInitialTouchX = x;
ItemTouchHelper.this.mInitialTouchY = y;
ItemTouchHelper itemTouchHelper = ItemTouchHelper.this;
ItemTouchHelper.this.mDy = 0.0f;
itemTouchHelper.mDx = 0.0f;
if (ItemTouchHelper.this.mCallback.isLongPressDragEnabled()) {
ItemTouchHelper.this.select(vh, 2);
}
}
}
}
示例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: onTouchActivePointer
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private void onTouchActivePointer(int action, MotionEvent ev) {
switch (action) {
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 = 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);
mLastTouchX = MotionEventCompat.getX(ev, newPointerIndex);
mLastTouchY = MotionEventCompat.getY(ev, newPointerIndex);
}
break;
}
mActivePointerIndex = MotionEventCompat.findPointerIndex(ev,
mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
}
示例5: onSecondaryPointerUp
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private void onSecondaryPointerUp(MotionEvent ev) {
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = MotionEventCompat.getPointerId(ev, 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;
if (isHorizontal()) {
mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex);
} else {
mLastMotionY = MotionEventCompat.getY(ev, newPointerIndex);
}
mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
if (mVelocityTracker != null) {
mVelocityTracker.clear();
}
}
}
示例6: 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;
}
}
示例7: onPointerUp
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private void onPointerUp(MotionEvent e) {
int actionIndex = MotionEventCompat.getActionIndex(e);
if (MotionEventCompat.getPointerId(e, actionIndex) == this.mScrollPointerId) {
int newIndex = actionIndex == 0 ? 1 : 0;
this.mScrollPointerId = MotionEventCompat.getPointerId(e, newIndex);
int x = (int) (MotionEventCompat.getX(e, newIndex) + 0.5f);
this.mLastTouchX = x;
this.mInitialTouchX = x;
x = (int) (MotionEventCompat.getY(e, newIndex) + 0.5f);
this.mLastTouchY = x;
this.mInitialTouchY = x;
}
}
示例8: onSecondaryPointerUp
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private void onSecondaryPointerUp(MotionEvent ev) {
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = MotionEventCompat.getPointerId(ev, 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;
mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex);
mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
if (mVelocityTracker != null) {
mVelocityTracker.clear();
}
}
}
示例9: onSecondaryPointerUp
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private void onSecondaryPointerUp(MotionEvent ev) {
if (DEBUG) Log.v(TAG, "onSecondaryPointerUp called");
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = MotionEventCompat.getPointerId(ev, 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;
mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex);
mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
if (mVelocityTracker != null) {
mVelocityTracker.clear();
}
}
}
示例10: onSecondaryPointerUp
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private void onSecondaryPointerUp(MotionEvent ev) {
if (DEBUG) Log.v(TAG, "onSecondaryPointerUp called");
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = MotionEventCompat.getPointerId(ev, 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;
mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex);
mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
if (mVelocityTracker != null) {
mVelocityTracker.clear();
}
}
}
示例11: 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);
}
}
}
}
}
示例12: onPointerUp
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private void onPointerUp(MotionEvent e) {
final int actionIndex = MotionEventCompat.getActionIndex(e);
if (MotionEventCompat.getPointerId(e, actionIndex) == mScrollPointerId) {
// Pick a new pointer to pick up the slack.
final int newIndex = actionIndex == 0 ? 1 : 0;
mScrollPointerId = MotionEventCompat.getPointerId(e, newIndex);
mInitialTouchX = mLastTouchX = (int) (MotionEventCompat.getX(e, newIndex) + 0.5f);
mInitialTouchY = mLastTouchY = (int) (MotionEventCompat.getY(e, newIndex) + 0.5f);
}
}
示例13: 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);
if (mLastMotionX != null && mLastMotionY != null) {
mLastMotionX[pointerId] = x;
mLastMotionY[pointerId] = y;
}
}
}
示例14: getActiveX
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private float getActiveX(MotionEvent ev) {
try {
return MotionEventCompat.getX(ev, mActivePointerIndex);
} catch (Exception e) {
return ev.getX();
}
}
示例15: onSecondaryPointerUp
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private void onSecondaryPointerUp(MotionEvent ev) {
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = MotionEventCompat.getPointerId(ev, 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;
mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex);
mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
if (mVelocityTracker != null) {
mVelocityTracker.clear();
}
}
}