/**
   * Back alphabet.
   *
   * @param isSelected 是否是选中的字母周围弹出的字母
   */
  protected void backAlphabet(boolean isSelected) {
    if (mAlphabetList.size() < POP_LIMIT_NUM) {
      return;
    }

    int halfMoveCount = (mMoveCount + 1) / 2;
    for (int i = 0; i < mAlphabetList.size(); i++) {
      ValueAnimator vaAnim = mAnimMap.get(i);
      if (vaAnim != null) {
        vaAnim.cancel();
      }
      // Back around the selected alphabet place.
      if (isSelected
          && i > mCurrentSelection - halfMoveCount
          && i < mCurrentSelection + halfMoveCount) {
        View view = getChildAt(i);

        float tX = view.getTranslationX();
        if (tX < 0f || tX > 0f) {
          doBackAnim(view);
        }
        // Back the unselected alphabet place.
      } else if (i <= mCurrentSelection - halfMoveCount || i >= mCurrentSelection + halfMoveCount) {
        View view = getChildAt(i);

        float tX = view.getTranslationX();
        if (tX < 0f || tX > 0f) {
          doBackAnim(view);
        }
      }
    }
  }
  /** Pop alphabet */
  protected void popAlphabet() {
    if (mAlphabetList.size() < POP_LIMIT_NUM) {
      return;
    }
    backAlphabet(false); // first, back alphabet, and pop alphabet

    isPoped = true;
    changeTextColor(mCurrentSelection, false);
    isShowSelected = false;
    invalidate();

    int position;
    int halfMoveCount = (mMoveCount + 1) / 2;
    for (int i = 0; i < mMoveCount; i++) {
      position = mCurrentSelection - halfMoveCount + 1 + i;
      if (position >= 0 && position < getChildCount()) {
        View view = getChildAt(position);
        ValueAnimator tmpAnimator =
            ObjectAnimator.ofFloat(
                view,
                "translationX",
                view.getTranslationX(),
                -mMaxOffset * (float) Math.sin((i + 1) * Math.PI / (mMoveCount + 1)));
        // Math.sin((i + 1) * Math.PI / (mMoveCount + 2))区间是[0,1],如移动的字母数(mMoveCount=3),
        // 那么取sin曲线上5个点,1和5点无动画,只创建中间3点动画,值是0.7071、1.0、0.7071。
        tmpAnimator.setDuration(mPopAnimTime);
        tmpAnimator.setRepeatCount(0);
        tmpAnimator.setInterpolator(mInterpolator);
        tmpAnimator.start();
        mAnimMap.put(position, tmpAnimator);
      }
    }
  }
  private void startAnimation(final boolean isLeft, final boolean isOpen, boolean staticDuration) {
    mToOpen = isOpen;
    int total;
    if (isLeft) {
      mTargetView = mLeftDrawer;
      mStartLeft = mLeftDrawer.getLeft();
      total = mLeftDrawer.getWidth();
      mEndLeft = mToOpen ? 0 : -total;
    } else {
      mTargetView = mRightDrawer;
      mStartLeft = mRightDrawer.getLeft();
      total = mRightDrawer.getWidth();
      mEndLeft = mToOpen ? getWidth() - total : getWidth();
    }

    if (mStartLeft == mEndLeft) {
      // No need to animate
      updateDrawerSlide(mTargetView, mToOpen ? 1.0f : 0.0f);
      updateDrawerState(mTargetView, mToOpen ? STATE_OPEN : STATE_CLOSED);
      if (mToOpen) dispatchOnDrawerOpened(mTargetView);
      else dispatchOnDrawerClosed(mTargetView);
      return;
    }

    mAnimator.setDuration(
        staticDuration ? ANIMATE_TIME : ANIMATE_TIME * Math.abs(mStartLeft - mEndLeft) / total);

    mAnimator.start();
  }
 private void doBackAnim(final View view) {
   ValueAnimator tmpAnimator =
       ObjectAnimator.ofFloat(view, "translationX", view.getTranslationX(), 0);
   tmpAnimator.setDuration(mBackAnimTime);
   tmpAnimator.setRepeatCount(0);
   tmpAnimator.start();
 }
  private void performDismiss() {
    // Animate the dismissed view to zero-height and then fire the dismiss callback.
    // This triggers layout on each animation frame; in the future we may want to do something
    // smarter and more performant.

    final ViewGroup.LayoutParams lp = mView.getLayoutParams();
    final int originalHeight = mView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            mCallbacks.onDismiss(mView, mToken);
            // Reset view presentation
            mView.setAlpha(1f);
            mView.setTranslationX(0);
            lp.height = originalHeight;
            mView.setLayoutParams(lp);
          }
        });

    animator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            mView.setLayoutParams(lp);
          }
        });

    animator.start();
  }
 private void setCurrentPlayTimeByStateAndPlay(long[] tab, State mState) {
   switch (mState) {
     case ANIMATING_LINE_TO_DOT:
       mArrowToLineAnimatorSet.start();
       for (int i = 0; i < mArrowToLineAnimatorSet.getChildAnimations().size(); i++) {
         ((ValueAnimator) mArrowToLineAnimatorSet.getChildAnimations().get(i))
             .setCurrentPlayTime(tab[i]);
       }
       break;
     case ANIMATING_PROGRESS:
       mProgressAnimationSet.start();
       for (int i = 0; i < mProgressAnimationSet.getChildAnimations().size(); i++) {
         ((ValueAnimator) mProgressAnimationSet.getChildAnimations().get(i))
             .setCurrentPlayTime(tab[i]);
       }
       break;
     case ANIMATING_ERROR:
       mErrorAnimation.start();
       mErrorAnimation.setCurrentPlayTime(tab[0]);
       break;
     case ANIMATING_SUCCESS:
       mSuccessAnimation.start();
       mSuccessAnimation.setCurrentPlayTime(tab[0]);
       break;
   }
 }
  public void collapse(final View v) {

    int finalHeight = v.getHeight();

    ValueAnimator mAnimator = slideAnimator(finalHeight, 0, v);

    mAnimator.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animator) {}

          @Override
          public void onAnimationEnd(Animator animator) {
            // Height=0, but it set visibility to GONE
            v.setVisibility(View.GONE);
          }

          @Override
          public void onAnimationCancel(Animator animator) {}

          @Override
          public void onAnimationRepeat(Animator animator) {}
        });
    mAnimator.start();
  }
