Java Code Examples for android.support.v4.view.ViewCompat#postOnAnimationDelayed()

The following examples show how to use android.support.v4.view.ViewCompat#postOnAnimationDelayed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutoScrollHelper.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
/**
 * Starts the scroll animation.
 */
private void startAnimating() {
    if (mRunnable == null) {
        mRunnable = new ScrollAnimationRunnable();
    }

    mAnimating = true;
    mNeedsReset = true;

    if (!mAlreadyDelayed && mActivationDelay > 0) {
        ViewCompat.postOnAnimationDelayed(mTarget, mRunnable, mActivationDelay);
    } else {
        mRunnable.run();
    }

    // If we start animating again before the user lifts their finger, we
    // already know it's not a tap and don't need an activation delay.
    mAlreadyDelayed = true;
}
 
Example 2
Source File: AutoScrollHelper.java    From android-recipes-app with Apache License 2.0 6 votes vote down vote up
/**
 * Starts the scroll animation.
 */
private void startAnimating() {
    if (mRunnable == null) {
        mRunnable = new ScrollAnimationRunnable();
    }

    mAnimating = true;
    mNeedsReset = true;

    if (!mAlreadyDelayed && mActivationDelay > 0) {
        ViewCompat.postOnAnimationDelayed(mTarget, mRunnable, mActivationDelay);
    } else {
        mRunnable.run();
    }

    // If we start animating again before the user lifts their finger, we
    // already know it's not a tap and don't need an activation delay.
    mAlreadyDelayed = true;
}
 
Example 3
Source File: AutoScrollHelper.java    From V.FlyoutTest with MIT License 6 votes vote down vote up
/**
 * Starts the scroll animation.
 */
private void startAnimating() {
    if (mRunnable == null) {
        mRunnable = new ScrollAnimationRunnable();
    }

    mAnimating = true;
    mNeedsReset = true;

    if (!mAlreadyDelayed && mActivationDelay > 0) {
        ViewCompat.postOnAnimationDelayed(mTarget, mRunnable, mActivationDelay);
    } else {
        mRunnable.run();
    }

    // If we start animating again before the user lifts their finger, we
    // already know it's not a tap and don't need an activation delay.
    mAlreadyDelayed = true;
}
 
Example 4
Source File: AutoScrollHelper.java    From guideshow with MIT License 6 votes vote down vote up
/**
 * Starts the scroll animation.
 */
private void startAnimating() {
    if (mRunnable == null) {
        mRunnable = new ScrollAnimationRunnable();
    }

    mAnimating = true;
    mNeedsReset = true;

    if (!mAlreadyDelayed && mActivationDelay > 0) {
        ViewCompat.postOnAnimationDelayed(mTarget, mRunnable, mActivationDelay);
    } else {
        mRunnable.run();
    }

    // If we start animating again before the user lifts their finger, we
    // already know it's not a tap and don't need an activation delay.
    mAlreadyDelayed = true;
}
 
Example 5
Source File: AutoScrollHelper.java    From letv with Apache License 2.0 5 votes vote down vote up
private void startAnimating() {
    if (this.mRunnable == null) {
        this.mRunnable = new ScrollAnimationRunnable();
    }
    this.mAnimating = true;
    this.mNeedsReset = true;
    if (this.mAlreadyDelayed || this.mActivationDelay <= 0) {
        this.mRunnable.run();
    } else {
        ViewCompat.postOnAnimationDelayed(this.mTarget, this.mRunnable, (long) this.mActivationDelay);
    }
    this.mAlreadyDelayed = true;
}
 
Example 6
Source File: ReactScrollView.java    From react-native-GPay with MIT License 4 votes vote down vote up
/**
 * This handles any sort of scrolling that may occur after a touch is finished.  This may be
 * momentum scrolling (fling) or because you have pagingEnabled on the scroll view.  Because we
 * don't get any events from Android about this lifecycle, we do all our detection by creating a
 * runnable that checks if we scrolled in the last frame and if so assumes we are still scrolling.
 */
