示例#1
0
 /**
  * {@inheritDoc}
  *
  * <p>Note that canceling a <code>AnimatorSet</code> also cancels all of the animations that it is
  * responsible for.
  */
 @SuppressWarnings("unchecked")
 @Override
 public void cancel() {
   mTerminated = true;
   if (isStarted()) {
     ArrayList<AnimatorListener> tmpListeners = null;
     if (mListeners != null) {
       tmpListeners = (ArrayList<AnimatorListener>) mListeners.clone();
       for (AnimatorListener listener : tmpListeners) {
         listener.onAnimationCancel(this);
       }
     }
     if (mDelayAnim != null && mDelayAnim.isRunning()) {
       // If we're currently in the startDelay period, just cancel that animator and
       // send out the end event to all listeners
       mDelayAnim.cancel();
     } else if (mSortedNodes.size() > 0) {
       for (Node node : mSortedNodes) {
         node.animation.cancel();
       }
     }
     if (tmpListeners != null) {
       for (AnimatorListener listener : tmpListeners) {
         listener.onAnimationEnd(this);
       }
     }
     mStarted = false;
   }
 }
示例#2
0
 /**
  * Sets up the animation supplied in the {@link AnimatorSet#play(Animator)} call that created
  * this <code>Builder</code> object to play when the given amount of time elapses.
  *
  * @param delay The number of milliseconds that should elapse before the animation starts.
  */
 public Builder after(long delay) {
   // setup dummy ValueAnimator just to run the clock
   ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
   anim.setDuration(delay);
   after(anim);
   return this;
 }
示例#3
0
 /**
  * {@inheritDoc}
  *
  * <p>Note that ending a <code>AnimatorSet</code> also ends all of the animations that it is
  * responsible for.
  */
 @Override
 public void end() {
   mTerminated = true;
   if (isStarted()) {
     if (mSortedNodes.size() != mNodes.size()) {
       // hasn't been started yet - sort the nodes now, then end them
       sortNodes();
       for (Node node : mSortedNodes) {
         if (mSetListener == null) {
           mSetListener = new AnimatorSetListener(this);
         }
         node.animation.addListener(mSetListener);
       }
     }
     if (mDelayAnim != null) {
       mDelayAnim.cancel();
     }
     if (mSortedNodes.size() > 0) {
       for (Node node : mSortedNodes) {
         node.animation.end();
       }
     }
     if (mListeners != null) {
       ArrayList<AnimatorListener> tmpListeners = (ArrayList<AnimatorListener>) mListeners.clone();
       for (AnimatorListener listener : tmpListeners) {
         listener.onAnimationEnd(this);
       }
     }
     mStarted = false;
   }
 }
示例#4
0
 /**
  * This method is called with the elapsed fraction of the animation during every animation frame.
  * This function turns the elapsed fraction into an interpolated fraction and then into an
  * animated value (from the evaluator. The function is called mostly during animation updates, but
  * it is also called when the <code>end()</code> function is called, to set the final value on the
  * property.
  *
  * <p>Overrides of this method must call the superclass to perform the calculation of the animated
  * value.
  *
  * @param fraction The elapsed fraction of the animation.
  */
 @Override
 void animateValue(float fraction) {
   super.animateValue(fraction);
   int numValues = mValues.length;
   for (int i = 0; i < numValues; ++i) {
     mValues[i].setAnimatedValue(mTarget);
   }
 }
示例#5
0
 @Override
 public void start() {
   // See if any of the current active/pending animators need to be canceled
   AnimationHandler handler = sAnimationHandler.get();
   if (handler != null) {
     int numAnims = sAnimations.get().size();
     for (int i = numAnims - 1; i >= 0; i--) {
       if (sAnimations.get().get(i) instanceof ObjectAnimator) {
         ObjectAnimator anim = (ObjectAnimator) sAnimations.get().get(i);
         if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) {
           anim.cancel();
         }
       }
     }
     numAnims = sPendingAnimations.get().size();
     for (int i = numAnims - 1; i >= 0; i--) {
       if (sPendingAnimations.get().get(i) instanceof ObjectAnimator) {
         ObjectAnimator anim = (ObjectAnimator) sPendingAnimations.get().get(i);
         if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) {
           anim.cancel();
         }
       }
     }
     numAnims = sDelayedAnims.get().size();
     for (int i = numAnims - 1; i >= 0; i--) {
       if (sDelayedAnims.get().get(i) instanceof ObjectAnimator) {
         ObjectAnimator anim = (ObjectAnimator) sDelayedAnims.get().get(i);
         if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) {
           anim.cancel();
         }
       }
     }
   }
   if (DBG) {
     Log.d("ObjectAnimator", "Anim target, duration: " + mTarget + ", " + getDuration());
     for (int i = 0; i < mValues.length; ++i) {
       PropertyValuesHolder pvh = mValues[i];
       ArrayList<Keyframe> keyframes = pvh.mKeyframeSet.mKeyframes;
       Log.d(
           "ObjectAnimator",
           "   Values["
               + i
               + "]: "
               + pvh.getPropertyName()
               + ", "
               + keyframes.get(0).getValue()
               + ", "
               + keyframes.get(pvh.mKeyframeSet.mNumKeyframes - 1).getValue());
     }
   }
   super.start();
 }