Example #8
0
  /**
   * call when you want to animate the highlight in or out - this is NOT dependant on {@link
   * #setChecked(boolean)} above because on scroll, among other layout calls, would trigger
   * setChecked many, many times
   *
   * @param checked
   */
  public void animateHighlight(boolean checked) {
    if (mHighlightAnimator != null && mHighlightAnimator.isRunning()) {
      mHighlightAnimator.cancel();
      mHighlightAnimator.removeAllUpdateListeners();
      mHighlightAnimator.removeAllListeners();
    }

    if (checked) {
      mHighlightAnimator = ValueAnimator.ofFloat(0, mMaxWidth);
    } else {
      mHighlightAnimator = ValueAnimator.ofFloat(mMaxWidth, 0);
    }

    mHighlightAnimator.setDuration(250);
    mHighlightAnimator.addListener(mHighlightAnimatorListener);
    mHighlightAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            mPinkPaint.setStrokeWidth((float) animation.getAnimatedValue());
            postInvalidate();
          }
        });
    mHighlightAnimator.start();
  }
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   switch (event.getAction()) {
     case MotionEvent.ACTION_UP:
       {
         if (mStatus.equals(INIT)) {
           startAnimation();
         } else {
           mStatus = INIT;
           rippleAnimator.cancel();
           rippleAlphaAnimator.cancel();
           linePosXAnim.cancel();
           sweepAngAnim.cancel();
           tickRightEndAnim.cancel();
           tickRightStartAnim.cancel();
           tickLeftEndAnim.cancel();
           tickLeftStartAnim.cancel();
           btnBgColorAnim.cancel();
           tickColorAnim.cancel();
           startAnimation();
         }
         break;
       }
   }
   super.onTouchEvent(event);
   return true;
 }
