Exemplo n.º 1
0
  private PreviewItemDrawingParams computePreviewItemDrawingParams(
      int index, PreviewItemDrawingParams params) {
    index = NUM_ITEMS_IN_PREVIEW - index - 1;
    float r = (index * 1.0f) / (NUM_ITEMS_IN_PREVIEW - 1);
    float scale = (1 - PERSPECTIVE_SCALE_FACTOR * (1 - r));

    float offset = (1 - r) * mMaxPerspectiveShift;
    float scaledSize = scale * mBaselineIconSize;
    float scaleOffsetCorrection = (1 - scale) * mBaselineIconSize;

    // We want to imagine our coordinates from the bottom left, growing up and to the
    // right. This is natural for the x-axis, but for the y-axis, we have to invert things.
    float transY = mAvailableSpaceInPreview - (offset + scaledSize + scaleOffsetCorrection);
    float transX = offset + scaleOffsetCorrection;
    float totalScale = mBaselineIconScale * scale;
    final int overlayAlpha = (int) (80 * (1 - r));

    if (params == null) {
      params = new PreviewItemDrawingParams(transX, transY, totalScale, overlayAlpha);
    } else {
      params.transX = transX;
      params.transY = transY;
      params.scale = totalScale;
      params.overlayAlpha = overlayAlpha;
    }
    return params;
  }