/** Animation step. */
  public void run() {
    long now = System.currentTimeMillis();
    long timeLeft = mTargetTime - now;
    if (timeLeft < 0) {
      mDimmingSpan.setAlpha(mDimming ? MIN_ALPHA : MAX_ALPHA);
      mAnimating = false;
      onAnimationEnded();
      return;
    }

    // Start=1, end=0
    float virtualTime = (float) timeLeft / mDuration;
    if (mDimming) {
      float interpolatedTime = DECELERATE_INTERPOLATOR.getInterpolation(virtualTime);
      mDimmingSpan.setAlpha((int) (MIN_ALPHA + (MAX_ALPHA - MIN_ALPHA) * interpolatedTime));
    } else {
      float interpolatedTime = ACCELERATE_INTERPOLATOR.getInterpolation(virtualTime);
      mDimmingSpan.setAlpha((int) (MIN_ALPHA + (MAX_ALPHA - MIN_ALPHA) * (1 - interpolatedTime)));
    }

    invalidate();

    // Repeat
    mHandler.postDelayed(this, FRAME_RATE);
  }
  private void updateAnimation() {
    final long millisSoFar = currentAnimationTimeMillis() - mAnimationStartTime;
    final long millisLeft = mAnimationDuration - millisSoFar;
    final int totalDeltaX = mAnimatingDeltaXStart - mAnimatingDeltaXEnd;
    final int totalDeltaY = mAnimatingDeltaYStart - mAnimatingDeltaYEnd;
    int delta;
    final boolean goingRight = totalDeltaX < 0;
    if (DBG) log("millisleft for animating: " + millisLeft);
    if (millisLeft <= 0) {
      mAnimating = false;
      mAnimatingUp = false;
      reset();
      return;
    }
    // from 0 to 1 as animation progresses
    float interpolation = mInterpolator.getInterpolation((float) millisSoFar / mAnimationDuration);
    if (mAnimating) {
      delta = (int) (totalDeltaX * (1 - interpolation));
      mRotaryOffsetX = mAnimatingDeltaXEnd + delta;
    }
    if (mAnimatingUp) {
      delta = (int) (totalDeltaY * (1 - interpolation));
      mRotaryOffsetY = mAnimatingDeltaYEnd + delta;
    }

    // once we have gone far enough to animate the current buttons off screen, we start
    // wrapping the offset back to the other side so that when the animation is finished,
    // the buttons will come back into their original places.
    if (mDimplesOfFling > 0 && mAnimatingUp == false) {
      if (!goingRight && mRotaryOffsetX < -3 * mDimpleSpacing) {
        // wrap around on fling left
        mRotaryOffsetX += mDimplesOfFling * mDimpleSpacing;
      } else if (goingRight && mRotaryOffsetX > 3 * mDimpleSpacing) {
        // wrap around on fling right
        mRotaryOffsetX -= mDimplesOfFling * mDimpleSpacing;
      }
    }
    invalidate();
  }
Example #3
0
  void onDraw(Canvas c, Paint p) {

    float partDone = (RefresherThread.time - startTime) / (float) dur;
    if (partDone > 1) {
      return;
    }

    float[] currentCrds = {
      crds[0] + a.getInterpolation(partDone) * dist * (float) Math.cos(angle),
      crds[1] - a.getInterpolation(partDone) * dist * (float) Math.sin(angle)
    };

    for (int i = 0; i < CoreLogics.a.railcarNumber; i++) {
      if (Math.sqrt(
              (CoreLogics.a.crds[i][1] - currentCrds[1])
                      * (CoreLogics.a.crds[i][1] - currentCrds[1])
                  + (CoreLogics.a.crds[i][0] - currentCrds[0])
                      * (CoreLogics.a.crds[i][0] - currentCrds[0]))
          < hurtDist) {
        startTime = -dur;
        CoreLogics.a.hurt();
        return;
      }
    }

    p.setStrokeWidth(1.0f);
    p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN));
    p.setColor(Cnt.shotColor);

    c.drawLine(
        currentCrds[0],
        currentCrds[1],
        currentCrds[0] + length * (float) Math.cos(angle),
        currentCrds[1] - length * (float) Math.sin(angle),
        p);
    p.reset();
  }
  private void animateToCenterStep() {
    long curTime = System.currentTimeMillis();
    float percentTime = (float) (curTime - startTime) / (float) (endTime - startTime);
    float percentDistance = interpolator.getInterpolation(percentTime);

    if (DBG)
      Log.i(
          TAG,
          "animateToCenterStep: %t="
              + percentDistance
              + " %d="
              + percentDistance
              + " x="
              + (int) (percentDistance * (endFlingX - startFlingX))
              + " y="
              + (int) (percentDistance * (endFlingY - startFlingY)));
    moveRing(
        (int) (startFlingX + percentDistance * (endFlingX - startFlingX)),
        (int) (startFlingY + percentDistance * (endFlingY - startFlingY)));

    // not yet finished?
    if (percentTime < 1.0f) {
      // more!
      post(
          new Runnable() {
            @Override
            public void run() {
              animateToCenterStep();
            }
          });
    } else {
      // finished
      isFlinging = false;
      mCallback.goToUnlockScreen();
    }
  }