Example #10
0
 private void showCheck() {
   if (isAnim) {
     return;
   }
   isAnim = true;
   ValueAnimator va = ValueAnimator.ofFloat(0, 1).setDuration(animDurtion);
   va.setInterpolator(new LinearInterpolator());
   va.start();
   va.addUpdateListener(
       new ValueAnimator.AnimatorUpdateListener() {
         @Override
         public void onAnimationUpdate(ValueAnimator animation) {
           float value = (float) animation.getAnimatedValue(); // 0f ~ 1f
           radius = (int) (value * height * 0.37f + height * 0.125f);
           if (value >= 1) {
             isChecked = true;
             isAnim = false;
             if (listener != null) {
               listener.onCheckedChanged(AnimatedCheckBox.this, true);
             }
             showCorrect();
           }
           invalidate();
         }
       });
 }
  private void performDismiss(
      final View dismissView, final int dismissPosition, final int direction) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.

    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalHeight = dismissView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(createAnimatorListener(originalHeight));

    animator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
          }
        });

    mPendingDismisses.add(new PendingDismissData(dismissPosition, direction, dismissView));
    animator.start();
  }
 public void setShown(boolean shown, boolean animate) {
   synchronized (mWindowManagerService.mWindowMap) {
     if (mShown == shown) {
       return;
     }
     mShown = shown;
     if (animate) {
       if (mShowHideFrameAnimator.isRunning()) {
         mShowHideFrameAnimator.reverse();
       } else {
         if (shown) {
           mShowHideFrameAnimator.start();
         } else {
           mShowHideFrameAnimator.reverse();
         }
       }
     } else {
       mShowHideFrameAnimator.cancel();
       if (shown) {
         setAlpha(MAX_ALPHA);
       } else {
         setAlpha(MIN_ALPHA);
       }
     }
     if (DEBUG_VIEWPORT_WINDOW) {
       Slog.i(LOG_TAG, "ViewportWindow shown: " + mShown);
     }
   }
 }
Example #13
0
  @Override
  public void onAnimationUpdate(ValueAnimator animation) {
    int va = (int) animation.getAnimatedValue();
    if (playing) {
      s = va;
      if (s <= 100) {
        temp1 = (y1 + y2) / 2 + (y1 - y2) / 2 * s / 100;
        temp2 = (y1 + y2) / 2 - (y1 - y2) / 2 * s / 100;
      } else if (s > 900) {
        temp1 = y1 + (y2 - y1) / 2 * (s - 900) / 100;
        temp2 = y2 + (y1 - y2) / 2 * (s - 900) / 100;
      }
      if (va == 1000) {
        playing = false;
        v.cancel();
        if (h != null) h.sendEmptyMessage(0);
      }

    } else {
      s = 0;
      temp1 = y1 + (y2 - y1) / 2 * (va) / 100;
      temp2 = y2 + (y1 - y2) / 2 * (va) / 100;
    }
    invalidate();
  }
Example #14
0
 public void start(int a) {
   v = ValueAnimator.ofInt(0, 1000);
   v.setDuration(a);
   v.addUpdateListener(this);
   playing = true;
   v.start();
 }
 private void cancelAnimation() {
   if (mAnimator.isRunning()) {
     mOpenTask = null;
     mCancelAnimation = true;
     mAnimator.cancel();
   }
 }
 private long[] getCurrentPlayTimeByState(State mState) {
   long[] tab = new long[3];
   switch (mState) {
     case ANIMATING_LINE_TO_DOT:
       for (int i = 0; i < mArrowToLineAnimatorSet.getChildAnimations().size(); i++) {
         tab[i] =
             ((ValueAnimator) mArrowToLineAnimatorSet.getChildAnimations().get(i))
                 .getCurrentPlayTime();
       }
       mArrowToLineAnimatorSet.cancel();
       break;
     case ANIMATING_PROGRESS:
       for (int i = 0; i < mProgressAnimationSet.getChildAnimations().size(); i++) {
         tab[i] =
             ((ValueAnimator) mProgressAnimationSet.getChildAnimations().get(i))
                 .getCurrentPlayTime();
       }
       mProgressAnimationSet.cancel();
       break;
     case ANIMATING_ERROR:
       tab[0] = mErrorAnimation.getCurrentPlayTime();
       mErrorAnimation.cancel();
       break;
     case ANIMATING_SUCCESS:
       tab[0] = mSuccessAnimation.getCurrentPlayTime();
       mSuccessAnimation.cancel();
       break;
   }
   return tab;
 }
Example #17
0
  private void animateOut() {
    ValueAnimator animWidth = ValueAnimator.ofInt(zoomableImageView.getMeasuredWidth(), rect.right);
    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.start();

    ValueAnimator animHeight =
        ValueAnimator.ofInt(zoomableImageView.getMeasuredHeight(), rect.bottom);
    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.start();
    if (statusBarHeightCorrection > 0) {
      zoomableImageView.animate().y(-statusBarHeightCorrection).setDuration(300).start();
    }
    zoomableImageView.animate().alpha(0.0f).setDuration(500).start();
  }
