B4A Library [Class] Custom Animated Menu

This class will allow you to create customized modal multicolored menus, you can change the color of the background, transparency, textsize, textcolor, add bitmaps to the background, add customized lines (or not), etc...

Requirements:

- B4A 2.xx
- Animation Lib
- AnimationPlus Lib
(AHlocale for the months demo)

- Add the Class module mbMenu.bas" to your project

How to use:

Initialize the class like this for example:

B4X:
Sub Globals
   Dim Menu As mbMenu
End Sub

then create your custom menu :
B4X:
' Directions in
' 0 : Bottom -> Top
' 1 : Left -> Right
' 2 : Right -> Left
' Directions out
' 3 : Top -> Bottom
' 4 : Left -> Right
' 5 : Right -> Left

' Activity, Module, EventName,ColCount, MinBtnSize,ItemsNbr,Width, Corner, Color, Direction In , Direction Out
Menu.Initialize(Activity,Me,"Menu_Click", 3,80dip, 3, 100%x, 0, Colors.ARGB(200,30,30,30),0,3)

'Text, Image, BackColor, TextSize, TextColor, ReturnValue
Menu.AddItem("Smile",LoadBitmap(File.DirAssets, "emotion_smile_icon&32.png"),Colors.ARGB(0,0,0,0),14,Colors.White,0)
Menu.AddItem("Preferences",LoadBitmap(File.DirAssets, "cogs_icon&32.png"),Colors.ARGB(0,0,0,0),14,Colors.White,1)
Menu.AddItem("Search",LoadBitmap(File.DirAssets, "globe_3_icon&32.png"),Colors.ARGB(0,0,0,0),14,Colors.White,2)
'                   LinesOnOff, LinesColor,LinesStroke
Menu.Dispatch_Menus(True,Colors.ARGB(80,255,255,255),1)

At this time the menu is initialized and hidden at the bottom.
You just have to call it from "Sub Activity_KeyPress" (or any button on the screen)

B4X:
Menu.Show

and get the return parameter with this routine

B4X:
Sub Menu_Click(mbButton As Int)
   Menu.Hide
   ToastMessageShow ("Clicked on Button " & mbButton, False)
End Sub

The examples are documented for a nice handling.
You can of course customize the animations too.

This is my first post. Have fun !
 

Attachments

  • image1.png
    52.6 KB · Views: 1,163
  • image2.png
    41.9 KB · Views: 970
  • image3.png
    41 KB · Views: 946
  • mbMenu V1.11.zip
    33.4 KB · Views: 617
Last edited:

mabool

Member
Licensed User
Longtime User
@Informatix : en effet ! Merci de m' encourager. Ce sont des démos que j'ai écrites uniquement pour les poster ici. Je me sers de cette classe dans une appli commerciale car je n'aime pas du tout les menus de Gingerbread.

@NJDude : it runs perfectly on my Galaxy S with Gingerbread 2.3.5 and my tablet with ICS 4.04 . The three demos are crashing ?
 

bluedude

Well-Known Member
Licensed User
Longtime User
Galaxy Nexus, random unexpected behavior

I tested it on my Galaxy Nexus and it shows random unexpected behavior. Menu not showing, menu not hiding, nothing happens etc.

I think you need to get back to the drawing board
 

mabool

Member
Licensed User
Longtime User
Ok guys,
since yesterday I've tested my demos on 9 different devices: galaxy S, S2, HTC Desire,SuperPad VII, Galaxy Tab2, Sony Xperia Advance, and so on... on BLueStacks too, and witn android emulator running Jelly Bean (with and without VT HAXM).

It runs fine everywhere, so I really don't know where can be the problem.
Perhaps should I try it without 'AnimationPlus', but without a crashing device, I don't know how to do.

If someone beyond you has five minutes to run it in debug mode and tell me where is the problem ...
 

Informatix

Expert
Licensed User
Longtime User

As I said, it is a problem with the Animation library. Here's why:
- if you replace AnimationPlus by Animation, the result is the same (nothing happens on my Nexus 7, or very lately);
- if you remove the animation, the menu shows and hides properly.

As your tries suggest, it is maybe a problem with the Nexus 7 hardware or the new OS (Jelly Bean 4.1.2, the emulator has only 4.1). I'm going to try with the hardware acceleration set to false. EDIT: same result.
 
Last edited:

mabool

