当前位置: 首页>>代码示例>>Java>>正文


Java MotionEventCompat.getX方法代码示例

本文整理汇总了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);
            }
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:20,代码来源:ItemTouchHelper.java

示例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);
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:26,代码来源:ItemTouchHelper.java

示例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);
    }
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:21,代码来源:ItemTouchHelper.java

示例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);
}
 
开发者ID:lanyuanxiaoyao,项目名称:PicKing,代码行数:26,代码来源:ScaleDragDetector.java

示例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();
        }
    }
}
 
开发者ID:zwmlibs,项目名称:BookReader-master,代码行数:19,代码来源:DirectionalViewpager.java

示例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;
    }
}
 
开发者ID:huashengzzz,项目名称:SmartChart,代码行数:11,代码来源:ViewDragHelper.java

示例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;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:14,代码来源:RecyclerView.java

示例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();
        }
    }
}
 
开发者ID:reyanshmishra,项目名称:Rey-MusicPlayer,代码行数:15,代码来源:VelocityViewPager.java

示例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();
		}
	}
}
 
开发者ID:6ag,项目名称:LiuAGeAndroid,代码行数:16,代码来源:CustomViewAbove.java

示例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();
        }
    }
}
 
开发者ID:Datatellit,项目名称:xlight_android_native,代码行数:16,代码来源:CustomViewAbove.java

示例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);
                }
            }
        }
    }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:33,代码来源:ItemTouchHelper.java

示例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);
    }
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:11,代码来源:RecyclerView.java

示例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;
        }
    }
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:13,代码来源:ViewDragHelper.java

示例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();
    }
}
 
开发者ID:lanyuanxiaoyao,项目名称:PicKing,代码行数:8,代码来源:ScaleDragDetector.java

示例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();
		}
	}
}
 
开发者ID:fengshihao,项目名称:WebPager,代码行数:15,代码来源:CustomViewPager.java


注:本文中的android.support.v4.view.MotionEventCompat.getX方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。