B4A Library SD: Menu (with Animation)

Star-Dust

Expert
Licensed User
(No WRAP, No Java Only B4A)

Guillotine is just a swivel guillotine panel that could accommodate a menu but also a panel with all sorts of views.
The RollOut Menu and Side Menu are instead menus as you see in the Third Example. There is also a video in post # 6
TreeMenu (Tree ListView): This class allows you to enter a ListView type menu and clicking each item opens a submenu with its entries (if any) and raises the click event

SD_Menu

Author: Star-Dust
Version: 0.06
  • GhigliottinaPanel
    • Fields:
      • Panel As Panel
      • View As View
    • Functions:
      • Class_Globals As String
      • Close (Animation As Boolean) As String
      • GetPanelBase As Panel
      • GetPanelMenu As Panel
      • Initialize (EventName As String, Me_CallBack As Object) As String
        Initializes the object. You can add parameters to this method if needed.
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • IsOpen As Boolean
      • Open (Animation As Boolean) As String
      • SetMenuButtonDark As String
      • SetMenuButtonLight As String
      • SetPanelColor (Color As Int) As String
      • SetTextMenu (Message As String) As String
      • SetTextMenuColor (Color As Int) As String
  • GhigliottinaView
    • Events:
      • Click
      • LongClick
    • Fields:
      • Panel As Panel
    • Functions:
      • AddPanel (MyPanel As Panel) As String
      • Class_Globals As String
      • Close (Animation As Boolean) As String
      • DesignerCreateView (Base As Panel, Lbl As Label, Props As Map) As String
      • GetPanelBase As Panel
      • GetPanelMenu As Panel
      • Initialize (vCallback As Object, vEventName As String) As String
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • IsOpen As Boolean
      • Open (Animation As Boolean) As String
      • SetMenuButtonDark As String
      • SetMenuButtonLight As String
      • SetPanelColor (Color As Int) As String
      • SetTextMenu (Message As String) As String
      • SetTextMenuColor (Color As Int) As String
  • MenuTree
    • Events:
      • Click (MenuName As String, ID As String)
    • Fields:
      • ExpandableList As List
      • ImageCloseMenu As Bitmap
      • ImageOpenMenu As Bitmap
      • OpenOneOnlyMenu As Boolean
    • Functions:
      • AddMenuVoice (Name As String, ID As Int, Expanded As Boolean) As String
      • AddRoot (Name As String) As String
      • AddSubMenuVoice (Name As String, IDSub As Int, IDMenu As Int) As String
      • Class_Globals As String
      • ClearMenu As String
      • DesignerCreateView (Base As Panel, Lbl As Label, Props As Map) As String
      • GetBase As Panel
      • Initialize (vCallback As Object, vEventName As String) As String
      • Invalidate As String
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
  • RollOutMenu
    • Events:
      • Click (ID As String)
    • Fields:
      • IsOpen As Boolean
    • Functions:
      • AddImageButton (Bitmap As Bitmap, ID As String) As String
      • Class_Globals As String
      • Close (Animation As Boolean) As String
      • GetPanel As Panel
        If you want Add into Panel USE After Initialize
      • Initialize (EventaName As String, Me_CallBack As Object, LeftStick As Boolean, HightWidh As Int) As String
        Initializes the object. You can add parameters to this method if needed.
        RollOut.Initialize("Roll",Me,Activity,True,60dip)
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • Open (Animation As Boolean) As String
  • SideMenu
    • Events:
      • Click (ID As String)
    • Fields:
      • IsOpen As Boolean
    • Functions:
      • AddImageButton (Bitmap As Bitmap, ID As String) As String
      • Class_Globals As String
      • Close (Animation As Boolean) As String
      • GetPanel As Panel
      • Initialize (EventaName As String, Me_CallBack As Object, LeftStick As Boolean, HightWidh As Int) As String
        Initializes the object. You can add parameters to this method if needed.
        RollOut.Initialize("Roll",Me,Activity,True,60dip)
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • Open (Animation As Boolean) As String
3.gif 4.png 5.png1.gif 2.gif
 

