// 初始化歌曲列表
  private void initLocalMusicList() {
    // fileInfos = MediaUtil.getFileInfos(getApplicationContext()); //获取歌曲对象集合
    setListAdpter(MediaUtil.getMusicMaps(fileInfos)); // 显示歌曲列表
    music_siger_tv.setText(fileInfos.get(listPosition).getArtist());
    music_name_tv.setText(fileInfos.get(listPosition).getTitle());
    music_play_bt.setPressed(play_bt_press);
    music_play_bt.setChecked(play_bt_check);

    anim = ObjectAnimator.ofFloat(music_album_iv, "rotation", 0, 360);
    lin = new LinearInterpolator();
    anim.setDuration(6000);
    anim.setRepeatCount(-1);
    anim.setRepeatMode(ObjectAnimator.RESTART);
    anim.setInterpolator(lin); // 匀速

    PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("alpha", 1f, 0f, 1f);
    PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("scaleX", 1f, 0, 1f);
    PropertyValuesHolder pvhZ = PropertyValuesHolder.ofFloat("scaleY", 1f, 0, 1f);
    animSongName = ObjectAnimator.ofPropertyValuesHolder(music_name_tv, pvhX, pvhY, pvhZ); // 渐现
    animSongName.setDuration(1000);
    animSongName.setRepeatCount(0);
    animSongName.setRepeatMode(ObjectAnimator.RESTART);

    animSongSinger = ObjectAnimator.ofPropertyValuesHolder(music_siger_tv, pvhX, pvhY, pvhZ); // 渐现
    animSongSinger.setDuration(1000);
    animSongSinger.setRepeatCount(0);
    animSongSinger.setRepeatMode(ObjectAnimator.RESTART);
  }
  /** Show post-send animation */
  public void showPostSend() {
    if (!mAttached) {
      return;
    }

    mSlowSendAnimator.cancel();
    mTextHint.setVisibility(View.GONE);

    float currentScale = mScreenshotView.getScaleX();

    // Modify the fast clone parameters to match the current scale
    PropertyValuesHolder postX =
        PropertyValuesHolder.ofFloat("scaleX", new float[] {currentScale, 0.0f});
    PropertyValuesHolder postY =
        PropertyValuesHolder.ofFloat("scaleY", new float[] {currentScale, 0.0f});
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", new float[] {1.0f, 0.0f});
    mFastCloneAnimator.setValues(postX, postY, alpha);

    // Modify the fadeIn parameters to match the current scale
    PropertyValuesHolder fadeIn = PropertyValuesHolder.ofFloat("alpha", new float[] {0.0f, 1.0f});
    mFadeInAnimator.setValues(fadeIn);

    if (mFireflyRenderThread != null) {
      mFireflyRenderThread.fadeOut();
    }

    mSuccessAnimatorSet.start();
  }
 /** Return to initial state */
 public void finish(int finishMode) {
   if (!mAttached) {
     return;
   }
   mTextHint.setVisibility(View.GONE);
   if (finishMode == FINISH_SLIDE_OUT) {
     PropertyValuesHolder slideX =
         PropertyValuesHolder.ofFloat(
             "translationX", new float[] {0.0f, mScreenshotView.getWidth()});
     mSlideoutAnimator = ObjectAnimator.ofPropertyValuesHolder(mScreenshotView, slideX);
     mSlideoutAnimator.setInterpolator(new AccelerateInterpolator());
     mSlideoutAnimator.setDuration(SLIDE_OUT_DURATION_MS);
     mSlideoutAnimator.addListener(this);
     mSlideoutAnimator.start();
   } else {
     float currentScale = mScreenshotView.getScaleX();
     float currentAlpha = mScreenshotView.getAlpha();
     PropertyValuesHolder scaleUpX =
         PropertyValuesHolder.ofFloat("scaleX", new float[] {currentScale, 1.0f});
     PropertyValuesHolder scaleUpY =
         PropertyValuesHolder.ofFloat("scaleY", new float[] {currentScale, 1.0f});
     PropertyValuesHolder scaleUpAlpha =
         PropertyValuesHolder.ofFloat("alpha", new float[] {currentAlpha, 1.0f});
     mScaleUpAnimator =
         ObjectAnimator.ofPropertyValuesHolder(mScreenshotView, scaleUpX, scaleUpY, scaleUpAlpha);
     mScaleUpAnimator.setInterpolator(new DecelerateInterpolator());
     mScaleUpAnimator.setDuration(SCALE_UP_DURATION_MS);
     mScaleUpAnimator.addListener(this);
     mScaleUpAnimator.start();
   }
 }
  public void propertyValuesHolder(View view) {
    Log.i("tag", "动画已经被执行");
    PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat("alpha", 1f, 1f);
    PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("scaleX", 1f, 1f);
    PropertyValuesHolder pvhZ = PropertyValuesHolder.ofFloat("scaleY", 1f, 1f);
    Animator objectAnimator =
        ObjectAnimator.ofPropertyValuesHolder(view, pvhX, pvhY, pvhZ).setDuration(2000);
    objectAnimator.start();
    objectAnimator.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animation) {}

          @Override
          public void onAnimationEnd(Animator animation) {
            if (mFirst) {
              turn2Activity(New_login.this, WelcomeActivity.class);
            } else {
              turn2Activity(New_login.this, NewMain.class);
              overridePendingTransition(R.anim.push_center_in, R.anim.push_center_out);
            }
            finish();
          }

          @Override
          public void onAnimationCancel(Animator animation) {}

          @Override
          public void onAnimationRepeat(Animator animation) {}
        });
  }
 // 开始动画
 private void startAnim() {
   // 遍历第一个不是主菜单的ImageView列表
   for (int i = 1; i < res.length; i++) {
     // 获取展开角度
     float angle = (90 * 1.0f / (res.length - 2)) * (i - 1);
     // 获取X位移
     PropertyValuesHolder holder1 =
         PropertyValuesHolder.ofFloat(
             "translationX", 0, (float) (Math.sin((angle * 1.57 / 90)) * 200));
     // 获取Y位移
     PropertyValuesHolder holder2 =
         PropertyValuesHolder.ofFloat(
             "translationY", 0, (float) (Math.cos((angle * 1.57 / 90)) * 200));
     // 设置ImageView的属性动画
     ObjectAnimator animator =
         ObjectAnimator.ofPropertyValuesHolder(imageViewList.get(i), holder1, holder2);
     // ObjectAnimator animator =
     // ObjectAnimator.ofFloat(imageViewList.get(i), "translationY", 0, i *
     // 60);
     // 动画时间
     animator.setDuration(1000);
     // 动画延迟时间
     animator.setFrameDelay(500 * i);
     // 设置加速器
     animator.setInterpolator(new BounceInterpolator());
     // 启动动画
     animator.start();
     isNotExpand = false;
   }
 }
  public ObjectAnimator getDisappearAnimator() {
    if (!mIsInitialized || !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, 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);

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

    return disappearAnimator;
  }
  public void animateClosed() {
    if (!(getParent() instanceof DragLayer)) return;
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f);
    final ObjectAnimator oa = LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);

    oa.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            onCloseComplete();
            setLayerType(LAYER_TYPE_NONE, null);
            mState = STATE_SMALL;
          }

          @Override
          public void onAnimationStart(Animator animation) {
            sendCustomAccessibilityEvent(
                AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                getContext().getString(R.string.folder_closed));
            mState = STATE_ANIMATING;
          }
        });
    oa.setDuration(mExpandDuration);
    setLayerType(LAYER_TYPE_HARDWARE, null);
    oa.start();
  }
  public void treeMe(final View view, boolean isUp) {

    ObjectAnimator.ofPropertyValuesHolder(
            view,
            PropertyValuesHolder.ofFloat(View.TRANSLATION_X, 40),
            PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, isUp ? 40 : -40))
        .start();
  }
 private void startAnim(View convertView) {
   convertView.setPivotX(0.0f);
   convertView.setPivotY(1.0f);
   PropertyValuesHolder x = PropertyValuesHolder.ofFloat("scaleX", 0.0f, 1.0f);
   PropertyValuesHolder y = PropertyValuesHolder.ofFloat("scaleY", 0.0f, 1.0f);
   ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(convertView, x, y);
   animator.setDuration(animTime);
   animator.start();
 }
    public static void animateShowing(
        final ViewHolder holder, final ListAdapter adapter, boolean isAnimate) {
      final CheckBox checkBox = holder.checkBox;
      if (checkBox.getVisibility() == View.VISIBLE) {
        return;
      }
      checkBox.setVisibility(View.VISIBLE);
      checkBox.setAlpha(0.0f);
      final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
      final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
      checkBox.measure(widthSpec, heightSpec);
      ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) checkBox.getLayoutParams();
      final long transValue = checkBox.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;

      if (!isAnimate) {
        checkBox.setAlpha(1.0f);
        holder.contentLayout.setTranslationX(transValue);
        return;
      }

      final ObjectAnimator transBodyAnimator = new ObjectAnimator();
      final PropertyValuesHolder trans =
          PropertyValuesHolder.ofFloat("TranslationX", 0.0f, transValue);
      transBodyAnimator.setTarget(holder.contentLayout);
      transBodyAnimator.setValues(trans);
      transBodyAnimator.setDuration(DURATION);

      ObjectAnimator checkBoxAnim = new ObjectAnimator();
      final PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("ScaleX", 0.0f, 1.0f);
      final PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("ScaleY", 0.0f, 1.0f);
      final PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("Alpha", 0.0f, 1.0f);
      checkBoxAnim.setValues(scaleX, scaleY, alpha);
      checkBoxAnim.setTarget(holder.checkBox);
      checkBoxAnim.setDuration(DURATION);
      checkBoxAnim.setInterpolator(new DecelerateInterpolator());
      checkBoxAnim.addListener(
          new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
              checkBox.setTag("animating");
            }

            @Override
            public void onAnimationEnd(Animator animation) {
              // adapter.setCheckBoxAnimator(false);
              checkBox.setTag("animated");
            }
          });
      if (!(checkBox.getTag() != null && "animating".equals(checkBox.getTag()))) {
        // 若正在播放动画,则不继续播放动画
        transBodyAnimator.start();
        checkBoxAnim.start();
      }
    }
    public static void animateHiding(
        final ViewHolder holder, final ListAdapter adapter, boolean isAnimate) {
      final CheckBox checkBox = holder.checkBox;
      final View tansBody = holder.contentLayout;

      if (checkBox.getVisibility() == View.GONE) {
        return;
      }
      ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) checkBox.getLayoutParams();
      final float transValue = checkBox.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;

      if (!isAnimate) {
        checkBox.setVisibility(View.GONE);
        holder.contentLayout.setTranslationX(0.0f);
        return;
      }
      final ObjectAnimator transBodyAnimator = new ObjectAnimator();
      final PropertyValuesHolder trans =
          PropertyValuesHolder.ofFloat("TranslationX", transValue, 0.0f);
      transBodyAnimator.setTarget(tansBody);
      transBodyAnimator.setValues(trans);
      transBodyAnimator.setDuration(DURATION);

      ObjectAnimator checkBoxAnim = new ObjectAnimator();
      final PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("ScaleX", 1.0f, 0.0f);
      final PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("ScaleY", 1.0f, 0.0f);
      final PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("Alpha", 1.0f, 0.0f);
      checkBoxAnim.setValues(scaleX, scaleY, alpha);
      checkBoxAnim.setTarget(checkBox);
      checkBoxAnim.setDuration(DURATION);
      checkBoxAnim.setInterpolator(new AccelerateInterpolator());
      checkBoxAnim.addListener(
          new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
              checkBox.setTag("animating");
            }

            @Override
            public void onAnimationEnd(Animator animation) {
              // adapter.setCheckBoxAnimator(false);
              checkBox.setScaleX(1.0f);
              checkBox.setScaleY(1.0f);
              checkBox.setAlpha(1.0f);
              checkBox.setVisibility(View.GONE);
              checkBox.setTag("animated");
            }
          });
      if (!(checkBox.getTag() != null && "animating".equals(checkBox.getTag()))) {
        transBodyAnimator.start();
        checkBoxAnim.start();
      }
    }
 protected void init(Float... values) {
   if (mStartColor == null || mEndColor == null) {
     return;
   }
   PropertyValuesHolder countProperty =
       PropertyValuesHolder.ofFloat(
           PROPERTY_VALUE_COUNT, PrimitiveUtils.asPrimitive((Float[]) values));
   PropertyValuesHolder colorProperty =
       PropertyValuesHolder.ofObject(
           ViewConstants.PROPERTY_TEXT_COLOR, new ArgbEvaluator(), mStartColor, mEndColor);
   setValues(countProperty, colorProperty);
 }
  @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
  @Override
  public ObjectAnimator getInitalAnimator(Context context) {

    ObjectAnimator animator =
        ObjectAnimator.ofPropertyValuesHolder(
            new Object(),
            PropertyValuesHolder.ofFloat("alpha", 0.5f, 1.f),
            PropertyValuesHolder.ofFloat("rotation", 60.f, 0.f));

    animator.setDuration((long) (200 * mSpeedFactor));
    return animator;
  }
