private void createDefaultIconAnimation() {
    ObjectAnimator collapseAnimator =
        ObjectAnimator.ofFloat(
            mImageToggle,
            "rotation",
            mLabelsPosition == LABELS_POSITION_LEFT
                ? OPENED_PLUS_ROTATION_LEFT
                : OPENED_PLUS_ROTATION_RIGHT,
            CLOSED_PLUS_ROTATION);

    ObjectAnimator expandAnimator =
        ObjectAnimator.ofFloat(
            mImageToggle,
            "rotation",
            CLOSED_PLUS_ROTATION,
            mLabelsPosition == LABELS_POSITION_LEFT
                ? OPENED_PLUS_ROTATION_LEFT
                : OPENED_PLUS_ROTATION_RIGHT);

    mOpenAnimatorSet.play(expandAnimator);
    mCloseAnimatorSet.play(collapseAnimator);

    mOpenAnimatorSet.setInterpolator(mOpenInterpolator);
    mCloseAnimatorSet.setInterpolator(mCloseInterpolator);

    mOpenAnimatorSet.setDuration(ANIMATION_DURATION);
    mCloseAnimatorSet.setDuration(ANIMATION_DURATION);
  }
  @Override
  public void onTextSizeChanged(final TextView textView, float oldSize) {
    if (mCurrentState != CalculatorState.INPUT) { // TODO dont animate when showing graph
      // Only animate text changes that occur from user input.
      return;
    }

    // Calculate the values needed to perform the scale and translation animations,
    // maintaining the same apparent baseline for the displayed text.
    final float textScale = oldSize / textView.getTextSize();
    final float translationX;
    if (android.os.Build.VERSION.SDK_INT >= 17) {
      translationX = (1.0f - textScale) * (textView.getWidth() / 2.0f - textView.getPaddingEnd());
    } else {
      translationX = (1.0f - textScale) * (textView.getWidth() / 2.0f - textView.getPaddingRight());
    }
    final float translationY =
        (1.0f - textScale) * (textView.getHeight() / 2.0f - textView.getPaddingBottom());
    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(
        ObjectAnimator.ofFloat(textView, View.SCALE_X, textScale, 1.0f),
        ObjectAnimator.ofFloat(textView, View.SCALE_Y, textScale, 1.0f),
        ObjectAnimator.ofFloat(textView, View.TRANSLATION_X, translationX, 0.0f),
        ObjectAnimator.ofFloat(textView, View.TRANSLATION_Y, translationY, 0.0f));
    animatorSet.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime));
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.start();
  }
  private void animateFadeOutFadeIn(final View src, final View dst) {
    if (dst.getVisibility() != View.VISIBLE || dst.getAlpha() != 1f) {
      AnimatorSet set = new AnimatorSet();
      set.playSequentially(
          ObjectAnimator.ofFloat(src, "alpha", 0f), ObjectAnimator.ofFloat(dst, "alpha", 1f));
      set.setInterpolator(new LinearInterpolator());
      set.addListener(
          new AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
              src.setAlpha(1f);
              dst.setAlpha(0f);
              src.setVisibility(View.VISIBLE);
              dst.setVisibility(View.VISIBLE);
            }

            @Override
            public void onAnimationRepeat(Animator animation) {}

            @Override
            public void onAnimationEnd(Animator animation) {
              src.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationCancel(Animator animation) {}
          });
      set.setDuration(250);
      set.start();
    } else {
      src.setAlpha(1f);
      src.setVisibility(View.GONE);
    }
  }
  private AnimatorSet createAnimationSet() {
    List<Animator> animators = new ArrayList<>();
    view.setLayerType(View.LAYER_TYPE_HARDWARE, null);

    if (!objectAnimations.isEmpty())
      for (AnimationParams customAnimation : objectAnimations) {
        animators.add(createAnimation(view, customAnimation));
      }

    if (this.animators != null)
      for (Animator animator : this.animators) {
        animators.add(animator);
      }
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(animators);
    if (interpolator != null) {
      animatorSet.setInterpolator(interpolator);
    }
    animatorSet.setDuration(duration);
    animatorSet.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationCancel(Animator animation) {
            super.onAnimationCancel(animation);
            view.setLayerType(View.LAYER_TYPE_NONE, null);
          }

          @Override
          public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            view.setLayerType(View.LAYER_TYPE_NONE, null);
          }
        });
    return animatorSet;
  }
  private void animateHide() {
    bubbleHideAnimator = new AnimatorSet();
    this.setPivotX(this.getWidth());
    this.setPivotY(this.getHeight());
    Animator shrinkerX =
        ObjectAnimator.ofFloat(this, SCALE_X, 1f, 0f).setDuration(BUBBLE_ANIMATION_DURATION);
    Animator shrinkerY =
        ObjectAnimator.ofFloat(this, SCALE_Y, 1f, 0f).setDuration(BUBBLE_ANIMATION_DURATION);
    Animator alpha =
        ObjectAnimator.ofFloat(this, ALPHA, 1f, 0f).setDuration(BUBBLE_ANIMATION_DURATION);
    bubbleHideAnimator.setInterpolator(new AccelerateInterpolator());
    bubbleHideAnimator.playTogether(shrinkerX, shrinkerY, alpha);
    bubbleHideAnimator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            FastScrollBubble.this.setVisibility(INVISIBLE);
            bubbleHideAnimator = null;
          }

          @Override
          public void onAnimationCancel(Animator animation) {
            super.onAnimationCancel(animation);
            FastScrollBubble.this.setVisibility(INVISIBLE);
            bubbleHideAnimator = null;
          }
        });
    bubbleHideAnimator.start();
  }
