GithubHelp home page GithubHelp logo

florent37 / viewanimator Goto Github PK

View Code? Open in Web Editor NEW
2.7K 71.0 423.0 8.98 MB

A fluent Android animation library

License: Apache License 2.0

Java 99.74% Shell 0.26%
android animation viewanimator view anim path-animation compat

viewanimator's Introduction

ViewAnimator

API Android Arsenal

A fluent Android animation library !

Android app on Google Play

png

Usage

Animate multiple view from one method

ViewAnimator
       .animate(image)
            .translationY(-1000, 0)
            .alpha(0,1)
       .andAnimate(text)
            .dp().translationX(-20, 0)
            .decelerate()
            .duration(2000)
       .thenAnimate(image)
            .scale(1f, 0.5f, 1f)
            .accelerate()
            .duration(1000)
       .start();
       

gif

Without ViewAnimator

AnimatorSet animatorSet = new AnimatorSet();
animatorSet.playTogether(
  ObjectAnimator.ofFloat(image,"translationY",-1000,0),
  ObjectAnimator.ofFloat(image,"alpha",0,1),
  ObjectAnimator.ofFloat(text,"translationX",-200,0)
);
animatorSet.setInterpolator(new DescelerateInterpolator());
animatorSet.setDuration(2000);
animatorSet.addListener(new AnimatorListenerAdapter(){
    @Override public void onAnimationEnd(Animator animation) {

      AnimatorSet animatorSet2 = new AnimatorSet();
      animatorSet2.playTogether(
          ObjectAnimator.ofFloat(image,"scaleX", 1f, 0.5f, 1f),
          ObjectAnimator.ofFloat(image,"scaleY", 1f, 0.5f, 1f)
      );
      animatorSet2.setInterpolator(new AccelerateInterpolator());
      animatorSet2.setDuration(1000);
      animatorSet2.start();

    }
});
animatorSet.start();

More

gif

Add same animation on multiples view

ViewAnimator
       .animate(image,text)
       .scale(0,1)
       .start();

Add listeners

ViewAnimator
       .animate(image)
       .scale(0,1)
       .onStart(() -> {})
       .onStop(() -> {})
       .start();

Use DP values

ViewAnimator
       .animate(image)
       .dp().translationY(-200, 0)
       .start();

Animate Height / Width

ViewAnimator
       .animate(view)
       .waitForHeight() //wait until a ViewTreeObserver notification
       .dp().width(100,200)
       .dp().height(50,100)
       .start();

Color animations

ViewAnimator
       .animate(view)
       .textColor(Color.BLACK,Color.GREEN)
       .backgroundColor(Color.WHITE,Color.BLACK)
       .start();

Rotation animations

ViewAnimator
       .animate(view)
       .rotation(360)
       .start();

Custom animations

ViewAnimator
       .animate(text)
       .custom(new AnimationListener.Update<TextView>() {
            @Override public void update(TextView view, float value) {
                  view.setText(String.format("%.02f",value));
            }
        }, 0, 1)
       .start();

Cancel animations

ViewAnimator viewAnimator = ViewAnimator
       .animate(view)
       .rotation(360)
       .start();

viewAnimator.cancel();

Enhanced animations (Thanks AndroidViewAnimations and NiftyDialogEffects )

.shake().interpolator(new LinearInterpolator());
.bounceIn().interpolator(new BounceInterpolator());
.flash().repeatCount(4);
.flipHorizontal();
.wave().duration(5000);
.tada();
.pulse();
.standUp();
.swing();
.wobble();

... Preview

