Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1547171
  • 博文数量: 596
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 173
  • 用 户 组: 普通用户
  • 注册时间: 2016-07-06 15:50
个人简介

在线笔记

文章分类

全部博文(596)

文章存档

2016年(1)

2015年(104)

2014年(228)

2013年(226)

2012年(26)

2011年(11)

分类: Android平台

2015-05-15 11:44:01


  1. IBCScaleGestureDetector      多点触控手势接口
  2.     DummyScaleGestureDetector 不支持多点触控
  3.     ScaleGestureDetector      支持多点触控

  1. //触屏模式
  2. //先检测缩放模式,再检测滑动模式
  3. simulatedTouchpadInputHandler(AbstractGestureInputHandler).onScale(IBCScaleGestureDetector)
  4. line: 470 {

  5.         boolean consumed = true;

  6.         // Get the current focus.
  7.         xCurrentFocus = detector.getFocusX();
  8.         yCurrentFocus = detector.getFocusY();
  9.         
  10.         // If we haven't started scaling yet, we check whether a swipe is being performed.
  11.         // The arbitrary fudge factor may not be the best way to set a tolerance...
  12.         if (!inScaling) { //缩放模式
  13.             
  14.             // Start swiping mode only after we've moved away from the initial focal point some distance.
  15.             if (!inSwiping) {//滑动模式,移动距离超过40个像素
  16.                 if ( (yCurrentFocus < (yInitialFocus - baseSwipeDist)) ||
  17.                      (yCurrentFocus > (yInitialFocus + baseSwipeDist)) ||
  18.                      (xCurrentFocus < (xInitialFocus - baseSwipeDist)) ||
  19.                      (xCurrentFocus > (xInitialFocus + baseSwipeDist)) ) {
  20.                     inSwiping = true;
  21.                     xPreviousFocus = xInitialFocus;
  22.                     yPreviousFocus = yInitialFocus;
  23.                 }
  24.             }
  25.             
  26.             // If in swiping mode, indicate a swipe at regular intervals.
  27.             if (inSwiping) {
  28.                 twoFingerSwipeUp = false;
  29.                 twoFingerSwipeDown = false;
  30.                 twoFingerSwipeLeft = false;
  31.                 twoFingerSwipeRight = false;
  32.                 if (yCurrentFocus < (yPreviousFocus - baseSwipeDist)) {
  33.                     twoFingerSwipeDown = true;//向下滑动
  34.                     xPreviousFocus = xCurrentFocus;
  35.                     yPreviousFocus = yCurrentFocus;
  36.                 } else if (yCurrentFocus > (yPreviousFocus + baseSwipeDist)) {
  37.                     twoFingerSwipeUp = true;//向上滑动
  38.                     xPreviousFocus = xCurrentFocus;
  39.                     yPreviousFocus = yCurrentFocus;
  40.                 } else if (xCurrentFocus < (xPreviousFocus - baseSwipeDist)) {
  41.                     twoFingerSwipeRight = true;//向右滑动
  42.                     xPreviousFocus = xCurrentFocus;
  43.                     yPreviousFocus = yCurrentFocus;
  44.                 } else if (xCurrentFocus > (xPreviousFocus + baseSwipeDist)) {
  45.                     twoFingerSwipeLeft = true;//向左滑动
  46.                     xPreviousFocus = xCurrentFocus;
  47.                     yPreviousFocus = yCurrentFocus;
  48.                 } else {
  49.                     consumed = false;
  50.                 }
  51.                 // The faster we swipe, the faster we traverse the screen, and hence, the
  52.                 // smaller the time-delta between consumed events. We take the reciprocal
  53.                 // obtain swipeSpeed. If it goes to zero, we set it to at least one.
  54.                 long elapsedTime = detector.getTimeDelta();
  55.                 if (elapsedTime < 10) elapsedTime = 10;
  56.                 
  57.                 swipeSpeed = baseSwipeTime/elapsedTime;
  58.                 if (swipeSpeed == 0) swipeSpeed = 1;
  59.                 if (consumed) Log.d(TAG,"Current swipe speed: " + swipeSpeed);
  60.             }
  61.         }
  62.         
  63.         if (!inSwiping) {
  64.             
  65.             if ( !inScaling && Math.abs(1.0 - detector.getScaleFactor()) < minScaleFactor ) {
  66.                 Log.i(TAG,"Not scaling due to small scale factor.");
  67.                 consumed = false;
  68.             }

  69.             if (consumed) {
  70.                 inScaling = true;
  71.                 Log.i(TAG,"Adjust scaling " + detector.getScaleFactor());
  72.                 if (canvas != null && canvas.scaling != null)
  73.                     canvas.scaling.adjust(activity, detector.getScaleFactor(), xCurrentFocus, yCurrentFocus);
  74.             }
  75.         }
  76.         return consumed;
  77.     }
  78. //SimulatedTouchpadInputHandler.onScale(IBCScaleGestureDetector) line: 1
  79. //ScaleGestureDetector.onTouchEvent(MotionEvent) line: 258
  80. SimulatedTouchpadInputHandler(AbstractGestureInputHandler).onTouchEvent(MotionEvent)
  81. line: 460 {
  82.         //多点触控手势
  83.         scaleGestures.onTouchEvent(e);
  84.         
  85.     }
  86. //SimulatedTouchpadInputHandler.onTouchEvent(MotionEvent) line: 1
  87. RemoteCanvasActivity.onTouchEvent(MotionEvent) line: 1217 {
  88.     try {
  89.         //activity检测到TouchEvent
  90.      return inputHandler.onTouchEvent(event);
  91.     } catch (NullPointerException e) { }
  92.     return false;
  93.     }



阅读(1032) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~