本文整理了Java中android.view.MotionEvent.getPointerCount()
方法的一些代码示例,展示了MotionEvent.getPointerCount()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MotionEvent.getPointerCount()
方法的具体详情如下:
包路径:android.view.MotionEvent
类名称:MotionEvent
方法名:getPointerCount
暂无
代码示例来源:origin: TonicArtos/StickyGridHeaders
private static int[] getPointerIds(MotionEvent e) {
int n = e.getPointerCount();
int[] r = new int[n];
for (int i = 0; i < n; i++) {
r[i] = e.getPointerId(i);
}
return r;
}
代码示例来源:origin: stackoverflow.com
import android.view.MotionEvent;
public class EclairMotionEvent extends WrapMotionEvent {
protected EclairMotionEvent(MotionEvent event) {
super(event);
}
public float getX(int pointerIndex) {
return event.getX(pointerIndex);
}
public float getY(int pointerIndex) {
return event.getY(pointerIndex);
}
public int getPointerCount() {
return event.getPointerCount();
}
public int getPointerId(int pointerIndex) {
return event.getPointerId(pointerIndex);
}
}
代码示例来源:origin: robolectric/robolectric
public void set(MotionEvent event) {
pointerCount = event.getPointerCount();
pointerIds = new int[pointerCount];
x.clear();
y.clear();
for (int i = 0; i < pointerCount; i++) {
pointerIds[i] = event.getPointerId(i);
x.put(pointerIds[i], event.getX(i));
y.put(pointerIds[i], event.getY(i));
}
activePointerId = event.getPointerId(0);
eventTime = event.getEventTime();
}
代码示例来源:origin: chrisbanes/PhotoView
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX, float velocityY) {
if (mSingleFlingListener != null) {
if (getScale() > DEFAULT_MIN_SCALE) {
return false;
}
if (e1.getPointerCount() > SINGLE_TOUCH
|| e2.getPointerCount() > SINGLE_TOUCH) {
return false;
}
return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY);
}
return false;
}
});
代码示例来源:origin: novoda/android-demos
public void setMultitouchPoints(MotionEvent event) {
touchPoints.clear();
int pointerIndex = 0;
for (int index = 0; index < event.getPointerCount(); ++index) {
pointerIndex = event.getPointerId(index);
touchPoints.add(new PointF(event.getX(pointerIndex), event.getY(pointerIndex)));
}
}
代码示例来源:origin: novoda/android-demos
public void setInitalPositionMultiPoints(MotionEvent event) {
touchPoints.clear();
int pointerIndex = 0;
for (int index = 0; index < event.getPointerCount(); ++index) {
pointerIndex = event.getPointerId(index);
touchPoints.add(new PointF(event.getX(pointerIndex), event.getY(pointerIndex)));
}
double r = Math.atan2(touchPoints.get(1).x - touchPoints.get(1 - 1).x,
touchPoints.get(1).y - touchPoints.get(1 - 1).y);
old_degrees = -(int) Math.toDegrees(r);
}
代码示例来源:origin: TeamNewPipe/NewPipe
private boolean handleMultiDrag(final MotionEvent event) {
if (event.getPointerCount() != 2) return false;
final float firstPointerX = event.getX(0);
final float secondPointerX = event.getX(1);
final float diff = Math.abs(firstPointerX - secondPointerX);
if (firstPointerX > secondPointerX) {
// second pointer is the anchor (the leftmost pointer)
popupLayoutParams.x = (int) (event.getRawX() - diff);
} else {
// first pointer is the anchor
popupLayoutParams.x = (int) event.getRawX();
}
checkPopupPositionBounds();
updateScreenSize();
final int width = (int) Math.min(screenWidth, diff);
updatePopupSize(width, -1);
return true;
}
代码示例来源:origin: alexvasilkov/GestureViews
private void handleTouch(MotionEvent event) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_POINTER_DOWN:
if (event.getPointerCount() == 2) { // on first non-primary pointer
// Skipping ViewPager fake dragging if we're not started dragging yet
// to allow scale/rotation gestures
isSkipViewPager = !hasViewPagerX();
}
break;
default:
}
}
代码示例来源:origin: sephiroth74/ImageViewZoom
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if (!mScrollEnabled) {
return false;
}
if (e1 == null || e2 == null) {
return false;
}
if (e1.getPointerCount() > 1 || e2.getPointerCount() > 1) {
return false;
}
if (mScaleDetector.isInProgress()) {
return false;
}
return ImageViewTouch.this.onScroll(e1, e2, distanceX, distanceY);
}
代码示例来源:origin: steelkiwi/cropiwa
private void onPointerUp(MotionEvent e) {
//If user lifted finger that we used to calculate translation, we need to find a new one
if (e.getPointerId(e.getActionIndex()) == id) {
int index = 0;
while (index < e.getPointerCount() && index == e.getActionIndex()) {
index++;
}
onDown(e.getX(index), e.getY(index), e.getPointerId(index));
}
}
代码示例来源:origin: TonicArtos/StickyGridHeaders
private static MotionEvent.PointerCoords[] getPointerCoords(MotionEvent e) {
int n = e.getPointerCount();
MotionEvent.PointerCoords[] r = new MotionEvent.PointerCoords[n];
for (int i = 0; i < n; i++) {
r[i] = new MotionEvent.PointerCoords();
e.getPointerCoords(i, r[i]);
}
return r;
}
代码示例来源:origin: lyft/scissors
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if (e2.getPointerCount() != 1) {
return true;
}
TouchPoint delta = new TouchPoint(-distanceX, -distanceY);
position.add(delta);
ensureInsideViewport();
return true;
}
代码示例来源:origin: Yalantis/uCrop
/**
* If it's ACTION_DOWN event - user touches the screen and all current animation must be canceled.
* If it's ACTION_UP event - user removed all fingers from the screen and current image position must be corrected.
* If there are more than 2 fingers - update focal point coordinates.
* Pass the event to the gesture detectors if those are enabled.
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
cancelAllAnimations();
}
if (event.getPointerCount() > 1) {
mMidPntX = (event.getX(0) + event.getX(1)) / 2;
mMidPntY = (event.getY(0) + event.getY(1)) / 2;
}
mGestureDetector.onTouchEvent(event);
if (mIsScaleEnabled) {
mScaleDetector.onTouchEvent(event);
}
if (mIsRotateEnabled) {
mRotateDetector.onTouchEvent(event);
}
if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
setImageToWrapCropBounds();
}
return true;
}
代码示例来源:origin: PhilJay/MPAndroidChart
public static void velocityTrackerPointerUpCleanUpIfNecessary(MotionEvent ev,
VelocityTracker tracker) {
// Check the dot product of current velocities.
// If the pointer that left was opposing another velocity vector, clear.
tracker.computeCurrentVelocity(1000, mMaximumFlingVelocity);
final int upIndex = ev.getActionIndex();
final int id1 = ev.getPointerId(upIndex);
final float x1 = tracker.getXVelocity(id1);
final float y1 = tracker.getYVelocity(id1);
for (int i = 0, count = ev.getPointerCount(); i < count; i++) {
if (i == upIndex)
continue;
final int id2 = ev.getPointerId(i);
final float x = x1 * tracker.getXVelocity(id2);
final float y = y1 * tracker.getYVelocity(id2);
final float dot = x + y;
if (dot < 0) {
tracker.clear();
break;
}
}
}
代码示例来源:origin: vondear/RxTool
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getPointerCount() == 1) {
if (camera != null) {
/*camera.startPreview();
handleFocusMetering(event, camera);*/
}
} else {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_POINTER_DOWN:
oldDist = getFingerSpacing(event);
break;
case MotionEvent.ACTION_MOVE:
float newDist = getFingerSpacing(event);
if (newDist > oldDist) {
Log.e("Camera", "进入放大手势");
handleZoom(true, camera);
} else if (newDist < oldDist) {
Log.e("Camera", "进入缩小手势");
handleZoom(false, camera);
}
oldDist = newDist;
break;
default:
break;
}
}
return true;
}
代码示例来源:origin: Hitomis/transferee
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
if (isEnable) {
final int Action = event.getActionMasked();
if (event.getPointerCount() >= 2) hasMultiTouch = true;
mDetector.onTouchEvent(event);
mRotateDetector.onTouchEvent(event);
mScaleDetector.onTouchEvent(event);
if (Action == MotionEvent.ACTION_UP || Action == MotionEvent.ACTION_CANCEL) onUp();
return true;
} else {
return super.dispatchTouchEvent(event);
}
}
代码示例来源:origin: ankidroid/Anki-Android
private boolean handleMultiTouchEvent(MotionEvent event) {
if (event.getPointerCount() == 2) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_POINTER_DOWN:
reinitializeSecondFinger(event);
return true;
case MotionEvent.ACTION_MOVE:
return trySecondFingerScroll(event);
case MotionEvent.ACTION_POINTER_UP:
return trySecondFingerClick(event);
default:
return false;
}
}
return false;
}
代码示例来源:origin: bm-x/PhotoView
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
if (isEnable) {
final int Action = event.getActionMasked();
if (event.getPointerCount() >= 2) hasMultiTouch = true;
mDetector.onTouchEvent(event);
if (isRotateEnable) {
mRotateDetector.onTouchEvent(event);
}
mScaleDetector.onTouchEvent(event);
if (Action == MotionEvent.ACTION_UP || Action == MotionEvent.ACTION_CANCEL) onUp();
return true;
} else {
return super.dispatchTouchEvent(event);
}
}
代码示例来源:origin: lyft/scissors
@OnTouch(R.id.crop_view)
public boolean onTouchCropView(MotionEvent event) { // GitHub issue #4
if (event.getPointerCount() > 1 || cropView.getImageBitmap() == null) {
return true;
}
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
ButterKnife.apply(buttons, VISIBILITY, View.INVISIBLE);
break;
default:
ButterKnife.apply(buttons, VISIBILITY, View.VISIBLE);
break;
}
return true;
}
代码示例来源:origin: robolectric/robolectric
@Test
public void addingSecondPointerSetsCount() {
assertThat(event.getX(0)).isEqualTo(5.0f);
assertThat(event.getY(0)).isEqualTo(10.0f);
assertThat(event.getPointerCount()).isEqualTo(1);
shadowMotionEvent.setPointer2(20.0f, 30.0f);
assertThat(event.getX(1)).isEqualTo(20.0f);
assertThat(event.getY(1)).isEqualTo(30.0f);
assertThat(event.getPointerCount()).isEqualTo(2);
}
内容来源于网络,如有侵权,请联系作者删除!