public ObjectAnimator getDisappearAnimator() {
    if (!this.mIsInitialized || !this.mDrawValuesReady) {
      Log.e(TAG, "RadialSelectorView was not ready for animation.");
      return null;
    }

    Keyframe kf0, kf1, kf2;
    float midwayPoint = 0.2f;
    int duration = 500;

    kf0 = Keyframe.ofFloat(0f, 1);
    kf1 = Keyframe.ofFloat(midwayPoint, this.mTransitionMidRadiusMultiplier);
    kf2 = Keyframe.ofFloat(1f, this.mTransitionEndRadiusMultiplier);
    PropertyValuesHolder radiusDisappear =
        PropertyValuesHolder.ofKeyframe("animationRadiusMultiplier", kf0, kf1, kf2);

    kf0 = Keyframe.ofFloat(0f, 1f);
    kf1 = Keyframe.ofFloat(1f, 0f);
    PropertyValuesHolder fadeOut = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1);

    ObjectAnimator disappearAnimator =
        ObjectAnimator.ofPropertyValuesHolder(this, radiusDisappear, fadeOut).setDuration(duration);
    disappearAnimator.addUpdateListener(this.mInvalidateUpdateListener);

    return disappearAnimator;
  }
示例#2
0
 @Override
 public void start(@Nullable IEndListener listener) {
   text.setScalePivot(pivot, pivot);
   PropertyValuesHolder sX = PropertyValuesHolder.ofFloat("scaleX", from, to);
   PropertyValuesHolder sY = PropertyValuesHolder.ofFloat("scaleY", from, to);
   ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(text, sX, sY);
   Utils.addEndListener(this, animator, listener);
   animator.setDuration(duration);
   animator.addUpdateListener(this);
   animator.start();
 }
示例#3
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();
 }
示例#4
0
  /**
   * This method takes some view and the values by which its top and bottom bounds should be changed
   * by. Given these params, an animation which will animate these bound changes is created and
   * returned.
   */
  private Animator getAnimation(final View view, float translateTop, float translateBottom) {

    int top = view.getTop();
    int bottom = view.getBottom();

    int endTop = (int) (top + translateTop);
    int endBottom = (int) (bottom + translateBottom);

    PropertyValuesHolder translationTop = PropertyValuesHolder.ofInt("top", top, endTop);
    PropertyValuesHolder translationBottom =
        PropertyValuesHolder.ofInt("bottom", bottom, endBottom);

    return ObjectAnimator.ofPropertyValuesHolder(view, translationTop, translationBottom);
  }
示例#5
0
 /**
  * Sets the name of the property that will be animated. This name is used to derive a setter
  * function that will be called to set animated values. For example, a property name of <code>foo
  * </code> will result in a call to the function <code>setFoo()</code> on the target object. If
  * either <code>valueFrom</code> or <code>valueTo</code> is null, then a getter function will also
  * be derived and called.
  *
  * <p>For best performance of the mechanism that calls the setter function determined by the name
  * of the property being animated, use <code>float</code> or <code>int</code> typed values, and
  * make the setter function for those properties have a <code>void</code> return value. This will
  * cause the code to take an optimized path for these constrained circumstances. Other property
  * types and return types will work, but will have more overhead in processing the requests due to
  * normal reflection mechanisms.
  *
  * <p>Note that the setter function derived from this property name must take the same parameter
  * type as the <code>valueFrom</code> and <code>valueTo</code> properties, otherwise the call to
  * the setter function will fail.
  *
  * <p>If this ObjectAnimator has been set up to animate several properties together, using more
  * than one PropertyValuesHolder objects, then setting the propertyName simply sets the
  * propertyName in the first of those PropertyValuesHolder objects.
  *
  * @param propertyName The name of the property being animated. Should not be null.
  */
 public void setPropertyName(String propertyName) {
   // mValues could be null if this is being constructed piecemeal. Just record the
   // propertyName to be used later when setValues() is called if so.
   if (mValues != null) {
     PropertyValuesHolder valuesHolder = mValues[0];
     String oldName = valuesHolder.getPropertyName();
     valuesHolder.setPropertyName(propertyName);
     mValuesMap.remove(oldName);
     mValuesMap.put(propertyName, valuesHolder);
   }
   mPropertyName = propertyName;
   // New property/values/target should cause re-initialization prior to starting
   mInitialized = false;
 }
