Android Open Source - Calma Animation Utils






From Project

Back to project page Calma.

License

The source code is released under:

Apache License

If you think the Android project Calma listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.espian.showcaseview.anim;
//from ww w.  j a  va2 s.  c  om
import android.os.Handler;
import android.view.View;

import com.nineoldandroids.animation.Animator;
import com.nineoldandroids.animation.AnimatorSet;
import com.nineoldandroids.animation.ObjectAnimator;
import com.nineoldandroids.view.ViewHelper;

public class AnimationUtils {

    public static final int DEFAULT_DURATION = 300;

    private static final String ALPHA = "alpha";
    private static final float INVISIBLE = 0f;
    private static final float VISIBLE = 1f;
    private static final String COORD_X = "x";
    private static final String COORD_Y = "y";
    private static final int INSTANT = 0;

    public interface AnimationStartListener {
        void onAnimationStart();
    }

    public interface AnimationEndListener {
        void onAnimationEnd();
    }

    public static float getX(View view) {
        return ViewHelper.getX(view);
    }

    public static float getY(View view) {
        return ViewHelper.getY(view);
    }

    public static void hide(View view) {
        ViewHelper.setAlpha(view, INVISIBLE);
    }

    public static ObjectAnimator createFadeInAnimation(Object target, final AnimationStartListener listener) {
        return createFadeInAnimation(target, DEFAULT_DURATION, listener);
    }

    public static ObjectAnimator createFadeInAnimation(Object target, int duration, final AnimationStartListener listener) {
        ObjectAnimator oa = ObjectAnimator.ofFloat(target, ALPHA, INVISIBLE, VISIBLE);
        oa.setDuration(duration).addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animator) {
                listener.onAnimationStart();
            }

            @Override
            public void onAnimationEnd(Animator animator) {
            }

            @Override
            public void onAnimationCancel(Animator animator) {
            }

            @Override
            public void onAnimationRepeat(Animator animator) {
            }
        });
        return oa;
    }

    public static ObjectAnimator createFadeOutAnimation(Object target, final AnimationEndListener listener) {
        return createFadeOutAnimation(target, DEFAULT_DURATION, listener);
    }

    public static ObjectAnimator createFadeOutAnimation(Object target, int duration, final AnimationEndListener listener) {
        ObjectAnimator oa = ObjectAnimator.ofFloat(target, ALPHA, INVISIBLE);
        oa.setDuration(duration).addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animator) {
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                listener.onAnimationEnd();
            }

            @Override
            public void onAnimationCancel(Animator animator) {
            }

            @Override
            public void onAnimationRepeat(Animator animator) {
            }
        });
        return oa;
    }

    public static AnimatorSet createMovementAnimation(View view, float canvasX, float canvasY,
                                                      float offsetStartX, float offsetStartY,
                                                      float offsetEndX, float offsetEndY,
                                                      final AnimationEndListener listener) {
        ViewHelper.setAlpha(view, INVISIBLE);

        ObjectAnimator alphaIn = ObjectAnimator.ofFloat(view, ALPHA, INVISIBLE, VISIBLE).setDuration(500);

        ObjectAnimator setUpX = ObjectAnimator.ofFloat(view, COORD_X, canvasX + offsetStartX).setDuration(INSTANT);
        ObjectAnimator setUpY = ObjectAnimator.ofFloat(view, COORD_Y, canvasY + offsetStartY).setDuration(INSTANT);

        ObjectAnimator moveX = ObjectAnimator.ofFloat(view, COORD_X, canvasX + offsetEndX).setDuration(1000);
        ObjectAnimator moveY = ObjectAnimator.ofFloat(view, COORD_Y, canvasY + offsetEndY).setDuration(1000);
        moveX.setStartDelay(1000);
        moveY.setStartDelay(1000);

        ObjectAnimator alphaOut = ObjectAnimator.ofFloat(view, ALPHA, INVISIBLE).setDuration(500);
        alphaOut.setStartDelay(2500);

        AnimatorSet as = new AnimatorSet();
        as.play(setUpX).with(setUpY).before(alphaIn).before(moveX).with(moveY).before(alphaOut);

        Handler handler = new Handler();
        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                listener.onAnimationEnd();
            }
        };
        handler.postDelayed(runnable, 3000);

        return as;
    }

    public static AnimatorSet createMovementAnimation(View view, float x, float y) {
        ObjectAnimator alphaIn = ObjectAnimator.ofFloat(view, ALPHA, INVISIBLE, VISIBLE).setDuration(500);

        ObjectAnimator setUpX = ObjectAnimator.ofFloat(view, COORD_X, x).setDuration(INSTANT);
        ObjectAnimator setUpY = ObjectAnimator.ofFloat(view, COORD_Y, y).setDuration(INSTANT);

        AnimatorSet as = new AnimatorSet();
        as.play(setUpX).with(setUpY).before(alphaIn);
        return as;
    }
}