Example #18
0
  /**
   * Set the thumb to be in the normal/un-pressed state and calls invalidate() to redraw the canvas
   * to reflect the updated state.
   *
   * @param thumb the thumb to release
   */
  private void releasePin(final PinView thumb) {

    final float nearestTickX = mBar.getNearestTickCoordinate(thumb);
    thumb.setX(nearestTickX);
    int tickIndex = mBar.getNearestTickIndex(thumb);
    thumb.setXValue(getPinValue(tickIndex));

    if (mArePinsTemporary) {
      ValueAnimator animator = ValueAnimator.ofFloat(mExpandedPinRadius, 0);
      animator.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
              mThumbRadiusDP = (Float) (animation.getAnimatedValue());
              thumb.setSize(
                  mThumbRadiusDP, mPinPadding - (mPinPadding * animation.getAnimatedFraction()));
              invalidate();
            }
          });
      animator.start();
    } else {
      invalidate();
    }

    thumb.release();
  }
Example #19
0
  private AnimatorSet startAniMoveRightToCenter(View rightDot) {
    int dotDiameter = (int) getResources().getDimension(R.dimen.loading_dot_size);
    int dotPadding = (int) getResources().getDimension(R.dimen.loading_dot_padding);
    AnimatorSet moveRightToCentral = new AnimatorSet();
    ObjectAnimator rightDotToCentral =
        ObjectAnimator.ofFloat(rightDot, "translationX", 0, -dotPadding - dotDiameter);

    rightDotColorChange =
        ValueAnimator.ofObject(
            new ArgbEvaluator(),
            getResources().getColor(R.color.dot_normal),
            getResources().getColor(R.color.dot_active));
    final GradientDrawable rightDotBg = (GradientDrawable) rightDot.getBackground();
    rightDotColorChange.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(final ValueAnimator animator) {
            rightDotBg.setColor((Integer) animator.getAnimatedValue());
          }
        });
    rightDotColorChange.setDuration(aniDuration);
    rightDotColorChange.addListener(this);
    moveRightToCentral.play(rightDotColorChange).with(rightDotToCentral);
    return moveRightToCentral;
  }
  @Override
  protected void runAnimators() {
    reflectSetupStartEndListeners();
    animMap.clear();
    for (int i = 0, count = getTransitionCount(); i < count; i++) {
      Transition transition = getTransitionAt(i);
      ArrayList<ValueAnimator> valueAnimators = new ArrayList<>();
      for (Animator animator : AnimatorUtils.collectAnimators(transition)) {
        valueAnimators.addAll(AnimatorUtils.collectValueAnimators(animator));
      }

      // insure animator's duration, startDelay, Interpolator same as this transition
      long duration = (long) (getDuration() / AnimatorUtils.getAnimatorDurationScale());
      long startDelay = getStartDelay();
      TimeInterpolator interpolator = getInterpolator();
      for (ValueAnimator animator : valueAnimators) {
        if (duration >= 0) animator.setDuration(duration);
        if (startDelay >= 0) animator.setStartDelay(startDelay + animator.getStartDelay());
        if (interpolator != null) animator.setInterpolator(interpolator);
      }

      animMap.put(transition, valueAnimators);
      // you can change transition's duration, startDelay and Interpolator at here
      if (playControl != null) playControl.onPreRunAnimator(transition, valueAnimators);
    }
  }
 public void setCurrentPlayTime(long playTime) {
   for (ValueAnimator valueAnimator : getAllAnimator()) {
     playTime -= valueAnimator.getStartDelay();
     if (playTime < 0) playTime = 0;
     valueAnimator.setCurrentPlayTime(playTime);
   }
 }
 private void createAnimation(int... colors) {
   if (colorAnim == null) {
     colorAnim = ObjectAnimator.ofInt(this, "backgroundColor", colors);
     colorAnim.setEvaluator(new ArgbEvaluator());
     colorAnim.setDuration(DURATION);
     colorAnim.addUpdateListener(this);
   }
 }
 public void setCurrentFraction(float fraction) {
   if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
     for (ValueAnimator valueAnimator : getAllAnimator()) {
       valueAnimator.setCurrentFraction(fraction);
     }
   } else {
     setCurrentPlayTime((long) (fraction * getDuration()));
   }
 }