示例#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);
   }
 }
  /** Render the animations for appearing and disappearing. */
  private void renderAnimations() {
    Keyframe kf0, kf1, kf2, kf3;
    float midwayPoint = 0.2f;
    int duration = 500;

    // Set up animator for disappearing.
    kf0 = Keyframe.ofFloat(0f, 1);
    kf1 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier);
    kf2 = Keyframe.ofFloat(1f, mTransitionEndRadiusMultiplier);
    PropertyValuesHolder radiusDisappear =
        PropertyValuesHolder.ofKeyframe("animationRadiusMultiplier", kf0, kf1, kf2);

    kf0 = Keyframe.ofFloat(0f, 1f);
    kf1 = Keyframe.ofFloat(1f, 0f);
    PropertyValuesHolder fadeOut = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1);

    mDisappearAnimator =
        ObjectAnimator.ofPropertyValuesHolder(
                AnimatorProxy.NEEDS_PROXY ? AnimatorProxy.wrap(this) : this,
                radiusDisappear,
                fadeOut)
            .setDuration(duration);
    mDisappearAnimator.addUpdateListener(mInvalidateUpdateListener);

    // Set up animator for reappearing.
    float delayMultiplier = 0.25f;
    float transitionDurationMultiplier = 1f;
    float totalDurationMultiplier = transitionDurationMultiplier + delayMultiplier;
    int totalDuration = (int) (duration * totalDurationMultiplier);
    float delayPoint = (delayMultiplier * duration) / totalDuration;
    midwayPoint = 1 - (midwayPoint * (1 - delayPoint));

    kf0 = Keyframe.ofFloat(0f, mTransitionEndRadiusMultiplier);
    kf1 = Keyframe.ofFloat(delayPoint, mTransitionEndRadiusMultiplier);
    kf2 = Keyframe.ofFloat(midwayPoint, mTransitionMidRadiusMultiplier);
    kf3 = Keyframe.ofFloat(1f, 1);
    PropertyValuesHolder radiusReappear =
        PropertyValuesHolder.ofKeyframe("animationRadiusMultiplier", kf0, kf1, kf2, kf3);

    kf0 = Keyframe.ofFloat(0f, 0f);
    kf1 = Keyframe.ofFloat(delayPoint, 0f);
    kf2 = Keyframe.ofFloat(1f, 1f);
    PropertyValuesHolder fadeIn = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1, kf2);

    mReappearAnimator =
        ObjectAnimator.ofPropertyValuesHolder(
                AnimatorProxy.NEEDS_PROXY ? AnimatorProxy.wrap(this) : this, radiusReappear, fadeIn)
            .setDuration(totalDuration);
    mReappearAnimator.addUpdateListener(mInvalidateUpdateListener);
  }
示例#8
0
  public static ObjectAnimator getPulseAnimator(
      View labelToAnimate, float decreaseRatio, float increaseRatio) {
    Keyframe k0 = Keyframe.ofFloat(0f, 1f);
    Keyframe k1 = Keyframe.ofFloat(0.275f, decreaseRatio);
    Keyframe k2 = Keyframe.ofFloat(0.69f, increaseRatio);
    Keyframe k3 = Keyframe.ofFloat(1f, 1f);

    PropertyValuesHolder scaleX = PropertyValuesHolder.ofKeyframe("scaleX", k0, k1, k2, k3);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofKeyframe("scaleY", k0, k1, k2, k3);
    ObjectAnimator pulseAnimator =
        ObjectAnimator.ofPropertyValuesHolder(labelToAnimate, scaleX, scaleY);
    pulseAnimator.setDuration(PULSE_ANIMATOR_DURATION);

    return pulseAnimator;
  }
