B4A Library Spotlight PopUp Menu

hi b4x.com

this is a simple lib i wrote (no wrapper).
Its a Popup Menu in Spotlight look.

this is NOT the feature Spotlight that is available on Android 7, it is a just a PopUp Menu in Spotlight look.

if you like it i would really appreciate a small donation :)

Please tell me if you find any issues or bugs.
I am including the lib files + an example. take a look at it, it should be very simple to understand.
if you have any question don't hesitate to ask me ;)

EDIT: v1.01 support for Fontawesome/Materialdesign Icons (see post #4)

EDIT: v1.02 bug fixed + Example updated

EDIT: v1.03 bug fixed+ Example updated + option to change background color for each item


EDIT: v1.04 bug fixed

EDIT: Source file available!


ezgif.com-77f8f62e38.gif
 

Attachments

  • IL_SpotLightMenuv1.01.zip
    7.6 KB · Views: 574
  • IL_SpotLightMenuv1.02.zip
    7.8 KB · Views: 562
  • IL_SpotLightMenuv1.03.zip
    8.1 KB · Views: 568
  • Example.zip
    37 KB · Views: 946
  • IL_SpotLightMenuv1.04.zip
    8.1 KB · Views: 946
  • Source.zip
    39.9 KB · Views: 751
Last edited:

ilan

Expert
Licensed User
Longtime User
Hi,

I want to implement a popup menu in my app, when I do a long press on a view. I don't want the menu to pop up on a single press on the view, since my app already has an action triggered by a single press on that view. Can I do that with this library?

Regards,

Just put the sp.show command in your button1_longclick event.
 

ziomorgan

Active Member
Licensed User
Longtime User
Hi,
i want change the button bitmap:

B4X:
Dim btn As Button = Spotlightmenu.ItemIcon(2)
btn.SetBackgroundImage(LoadBitmap(File.DirAssets, "no_notifica.jpg"))

but the image is not rounded as the initial one.
Is it a bug?

notifiche.png
no_notifiche.png
 

Mostez

Well-Known Member
Licensed User
Longtime User
first thanks for this great lib., sorry if it seems silly to ask, if I can remove the '=' sign appears at the right end of the menu item.
 

ilan

Expert
Licensed User
Longtime User
first thanks for this great lib., sorry if it seems silly to ask, if I can remove the '=' sign appears at the right end of the menu item.

yes you can. use the class instead of the lib. you can get the class from the source.zip. add it to you project.
now you need to update the "additem" function in the class to this:

B4X:
'Text = Set the Text of the Menuitem
'Text2 = Set the Text of the second Label (=)
'txtColor = Set the Textcolor
'txtsize = Set the Textsize
'bmp = set the icon bitmap
Public Sub additem(Text As String, Text2 as String, txtColor As Int, txtsize As Int, bmp As Bitmap)
   Dim dr As ColorDrawable
   dr.Initialize(Colors.White,(itemHeight/2)-1)

   Dim ItemPnl As Panel
   ItemPnl.Initialize("itempnl")
   ItemPnl.Tag = itemlist.Size
   ItemPnl.Background = dr

   Dim itemlbl As Label
   itemlbl.Initialize("itemlbl")
   itemlbl.Text = Text
   itemlbl.TextColor = txtColor
   itemlbl.Gravity = Gravity.CENTER_VERTICAL
   itemlbl.Typeface = Typeface.DEFAULT
   itemlbl.TextSize = txtsize

   Dim itemlbl2 As Label
   itemlbl2.Initialize("itemlbl2")
   itemlbl2.Text = Text2
   itemlbl2.TextColor = Colors.RGB(43,43,43)
   itemlbl2.TextSize = 24
   itemlbl2.Gravity = Gravity.CENTER
   itemlbl2.Typeface = Typeface.DEFAULT
   itemlbl2.Tag = "lbl"

   Dim itemimgbtn As Button
   itemimgbtn.Initialize("")
   itemimgbtn.Tag = "btn"
   itemimgbtn.Color = Colors.Transparent

   If bmp <> Null And bmp.IsInitialized Then
     itemimgbtn.SetBackgroundImage(updatebmp(bmp))
     itemimgbtn.Gravity = Gravity.FILL
   End If

  'add items to list
   ItemPnl.AddView(itemlbl,itemHeight+2%x,0,0,itemHeight)
   ItemPnl.AddView(itemimgbtn,itemHeight*0.1,itemHeight*0.1,itemHeight*0.8,itemHeight*0.8)
   ItemPnl.AddView(itemlbl2,0,0,itemHeight,itemHeight)
   itemlist.Add(ItemPnl)
End Sub

and now you can add an item like this:

B4X:
    Dim icon As Bitmap
    icon.Initialize(File.DirAssets,"images.png")

    splight.Initialize(Me,"splight",10%y,False,False,True,Button1,Activity)
    splight.additem("Inbox (5)", "#",Colors.Black,18,icon)
    splight.additem("Refresh","%",Colors.Black,18,Null)
    splight.additem("Compose","",Colors.Black,18,Null)

as you can see we are putting another string in our additem call. the second string is the "=" char you see in the menu.
if you dont want anything put an empty string like in the 3rd item.


### OPTIONAL ###
if you would like to update the second label in runtime add this function to the class:

B4X:
'Get the Label2 of the Menuitem
Public Sub ItemLabel2(index As Int) As Label
    If itemlist.Size-1 < index Then
         Log("Index is wrong.")
         Return Null
    End If
    Dim p As Panel = itemlist.Get(index)
    Dim lbl As Label = p.GetView(2)
    Return lbl
End Sub

and you can can update the second label text like this:

B4X:
Sub splight_Click(index As Int)
    Log("selected itemindex: " & index)
    'UPDATE AN ITEM !!!
    splight.ItemLabel2(index).Text = "$"
End Sub
 

ibra939

Active Member
Licensed User
Longtime User
THANKS SO MUCH
 
Top