Attachments

Last edited:

LucaMs

Expert
Licensed User
I suppose it is a very big panel; so I'm thinking that we know that a big image means much ram, but how much "heavy" is a big empty panel?

BTW I have not found a "perfect" method to get the memory used (I saw some code but I get not reliable results, I think).

[Yes, I'm a little bit OT but I don't want open a thread for this question]


[Note: my observation is not strictly related to this menu, it is more general, about panels; we will never have so many menus that will take up too much memory].
 

Star-Dust

Expert
Licensed User
The supposition is right, is empty panel, but I do not know the answer

La "supposta" è giusta é un pannello vuoto, ma non conosco la risposta.
 
Last edited:

Erel

Administrator
Staff member
Licensed User
The memory consumption of a panel is insignificant. Its size doesn't matter. If you are using a large bitmap as its background then the bitmap itself can consume a lot of RAM.
 

Star-Dust

Expert
Licensed User
I suppose it is a very big panel; so I'm thinking that we know that a big image means much ram, but how much "heavy" is a big empty panel?

BTW I have not found a "perfect" method to get the memory used (I saw some code but I get not reliable results, I think).

[Yes, I'm a little bit OT but I don't want open a thread for this question]


[Note: my observation is not strictly related to this menu, it is more general, about panels; we will never have so many menus that will take up too much memory].
But isn't necessary a big panel.
The rotating panel must be of MaxiDip dimensions, see below
B4X:
private Sub MaxDip As Int
    Return (Max( GetDeviceLayoutValues.Height, GetDeviceLayoutValues.Width)+10dip)
End Sub
And rotate the panel by choosing the right Pivot point.
See: https://www.b4x.com/android/forum/threads/view-utils.39347/
 
Last edited:

Star-Dust

Expert
Licensed User
I extended my Ghigliottina (guillotine) library by adding 2 menus, RollOutMenu and SideMenu. I changed the name in Menu Library




 
Last edited:

Star-Dust

Expert
Licensed User
update: 0.02 You do not have to pass the Activity as an Initialization Parameter.

Download on Post#1
 

Star-Dust

Expert
Licensed User
For GhigliottinaPanel
B4X:
GhigliottinaPanel1.Initialize("GhigliottinaPanel1",Me)
GhigliottinaPanel1.SetTextMenu("My Guillotine Menu")
GhigliottinaPanel1.SetMenuButtonLight
GhigliottinaPanel1.SetPanelColor(Colors.gray)

Activity.AddView(GhigliottinaPanel1.View,0,0,100%x,100%y) ' For add to Activity
MyPanel.AddView(GhigliottinaPanel1.View,0,0,100%x,100%y) ' For add to Panel
GhigliottinaView use design for Add to Panel or Activity

For SideMenu and RollOutMenu

B4X:
SideMenu1.Initialize("SideMenu1",Me,True,50dip)
SideMenu1.View.RemoveView ' Remove from Activity
MyPanel.AddView(SideMenu1.View,0,0,100%x,100%y) ' For add to Panel

RollOutMenu1.Initialize("RollOutMenu1",Me,False,50dip)
RollOutMenu1.View.RemoveView ' Remove from Activity
MyPanel.AddView(RollOutMenu1.View,0,0,100%x,100%y) ' For add to Panel
 
Last edited:

Star-Dust

Expert
Licensed User
But for SideMenu and RollOutMenu use Version 0.03+ for add to Panel.
 
Last edited:

mberthe

Member
Licensed User
For GhigliottinaPanel
B4X:
GhigliottinaPanel1.Initialize("GhigliottinaPanel1",Me)
GhigliottinaPanel1.SetTextMenu("My Guillotine Menu")
GhigliottinaPanel1.SetMenuButtonLight
GhigliottinaPanel1.SetPanelColor(Colors.gray)