Exemplo n.º 6
0
 /** Starts the animation. */
 public void start() {
   resetAllPaths();
   animatorSet.cancel();
   animatorSet.setDuration(duration);
   animatorSet.setInterpolator(interpolator);
   animatorSet.setStartDelay(delay);
   animatorSet.start();
 }
  @Override
  public void animate() {
    final ViewGroup parentView = (ViewGroup) view.getParent();
    final FrameLayout slideOutFrame = new FrameLayout(view.getContext());
    final int positionView = parentView.indexOfChild(view);
    slideOutFrame.setLayoutParams(view.getLayoutParams());
    slideOutFrame.setClipChildren(true);
    parentView.removeView(view);
    slideOutFrame.addView(view);
    parentView.addView(slideOutFrame, positionView);

    switch (direction) {
      case DIRECTION_LEFT:
        slideAnim =
            ObjectAnimator.ofFloat(
                view, View.TRANSLATION_X, view.getTranslationX() - view.getWidth());
        break;
      case DIRECTION_RIGHT:
        slideAnim =
            ObjectAnimator.ofFloat(
                view, View.TRANSLATION_X, view.getTranslationX() + view.getWidth());
        break;
      case DIRECTION_UP:
        slideAnim =
            ObjectAnimator.ofFloat(
                view, View.TRANSLATION_Y, view.getTranslationY() - view.getHeight());
        break;
      case DIRECTION_DOWN:
        slideAnim =
            ObjectAnimator.ofFloat(
                view, View.TRANSLATION_Y, view.getTranslationY() + view.getHeight());
        break;
      default:
        break;
    }

    AnimatorSet slideSet = new AnimatorSet();
    slideSet.play(slideAnim);
    slideSet.setInterpolator(interpolator);
    slideSet.setDuration(duration);
    slideSet.addListener(
        new AnimatorListenerAdapter() {

          @Override
          public void onAnimationEnd(Animator animation) {
            view.setVisibility(View.INVISIBLE);
            slideAnim.reverse();
            slideOutFrame.removeAllViews();
            parentView.removeView(slideOutFrame);
            parentView.addView(view, positionView);
            if (getListener() != null) {
              getListener().onAnimationEnd(SlideOutUnderneathAnimation.this);
            }
          }
        });
    slideSet.start();
  }
Exemplo n.º 8
0
  private AnimatorSet buildAnimationSet(int duration, ObjectAnimator... objectAnimators) {

    AnimatorSet a = new AnimatorSet();
    a.playTogether(objectAnimators);
    a.setInterpolator(
        AnimationUtils.loadInterpolator(
            EventActivity.this, android.R.interpolator.accelerate_decelerate));
    a.setDuration(duration);

    return a;
  }
 private void startChildAnimation(View child) {
   if (animationEnabled) {
     AnimatorSet animatorSet = new AnimatorSet();
     animatorSet.playTogether(
         ObjectAnimator.ofFloat(child, "alpha", 0.0f, 1.0f),
         ObjectAnimator.ofFloat(
             child, "translationY", AndroidUtilities.dp(showedFromBotton ? 6 : -6), 0));
     animatorSet.setDuration(180);
     animatorSet.setInterpolator(decelerateInterpolator);
     animatorSet.start();
   }
 }
Exemplo n.º 10
0
  @SuppressLint("NewApi")
  public void onRevealAnimationProgress(boolean open, float radius, int x, int y) {
    if (!open) {
      return;
    }
    int count = Build.VERSION.SDK_INT <= 19 ? 11 : 8;
    for (int a = 0; a < count; a++) {
      if (views[a].getTag(R.string.AppName) == null) {
        if (distCache[a] == 0) {
          int buttonX = views[a].getLeft() + views[a].getMeasuredWidth() / 2;
          int buttonY = views[a].getTop() + views[a].getMeasuredHeight() / 2;
          distCache[a] =
              (float) Math.sqrt((x - buttonX) * (x - buttonX) + (y - buttonY) * (y - buttonY));
          float vecX = (x - buttonX) / distCache[a];
          float vecY = (y - buttonY) / distCache[a];
          views[a].setPivotX(views[a].getMeasuredWidth() / 2 + vecX * AndroidUtilities.dp(20));
          views[a].setPivotY(views[a].getMeasuredHeight() / 2 + vecY * AndroidUtilities.dp(20));
        }
        if (distCache[a] > radius + AndroidUtilities.dp(27)) {
          continue;
        }

        views[a].setTag(R.string.AppName, 1);
        final ArrayList<Animator> animators = new ArrayList<>();
        final ArrayList<Animator> animators2 = new ArrayList<>();
        if (a < 8) {
          animators.add(ObjectAnimator.ofFloat(views[a], "scaleX", 0.7f, 1.05f));
          animators.add(ObjectAnimator.ofFloat(views[a], "scaleY", 0.7f, 1.05f));
          animators2.add(ObjectAnimator.ofFloat(views[a], "scaleX", 1.0f));
          animators2.add(ObjectAnimator.ofFloat(views[a], "scaleY", 1.0f));
        }
        if (Build.VERSION.SDK_INT <= 19) {
          animators.add(ObjectAnimator.ofFloat(views[a], "alpha", 1.0f));
        }
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(animators);
        animatorSet.setDuration(150);
        animatorSet.setInterpolator(decelerateInterpolator);
        animatorSet.addListener(
            new AnimatorListenerAdapter() {
              @Override
              public void onAnimationEnd(Animator animation) {
                AnimatorSet animatorSet = new AnimatorSet();
                animatorSet.playTogether(animators2);
                animatorSet.setDuration(100);
                animatorSet.setInterpolator(decelerateInterpolator);
                animatorSet.start();
              }
            });
        animatorSet.start();
      }
    }
  }
Exemplo n.º 11
0
  private void animBottom(View v) {
    ObjectAnimator animator_x = ObjectAnimator.ofFloat(v, View.ALPHA, 0f, 1f);
    animator_x.setDuration(ANIMATION_DURATION_BASE * 2);
    int y = v.getTop();
    if (mStart) y += vh.ll_parent.getPaddingTop();
    ObjectAnimator animator_y = ObjectAnimator.ofFloat(v, "y", +1400, y);
    animator_y.setDuration(ANIMATION_DURATION_BASE);

    AnimatorSet set = new AnimatorSet();
    set.setInterpolator(new LinearInterpolator());
    set.playTogether(animator_x, animator_y);
    set.start();
  }