示例#9
0
 private boolean hasSameTargetAndProperties(Animator anim) {
   if (anim instanceof ObjectAnimator) {
     PropertyValuesHolder[] theirValues = ((ObjectAnimator) anim).getValues();
     if (((ObjectAnimator) anim).getTarget() == getTarget()
         && mValues.length == theirValues.length) {
       for (int i = 0; i < mValues.length; ++i) {
         PropertyValuesHolder pvhMine = mValues[i];
         PropertyValuesHolder pvhTheirs = theirValues[i];
         if (pvhMine.getPropertyName() == null
             || !pvhMine.getPropertyName().equals(pvhTheirs.getPropertyName())) {
           return false;
         }
       }
       return true;
     }
   }
   return false;
 }
  @Override
  public void createAnimation() {
    /*ObjectAnimator rotationXAnimation=ObjectAnimator.ofFloat(getTarget(), "rotationX",0,180,180,0,0);
    rotationXAnimation.setDuration(3000);

    ObjectAnimator rotationYAnimation=ObjectAnimator.ofFloat(getTarget(), "rotationY",0,0,180,180,0);
    rotationYAnimation.setDuration(3000);

    final AnimatorSet animatorSet=new AnimatorSet();
    animatorSet.playTogether(rotationXAnimation,rotationYAnimation);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationRepeat(Animator animation) {
            super.onAnimationRepeat(animation);
            System.out.println("onAnimationRepeat");
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            System.out.println("onAnimationEnd(");
            animatorSet.start();
        }
    });
    animatorSet.start();*/

    /*PropertyValuesHolder rotation1=PropertyValuesHolder.ofFloat("rotationX",0,180,0,0,0);
    PropertyValuesHolder rotation2=PropertyValuesHolder.ofFloat("rotationX",0,0,180,0,0);
    PropertyValuesHolder rotation3=PropertyValuesHolder.ofFloat("rotationY",0,0,180,0,0);
    PropertyValuesHolder rotation4=PropertyValuesHolder.ofFloat("rotationY",0,0,0,180,0);*/

    PropertyValuesHolder rotation5 = PropertyValuesHolder.ofFloat("rotationX", 0, 180, 180, 0, 0);
    PropertyValuesHolder rotation6 = PropertyValuesHolder.ofFloat("rotationY", 0, 0, 180, 180, 0);
    ObjectAnimator animator =
        ObjectAnimator.ofPropertyValuesHolder(getTarget(), rotation6, rotation5);
    animator.setInterpolator(new LinearInterpolator());
    animator.setRepeatCount(-1);
    animator.setDuration(2500);
    animator.start();
  }
  public ObjectAnimator getReappearAnimator() {
    if (!this.mIsInitialized || !this.mDrawValuesReady) {
      Log.e(TAG, "RadialSelectorView was not ready for animation.");
      return null;
    }

    Keyframe kf0, kf1, kf2, kf3;
    float midwayPoint = 0.2f;
    int duration = 500;

    // The time points are half of what they would normally be, because this animation is
    // staggered against the disappear so they happen seamlessly. The reappear starts
    // halfway into the disappear.
    float delayMultiplier = 0.25f;
    float transitionDurationMultiplier = 1f;
    float totalDurationMultiplier = transitionDurationMultiplier + delayMultiplier;
    int totalDuration = (int) (duration * totalDurationMultiplier);
    float delayPoint = delayMultiplier * duration / totalDuration;
    midwayPoint = 1 - midwayPoint * (1 - delayPoint);

    kf0 = Keyframe.ofFloat(0f, this.mTransitionEndRadiusMultiplier);
    kf1 = Keyframe.ofFloat(delayPoint, this.mTransitionEndRadiusMultiplier);
    kf2 = Keyframe.ofFloat(midwayPoint, this.mTransitionMidRadiusMultiplier);
    kf3 = Keyframe.ofFloat(1f, 1);
    PropertyValuesHolder radiusReappear =
        PropertyValuesHolder.ofKeyframe("animationRadiusMultiplier", kf0, kf1, kf2, kf3);

    kf0 = Keyframe.ofFloat(0f, 0f);
    kf1 = Keyframe.ofFloat(delayPoint, 0f);
    kf2 = Keyframe.ofFloat(1f, 1f);
    PropertyValuesHolder fadeIn = PropertyValuesHolder.ofKeyframe("alpha", kf0, kf1, kf2);

    ObjectAnimator reappearAnimator =
        ObjectAnimator.ofPropertyValuesHolder(this, radiusReappear, fadeIn)
            .setDuration(totalDuration);
    reappearAnimator.addUpdateListener(this.mInvalidateUpdateListener);
    return reappearAnimator;
  }
  /** 更新优惠信息 */
  private void updatePreferential() {
    final Notice preferentialNotice = new Notice();
    List<Notice.Note> notes = new ArrayList<>();
    preferentialNotice.setNotes(notes);
    // 配送信息
    Tags deliveryTag = mRestaurant.getDeliveryTag();

    // 优惠列表
    final List<Tags> preferentialList = mRestaurant.getPerferentials();
    mPreferentialViewGroup = new LinearLayout(getContext());
    mPreferentialViewGroup.setOrientation(LinearLayout.VERTICAL);

    // 设置优惠信息
    if (!ListUtils.isEmpty(preferentialList)) {
      Notice.Note note = new Notice.Note();
      notes.add(note);
      note.title = "优惠信息";
      note.items = new ArrayList<>();

      for (Tags tag : preferentialList) {
        Notice.NoteItem item = new Notice.NoteItem();
        item.name = tag.getName();
        item.icon = tag.getIcon();
        note.items.add(item);
      }
      Tags tags = ListUtils.getItem(preferentialList, 0);
      if (tags != null) {
        final View item = View.inflate(getContext(), R.layout.view_dish_preferential, null);
        mPreferentialViewGroup.addView(item);
        final ImageView icon = (ImageView) item.findViewById(R.id.app_dish_preferential_icon);
        final TextView name = (TextView) item.findViewById(R.id.app_dish_preferential_name);
        name.setText(tags.getName());
        ImageFetcher.asInstance()
            .load(tags.getIcon(), icon, R.drawable.app_bt_address_icon_default);
        if (deliveryTag != null) {
          preferentialList.add(deliveryTag);
        }
        if (preferentialList.size() > 1) {
          mLoopTime = 0;
          final PropertyValuesHolder rotationTo =
              PropertyValuesHolder.ofFloat("rotationX", 0f, 90f);
          final PropertyValuesHolder rotationBack =
              PropertyValuesHolder.ofFloat("rotationX", 90f, 0f);
          ObjectAnimator rotationToAnimator =
              ObjectAnimator.ofPropertyValuesHolder(name, rotationTo).setDuration(300);
          ObjectAnimator rotationBackAnimator =
              ObjectAnimator.ofPropertyValuesHolder(name, rotationBack).setDuration(300);
          mLoopAnimator = new AnimatorSet();
          mLoopAnimator.playSequentially(rotationToAnimator, rotationBackAnimator);
          rotationToAnimator.addUpdateListener(
              new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                  float rotationX = (float) valueAnimator.getAnimatedValue();
                  if (Float.compare(rotationX, 90) == 0) {
                    Tags current = preferentialList.get(mLoopTime++ % preferentialList.size());
                    name.setText(current.getName());
                    ImageFetcher.asInstance().load(current.getIcon(), icon);
                  }
                }
              });
        }
      }
    }

    // 设置配送信息
    if (deliveryTag != null) {
      Notice.Note note = new Notice.Note();
      notes.add(note);
      note.title = "配送信息";
      note.items = new ArrayList<>();
      Notice.NoteItem noteItem = new Notice.NoteItem();
      noteItem.name = deliveryTag.getName();
      noteItem.icon = deliveryTag.getIcon();
      note.items.add(noteItem);

      //            View item = View.inflate(getContext(), R.layout.view_dish_preferential, null);
      //            mPreferentialViewGroup.addView(item);
      //            final ImageView icon = (ImageView)
      // item.findViewById(R.id.app_dish_preferential_icon);
      //            final TextView name = (TextView)
      // item.findViewById(R.id.app_dish_preferential_name);
      //            name.setText(deliveryTag.getName());
      //            ImageFetcher.asInstance().load(deliveryTag.getIcon(), icon);
    }

    if (mPreferentialViewGroup.getChildCount() > 0) {
      if (null != mNoticeView) {
        mNoticeView.removeAllViews();
        mNoticeView.addView(mPreferentialViewGroup);
      }
      //            mAdapter.addView(mPreferentialViewGroup);
      mPreferentialViewGroup.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              new NoticeListDialog(getContext(), preferentialNotice)
                  .setCloseClick(
                      new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {}
                      })
                  .setDialogIcon(R.drawable.app_ic_dialog_preferential)
                  .show();
            }
          });

      ////            增加底部的灰色间隔
      //            View view = new View(getContext());
      //
      // view.setBackgroundColor(getContext().getResources().getColor(R.color.uikit_grey_light));
      //            ScreenUtils.resizeViewWithSpecial(view, ScreenUtils.getScreenWidthInt(),
      // ScreenUtils.dip2px(8));
      //            mPreferentialViewGroup.addView(view);
    }
  }
