B4A Library [Lib] AnimationPlus

Hello everybody,

Here's my new baby. The AnimationPlus library extends the Animation library by adding:
  • the interpolators (Bounce, Accelerate, Overshoot, Cycle, etc.)
  • two parameters:
    PersistAfter (boolean): if True, the animation does not revert to its initial state
    StartOffset (long): delay before the animation really starts
  • AnimationSet (animations on the same view are played together)
  • four new Drawables:
    AnimationDrawable: image-by-image animation
    ClipDrawable: drawable with automatic clipping (ideal for progress bars)
    LayerDrawable: multi-layer drawable
    TransitionDrawable: cross-fade between two drawables
  • for translation animations:
    PauseTranslation/ResumeTranslation/IsPaused: new functions to pause/resume the animation
    AnimationRepeat: new event
List of properties and methods

If you want a library with more possibilities, and easy to use, give a try to NineOldAndroids.

Examples : https://drive.google.com/file/d/0B-kneWWcCy7PUTNERGJIamlzSjA/view?usp=sharing&resourcekey=0-LK97oJs9aV-UHK4CWY0utw
 

Attachments

  • AnimationPlus v2.3.zip
    12.7 KB · Views: 4,368
Last edited:

Informatix

Expert
Licensed User
Longtime User
I think you agree that, for my purpose, a simple Tag property (a simple identifier) would be enough ;)

[I could use a module variable to store the number of events fired, but if @Informatix wants to add this property...!]
For readability of code, a variable named "LastAnimation" is more understandable than "Tag".
Anyway, AnimationPlus should be used only for very simple animations because it is very limited. Here are the alternatives (sorted by number of features/complexity):
NineOldAndroids
Accelerated Surface
LibGDX
 

LucaMs

Expert
Licensed User
Longtime User
For readability of code, a variable named "LastAnimation" is more understandable than "Tag".
Anyway, AnimationPlus should be used only for very simple animations because it is very limited. Here are the alternatives (sorted by number of features/complexity):
NineOldAndroids
Accelerated Surface
LibGDX

Yes, I know these your beautiful works ;).

I wanted to avoid using libGDX because I need only one effect and the library weighs 2/3 MB, if I remember correctly; but I think I'll have to use it because
I was able to get almost the desired effect using AnimationPlus but I would also "need" rotation of views together with movement, scaling and fading.
 

Informatix

Expert
Licensed User
Longtime User
Yes, I know these your beautiful works ;).

I wanted to avoid using libGDX because I need only one effect and the library weighs 2/3 MB, if I remember correctly; but I think I'll have to use it because
I was able to get almost the desired effect using AnimationPlus but I would also "need" rotation of views together with movement, scaling and fading.
Then use NineOldAndroids. You don't need something as complex as libGDX (and it's not for views).
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
I would also "need" rotation of views together with movement, scaling and fading
Before giving up on the AnimationPlus library, look at the AnimationSet object -- it allows you to apply multiple transitions to one animation.
 

LucaMs

Expert
Licensed User
Longtime User
Before giving up on the AnimationPlus library, look at the AnimationSet object -- it allows you to apply multiple transitions to one animation.

I'm using AnimationSet. You can add objects of type AnimationPlus to it (indeed I added 3 anims: Translate, Alpha and ScaleCenter) but if I add RotationCenter the rotation will be applied to the group (set), not to the view, "unfortunately".

Thank you, @Jeffrey Cameron
 

LucaMs

Expert
Licensed User
Longtime User
I'm using AnimationSet. You can add objects of type AnimationPlus to it (indeed I added 3 anims: Translate, Alpha and ScaleCenter) but if I add RotationCenter the rotation will be applied to the group (set), not to the view, "unfortunately".

Thank you, @Jeffrey Cameron


I just tried again, moving the addition of the RotationCenter animation on top and it works :)

Thank you again.
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
That looks very nice!

You're very welcome, and I'm happy to help. I've banged my head against this particular wall far too many times ;)

And thanks to Informatix for his hard work making this library :)
 

LucaMs

Expert
Licensed User
Longtime User
Hi, @Informatix

This is strange.

I move (InitializeTranslate with PersistAfter) an ImageView and at the end of the animation I can see the view in the new right place but its coordinates are the same as before the animation.

I mean:
ImageView1.Left = 100dip
ImaveView1.Top = 100dip

...InitializeTranslate("Anim", 0, 0, 50dip, 50dip)
...PersistAfter = True

after the animation, ImageView1.Left should be 150dip (same Top) instead it is still 100dip.

Then, if I run another animation on the same view, I get "wrong results".
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
Activity.NumberOfViews returns 2 !

(of course, the view cannot be in the new position AND have different coordinates).

The view I can see is a duplicate and after the animation there 2 views on my activity.

2 hours of
upload_2016-1-17_16-13-40.jpeg
 

Informatix

Expert
Licensed User
Longtime User
It's not enough: I don't have control on the new View created by the animation!

AnimationPlus with PersistAfter is not useful, so.
I explained this a billion times: Animation and AnimationPlus do not move the view. PersistAfter does not reset the image position at the end of the animation; that's all. This is the behavior of the Android API. I have no control over this. You should use NineOldAndroids instead.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
I explained this a billion times: Animation and AnimationPlus does not move the view. PersistAfter does not reset the image position at the end of the animation; that's all. This is the behavior of the Android API. I have no control over this. You should use NineOldAndroids instead.

I tried:
B4X:
mAnimTranslX.InitializeFloat(ImageView1, mAnimTranslX.PROPERTY_TRANSLATION_X, ImageView1.Left, ImageView1.Left + 200dip, "animX")
mAnimTranslY.InitializeFloat(ImageView1, mAnimTranslY.PROPERTY_TRANSLATION_Y, ImageView1.Top, ImageView1.Top + 100dip, "animY")
mAnimatorSet.setDuration(1000)
mAnimatorSet.PlayTogether(Array As Object(mAnimTranslX, mAnimTranslY))

Sub Button1_Click
   mAnimatorSet.Start
End Sub

Sub animY_End
   Log(Activity.NumberOfViews)
End Sub

Same as AnimationPlus:
Activity.NumberOfViews returns 2 and ImageView1 has the same position's values (left, top) it had before the animation (it has not been moved but duplicated).


Thank you
 

Informatix

Expert
Licensed User
Longtime User
@LucaMs , if you're using NineOldAndroids, the view does move, but the original coordinates (left, top) stay the same and it adds translation values to determine the new location.

Here's a post describing what I found:
https://www.b4x.com/android/forum/threads/nineoldandroids.44393/page-2#post-368568

Once I figured that out, it worked fine. :)
NineOldAndroids also allows to move the view yourself with noaTimeAnimator and the TimeUpdate event, which is what I use to adjust the move speed to the time span to ensure the smoothest move or to follow a curved path. No need to add the translation values of the view; it is exactly where you placed it.
 
Top