Member
Licensed User
Longtime User
Thank you Informatix. A new animation library coming soon I guess.

PS: I've updated the emulator yesterday and jelly bean 4.1.2 is active.
 

Informatix

Expert
Licensed User
Longtime User
OK, GOT IT !
You must explicitely define the hardware acceleration to true to make it work. I have no idea why it is mandatory here and not in my class "Floating Windows".

On the Nexus 7, the hardware acceleration is not activated by default for apps (only for OS).
 

mabool

Member
Licensed User
Longtime User
Version 1.11 (forgot two lines of code) uploaded in the first post:

Due to problems with Jellybean, I've added a line in the manifest of every demo :
B4X:
SetApplicationAttribute(android:hardwareAccelerated, "true")

It runs fine and fastest in the emulator 4.2.

I would like to thank Informatix for his precious help.
 
Last edited:

yuhong

Member
Licensed User
Longtime User
I test it, but can't compiling!

Compiling code. 0.02
Compiling layouts code. 0.00
Generating R file. Error
AndroidManifest.xml:17: error: No resource identifier found for attribute 'hardwareAccelerated' in package 'android'

I modify AndroidManifest.xml,delete it and compiling....
 
Last edited:

Sytek

Active Member
Licensed User
Longtime User
Tested on Viewsonic Viewpad7 2.2.1 Android Version. Works Just Fine; But the Menu shows just only once if I press the Menu Key Again, if I trap the Keycode on a Message Box the menu shows just fine; But I don't need to display the message box how can I Show the Menu without trapping the key on a msgbox?
Thank's in advance!

B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'handles the menu key
   If KeyCode = KeyCodes.KEYCODE_MENU Then 'menu 
       Msgbox(KeyCodes.KEYCODE_MENU,"pressed key")
      If Menu.IsInitialized Then
         If (Menu.AnimIsPlaying = False) AND (Menu.AnimState = True) Then
            Menu.Hide
            Return
         End If   
         If (Menu.AnimIsPlaying = False) AND (Menu.AnimState = False) Then
         
         ' These lines are there juste for fun
         If CB_DIRECTIONS.Checked = True Then
            Menu.mbDirectionIn = Rnd(0,3)
            Menu.mbDirectionOut = Rnd(3,6)
         End If
         ' These lines are there juste for fun
      
         Menu.Show
         End If   
      End If
   End If
End Sub
:sign0098:
 

Scantech

Well-Known Member
Licensed User
Longtime User
Thank you for this wonderful class.

The highlight was not clearing and can't cancel on drag. Here is a better touch handling (Sort of). Still have problem with selecting multiple buttons.

Need to find a way to set click sound and multiple buttons highlighting issue

B4X:
Sub Class_Globals
 
 
   Private ButtonAway As Boolean
Private LastPanel as Panel
End Sub


B4X:
 Private Sub Button_Touch (Action As Int, x As Float, Y As Float)

   If isVisible = True Then
      Dim tempPanel As Panel
      tempPanel = Sender 
      
      Select Action
 
         Case mbActivity.ACTION_DOWN
            If LastPanel.IsInitialized Then
               If LastPanel <> tempPanel Then
                  LastPanel.Color = Colors.ARGB(0, 0, 0, 0)
               End If
            End If
            
            ButtonAway = False
            tempPanel.Color = Colors.ARGB(100, 100, 100, 100)
            
            LastPanel = Sender
         Case mbActivity.ACTION_UP
            If ButtonAway = True Then Return      'CANCEL THE SELECTED BUTTON

            If LastPanel.IsInitialized Then
               If LastPanel <> tempPanel Then
                  LastPanel.Color = Colors.ARGB(0, 0, 0, 0)
               End If
            End If
            
            tempPanel.Color = Colors.ARGB(0, 0, 0, 0)
            
            If SubExists(mbModule, mbEventName) Then
               CallSub2(mbModule, mbEventName, tempPanel.Tag)
            End If
         Case mbActivity.ACTION_MOVE

            If (x <= tempPanel.Width AND x >= 0) AND (Y <= tempPanel.Height AND Y >= 0 )Then
               ButtonAway = False
               LastPanel.Color = Colors.ARGB(100, 100,100, 100)
            Else
               ButtonAway = True
               LastPanel.Color = Colors.ARGB(0, 0, 0, 0)
            End If


      End Select
 
   End If
 
End Sub
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…