Example #24
0
 /*package*/ void teardown() {
   if (jumpAnimator != null) {
     jumpAnimator.cancel();
     jumpAnimator.removeAllListeners();
   }
   if (textView.get() != null) {
     textView.clear();
   }
 }
  static float getAnimatedFraction(ValueAnimator animator) {
    float fraction =
        animator.getDuration() > 0
            ? ((float) animator.getCurrentPlayTime()) / animator.getDuration()
            : 0f;

    fraction = min(fraction, 1f);
    fraction = animator.getInterpolator().getInterpolation(fraction);
    return fraction;
  }
  /** 圆周运动 */
  public void circleRun(View view) {
    ValueAnimator animator = new ValueAnimator();
    animator.setDuration(10000);
    animator.setTarget(mCircleBall);
    animator.setObjectValues(new PointF(mCircleBall.getX(), mCircleBall.getY()));
    animator.setInterpolator(new LinearInterpolator());

    animator.setEvaluator(
        new TypeEvaluator<PointF>() {
          @Override
          public PointF evaluate(float fraction, PointF startValue, PointF endValue) {
            /** 设置圆的半径r为200px 圆点坐标为(x1,y1) 圆周上的点坐标的公式为 x = x1 + r * cos(wt) y = y1 + r * sin(wt) */
            PointF point = new PointF();
            point.x =
                (float) (mScreenWidth / 2 + 200 * Math.cos(Math.toRadians(360 * fraction - 90)));
            point.y = (float) (200 + 200 * Math.sin(Math.toRadians(360 * fraction - 90)));
            return point;
          }
        });
    //        //设置重复模式,RESTART为结束后重新开始,REVERSE为按原来的轨迹逆向返回
    // animator.setRepeatMode(Animation.RESTART);
    // 设置重复次数,INFINITE为无限
    animator.setRepeatCount(0);
    animator.start();
    animator.addUpdateListener(
        new AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            PointF point = (PointF) animation.getAnimatedValue();
            mCircleBall.setX(point.x);
            mCircleBall.setY(point.y);
          }
        });
  }
Example #27
0
  private void peak(boolean next, boolean once) {
    final float baseFlipDistance = mCurrentPageIndex * FLIP_DISTANCE_PER_PAGE;
    if (next) {
      mPeakAnim =
          ValueAnimator.ofFloat(baseFlipDistance, baseFlipDistance + FLIP_DISTANCE_PER_PAGE / 4);
    } else {
      mPeakAnim =
          ValueAnimator.ofFloat(baseFlipDistance, baseFlipDistance - FLIP_DISTANCE_PER_PAGE / 4);
    }
    mPeakAnim.setInterpolator(mPeakInterpolator);
    mPeakAnim.addUpdateListener(
        new AnimatorUpdateListener() {

          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            setFlipDistance((Float) animation.getAnimatedValue());
          }
        });
    mPeakAnim.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            endPeak();
          }
        });
    mPeakAnim.setDuration(PEAK_ANIM_DURATION);
    mPeakAnim.setRepeatMode(ValueAnimator.REVERSE);
    mPeakAnim.setRepeatCount(once ? 1 : ValueAnimator.INFINITE);
    mPeakAnim.start();
  }
 public void setQsbSearchBar(View qsb) {
   mQSBSearchBar = qsb;
   if (mQSBSearchBar != null) {
     mHideSearchBarAnim = LauncherAnimUtils.ofFloat(mQSBSearchBar, "alpha", 1f, 0f);
     setupAnimation(mHideSearchBarAnim, mQSBSearchBar);
   } else {
     // Create a no-op animation of the search bar is null
     mHideSearchBarAnim = ValueAnimator.ofFloat(0, 0);
     mHideSearchBarAnim.setDuration(TRANSITION_DURATION);
   }
 }
Example #29
0
  public void stopAnim() {
    if (valueAnimator != null) {
      clearAnimation();

      valueAnimator.setRepeatCount(0);
      valueAnimator.cancel();
      valueAnimator.end();
      mAnimatedValue = 0.9f;
      postInvalidate();
    }
  }
 /** 涟漪开启 */
 public void rippleStart() {
   if (valueRadiusAnimator == null) {
     valueRadiusAnimator =
         createValueAnimator(
             COMMON_RADIUS, (int) (mCx + COMMON_RADIUS), mRippleTime, RIPPLE_COUNT, this, this);
   } else {
     if (!valueRadiusAnimator.isRunning()) {
       valueRadiusAnimator.start();
     }
   }
 }