Path animations ( Inspiration from http://blog.csdn.net/tianjian4592/article/details/47067161 )

    final int[] START_POINT = new int[]{ 300, 270 };
    final int[] BOTTOM_POINT = new int[]{ 300, 400 };
    final int[] LEFT_CONTROL_POINT = new int[]{ 450, 200 };
    final int[] RIGHT_CONTROL_POINT = new int[]{ 150, 200 };
    Path path = new Path();
    path.moveTo(START_POINT[0], START_POINT[1]);
    path.quadTo(RIGHT_CONTROL_POINT[0], RIGHT_CONTROL_POINT[1], BOTTOM_POINT[0], BOTTOM_POINT[1]);
    path.quadTo(LEFT_CONTROL_POINT[0], LEFT_CONTROL_POINT[1], START_POINT[0], START_POINT[1]);
    path.close();
    ViewAnimator.animate(view).path(path).repeatCount(-1).start();

Download

Buy Me a Coffee at ko-fi.com

Add into your build.gradle

Download

compile 'com.github.florent37:viewanimator:1.1.0'

Community

Looking for contributors, feel free to fork !

Credits

Author: Florent Champigny
Contributor: 李玉江(liyujiang)

Fiches Plateau Moto : https://www.fiches-plateau-moto.fr/

Android app on Google Play Follow me on Google+ Follow me on Twitter Follow me on LinkedIn

License

Copyright 2015 florent37, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

viewanimator's People

Contributors

bryant1410 avatar chaunqingren avatar florent37 avatar liyujiang-gzu avatar qinglinyi avatar shahimclt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

viewanimator's Issues

Problem with looping to define an animation

Hello.

I would like to make a loop and modify the ViewAnimator on the go.

So, theorically making this:

    ViewAnimator viewAnimator = ViewAnimator.animate(heart_progress).translationY(0, heart_progress.getHeight() / maxSeconds).descelerate().duration(1000);
    for (int i = 1; i < maxSeconds; i++) {

        final int finalI = i;
        viewAnimator.thenAnimate(heart_progress).translationY((i % maxSeconds) * heart_progress.getHeight() / maxSeconds, ((i + 1) % maxSeconds) * heart_progress.getHeight() / maxSeconds).descelerate().onStart(new AnimationListener.Start() {
            @Override
            public void onStart() {
                System.out.println("animation #"+ finalI);
            }
        }).duration(1000);
    }

    viewAnimator.start();

would be the same than doing this:

    ViewAnimator viewAnimator = ViewAnimator.animate(heart_progress).translationY(0, heart_progress.getHeight() / maxSeconds).descelerate().duration(1000).
    thenAnimate(heart_progress).translationY((1 % maxSeconds) * heart_progress.getHeight() / maxSeconds, ((1 + 1) % maxSeconds) * heart_progress.getHeight() / maxSeconds).descelerate().onStart(new AnimationListener.Start() {
        @Override
        public void onStart() {
            System.out.println("animation #"+ 1);
        }
    }).duration(900).
            thenAnimate(heart_progress).translationY((2 % maxSeconds) * heart_progress.getHeight() / maxSeconds, ((2 + 1) % maxSeconds) * heart_progress.getHeight() / maxSeconds).descelerate().onStart(new AnimationListener.Start() {
        @Override
        public void onStart() {
            System.out.println("animation #"+ 2);
        }
    }).duration(900).
            thenAnimate(heart_progress).translationY((3 % maxSeconds) * heart_progress.getHeight() / maxSeconds, ((3 + 1) % maxSeconds) * heart_progress.getHeight() / maxSeconds).descelerate().onStart(new AnimationListener.Start() {
        @Override
        public void onStart() {
            System.out.println("animation #"+ 3);
        }
    }).duration(900).
            thenAnimate(heart_progress).translationY((4 % maxSeconds) * heart_progress.getHeight() / maxSeconds, ((4 + 1) % maxSeconds) * heart_progress.getHeight() / maxSeconds).descelerate().onStart(new AnimationListener.Start() {
        @Override
        public void onStart() {
            System.out.println("animation #"+ 4);
        }
    }).duration(900).
            thenAnimate(heart_progress).translationY((5 % maxSeconds) * heart_progress.getHeight() / maxSeconds, ((5 + 1) % maxSeconds) * heart_progress.getHeight() / maxSeconds).descelerate().onStart(new AnimationListener.Start() {
        @Override
        public void onStart() {
            System.out.println("animation #"+ 5);
        }
    }).duration(900).
            thenAnimate(heart_progress).translationY((6 % maxSeconds) * heart_progress.getHeight() / maxSeconds, ((6 + 1) % maxSeconds) * heart_progress.getHeight() / maxSeconds).descelerate().onStart(new AnimationListener.Start() {
        @Override
        public void onStart() {
            System.out.println("animation #"+ 6);
        }
    }).duration(900).start();

but the result is pretty different:

CORRECT
heart_correct

(please allow some time to load the GIF and an offset to start the video :D)

WRONG
heart_wrong

(please allow some time to load the GIF and an offset to start the video :D)

What's wrong with the for loop?

Thanks.

Unable to Cancel

Hi,

I have the following...

` viewAnimator
.animate(statusIcon)
.rotation(360).repeatCount(8)

         .interpolator(new LinearInterpolator())

            .start();`

I cant seem to get it to cancel... please help!

Feature: Add `ValueAnimator` add on

Hey @florent37, great library by the way! This issue more a proposition for new feature than an issue. What are your thoughts on extending this library to have a pure ValueAnimator animation builder where the end-user can use it to animate values rather than views as well?

Null pointer Exception when combining fadein and fadeout animation

Hi, trying to animate by button with the following code but getting null exception not from my code but from internal code.

ViewAnimator.animate(binding.liveFavorite)
.zoomIn()
.fadeOut()
.custom(AnimationListener.Update { view, _ -> view.setImageResource(R.drawable.ic_bookmarked) } )
.fadeIn()
.zoomOut()
.start()

Stacktrace:

FATAL EXCEPTION: main
Process: com.dbeginc.dbweather, PID: 5806
java.lang.NullPointerException: Attempt to get length of null array
at android.animation.ValueAnimator.initAnimation(ValueAnimator.java:534)
at android.animation.ValueAnimator.startAnimation(ValueAnimator.java:1263)
at android.animation.ValueAnimator.access$100(ValueAnimator.java:67)
at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:724)
at android.animation.ValueAnimator$AnimationHandler$1.run(ValueAnimator.java:801)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:896)
at android.view.Choreographer.doCallbacks(Choreographer.java:698)
at android.view.Choreographer.doFrame(Choreographer.java:630)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:882)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5795)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:768)

