public WebViewInputDispatcher(UiCallbacks uiCallbacks, WebKitCallbacks webKitCallbacks) {
    this.mUiCallbacks = uiCallbacks;
    mUiHandler = new UiHandler(uiCallbacks.getUiLooper());

    this.mWebKitCallbacks = webKitCallbacks;
    mWebKitHandler = new WebKitHandler(webKitCallbacks.getWebKitLooper());

    ViewConfiguration config = ViewConfiguration.get(mUiCallbacks.getContext());
    mDoubleTapSlopSquared = config.getScaledDoubleTapSlop();
    mDoubleTapSlopSquared = (mDoubleTapSlopSquared * mDoubleTapSlopSquared);
    mTouchSlopSquared = config.getScaledTouchSlop();
    mTouchSlopSquared = (mTouchSlopSquared * mTouchSlopSquared);
  }
  @Test
  public void methodsShouldReturnScaledAndroidConstantsDependingOnPixelDensity() {
    Activity context = new Activity();
    shadowOf(context.getResources()).setDensity(1.5f);
    ViewConfiguration viewConfiguration = ViewConfiguration.get(context);

    assertEquals(15, viewConfiguration.getScaledScrollBarSize());
    assertEquals(18, viewConfiguration.getScaledFadingEdgeLength());
    assertEquals(18, viewConfiguration.getScaledEdgeSlop());
    assertEquals(24, viewConfiguration.getScaledTouchSlop());
    assertEquals(48, viewConfiguration.getScaledPagingTouchSlop());
    assertEquals(150, viewConfiguration.getScaledDoubleTapSlop());
    assertEquals(24, viewConfiguration.getScaledWindowTouchSlop());
    assertEquals(75, viewConfiguration.getScaledMinimumFlingVelocity());
    assertEquals(6000, viewConfiguration.getScaledMaximumFlingVelocity());
  }
    private void init(Context context) {
      if (context == null) {
        throw new IllegalArgumentException("Context must not be null");
      }
      if (mListener == null) {
        throw new IllegalArgumentException("OnGestureListener must not be null");
      }
      mIsLongpressEnabled = true;

      final ViewConfiguration configuration = ViewConfiguration.get(context);
      final int touchSlop = configuration.getScaledTouchSlop();
      final int doubleTapSlop = configuration.getScaledDoubleTapSlop();
      mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
      mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity();

      mTouchSlopSquare = touchSlop * touchSlop;
      mDoubleTapSlopSquare = doubleTapSlop * doubleTapSlop;
    }
Beispiel #4
0
  public TouchImageView(Context context, AttributeSet attrs) {
    super(context, attrs);

    if (getDrawable() != null) {
      bitmap = ((BitmapDrawable) getDrawable()).getBitmap();
    }
    setScaleType(ScaleType.MATRIX);

    setOnTouchListener(this); // 设置触屏监听
    dm = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm); // 获取分辨率

    if (bitmap != null) {
      Log.d("test", "TouchImageView(), call center()");
      minZoom();
      center();
    }
    setImageMatrix(matrix);

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    touchSlop = configuration.getScaledTouchSlop();
    doubleTapSlop = configuration.getScaledDoubleTapSlop();
    mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity();

    Log.d(
        "test",
        "touchSlop: "
            + touchSlop
            + ", doubleTapSlop: "
            + doubleTapSlop
            + ", mMinimumFlingVelocity: "
            + mMinimumFlingVelocity
            + ", mMaximumFlingVelocity: "
            + mMaximumFlingVelocity);
  }
  @Test
  public void methodsShouldReturnAndroidConstants() {
    Activity context = new Activity();
    ViewConfiguration viewConfiguration = ViewConfiguration.get(context);

    assertEquals(10, ViewConfiguration.getScrollBarSize());
    assertEquals(250, ViewConfiguration.getScrollBarFadeDuration());
    assertEquals(300, ViewConfiguration.getScrollDefaultDelay());
    assertEquals(12, ViewConfiguration.getFadingEdgeLength());
    assertEquals(125, ViewConfiguration.getPressedStateDuration());
    assertEquals(500, ViewConfiguration.getLongPressTimeout());
    assertEquals(115, ViewConfiguration.getTapTimeout());
    assertEquals(500, ViewConfiguration.getJumpTapTimeout());
    assertEquals(300, ViewConfiguration.getDoubleTapTimeout());
    assertEquals(12, ViewConfiguration.getEdgeSlop());
    assertEquals(16, ViewConfiguration.getTouchSlop());
    assertEquals(16, ViewConfiguration.getWindowTouchSlop());
    assertEquals(50, ViewConfiguration.getMinimumFlingVelocity());
    assertEquals(4000, ViewConfiguration.getMaximumFlingVelocity());
    assertEquals(320 * 480 * 4, ViewConfiguration.getMaximumDrawingCacheSize());
    assertEquals(3000, ViewConfiguration.getZoomControlsTimeout());
    assertEquals(500, ViewConfiguration.getGlobalActionKeyTimeout());
    assertEquals(0.015f, ViewConfiguration.getScrollFriction());

    assertEquals(1f, context.getResources().getDisplayMetrics().density);

    assertEquals(10, viewConfiguration.getScaledScrollBarSize());
    assertEquals(12, viewConfiguration.getScaledFadingEdgeLength());
    assertEquals(12, viewConfiguration.getScaledEdgeSlop());
    assertEquals(16, viewConfiguration.getScaledTouchSlop());
    assertEquals(32, viewConfiguration.getScaledPagingTouchSlop());
    assertEquals(100, viewConfiguration.getScaledDoubleTapSlop());
    assertEquals(16, viewConfiguration.getScaledWindowTouchSlop());
    assertEquals(50, viewConfiguration.getScaledMinimumFlingVelocity());
    assertEquals(4000, viewConfiguration.getScaledMaximumFlingVelocity());
  }