B4A Library Floating Action Menu (FAM) and Floating Action Button (FAB)

This is a wrap for this Github Project. Thanx to @ivan.tellez for pointing me into it :)
The library is a replacement for the Floating Action Button lib by @corwin42
They are not compatible as we are both using the same Objectname (FloatingActionbutton).

Requires B4A Version 5.8+

FloatingActionButton
Author:
DonManfred (wrapper)
Version: 1.02
  • FloatingActionButton
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • hasShadow As Boolean
    • hide (animate As Boolean)
      Makes the <b>FloatingActionButton</b> to disappear and sets its visibility to {@link #INVISIBLE}
      animate: if true - plays "hide animation"
    • hideButtonInMenu (animate As Boolean)
      <b>This will clear all AnimationListeners.</b>
    • hideProgress
    • isHidden As Boolean
      Checks whether <b>FloatingActionButton</b> is hidden
      Return type: @return:true if <b>FloatingActionButton</b> is hidden, false otherwise
    • isProgressBackgroundShown As Boolean
    • isProgressIndeterminate As Boolean

      Return type: @return:the mProgressIndeterminate
    • setProgress (progress As Int, animate As Boolean)
    • show (animate As Boolean)
      Makes the <b>FloatingActionButton</b> to appear and sets its visibility to {@link #VISIBLE}
      animate: if true - plays "show animation"
    • showButtonInMenu (animate As Boolean)
    • toggle (animate As Boolean)
    Properties:
    • Background As Drawable
    • ButtonSize As Int
      Sets the size of the <b>FloatingActionButton</b> and invalidates its layout.
    • Color As Int [write only]
    • ColorDisabled As Int
    • ColorNormal As Int
    • ColorPressed As Int
    • ColorRipple As Int
    • Elevation As Float [write only]
    • ElevationCompat As Float [write only]
      Sets the shadow color and radius to mimic the native elevation.

      <p><b>API 21+</b>: Sets the native elevation of this view, in pixels. Updates margins to
      make the view hold its position in layout across different platform versions.</p>
    • Enabled As Boolean
    • Height As Int
    • HideAnimation As Animation [write only]
    • IconDrawable As String [write only]
    • ImageDrawable As Drawable [write only]
    • Indeterminate As Boolean [write only]
      <p>Change the indeterminate mode for the progress bar. In indeterminate
      mode, the progress is ignored and the progress bar shows an infinite
      animation instead.</p>
    • LabelText As String
    • LabelVisibility As Int
    • Left As Int
    • Max As Int
    • Parent As Object [read only]
    • Progress As Int [read only]
    • ProgressBackgroundColor As Int
    • ProgressColor As Int
    • ProgressWidth As Int
    • ShadowColor As Int
    • ShadowRadius As Int
      Sets the shadow radius of the <b>FloatingActionButton</b> and invalidates its layout.
      <p>
      Must be specified in density-independent (dp) pixels, which are then converted into actual
      pixels (px).
    • ShadowXOffset As Int
      Sets the shadow x offset of the <b>FloatingActionButton</b> and invalidates its layout.
      <p>
      Must be specified in density-independent (dp) pixels, which are then converted into actual
      pixels (px).
    • ShadowYOffset As Int
      Sets the shadow y offset of the <b>FloatingActionButton</b> and invalidates its layout.
      <p>
      Must be specified in density-independent (dp) pixels, which are then converted into actual
      pixels (px).
    • ShowAnimation As Animation [write only]
    • ShowProgressBackground As Boolean [write only]
    • ShowShadow As Boolean [write only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int
  • FloatingActionMenu
    Events:
    • onClick (obj As View)
    • onMenuToggle (opened As Boolean)
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • addMenuButton (fab As FloatingActionButton)
    • addMenuButton2 (fab As FloatingActionButton, index As Int)
    • close (animate As Boolean)
    • hideMenu (animate As Boolean)
      Makes the {@link #FloatingActionMenu} to disappear and sets its visibility to {@link #INVISIBLE}
      animate: if true - plays "hide animation"
    • hideMenuButton (animate As Boolean)
      Makes the {@link FloatingActionButton} to disappear inside the {@link #FloatingActionMenu} and
      sets its visibility to {@link #INVISIBLE}
      animate: if true - plays "hide animation"
    • isAnimated As Boolean
    • isIconAnimated As Boolean
    • isMenuButtonHidden As Boolean
    • isMenuHidden As Boolean
    • isOpened As Boolean
    • open (animate As Boolean)
    • removeAllMenuButtons
    • removeMenuButton (fab As FloatingActionButton)
    • showMenu (animate As Boolean)
      Makes the whole {@link #FloatingActionMenu} to appear and sets its visibility to {@link #VISIBLE}
      animate: if true - plays "show animation"
    • showMenuButton (animate As Boolean)
      Makes the {@link FloatingActionButton} to appear inside the {@link #FloatingActionMenu} and
      sets its visibility to {@link #VISIBLE}
      animate: if true - plays "show animation"
    • toggle (animate As Boolean)
    • toggleMenu (animate As Boolean)
    • toggleMenuButton (animate As Boolean)
    Properties:
    • ActivityHeight As Int [write only]
    • ActivityWidth As Int [write only]
    • Animated As Boolean [write only]
      Sets whether open and close actions should be animated
    • AnimationDelayPerItem As Int
    • Background As Drawable
    • ClosedOnTouchOutside As Boolean [write only]
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • IconAnimated As Boolean [write only]
    • IconAnimationCloseInterpolator As Interpolator [write only]
    • IconAnimationInterpolator As Interpolator [write only]
      Sets the {@link android.view.animation.Interpolator} for <b>FloatingActionButton's</b> icon animation.
    • IconAnimationOpenInterpolator As Interpolator [write only]
    • IconToggleAnimatorSet As AnimatorSet
    • LabelsCornerRadius As Int
    • LabelsMargin As Int
    • LabelsMaxLines As Int
    • LabelsPaddingBottom As Int
    • LabelsPaddingLeft As Int
    • LabelsPaddingRight As Int
    • LabelsPaddingTop As Int
    • LabelsPosition As Int
    • Left As Int
    • MenuButtonColorNormal As Int
    • MenuButtonColorPressed As Int
    • MenuButtonColorRipple As Int
    • MenuButtonHideAnimation As Animation [write only]
    • MenuButtonLabelText As String
    • MenuButtonShowAnimation As Animation [write only]
    • MenuIconView As ImageView [read only]
    • OpenDirection As Int
    • Parent As Object [read only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int

Known problems:
- I still don´t know what the problem is, but the first 2 FABs (FloatingActionButton) added to the FAM (FloatingActionMenu)will be ignored; they do not show in menu
But away from this it works fine here

Screenshot_20160325-080229.png


If you want to donate for my work building the wrapper you can do it here:
 

Attachments

  • FAMFABEx.zip
    18.3 KB · Views: 1,895
  • FloatingActionButtonV1.0.2.zip
    57 KB · Views: 1,941
Last edited:

ArminKH

Well-Known Member
thank u
and it seems first time mButtonsCount variable is -2 see this
B4X:
public void addMenuButton(FloatingActionButton fab, int index) {
        int size = mButtonsCount - 2;
        if (index < 0) {
            index = 0;
        } else if (index > size) {
            index = size;
        }

        addView(fab, index);
        mButtonsCount++;
        addLabel(fab);
    }
i think when for first time we want to add 5 button then the size will be -2 (because mButtonsCount is 0 and mButtonsCount - 2 is equal to -2)so it's ignore 2 button for first time
so when we add 7 button then size is 5 and 5 items will be added
try to add first item at index -1 then u can see 4 of 5 button will be shown
i don't know but any way i think it's relevant to mButtonsCount variable
I think mButtonsCount should be 2 as default to solve this problem
thank u for this great lib
 
Last edited:

johndb

Active Member
Licensed User
Longtime User
Thank you @DonManfred! Does this Floating Action Button have the provision to link to a list in order provide automatic hide (animated move below screen) when the listview is scrolled to the bottom? I am using @corwin42's FloatingActionButton with @Informatix's ULV and it works rather well but would like to replace it with this one but I rely on this feature.

John
 

woniol

Active Member
Licensed User
Longtime User
Looks nice, but when I try the example i get this
B4X:
4A version: 5.80
Parsing code.    Error
Error parsing program.
Error description: Unknown type: floatingactionmenu
Are you missing a library reference?
Occurred on line: 26 (Main)
Private fam As FloatingActionMenu
 

itgirl

Active Member
Licensed User
Longtime User
Hello and thank you for this great Lib ,, but im having difficulties setting the fam on the right side of the activity even in the example if you just rotate the phone it gets in the middle of the activity ,,, im trying to set it manually not with the designer

B4X:
fam.Initialize("fam")
Activity.AddView(fam,0,0,100%x,100%y)
fam.ActivityHeight =100%y
fam.ActivityWidth = 100%x

i tried to play with left setting ...

B4X:
fam.left = 100dip

is just not working it takes the whole fam 100dip from the left also i tried to give the fam 100dip width and the left as 100%x - 100dip but still no luck .... any ideas ?
 
Last edited:

itgirl

Active Member
Licensed User
Longtime User
Looks nice, but when I try the example i get this
B4X:
4A version: 5.80
Parsing code.    Error
Error parsing program.
Error description: Unknown type: floatingactionmenu
Are you missing a library reference?
Occurred on line: 26 (Main)
Private fam As FloatingActionMenu
did you copy the Lib files in your extra lib folders ?
 

itgirl

Active Member
Licensed User
Longtime User
Ok i've found out whats the issue is ... i think it's related to gravity ... try to make the texts on FloatingActionButton smaller and you will notice the FAM got closer to the left edges so you need to put in a really long text so the FAM stick to the right side .... any solution on this one


my solution was to put a really long text in the first FAB as the first and second already dont show in the menu...
 

itgirl

Active Member
Licensed User
Longtime User
;-) Nice idea...
I was facing similar problems. As of yet i did not found the point to change. Still investigating

i know lol but still not a very good approach because as of some RTL languages it seems to be a problem

do you think the layout has anything to do with it ?

B4X:
<com.github.clans.fab.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|right"
        android:layout_marginBottom="8dp"
        android:layout_marginRight="8dp"
        android:src="@drawable/ic_menu"
        fab:fab_colorNormal="@color/app_primary"
        fab:fab_colorPressed="@color/app_primary_pressed"
        fab:fab_colorRipple="@color/app_ripple"/>

as you can see in the main project the gravity is set to bottom|right
 

stanks

Active Member
Licensed User
Longtime User
buttons can be added to mapfragment but not menu. any idea why? did you try that...maybe?

thanks
 
Top