當前位置: 首頁>>代碼示例>>Java>>正文


Java MotionEvent.getPointerCount方法代碼示例

本文整理匯總了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));
    }
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:21,代碼來源:MutitouchKeysContainer.java

示例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;
}
 
開發者ID:sdrausty,項目名稱:buildAPKsApps,代碼行數:21,代碼來源:Microscope.java

示例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;
}
 
開發者ID:weexext,項目名稱:ucar-weex-core,代碼行數:25,代碼來源:WXGesture.java

示例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());
}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:27,代碼來源:AndroidUtils.java

示例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;
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:20,代碼來源:MoveGestureDetector.java

示例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;
}
 
開發者ID:eventtus,項目名稱:photo-editor-android,代碼行數:15,代碼來源:ScaleGestureDetector.java

示例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;
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:37,代碼來源:OverlayPanelEventFilter.java

示例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;
}
 
開發者ID:mingdroid,項目名稱:tumbviewer,代碼行數:18,代碼來源:MultiPointerGestureDetector.java

示例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));
    }
}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:16,代碼來源:PTouchPad_.java

示例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;
}
 
開發者ID:ibosong,項目名稱:CommentGallery,代碼行數:13,代碼來源:MultiPointerGestureDetector.java

示例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;
}
 
開發者ID:gicheonkang,項目名稱:fast_face_android,代碼行數:38,代碼來源:FloatingCameraWindow.java

示例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);
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:41,代碼來源:BannerView.java

示例13: onInterceptTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    pointerCount = ev.getPointerCount();
    requestDisallowInterceptTouchEvent(pointerCount > 1);
    return super.onInterceptTouchEvent(ev);
}
 
開發者ID:martinwithaar,項目名稱:PinchToZoom,代碼行數:7,代碼來源:ImageViewPager.java

示例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;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:55,代碼來源:LetvPlayGestureLayout.java

示例15: onInterceptTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    return ev.getPointerCount() == 2 && delegate.shouldReceiveTouches();
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:5,代碼來源:EntitiesContainerView.java


注:本文中的android.view.MotionEvent.getPointerCount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。