Code example for ValueAnimator

Methods: addListener, setDuration, setFloatValues

0
	} 
	 
	private final void animateNewGame(){ 
		if(message.getResults().isStartNewGame()){
			ValueAnimator animator = getDummyAnimator();
			animator.addListener(new NewGame());
			animator.addListener(new SyncListener());
			animators.add(animator);
		} 
	} 
	 
	private final void animateGameOver(){ 
		if(message.isGameOver() && !message.getResults().followUpMove()){
			DisplayableString gameOver = getDisplayString("GAME OVER", Color.MAGENTA);
			float shift = view.getBoardView().getWidth()/10f;
			float left = gameOver.getLocation().getLeft() - shift;
			float right = gameOver.getLocation().getLeft() + shift;
			float top = gameOver.getLocation().getTop();
			float stopTop = view.getBoardView().getHeight()/8f;
			DisplayLocation center = gameOver.getLocation();
			DisplayLocation l = new DisplayLocation(left, top);
			DisplayLocation r = new DisplayLocation(right, top);
			List<DisplayLocation> locations = new LinkedList<DisplayLocation>();
			for(int i = 0; i < 3; i++){
				locations.add(l);
				locations.add(r);
			} 
			locations.add(center);
			 
			ValueAnimator animation = gameOver.createAnimator(locations);
			animation.setDuration(500);
			animation.setStartDelay(100);
			ValueAnimator animation2 = gameOver.createAnimator(Collections.singletonList(new DisplayLocation(center.getLeft(), stopTop)));
			animation2.setStartDelay(1100);
			animation2.setDuration(3200);
			animation.addListener(new GameOverListener(gameOver));
			animators.add(animation2);
			animators.add(animation);
		} 
	} 
	 
	private final void animateCombo(){ 
		int streak = message.getStreak()-1;
		if(!message.getResults().followUpMove() && streak > 1){
			String name = null;
			switch(streak){
			case 2: 
				name = "DUECE";
				break; 
			case 3: 
				name = "TRIPLE";
				break; 
			case 4: 
				name = "DOUBLE DEUCE";
				break; 
			case 5: 
				name = "HIGH FIVE";
				break; 
			default: 
				name  = streak + "-STREAK";				
			} 
			DisplayableString string = getDisplayString(name, Color.RED);
			ValueAnimator animation = getStringAnimation(string);
			animation.setStartDelay(100);
			animation.setDuration(800);
			animators.add(animation);
		} 
	} 
	 
	private final DisplayableString getDisplayString(String string, int color){
		float left = view.getBoardView().getWidth()/2f;
		float top = view.getBoardView().getHeight()/2f;
		DisplayLocation start = calculateCenter(left, top, string.length());
		DisplayableString ds = new DisplayableString(string, start, view.getBoardView(), color);
		return ds;
	} 
	 
	private final ValueAnimator getStringAnimation(DisplayableString ds){
		DisplayLocation start = ds.getLocation();
		float distanceUp = view.getBoardView().getHeight()/4f;
		DisplayLocation end = new DisplayLocation(start.getLeft(), start.getTop()-distanceUp);
		ValueAnimator animation = ds.createAnimator(Collections.singletonList(end));
		animation.addListener(new StringListener(ds));
		return animation;
	} 
	 
	private final void animateBonusMoves(){ 
		int moves = message.getMovesChange();
		if(moves > 0){
			DisplayableString string = getDisplayString("+" + moves, Color.GREEN);
			ValueAnimator animation = getStringAnimation(string);
			animation.setStartDelay(100);
			animation.setDuration(500);
			animators.add(animation);
		} 
	} 
	 
	private final void animatePoints(){ 
		int points = message.getPointsAwarded();
		if(points > 0){
			DisplayableString string = getDisplayString(""+points, Color.YELLOW);
			ValueAnimator animation = getStringAnimation(string);
			animators.add(animation);
			animation = getDummyAnimator();
			animation.addListener(new SoundListener(SFX.WOOSH));
			animators.add(animation);
		} 
	} 
	 
	private final ValueAnimator getDummyAnimator(){
		ValueAnimator animator = new ValueAnimator();
		animator.setFloatValues(1.0f);
		animator.setDuration(1);
		return animator;
	} 
	 
	private final DisplayLocation calculateCenter(float left, float top, int length){
		float middle = length/2f;