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
Thanks to Warwound for his script. Here's a conversion of the library XML file:

AnimationPlus v2.2
  • AnimationDrawable
    Methods:
    • AddFrame (Frame As Object, Duration As Int)
      Adds a frame to the animation
      Frame: the frame to add. It must be a drawable or a bitmap.
      Duration: how long in milliseconds the frame should appear.
    • GetDuration (Index As Int) As Int
      Returns the duration in milliseconds of the frame at the specified index.
    • GetFrame (Index As Int) As Drawable
      Returns the drawable at the specified frame index.
    • GetNumberOfFrames As Int
      Returns the number of frames in the animation
    • Initialize
      Initializes the AnimationDrawable.
    • IsInitialized As Boolean
    • IsRunning As Boolean
      Indicates whether the animation is currently running or not.
    • Start
      Starts the animation, looping if necessary. This method has no effect if the animation is running.
    • Stop
      Stops the animation. This method has no effect if the animation is not running.
    Properties:
    • OneShot As Boolean
      Gets/sets whether the animation will play once.
  • AnimationPlus
    Events:
    • AnimationEnd
    Fields:
    • INTERPOLATOR_ACCELERATE As Int
    • INTERPOLATOR_ACCELERATE_DECELERATE As Int
    • INTERPOLATOR_ANTICIPATE As Int
    • INTERPOLATOR_ANTICIPATE_OVERSHOOT As Int
    • INTERPOLATOR_BOUNCE As Int
    • INTERPOLATOR_CYCLE As Int
    • INTERPOLATOR_DECELERATE As Int
    • INTERPOLATOR_LINEAR As Int
    • INTERPOLATOR_OVERSHOOT As Int
    • REPEAT_INFINITE As Int
    • REPEAT_RESTART As Int
    • REPEAT_REVERSE As Int
    Methods:
    • InitializeAlpha (arg1 As String, arg2 As Float, arg3 As Float)
    • InitializeRotate (arg1 As String, arg2 As Float, arg3 As Float)
    • InitializeRotateCenter (arg1 As String, arg2 As Float, arg3 As Float, arg4 As View)
    • InitializeScale (arg1 As String, arg2 As Float, arg3 As Float, arg4 As Float, arg5 As Float)
    • InitializeScaleCenter (arg1 As String, arg2 As Float, arg3 As Float, arg4 As Float, arg5 As Float, arg6 As View)
    • InitializeTranslate (EventName As String, FromDX As Float, FromDY As Float, ToDX As Float, ToDY As Float)
    • IsInitialized As Boolean
    • PauseTranslation
      Pauses a translation animation.
    • ResumeTranslation
      Resumes a paused translation animation.
    • SetInterpolator (Interpolator As Int)
      Sets the acceleration curve for this animation. Defaults to a linear interpolation.
      See http://developer.android.com/reference/android/view/animation/Interpolator.html for further details.
      Interpolator: one of the INTERPOLATOR constants.
      The Cycle Interpolator cannot be used with this function because the parameter is mandatory.
    • SetInterpolatorWithParam (Interpolator As Int, Param As Float)
      Sets the acceleration curve for this animation. Defaults to a linear interpolation.
      See http://developer.android.com/reference/android/view/animation/Interpolator.html for further details.
      Interpolator: one of the INTERPOLATOR constants.
      Param: factor or tension.
      The Accelerate/Decelerate Interpolator and the Bounce Interpolator have no parameter.
    • Start (MyView As View)
    • Stop (arg0 As View)
    Properties:
    • Duration As Long
    • IsPaused As Boolean [read only]
      Gets whether the translation animation is paused.
    • PersistAfter As Boolean
      Gets/sets if the transformation that this animation performed will persist when it is finished.
    • RepeatCount As Int
    • RepeatMode As Int
    • StartOffset As Long
      Gets/sets when the animation should begin after the Start function was called (in milliseconds).
  • AnimationSet
    Fields:
    • INTERPOLATOR_ACCELERATE As Int
    • INTERPOLATOR_ACCELERATE_DECELERATE As Int
    • INTERPOLATOR_ANTICIPATE As Int
    • INTERPOLATOR_ANTICIPATE_OVERSHOOT As Int
    • INTERPOLATOR_BOUNCE As Int
    • INTERPOLATOR_CYCLE As Int
    • INTERPOLATOR_DECELERATE As Int
    • INTERPOLATOR_LINEAR As Int
    • INTERPOLATOR_OVERSHOOT As Int
    Methods:
    • AddAnimation (Anim As AnimationPlusWrapper)
      Adds a child animation to this animation set.
      Anim: animation to add.
    • Initialize (ShareInterpolator As Boolean)
      Initializes the AnimationSet.
      ShareInterpolator: pass true if all of the animations in this set should use the interpolator associated with this AnimationSet. Pass false if each animation should use its own interpolator.
    • IsInitialized As Boolean
    • SetInterpolator (Interpolator As Int)
      Sets the acceleration curve for every child animation in the set. Defaults to a linear interpolation.
      See http://developer.android.com/reference/android/view/animation/Interpolator.html for further details.
      This setting is ignored if you set ShareInterpolator to false when you initialized the set.
      Interpolator: one of the INTERPOLATOR constants.
      The Cycle Interpolator cannot be used with this function because the parameter is mandatory.
    • SetInterpolatorWithParam (Interpolator As Int, Param As Float)
      Sets the acceleration curve for every child animation in the set. Defaults to a linear interpolation.
      See http://developer.android.com/reference/android/view/animation/Interpolator.html for further details.
      This setting is ignored if you set ShareInterpolator to false when you initialized the set.
      Interpolator: one of the INTERPOLATOR constants.
      Param: factor or tension.
      The Accelerate/Decelerate Interpolator and the Bounce Interpolator have no parameter.
    • Start (view As View)
      Plays the added animations together.
    • Stop (view As View)
      Stops all child animations.
      Warning: stopping an animation set does not trigger the AnimationEnd event of the child animations.
    Properties:
    • Duration As Long
      Gets/sets the duration in milliseconds of every child animation.
    • PersistAfter As Boolean
      Gets/sets if the transformations that this animation set performed will persist when it is finished.
    • StartOffset As Long
      Gets/sets when the animation set should begin after the Start function was called (in milliseconds).
  • ClipDrawable
    Fields:
    • ORIENTATION_HORIZONTAL As Int
    • ORIENTATION_VERTICAL As Int
    Methods:
    • Initialize (Drawable As Object, Gravity As Int, Orientation As Int, StartLevel As Int)
      Initializes the ClipDrawable.
      Drawable: the drawable or bitmap to clip.
      Gravity: where to clip within the drawable.
      Orientation: one of the two orientation constants (horizontal or vertical).
      StartLevel: the initial clipping level.
      The drawable is clipped completely and not visible when the level is 0 and fully revealed when the level is 10000.
    • IsInitialized As Boolean
    Properties:
    • Level As Int
      Gets or sets the clipping level.
      The drawable is clipped completely and not visible when the level is 0 and fully revealed when the level is 10000.
  • LayerDrawable
    Methods:
    • ChangeLayer (Index As Int, Layer As Object) As Boolean
      Changes the layer (drawable or bitmap) at the given index.
      Returns True if the layer was replaced or False if the index was not found.
      You should invalidate the view displaying the layerdrawable after using this function.
    • GetDrawable (Index As Int) As Drawable
      Returns the drawable at the specified layer index.
    • Initialize (Layers() As Object)
      Initializes the LayerDrawable.
      Layers: an array of drawables (or bitmaps) to draw together.
      The element with the largest index will be drawn on top.
    • IsInitialized As Boolean
    Properties:
    • NumberOfLayers As Int [read only]
      Returns the number of layers contained within the LayerDrawable.
  • TransitionDrawable
    Methods:
    • Initialize (Layer1 As Object, Layer2 As Object)
      Initializes the TransitionDrawable.
      Layer1: the drawable (or bitmap) to display first.
      Layer2: the drawable (or bitmap) displayed after a transition.
    • IsInitialized As Boolean
    • ReverseTransition_2To1 (Duration As Int)
      Reverses the transition, picking up where the transition currently is. If the transition is not currently running, this will start the transition with the specified duration. If the transition is already running, the last known duration will be used.
      Duration: the duration to use if no transition is running.
    • ShowFirstLayer
      Shows only the first layer.
    • StartTransition_1To2 (Duration As Int)
      Starts the cross-fade sequence to display the second layer on top of the first layer.
      Duration: the length of the transition in milliseconds.
    Properties:
    • CrossFadeEnabled As Boolean
      Gets/sets whether the cross fade is enabled for this transition.
      When cross fade is disabled, the first drawable is always drawn opaque. With cross fade enabled, the first drawable is drawn with the opposite alpha of the second drawable. Cross fade is disabled by default.
 