示例#13
0
  @Override
  public void start(@Nullable final IEndListener listener) {

    PropertyValuesHolder valHolder = null;
    ObjectAnimator animator;

    int fromDegree;
    int toDegree;

    text.setAlpha(255);

    if (show) {
      fromDegree = 90;
      toDegree = 0;
    } else {
      fromDegree = 0;
      toDegree = -90;
    }

    if ((pivot & Pivot.BOTTOM) == Pivot.BOTTOM) {

      valHolder = PropertyValuesHolder.ofFloat("rotationX", fromDegree, toDegree);
      cameraTransXPre = -text.getWidth() / 2;
      cameraTransXPost = text.getWidth() / 2;
      cameraTransYPre = -text.getFontDescent();
      cameraTransYPost = 0;
    } else if ((pivot & Pivot.TOP) == Pivot.TOP) {
      valHolder = PropertyValuesHolder.ofFloat("rotationX", -fromDegree, toDegree);
      cameraTransXPre = -text.getWidth() / 2;
      cameraTransXPost = text.getWidth() / 2;
      cameraTransYPre = text.getHeight() - text.getFontDescent();
      cameraTransYPost = -text.getHeight();
    }

    if ((pivot & Pivot.LEFT) == Pivot.LEFT) {
      valHolder = PropertyValuesHolder.ofFloat("rotationY", fromDegree, toDegree);
      cameraTransXPre = 0;
      cameraTransXPost = 0;
      cameraTransYPre = text.getHeight() / 2 - text.getFontDescent();
      cameraTransYPost = text.getHeight() / 2 - text.getHeight();
    } else if ((pivot & Pivot.RIGHT) == Pivot.RIGHT) {
      valHolder = PropertyValuesHolder.ofFloat("rotationY", -fromDegree, toDegree);
      cameraTransXPre = -text.getWidth();
      cameraTransXPost = text.getWidth();
      cameraTransYPre = text.getHeight() / 2 - text.getFontDescent();
      cameraTransYPost = text.getHeight() / 2 - text.getHeight();
    }

    if ((pivot & Pivot.CENTER) == Pivot.CENTER) {
      valHolder =
          PropertyValuesHolder.ofFloat(
              axis == Axis.Y ? "rotationY" : "rotationX", fromDegree, toDegree);
      cameraTransXPre = -text.getWidth() / 2;
      cameraTransXPost = text.getWidth() / 2;
      cameraTransYPre = text.getHeight() / 2 - text.getFontDescent();
      cameraTransYPost = text.getHeight() / 2 - text.getHeight();
    }

    if (valHolder != null) {
      animator = ObjectAnimator.ofPropertyValuesHolder(this, valHolder);
      animator.setInterpolator(new FastOutSlowInInterpolator());
      Utils.addEndListener(
          this,
          animator,
          new IEndListener() {
            @Override
            public void onAnimationEnd(ISurfaceAnimation animation) {
              text.removeEffect(Rotate3D.this);
              if (!show) text.setAlpha(0);
              if (listener != null) listener.onAnimationEnd(Rotate3D.this);
            }
          });
      animator.setDuration(duration);
      animator.addUpdateListener(this);
      animator.start();
    } else {
      throw new RuntimeException(
          getClass().getSuperclass() + " was not configured properly. Pivot:" + pivot);
    }
  }