本文整理汇总了Java中android.view.MotionEvent.getPointerId方法的典型用法代码示例。如果您正苦于以下问题:Java MotionEvent.getPointerId方法的具体用法?Java MotionEvent.getPointerId怎么用?Java MotionEvent.getPointerId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.getPointerId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onSecondaryPointerUp
import android.view.MotionEvent; //导入方法依赖的package包/类
private void onSecondaryPointerUp(MotionEvent ev) {
final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >>
MotionEvent.ACTION_POINTER_INDEX_SHIFT;
final int pointerId = ev.getPointerId(pointerIndex);
if (pointerId == mActivePointerId) {
// This was our active pointer going up. Choose a new
// active pointer and adjust accordingly.
// TODO: Make this decision more intelligent.
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mLastMotionX = mDownMotionX = ev.getX(newPointerIndex);
mLastMotionY = ev.getY(newPointerIndex);
mLastMotionXRemainder = 0;
mActivePointerId = ev.getPointerId(newPointerIndex);
if (mVelocityTracker != null) {
mVelocityTracker.clear();
}
}
}
示例2: handleFling
import android.view.MotionEvent; //导入方法依赖的package包/类
/**
* Handles a fling gesture.
*
* @param event
* The motion event, which triggered the fling gesture, as an instance of the class
* {@link MotionEvent}. The motion event may not be null
* @param dragState
* The current drag state, which determines the fling direction, as a value of the enum
* {@link DragState}. The drag state may not be null
*/
private void handleFling(@NonNull final MotionEvent event, @NonNull final DragState dragState) {
if (getVelocityTracker() != null) {
int pointerId = event.getPointerId(0);
getVelocityTracker().computeCurrentVelocity(1000, maxFlingVelocity);
float flingVelocity = Math.abs(getVelocityTracker().getYVelocity(pointerId));
if (flingVelocity > minFlingVelocity) {
float flingDistance = 0.25f * flingVelocity;
if (dragState == DragState.DRAG_TO_START) {
flingDistance = -1 * flingDistance;
}
long duration = Math.round(Math.abs(flingDistance) / flingVelocity * 1000);
notifyOnFling(flingDistance, duration);
}
}
}
示例3: onSecondaryPointerUp
import android.view.MotionEvent; //导入方法依赖的package包/类
private final void onSecondaryPointerUp(MotionEvent ev) {
final int pointerIndex = (ev.getAction() & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT;
final int pointerId = ev.getPointerId(pointerIndex);
if (pointerId == mActivePointerId) {
// This was our active pointer going up. Choose
// a new active pointer and adjust accordingly.
// TODO: Make this decision more intelligent.
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mDownMotionX = ev.getX(newPointerIndex);
mActivePointerId = ev.getPointerId(newPointerIndex);
}
}
示例4: onSecondaryPointerUp
import android.view.MotionEvent; //导入方法依赖的package包/类
private void onSecondaryPointerUp(MotionEvent ev) {
final int pointerIndex = ev.getActionIndex();
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;
mInitialTouchX = ev.getX(newPointerIndex);
mInitialTouchY = mLastTouchY = ev.getY(newPointerIndex);
mActivePointerId = ev.getPointerId(newPointerIndex);
}
}
示例5: onSecondaryPointerUp
import android.view.MotionEvent; //导入方法依赖的package包/类
private void onSecondaryPointerUp(MotionEvent ev) {
final int pointerIndex = (ev.getAction() & MotionEventCompat.ACTION_POINTER_INDEX_MASK)
>> MotionEventCompat.ACTION_POINTER_INDEX_SHIFT;
final int pointerId = ev.getPointerId(pointerIndex);
if (pointerId == mActivePointerId) {
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mLastMotionY = (int) ev.getY(newPointerIndex);
mActivePointerId = ev.getPointerId(newPointerIndex);
if (mVelocityTracker != null) {
mVelocityTracker.clear();
}
}
}
示例6: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@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);
try {
return super.onTouchEvent(ev);
} catch (IllegalArgumentException e) {
// Fix for support lib bug, happening when onDestroy is
return true;
}
}
示例7: onSecondaryPointerUp
import android.view.MotionEvent; //导入方法依赖的package包/类
private void onSecondaryPointerUp(MotionEvent ev) {
final int pointerIndex = ev.getActionIndex();
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;
mLastMotionX = ev.getX(newPointerIndex);
mActivePointerId = ev.getPointerId(newPointerIndex);
}
}
示例8: onInterceptTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
public boolean onInterceptTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case 0:
this.mActivePointerId = event.getPointerId(0);
this.mLastMotionY = event.getY();
break;
case 2:
int activePointerIndex = event.findPointerIndex(this.mActivePointerId);
if (activePointerIndex != -1) {
int move = (int) (event.getY(activePointerIndex) - this.mLastMotionY);
switch (this.mStatus) {
case one:
if (this.mChildHeader.isScrollBottom() && move < 0) {
return true;
}
case two:
if (this.mChildHeader.isScrollBottom() && this.mWebView.isScrollTop()
&& move > 0) {
return true;
}
default:
break;
}
}
break;
}
return super.onInterceptTouchEvent(event);
}
示例9: onPointerUp
import android.view.MotionEvent; //导入方法依赖的package包/类
private void onPointerUp(MotionEvent ev) {
final int pointerIndex = ev.getActionIndex();
final int pointerId = ev.getPointerId(pointerIndex);
if (pointerId == mActivePointerId) {
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mLastMotionX = ev.getX(newPointerIndex);
mActivePointerId = ev.getPointerId(newPointerIndex);
if (mVelocityTracker != null) {
mVelocityTracker.clear();
}
}
}
示例10: onSecondaryPointerUp
import android.view.MotionEvent; //导入方法依赖的package包/类
private void onSecondaryPointerUp(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;
mActivePointerId = ev.getPointerId(newPointerIndex);
}
}
示例11: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@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:
final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
>> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
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);
return super.onTouchEvent(ev);
}
示例12: onScroll
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
boolean result = false;
if (containsPan() &&
(e2.getPointerId(e1.getActionIndex()) == e1.getPointerId(e1.getActionIndex()))) {
if (panDownTime != e1.getEventTime()) {
panDownTime = e1.getEventTime();
scrolling = true;
component.getInstance().fireEvent(
component.getDomObject().getRef(), HighLevelGesture.PAN_START.toString(),
createFireEventParam(e1, CUR_EVENT));
} else {
component.getInstance().fireEvent(
component.getDomObject().getRef(), HighLevelGesture.PAN_MOVE.toString(),
createFireEventParam(e2, CUR_EVENT));
}
result = true;
}
if (component.containsGesture(HighLevelGesture.SWIPE)) {
if (swipeDownTime != e1.getEventTime()) {
swipeDownTime = e1.getEventTime();
List<Map<String, Object>> list = createFireEventParam(e2);
Map<String, Object> param = list.get(list.size() - 1);
if (Math.abs(distanceX) > Math.abs(distanceY)) {
param.put(GestureInfo.DIRECTION, distanceX > 0 ? "left" : "right");
} else {
param.put(GestureInfo.DIRECTION, distanceY > 0 ? "up" : "down");
}
component.getInstance().fireEvent( component.getDomObject().getRef(),
HighLevelGesture.SWIPE.toString(), param);
result = true;
}
}
return result;
}
示例13: getSwipeDistance
import android.view.MotionEvent; //导入方法依赖的package包/类
private float getSwipeDistance(MotionEvent event) {
for (int i = 0, l = event.getPointerCount(); i < l; ++i) {
if (event.getPointerId(i) == pointerId) {
return event.getX(i) - initialX;
}
}
return 0;
}
示例14: onSecondaryPointerUp
import android.view.MotionEvent; //导入方法依赖的package包/类
private void onSecondaryPointerUp(MotionEvent ev) {
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = ev.getPointerId(pointerIndex);
if (pointerId == mActivePointerId) {
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mActivePointerId = ev.getPointerId(newPointerIndex);
}
}
示例15: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent ev) {
final int action = ev.getActionMasked();
final int actionIndex = ev.getActionIndex();
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
}
mVelocityTracker.addMovement(ev);
switch (action){
case MotionEvent.ACTION_POINTER_DOWN:
mActivePointerId = ev.getPointerId(actionIndex);
mLastMotionX = ev.getX(actionIndex);
mLastMotionY = ev.getY(actionIndex);
break;
case MotionEvent.ACTION_POINTER_UP:
final int pointerId = ev.getPointerId(actionIndex);
if(pointerId==mActivePointerId){
final int newIndex = actionIndex == 0 ? 1 : 0;
mActivePointerId = ev.getPointerId(newIndex);
mLastMotionX = ev.getX(newIndex);
mLastMotionY = ev.getY(newIndex);
}
break;
//down时,已经将capture item定下来了。所以,后面可以安心考虑event处理
case MotionEvent.ACTION_MOVE: {
final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
if (activePointerIndex == -1)
break;
final float x = ev.getX(activePointerIndex);
final float y = (int) ev.getY(activePointerIndex);
int deltaX = (int) (x - mLastMotionX);
if(mCaptureItem!=null && mCaptureItem.getTouchMode()== Mode.DRAG){
mLastMotionX = x;
mLastMotionY = y;
//对capture item进行拖拽
mCaptureItem.trackMotionScroll(deltaX);
}
break;
}
case MotionEvent.ACTION_UP:
if(mCaptureItem!=null){
Mode touchMode = mCaptureItem.getTouchMode();
if(touchMode== Mode.DRAG){
final VelocityTracker velocityTracker = mVelocityTracker;
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
int xVel = (int) velocityTracker.getXVelocity(mActivePointerId);
mCaptureItem.fling(xVel);
}
}
cancel();
break;
case MotionEvent.ACTION_CANCEL:
if(mCaptureItem!=null)
mCaptureItem.revise();
cancel();
break;
}
}