示例#6
0
 @Override
 public void setObjectValues(Object... values) {
   if (mValues == null || mValues.length == 0) {
     // No values yet - this animator is being constructed piecemeal. Init the values with
     // whatever the current propertyName is
     if (mProperty != null) {
       setValues(PropertyValuesHolder.ofObject(mProperty, (TypeEvaluator) null, values));
     } else {
       setValues(PropertyValuesHolder.ofObject(mPropertyName, (TypeEvaluator) null, values));
     }
   } else {
     super.setObjectValues(values);
   }
 }
示例#7
0
 /**
  * This function is called immediately before processing the first animation frame of an
  * animation. If there is a nonzero <code>startDelay</code>, the function is called after that
  * delay ends. It takes care of the final initialization steps for the animation. This includes
  * setting mEvaluator, if the user has not yet set it up, and the setter/getter methods, if the
  * user did not supply them.
  *
  * <p>Overriders of this method should call the superclass method to cause internal mechanisms to
  * be set up correctly.
  */
 @Override
 void initAnimation() {
   if (!mInitialized) {
     // mValueType may change due to setter/getter setup; do this before calling super.init(),
     // which uses mValueType to set up the default type evaluator.
     if ((mProperty == null)
         && AnimatorProxy.NEEDS_PROXY
         && (mTarget instanceof View)
         && PROXY_PROPERTIES.containsKey(mPropertyName)) {
       setProperty(PROXY_PROPERTIES.get(mPropertyName));
     }
     int numValues = mValues.length;
     for (int i = 0; i < numValues; ++i) {
       mValues[i].setupSetterAndGetter(mTarget);
     }
     super.initAnimation();
   }
 }
    public MyAnimationView(Context context) {
      super(context);

      // Animate background color
      // Note that setting the background color will automatically invalidate the
      // view, so that the animated color, and the bouncing balls, get redisplayed on
      // every frame of the animation.
      ValueAnimator colorAnim = ObjectAnimator.ofInt(this, "backgroundColor", RED, BLUE);
      colorAnim.setDuration(3000);
      colorAnim.setEvaluator(new ArgbEvaluator());
      colorAnim.setRepeatCount(ValueAnimator.INFINITE);
      colorAnim.setRepeatMode(ValueAnimator.REVERSE);
      colorAnim.start();
    }
    @Override
    public boolean onTouchEvent(MotionEvent event) {
      if (event.getAction() != MotionEvent.ACTION_DOWN
          && event.getAction() != MotionEvent.ACTION_MOVE) {
        return false;
      }
      ShapeHolder newBall = addBall(event.getX(), event.getY());

      // Bouncing animation with squash and stretch
      float startY = newBall.getY();
      float endY = getHeight() - 50f;
      float h = (float) getHeight();
      float eventY = event.getY();
      int duration = (int) (500 * ((h - eventY) / h));
      ValueAnimator bounceAnim = ObjectAnimator.ofFloat(newBall, "y", startY, endY);
      bounceAnim.setDuration(duration);
      bounceAnim.setInterpolator(new AccelerateInterpolator());
      ValueAnimator squashAnim1 =
          ObjectAnimator.ofFloat(newBall, "x", newBall.getX(), newBall.getX() - 25f);
      squashAnim1.setDuration(duration / 4);
      squashAnim1.setRepeatCount(1);
      squashAnim1.setRepeatMode(ValueAnimator.REVERSE);
      squashAnim1.setInterpolator(new DecelerateInterpolator());
      ValueAnimator squashAnim2 =
          ObjectAnimator.ofFloat(newBall, "width", newBall.getWidth(), newBall.getWidth() + 50);
      squashAnim2.setDuration(duration / 4);
      squashAnim2.setRepeatCount(1);
      squashAnim2.setRepeatMode(ValueAnimator.REVERSE);
      squashAnim2.setInterpolator(new DecelerateInterpolator());
      ValueAnimator stretchAnim1 = ObjectAnimator.ofFloat(newBall, "y", endY, endY + 25f);
      stretchAnim1.setDuration(duration / 4);
      stretchAnim1.setRepeatCount(1);
      stretchAnim1.setInterpolator(new DecelerateInterpolator());
      stretchAnim1.setRepeatMode(ValueAnimator.REVERSE);
      ValueAnimator stretchAnim2 =
          ObjectAnimator.ofFloat(newBall, "height", newBall.getHeight(), newBall.getHeight() - 25);
      stretchAnim2.setDuration(duration / 4);
      stretchAnim2.setRepeatCount(1);
      stretchAnim2.setInterpolator(new DecelerateInterpolator());
      stretchAnim2.setRepeatMode(ValueAnimator.REVERSE);
      ValueAnimator bounceBackAnim = ObjectAnimator.ofFloat(newBall, "y", endY, startY);
      bounceBackAnim.setDuration(duration);
      bounceBackAnim.setInterpolator(new DecelerateInterpolator());
      // Sequence the down/squash&stretch/up animations
      AnimatorSet bouncer = new AnimatorSet();
      bouncer.play(bounceAnim).before(squashAnim1);
      bouncer.play(squashAnim1).with(squashAnim2);
      bouncer.play(squashAnim1).with(stretchAnim1);
      bouncer.play(squashAnim1).with(stretchAnim2);
      bouncer.play(bounceBackAnim).after(stretchAnim2);

      // Fading animation - remove the ball when the animation is done
      ValueAnimator fadeAnim = ObjectAnimator.ofFloat(newBall, "alpha", 1f, 0f);
      fadeAnim.setDuration(250);
      fadeAnim.addListener(
          new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
              balls.remove(((ObjectAnimator) animation).getTarget());
            }
          });

      // Sequence the two animations to play one after the other
      AnimatorSet animatorSet = new AnimatorSet();
      animatorSet.play(bouncer).before(fadeAnim);

      // Start the animation
      animatorSet.start();

      return true;
    }