Exemple #14
0
  private void init() {

    PropertyValuesHolder valueHolder_1 = PropertyValuesHolder.ofFloat("scaleX", 1f, 0.9f);
    PropertyValuesHolder valueHolder_2 = PropertyValuesHolder.ofFloat("scaleY", 1f, 0.9f);
    anim1 = ObjectAnimator.ofPropertyValuesHolder(this, valueHolder_1, valueHolder_2);
    anim1.setDuration(200);
    anim1.setInterpolator(new LinearInterpolator());

    PropertyValuesHolder valueHolder_3 = PropertyValuesHolder.ofFloat("scaleX", 0.9f, 1f);
    PropertyValuesHolder valueHolder_4 = PropertyValuesHolder.ofFloat("scaleY", 0.9f, 1f);
    anim2 = ObjectAnimator.ofPropertyValuesHolder(this, valueHolder_3, valueHolder_4);
    anim2.setDuration(200);
    anim2.setInterpolator(new LinearInterpolator());
  }
 @Override
 public List<Animator> createAnimation() {
   List<Animator> animators = new ArrayList<>();
   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();
   animators.add(animator);
   return animators;
 }
  /**
   * 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);
  }
  public static ObjectAnimator tada(View view, float shakeFactor) {

    PropertyValuesHolder pvhScaleX =
        PropertyValuesHolder.ofKeyframe(
            View.SCALE_X,
            Keyframe.ofFloat(0f, 1f),
            Keyframe.ofFloat(.1f, .9f),
            Keyframe.ofFloat(.2f, .9f),
            Keyframe.ofFloat(.3f, 1.1f),
            Keyframe.ofFloat(.4f, 1.1f),
            Keyframe.ofFloat(.5f, 1.1f),
            Keyframe.ofFloat(.6f, 1.1f),
            Keyframe.ofFloat(.7f, 1.1f),
            Keyframe.ofFloat(.8f, 1.1f),
            Keyframe.ofFloat(.9f, 1.1f),
            Keyframe.ofFloat(1f, 1f));

    PropertyValuesHolder pvhScaleY =
        PropertyValuesHolder.ofKeyframe(
            View.SCALE_Y,
            Keyframe.ofFloat(0f, 1f),
            Keyframe.ofFloat(.1f, .9f),
            Keyframe.ofFloat(.2f, .9f),
            Keyframe.ofFloat(.3f, 1.1f),
            Keyframe.ofFloat(.4f, 1.1f),
            Keyframe.ofFloat(.5f, 1.1f),
            Keyframe.ofFloat(.6f, 1.1f),
            Keyframe.ofFloat(.7f, 1.1f),
            Keyframe.ofFloat(.8f, 1.1f),
            Keyframe.ofFloat(.9f, 1.1f),
            Keyframe.ofFloat(1f, 1f));

    PropertyValuesHolder pvhRotate =
        PropertyValuesHolder.ofKeyframe(
            View.ROTATION,
            Keyframe.ofFloat(0f, 0f),
            Keyframe.ofFloat(.1f, -3f * shakeFactor),
            Keyframe.ofFloat(.2f, -3f * shakeFactor),
            Keyframe.ofFloat(.3f, 3f * shakeFactor),
            Keyframe.ofFloat(.4f, -3f * shakeFactor),
            Keyframe.ofFloat(.5f, 3f * shakeFactor),
            Keyframe.ofFloat(.6f, -3f * shakeFactor),
            Keyframe.ofFloat(.7f, 3f * shakeFactor),
            Keyframe.ofFloat(.8f, -3f * shakeFactor),
            Keyframe.ofFloat(.9f, 3f * shakeFactor),
            Keyframe.ofFloat(1f, 0));

    return ObjectAnimator.ofPropertyValuesHolder(view, pvhScaleX, pvhScaleY, pvhRotate)
        .setDuration(1000);
  }
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  @Override
  public ObjectAnimator getDisappearingAnimator(Context context) {

    ObjectAnimator animator =
        ObjectAnimator.ofPropertyValuesHolder(
            new Object(),
            PropertyValuesHolder.ofFloat("alpha", 1.f, 0.f),
            PropertyValuesHolder.ofFloat("scaleX", 1.f, 0.f),
            PropertyValuesHolder.ofFloat("scaleY", 1.f, 0.f),
            PropertyValuesHolder.ofFloat("rotation", 0.f, 270.f));

    animator.setDuration((long) (200 * mSpeedFactor));
    return animator;
  }
  void animatePagesToCarousel() {
    if (mChildrenTransformsAnimator != null) {
      mChildrenTransformsAnimator.cancel();
      mChildrenTransformsAnimator = null;
    }

    int count = getChildCount();
    PropertyValuesHolder alpha;
    PropertyValuesHolder outlineAlpha;
    PropertyValuesHolder rotationY;
    PropertyValuesHolder pivotX;
    PropertyValuesHolder pivotY;
    ArrayList<Animator> anims = new ArrayList<Animator>();

    for (int i = 0; i < count; i++) {
      KeyguardWidgetFrame child = getWidgetPageAt(i);
      float finalAlpha = getAlphaForPage(mScreenCenter, i, true);
      float finalOutlineAlpha = getOutlineAlphaForPage(mScreenCenter, i, true);
      getTransformForPage(mScreenCenter, i, mTmpTransform);

      boolean inVisibleRange = (i >= mCurrentPage - 1 && i <= mCurrentPage + 1);

      ObjectAnimator a;
      alpha = PropertyValuesHolder.ofFloat("contentAlpha", finalAlpha);
      outlineAlpha = PropertyValuesHolder.ofFloat("backgroundAlpha", finalOutlineAlpha);
      pivotX = PropertyValuesHolder.ofFloat("pivotX", mTmpTransform[0]);
      pivotY = PropertyValuesHolder.ofFloat("pivotY", mTmpTransform[1]);
      rotationY = PropertyValuesHolder.ofFloat("rotationY", mTmpTransform[2]);

      if (inVisibleRange) {
        // for the central pages we animate into a rotated state
        a =
            ObjectAnimator.ofPropertyValuesHolder(
                child, alpha, outlineAlpha, pivotX, pivotY, rotationY);
      } else {
        a = ObjectAnimator.ofPropertyValuesHolder(child, alpha, outlineAlpha);
        a.setInterpolator(mFastFadeInterpolator);
      }
      anims.add(a);
    }

    int duration = REORDERING_ZOOM_IN_OUT_DURATION;
    mChildrenTransformsAnimator = new AnimatorSet();
    mChildrenTransformsAnimator.playTogether(anims);

    mChildrenTransformsAnimator.setDuration(duration);
    mChildrenTransformsAnimator.start();
  }
Exemple #20
0
  /** 打开动画 */
  public void animateOpen() {
    positionAndSizeAsIcon();

    if (!(getParent() instanceof DragLayer)) return;
    centerAboutIcon();
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
    final ObjectAnimator oa =
        mOpenCloseAnimator = LauncherAnimUtils.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);

    oa.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationStart(Animator animation) {
            sendCustomAccessibilityEvent(
                AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                String.format(
                    getContext().getString(R.string.folder_opened),
                    mContent.getCountX(),
                    mContent.getCountY()));
            mState = STATE_ANIMATING;
          }

          @Override
          public void onAnimationEnd(Animator animation) {
            mState = STATE_OPEN;
            setLayerType(LAYER_TYPE_NONE, null);
            Cling cling = mLauncher.showFirstRunFoldersCling();
            if (cling != null) {
              cling.bringToFront();
            }
            setFocusOnFirstChild();
          }
        });
    oa.setDuration(mExpandDuration);
    setLayerType(LAYER_TYPE_HARDWARE, null);
    buildLayer();
    post(
        new Runnable() {
          public void run() {
            // Check if the animator changed in the meantime
            if (oa != mOpenCloseAnimator) return;
            oa.start();
          }
        });
  }
  /** 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(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(this, radiusReappear, fadeIn)
            .setDuration(totalDuration);
    mReappearAnimator.addUpdateListener(mInvalidateUpdateListener);
  }
  @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
  @Override
  public ObjectAnimator getAppearingAnimator(Context context) {

    final Point outPoint = new Point();
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    wm.getDefaultDisplay().getSize(outPoint);

    ObjectAnimator animator =
        ObjectAnimator.ofPropertyValuesHolder(
            new Object(),
            PropertyValuesHolder.ofFloat("alpha", 0.f, 1.f),
            PropertyValuesHolder.ofFloat("translationY", outPoint.y / 2.f, 0.f),
            PropertyValuesHolder.ofFloat("rotation", -45.f, 0.f));

    animator.setDuration((long) (200 * mSpeedFactor));
    return animator;
  }
  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.btn_change:
        imageView.setImageResource(R.drawable.toutiao__news_ic_video_selected);

        PropertyValuesHolder pvhAlpha = PropertyValuesHolder.ofFloat("alpha", 0.3f, 1f);
        PropertyValuesHolder pvhScaleX = PropertyValuesHolder.ofFloat("scaleX", 0.3f, 1f);
        PropertyValuesHolder pvhScaleY = PropertyValuesHolder.ofFloat("scaleY", 0.3f, 1f);

        ObjectAnimator objectAnimator =
            ObjectAnimator.ofPropertyValuesHolder(imageView, pvhAlpha, pvhScaleX, pvhScaleY)
                .setDuration(300);
        objectAnimator.setInterpolator(new DecelerateInterpolator());
        objectAnimator.start();

        break;
    }
  }
 // 关闭动画
 private void closeAnim() {
   for (int i = 1; i < res.length; i++) {
     float angle = (90 * 1.0f / (res.length - 2)) * (i - 1);
     PropertyValuesHolder holder1 =
         PropertyValuesHolder.ofFloat(
             "translationX", (float) (Math.sin((angle * 1.57 / 90)) * 200), 0);
     PropertyValuesHolder holder2 =
         PropertyValuesHolder.ofFloat(
             "translationY", (float) (Math.cos((angle * 1.57 / 90)) * 200), 0);
     ObjectAnimator animator =
         ObjectAnimator.ofPropertyValuesHolder(imageViewList.get(i), holder1, holder2);
     // ObjectAnimator animator =
     // ObjectAnimator.ofFloat(imageViewList.get(i), "translationY", i * 60,
     // 0);
     animator.setDuration(300);
     animator.start();
     isNotExpand = true;
   }
 }
Exemple #25
0
  public void animateClosed() {
    if (!(getParent() instanceof DragLayer)) return;

    ObjectAnimator oa;
    if (mMode == PARTIAL_GROW) {
      PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0);
      PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.9f);
      PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.9f);
      oa = ObjectAnimator.ofPropertyValuesHolder(this, alpha, scaleX, scaleY);
    } else {
      DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();

      PropertyValuesHolder width = PropertyValuesHolder.ofInt("width", mIconRect.width());
      PropertyValuesHolder height = PropertyValuesHolder.ofInt("height", mIconRect.height());
      PropertyValuesHolder x = PropertyValuesHolder.ofInt("x", mIconRect.left);
      PropertyValuesHolder y = PropertyValuesHolder.ofInt("y", mIconRect.top);
      oa = ObjectAnimator.ofPropertyValuesHolder(lp, width, height, x, y);
      oa.addUpdateListener(
          new AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator animation) {
              requestLayout();
            }
          });

      PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0f);
      ObjectAnimator alphaOa = ObjectAnimator.ofPropertyValuesHolder(mContent, alpha);
      alphaOa.setDuration(mExpandDuration);
      alphaOa.setInterpolator(new DecelerateInterpolator(2.0f));
      alphaOa.start();
    }

    oa.addListener(
        new AnimatorListenerAdapter() {
          @Override
          public void onAnimationEnd(Animator animation) {
            onCloseComplete();
            mState = STATE_SMALL;
          }

          @Override
          public void onAnimationStart(Animator animation) {
            sendCustomAccessibilityEvent(
                AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED,
                getContext().getString(R.string.folder_closed));
            mState = STATE_ANIMATING;
          }
        });
    oa.setDuration(mExpandDuration);
    oa.start();
  }
  void animatePagesToNeutral() {
    if (mChildrenTransformsAnimator != null) {
      mChildrenTransformsAnimator.cancel();
      mChildrenTransformsAnimator = null;
    }

    int count = getChildCount();
    PropertyValuesHolder alpha;
    PropertyValuesHolder outlineAlpha;
    PropertyValuesHolder rotationY;
    ArrayList<Animator> anims = new ArrayList<Animator>();

    for (int i = 0; i < count; i++) {
      KeyguardWidgetFrame child = getWidgetPageAt(i);
      boolean inVisibleRange = (i >= mCurrentPage - 1 && i <= mCurrentPage + 1);
      if (!inVisibleRange) {
        child.setRotationY(0f);
      }
      alpha = PropertyValuesHolder.ofFloat("contentAlpha", 1.0f);
      outlineAlpha =
          PropertyValuesHolder.ofFloat(
              "backgroundAlpha", KeyguardWidgetFrame.OUTLINE_ALPHA_MULTIPLIER);
      rotationY = PropertyValuesHolder.ofFloat("rotationY", 0f);
      ObjectAnimator a =
          ObjectAnimator.ofPropertyValuesHolder(child, alpha, outlineAlpha, rotationY);
      child.setVisibility(VISIBLE);
      if (!inVisibleRange) {
        a.setInterpolator(mSlowFadeInterpolator);
      }
      anims.add(a);
    }

    int duration = REORDERING_ZOOM_IN_OUT_DURATION;
    mChildrenTransformsAnimator = new AnimatorSet();
    mChildrenTransformsAnimator.playTogether(anims);

    mChildrenTransformsAnimator.setDuration(duration);
    mChildrenTransformsAnimator.start();
  }
  private void flip(final View v1, final View v2, final boolean scale, boolean reverse) {
    final int duration = 300;
    final int degree = reverse ? 90 : -90;
    final int degree2 = -degree;

    final ObjectAnimator a, b;
    if (!scale) {
      a = ObjectAnimator.ofFloat(v1, "rotationY", 0, degree);
      b = ObjectAnimator.ofFloat(v2, "rotationY", degree2, 0);
    } else {
      final float scaleX = 0.5f;
      final float scaleY = 0.5f;
      a =
          ObjectAnimator.ofPropertyValuesHolder(
              v1,
              PropertyValuesHolder.ofFloat("rotationY", 0, degree),
              PropertyValuesHolder.ofFloat("scaleX", 1, scaleX),
              PropertyValuesHolder.ofFloat("scaleY", 1, scaleY));
      b =
          ObjectAnimator.ofPropertyValuesHolder(
              v2,
              PropertyValuesHolder.ofFloat("rotationY", degree2, 0),
              PropertyValuesHolder.ofFloat("scaleX", scaleX, 1),
              PropertyValuesHolder.ofFloat("scaleY", scaleY, 1));
    }

    a.setInterpolator(new LinearInterpolator());
    b.setInterpolator(new LinearInterpolator());
    a.setDuration(duration);
    b.setDuration(duration);

    a.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animation) {}

          @Override
          public void onAnimationEnd(Animator animation) {
            v1.setVisibility(View.GONE);
            v2.setVisibility(View.VISIBLE);
            if (scale) { // 恢复scale
              v1.setScaleX(1);
              v1.setScaleY(1);
            }
          }

          @Override
          public void onAnimationCancel(Animator animation) {}

          @Override
          public void onAnimationRepeat(Animator animation) {}
        });
    v1.setVisibility(View.VISIBLE);
    v2.setVisibility(View.GONE);

    AnimatorSet set = new AnimatorSet();
    set.play(a).before(b);
    set.start();
  }
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  @Override
  public ObjectAnimator getSwipeInAnimator(View view, float deltaX, float deltaY) {

    float deltaXAbs = Math.abs(deltaX);

    float fractionCovered = 1.f - (deltaXAbs / view.getWidth());
    long duration = Math.abs((int) ((1 - fractionCovered) * 200 * mSpeedFactor));

    // Animate position and alpha of swiped item

    ObjectAnimator animator =
        ObjectAnimator.ofPropertyValuesHolder(
            view,
            PropertyValuesHolder.ofFloat("alpha", 1.f),
            PropertyValuesHolder.ofFloat("translationX", 0.f),
            PropertyValuesHolder.ofFloat("rotationY", 0.f));

    animator.setDuration(duration).setInterpolator(new BounceInterpolator());

    return animator;
  }
  public ObjectAnimator getReappearAnimator() {
    if (!mIsInitialized || !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, 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);

    ObjectAnimator reappearAnimator =
        ObjectAnimator.ofPropertyValuesHolder(this, radiusReappear, fadeIn)
            .setDuration(totalDuration);
    reappearAnimator.addUpdateListener(mInvalidateUpdateListener);
    return reappearAnimator;
  }
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  @Override
  public ObjectAnimator getSwipeOutAnimator(View view, float deltaX, float deltaY) {

    float endX;
    float endRotationY;

    float deltaXAbs = Math.abs(deltaX);

    float fractionCovered = 1.f - (deltaXAbs / view.getWidth());
    long duration = Math.abs((int) ((1 - fractionCovered) * 200 * mSpeedFactor));

    endX = deltaX < 0 ? -view.getWidth() : view.getWidth();
    if (deltaX > 0) endRotationY = -15.f;
    else endRotationY = 15.f;

    // Animate position and alpha of swiped item
    return ObjectAnimator.ofPropertyValuesHolder(
            view,
            PropertyValuesHolder.ofFloat("alpha", 0.f),
            PropertyValuesHolder.ofFloat("translationX", endX),
            PropertyValuesHolder.ofFloat("rotationY", endRotationY))
        .setDuration(duration);
  }