Exemplo n.º 12
0
  @Override
  public AnimatorSet createAnimatorSet() {
    ViewHelper.setClipChildren(targetView, false);

    AnimatorSet rotationSet = new AnimatorSet();
    rotationSet.play(
        ObjectAnimator.ofFloat(targetView, View.ROTATION, targetView.getRotation() + degrees));
    rotationSet.setInterpolator(interpolator);
    rotationSet.setDuration(duration);
    if (listener != null) {
      rotationSet.addListener(listener);
    }

    return rotationSet;
  }
  private void animateShow() {

    AnimatorSet animatorSet = new AnimatorSet();
    this.setPivotX(this.getWidth());
    this.setPivotY(this.getHeight());
    this.setVisibility(VISIBLE);
    Animator growerX =
        ObjectAnimator.ofFloat(this, SCALE_X, 0f, 1f).setDuration(BUBBLE_ANIMATION_DURATION);
    Animator growerY =
        ObjectAnimator.ofFloat(this, SCALE_Y, 0f, 1f).setDuration(BUBBLE_ANIMATION_DURATION);
    Animator alpha =
        ObjectAnimator.ofFloat(this, ALPHA, 0f, 1f).setDuration(BUBBLE_ANIMATION_DURATION);
    animatorSet.setInterpolator(new DecelerateInterpolator());
    animatorSet.playTogether(growerX, growerY, alpha);
    animatorSet.start();
  }
Exemplo n.º 14
0
  /**
   * item的交换动画效果
   *
   * @param oldPosition
   * @param newPosition
   */
  private void animateReorder(final int oldPosition, final int newPosition) {
    boolean isForward = newPosition > oldPosition;
    List<Animator> resultList = new LinkedList<Animator>();
    if (isForward) {
      for (int pos = oldPosition; pos < newPosition; pos++) {
        View view = getChildAt(pos - getFirstVisiblePosition());
        System.out.println(pos);

        if ((pos + 1) % getNumColumns() == 0) {
          resultList.add(
              createTranslationAnimations(
                  view, -view.getWidth() * (getNumColumns() - 1), 0, view.getHeight(), 0));
        } else {
          resultList.add(createTranslationAnimations(view, view.getWidth(), 0, 0, 0));
        }
      }
    } else {
      for (int pos = oldPosition; pos > newPosition; pos--) {
        View view = getChildAt(pos - getFirstVisiblePosition());
        if ((pos + getNumColumns()) % getNumColumns() == 0) {
          resultList.add(
              createTranslationAnimations(
                  view, view.getWidth() * (getNumColumns() - 1), 0, -view.getHeight(), 0));
        } else {
          resultList.add(createTranslationAnimations(view, -view.getWidth(), 0, 0, 0));
        }
      }
    }

    AnimatorSet resultSet = new AnimatorSet();
    resultSet.playTogether(resultList);
    resultSet.setDuration(300);
    resultSet.setInterpolator(new AccelerateDecelerateInterpolator());
    resultSet.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationStart(Animator animation) {
            mAnimationEnd = false;
          }

          @Override
          public void onAnimationEnd(Animator animation) {
            mAnimationEnd = true;
          }
        });
    resultSet.start();
  }
Exemplo n.º 15
0
 private void startAnim(ImageView v) {
   ObjectAnimator scaleX = ObjectAnimator.ofFloat(v, "scaleX", 1f, 1.15f);
   ObjectAnimator scaleY = ObjectAnimator.ofFloat(v, "scaleY", 1f, 1.15f);
   AnimatorSet animatorSet = new AnimatorSet();
   animatorSet.setDuration(3000);
   animatorSet.setInterpolator(new DecelerateInterpolator());
   animatorSet.play(scaleX).with(scaleY);
   animatorSet.addListener(
       new AnimatorListenerAdapter() {
         @Override
         public void onAnimationEnd(Animator animation) {
           Intent homeIntent = new Intent(MainActivity.this, HomePageActivity.class);
           startActivity(homeIntent);
           overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
           finish();
         }
       });
   animatorSet.start();
 }
  public void show() {
    if (callback != null) {
      callback.onShowStart();
    }

    ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(this, View.ALPHA, 0f, 1f);

    ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(this, View.SCALE_X, 1.8f, 1f);

    ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(this, View.SCALE_Y, 1.8f, 1f);

    showAnimatorSet = new AnimatorSet();
    showAnimatorSet.playTogether(alphaAnimator, scaleXAnimator, scaleYAnimator);
    showAnimatorSet.setDuration(
        getResources().getInteger(R.integer.framework_animation_duration_long));
    showAnimatorSet.setStartDelay(
        getResources().getInteger(R.integer.framework_animation_delay_short));
    showAnimatorSet.setInterpolator(new Back.EaseOut(2));
    final View container = this;
    showAnimatorSet.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationStart(Animator animation) {
            container.setAlpha(0f);
            container.setVisibility(View.VISIBLE);
          }

          @Override
          public void onAnimationEnd(Animator animation) {
            new Handler()
                .postDelayed(
                    new Runnable() {
                      @Override
                      public void run() {
                        hide();
                      }
                    },
                    getResources().getInteger(R.integer.framework_animation_duration_long));
          }
        });
    showAnimatorSet.start();
  }
Exemplo n.º 17
0
 private void startAnimator() {
   Point startPoint = new Point(getWidth() / 2, RADIUS);
   Point endPoint = new Point(getWidth() / 2, getHeight() - RADIUS);
   ValueAnimator anim = ValueAnimator.ofObject(new PointEvaluator(), startPoint, endPoint);
   anim.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           currentPoint = (Point) animation.getAnimatedValue();
           invalidate();
         }
       });
   ObjectAnimator anim2 =
       ObjectAnimator.ofObject(this, "color", new ColorEvaluator(), "#0000FF", "#FF0000");
   AnimatorSet animset = new AnimatorSet();
   animset.play(anim).with(anim2);
   animset.setInterpolator(new BounceInterpolator());
   animset.setDuration(5000);
   animset.start();
 }
Exemplo n.º 18
0
  private Animator switchToStandardInputAnimator() {
    final View standard = getChildAt(0);
    final View manual = getChildAt(1);

    AnimatorSet set = new AnimatorSet();
    set.setInterpolator(IN_INTERPOLATOR);
    set.setDuration(ANIM_DURATION);
    set.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animation) {
            manual.setVisibility(VISIBLE);
            standard.setVisibility(VISIBLE);
          }

          @Override
          public void onAnimationEnd(Animator animation) {
            manual.setVisibility(GONE);
            standard.setVisibility(VISIBLE);
          }

          @Override
          public void onAnimationCancel(Animator animation) {
            manual.setVisibility(GONE);
            standard.setVisibility(VISIBLE);
          }

          @Override
          public void onAnimationRepeat(Animator animation) {}
        });
    set.playTogether(
        ofFloat(manual, "translationY", 0, getHeight()),
        ofFloat(manual, "alpha", 1f, 0f),
        ofFloat(standard, "scaleX", 0.5f, 1f),
        ofFloat(standard, "scaleY", 0.5f, 1f),
        ofFloat(standard, "alpha", 0f, 1f));

    return set;
  }
