Exemplo n.º 1
0
    @Override
    public void run() {
      if (mScroller.isFinished()) {
        return; // remaining post that should not be handled
      }

      ImageView imageView = getImageView();
      if (null != imageView && mScroller.computeScrollOffset()) {

        final int newX = mScroller.getCurrX();
        final int newY = mScroller.getCurrY();

        if (DEBUG) {
          LogManager.getLogger()
              .d(
                  LOG_TAG,
                  "fling run(). CurrentX:"
                      + mCurrentX
                      + " CurrentY:"
                      + mCurrentY
                      + " NewX:"
                      + newX
                      + " NewY:"
                      + newY);
        }

        mSuppMatrix.postTranslate(mCurrentX - newX, mCurrentY - newY);
        setImageViewMatrix(getDrawMatrix());

        mCurrentX = newX;
        mCurrentY = newY;

        // Post On animation
        Compat.postOnAnimation(imageView, this);
      }
    }
Exemplo n.º 2
0
    public void fling(int viewWidth, int viewHeight, int velocityX, int velocityY) {
      final RectF rect = getDisplayRect();
      if (null == rect) {
        return;
      }

      final int startX = Math.round(-rect.left);
      final int minX, maxX, minY, maxY;

      if (viewWidth < rect.width()) {
        minX = 0;
        maxX = Math.round(rect.width() - viewWidth);
      } else {
        minX = maxX = startX;
      }

      final int startY = Math.round(-rect.top);
      if (viewHeight < rect.height()) {
        minY = 0;
        maxY = Math.round(rect.height() - viewHeight);
      } else {
        minY = maxY = startY;
      }

      mCurrentX = startX;
      mCurrentY = startY;

      if (DEBUG) {
        LogManager.getLogger()
            .d(
                LOG_TAG,
                "fling. StartX:"
                    + startX
                    + " StartY:"
                    + startY
                    + " MaxX:"
                    + maxX
                    + " MaxY:"
                    + maxY);
      }

      // If we actually can move, fling the scroller
      if (startX != maxX || startY != maxY) {
        mScroller.fling(startX, startY, velocityX, velocityY, minX, maxX, minY, maxY, 0, 0);
      }
    }
Exemplo n.º 3
0
 public void cancelFling() {
   if (DEBUG) {
     LogManager.getLogger().d(LOG_TAG, "Cancel Fling");
   }
   mScroller.forceFinished(true);
 }
Exemplo n.º 4
0
 public FlingRunnable(Context context) {
   mScroller = ScrollerProxy.getScroller(context);
 }