package com.sharefaith.thesharefaithapp.ui;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;

/**
 * Created by Sharefaith1 on 2014-11-11.
 *
 * Animator to make a list item expand/contract
 *
 * NO LONGER BEING USED USING XML RES INSTEAD. IT IS MORE EFFICIENT. SEE RES/ANIM
 * @deprecated
 */
public class SFAnimations extends Animation
{

	public SFAnimations()
	{
		super();
	}

	public SFAnimations( Context context, AttributeSet attrs)
	{
		super( context, attrs );
	}

	@Override
	protected void applyTransformation( float interpolatedTime, Transformation t )
	{

	}

	@Override
	public void initialize( int width, int height, int parentWidth, int parentHeight )
	{

	}

	@Override
	public boolean willChangeBounds()
	{
		return true;
	}

	public static void fadeIn( View view, int duration )
	{
		view.setVisibility( View.VISIBLE );
		view.requestLayout();
		ObjectAnimator in = ObjectAnimator.ofFloat( view, "alpha", 1f );
		in.setDuration( duration );
		in.addListener( SFAnimations.fadeCompletion( view, "in" ) );
		in.start();
	}

	public static void fadeOut( View view, int duration )
	{
		ObjectAnimator in = ObjectAnimator.ofFloat( view, "alpha", 0f );
		in.setDuration( duration );
		in.addListener( SFAnimations.fadeCompletion( view, "out" ) );

		in.start();
	}

	public static Animator.AnimatorListener fadeCompletion( final View view, final String inOrOut )
	{
		return new Animator.AnimatorListener()
		{
			@Override
			public void onAnimationStart( Animator animator )
			{

			}

			@Override
			public void onAnimationEnd( Animator animator )
			{
				if( inOrOut.equals( "out" ) )
				{
					view.setVisibility( View.INVISIBLE );
				}
				//view.invalidate();
			}

			@Override
			public void onAnimationCancel( Animator animator )
			{

			}

			@Override
			public void onAnimationRepeat( Animator animator )
			{

			}
		};
	}

}
