Exemplo n.º 1
0
  @Override
  public boolean onTouchEvent(MotionEvent ev) {
    super.onTouchEvent(ev);

    if (velocityTracker == null) {
      velocityTracker = VelocityTracker.obtain();
    }
    velocityTracker.addMovement(ev);

    switch (ev.getAction()) {
      case MotionEvent.ACTION_DOWN:
        Log.d("ZoomRoll", "MotionEvent.ACTION_DOWN-----------1");
        if (!scroller.isFinished()) {
          scroller.abortAnimation();
          zoomModel.commit();
        }

        lastX = ev.getX();
        break;
      case MotionEvent.ACTION_MOVE:
        Log.d("ZoomRoll", "MotionEvent.ACTION_MOVE-----------2");
        setCurrentValue(getCurrentValue() - (ev.getX() - lastX));

        lastX = ev.getX();
        break;
      case MotionEvent.ACTION_UP:
        Log.d("ZoomRoll", "MotionEvent.ACTION_UP-----------3");
        velocityTracker.computeCurrentVelocity(1000);
        scroller.fling(
            (int) getCurrentValue(),
            0,
            (int) -velocityTracker.getXVelocity(),
            0,
            0,
            MAX_VALUE,
            0,
            0);
        velocityTracker.recycle();
        velocityTracker = null;

        if (!scroller.computeScrollOffset()) {
          zoomModel.commit();
        }
        break;
    }
    invalidate();
    return true;
  }
Exemplo n.º 2
0
 @Override
 public void computeScroll() {
   if (scroller.computeScrollOffset()) {
     setCurrentValue(scroller.getCurrX());
     invalidate();
   } else {
     zoomModel.commit();
   }
 }
Exemplo n.º 3
0
 public void setCurrentValue(float currentValue) {
   if (currentValue < 0.0) currentValue = 0.0f;
   if (currentValue > MAX_VALUE) currentValue = MAX_VALUE;
   final float zoom = 1.0f + currentValue / MULTIPLIER;
   zoomModel.setZoom(zoom);
 }
Exemplo n.º 4
0
 public float getCurrentValue() {
   return (zoomModel.getZoom() - 1.0f) * MULTIPLIER;
 }