Exemplo n.º 19
0
  /**
   * Method that create a new frame to be drawn in the specified location
   *
   * @param r The location relative to the parent layout
   * @return v The new view
   */
  private View createFrame(Rect r, boolean animate) {
    int padding = (int) getResources().getDimension(R.dimen.disposition_frame_padding);
    final ImageView v = new ImageView(getContext());
    v.setImageResource(R.drawable.ic_camera);
    v.setScaleType(ScaleType.CENTER);

    // Is locked? Then change the background color
    v.setBackgroundColor(
        getResources()
            .getColor(
                mResizeFrame == null
                    ? R.color.disposition_locked_frame_bg_color
                    : R.color.disposition_frame_bg_color));

    RelativeLayout.LayoutParams params =
        new RelativeLayout.LayoutParams(r.width() - padding, r.height() - padding);
    v.setX(r.left + padding);
    v.setY(r.top + padding);
    v.setOnLongClickListener(this);
    addView(v, params);

    // Animate the view
    if (animate) {
      List<Animator> animators = new ArrayList<Animator>();
      animators.add(ObjectAnimator.ofFloat(v, "scaleX", 0.0f, 1.0f));
      animators.add(ObjectAnimator.ofFloat(v, "scaleY", 0.0f, 1.0f));
      animators.add(ObjectAnimator.ofFloat(v, "alpha", 0.0f, 1.0f));
      animators.add(ObjectAnimator.ofFloat(v, "alpha", 0.0f, 1.0f));

      AnimatorSet animSet = new AnimatorSet();
      animSet.playTogether(animators);
      animSet.setDuration(getResources().getInteger(R.integer.disposition_show_anim));
      animSet.setInterpolator(new BounceInterpolator());
      animSet.setTarget(v);
      animSet.start();
    }

    return v;
  }
Exemplo n.º 20
0
  private void animer(int width) {

    valeurHaut.setText("");
    valeurBas.setText("");

    ViewGroup.LayoutParams params = progressBarHaut.getLayoutParams();
    params.width = 0;
    progressBarHaut.setLayoutParams(params);

    ViewGroup.LayoutParams params2 = progressBarBas.getLayoutParams();
    params2.width = 0;
    progressBarBas.setLayoutParams(params2);

    float largeurMax = barreHaut.getWidth();
    float pourcentHaut = vHaut / max;
    float pourcentBas = vBas / max;

    int largeurHaut = (int) (largeurMax * pourcentHaut);
    int largeurtBas = (int) (largeurMax * pourcentBas);

    final AnimatorSet anim = new AnimatorSet();
    anim.setInterpolator(new AccelerateInterpolator());
    anim.setDuration((long) temps);
    anim.playTogether(
        ValueAnimator.ofObject(
            new WidthEvaluator(progressBarHaut, valeurHaut, vHaut), 0, largeurHaut),
        ValueAnimator.ofObject(
            new WidthEvaluator(progressBarBas, valeurBas, vBas), 0, largeurtBas));

    this.postDelayed(
        new Runnable() {
          @Override
          public void run() {
            anim.start();
          }
        },
        attente);
  }
  @Override
  public boolean animateChange(
      RecyclerView.ViewHolder oldHolder,
      RecyclerView.ViewHolder newHolder,
      ItemHolderInfo preInfo,
      ItemHolderInfo postInfo) {
    if (preInfo instanceof DesignerNewsItemHolderInfo
        && ((DesignerNewsItemHolderInfo) preInfo).animateAddToPocket) {
      final FeedAdapter.DesignerNewsStoryHolder holder =
          (FeedAdapter.DesignerNewsStoryHolder) newHolder;

      // setup for anim
      holder.itemView.setHasTransientState(true);
      ((ViewGroup) holder.pocket.getParent().getParent()).setClipChildren(false);
      final int initialLeft = holder.pocket.getLeft();
      final int initialTop = holder.pocket.getTop();
      final int translatedLeft = (holder.itemView.getWidth() - holder.pocket.getWidth()) / 2;
      final int translatedTop =
          initialTop - ((holder.itemView.getHeight() - holder.pocket.getHeight()) / 2);
      final ArcMotion arc = new ArcMotion();

      // animate the title & pocket icon up, scale the pocket icon up
      Animator titleMoveFadeOut =
          ObjectAnimator.ofPropertyValuesHolder(
              holder.title,
              PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, -(holder.itemView.getHeight() / 5)),
              PropertyValuesHolder.ofFloat(View.ALPHA, 0.54f));

      Animator pocketMoveUp =
          ObjectAnimator.ofFloat(
              holder.pocket,
              View.TRANSLATION_X,
              View.TRANSLATION_Y,
              arc.getPath(initialLeft, initialTop, translatedLeft, translatedTop));
      Animator pocketScaleUp =
          ObjectAnimator.ofPropertyValuesHolder(
              holder.pocket,
              PropertyValuesHolder.ofFloat(View.SCALE_X, 3f),
              PropertyValuesHolder.ofFloat(View.SCALE_Y, 3f));
      ObjectAnimator pocketFadeUp = ObjectAnimator.ofInt(holder.pocket, ViewUtils.IMAGE_ALPHA, 255);

      AnimatorSet up = new AnimatorSet();
      up.playTogether(titleMoveFadeOut, pocketMoveUp, pocketScaleUp, pocketFadeUp);
      up.setDuration(300);
      up.setInterpolator(
          AnimationUtils.loadInterpolator(
              holder.itemView.getContext(), android.R.interpolator.fast_out_slow_in));

      // animate everything back into place
      Animator titleMoveFadeIn =
          ObjectAnimator.ofPropertyValuesHolder(
              holder.title,
              PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, 0f),
              PropertyValuesHolder.ofFloat(View.ALPHA, 1f));
      Animator pocketMoveDown =
          ObjectAnimator.ofFloat(
              holder.pocket,
              View.TRANSLATION_X,
              View.TRANSLATION_Y,
              arc.getPath(translatedLeft, translatedTop, 0, 0));
      Animator pvhPocketScaleDown =
          ObjectAnimator.ofPropertyValuesHolder(
              holder.pocket,
              PropertyValuesHolder.ofFloat(View.SCALE_X, 1f),
              PropertyValuesHolder.ofFloat(View.SCALE_Y, 1f));
      ObjectAnimator pocketFadeDown =
          ObjectAnimator.ofInt(holder.pocket, ViewUtils.IMAGE_ALPHA, 138);

      AnimatorSet down = new AnimatorSet();
      down.playTogether(titleMoveFadeIn, pocketMoveDown, pvhPocketScaleDown, pocketFadeDown);
      down.setDuration(300);
      down.setInterpolator(
          AnimationUtils.loadInterpolator(
              holder.itemView.getContext(), android.R.interpolator.fast_out_slow_in));
      down.setStartDelay(500);

      // play it
      AnimatorSet upDown = new AnimatorSet();
      upDown.playSequentially(up, down);

      // clean up
      upDown.addListener(
          new AnimatorListenerAdapter() {

            @Override
            public void onAnimationStart(Animator animation) {
              dispatchAnimationStarted(holder);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
              ((ViewGroup) holder.pocket.getParent().getParent()).setClipChildren(true);
              holder.itemView.setHasTransientState(false);
              dispatchAnimationFinished(holder);
            }
          });
      upDown.start();
    }
    return super.animateChange(oldHolder, newHolder, preInfo, postInfo);
  }
