Applies a specific animation for transitioning back a screen. - Android Animation

Android examples for Animation:Animation Creation

Description

Applies a specific animation for transitioning back a screen.

Demo Code

// Copyright 2009-2011 Google, All Rights reserved
import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.TranslateAnimation;

public class Main{
    /**/* w ww  . j a va2s  .c  om*/
     * Applies a specific animation for transitioning back a screen.
     *
     * @param activity - the form which is closing
     * @param animType - the animation type
     */
    public static void ApplyCloseScreenAnimation(Activity activity,
            String animType) {
        if (animType == null) {
            return;
        }
        if (SdkLevel.getLevel() <= SdkLevel.LEVEL_DONUT) {
            Log.e("AnimationUtil",
                    "Screen animations are not available on android versions less than 2.0.");
            return;
        }
        int enter = 0;
        int exit = 0;
        if (animType.equalsIgnoreCase("fade")) {
            exit = activity.getResources().getIdentifier("fadeout", "anim",
                    activity.getPackageName());
            enter = activity.getResources().getIdentifier("hold", "anim",
                    activity.getPackageName());
        } else if (animType.equalsIgnoreCase("zoom")) {
            exit = activity.getResources().getIdentifier(
                    "zoom_exit_reverse", "anim", activity.getPackageName());
            enter = activity.getResources()
                    .getIdentifier("zoom_enter_reverse", "anim",
                            activity.getPackageName());
        } else if (animType.equalsIgnoreCase("slidehorizontal")) {
            exit = activity.getResources()
                    .getIdentifier("slide_exit_reverse", "anim",
                            activity.getPackageName());
            enter = activity.getResources().getIdentifier(
                    "slide_enter_reverse", "anim",
                    activity.getPackageName());
        } else if (animType.equalsIgnoreCase("slidevertical")) {
            exit = activity.getResources().getIdentifier(
                    "slide_v_exit_reverse", "anim",
                    activity.getPackageName());
            enter = activity.getResources().getIdentifier(
                    "slide_v_enter_reverse", "anim",
                    activity.getPackageName());
        } else if (animType.equalsIgnoreCase("none")) {
            // enter and exit are already set to 0, so
            // no animations will be played.
        } else {
            // Return here so overridePendingTransitions isn't run, and android
            // does it's default thing.
            return;
        }
        EclairUtil.overridePendingTransitions(activity, enter, exit);
    }
}

Related Tutorials