// Returns true if the animation has been drawn.
  // preview: camera preview view.
  // review: snapshot of the preview before switching the camera.
  public boolean drawAnimation(
      GLCanvas canvas,
      int x,
      int y,
      int width,
      int height,
      CameraScreenNail preview,
      RawTexture review) {
    long timeDiff = SystemClock.uptimeMillis() - mAnimStartTime;
    if (timeDiff > ANIMATION_DURATION) return false;
    float fraction = timeDiff / ANIMATION_DURATION;

    // Calculate the position and the size of the preview.
    float centerX = x + width / 2f;
    float centerY = y + height / 2f;
    float previewAnimScale = 1 - ZOOM_DELTA_PREVIEW * (1 - fraction);
    float previewWidth = width * previewAnimScale;
    float previewHeight = height * previewAnimScale;
    int previewX = Math.round(centerX - previewWidth / 2);
    int previewY = Math.round(centerY - previewHeight / 2);

    // Calculate the position and the size of the review.
    float reviewAnimScale = 1 + ZOOM_DELTA_REVIEW * fraction;

    // Calculate how much preview is scaled.
    // The scaling is done by PhotoView in Gallery so we don't have the
    // scaling information but only the width and the height passed to this
    // method. The inference of the scale ratio is done by matching the
    // current width and the original width we have at first when the camera
    // layout is inflated.
    float scaleRatio = 1;
    if (mPreviewFrameLayoutWidth != 0) {
      scaleRatio = (float) width / mPreviewFrameLayoutWidth;
    } else {
      Log.e(TAG, "mPreviewFrameLayoutWidth is 0.");
    }
    float reviewWidth = mReviewDrawingWidth * reviewAnimScale * scaleRatio;
    float reviewHeight = mReviewDrawingHeight * reviewAnimScale * scaleRatio;
    int reviewX = Math.round(centerX - reviewWidth / 2);
    int reviewY = Math.round(centerY - reviewHeight / 2);

    // Draw the preview.
    float alpha = canvas.getAlpha();
    canvas.setAlpha(fraction); // fade in
    preview.directDraw(
        canvas, previewX, previewY, Math.round(previewWidth), Math.round(previewHeight));

    // Draw the review.
    canvas.setAlpha((1f - fraction) * INITIAL_DARKEN_ALPHA); // fade out
    review.draw(canvas, reviewX, reviewY, Math.round(reviewWidth), Math.round(reviewHeight));
    canvas.setAlpha(alpha);
    return true;
  }
  public boolean drawDarkPreview(
      GLCanvas canvas, int x, int y, int width, int height, RawTexture review) {
    // Calculate the position and the size.
    float centerX = x + width / 2f;
    float centerY = y + height / 2f;
    float scaleRatio = 1;
    if (mPreviewFrameLayoutWidth != 0) {
      scaleRatio = (float) width / mPreviewFrameLayoutWidth;
    } else {
      Log.e(TAG, "mPreviewFrameLayoutWidth is 0.");
    }
    float reviewWidth = mReviewDrawingWidth * scaleRatio;
    float reviewHeight = mReviewDrawingHeight * scaleRatio;
    int reviewX = Math.round(centerX - reviewWidth / 2);
    int reviewY = Math.round(centerY - reviewHeight / 2);

    // Draw the review.
    float alpha = canvas.getAlpha();
    canvas.setAlpha(INITIAL_DARKEN_ALPHA);
    review.draw(canvas, reviewX, reviewY, Math.round(reviewWidth), Math.round(reviewHeight));
    canvas.setAlpha(alpha);
    return true;
  }