Exemplo n.º 22
0
    @Override
    public void run() {
      long delay = MOVE_DELAY;
      if (mContentView == null || mSaverView == null) {
        mHandler.removeCallbacks(this);
        mHandler.postDelayed(this, delay);
        return;
      }

      final float xrange = mContentView.getWidth() - mSaverView.getWidth();
      final float yrange = mContentView.getHeight() - mSaverView.getHeight();
      Log.v("xrange: " + xrange + " yrange: " + yrange);

      if (xrange == 0 && yrange == 0) {
        delay = 500; // back in a split second
      } else {
        final int nextx = (int) (Math.random() * xrange);
        final int nexty = (int) (Math.random() * yrange);

        if (mSaverView.getAlpha() == 0f) {
          // jump right there
          mSaverView.setX(nextx);
          mSaverView.setY(nexty);
          ObjectAnimator.ofFloat(mSaverView, "alpha", 0f, 1f).setDuration(FADE_TIME).start();
        } else {
          AnimatorSet s = new AnimatorSet();
          Animator xMove = ObjectAnimator.ofFloat(mSaverView, "x", mSaverView.getX(), nextx);
          Animator yMove = ObjectAnimator.ofFloat(mSaverView, "y", mSaverView.getY(), nexty);

          Animator xShrink = ObjectAnimator.ofFloat(mSaverView, "scaleX", 1f, 0.85f);
          Animator xGrow = ObjectAnimator.ofFloat(mSaverView, "scaleX", 0.85f, 1f);

          Animator yShrink = ObjectAnimator.ofFloat(mSaverView, "scaleY", 1f, 0.85f);
          Animator yGrow = ObjectAnimator.ofFloat(mSaverView, "scaleY", 0.85f, 1f);
          AnimatorSet shrink = new AnimatorSet();
          shrink.play(xShrink).with(yShrink);
          AnimatorSet grow = new AnimatorSet();
          grow.play(xGrow).with(yGrow);

          Animator fadeout = ObjectAnimator.ofFloat(mSaverView, "alpha", 1f, 0f);
          Animator fadein = ObjectAnimator.ofFloat(mSaverView, "alpha", 0f, 1f);

          if (SLIDE) {
            s.play(xMove).with(yMove);
            s.setDuration(SLIDE_TIME);

            s.play(shrink.setDuration(SLIDE_TIME / 2));
            s.play(grow.setDuration(SLIDE_TIME / 2)).after(shrink);
            s.setInterpolator(mSlowStartWithBrakes);
          } else {
            AccelerateInterpolator accel = new AccelerateInterpolator();
            DecelerateInterpolator decel = new DecelerateInterpolator();

            shrink.setDuration(FADE_TIME).setInterpolator(accel);
            fadeout.setDuration(FADE_TIME).setInterpolator(accel);
            grow.setDuration(FADE_TIME).setInterpolator(decel);
            fadein.setDuration(FADE_TIME).setInterpolator(decel);
            s.play(shrink);
            s.play(fadeout);
            s.play(xMove.setDuration(0)).after(FADE_TIME);
            s.play(yMove.setDuration(0)).after(FADE_TIME);
            s.play(fadein).after(FADE_TIME);
            s.play(grow).after(FADE_TIME);
          }
          s.start();
        }

        long now = System.currentTimeMillis();
        long adjust = (now % 60000);
        delay =
            delay
                + (MOVE_DELAY - adjust) // minute aligned
                - (SLIDE ? 0 : FADE_TIME) // start moving before the fade
        ;
      }

      mHandler.removeCallbacks(this);
      mHandler.postDelayed(this, delay);
    }
  private void animateClose(ObjectAnimator backgroundAnimator) {

    AnimationRect rect = getArguments().getParcelable("rect");

    if (rect == null) {
      photoView.animate().alpha(0);
      backgroundAnimator.start();
      return;
    }

    final Rect startBounds = rect.scaledBitmapRect;
    final Rect finalBounds = AnimationUtility.getBitmapRectFromImageView(photoView);

    if (finalBounds == null) {
      photoView.animate().alpha(0);
      backgroundAnimator.start();
      return;
    }

    if (Utility.isDevicePort() != rect.isScreenPortrait) {
      photoView.animate().alpha(0);
      backgroundAnimator.start();
      return;
    }

    float startScale;
    if ((float) finalBounds.width() / finalBounds.height()
        > (float) startBounds.width() / startBounds.height()) {
      startScale = (float) startBounds.height() / finalBounds.height();

    } else {
      startScale = (float) startBounds.width() / finalBounds.width();
    }

    final float startScaleFinal = startScale;

    int deltaTop = startBounds.top - finalBounds.top;
    int deltaLeft = startBounds.left - finalBounds.left;

    photoView.setPivotY((photoView.getHeight() - finalBounds.height()) / 2);
    photoView.setPivotX((photoView.getWidth() - finalBounds.width()) / 2);

    photoView
        .animate()
        .translationX(deltaLeft)
        .translationY(deltaTop)
        .scaleY(startScaleFinal)
        .scaleX(startScaleFinal)
        .setDuration(ANIMATION_DURATION)
        .setInterpolator(new AccelerateDecelerateInterpolator())
        .withEndAction(
            new Runnable() {
              @Override
              public void run() {

                photoView
                    .animate()
                    .alpha(0.0f)
                    .setDuration(200)
                    .withEndAction(
                        new Runnable() {
                          @Override
                          public void run() {}
                        });
              }
            });

    AnimatorSet animationSet = new AnimatorSet();
    animationSet.setDuration(ANIMATION_DURATION);
    animationSet.setInterpolator(new AccelerateDecelerateInterpolator());

    animationSet.playTogether(backgroundAnimator);

    animationSet.playTogether(
        ObjectAnimator.ofFloat(
            photoView, "clipBottom", 0, AnimationRect.getClipBottom(rect, finalBounds)));
    animationSet.playTogether(
        ObjectAnimator.ofFloat(
            photoView, "clipRight", 0, AnimationRect.getClipRight(rect, finalBounds)));
    animationSet.playTogether(
        ObjectAnimator.ofFloat(
            photoView, "clipTop", 0, AnimationRect.getClipTop(rect, finalBounds)));
    animationSet.playTogether(
        ObjectAnimator.ofFloat(
            photoView, "clipLeft", 0, AnimationRect.getClipLeft(rect, finalBounds)));

    animationSet.start();
  }
