當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。