final void setBroadcastTimeoutLocked(long timeoutTime) {
   if (!mPendingBroadcastTimeoutMessage) {
     Message msg = mHandler.obtainMessage(BROADCAST_TIMEOUT_MSG, this);
     mHandler.sendMessageAtTime(msg, timeoutTime);
     mPendingBroadcastTimeoutMessage = true;
   }
 }
 public void postOnNewPicture(Callable<Picture> pictureProvider) {
   if (mHasPendingOnNewPicture) return;
   mHasPendingOnNewPicture = true;
   long pictureTime =
       java.lang.Math.max(
           mLastPictureTime + ON_NEW_PICTURE_MIN_PERIOD_MILLIS, SystemClock.uptimeMillis());
   mHandler.sendMessageAtTime(
       mHandler.obtainMessage(MSG_ON_NEW_PICTURE, pictureProvider), pictureTime);
 }
 @Test
 public void sendMessageAtTime_sendsMessageAtCorrectTime() {
   ShadowLooper.pauseMainLooper();
   Handler handler = new Handler();
   Message message = handler.obtainMessage(123);
   handler.sendMessageAtTime(message, 500);
   assertThat(handler.hasMessages(123)).isTrue();
   ShadowLooper.idleMainLooper(100);
   assertThat(handler.hasMessages(123)).isTrue();
   ShadowLooper.idleMainLooper(400);
   assertThat(handler.hasMessages(123)).isFalse();
 }
  private void performFling(int position, float velocity, boolean always) {
    mAnimationPosition = position;
    mAnimatedVelocity = velocity;

    if (mExpanded) {
      if (always
          || (velocity > mMaximumMajorVelocity
              || (position > mTopOffset + (mVertical ? mHandleHeight : mHandleWidth)
                  && velocity > -mMaximumMajorVelocity))) {
        // We are expanded, but they didn't move sufficiently to cause
        // us to retract.  Animate back to the expanded position.
        mAnimatedAcceleration = mMaximumAcceleration;
        if (velocity < 0) {
          mAnimatedVelocity = 0;
        }
      } else {
        // We are expanded and are now going to animate away.
        mAnimatedAcceleration = -mMaximumAcceleration;
        if (velocity > 0) {
          mAnimatedVelocity = 0;
        }
      }
    } else {
      if (!always
          && (velocity > mMaximumMajorVelocity
              || (position > (mVertical ? getHeight() : getWidth()) / 2
                  && velocity > -mMaximumMajorVelocity))) {
        // We are collapsed, and they moved enough to allow us to expand.
        mAnimatedAcceleration = mMaximumAcceleration;
        if (velocity < 0) {
          mAnimatedVelocity = 0;
        }
      } else {
        // We are collapsed, but they didn't move sufficiently to cause
        // us to retract.  Animate back to the collapsed position.
        mAnimatedAcceleration = -mMaximumAcceleration;
        if (velocity > 0) {
          mAnimatedVelocity = 0;
        }
      }
    }

    long now = SystemClock.uptimeMillis();
    mAnimationLastTime = now;
    mCurrentAnimationTime = now + ANIMATION_FRAME_DURATION;
    mAnimating = true;
    mHandler.removeMessages(MSG_ANIMATE);
    mHandler.sendMessageAtTime(mHandler.obtainMessage(MSG_ANIMATE), mCurrentAnimationTime);
    stopTracking();
  }
 private void doAnimation() {
   if (mAnimating) {
     incrementAnimation();
     if (mAnimationPosition >= mBottomOffset + (mVertical ? getHeight() : getWidth()) - 1) {
       mAnimating = false;
       closeDrawer();
     } else if (mAnimationPosition < mTopOffset) {
       mAnimating = false;
       openDrawer();
     } else {
       moveHandle((int) mAnimationPosition);
       mCurrentAnimationTime += ANIMATION_FRAME_DURATION;
       mHandler.sendMessageAtTime(mHandler.obtainMessage(MSG_ANIMATE), mCurrentAnimationTime);
     }
   }
 }