Activity.AddView(GhigliottinaPanel1.View,0,0,100%x,100%y) ' For add to Activity
MyPanel.AddView(GhigliottinaPanel1.View,0,0,100%x,100%y) ' For add to Panel
GhigliottinaView use design for Add to Panel or Activity

For SideMenu and RollOutMenu

B4X:
SideMenu1.Initialize("SideMenu1",Me,True,50dip)
SideMenu1.View.RemoveView ' Remove from Activity
MyPanel.AddView(SideMenu1.View,0,0,100%x,100%y) ' For add to Panel

RollOutMenu1.Initialize("RollOutMenu1",Me,False,50dip)
RollOutMenu1.View.RemoveView ' Remove from Activity
MyPanel.AddView(RollOutMenu1.View,0,0,100%x,100%y) ' For add to Panel
The example below (example4.zip) do not work
I have noticed:
- line 42 (SM.View.RemoveView) make the pane1 invisible
- line 43 (Panel1.AddView(SM.View,0,0,100%x,100%y) causes a stackoverflowError :
B4X:
at android.view.viewgroup.resetResolvedLayoutDirection(view group.java:6571)
at android.view.viewgroup.resetResolvedLayoutDirection(view group.java:6572)
at android.view.viewgroup.resetResolvedLayoutDirection(view group.java:6572)
.......
 

Attachments

Star-Dust

Expert
Licensed User
I modified the method. Use AddToPanel. I tried it and it works. I have also attached the modified template example to the panel.

B4X:
SM.Initialize("Side",Me,False,50dip)
SM.AddToPanel(Panel1)
For i=1 To 5
        SM.AddImageButton(LoadBitmap(File.DirAssets, I & ".png"),i)
Next
SM.Open(True)
Download rel 0.04 at post#1
 

Attachments

Star-Dust

Expert
Licensed User
Update rel 0.05
Add Class MenuTree: This class allows you to enter a ListView type menu and clicking each item opens a submenu with its entries (if any) and raises the click event

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
     Private MenuTree1 As MenuTree
End Sub

Sub Activity_Create(FirstTime As Boolean)

Activity.LoadLayout("Menu")
   ' If required add image 
   MenuTree1.ImageOpenMenu=LoadBitmap(File.DirAssets,"open.png")
   MenuTree1.ImageCloseMenu=LoadBitmap(File.DirAssets,"close.png")

   For i=1 To 8
        'Menu Item
        MenuTree1.AddMenuVoice("Item " & i,i,False)
        'Sub Menu Item
        For x=1 To Rnd(2,5)
            MenuTree1.AddSubMenuVoice("Sub " & X, i & x, i )
        Next
   Next

   MenuTree1.Invalidate
End Sub

Sub MenuTree1_Click (MenuName As String, ID As String)
    Log(MenuName & "-" & ID)
End Sub
 
Last edited:

IdasI4A

Member
Licensed User
Good morning, I am trying to execute the example3 and I get the following error:
B4X:
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
java.lang.NoSuchMethodError: anywheresoftware.b4a.keywords.Common.ToastMessageShow
   at b4a.example.rolloutmenu._initialize(rolloutmenu.java:333)
   at b4a.example.main._activity_create(main.java:403)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
   at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
   at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
   at b4a.example.main.afterFirstLayout(main.java:102)
   at b4a.example.main.access$000(main.java:17)
   at b4a.example.main$WaitForLayout.run(main.java:80)
   at android.os.Handler.handleCallback(Handler.java:733)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5001)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:603)
   at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
How is it solved?

I use version 7.30 of B4A

Thank you.
 

Star-Dust

Expert
Licensed User
Compiled libraries for version 6.5, with more than 7 versions of this issue.

As soon as I can do I will compile by someone for version 7 and attach this post, hope for the afternoon.
 
Top