Java Code Examples for android.animation.ValueAnimator#setTarget()

The following examples show how to use android.animation.ValueAnimator#setTarget() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElectricFanLoadingRenderer.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
private ValueAnimator getBezierValueAnimator(LeafHolder target, RectF leafFlyRect, float progress) {
    BezierEvaluator evaluator = new BezierEvaluator(getPoint1(leafFlyRect), getPoint2(leafFlyRect));

    int leafFlyStartY = (int) (mCurrentProgressBounds.bottom - mLeafDrawable.getIntrinsicHeight());
    int leafFlyRange = (int) (mCurrentProgressBounds.height() - mLeafDrawable.getIntrinsicHeight());

    int startPointY = leafFlyStartY - mRandom.nextInt(leafFlyRange);
    int endPointY = leafFlyStartY - mRandom.nextInt(leafFlyRange);

    ValueAnimator animator = ValueAnimator.ofObject(evaluator,
            new PointF((int) (leafFlyRect.right - mLeafDrawable.getIntrinsicWidth()), startPointY),
            new PointF(leafFlyRect.left, endPointY));
    animator.addUpdateListener(new BezierListener(target));
    animator.setTarget(target);

    animator.setDuration((long) ((mRandom.nextInt(300) + mDuration * DEFAULT_LEAF_FLY_DURATION_FACTOR) * (1.0f - progress)));

    return animator;
}
 
Example 2
Source File: PhotoListDialog.java    From AndroidPickPhotoDialog with Apache License 2.0 6 votes vote down vote up
public void showFloor(final View v) {
    isShowListView = true;
    ValueAnimator animator;
    animator = ValueAnimator.ofFloat(listviewHeight, 0);
    animator.setTarget(v);
    animator.setDuration(200).start();
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            v.setTranslationY((Float) animation.getAnimatedValue());
        }
    });

    vBg.animate().alpha(1).setDuration(200);
    vBg.setVisibility(View.VISIBLE);
}
 
Example 3
Source File: PhotoListDialog.java    From AndroidPickPhotoDialog with Apache License 2.0 6 votes vote down vote up
public void hideFloor(final View v)
{
    isShowListView = false;
    ValueAnimator animator;
    animator = ValueAnimator.ofFloat(0, listviewHeight);
    animator.setTarget(v);
    animator.setDuration(200).start();
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            v.setTranslationY((Float) animation.getAnimatedValue());
        }
    });
    vBg.animate().alpha(0).setDuration(200);
    vBg.setVisibility(View.GONE);

}
 
Example 4
Source File: LiveActivity.java    From WliveTV with Apache License 2.0 6 votes vote down vote up
public void hideFloor(final View v) {
    ValueAnimator animator;
    if(Build.VERSION.SDK_INT >= 19) {
        animator = ValueAnimator.ofFloat(0, (CommonUtil.dip2px(this, 55) + CommonUtil.getStatusHeight(this)));
    }
    else
    {
        animator = ValueAnimator.ofFloat(0, CommonUtil.dip2px(this, 55));
    }

    animator.setTarget(v);
    animator.setDuration(400).start();
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            v.setTranslationY((Float) animation.getAnimatedValue());
        }
    });
}
 
Example 5
Source File: WaveView.java    From AndroidAnimationExercise with Apache License 2.0 6 votes vote down vote up
/**
 * 通过动画设置当前进度
 *
 * @param progress 进度 <=100
 * @param duration 动画时长
 */
public void setProgress(final int progress, int duration) {
    if (progress > 100 || progress < 0)
        throw new RuntimeException(getClass().getName() + "请设置[0,100]之间的值");
    autoIncrement = false;
    openAnimate = true;
    ValueAnimator progressAnimator = ValueAnimator.ofInt(0, progress);
    progressAnimator.setDuration(duration);
    progressAnimator.setTarget(progress);
    progressAnimator.setInterpolator(new LinearInterpolator());
    progressAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            WaveView.this.progress = (int) animation.getAnimatedValue();
            if (WaveView.this.progress == progress)
                openAnimate = false;
            invalidate();
        }
    });
    progressAnimator.start();
}
 
Example 6
Source File: LiveActivity.java    From WliveTV with Apache License 2.0 6 votes vote down vote up
public void showToolbar(final View v) {
    ValueAnimator animator;
    if(Build.VERSION.SDK_INT >= 19) {
        animator = ValueAnimator.ofFloat(-(CommonUtil.dip2px(this, 55) + CommonUtil.getStatusHeight(this)), 0);
    }
    else
    {
        animator = ValueAnimator.ofFloat(-CommonUtil.dip2px(this, 55), 0);
    }
    animator.setTarget(v);
    animator.setDuration(500).start();
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            v.setTranslationY((Float) animation.getAnimatedValue());
        }
    });
}
 
