B4A Library NineOldAndroids

This is my version of the NineOldAndroids lib for B4A. It's free and provided with the Java source code.

This library offers more possibilities of animation than AnimationPlus (rotation or translation on more than one axis for 3D effect, animation step by step with events for each step, synchronization between animations, ability to change the view size and contents during the animation, etc.).

It works with all versions of Android >= 2 and with all views, even custom ones.

v0.92: Initial release.
v0.92b: I changed the package name and repackaged the source to ease its compilation.
v0.93: I fixed a bug in noaObjectAnimator.InitializeFloat.
 

Attachments

  • NineOldAndroids v0.93.zip
    328 KB · Views: 1,821
  • BasicTranslationExample.zip
    6.8 KB · Views: 835
Last edited:

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Trying to test the example Im getting an error...
Ive tried to find nineoldandroid-2.4.0.jar but it is not in any of the zips.
How do I make it work? Thanks
 

Attachments

  • 2015-08-02_1839.png
    2015-08-02_1839.png
    10.7 KB · Views: 212

ducphu

Active Member
Licensed User
Longtime User
Hi all,

I'm using this lib for my app. I have a label moving from X1 to X10. I want to code a button in such a way that when it's clicked, the label's position is immediately changed to a point, between X1 and X10. Example,

X1....X2.....X3........X10

The label is animated moving to point X2, then the button is clicked. I want the label immediately jumps to X3 (no animation from X2 to X3). And then continue the animated moving from X3 to X10. How can I do this? Thanks.
 

ducphu

Active Member
Licensed User
Longtime User
By setting the left property of your label before doing the animation.

It doesn't work correctly as if I set left property of my label to X3 while the animation runs only to X2.5, between X2 and X3 then the label will behave like jump forward to X3 then jump backward to X2.5

Anyway, I find out that the below code works well. Where X is the distance you want the label to jump forward.
B4X:
Sub btn_Click
   Anim.CurrentPlayTime = Anim.CurrentPlayTime + Anim.Duration / X
End Sub
 

ducphu

Active Member
Licensed User
Longtime User
Hi all,

Have a question abt this lib. I have 2 ObjectAnimator

AnimC1.InitializeFloat(lb,AnimC1.PROPERTY_SCALE_X,1,0,"X").setDuration(1000)
AnimC1.INTERPOLATOR_LINEAR
AnimC2.InitializeFloat(lb,AnimC2.PROPERTY_SCALE_Y,1,0,"Y").setDuration(1000)
AnimC2.INTERPOLATOR_LINEAR
AnimSetC.Play(AnimC1).with(AnimC2)
AnimSetC.Start

After the mentioned above animations end, I want to set back my lb property to origin. How can I do that? I tried:

Dim AnimH As noaViewHelper
AnimH.setScaleX(lb,1)
AnimH.setScaleY(lb,1)

But it doesn't work.
 

ArminKH

Well-Known Member
@Informatix
Can u please explain a bit about SetPivotX and Y? I can use this with xml animations but it does n't works for me with Nine Old Android
If i set for example PivotX to 0 or 200dip i can't see any affects
 

Informatix

Expert
Licensed User
Longtime User
@Informatix
Can u please explain a bit about SetPivotX and Y? I can use this with xml animations but it does n't works for me with Nine Old Android
If i set for example PivotX to 0 or 200dip i can't see any affects
The pivot coordinates set the location of the point around which the view is rotated and scaled. By default, the pivot point is centered on the object.
 

Informatix

Expert
Licensed User
Longtime User
Hi all,

Have a question abt this lib. I have 2 ObjectAnimator

AnimC1.InitializeFloat(lb,AnimC1.PROPERTY_SCALE_X,1,0,"X").setDuration(1000)
AnimC1.INTERPOLATOR_LINEAR
AnimC2.InitializeFloat(lb,AnimC2.PROPERTY_SCALE_Y,1,0,"Y").setDuration(1000)
AnimC2.INTERPOLATOR_LINEAR
AnimSetC.Play(AnimC1).with(AnimC2)
AnimSetC.Start

After the mentioned above animations end, I want to set back my lb property to origin. How can I do that? I tried:

Dim AnimH As noaViewHelper
AnimH.setScaleX(lb,1)
AnimH.setScaleY(lb,1)

