B4A Library [Class] ModularMenu

Dominex

Active Member
Licensed User
[Class/Library] ModularMenu

I created a simple alternative to the standard menu similar to the one used by many apps.

Requires the library AnimationPlus V2!.

Events:
- Click

Methods:
- AddMenuItem
- AddMenuItemAt
- OpenMenu
- CloseMenu
- IsOpen
- RenameItem

- RemoveAt
- RemoveAll
- MenuLock
- MenuUnlock
- KeyMenuPress
- Size

[ UPDATE 1.10 ]
- Added the method AddMenuItemAt to add an item at a specific position.

[ UPDATE 1.20 ]
- Added the method RemoveAll.
- Now the events are generated in different activity from the Main.

[ UPDATE 1.32 ]
- Inserted also Library version in Zip Class.
- Adding methods LoadItem and SaveItem to use the same menu with any Activity. I have included an example Multi-Activity in the Zip (use the library for this).
- Small improvements.

[ UPDATE 1.33 ]
- Minor bugfix.

[ UPDATE 1.34 ]
- Fixed bug with RemoveAll method.
- Fixed the forced closure devices with ICS.

[ UPDATE 1.36 ]
- Added the method RenameItem and IsOpen.
- Modified slightly the animation menu.

[ UPDATE 1.37 ]
- Fixed some bugs.

IMPORTANT
For most fluidity add this code to the Manifest:
B4X:
SetActivityAttribute(Main, android:hardwareAccelerated, "true")
For suggestions and bug reports please do not hesitate to post it here.
 

Attachments

Last edited:

ivanomonti

Well-Known Member
Licensed User
problem compiler

error line

Dim AnimSet As AnimationSet (no AnimationSet lib)

AnimationPlus v1 = ok
Animation 1.02 = ok
Reflection v 2.20 = ok

Help ...
 

Harris

Expert
Licensed User
When manifest reads:

<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>
the menu button will not appear on my Nexus 7

when:
<uses-sdk android:minSdkVersion="4" /> - menu button is enabled but tabhost behaves badly...

Anyway to have both function fine?

BTW, nice class.

Changed android:targetSdkVersion="14" to android:targetSdkVersion="10" and it works (looks old school however)
 
Last edited:

Dominex

Active Member
Licensed User
When manifest reads:

<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>
the menu button will not appear on my Nexus 7
Me too Android:targetSdkVersion = "14" disappears from the menu button, but I do not know why.

when:
<uses-sdk android:minSdkVersion="4" /> - menu button is enabled but tabhost behaves badly...
I did not do the tests, but I think it's weird.

Anyway to have both function fine?

BTW, nice class.

Changed android:targetSdkVersion="14" to android:targetSdkVersion="10" and it works (looks old school however)
At the moment I do not have a solution, I have to experiment with the new function to create libraries, so maybe I'll find a solution.
 

Harris

Expert
Licensed User
If I use the standard menus with SDK 14, the menu button will appear, however not when using this class... (if this helps in anyway).
 

Dominex

Active Member
Licensed User
[ UPDATE 1.32 ]
- Inserted also Library version in Zip Class.
- Adding methods LoadItem and SaveItem to use the same menu with any Activity. I have included an example Multi-Activity in the Zip (use the library for this).
- Small improvements.
 

barx

Well-Known Member
Licensed User
I'm trying to use this class but struggling, when I run your demo, all seems to work fine. Then I add the class to my project and use the following code to build the menu

B4X:
Dim Menu As clsModularMenu ' in sub globals
.....

Menu.Initialize(5, 49dip, Activity, Me) 'in Activity_Create

......

'then as part of one of my subs I have (only test data to see if works)
Menu.RemoveAll 'remove previous items 
   Menu.AddMenuItem("menu item 1" & ID, Null, "mnu") 'ID is an Int 
   Menu.AddMenuItem("menu item 2" & ID, Null, "mnu")
   Menu.AddMenuItem("menu item 3" & ID, Null, "mnu")
   Menu.AddMenuItem("menu item 4" & ID, Null, "mnu")
   
   Menu.OpenMenu
......

'then a sub to catch the click

Sub mnu_Click
   ToastMessageShow("clicked", False)
End Sub
The menu shows ok but when i click an item I get the Unfortunately, App Name has stopped. error and it closes. The strange thing is, If I try to debug the code and step through a line at a time, there is no error, it complete execution fine. Any Ideas?

The log shows the following error.

B4X:
java.lang.NullPointerException


   at android.view.GLES20RecordingCanvas.drawPatch(GLES20RecordingCanvas.java:97)
   at android.graphics.NinePatch.draw(NinePatch.java:125)
   at android.graphics.drawable.NinePatchDrawable.draw(NinePatchDrawable.java:189)
   at android.widget.ListView.drawDivider(ListView.java:3244)
   at android.widget.ListView.dispatchDraw(ListView.java:3147)
   at android.view.View.draw(View.java:10981)
   at android.widget.AbsListView.draw(AbsListView.java:3400)
   at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
   at android.view.View.draw(View.java:10981)
   at android.view.ViewGroup.drawChild(ViewGroup.java:2887)
   at android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489)
   at android.view.View.draw(View.java:10981)
   at android.view.View.getDisplayList(View.java:10417)
   at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2597)
   at android.view.View.getDisplayList(View.java:10380)
   at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2597)
   at android.view.View.getDisplayList(View.java:10380)
   at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2597)
   at android.view.View.getDisplayList(View.java:10380)
   at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2597)
   at android.view.View.getDisplayList(View.java:10380)
   at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:875)
   at android.view.ViewRootImpl.draw(ViewRootImpl.java:1910)
   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1634)
   at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
   at android.os.Handler.dispatchMessage(Handler.java:99)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4575)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
   at dalvik.system.NativeStart.main(Native Method)
Android 4.0.4

Thanks
 

Dominex

Active Member
Licensed User
@barx

The method RemoveAll contains a small error, but I'm not sure that this is your problem. Now upload the correct code. please re-download the file.

I tried your code, it works for me correctly, I attach my test with your code.

If it does not work I'll need more information about your code.
 
Last edited:

barx

Well-Known Member
Licensed User
Still the same, yet again the demo / test works fine. There must be a conflict somewhere. I trigger the menu by clicking a listview item, similar effect to a context menu. maybe it's that. I will keep trying to figure it out. Don't really want to put this on public forum but could send it private if you like. As this is a free class, I don't want to take too much of your time mate.

Thanks
 

Dominex

Active Member
Licensed User
Still the same, yet again the demo / test works fine. There must be a conflict somewhere. I trigger the menu by clicking a listview item, similar effect to a context menu. maybe it's that. I will keep trying to figure it out. Don't really want to put this on public forum but could send it private if you like. As this is a free class, I don't want to take too much of your time mate.

Thanks
If you send me with PM your code will give him a look, maybe I'll find the problem.
 

barx

Well-Known Member
Licensed User
PM Sent, thanks
 

Dominex

Active Member
Licensed User
PM Sent, thanks
I'm testing your app. I tried it on five different devices with different OS, it works on all of them except the one with the version 4.0.3 (the one with ICS). At this point the problem would seem to be here. I'll try to figure out what's wrong.
 
Top