Exemplo n.º 24
0
 @Override
 public void setInterpolator(TimeInterpolator value) {
   mAnimatorSet.setInterpolator(value);
 }
Exemplo n.º 25
0
  private void zoomImageFromThumb(final View thumbView, int imageResId) {

    if (mCurrentAnimator != null) {
      mCurrentAnimator.cancel();
    }

    expandedImageView = (ImageView) rootView.findViewById(R.id.expanded_image);

    expandedImageView.setOnTouchListener(
        new View.OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            if (detector.onTouchEvent(event)) {
              return true;
            } else {
              return false;
            }
          }
        });

    expandedImageView.setImageResource(imageResId);

    final Rect startBounds = new Rect();
    final Rect finalBounds = new Rect();
    final Point globalOffset = new Point();

    thumbView.getGlobalVisibleRect(startBounds);
    rootView.findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset);

    startBounds.offset(-globalOffset.x, -globalOffset.y);
    finalBounds.offset(-globalOffset.x, -globalOffset.y);

    float startScale;

    if ((float) finalBounds.width() / finalBounds.height()
        > (float) startBounds.width() / startBounds.height()) {

      startScale = (float) startBounds.height() / finalBounds.height();
      float startWidth = startScale * finalBounds.width();
      float deltaWidth = (startWidth - startBounds.width()) / 2;
      startBounds.left -= deltaWidth;
      startBounds.right += deltaWidth;

    } else {

      startScale = (float) startBounds.height() / finalBounds.height();
      float startHeight = startScale * finalBounds.height();
      float deltaHeight = (startHeight - startBounds.height()) / 2;
      startBounds.top -= deltaHeight;
      startBounds.bottom += deltaHeight;
    }

    thumbView.setAlpha(0f);
    expandedImageView.setVisibility(View.VISIBLE);
    expandedImageView.setPivotX(0f);
    expandedImageView.setPivotY(0f);

    AnimatorSet set = new AnimatorSet();

    set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left, finalBounds.left))
        .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top, finalBounds.top))
        .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f))
        .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f));

    set.setDuration(mShortAnimationDuration);
    set.setInterpolator(new DecelerateInterpolator());
    set.addListener(
        new AnimatorListenerAdapter() {

          @Override
          public void onAnimationEnd(Animator animation) {
            mCurrentAnimator = null;
          }

          @Override
          public void onAnimationCancel(Animator animation) {
            mCurrentAnimator = null;
          }
        });
    set.start();
    mCurrentAnimator = set;

    final float startScaleFinal = startScale;
    expandedImageView.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            if (mCurrentAnimator != null) {
              mCurrentAnimator.cancel();
            }

            AnimatorSet set = new AnimatorSet();
            set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left))
                .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top))
                .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScaleFinal))
                .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal));

            set.setDuration(mShortAnimationDuration);
            set.setInterpolator(new DecelerateInterpolator());
            set.addListener(
                new AnimatorListenerAdapter() {
                  @Override
                  public void onAnimationEnd(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                  }

                  @Override
                  public void onAnimationCancel(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    mCurrentAnimator = null;
                  }
                });
            set.start();
            mCurrentAnimator = set;
          }
        });
  }