Animation Timeline

Hi Guys,

I cant seem to find a way to acheive this animation

Fade in -> pause(3000) -> fadeout -> pause(3000) -> restart

I can only find startDelay but this does add a delay after a transition

Can you please help

Build failed

Program type already present: android.support.v4.app.FragmentTransitionCompat21$1

Unable to repeat animation with timer

I'm experimenting an issue trying to repeating an animation with a timer. I have the following method:

ViewAnimator.animate(buttonStart) .rotation(360) .duration(2000) .decelerate() .start();

And a timer which call this methods every 4 seconds. It works always the first time but never again in the sequence although the method call is working. Why is this happening? Why I only can call to the animation once? Am I doing something wrong?

Problem when animating width

When i try to animate width it just go left without change width then only when it finish the animation the view change the width.

ViewAnimator code:

ViewAnimator.animate(cardView)
   .scale(0,1)
   .duration(300)
   .thenAnimate(cardView)
   .dp().width(36,200)
   .duration(200)
   .start();

XML code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true" >
    <android.support.v7.widget.CardView
        android:id="@+id/fave_card"
        android:layout_width="wrap_content"
        android:layout_height="36dp"
        android:minWidth="36dp"
        android:layout_margin="16dp"
        app:cardBackgroundColor="@color/primary_light"
        app:cardCornerRadius="18dp">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center"
            android:layout_gravity="center">
            <ImageView
                android:id="@+id/fave_image"
                android:layout_width="36dp"
                android:layout_height="36dp"
                android:layout_gravity="center_vertical"
                android:gravity="center_vertical"/>
            <TextView
                android:id="@+id/fave_text"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center_vertical"
                android:gravity="center_vertical"
                tools:text="Placeholder"/>
        </LinearLayout>
    </android.support.v7.widget.CardView>
</LinearLayout>

your app in google play

java.lang.NoSuchFieldError: No field zzcsl of type Ljava/lang/Object; in class Lcom/google/android/gms/internal/adn; or its superclasses (declaration of 'com.google.android.gms.internal.adn' appears in /data/app/com.florent37.github.florent.champigny-1/base.apk)
at com.google.android.gms.internal.zzay.zzo(Unknown Source)
at com.google.android.gms.internal.zzax.(Unknown Source)
at com.google.android.gms.internal.zzcar.zzvy(Unknown Source)
at com.google.android.gms.internal.zzcar.onConnectionFailed(Unknown Source)
at com.google.android.gms.common.internal.zzn.zzj(Unknown Source)
at com.google.android.gms.common.internal.zze.zzs(Unknown Source)
at com.google.android.gms.common.internal.zzi.zzrk(Unknown Source)
at com.google.android.gms.common.internal.zzh.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.os.HandlerThread.run(HandlerThread.java:61)

Library is broken from 1.0.1 to 1.0.2

animation = ViewAnimator
.animate(logo).scaleX(0, 1).scaleY(0, 1).alpha(0, 1).descelerate().duration(500)
.thenAnimate(logo).scaleX(1, 0).scaleY(1, 0).alpha(1, 0).accelerate().duration(500);

descelerate cannot exists...

