B4A Library [CLASS] Animated Sliding Menu

This class will allow you to create animated sliding menus.

Requirements:

- B4A 2.xx
- Universal Tween Lib
- Phone Lib
- Add the Class module "AnimatedSlidingMenu.bas" to your project

How to use:

Initialize the class:

B4X:
Sub Globals

    Dim MyMenu As AnimatedSlidingMenu

End Sub

Then, create your animated sliding menu:
B4X:
'The menu title is optional, pass an empty sting if no title is needed
'If you add a picture to the title's background then enter an * on the title text or
'the title won't show up
myMenu.Initialize(Activity, Me, "Menu Title", "Test", "L", 50dip, 300dip, Colors.Blue, Null)

'Then add items to the menu
myMenu.AddItem(Null, "Item One", Colors.White, Colors.Transparent, 1)
myMenu.AddItem(Null, "Item Two", Colors.White, Colors.Transparent, 2)
myMenu.AddItem(Null, "Item Three", Colors.White, Colors.Transparent, 3)
myMenu.AddItem(Null, "Item Four", Colors.White, Colors.Transparent, 4)

...

'This routine will get the selected menu item, in this case, "Test" is the name of the event
'that will catch the selection, you can name yours with whatever name you like
Sub Test_Click(SelectedItem As Object)
            
    ToastMessageShow("Item selected: " & SelectedItem, False)

End Sub
If you added a title, you can modify its properties like this:
B4X:
myMenu.SetTitle(Colors.Red, Colors.White, Gravity.CENTER_HORIZONTAL, Null)

To open the menu use the following code:
B4X:
Sub Button1_Click

    myMenu.OpenMenu("Casino")
   
End Sub

There are 8 pre-defined animations included in this class: Default, Casino, CasinoReverse, ShootUp, Cascade, Flip, Fade and ZigZag.

This class supports up to 50 menu items.

That's it!!.

The attached file contains a DEMO and a BAREBONES sample to better understand the use of this class.

Updated on Nov 26, 2012 to version 1.2

Screen shots:

C43h2l.jpg
FW2jgl.png

ptTTPl.png
nSH0Zl.png
 

Attachments

  • AnimatedSlidingMenuClass.zip
    165.6 KB · Views: 2,065
Last edited:

NJDude

Expert
Licensed User
Longtime User
Very nice! Are there any requirements for the tween lib about OS version?

Sent from my GT-I9000 using Tapatalk 2

Animations using ROTATION, SCALE and ALPHA will require SDK >= 11, however, this class will detect that and use the "default" animation if the device has a lower SDK.
 
Last edited:

walterf25

Expert
Licensed User
Longtime User
NJDude my Hero

Awesome class NJ, just loaded it on my phone and it works like a charm, thanks for your awesome work bud, really amazing!

Cheers,
Walter Flores
 

barx

Well-Known Member
Licensed User
Longtime User
Someone was wanting this very thing on the chat room other night. Think it was SCIS
 

moster67

Expert
Licensed User
Longtime User
Nice NJ :sign0098:

Tried them on GIngerbread, ICS and JellyBean.

Thanks for sharing.
 

walterf25

Expert
Licensed User
Longtime User
Help Needed

Hi NJDude, i was wondering if you could help me out, I'm trying to play around with your class for animating menus, I want to animate a panel so that it will come from the left to right until it's fully centered on the screen, i took some of your code specifically the AnimateTween part, but i keep getting an error and i can't figure out why.

this is the code i took from your example
B4X:
Private Sub AnimateTween(ViewType As String, ID As Int, ViewName As Object, TweenConstant As Double, xPos As Int, yPos As Int, Easing As Object, Duration As Float, StartDelay As Float)

        Tween1(ID).Initialize("Tween")
            
                Duration = Duration * 10 'It was said that the duration is in tenths of a second, here we convert seconds to tenths of a second for easy handling.
                StartDelay = StartDelay * 10

        Select Case ViewType

                    Case "Panel", "HorizontalScrollView", "ListView", "ScrollView", "Spinner", "TabHost", "WebView"                              

                           Tween1(ID).registerPanelAccessor 
                           Tween1(ID).PanelTo(ViewName, TweenConstant, Duration)

                    Case "ImageView"      
   
                           Tween1(ID).registerImageAccessor 
                           Tween1(ID).ImageTo(ViewName, TweenConstant, Duration)
                                                               
                    Case "Label", "Button", "AutoCompleteEditText", "CheckBox", "EditText", "RadioButton", "ToggleButton"                                 
   
                           Tween1(ID).registerLabelAccessor 
                           Tween1(ID).LabelTo(ViewName, TweenConstant, Duration)   

                End Select
            
                Tween1(ID).setTarget(xPos, yPos)
          Tween1(ID).Ease(Easing)
          Tween1(ID).Delay = StartDelay
      
                Manager.addTween(Tween1(ID).Tween)    'this is where the code stops when i run my program

End Sub

and this is the error i get
**
main_animatetween (B4A line: 112)
Manager.addTween(Tween1(ID).Tween)
java.lang.NullPointerException at com.rootsoft.tweenengine.RSTweenManager.addTween(RSTweenManager.java:61)
at com.dandre.weatherforecast.main._animatetween(main.java:425)
at com.dandre.weatherforecast.main._activity_create(main.java:284)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
at com.dandre.weatherforecast.main.afterFirstLayout(main.java:84)
at com.dandre.weatherforecast.main.access$100(main.java:16)
at com.dandre.weatherforecast.main$WaitForLayout.run(main.java:72)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3806)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)


at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException

Any advise on how to fix this will be greatly appreciated!

:sign0188:

Cheers,
Walter
 

NJDude

Expert
Licensed User
Longtime User
You can either create a new animation or modify an existing one, for example, modify the "Default" animation to do what you need, modify line #181 in the class and make this change:

From:
B4X:
xPos = 0dip
To:
B4X:
xPos = (100%x - mWidth) / 2
 

walterf25

Expert
Licensed User
Longtime User
Help Needed

Hi NJDude i realize i can create my own animations but the problem i'm having is at this line inside the "AnimateTween" Sub

B4X:
Manager.addTween(Tween1(ID).Tween)

my program stops at this line and it gives me the error on the previous post, do you have any idea why this is?

Thanks,
Walter
 

walterf25

Expert
Licensed User
Longtime User
Help Needed

i'm calling the animation from the Sub Activity Create(FirstTime as Boolean) like this:
B4X:
   AnimateTween("Panel", 2, panel1, Constants.POSITION_XY, 250, 10, Constants.BACK_INOUT, 2, 0)
   'AnimDefault(250, 250)
   
   
   tmrUpdate.Initialize("tmrUpdate", 10)
   
Manager.StartTween   
tmrUpdate.Enabled = True
Callback.Initialize("TweenCallback")
              Callback.Listener = True
              Tween1(1).Callback = Callback.TweenCallback
            
              Manager.StartTween

Thanks,
Walter
 
Top