Java Source Code List

com.cyanogenmod.filemanager.activities.preferences.SettingsPreferences.java
com.espian.showcaseview.OnShowcaseEventListener.java
com.espian.showcaseview.ShowcaseViewBuilder.java
com.espian.showcaseview.ShowcaseView.java
com.espian.showcaseview.ShowcaseViews.java
com.espian.showcaseview.actionbar.ActionBarViewWrapper.java
com.espian.showcaseview.actionbar.reflection.ActionBarReflector.java
com.espian.showcaseview.actionbar.reflection.AppCompatReflector.java
com.espian.showcaseview.actionbar.reflection.BaseReflector.java
com.espian.showcaseview.actionbar.reflection.SherlockReflector.java
com.espian.showcaseview.anim.AnimationUtils.java
com.espian.showcaseview.drawing.ClingDrawerImpl.java
com.espian.showcaseview.drawing.ClingDrawer.java
com.espian.showcaseview.drawing.TextDrawerImpl.java
com.espian.showcaseview.drawing.TextDrawer.java
com.espian.showcaseview.targets.ActionItemTarget.java
com.espian.showcaseview.targets.ActionViewTarget.java
com.espian.showcaseview.targets.PointTarget.java
com.espian.showcaseview.targets.Target.java
com.espian.showcaseview.targets.ViewTarget.java
com.espian.showcaseview.utils.Calculator.java
com.espian.showcaseview.utils.PointAnimator.java
com.espian.showcaseview.utils.ShowcaseAreaCalculator.java
com.scto.android.calma.CalmaApp.java
com.scto.android.calma.activities.BaseActivity.java
com.scto.android.calma.activities.CalmaActivity.java
com.scto.android.calma.activities.SettingsActivity.java
com.scto.android.calma.activities.preferences.AboutPreferenceFragment.java
com.scto.android.calma.activities.preferences.DisplayPreferenceFragment.java
com.scto.android.calma.activities.preferences.GeneralPreferenceFragment.java
com.scto.android.calma.activities.preferences.NavigationPreferenceFragment.java
com.scto.android.calma.activities.preferences.SettingsActivity.java
com.scto.android.calma.activities.preferences.TitlePreferenceFragment.java
com.scto.android.calma.adapter.NavDrawerListAdapter.java
com.scto.android.calma.fragments.CommunityFragment.java
com.scto.android.calma.fragments.FindPeopleFragment.java
com.scto.android.calma.fragments.HomeFragment.java
com.scto.android.calma.fragments.PagesFragment.java
com.scto.android.calma.fragments.PhotosFragment.java
com.scto.android.calma.fragments.WhatsHotFragment.java
com.scto.android.calma.model.NavDrawerItem.java
com.scto.android.calma.preferences.AccessMode.java
com.scto.android.calma.preferences.CalmaSettings.java
com.scto.android.calma.preferences.ConfigurationListener.java
com.scto.android.calma.preferences.ObjectIdentifier.java
com.scto.android.calma.preferences.ObjectStringIdentifier.java
com.scto.android.calma.preferences.Preferences.java
com.scto.android.calma.ui.MyPrerference.java
com.scto.android.calma.utils.CalmaUtils.java
com.scto.android.calma.utils.Compress.java
com.scto.android.calma.utils.Decompress.java
com.scto.android.calma.utils.FileUtils.java
com.scto.android.calma.utils.LinuxShell.java
com.scto.android.calma.utils.PreferenceUtils.java
com.scto.android.calma.utils.SharedPreferencesCompat.java
com.scto.android.calma.utils.SortOrder.java
com.scto.android.calma.utils.Utils.java
com.stericson.RootTools.Constants.java
com.stericson.RootTools.RootTools.java
com.stericson.RootToolsTests.NativeJavaClass.java
com.stericson.RootToolsTests.SanityCheckRootTools.java
com.stericson.RootTools.containers.Mount.java
com.stericson.RootTools.containers.Permissions.java
com.stericson.RootTools.containers.RootClass.java
com.stericson.RootTools.containers.Symlink.java
com.stericson.RootTools.exceptions.RootDeniedException.java
com.stericson.RootTools.execution.CommandCapture.java
com.stericson.RootTools.execution.Command.java
com.stericson.RootTools.execution.JavaCommandCapture.java
com.stericson.RootTools.execution.Shell.java
com.stericson.RootTools.internal.Installer.java
com.stericson.RootTools.internal.InternalVariables.java
com.stericson.RootTools.internal.Remounter.java
com.stericson.RootTools.internal.RootToolsInternalMethods.java
com.stericson.RootTools.internal.Runner.java