Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.view.View;

import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;

import android.view.animation.Interpolator;
import android.view.animation.Transformation;

public class Main {
    /**
     * Expanding the view into matching the parent size
     *
     * @param v the target view
     */
    public static void expand(final View v, int targetHeight) {
        int initialHeight = v.getMeasuredHeight();
        int diffHeight = targetHeight - initialHeight;
        expand(v, diffHeight, 500, new AccelerateInterpolator(2), null);
    }

    public static void expand(final View v, final int targetHeight, int duration, Interpolator interpolator,
            final Animation.AnimationListener listener) {
        final int initialHeight = v.getMeasuredHeight();
        Animation a = new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
                v.getLayoutParams().height = initialHeight + (int) (targetHeight * interpolatedTime);
                v.requestLayout();
            }

            @Override
            public boolean willChangeBounds() {
                return true;
            }
        };
        a.setDuration(duration);
        if (interpolator != null) {
            a.setInterpolator(interpolator);
        }
        a.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
                v.setLayerType(View.LAYER_TYPE_HARDWARE, null);
                if (listener != null)
                    listener.onAnimationStart(animation);
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                v.setLayerType(View.LAYER_TYPE_NONE, null);
                if (listener != null)
                    listener.onAnimationEnd(animation);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
                if (listener != null)
                    onAnimationRepeat(animation);
            }
        });

        v.startAnimation(a);
    }
}