示例#10
0
文件: H.java 项目: KilFer/miband
 public final void handleMessage(Message paramMessage)
 {
   ArrayList localArrayList1 = (ArrayList)ValueAnimator.b().get();
   ArrayList localArrayList2 = (ArrayList)ValueAnimator.c().get();
   ArrayList localArrayList5;
   int i;
   switch (paramMessage.what)
   {
   default:
     return;
   case 0:
     localArrayList5 = (ArrayList)ValueAnimator.d().get();
     if ((localArrayList1.size() > 0) || (localArrayList2.size() > 0))
     {
       i = 0;
       label77: if (localArrayList5.size() > 0)
         break;
     }
     break;
   case 1:
   }
   while (true)
   {
     long l = AnimationUtils.currentAnimationTimeMillis();
     ArrayList localArrayList3 = (ArrayList)ValueAnimator.e().get();
     ArrayList localArrayList4 = (ArrayList)ValueAnimator.f().get();
     int j = localArrayList2.size();
     int k = 0;
     label121: int i4;
     label143: int i1;
     int i2;
     if (k >= j)
     {
       int m = localArrayList3.size();
       if (m > 0)
       {
         i4 = 0;
         if (i4 < m)
           break label351;
         localArrayList3.clear();
       }
       int n = localArrayList1.size();
       i1 = 0;
       i2 = n;
       label168: if (i1 < i2)
         break label387;
       if (localArrayList4.size() <= 0);
     }
     for (int i3 = 0; ; i3++)
     {
       if (i3 >= localArrayList4.size())
       {
         localArrayList4.clear();
         if ((i == 0) || ((localArrayList1.isEmpty()) && (localArrayList2.isEmpty())))
           break;
         sendEmptyMessageDelayed(1, Math.max(0L, ValueAnimator.g() - (AnimationUtils.currentAnimationTimeMillis() - l)));
         return;
         ArrayList localArrayList6 = (ArrayList)localArrayList5.clone();
         localArrayList5.clear();
         int i5 = localArrayList6.size();
         int i6 = 0;
         if (i6 >= i5)
           break label77;
         ValueAnimator localValueAnimator4 = (ValueAnimator)localArrayList6.get(i6);
         if (ValueAnimator.a(localValueAnimator4) == 0L)
           ValueAnimator.b(localValueAnimator4);
         while (true)
         {
           i6++;
           break;
           localArrayList2.add(localValueAnimator4);
         }
         ValueAnimator localValueAnimator1 = (ValueAnimator)localArrayList2.get(k);
         if (ValueAnimator.a(localValueAnimator1, l))
           localArrayList3.add(localValueAnimator1);
         k++;
         break label121;
         label351: ValueAnimator localValueAnimator3 = (ValueAnimator)localArrayList3.get(i4);
         ValueAnimator.b(localValueAnimator3);
         ValueAnimator.a(localValueAnimator3, true);
         localArrayList2.remove(localValueAnimator3);
         i4++;
         break label143;
         label387: ValueAnimator localValueAnimator2 = (ValueAnimator)localArrayList1.get(i1);
         if (localValueAnimator2.a(l))
           localArrayList4.add(localValueAnimator2);
         if (localArrayList1.size() == i2)
         {
           i1++;
           break label168;
         }
         i2--;
         localArrayList4.remove(localValueAnimator2);
         break label168;
       }
       ValueAnimator.c((ValueAnimator)localArrayList4.get(i3));
     }
     i = 1;
     break label77;
     i = 1;
   }
 }