Example 7
Source File: FavorLayout.java    From PracticeDemo with Apache License 2.0 5 votes vote down vote up
private ValueAnimator getBezierValueAnimator(View target) {

        //初始化一个贝塞尔计算器- - 传入
        BezierEvaluator evaluator = new BezierEvaluator(getPointF(2),getPointF(1));

        //这里最好画个图 理解一下 传入了起点 和 终点
        ValueAnimator animator = ValueAnimator.ofObject(evaluator,new PointF((mWidth-dWidth)/2,mHeight-dHeight),new PointF(random.nextInt(getWidth()),0));
        animator.addUpdateListener(new BezierListenr(target));
        animator.setTarget(target);
        animator.setDuration(3000);
        return animator;
    }
 
Example 8
Source File: SunView.java    From OpenWeatherPlus-Android with Apache License 2.0 5 votes vote down vote up
private void setAnimation(float startAngle, float currentAngle, int duration) {
    ValueAnimator sunAnimator = ValueAnimator.ofFloat(startAngle, currentAngle);
    sunAnimator.setDuration(duration);
    sunAnimator.setTarget(currentAngle);
    sunAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            //每次要绘制的圆弧角度
            mCurrentAngle = (float) animation.getAnimatedValue();
            invalidateView();
        }

    });
    sunAnimator.start();
}
 
Example 9
Source File: PeriscopeLayout.java    From PeriscopeLayout with Apache License 2.0 5 votes vote down vote up
private ValueAnimator getBezierValueAnimator(View target) {

        //初始化一个贝塞尔计算器- - 传入
        BezierEvaluator evaluator = new BezierEvaluator(getPointF(2), getPointF(1));

        //这里最好画个图 理解一下 传入了起点 和 终点
        ValueAnimator animator = ValueAnimator.ofObject(evaluator, new PointF((mWidth - dWidth) / 2, mHeight - dHeight), new PointF(random.nextInt(getWidth()), 0));
        animator.addUpdateListener(new BezierListener(target));
        animator.setTarget(target);
        animator.setDuration(3000);
        return animator;
    }
 
Example 10
Source File: FavorLayout.java    From MousePaint with MIT License 5 votes vote down vote up
private ValueAnimator getBezierValueAnimator(View target) {

        //初始化一个贝塞尔计算器- - 传入
        BezierEvaluator evaluator = new BezierEvaluator(getPointF(2),getPointF(1));

        //这里最好画个图 理解一下 传入了起点 和 终点
        ValueAnimator animator = ValueAnimator.ofObject(evaluator,new PointF((mWidth-dWidth)/2,mHeight-dHeight),new PointF(random.nextInt(getWidth()),0));
        animator.addUpdateListener(new BezierListenr(target));
        animator.setTarget(target);
        animator.setDuration(3000);
        return animator;
    }
 
Example 11
Source File: LiveActivity.java    From WliveTV with Apache License 2.0 5 votes vote down vote up
public void showRelier(final View v)
{
    ValueAnimator animator;
    animator = ValueAnimator.ofFloat(0, -CommonUtil.dip2px(this, 172));
    animator.setTarget(v);
    animator.setDuration(400).start();
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            v.setTranslationY((Float) animation.getAnimatedValue());
        }
    });
    vClose.setVisibility(View.VISIBLE);
}
 
Example 12
Source File: MainActivity.java    From AndroidHeros with MIT License 5 votes vote down vote up
public void btnValueAnimaotr(final View view){
    ValueAnimator animator = ValueAnimator.ofFloat(0, 100);
    animator.setTarget(view);
    animator.setDuration(2000).start();
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            Float value = (Float) animation.getAnimatedValue();
            Toast.makeText(MainActivity.this, value + "", Toast.LENGTH_SHORT).show();
        }
    });
}
 
Example 13
Source File: LiveActivity.java    From WliveTV with Apache License 2.0 5 votes vote down vote up
public void hideToolbar(final View v) {
    ValueAnimator animator;
    animator = ValueAnimator.ofFloat(0, -(CommonUtil.dip2px(this, 55) + CommonUtil.getStatusHeight(this)));
    animator.setTarget(v);
    animator.setDuration(400).start();
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            v.setTranslationY((Float) animation.getAnimatedValue());
        }
    });
}
 
Example 14
Source File: StepArcView.java    From LLApp with Apache License 2.0 5 votes vote down vote up
/**
 * 为进度设置动画
 * ValueAnimator是整个属性动画机制当中最核心的一个类,属性动画的运行机制是通过不断地对值进行操作来实现的,
 * 而初始值和结束值之间的动画过渡就是由ValueAnimator这个类来负责计算的。
 * 它的内部使用一种时间循环的机制来计算值与值之间的动画过渡,
 * 我们只需要将初始值和结束值提供给ValueAnimator,并且告诉它动画所需运行的时长,
 * 那么ValueAnimator就会自动帮我们完成从初始值平滑地过渡到结束值这样的效果。
 *
 * @param start   初始值
 * @param current 结束值
 * @param length  动画时长
 */