Last edited:

ozgureffe

Member
Licensed User
Longtime User
Hi, as i see it is not possible to add event AnimationEnd for AnimationDrawables.
Is there any way of triggering a SUB after AnimationDrawable finish its job?
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
Hi Frédéric,

I just made ​​a donation for this your great job.

I have a question, why in methods you did not enter a description of each arg?
It would be much more comfortable to work with.

Thanks a lot for your donation and happy new year !
Some arguments are defined in the Animation class and I don't have its source code (my class extends this class so I inherit the methods and properties of the ancestor class).
 

Dominex

Active Member
Licensed User
Longtime User
Thanks a lot for your donation and happy new year !
Some arguments are defined in the Animation class and I don't have its source code (my class extends this class so I inherit the methods and properties of the ancestor class).

Happy new year!

I imagined such a thing. Too bad :)

Inviato dal mio Nexus 7 con Tapatalk 2
 

NFOBoy

Active Member
Licensed User
Longtime User
*** Not Animation Plus, in underlying Animation as well ***

Fred,

Ignore Everything I wrote, as I woke up, tried again with straight animation library, and get the same thing)

The problem was my MyTab panel... it gets redrawn at the end of the animation in original location, prior to the animationEnd call, thus getting a screen refresh when it is moved. Still don't know why the whole screen would "flash", or why I have to set the Panel's position to 0 before calling the animation, but at least it looks good now!



