Ejemplo n.º 1
0
  private void animateIn(final Dialog dialog) {
    RelativeLayout.LayoutParams params =
        (RelativeLayout.LayoutParams) zoomableImageView.getLayoutParams();
    params.width = rect.right;
    params.height = rect.bottom;
    zoomableImageView.setLayoutParams(params);

    zoomableImageView.setX(rect.left);
    zoomableImageView.setY(rect.top - statusBarHeightCorrection);
    zoomableImageView.setAlpha(0.0f);
    zoomableImageView.setImageBitmap(bitmap);

    WindowManager win = getActivity().getWindowManager();
    Display d = win.getDefaultDisplay();
    int displayWidth = d.getWidth(); // Width of the actual device
    int displayHeight = d.getHeight() + statusBarHeightCorrection;

    ValueAnimator animWidth = ValueAnimator.ofInt(rect.right, displayWidth);
    animWidth.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = zoomableImageView.getLayoutParams();
            layoutParams.width = val;
            zoomableImageView.setLayoutParams(layoutParams);
          }
        });
    animWidth.setDuration(500);
    animWidth.setInterpolator(new LinearOutSlowInInterpolator());
    animWidth.start();

    ValueAnimator animHeight = ValueAnimator.ofInt(rect.bottom, displayHeight);
    animHeight.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ViewGroup.LayoutParams layoutParams = zoomableImageView.getLayoutParams();
            layoutParams.height = val;
            zoomableImageView.setLayoutParams(layoutParams);
          }
        });
    animHeight.setDuration(500);
    animHeight.setInterpolator(new LinearOutSlowInInterpolator());

    animHeight.start();

    if (statusBarHeightCorrection > 0) {
      zoomableImageView.animate().y(0.0f).setDuration(300).start();
    }

    ValueAnimator animDim = ValueAnimator.ofFloat(0.0f, 0.5f);
    animDim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
            layoutParams.copyFrom(dialog.getWindow().getAttributes());
            layoutParams.dimAmount = (Float) valueAnimator.getAnimatedValue();
            dialog.getWindow().setAttributes(layoutParams);
          }
        });
    animDim.setDuration(300);
    animDim.setStartDelay(300);
    animDim.start();
    zoomableImageView.animate().alpha(1.0f).setDuration(300).start();
  }