private void setAnimation(float start, float current, int length) {
    ValueAnimator progressAnimator = ValueAnimator.ofFloat(start, current);
    progressAnimator.setDuration(length);
    progressAnimator.setTarget(currentAngleLength);
    progressAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            /**每次在初始值和结束值之间产生的一个平滑过渡的值,逐步去更新进度*/
            currentAngleLength = (float) animation.getAnimatedValue();
            invalidate();
        }
    });
    progressAnimator.start();
}
 
Example 15
Source File: PeriscopeLayout.java    From PeriscopeLayout with Apache License 2.0 5 votes vote down vote up
private ValueAnimator getBezierValueAnimator(View target) {

        //初始化一个贝塞尔计算器- - 传入
        BezierEvaluator evaluator = new BezierEvaluator(getPointF(2), getPointF(1));

        //这里最好画个图 理解一下 传入了起点 和 终点
        ValueAnimator animator = ValueAnimator.ofObject(evaluator, new PointF((mWidth - dWidth) / 2, mHeight - dHeight), new PointF(random.nextInt(getWidth()), 0));
        animator.addUpdateListener(new BezierListener(target));
        animator.setTarget(target);
        animator.setDuration(3000);
        return animator;
    }
 
Example 16
Source File: StepArcView.java    From NewFastFrame with Apache License 2.0 5 votes vote down vote up
/**
 * 为进度设置动画
 * ValueAnimator是整个属性动画机制当中最核心的一个类,属性动画的运行机制是通过不断地对值进行操作来实现的,
 * 而初始值和结束值之间的动画过渡就是由ValueAnimator这个类来负责计算的。
 * 它的内部使用一种时间循环的机制来计算值与值之间的动画过渡,
 * 我们只需要将初始值和结束值提供给ValueAnimator,并且告诉它动画所需运行的时长,
 * 那么ValueAnimator就会自动帮我们完成从初始值平滑地过渡到结束值这样的效果。
 *
 * @param start   初始值
 * @param current 结束值
 * @param length  动画时长
 */
private void setAnimation(float start, float current, int length) {
    ValueAnimator progressAnimator = ValueAnimator.ofFloat(start, current);
    progressAnimator.setDuration(length);
    progressAnimator.setTarget(currentAngleLength);
    progressAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            /**每次在初始值和结束值之间产生的一个平滑过渡的值,逐步去更新进度*/
            currentAngleLength = (float) animation.getAnimatedValue();
            invalidate();
        }
    });
    progressAnimator.start();
}
 
Example 17
Source File: FlowLikeView.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 生成曲线运动动画
 * @param target 动画作用 View
 * @return 动画集合
 */
private ValueAnimator generateCurveAnimation(View target) {
    CurveEvaluator evaluator = new CurveEvaluator(generateCTRLPointF(1));
    ValueAnimator valueAnimator = ValueAnimator.ofObject(evaluator,
            new PointF((mViewWidth - mIconWidth) / 2, mViewHeight - mChildViewHeight - mIconHeight),
            new PointF((mViewWidth) / 2 + (mRandom.nextBoolean() ? 1 : -1) * mRandom.nextInt(100), 0)
    );
    valueAnimator.setDuration(mAnimDuration);
    valueAnimator.addUpdateListener(new CurveUpdateLister(target));
    valueAnimator.setTarget(target);
    return valueAnimator;
}
 
Example 18
Source File: BezierPraiseAnimator.java    From kAndroid with Apache License 2.0 5 votes vote down vote up
private ValueAnimator getBezierPraiseAnimator(final View target) {
    // 构建贝塞尔曲线的起点,控制点,终点坐标
    float startX = mTargetX;
    float startY = mTargetY;
    int random = mRandom.nextInt(mPraiseIconWidth);
    float endX;
    float endY;
    float controlX;
    final float controlY;

    controlY = startY - mRandom.nextInt(500) - 100;
    // 左右两边
    if (random % 2 == 0) {
        endX = mTargetX - random * 8;
        controlX = mTargetX - random * 2;
    } else {
        endX = mTargetX + random * 8;
        controlX = mTargetX + random * 2;
    }
    endY = mTargetY + random + 400;

    // 构造自定义的贝塞尔估值器
    PraiseEvaluator evaluator = new PraiseEvaluator(new PointF(controlX, controlY));

    ValueAnimator animator = ValueAnimator.ofObject(evaluator, new PointF(startX, startY), new PointF(endX, endY));
    animator.setInterpolator(new AnticipateInterpolator());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            PointF currentPoint = (PointF) animation.getAnimatedValue();
            target.setX(currentPoint.x);
            target.setY(currentPoint.y);
            // 设置透明度 [1~0]
            target.setAlpha(1.0f - animation.getAnimatedFraction());
        }
    });
    animator.setTarget(target);
    return animator;
}
 