Exemplo n.º 26
0
  /** 指定光标相对位置 */
  private void setBorderParams(final View item) {
    cursor.clearAnimation();
    cursor.setVisibility(View.VISIBLE);
    final RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) item.getLayoutParams();
    final int l = params.leftMargin + paddingLeft - boarderLeft;
    final int t = params.topMargin + paddingTop - boarderTop;
    final int r = l + itemWidth + boarderRight;
    final int b = t + itemHeight + boarderBottom;
    // 判断动画类型
    switch (animationType) {
      case ANIM_DEFAULT:
        cursor.layout(l, t, r, b);
        item.bringToFront();
        cursor.bringToFront();
        if (scalable) {
          scaleToLarge(item);
        }
        break;
      case ANIM_TRASLATE:
        ValueAnimator transAnimatorX = ObjectAnimator.ofFloat(cursor, "x", cursor.getLeft(), l);
        ValueAnimator transAnimatorY = ObjectAnimator.ofFloat(cursor, "y", cursor.getTop(), t);
        cursor.layout(l, t, r, b);
        item.bringToFront();
        cursor.bringToFront();
        if (scalable) {
          scaleToLarge(item);
        }
        if (focusIsOut) {
          return;
        }

        animatorSet = new AnimatorSet();
        animatorSet.play(transAnimatorY).with(transAnimatorX);
        animatorSet.setDuration(durationTraslate);
        animatorSet.setInterpolator(new DecelerateInterpolator(1));
        //			animatorSet.addListener(new AnimatorListener() {
        //
        //				@Override
        //				public void onAnimationStart(Animator arg0) {
        //				}
        //
        //				@Override
        //				public void onAnimationRepeat(Animator arg0) {
        //				}
        //
        //				@Override
        //				public void onAnimationEnd(Animator arg0) {
        //					cursor.layout(l, t, r, b);
        //					item.bringToFront();
        //					cursor.bringToFront();
        //					if (scalable) {
        //						scaleToLarge(item);
        //					}
        //				}
        //
        //				@Override
        //				public void onAnimationCancel(Animator arg0) {
        //				}
        //			});
        animatorSet.start();

        break;
    }
  }
  protected void onResult(final String result) {
    // Calculate the values needed to perform the scale and translation animations,
    // accounting for how the scale will affect the final position of the text.
    final float resultScale =
        mFormulaEditText.getVariableTextSize(result) / mResultEditText.getTextSize();
    final float resultTranslationX =
        (1.0f - resultScale)
            * (mResultEditText.getWidth() / 2.0f - mResultEditText.getPaddingRight());

    // Calculate the height of the formula (without padding)
    final float formulaRealHeight =
        mFormulaEditText.getHeight()
            - mFormulaEditText.getPaddingTop()
            - mFormulaEditText.getPaddingBottom();

    // Calculate the height of the resized result (without padding)
    final float resultRealHeight =
        resultScale
            * (mResultEditText.getHeight()
                - mResultEditText.getPaddingTop()
                - mResultEditText.getPaddingBottom());

    // Now adjust the result upwards!
    final float resultTranslationY =
        // Move the result up (so both formula + result heights match)
        -mFormulaEditText.getHeight()
            // Now switch the result's padding top with the formula's padding top
            - resultScale * mResultEditText.getPaddingTop()
            + mFormulaEditText.getPaddingTop()
            // But the result centers its text! And it's taller now! So adjust for that centered
            // text
            + (formulaRealHeight - resultRealHeight) / 2;

    // Move the formula all the way to the top of the screen
    final float formulaTranslationY = -mFormulaEditText.getBottom();

    // Use a value animator to fade to the final text color over the course of the animation.
    final int resultTextColor = mResultEditText.getCurrentTextColor();
    final int formulaTextColor = mFormulaEditText.getCurrentTextColor();
    final ValueAnimator textColorAnimator =
        ValueAnimator.ofObject(new ArgbEvaluator(), resultTextColor, formulaTextColor);
    textColorAnimator.addUpdateListener(
        new AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mResultEditText.setTextColor((Integer) valueAnimator.getAnimatedValue());
          }
        });
    mResultEditText.setText(result);
    mResultEditText.setPivotX(mResultEditText.getWidth() / 2);
    mResultEditText.setPivotY(0f);

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(
        textColorAnimator,
        ObjectAnimator.ofFloat(mResultEditText, View.SCALE_X, resultScale),
        ObjectAnimator.ofFloat(mResultEditText, View.SCALE_Y, resultScale),
        ObjectAnimator.ofFloat(mResultEditText, View.TRANSLATION_X, resultTranslationX),
        ObjectAnimator.ofFloat(mResultEditText, View.TRANSLATION_Y, resultTranslationY),
        ObjectAnimator.ofFloat(mFormulaEditText, View.TRANSLATION_Y, formulaTranslationY));
    animatorSet.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
    animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
    animatorSet.addListener(
        new AnimationFinishedListener() {
          @Override
          public void onAnimationFinished() {
            // Reset all of the values modified during the animation.
            mResultEditText.setPivotY(mResultEditText.getHeight() / 2);
            mResultEditText.setTextColor(resultTextColor);
            mResultEditText.setScaleX(1.0f);
            mResultEditText.setScaleY(1.0f);
            mResultEditText.setTranslationX(0.0f);
            mResultEditText.setTranslationY(0.0f);
            mFormulaEditText.setTranslationY(0.0f);

            // Finally update the formula to use the current result.
            mFormulaEditText.setText(result);
            setState(CalculatorState.RESULT);
          }
        });

    play(animatorSet);
  }
  public void showAnimation(View MainView, final View thumbView, Bitmap imageResId) {
    requestAnimation = true;
    if (ivFullScreen == null) {
      mView = MainView;
      this.thumbView = thumbView;
      this.mResId = imageResId;
      return;
    }
    if (mCurrentAnimator != null) {
      mCurrentAnimator.cancel();
    }
    // Load the high-resolution "zoomed-in" image.
    final ImageView expandedImageView = ivFullScreen;
    expandedImageView.setImageBitmap(imageResId);
    // Calculate the starting and ending bounds for the zoomed-in image. This step
    // involves lots of math. Yay, math.
    final Rect startBounds = new Rect();
    final Rect finalBounds = new Rect();
    final Point globalOffset = new Point();
    // The start bounds are the global visible rectangle of the thumbnail, and the
    // final bounds are the global visible rectangle of the container view. Also
    // set the container view's offset as the origin for the bounds, since that's
    // the origin for the positioning animation properties (X, Y).
    thumbView.getGlobalVisibleRect(startBounds);
    MainView.getGlobalVisibleRect(finalBounds, globalOffset);
    startBounds.offset(-globalOffset.x, -globalOffset.y);
    finalBounds.offset(-globalOffset.x, -globalOffset.y);
    // Adjust the start bounds to be the same aspect ratio as the final bounds using the
    // "center crop" technique. This prevents undesirable stretching during the animation.
    // Also calculate the start scaling factor (the end scaling factor is always 1.0).
    float startScale;
    if ((float) finalBounds.width() / finalBounds.height()
        > (float) startBounds.width() / startBounds.height()) {

      // Extend start bounds horizontally
      startScale = (float) startBounds.height() / finalBounds.height();
      float startWidth = startScale * finalBounds.width();
      float deltaWidth = (startWidth - startBounds.width()) / 2;
      startBounds.left -= deltaWidth;
      startBounds.right += deltaWidth;
    } else {
      // Extend start bounds vertically
      startScale = (float) startBounds.width() / finalBounds.width();
      float startHeight = startScale * finalBounds.height();
      float deltaHeight = (startHeight - startBounds.height()) / 2;
      startBounds.top -= deltaHeight;
      startBounds.bottom += deltaHeight;
    }

    // Hide the thumbnail and show the zoomed-in view. When the animation begins,
    // it will position the zoomed-in view in the place of the thumbnail.
    thumbView.setAlpha(0f);
    expandedImageView.setVisibility(View.VISIBLE);

    // Set the pivot point for SCALE_X and SCALE_Y transformations to the top-left corner of
    // the zoomed-in view (the default is the center of the view).
    expandedImageView.setPivotX(0f);
    expandedImageView.setPivotY(0f);

    // Construct and run the parallel animation of the four translation and scale properties
    // (X, Y, SCALE_X, and SCALE_Y).
    AnimatorSet set = new AnimatorSet();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {

      set.play(
              ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left, finalBounds.left))
          .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top, finalBounds.top))
          .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f))
          .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f));
    }

    set.setDuration(mShortAnimationDuration);
    set.setInterpolator(new DecelerateInterpolator());

    set.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
          }

          @Override
          public void onAnimationEnd(Animator animation) {
            mCurrentAnimator = null;
          }

          @Override
          public void onAnimationCancel(Animator animation) {
            mCurrentAnimator = null;
          }
        });
    set.start();
    mCurrentAnimator = set;

    // Upon clicking the zoomed-in image, it should zoom back down to the original bounds
    // and show the thumbnail instead of the expanded image.
    final float startScaleFinal = startScale;
    expandedImageView.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View view) {
            if (mCurrentAnimator != null) {
              mCurrentAnimator.cancel();
            }

            // Animate the four positioning/sizing properties in parallel, back to their
            // original values.
            AnimatorSet set = new AnimatorSet();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
              set.play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left))
                  .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top))
                  .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScaleFinal))
                  .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal));
            }
            set.setDuration(mShortAnimationDuration);
            set.setInterpolator(new DecelerateInterpolator());
            set.addListener(
                new AnimatorListenerAdapter() {
                  @Override
                  public void onAnimationEnd(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    dismiss();
                    mCurrentAnimator = null;
                  }

                  @Override
                  public void onAnimationCancel(Animator animation) {
                    thumbView.setAlpha(1f);
                    expandedImageView.setVisibility(View.GONE);
                    dismiss();
                    mCurrentAnimator = null;
                  }
                });
            set.start();
            mCurrentAnimator = set;
          }
        });
  }