i got a memory leak with Animator$AnimatorListener

  • android.arch.lifecycle.ReportFragment has leaked:
  • static Choreographer.!(mMainInstance)!
  • ↳ Choreographer.!(mCallbackQueues)!
  • ↳ array Choreographer$CallbackQueue[].!([1])!
  • ↳ Choreographer$CallbackQueue.!(mHead)!
  • ↳ Choreographer$CallbackRecord.!(action)!
  • ↳ AnimationHandler$1.!(this$0)! (anonymous implementation of android.view.Choreographer$FrameCallback)
  • ↳ AnimationHandler.!(mAnimationCallbacks)!
  • ↳ ArrayList.!(elementData)!
  • ↳ array Object[].!([2])!
  • ↳ AnimatorSet.!(mListeners)!
  • ↳ ArrayList.!(elementData)!
  • ↳ array Object[].!([0])!
  • ↳ ViewAnimator$1.!(this$0)! (anonymous implementation of android.animation.Animator$AnimatorListener)
  • ↳ ViewAnimator.!(animationList)!
  • ↳ ArrayList.!(elementData)!
  • ↳ array Object[].!([0])!
  • ↳ AnimationBuilder.!(views)!
  • ↳ array View[].!([0])!
  • ↳ AppCompatImageView.mContext
  • ↳ PerformanceAty.mFragments
  • ↳ FragmentController.mHost
  • ↳ Activity$HostCallbacks.mFragmentManager
  • ↳ FragmentManagerImpl.mAdded
  • ↳ ArrayList.elementData
  • ↳ array Object[].[0]
  • ↳ ReportFragment

my code is :

public static void viewScaleButtonAnimation(View... view) {
    ViewAnimator.animate(view).scale(1, 1.05f, 1).duration(3000)
            .repeatCount(-1).start();
}

how can i release this anim??

How to animate layout

I want to animate a layout like this

ViewAnimator
.animate(layout)
.translationY(-1000, 0)
.alpha(0,1)
.start();

But unfortunately this doesn't work. How to Make it work

repeatMode(ValueAnimator.INFINITE) doesn't work

Hello,

Here is my code:

ViewAnimator viewAnimator = ViewAnimator.animate(textView)
                .tada()
                .duration(4000)
                .repeatMode(ValueAnimator.INFINITE)
                .start();

The animation works but the 'ValueAnimator.INFINITE' value (which is an enum that is equal to "-1") doesn't work to make the animation loop indefinitely.

Could someone help me to find the issue?

thenAnimate() method is ignored when used before andAnimate() method

thenAnimate() method is ignored when used before andAnimate() method.
in my example the background animation won't be played:

    ViewAnimator
                     //increase play icon's opacity
            .animate(playLogo)
            .alpha(1)
            .startDelay((long) (ANIMATION_DURATION * 0.2f))
            .duration(1)
                     //then fade the background in
            .thenAnimate(background)
            .alpha(0, 1)
            .duration((long) (ANIMATION_DURATION * 0.7f))
            .interpolator(new AccelerateDecelerateInterpolator())
            .onStart(() -> background.setVisibility(View.VISIBLE))
                    //and rotate and scale the play icon & the logo
            .andAnimate(playLogo, varaLogo)
            .rotation(0, -6 * 360)
            .scale(1, 1.25f)
            .startDelay((long) (ANIMATION_DURATION * 0.1f))
            .duration((long) (ANIMATION_DURATION * 0.4f))
            .interpolator(new AccelerateDecelerateInterpolator())
            .onStart(() -> {
                switchIconAndLogoWithDelay();
                startBackgroundAnimation();
            })
                    //after it, scale the logo a bit more
            .thenAnimate(varaLogo)
            .scale(1.25f, 1.35f)
            .duration((long) (ANIMATION_DURATION * 0.4f))
            .start();

Stop animation

There is a way (method) to stop an animation started?

Cancel?

Please can you add Cancel method to AnimationBuilder?

Pivot on Scale?

Hello, I'm trying to do the pivot when scaling, but no success. Have you try this before?
Thanks!

Starting animation from visibility GONE

Hi,
I'm trying to animate a view when it's starting visibility state is View.GONE.
When setting view visibility on animation start to View.VISIBLE, the animation results in a very short blink because of the visibility change.
Can you recommend me maybe a better way to animate the view with a starting state of View.GONE?

Code:

ViewAnimator
.animate(view)
.onStart(new AnimationListener.Start() {
		@Override
		public void onStart()
			{
				view.setVisibility(View.VISIBLE);
			}
		})
.duration(400)
.zoomIn()
.start();

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.