本文整理汇总了Java中android.view.MotionEvent.getPointerCount方法的典型用法代码示例。如果您正苦于以下问题:Java MotionEvent.getPointerCount方法的具体用法?Java MotionEvent.getPointerCount怎么用?Java MotionEvent.getPointerCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.getPointerCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: move
import android.view.MotionEvent; //导入方法依赖的package包/类
private synchronized void move(MotionEvent event) {
for (PinData item : pressedRects) {
boolean pressed = false;
for (int i = 0; i < (event.getPointerCount() > maxPointers ? maxPointers
: event.getPointerCount()); i++) {
if (item.rect
.contains((int) event.getX(i), (int) event.getY(i)))
pressed = true;
}
if (!pressed) {
if (item.key != null && item.key.eventListener != null)
item.key.eventListener.onReleased(item.key);
pressedRects.remove(item);
}
}
for (int i = 0; i < (event.getPointerCount() > maxPointers ? maxPointers
: event.getPointerCount()); i++) {
down((int) event.getX(i), (int) event.getY(i));
}
}
示例2: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getPointerCount() > 1) {
// Multi touch - resize the prism
event.getPointerCoords(0, p1);
event.getPointerCoords(1, p2);
int a = (int) Math.abs(p1.x - p2.x);
physics.rF = a;
physics.rC = 2 * a;
} else {
// Single touch
mouse.x = (int) event.getX();
mouse.y = (int) event.getY();
}
invalidate();
return true;
}
示例3: createFireEventParam
import android.view.MotionEvent; //导入方法依赖的package包/类
/**
* Create a map represented touch event at a certain moment.
* @param motionEvent motionEvent, which contains all pointers event in a period of time
* @param pos index used to retrieve a certain moment in a period of time.
* @return touchEvent
* @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent">touchEvent</a>
*/
private Map<String, Object> createFireEventParam(MotionEvent motionEvent, int pos, String state) {
JSONArray jsonArray = new JSONArray(motionEvent.getPointerCount());
if (motionEvent.getActionMasked() == MotionEvent.ACTION_MOVE) {
for (int i = 0; i < motionEvent.getPointerCount(); i++) {
jsonArray.add(createJSONObject(motionEvent, pos, i));
}
} else if (isPointerNumChanged(motionEvent)) {
int pointerIndex = motionEvent.getActionIndex();
jsonArray.add(createJSONObject(motionEvent, CUR_EVENT, pointerIndex));
}
Map<String, Object> map = new HashMap<>();
map.put(GestureInfo.HISTORICAL_XY, jsonArray);
if (state != null) {
map.put(GestureInfo.STATE, state);
}
return map;
}
示例4: dumpMotionEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
/**
* Show an event in the LogCat view, for debugging
*/
public static void dumpMotionEvent(MotionEvent event) {
String names[] = {"DOWN", "UP", "MOVE", "CANCEL", "OUTSIDE", "POINTER_DOWN", "POINTER_UP", "7?", "8?", "9?"};
StringBuilder sb = new StringBuilder();
int action = event.getAction();
int actionCode = action & MotionEvent.ACTION_MASK;
sb.append("event ACTION_").append(names[actionCode]);
if (actionCode == MotionEvent.ACTION_POINTER_DOWN || actionCode == MotionEvent.ACTION_POINTER_UP) {
sb.append("(pid ").append(action >> MotionEvent.ACTION_POINTER_INDEX_SHIFT);
sb.append(")");
}
sb.append("[");
for (int i = 0; i < event.getPointerCount(); i++) {
sb.append("#").append(i);
sb.append("(pid ").append(event.getPointerId(i));
sb.append(")=").append((int) event.getX(i));
sb.append(",").append((int) event.getY(i));
if (i + 1 < event.getPointerCount()) {
sb.append(";");
}
}
sb.append("]");
MLog.d(TAG, sb.toString());
}
示例5: updateStateByEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
protected void updateStateByEvent(MotionEvent curr) {
super.updateStateByEvent(curr);
final MotionEvent prev = mPrevEvent;
// Focus intenal
mCurrFocusInternal = determineFocalPoint(curr);
mPrevFocusInternal = determineFocalPoint(prev);
// Focus external
// - Prevent skipping of focus delta when a finger is added or removed
boolean mSkipNextMoveEvent = prev.getPointerCount() != curr.getPointerCount();
mFocusDeltaExternal = mSkipNextMoveEvent ? FOCUS_DELTA_ZERO : new PointF(mCurrFocusInternal.x - mPrevFocusInternal.x, mCurrFocusInternal.y - mPrevFocusInternal.y);
// - Don't directly use mFocusInternal (or skipping will occur). Add
// unskipped delta values to mFocusExternal instead.
mFocusExternal.x += mFocusDeltaExternal.x;
mFocusExternal.y += mFocusDeltaExternal.y;
}
示例6: findNewActiveIndex
import android.view.MotionEvent; //导入方法依赖的package包/类
private int findNewActiveIndex(MotionEvent ev, int otherActiveId, int removedPointerIndex) {
final int pointerCount = ev.getPointerCount();
// It's ok if this isn't found and returns -1, it simply won't match.
final int otherActiveIndex = ev.findPointerIndex(otherActiveId);
// Pick a new id and update tracking state.
for (int i = 0; i < pointerCount; i++) {
if (i != removedPointerIndex && i != otherActiveIndex) {
return i;
}
}
return -1;
}
示例7: handleScroll
import android.view.MotionEvent; //导入方法依赖的package包/类
/**
* Handles the scroll event, determining the gesture orientation and event target,
* when appropriate.
* @param e1 The first down {@link MotionEvent} that started the scrolling.
* @param e2 The move {@link MotionEvent} that triggered the current scroll.
* @param distanceY The distance along the Y axis that has been scrolled since the last call
* to handleScroll.
* @return Whether the event has been consumed.
*/
protected boolean handleScroll(MotionEvent e1, MotionEvent e2, float distanceY) {
// TODO(mdjones): It seems impossible that either of the two MotionEvents passed into this
// function would be null provided the InternalGestureDetector checks them. However, it
// still seems to be possible...
if (e1 == null || e2 == null) return false;
// If the panel is peeking then the swipe recognizer will handle the scroll event.
if (mPanel.getPanelState() == PanelState.PEEKED) return false;
// Only determines the gesture orientation if it hasn't been determined yet,
// affectively "locking" the orientation once the gesture has started.
if (!mHasDeterminedGestureOrientation && isDistanceGreaterThanTouchSlop(e1, e2)) {
determineGestureOrientation(e1, e2);
}
// Only determines the event target after determining the gesture orientation and
// if it hasn't been determined yet or if changing the event target during the
// middle of the gesture is supported. This will allow a smooth transition from
// swiping the Panel and scrolling the Content View.
final boolean mayChangeEventTarget = mMayChangeEventTarget && e2.getPointerCount() == 1;
if (mHasDeterminedGestureOrientation
&& (!mHasDeterminedEventTarget || mayChangeEventTarget)) {
determineEventTarget(distanceY);
}
return false;
}
示例8: getPressedPointerIndex
import android.view.MotionEvent; //导入方法依赖的package包/类
/**
* Gets the index of the i-th pressed pointer.
* Normally, the index will be equal to i, except in the case when the pointer is released.
* @return index of the specified pointer or -1 if not found (i.e. not enough pointers are down)
*/
private int getPressedPointerIndex(MotionEvent event, int i) {
final int count = event.getPointerCount();
final int action = event.getActionMasked();
final int index = event.getActionIndex();
if (action == MotionEvent.ACTION_UP ||
action == MotionEvent.ACTION_POINTER_UP) {
if (i >= index) {
i++;
}
}
return (i < count) ? i : -1;
}
示例9: printSamples
import android.view.MotionEvent; //导入方法依赖的package包/类
void printSamples(MotionEvent ev) {
final int historySize = ev.getHistorySize();
final int pointerCount = ev.getPointerCount();
for (int h = 0; h < historySize; h++) {
System.out.printf("At time %d:", ev.getHistoricalEventTime(h));
for (int p = 0; p < pointerCount; p++) {
System.out.printf(" pointer %d: (%f,%f)", ev.getPointerId(p), ev.getHistoricalX(p, h),
ev.getHistoricalY(p, h));
}
}
System.out.printf("At time %d:", ev.getEventTime());
for (int p = 0; p < pointerCount; p++) {
System.out.printf(" pointer %d: (%f,%f)", ev.getPointerId(p), ev.getX(p), ev.getY(p));
}
}
示例10: getPressedPointerCount
import android.view.MotionEvent; //导入方法依赖的package包/类
/**
* Gets the number of pressed pointers (fingers down).
*/
private static int getPressedPointerCount(MotionEvent event) {
int count = event.getPointerCount();
int action = event.getActionMasked();
if (action == MotionEvent.ACTION_UP ||
action == MotionEvent.ACTION_POINTER_UP) {
count--;
}
return count;
}
示例11: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mLastX = (int) event.getRawX();
mLastY = (int) event.getRawY();
mFirstX = mLastX;
mFirstY = mLastY;
break;
case MotionEvent.ACTION_MOVE:
int deltaX = (int) event.getRawX() - mLastX;
int deltaY = (int) event.getRawY() - mLastY;
mLastX = (int) event.getRawX();
mLastY = (int) event.getRawY();
int totalDeltaX = mLastX - mFirstX;
int totalDeltaY = mLastY - mFirstY;
if (mIsMoving
|| Math.abs(totalDeltaX) >= MOVE_THRESHOLD
|| Math.abs(totalDeltaY) >= MOVE_THRESHOLD) {
mIsMoving = true;
WindowManager windowMgr = mWeakRef.get().mWindowManager;
WindowManager.LayoutParams parm = mWeakRef.get().mWindowParam;
if (event.getPointerCount() == 1 && windowMgr != null) {
parm.x -= deltaX;
parm.y -= deltaY;
windowMgr.updateViewLayout(this, parm);
}
}
break;
case MotionEvent.ACTION_UP:
mIsMoving = false;
break;
}
return true;
}
示例12: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
isTouch = true;
if (event.getPointerCount() >= 2) return false;
if (mAdapter == null) return super.onTouchEvent(event);
int count = mAdapter.getCount();
if (count <= 1) return super.onTouchEvent(event);
float x = event.getRawX();
mVelocityTracker.addMovement(event);
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
if (!mScroller.isFinished()) { // 如果上次的调用没有执行完就取消。
return false;
}
mLastX = x;
return true;
case MotionEvent.ACTION_MOVE:
requestDisallowInterceptTouchEvent(true);
int dxMove = (int) (mLastX - x);
mTotalDx += dxMove;
onScrollBy(dxMove);
mLastX = x;
return true;
case MotionEvent.ACTION_UP:
isTouch = false;
if (Math.abs(mTotalDx) <= 10)
performClick();
case MotionEvent.ACTION_CANCEL: {
final VelocityTracker velocityTracker = mVelocityTracker;
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
mXVelocity = velocityTracker.getXVelocity();
isTouch = false;
scrollToItem();
scrollFinish(count);
break;
}
}
return super.onTouchEvent(event);
}
示例13: onInterceptTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
pointerCount = ev.getPointerCount();
requestDisallowInterceptTouchEvent(pointerCount > 1);
return super.onInterceptTouchEvent(ev);
}
示例14: onScroll
import android.view.MotionEvent; //导入方法依赖的package包/类
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if (!this.mIsPanorama && (this.mModel == null || this.mModel.isFullScreen())) {
int s = e2.getPointerCount();
if (s == 2) {
this.offsetY += distanceY;
if (this.offsetY > 0.0f) {
if (this.offsetY > this.doubleFingersUpCuttingValue * ((float) getHeight())) {
this.event = 17;
} else {
this.event = 0;
}
} else if (this.offsetY < (-this.doubleFingersDownCuttingValue) * ((float) getHeight())) {
this.event = 16;
} else {
this.event = 0;
}
} else if (s == 1) {
if (Math.abs(distanceY) > this.portraitLimitSlope * Math.abs(distanceX) && this.directionalLock != 2) {
this.directionalLock = 1;
if (e2.getX() > (1.0f - this.bothSidesCuttingValue) * ((float) getWidth())) {
this.rightProgerss += distanceY / ((float) getHeight());
setVolume(this.rightProgerss);
if (this.mCallbacks != null) {
this.mCallbacks.onRightScroll(this.rightProgerss);
}
} else if (e2.getX() < this.bothSidesCuttingValue * ((float) getWidth())) {
this.leftProgress += distanceY / ((float) getHeight());
setBrightness(this.leftProgress);
if (this.mCallbacks != null) {
this.mCallbacks.onLeftScroll(this.leftProgress);
}
} else if (e1.getX() > (this.middleCuttingValue - this.bothSidesCuttingValue) * ((float) getWidth()) && e1.getX() < (this.middleCuttingValue + this.bothSidesCuttingValue) * ((float) getWidth())) {
this.offsetY += distanceY;
if (!(this.mCallbacks == null && this.mModel == null)) {
if (this.offsetY > this.bothSidesCuttingValue * ((float) getHeight())) {
this.event = 20;
} else if (this.offsetY < (-this.bothSidesCuttingValue) * ((float) getHeight())) {
this.event = 19;
}
}
}
} else if (Math.abs(distanceY) < this.landscapeLimitSlope * Math.abs(distanceX) && this.directionalLock != 1) {
this.directionalLock = 2;
this.offsetX -= distanceX;
this.landscapeProgress = this.offsetX / ((float) getWidth());
if (!(this.mCallbacks == null || isInterceptByNavigationBar(e1))) {
this.mCallbacks.onLandscapeScroll(this.landscapeProgress);
}
this.event = 18;
}
}
}
return false;
}
示例15: onInterceptTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return ev.getPointerCount() == 2 && delegate.shouldReceiveTouches();
}