示例#11
0
  private void startAnimation() {

    ValueAnimator mAnimatorAlpha = ValueAnimator.ofInt(255, 0);
    mAnimatorAlpha.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            int a = (int) animation.getAnimatedValue();
            Log.e("123132:", "" + a);
            mNewPaint.setAlpha((int) animation.getAnimatedValue());
            invalidate();
          }
        });
    mAnimatorAlpha.setDuration(2000);
    mAnimatorAlpha.start();

    //        Point startPoint = new Point(RADIUS, RADIUS);
    //        Point endPoint = new Point(getWidth() - RADIUS, getHeight() - RADIUS);
    //        ValueAnimator anim1 = ValueAnimator.ofObject(new PointEvaluator(), startPoint,
    // endPoint);
    //
    //        anim = ValueAnimator.ofObject(new ColorEvaluator(),
    //                "#FF0000", "#0000FF" );
    //        anim2 = ValueAnimator.ofObject( new ColorEvaluator(),
    //                "#0000FF", "#FF0000");
    //        AnimatorSet animSet = new AnimatorSet();
    //        animSet.play(anim1).with(anim2);
    //        animSet.setDuration(5000);
    //        anim1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    //            @Override
    //            public void onAnimationUpdate(ValueAnimator animation) {
    //                currentPoint = (Point) animation.getAnimatedValue();
    //                invalidate();
    //            }
    //        });
    //
    //        anim2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    //            @Override
    //            public void onAnimationUpdate(ValueAnimator animation) {
    //                mNewPaint.setColor(Color.parseColor((String) animation.getAnimatedValue()));
    //                invalidate();
    //            }
    //        });
    //        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    //            @Override
    //            public void onAnimationUpdate(ValueAnimator animation) {
    //                mNewPaint.setColor(Color.parseColor((String) animation.getAnimatedValue()));
    //                invalidate();
    //            }
    //        });
    //
    //        anim.addListener(new Animator.AnimatorListener() {
    //            @Override
    //            public void onAnimationStart(Animator animation) {
    //
    //            }
    //
    //            @Override
    //            public void onAnimationEnd(Animator animation) {
    //                    isTrue = true;
    //            }
    //
    //            @Override
    //            public void onAnimationCancel(Animator animation) {
    //
    //            }
    //
    //            @Override
    //            public void onAnimationRepeat(Animator animation) {
    //
    //            }
    //        });
    //        anim2.addListener(new Animator.AnimatorListener() {
    //            @Override
    //            public void onAnimationStart(Animator animation) {
    //
    //            }
    //
    //            @Override
    //            public void onAnimationEnd(Animator animation) {
    //                anim.setDuration(5000);
    //                    anim.start();
    //            }
    //
    //            @Override
    //            public void onAnimationCancel(Animator animation) {
    //
    //            }
    //
    //            @Override
    //            public void onAnimationRepeat(Animator animation) {
    //
    //            }
    //        });
    //
    //        anim2.start();
  }
