Beispiel #1
0
  /** Continue dynamically after a fling gesture, possibly off the screen. */
  public void fling(final View photo, float dx, float dy, int duration, boolean spin) {
    if (photo == getFocus()) {
      if (moveFocus(photo, 0f) == null) {
        moveFocus(photo, 180f);
      }
    }
    moveToForeground(photo);
    ViewPropertyAnimator animator =
        photo
            .animate()
            .withLayer()
            .xBy(dx)
            .yBy(dy)
            .setDuration(duration)
            .setInterpolator(new DecelerateInterpolator(2f));

    if (spin) {
      animator.rotation(mThrowRotation);
    }

    if (photoOffTable(photo, (int) dx, (int) dy)) {
      log("fling away");
      animator.withEndAction(
          new Runnable() {
            @Override
            public void run() {
              fadeAway(photo, true);
            }
          });
    }
  }
Beispiel #2
0
  /** Animate the selected photo to the foreground: zooming in to bring it forward. */
  private void pickUp(final View photo) {
    float photoWidth = photo.getWidth();
    float photoHeight = photo.getHeight();

    float scale = Math.min(getHeight() / photoHeight, getWidth() / photoWidth);

    log("scale is %f", scale);
    log("target it");
    float x = (getWidth() - photoWidth) / 2f;
    float y = (getHeight() - photoHeight) / 2f;

    photo.setRotation(wrapAngle(photo.getRotation()));

    log("animate it");
    // lift up to the glass for a good look
    mWaitingToJoinBackground.remove(photo);
    moveToForeground(photo);
    photo
        .animate()
        .withLayer()
        .rotation(0f)
        .rotationY(0f)
        .alpha(1f)
        .scaleX(scale)
        .scaleY(scale)
        .x(x)
        .y(y)
        .setDuration(mPickUpDuration)
        .setInterpolator(new DecelerateInterpolator(2f))
        .withEndAction(
            new Runnable() {
              @Override
              public void run() {
                log("endtimes: %f", photo.getX());
              }
            });
  }