- IBCScaleGestureDetector 多点触控手势接口
- DummyScaleGestureDetector 不支持多点触控
- ScaleGestureDetector 支持多点触控
- //触屏模式
- //先检测缩放模式,再检测滑动模式
- simulatedTouchpadInputHandler(AbstractGestureInputHandler).onScale(IBCScaleGestureDetector)
- line: 470 {
-
- boolean consumed = true;
-
- // Get the current focus.
- xCurrentFocus = detector.getFocusX();
- yCurrentFocus = detector.getFocusY();
-
- // If we haven't started scaling yet, we check whether a swipe is being performed.
- // The arbitrary fudge factor may not be the best way to set a tolerance...
- if (!inScaling) { //缩放模式
-
- // Start swiping mode only after we've moved away from the initial focal point some distance.
- if (!inSwiping) {//滑动模式,移动距离超过40个像素
- if ( (yCurrentFocus < (yInitialFocus - baseSwipeDist)) ||
- (yCurrentFocus > (yInitialFocus + baseSwipeDist)) ||
- (xCurrentFocus < (xInitialFocus - baseSwipeDist)) ||
- (xCurrentFocus > (xInitialFocus + baseSwipeDist)) ) {
- inSwiping = true;
- xPreviousFocus = xInitialFocus;
- yPreviousFocus = yInitialFocus;
- }
- }
-
- // If in swiping mode, indicate a swipe at regular intervals.
- if (inSwiping) {
- twoFingerSwipeUp = false;
- twoFingerSwipeDown = false;
- twoFingerSwipeLeft = false;
- twoFingerSwipeRight = false;
- if (yCurrentFocus < (yPreviousFocus - baseSwipeDist)) {
- twoFingerSwipeDown = true;//向下滑动
- xPreviousFocus = xCurrentFocus;
- yPreviousFocus = yCurrentFocus;
- } else if (yCurrentFocus > (yPreviousFocus + baseSwipeDist)) {
- twoFingerSwipeUp = true;//向上滑动
- xPreviousFocus = xCurrentFocus;
- yPreviousFocus = yCurrentFocus;
- } else if (xCurrentFocus < (xPreviousFocus - baseSwipeDist)) {
- twoFingerSwipeRight = true;//向右滑动
- xPreviousFocus = xCurrentFocus;
- yPreviousFocus = yCurrentFocus;
- } else if (xCurrentFocus > (xPreviousFocus + baseSwipeDist)) {
- twoFingerSwipeLeft = true;//向左滑动
- xPreviousFocus = xCurrentFocus;
- yPreviousFocus = yCurrentFocus;
- } else {
- consumed = false;
- }
- // The faster we swipe, the faster we traverse the screen, and hence, the
- // smaller the time-delta between consumed events. We take the reciprocal
- // obtain swipeSpeed. If it goes to zero, we set it to at least one.
- long elapsedTime = detector.getTimeDelta();
- if (elapsedTime < 10) elapsedTime = 10;
-
- swipeSpeed = baseSwipeTime/elapsedTime;
- if (swipeSpeed == 0) swipeSpeed = 1;
- if (consumed) Log.d(TAG,"Current swipe speed: " + swipeSpeed);
- }
- }
-
- if (!inSwiping) {
-
- if ( !inScaling && Math.abs(1.0 - detector.getScaleFactor()) < minScaleFactor ) {
- Log.i(TAG,"Not scaling due to small scale factor.");
- consumed = false;
- }
-
- if (consumed) {
- inScaling = true;
- Log.i(TAG,"Adjust scaling " + detector.getScaleFactor());
- if (canvas != null && canvas.scaling != null)
- canvas.scaling.adjust(activity, detector.getScaleFactor(), xCurrentFocus, yCurrentFocus);
- }
- }
- return consumed;
- }
- //SimulatedTouchpadInputHandler.onScale(IBCScaleGestureDetector) line: 1
- //ScaleGestureDetector.onTouchEvent(MotionEvent) line: 258
- SimulatedTouchpadInputHandler(AbstractGestureInputHandler).onTouchEvent(MotionEvent)
- line: 460 {
- //多点触控手势
- scaleGestures.onTouchEvent(e);
-
- }
- //SimulatedTouchpadInputHandler.onTouchEvent(MotionEvent) line: 1
- RemoteCanvasActivity.onTouchEvent(MotionEvent) line: 1217 {
- try {
- //activity检测到TouchEvent
- return inputHandler.onTouchEvent(event);
- } catch (NullPointerException e) { }
- return false;
- }
-
-
相关热门文章
给主人留下些什么吧!~~
评论热议