private void handlePostTouchScrolling(int velocityX, int velocityY) {
  // If we aren't going to do anything (send events or snap to page), we can early exit out.
  if (!mSendMomentumEvents && !mPagingEnabled && !isScrollPerfLoggingEnabled()) {
    return;
  }

  // Check if we are already handling this which may occur if this is called by both the touch up
  // and a fling call
  if (mPostTouchRunnable != null) {
    return;
  }

  if (mSendMomentumEvents) {
    enableFpsListener();
    ReactScrollViewHelper.emitScrollMomentumBeginEvent(this, velocityX, velocityY);
  }

  mActivelyScrolling = false;
  mPostTouchRunnable = new Runnable() {

    private boolean mSnappingToPage = false;

    @Override
    public void run() {
      if (mActivelyScrolling) {
        // We are still scrolling so we just post to check again a frame later
        mActivelyScrolling = false;
        ViewCompat.postOnAnimationDelayed(ReactScrollView.this,
          this,
          ReactScrollViewHelper.MOMENTUM_DELAY);
      } else {
        if (mPagingEnabled && !mSnappingToPage) {
          // Only if we have pagingEnabled and we have not snapped to the page do we
          // need to continue checking for the scroll.  And we cause that scroll by asking for it
          mSnappingToPage = true;
          flingAndSnap(0);
          ViewCompat.postOnAnimationDelayed(ReactScrollView.this,
            this,
            ReactScrollViewHelper.MOMENTUM_DELAY);
        } else {
          if (mSendMomentumEvents) {
            ReactScrollViewHelper.emitScrollMomentumEndEvent(ReactScrollView.this);
          }
          ReactScrollView.this.mPostTouchRunnable = null;
          disableFpsListener();
        }
      }
    }
  };
  ViewCompat.postOnAnimationDelayed(ReactScrollView.this,
    mPostTouchRunnable,
    ReactScrollViewHelper.MOMENTUM_DELAY);
}
 
Example 7
Source File: ReactHorizontalScrollView.java    From react-native-GPay with MIT License 4 votes vote down vote up
/**
 * This handles any sort of scrolling that may occur after a touch is finished.  This may be
 * momentum scrolling (fling) or because you have pagingEnabled on the scroll view.  Because we
 * don't get any events from Android about this lifecycle, we do all our detection by creating a
 * runnable that checks if we scrolled in the last frame and if so assumes we are still scrolling.
 */
private void handlePostTouchScrolling(int velocityX, int velocityY) {
  // If we aren't going to do anything (send events or snap to page), we can early exit out.
  if (!mSendMomentumEvents && !mPagingEnabled && !isScrollPerfLoggingEnabled()) {
    return;
  }

  // Check if we are already handling this which may occur if this is called by both the touch up
  // and a fling call
  if (mPostTouchRunnable != null) {
    return;
  }

  if (mSendMomentumEvents) {
    ReactScrollViewHelper.emitScrollMomentumBeginEvent(this, velocityX, velocityY);
  }

  mActivelyScrolling = false;
  mPostTouchRunnable = new Runnable() {

    private boolean mSnappingToPage = false;

    @Override
    public void run() {
      if (mActivelyScrolling) {
        // We are still scrolling so we just post to check again a frame later
        mActivelyScrolling = false;
        ViewCompat.postOnAnimationDelayed(ReactHorizontalScrollView.this,
          this,
          ReactScrollViewHelper.MOMENTUM_DELAY);
      } else {
        if (mPagingEnabled && !mSnappingToPage) {
          // Only if we have pagingEnabled and we have not snapped to the page do we
          // need to continue checking for the scroll.  And we cause that scroll by asking for it
          mSnappingToPage = true;
          flingAndSnap(0);
          ViewCompat.postOnAnimationDelayed(ReactHorizontalScrollView.this,
            this,
            ReactScrollViewHelper.MOMENTUM_DELAY);
        } else {
          if (mSendMomentumEvents) {
            ReactScrollViewHelper.emitScrollMomentumEndEvent(ReactHorizontalScrollView.this);
          }
          ReactHorizontalScrollView.this.mPostTouchRunnable = null;
          disableFpsListener();
        }
      }
    }
  };
  ViewCompat.postOnAnimationDelayed(ReactHorizontalScrollView.this,
    mPostTouchRunnable,
    ReactScrollViewHelper.MOMENTUM_DELAY);
}