Code example for ValueAnimator

Methods: addListener, addUpdateListener, setDuration, setInterpolator, setValues, start

0
			final int y2, Interpolator interpolator) {
		PropertyValuesHolder pvhX, pvhY;
		pvhX = PropertyValuesHolder.ofInt("x", x1, x2);
		pvhY = PropertyValuesHolder.ofInt("y", y1, y2);
 
		va1 = new ValueAnimator();
		va1.setInterpolator(mInterpolator);
		va1.setValues(pvhX, pvhY);
		va1.setDuration(ANIMATION_DURATION);
 
		va1.addUpdateListener(new AnimatorUpdateListener() {
 
			@Override 
			public void onAnimationUpdate(ValueAnimator animation) {
				int x = (Integer) animation.getAnimatedValue("x");
				int y = (Integer) animation.getAnimatedValue("y");
				if (mSurfaceHolder != null) {
					Canvas canvas = mSurfaceHolder.lockCanvas();
					try { 
						synchronized (mSurfaceHolder) {
							canvas.drawColor(0, PorterDuff.Mode.CLEAR);
							canvas.drawBitmap(mBlobBitmap, x - mBlobWidth / 2,
									y - mBlobWidth / 2, mPaint);
						} 
					} catch (Exception e) {
					} finally { 
						mSurfaceHolder.unlockCanvasAndPost(canvas);
					} 
				} 
			} 
 
		}); 
 
		va1.addListener(new AnimatorListener() {
 
			@Override 
			public void onAnimationCancel(Animator animation) {
			} 
 
			@Override 
			public void onAnimationEnd(Animator vanimation) {
				if (mSurfaceHolder != null && focussedBitmapOverlay != null) {
					ValueAnimator animation = (ValueAnimator) vanimation;
					int x = (Integer) animation.getAnimatedValue("x");
					int y = (Integer) animation.getAnimatedValue("y");
 
					Canvas canvas = mSurfaceHolder.lockCanvas();
					int focussedBitmapOverlayWidth = focussedBitmapOverlay
							.getWidth();
					try { 
						synchronized (mSurfaceHolder) {
							canvas.drawColor(0, PorterDuff.Mode.CLEAR);
							canvas.drawBitmap(mBlobBitmap, x - mBlobWidth / 2,
									y - mBlobWidth / 2, mPaint);
							canvas.drawBitmap(focussedBitmapOverlay, x
									- focussedBitmapOverlayWidth / 2, y
									- focussedBitmapOverlayWidth / 2, mPaint);
						} 
					} catch (Exception e) {
					} finally { 
						mSurfaceHolder.unlockCanvasAndPost(canvas);
					} 
				} 
			} 
 
			@Override 
			public void onAnimationRepeat(Animator animation) {
			} 
 
			@Override 
			public void onAnimationStart(Animator animation) {
			} 
		}); 
		va1.start();
	} 
 
	@Override 
	public void surfaceDestroyed(SurfaceHolder holder) {
		try {