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

The following examples show how to use android.animation.ValueAnimator#setFrameDelay() . 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: GlowingTextView.java    From JPPF with Apache License 2.0 5 votes vote down vote up
/**
 * Start the animation using the specified  duration, start color and end color.
 * @param duration the animation duration.
 * @param startColor the start color.
 * @param endColor the end color.
 * @return this view.
 */
public GlowingTextView startAnimation(long duration, int startColor, int endColor) {
  if (animator != null) {
    if (animator.isStarted() || animator.isRunning()) animator.end();
  }
  this.initialColor = getCurrentTextColor();
  animator = ValueAnimator.ofInt(startColor, endColor);
  animator.setDuration(duration);
  ValueAnimator.setFrameDelay(40L);
  animator.setRepeatCount(ValueAnimator.INFINITE);
  animator.setRepeatMode(ValueAnimator.REVERSE);
  animator.setEvaluator(new ArgbEvaluator());
  animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
      @Override
      public void onAnimationUpdate(final ValueAnimator animation) {
        if (getContext() instanceof Activity) {
          ((Activity) getContext()).runOnUiThread(new Runnable() {
            @Override
            public void run() {
              setTextColor((Integer) animation.getAnimatedValue() | 0xFF000000);
            }
          });
        }
      }
    });
  animator.start();
  return this;
}
 
Example 2
Source File: BootstrapProgressBar.java    From Android-Bootstrap with MIT License 4 votes vote down vote up
private void initialise(AttributeSet attrs) {
    ValueAnimator.setFrameDelay(15); // attempt 60fps
    tilePaint = new Paint();

    progressPaint = new Paint();
    progressPaint.setStyle(Paint.Style.FILL);
    progressPaint.setAntiAlias(true);

    stripePaint = new Paint();
    stripePaint.setStyle(Paint.Style.FILL);
    stripePaint.setAntiAlias(true);

    textPaint = new Paint();
    textPaint.setStyle(Paint.Style.FILL);
    textPaint.setAntiAlias(true);
    textPaint.setColor(ColorUtils.resolveColor(android.R.color.black, getContext()));
    textPaint.setTextSize(DimenUtils.pixelsFromSpResource(getContext(), R.dimen.bootstrap_progress_bar_default_font_size));

    bgPaint = new Paint();
    bgPaint.setStyle(Paint.Style.FILL);
    bgPaint.setColor(ColorUtils.resolveColor(R.color.bootstrap_gray_light, getContext()));

    // get attributes
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.BootstrapProgressBar);

    try {
        this.animated = a.getBoolean(R.styleable.BootstrapProgressBar_animated, false);
        this.rounded = a.getBoolean(R.styleable.BootstrapProgressBar_roundedCorners, false);
        this.striped = a.getBoolean(R.styleable.BootstrapProgressBar_striped, false);
        this.showPercentage = a.getBoolean(R.styleable.BootstrapProgressBar_bootstrapshowPercentage, false);
        this.userProgress = a.getInt(R.styleable.BootstrapProgressBar_bootstrapProgress, 0);
        this.maxProgress = a.getInt(R.styleable.BootstrapProgressBar_bootstrapMaxProgress, 100);

        int typeOrdinal = a.getInt(R.styleable.BootstrapProgressBar_bootstrapBrand, -1);
        int sizeOrdinal = a.getInt(R.styleable.BootstrapProgressBar_bootstrapSize, -1);

        this.bootstrapSize = DefaultBootstrapSize.fromAttributeValue(sizeOrdinal).scaleFactor();
        this.bootstrapBrand = DefaultBootstrapBrand.fromAttributeValue(typeOrdinal);
        this.drawnProgress = userProgress;
    } finally {
        a.recycle();
    }

    textPaint.setColor(bootstrapBrand.defaultTextColor(getContext()));
    textPaint.setTextSize((DimenUtils.pixelsFromSpResource(getContext(), R.dimen.bootstrap_button_default_font_size)) * this.bootstrapSize );
    updateBootstrapState();
    setProgress(this.userProgress);
    setMaxProgress(this.maxProgress);
}
 
Example 3
Source File: OrreryActivity.java    From AnimationApiDemos with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.orrery_main);

	ImageView orrery = (ImageView) findViewById(R.id.orrery);
	OrreryDrawable myOrreryDrawable = OrreryDrawable.Create();
	orrery.setImageDrawable(myOrreryDrawable);

	// ================================================================
	// 分别控制两种属性的动画
	// PropertyValuesHolder earthPositionValues = PropertyValuesHolder
	// .ofFloat("EarthPosition", 0, (float) (2 * Math.PI));
	// PropertyValuesHolder moonPositionValues =
	// PropertyValuesHolder.ofFloat(
	// "MoonPosition", 0, (float) (2 * Math.PI * 13));
	// ObjectAnimator orreryAnimator =
	// ObjectAnimator.ofPropertyValuesHolder(
	// myOrreryDrawable, earthPositionValues, moonPositionValues);

	// ================================================================
	// 使用新的数据结构,同时控制地球和月球
	OrreryDrawable.SolarSystemData startSolarSystemData = new OrreryDrawable.SolarSystemData();
	startSolarSystemData.rotationEarth = 0;
	startSolarSystemData.rotationMoon = 0;
	OrreryDrawable.SolarSystemData endSolarSystemData = new OrreryDrawable.SolarSystemData();
	endSolarSystemData.rotationEarth = (float) (2 * Math.PI);
	endSolarSystemData.rotationMoon = (float) (2 * Math.PI * 13);
	// 使用自定义的Evaluator
	OrreryEvaluator orreryEvaluator = new OrreryEvaluator();
	// ObjectAnimator orreryAnimator = ObjectAnimator.ofObject(
	// myOrreryDrawable, "SolarSystemData", orreryEvaluator,
	// startSolarSystemData, endSolarSystemData);

	// ================================================================
	// 尝试一下Keyframe
	Keyframe startFrame = Keyframe.ofObject(0, startSolarSystemData);
	Keyframe endFrame = Keyframe.ofObject(1, endSolarSystemData);
	PropertyValuesHolder solarSystemFrames = PropertyValuesHolder
			.ofKeyframe("SolarSystemData", startFrame, endFrame);
	solarSystemFrames.setEvaluator(orreryEvaluator);

	ObjectAnimator orreryAnimator = ObjectAnimator.ofPropertyValuesHolder(
			myOrreryDrawable, solarSystemFrames);

	// Default value is 10
	Log.i("FrameDelay", "delay: " + ValueAnimator.getFrameDelay());
	ValueAnimator.setFrameDelay(50);

	orreryAnimator.setDuration(60000);
	orreryAnimator.setInterpolator(new LinearInterpolator());
	orreryAnimator.setRepeatCount(ValueAnimator.INFINITE);
	orreryAnimator.setRepeatMode(ValueAnimator.RESTART);

	orreryAnimator.start();

	// add the fragment:
	FragmentTransaction ft = getFragmentManager().beginTransaction();

	ft.setCustomAnimations(R.anim.fade_in, android.R.animator.fade_out);
	ft.add(R.id.frame, new OrreryInfo());
	ft.commit();
}