lmoura
4/9/2019 - 7:36 PM

Animation Class with AnimationListener

Animation Class with AnimationListener

package com.costaemoura.luis.kanbanlauncher;

import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.Transformation;

/**
 * Animation for opening and closing Views
 *
 */
public class DropDownAnim extends Animation implements AnimationListener {
    private final int _targetHeight;
    private final View _view;
    private final boolean _down;

    DropDownAnim(View view, int targetHeight) {
        _view = view;
        _targetHeight = targetHeight;
        _down = view.getLayoutParams().height==0;

        setDuration(KanbanApp.animSpeed);
        setAnimationListener(this);
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        int newHeight;
        if (_down) {
            newHeight = (int) (_targetHeight * interpolatedTime);
        } else {
            newHeight = (int) (_targetHeight * (1 - interpolatedTime));
        }
        _view.getLayoutParams().height = newHeight;
        _view.requestLayout();
    }

    @Override
    public void initialize(int width, int height, int parentWidth, int parentHeight) {
        super.initialize(width, height, parentWidth, parentHeight);
    }

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

    @Override
    public void onAnimationStart(Animation animation) {
        Log.e("DROPDOWNANIM", "STARTING!!");
    }

    @Override
    public void onAnimationEnd(Animation animation) {
        Log.e("DROPDOWNANIM", "JÁ ESTÁ!!");
    }

    @Override
    public void onAnimationRepeat(Animation animation) {
        Log.e("DROPDOWNANIM", "DOING IT!!");
    }
}