But it doesn't work.
I pasted your code in a project and it worked fine.
Are you sure that you declared your event sub this way?
B4X:
Sub Y_End 'or X_End since both scaling are simultaneous
    Dim AnimH As noaViewHelper
    AnimH.setScaleX(IV,1)
    AnimH.setScaleY(IV,1)
End Sub
 

ArminKH

Well-Known Member
The pivot coordinates set the location of the point around which the view is rotated and scaled. By default, the pivot point is centered on the object.
yes i know but if u remember this thread https://www.b4x.com/android/forum/threads/increase-height-with-animation.57897/#post-364567 you posted a code for me to increase height and width of a view without modifying the child views
this works perfectly
but for example i have a panel in top left corner of screen now by using your lib i can use this code
B4X:
'width animation in x axis for scroll view
            NOA_X.InitializeInt(0,T8MenuSV.Width,"NOA_X")
            NOA_X.setDuration(50).Interpolator = NOA_X.INTERPOLATOR_DECELERATE
and in event this is my code
B4X:
Private Sub NOA_X_Update
    T8MenuSV.Width = NOA_X.AnimatedValue
End Sub
above codes is suitable for this view when it is in left side of screen
but when my view is in right top corner my animation must be start from 0 value to view.width value and also decrease view.left similar to this one
B4X:
NOA_L.InitializeFloat(T8MenuSV,NOA_L.PROPERTY_X,StartLeft + T8MenuSV.Width,StartLeft,"NOA_L")
            NOA_L.setDuration(50).Interpolator = NOA_L.INTERPOLATOR_DECELERAT
and this is okay
but i dont want to use more than 2 or 3 animation at the same time because i want my app be light weight for cpu calculations
is this possible to change PivotX for this view to achieve to second animation without animation ?
some thing like this