Example 19
Source File: SensorCardPresenter.java    From science-journal with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the UI of the SensorCard to be "active" (show all buttons) or "inactive" (only show
 * header). If recording is in progress, always deactivates.
 *
 * @param isActive Whether this SensorCardPresenter should be active
 * @param force If true, forces UI updates even if isActive is not changed from the previous
 *     state. This is useful when a card is created for the first time or when views are recycled
 *     from other SensorCards and we want to make sure that they have the correct visibility.
 */
public void setActive(boolean isActive, boolean force) {
  if (isRecording()) {
    isActive = false;
  }
  int expandedHeight =
      cardViewHolder != null
          ? cardViewHolder
              .getContext()
              .getResources()
              .getDimensionPixelSize(R.dimen.sensor_tablayout_height)
          : 0;
  // Add animation only if "force" is false -- in other words, if this was user initiated!
  if (this.isActive != isActive && !force) {
    this.isActive = isActive;
    if (cardViewHolder != null) {
      int startHeight = isActive ? 0 : expandedHeight;
      int endHeight = isActive ? expandedHeight : 0;
      cardViewHolder.sensorTabLayout.clearOnTabSelectedListeners();
      if (isActive) {
        cardViewHolder.sensorTabLayout.addOnTabSelectedListener(onTabSelectedListener);
      }
      final ValueAnimator animator =
          ValueAnimator.ofInt(startHeight, endHeight).setDuration(ANIMATION_TIME_MS);
      animator.setTarget(cardViewHolder.sensorSelectionArea);
      animator.addUpdateListener(
          new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
              if (cardViewHolder == null) {
                return;
              }
              Integer value = (Integer) animation.getAnimatedValue();
              cardViewHolder.sensorSelectionArea.getLayoutParams().height = value.intValue();
              cardViewHolder.sensorSelectionArea.requestLayout();
            }
          });
      animator.start();
    }
  } else if (force) {
    this.isActive = isActive;
    if (cardViewHolder != null) {
      cardViewHolder.sensorSelectionArea.getLayoutParams().height = isActive ? expandedHeight : 0;
      cardViewHolder.sensorSelectionArea.requestLayout();
    }
  }
  updateButtonsVisibility(!force);
  refreshTabLayout();
}
 
Example 20
Source File: FloatWindowHelp.java    From QSVideoPlayer with Apache License 2.0 4 votes vote down vote up
@Override
public void end() {
    if (floatMoveView == null)
        return;
    floatParams = newFloatParams.clone();
    //界面内浮窗超出边界回弹动画
    if (!floatParams.systemFloat & !floatParams.canCross) {
        final int w = decorView.getMeasuredWidth();
        final int h = decorView.getMeasuredHeight();
        int maxLeft = w - floatParams.w;
        int maxTop = h - floatParams.h;
        int newLeft = -1;
        int newTop = -1;
        //判断是否超出边界,以及超出边界后回弹新位置的坐标
        final ViewGroup.MarginLayoutParams l = (ViewGroup.MarginLayoutParams) floatMoveView.getLayoutParams();
        if (l.leftMargin < 0) newLeft = 0;
        if (l.leftMargin > maxLeft) newLeft = maxLeft;
        if (l.topMargin < 0) newTop = 0;
        if (l.topMargin > maxTop) newTop = maxTop;
        if (newLeft == -1 & newTop == -1)
            return;
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB)
            return;
        //执行属性动画
        ValueAnimator animator = ValueAnimator.ofFloat(0, 1.0F);
        animator.setTarget(floatMoveView);
        animator.setDuration(300).start();
        // animator.setInterpolator(value)
        final int finalNewLeft = newLeft;
        final int finalNewTop = newTop;
        final int finalLeft = l.leftMargin;
        final int finalTop = l.topMargin;
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @TargetApi(Build.VERSION_CODES.HONEYCOMB)
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                Float f = (Float) animation.getAnimatedValue();
                if (finalNewLeft >= 0)
                    l.leftMargin = (int) (finalLeft + f * (finalNewLeft - finalLeft));
                if (finalNewTop >= 0)
                    l.topMargin = (int) (finalTop + f * (finalNewTop - finalTop));
                floatMoveView.setLayoutParams(l);
                //更新浮窗中心点坐标
                floatParams.x = l.leftMargin + floatParams.w / 2 - w / 2;
                floatParams.y = l.topMargin + floatParams.h / 2 - h / 2;
            }
        });

    }

}