示例#12
0
 /**
  * Sets the length of the animation. The default duration is 300 milliseconds.
  *
  * @param duration The length of the animation, in milliseconds.
  * @return ObjectAnimator The object called with setDuration(). This return value makes it easier
  *     to compose statements together that construct and then set the duration, as in <code>
  *     ObjectAnimator.ofInt(target, propertyName, 0, 10).setDuration(500).start()</code>.
  */
 @Override
 public ObjectAnimator setDuration(long duration) {
   super.setDuration(duration);
   return this;
 }
示例#13
0
  /**
   * {@inheritDoc}
   *
   * <p>Starting this <code>AnimatorSet</code> will, in turn, start the animations for which it is
   * responsible. The details of when exactly those animations are started depends on the dependency
   * relationships that have been set up between the animations.
   */
  @SuppressWarnings("unchecked")
  @Override
  public void start() {
    mTerminated = false;
    mStarted = true;

    // First, sort the nodes (if necessary). This will ensure that sortedNodes
    // contains the animation nodes in the correct order.
    sortNodes();

    int numSortedNodes = mSortedNodes.size();
    for (int i = 0; i < numSortedNodes; ++i) {
      Node node = mSortedNodes.get(i);
      // First, clear out the old listeners
      ArrayList<AnimatorListener> oldListeners = node.animation.getListeners();
      if (oldListeners != null && oldListeners.size() > 0) {
        final ArrayList<AnimatorListener> clonedListeners =
            new ArrayList<AnimatorListener>(oldListeners);

        for (AnimatorListener listener : clonedListeners) {
          if (listener instanceof DependencyListener || listener instanceof AnimatorSetListener) {
            node.animation.removeListener(listener);
          }
        }
      }
    }

    // nodesToStart holds the list of nodes to be started immediately. We don't want to
    // start the animations in the loop directly because we first need to set up
    // dependencies on all of the nodes. For example, we don't want to start an animation
    // when some other animation also wants to start when the first animation begins.
    final ArrayList<Node> nodesToStart = new ArrayList<Node>();
    for (int i = 0; i < numSortedNodes; ++i) {
      Node node = mSortedNodes.get(i);
      if (mSetListener == null) {
        mSetListener = new AnimatorSetListener(this);
      }
      if (node.dependencies == null || node.dependencies.size() == 0) {
        nodesToStart.add(node);
      } else {
        int numDependencies = node.dependencies.size();
        for (int j = 0; j < numDependencies; ++j) {
          Dependency dependency = node.dependencies.get(j);
          dependency.node.animation.addListener(
              new DependencyListener(this, node, dependency.rule));
        }
        node.tmpDependencies = (ArrayList<Dependency>) node.dependencies.clone();
      }
      node.animation.addListener(mSetListener);
    }
    // Now that all dependencies are set up, start the animations that should be started.
    if (mStartDelay <= 0) {
      for (Node node : nodesToStart) {
        node.animation.start();
        mPlayingSet.add(node.animation);
      }
    } else {
      mDelayAnim = ValueAnimator.ofFloat(0f, 1f);
      mDelayAnim.setDuration(mStartDelay);
      mDelayAnim.addListener(
          new AnimatorListenerAdapter() {
            boolean canceled = false;

            @Override
            public void onAnimationCancel(Animator anim) {
              canceled = true;
            }

            @Override
            public void onAnimationEnd(Animator anim) {
              if (!canceled) {
                int numNodes = nodesToStart.size();
                for (int i = 0; i < numNodes; ++i) {
                  Node node = nodesToStart.get(i);
                  node.animation.start();
                  mPlayingSet.add(node.animation);
                }
              }
            }
          });
      mDelayAnim.start();
    }
    if (mListeners != null) {
      ArrayList<AnimatorListener> tmpListeners = (ArrayList<AnimatorListener>) mListeners.clone();
      int numListeners = tmpListeners.size();
      for (int i = 0; i < numListeners; ++i) {
        tmpListeners.get(i).onAnimationStart(this);
      }
    }
    if (mNodes.size() == 0 && mStartDelay == 0) {
      // Handle unusual case where empty AnimatorSet is started - should send out
      // end event immediately since the event will not be sent out at all otherwise
      mStarted = false;
      if (mListeners != null) {
        ArrayList<AnimatorListener> tmpListeners = (ArrayList<AnimatorListener>) mListeners.clone();
        int numListeners = tmpListeners.size();
        for (int i = 0; i < numListeners; ++i) {
          tmpListeners.get(i).onAnimationEnd(this);
        }
      }
    }
  }