If IsInRight then NOA_Helper.SetPivotX(T8MenuSV,T8MenuSV.Width)
excuse me if my english is not good :(
 

Informatix

Expert
Licensed User
Longtime User
yes i know but if u remember this thread https://www.b4x.com/android/forum/threads/increase-height-with-animation.57897/#post-364567 you posted a code for me to increase height and width of a view without modifying the child views
this works perfectly
but for example i have a panel in top left corner of screen now by using your lib i can use this code
B4X:
'width animation in x axis for scroll view
            NOA_X.InitializeInt(0,T8MenuSV.Width,"NOA_X")
            NOA_X.setDuration(50).Interpolator = NOA_X.INTERPOLATOR_DECELERATE
and in event this is my code
B4X:
Private Sub NOA_X_Update
    T8MenuSV.Width = NOA_X.AnimatedValue
End Sub
above codes is suitable for this view when it is in left side of screen
but when my view is in right top corner my animation must be start from 0 value to view.width value and also decrease view.left similar to this one
B4X:
NOA_L.InitializeFloat(T8MenuSV,NOA_L.PROPERTY_X,StartLeft + T8MenuSV.Width,StartLeft,"NOA_L")
            NOA_L.setDuration(50).Interpolator = NOA_L.INTERPOLATOR_DECELERAT
and this is okay
but i dont want to use more than 2 or 3 animation at the same time because i want my app be light weight for cpu calculations
is this possible to change PivotX for this view to achieve to second animation without animation ?
some thing like this

If IsInRight then NOA_Helper.SetPivotX(T8MenuSV,T8MenuSV.Width)
excuse me if my english is not good :(
To animate different panels in different directions, you can use the same code with different parameters. You need 5 params: X, Y, Width, Height and Direction, a simple byte which indicates the direction of expansion. If the direction is to the bottom right, then you change only the width in the event; if the direction is to the top left, you change the width but also the left and top properties. Etc.
PivotX and PivotY are of no use here, except if you rescale your panel instead of resizing it but resizing it is recommended if you don't want to rescale the contents.
2 or 3 animations at the same time are nothing for a modern device (and it's not the CPU that is concerned...).

to achieve to second animation without animation ?
I don't know whether it's a translation error or not. Anyway, that makes no sense as is.
 

Dave O

Well-Known Member
Licensed User
Longtime User
Just replaced my AnimationPlus animations with NoA animations. Both libraries are very easy to use. :)

I'm using animation to "fling" a score off the screen (when that player loses). When I start a new game, I want to reset the score to its original position.

I tried resetting its position using SetLayout, but nothing happened. In fact, the debugger showed that the left/top/width/height were correct, but the view was still offscreen. WTF?

Then I read the Android docs, and found that the actual position is a combination of the left/top coordinates and any "translation" values that the animation applied. (Apparently the translation values hang around after the animation finishes.) So I figure I just need to zero the translation offsets and the view should return to its correct position.

Problem is, I don't see any methods or properties that let me do that.

As a workaround, I created another animation that moved the view back to its original position. That works, but it feels like a hack.

Is there a proper way to reset a view's position after a NoA animation finishes?

Thanks!
 

Dave O

Well-Known Member
Licensed User
Longtime User
Is there a proper way to reset a view's position after a NoA animation finishes?

Ah, I finally found the noaViewHelper class (it's right there in the docs, I just missed it), which lets us change these values directly. So I can just reset the position and scale values like this, after I'm done with the animation:
B4X:
Dim tempHelper As noaViewHelper
tempHelper.setTranslationX(tempImage, 0)
tempHelper.setTranslationY(tempImage, 0)
tempHelper.setScaleX(tempImage, 1)
tempHelper.setScaleY(tempImage, 1)

RTFM, as they say... :)
 
Last edited:

Dave O

Well-Known Member
Licensed User
Longtime User
BTW, I think I found a bug in the NoA library when using float values.

If I set up an animation using the scale properties, and feed them float values, it seems to treat them like int values that are rounded down.

For example, in this animation:
B4X:
Dim animX As noaObjectAnimator
animX.InitializeFloat(someView, animX.PROPERTY_SCALE_X, 1, endScale, "")
...I want the view to "bulge" a bit, so I set endScale to 1.3 (that is, 1.3 times bigger than the original size). However, it treats it as 1.0 (no change in size) no matter what value I use between 1.1 and 1.9. If I set it to an int like 2, it animates properly.

Similarly if I try to shrink the view down to half size (0.5), it shrinks it down to nothing (as if it was rounding down to the next smallest int - zero).

In the docs, the method is also documented with int arguments instead of the floats I expected:
B4X:
InitializeFloat (target As Object, propertyName As String, StartValue As Int, EndValue As Int, EventPrefix As String) As ObjectAnimator

Scale takes float values in the AnimationPlus library. Should it also do that here, or are they using a different scheme?

Thanks!
 

Informatix

Expert
Licensed User
Longtime User
BTW, I think I found a bug in the NoA library when using float values.

If I set up an animation using the scale properties, and feed them float values, it seems to treat them like int values that are rounded down.

For example, in this animation:
B4X:
Dim animX As noaObjectAnimator
animX.InitializeFloat(someView, animX.PROPERTY_SCALE_X, 1, endScale, "")
...I want the view to "bulge" a bit, so I set endScale to 1.3 (that is, 1.3 times bigger than the original size). However, it treats it as 1.0 (no change in size) no matter what value I use between 1.1 and 1.9. If I set it to an int like 2, it animates properly.

Similarly if I try to shrink the view down to half size (0.5), it shrinks it down to nothing (as if it was rounding down to the next smallest int - zero).

In the docs, the method is also documented with int arguments instead of the floats I expected:
B4X:
InitializeFloat (target As Object, propertyName As String, StartValue As Int, EndValue As Int, EventPrefix As String) As ObjectAnimator

Scale takes float values in the AnimationPlus library. Should it also do that here, or are they using a different scheme?

Thanks!
Oops. I'm fixing it.

EDIT: fixed. The new version is in post #1.
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
Ah, I finally found the noaViewHelper class (it's right there in the docs, I just missed it), which lets us change these values directly. So I can just reset the position and scale values like this, after I'm done with the animation:
B4X:
Dim tempHelper As noaViewHelper
tempHelper.setTranslationX(tempImage, 0)
tempHelper.setTranslationY(tempImage, 0)
tempHelper.setScaleX(tempImage, 1)
tempHelper.setScaleY(tempImage, 1)

RTFM, as they say... :)



Hi,

How should I use setTranslationX in a case like the one below?
upload_2016-1-18_12-10-21.png
 
Top