Android Example CustomFloatingMenuButton - B4A Library source code

The attached code shows how to create a Floating Menu Button, you can show the button by clicking on a button or a swipe gesture (right edge of the screen).

This is a guide that hopefully will help you write libraries in B4A.

B4A is a POWERFUL Android development tool (despite all its limitations), and is usually overlooked by some users (especially noobs and LAZY "developers")
that's why they are always asking to "wrap" libraries they found around the interwebz (Erel should consider releasing a new version called B4G (Basic For GitHub))
since apparently some users have an infatuation with code posted there and do NOTHING but wrapping those libraries no matter how simple or silly might be,
that been said, some of those libraries could be EASILY done using nothing but Good 'ol B4A code (Fact: ALL my libraries posted are written in 100% B4A),
granted, some libraries would be too difficult if not impossible to write in B4A but there's where we draw the line, what you should do is look at the library
and ask yourselves: How could I do that in B4A? and then code away and TRY IT, don't sit there waiting for someone else to write it for you or posting silly "+1"
posts requesting a wrap, if that's all you do then you will NEVER learn.

Since this is a guide, if you decide to learn and write your own B4A libraries keep in mind the following:

1- Give your libraries/classes a meaningful and descriptive name, in other words, avoid things like naming your libraries/classes like the following:

njdudeCustomButtonLibrary
b4aCustomButtonWrapper
AmazingCustomButtonBySteve

If your library deals with custom buttons then name the library CustomButton, period.

2- Use descriptive names for your methods and parameters, avoid things like the following:

Bad:
B4X:
   setparameters(v As View, t As string)

Good:
B4X:
   SetProperties(TargetView As View, Title As String)

3- Add tooltips/inline help to your methods, that will make things easy to understand when using your library.

B4X:
'Title: The heading or description.
'Range: A number from 1-100.
 Code(Title As String, Range As Int)

4- Use capitalization to make things more legible.

Bad:
B4X:
   gettheviewtype(v As View)

Good:
B4X:
   GetViewType(TargetView As View)

5- Comment your source code properly.

6- Use descriptive names for variables in your source code.

7- Use proper code indentation.

8- Be consistent.

These simple guidelines will help tremendously, not only to you the library author but also other developers (if you post the source code) to learn and understand
what you did and why.

The attached code is a simple example of how B4A can be used to create amazing libraries, I have also attached the APK in case you want to see
what this is all about.

You can do whatever you want with the source code I've posted, use it as a source of inspiration to create your own B4A libraries.

B4A Rulez!!

Screenshots:

vApcRZF.png
pVH7Eew.png


Enjoy!
 

Attachments

  • CustomFMB.apk
    277.8 KB · Views: 583
  • CustomFloatingMenuButton_SourceCode.zip
    15.4 KB · Views: 1,228
Last edited:

Star-Dust

Expert
Licensed User
some of those libraries could be EASILY done using nothing but Good 'ol B4A code (Fact: ALL my libraries posted are written in 100% B4A)
I agree, I also write my Libraries in B4A. If I wanted to use GitHub Libraries I would develop my apps in Java.
If you chose to develop in B4A it makes sense that you also try to create libraries in B4A where you can.
 
Last edited:

jnjft

Member
Licensed User
Thanks NJDude for providing this as source code - there's much to learn for me in it! I've already integrated it in one of my apps as a class named 'myfloatingmenubutton'.
How can it be that I can run your code in debug mode, but everytime I make a 'Release', after starting the app it crashes as soon as the fmb is initialized. When I enter the B4A ide again and have another run in debug mode it shows the following errorlog (belonging to the crashed Release, I guess):

myfloatingmenubutton_initialize (java line: 164)
java.lang.RuntimeException: native typeface cannot be made

Can you help me?
 

NJDude

Expert
Licensed User
Hi,

Have you changed anything in the code besides the class name?, also, what version of B4A do you have?
Have you tried to run the original code in release mode?
 
Last edited:

jnjft

Member
Licensed User
Hi, thanks for your reply!
I have B4A ver. 7.3, and this also happens when I 'Release' your original example program without any changes - it runs in debug mode, but crashes after I've made a Release
(The OS says ¨B4A example wurde angehalten.¨ - german for 'was stopped/halted')
The device I'm working with is a few years old, though, it's a Galaxy Tab 2 and it runs Android 4.2.2. Could it be that I have to adjust the target version in the Manifest file?
But why is it running in debug mode then? Is it possible, that debug mode automatically gains some permissions the app needs, and Release doesn't?
Many thanks for your effort!
 

NJDude

Expert
Licensed User
It might be the device, I'll have to open my junk drawer and pull my Galaxy Tab 10 and test it myself.

I'll keep you posted.

In the meantime: check THIS thread and see if that fixes the problem.
 
Last edited:

jnjft

Member
Licensed User
Hi, thanks to all for the quick reply and sorry for the late response - had a few busy days...
And now I'm sitting at my laptop without my tablet, because I forgot it at my working place. So I cannot test right now.
I updated my Android SDK to version 23.0.2, thanks to NJDude!
@Mahares: I had to install the mentioned modules to get the app running (in debug mode only, though), but at the time I can't determine which version.
I will have my device with me when I get home tomorrow and look for the versions and see what changes with the new SDK.
Thanks for your help!
 

jnjft

Member
Licensed User
Updating the Android SDK solved the problem.
Thanks a lot, NJDude and Mahares!
This floating menu is a really cool thing, thank you for providing it with the source code!
 

NJDude

Expert
Licensed User
Updating the Android SDK solved the problem.
Thanks a lot, NJDude and Mahares!
This floating menu is a really cool thing, thank you for providing it with the source code!
Great!

I hope I get to see one of your creations soon.
 
Top