Exemplo n.º 29
0
  public synchronized void place(View v, Point pt, boolean animate) {
    final int i = pt.x;
    final int j = pt.y;
    final float rnd = frand();
    if (v.getTag(TAG_POS) != null) {
      for (final Point oc : getOccupied(v)) {
        mFreeList.add(oc);
        mCells[oc.y * mColumns + oc.x] = null;
      }
    }
    int scale = 1;
    if (rnd < PROB_4X) {
      if (!(i >= mColumns - 3 || j >= mRows - 3)) {
        scale = 4;
      }
    } else if (rnd < PROB_3X) {
      if (!(i >= mColumns - 2 || j >= mRows - 2)) {
        scale = 3;
      }
    } else if (rnd < PROB_2X) {
      if (!(i == mColumns - 1 || j == mRows - 1)) {
        scale = 2;
      }
    }

    v.setTag(TAG_POS, pt);
    v.setTag(TAG_SPAN, scale);

    tmpSet.clear();

    final Point[] occupied = getOccupied(v);
    for (final Point oc : occupied) {
      final View squatter = mCells[oc.y * mColumns + oc.x];
      if (squatter != null) {
        tmpSet.add(squatter);
      }
    }

    for (final View squatter : tmpSet) {
      for (final Point sq : getOccupied(squatter)) {
        mFreeList.add(sq);
        mCells[sq.y * mColumns + sq.x] = null;
      }
      if (squatter != v) {
        squatter.setTag(TAG_POS, null);
        if (animate) {
          squatter
              .animate()
              .withLayer()
              .scaleX(0.5f)
              .scaleY(0.5f)
              .alpha(0)
              .setDuration(DURATION)
              .setInterpolator(new AccelerateInterpolator())
              .setListener(
                  new Animator.AnimatorListener() {
                    public void onAnimationStart(Animator animator) {}

                    public void onAnimationEnd(Animator animator) {
                      removeView(squatter);
                    }

                    public void onAnimationCancel(Animator animator) {}

                    public void onAnimationRepeat(Animator animator) {}
                  })
              .start();
        } else {
          removeView(squatter);
        }
      }
    }

    for (final Point oc : occupied) {
      mCells[oc.y * mColumns + oc.x] = v;
      mFreeList.remove(oc);
    }

    final float rot = (float) irand(0, 4) * 90f;

    if (animate) {
      v.bringToFront();

      AnimatorSet set1 = new AnimatorSet();
      set1.playTogether(
          ObjectAnimator.ofFloat(v, View.SCALE_X, (float) scale),
          ObjectAnimator.ofFloat(v, View.SCALE_Y, (float) scale));
      set1.setInterpolator(new AnticipateOvershootInterpolator());
      set1.setDuration(DURATION);

      AnimatorSet set2 = new AnimatorSet();
      set2.playTogether(
          ObjectAnimator.ofFloat(v, View.ROTATION, rot),
          ObjectAnimator.ofFloat(v, View.X, i * mCellSize + (scale - 1) * mCellSize / 2),
          ObjectAnimator.ofFloat(v, View.Y, j * mCellSize + (scale - 1) * mCellSize / 2));
      set2.setInterpolator(new DecelerateInterpolator());
      set2.setDuration(DURATION);

      set1.addListener(makeHardwareLayerListener(v));

      set1.start();
      set2.start();
    } else {
      v.setX(i * mCellSize + (scale - 1) * mCellSize / 2);
      v.setY(j * mCellSize + (scale - 1) * mCellSize / 2);
      v.setScaleX((float) scale);
      v.setScaleY((float) scale);
      v.setRotation(rot);
    }
  }
 public void setIconAnimationCloseInterpolator(Interpolator closeInterpolator) {
   mCloseAnimatorSet.setInterpolator(closeInterpolator);
 }