********* Ignore Below **************

when using the AnimationPlus to animate a panel into and out of view, the out works great (caveat, this is when I was going to approx 10% left of the activity, when starting in the middle, it "jumps" to the right when pushing in... it's in the sample code) ...(new Note, if I set asview.left to 0 before starting the out animation, then it is smooth)

However, if the panel is off the screen, I need to set the Panel.Left to 0, then start the animation, otherwise, it either doesn't animate at all, or if "enough" of it is on the screen, it will then animate, but a gap will be left if I do not set the panel.Left to no greater than the final position. And if I don't set it 0, then there is a "jump" to when it finishes the animation.

But, if I do set the panel.left to 0 before starting the animation, it will be smooth as butter sometimes, and then others, there will be a "flash" as if the display is drawing the panel all the way left, and then draws it back to where it should be.

Wondering if you can tell what I'm doing wrong?

Here is the initialization stuff:

B4X:
Dim tempWidth As Int
      tempWidth = vActivity.Width
      
      If bRightSide Then
         animPlusIn.InitializeTranslate("animIn", tempWidth - AsView.Width, AsView.Top, tempWidth, AsView.Top)
         animPlusOut.InitializeTranslate("animOut", tempWidth - 1dip , AsView.Top, tempWidth - AsView.Width, AsView.Top)
      Else
         animPlusIn.InitializeTranslate("animIn", AsView.Width, AsView.Top, -AsView.Width, AsView.Top)
         animPlusOut.InitializeTranslate("animOut", -AsView.Width, AsView.Top, AsView.Width, AsView.Top)
      End If
      
      animPlusIn.Duration = animspeed
      animPlusOut.Duration = animspeed
      animPlusOut.SetInterpolator(animPlusOut.INTERPOLATOR_LINEAR)
      animPlusIn.SetInterpolator(animPlusIn.INTERPOLATOR_LINEAR)


and here's the call
B4X:
   If bRightSide Then

      
      If AsView.Left >= vActivity.Width Then
         AsView.Left = 0
         vActivity.Invalidate
         
         animPlusOut.Start(AsView)
         animPlusOut.Start(myTab)
      '   AsView.Left = vActivity.Width - AsView.Width
      Else
         animPlusIn.Start(AsView)
         myTab.Visible = False
      End If
   Else
      If (AsView.Left+AsView.Width) <= vActivity.Left Then
         animPlusOut.Start(AsView)
      Else
         animPlusIn.Start(AsView)
      End If

   End If

Ross

(the cHTabPanel is where the code lies, it is triggered in the MyTab_Click, and the AnimationPlus is set in the StartTabPanel call)
 

Attachments

  • cTabbedPanel.zip
    49.1 KB · Views: 392
Last edited:

yckhor

Member
Licensed User
Longtime User
Hi Informatix,

I am working on a google+ lookalike cards using panel + animation plus. I managed to make the panel animate during the add card. It works using scale+decelerate and I planned to use translate+anticipate to hide the card when user swipe on the panel. However, I can't find the documentation to set the original location (X,Y) and destination location (X,Y) for the translate animation to move the card-panel towards the right of the screen and eventually disappeared (hide).

P/s: where can I find a documentation of the parameters?
AnimPlus.InitializeScaleCenter("AnimPlus", ?, ?, ?, ?, view)

Thanks!
 
Last edited:

yckhor

Member
Licensed User
Longtime User
The functions with no description are directly imported from the Animation library, so you'll find their parameters and documentation in this lib.
Aha... got it. Thanks! I love your works very much and use your libraries extensively in my app. Shall donate when I start to collect $$$ and keep up the great works.
 

KDHeard

Member
Licensed User
Longtime User
Hi Informatix - thanks for the Freeware library. I love it.... Keep up the great development work!
 

luke2012

Well-Known Member
Licensed User
Longtime User
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

v1.0: Freeware.
Interpolators, PersistAfter, StartOffset

v2.2: Donationware.
Interpolators, PersistAfter, StartOffset
Pausable translation animation
AnimationSet
AnimationDrawable, ClipDrawable, LayerDrawable, TransitionDrawable

Starting from version 2, the AnimationPlus library is released as a donationware. That means: if you want to use it in your application (or reuse a part of it in any piece of software written in B4A or Java), please donate something by using the link in my signature. I'll send you the file as soon as I receive your donation.

You can donate what you want, from one dollar to one million dollars (for such an amount, you'll be my friend forever ).
I don't do that to earn a lot of money, just to be rewarded for my work (and I probably won't earn a lot of money this way ;-)).
 
Last edited:

capisx

Member
Licensed User
Longtime User
Unfortunately, no listener is available for an AnimationDrawable. Possible workaround (if OneShot = true): check with a timer whether the animation is running.

I've tried this workaround but the animation IsRunning method always return true even though the animation is already finish. (AnimationPlus V2.2.1)
 

Informatix

Expert
Licensed User
Longtime User
I've found a way to detect the end of an animation (by comparing the current frame to the last frame). I will send the new version of AnimationPlus tonight.
Message to the first donators: please send me an email with your email address because I'm not sure that you (the first donators of this library) are in my database.
 

Vincenzo Fabiano

Member
Licensed User
Longtime User
I need it to anchor one value for every AnimationPlus Object.

Ex:

AnimationObject(Counter).InitializeTranslate("AnimationEnd1", 0, 0, 0, -600)
AnimationObject(Counter).tag = Counter
LabelAnchor(Counter).ecc ecc

I need refer a Counter specific for the item when AnimationObject(Counter) is finished.

Sub AnimationEnd1_AnimationEnd
Dim Animation as AnimationPlus
Animation = Sender
Animation.stop(LabelAnchor(Animation.Tag))
LabelAnchor(Animation.Tag).RemoveView
end sub

Tag = Counter
 
Top