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: 520
  • IL_SpotLightMenuv1.02.zip
    7.8 KB · Views: 519
  • IL_SpotLightMenuv1.03.zip
    8.1 KB · Views: 517
  • Example.zip
    37 KB · Views: 894
  • IL_SpotLightMenuv1.04.zip
    8.1 KB · Views: 892
  • Source.zip
    39.9 KB · Views: 694
Last edited:

ilan

Expert
Licensed User
Longtime User
How can I change the width of the Spotlight PopUp Menu?

The width is calculated automatically.
The item with the longest string will define the width of the menu. If you want the menu width to be bigger you can add blank spaces to the item text like:

Spotlightmenu.additem("item1 ",Colors.Red,15,Null)
Spotlightmenu.additem("item2 ",Colors.Red,15,Null)
...
 

Enrico79

Member
Licensed User
Longtime User
The width is calculated automatically.
The item with the longest string will define the width of the menu. If you want the menu width to be bigger you can add blank spaces to the item text like:

Spotlightmenu.additem("item1 ",Colors.Red,15,Null)
Spotlightmenu.additem("item2 ",Colors.Red,15,Null)
...

Thanks for your reply, but on some devices I have an unwanted line break!

Is there a better method?
 

Enrico79

Member
Licensed User
Longtime User
ok, can you upload a small project only with the popup menu that has a line break on your galaxy 6 so i can test it.

thank you
B4X:
'Create Spotlight Menu
    Spotlightmenu.Initialize(Me,"Spotlightmenu",8%y,False,False,True,ButtonMenu,Activity)
    Spotlightmenu.additem("Favoritenliste",Colors.Black,15,LoadBitmapSample(File.DirAssets,"menu_star_256.png",256,256))
    Spotlightmenu.additem("Filter anwenden",Colors.Black,15,LoadBitmapSample(File.DirAssets,"menu_filter_256.png",256,256))


The second menu entry has a line break!
 

ilan

Expert
Licensed User
Longtime User
B4X:
'Create Spotlight Menu
    Spotlightmenu.Initialize(Me,"Spotlightmenu",8%y,False,False,True,ButtonMenu,Activity)
    Spotlightmenu.additem("Favoritenliste",Colors.Black,15,LoadBitmapSample(File.DirAssets,"menu_star_256.png",256,256))
    Spotlightmenu.additem("Filter anwenden",Colors.Black,15,LoadBitmapSample(File.DirAssets,"menu_filter_256.png",256,256))


The second menu entry has a line break!

ok i have tried it on Genymotion and i can reproduce it.

for now you can do this to avoid a line break:

B4X:
'Create Spotlight Menu
    Spotlightmenu.Initialize(Me,"Spotlightmenu",8%y,False,False,True,ButtonMenu,Activity)
    Spotlightmenu.additem("Favoritenliste",Colors.Black,15,LoadBitmapSample(File.DirAssets,"menu_star_256.png",256,256))
    Spotlightmenu.additem("Filter anwenden ",Colors.Black,15,LoadBitmapSample(File.DirAssets,"menu_filter_256.png",256,256))

the space after "Filter anwenden " will make the string longer and that will make the label width bigger.
i guess the calculation of the string length is not 100% correct.
 

alexb

Member
Licensed User
Longtime User
Hi, I have a problem with versions 1.02 - 1.04 of the libs when executing the sample program (with 1.01 it works with no problem!). I get following exception at line 30 of the sample program [ Spotlightmenu.additem("Inbox(5)",Colors.Red,15,LoadBitmap(File.DirAssets,"mailinbox.png")) ]

** Activity (main) Create, isFirst = true **
main_activity_create (java line: 342)
java.lang.NoSuchMethodError: No static method ObjectToCharSequence(Ljava/lang/Object;)Ljava/lang/CharSequence; in class Lanywheresoftware/b4a/BA; or its super classes (declaration of 'anywheresoftware.b4a.BA' appears in /data/app/b4a.spotlightmenu-2/base.apk)
at b4a.example.spotlight._additem(spotlight.java:76)
at b4a.spotlightmenu.main._activity_create(main.java:342)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at b4a.spotlightmenu.main.afterFirstLayout(main.java:102)
at b4a.spotlightmenu.main.access$000(main.java:17)
at b4a.spotlightmenu.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7225)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

I am using v6.5 of B4A and configured the path for platforms\android-21\android.jar (tried with other lower versions but does not help).

Did anybody have the same problem ? -Thank you
 

DonManfred

Expert
Licensed User
Longtime User
Last edited:

alexb

Member
Licensed User
Longtime User
I guess this is the problem. The Library is compiled - again i guess - with B4A 6.8+ to support the new Charsequences. But this means to you that you need to have B4A 6.8+ to use it.

WOW - Thanks for the hint - updated to 6.8, used latest libraries for testing and issue is indeed gone !!!
 

ilan

Expert
Licensed User
Longtime User
I guess this is the problem. The Library is compiled - again i guess - with B4A 6.8+ to support the new Charsequences. But this means to you that you need to have B4A 6.8+ to use it.

this is interesting. i think there should be an option to choose the minimum b4a version compatibility when compile a lib in b4a.
if i update my b4a version and then make a very small modification on my lib it will become only available on the b4a version it was compiled and this is not really necessary.

i will open a thread in the wishlist maybe @Erel can do something to make the lib work on the minimum b4a version that is needed without be depending on the b4a version it was compiled.
 

ilan

Expert
Licensed User
Longtime User

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi. I am thinking to use this nice feature for displaying some country flags and doing the relative choice.
I just copied the code from Ilan example.
The difference is that I haven't put the button on a panel, but directly on activity. (In my code the "btn" button is named "Lingua").
My code is hereunder, followed by the log with the error. The program, anyway, works.
Any hint? Thanks in advance.

B4X:
Sub Globals
 Private splight As SpotLight
 Private Lingua As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
 
 Activity.LoadLayout("Main")
 
 'Create Spotlight Menu
 Dim Italia,England,Russia As Bitmap  ' used alwasy same jpg for the flags, just experiment
 Italia.Initialize(File.DirAssets,"italia.jpg")
 England.Initialize(File.DirAssets,"italia.jpg")
 Russia.Initialize(File.DirAssets,"italia.jpg")
 
 splight.Initialize(Me,"splight",10%y,False,False,True,Lingua,Activity)
 
 splight.additem("Italia", Colors.Black,18,Italia)
 splight.additem("England",Colors.Black,18,England)
 splight.additem("Russia", Colors.Black,18,Russia)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub Lingua_Click
 splight.show
End Sub
Sub Lingua_LongClick
 Lingua_Click
End Sub

LOG:

** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 32 (Starter)
java.lang.NullPointerException: Attempt to read from field 'int android.view.ViewGroup$LayoutParams.width' on a null object reference
at anywheresoftware.b4a.objects.ViewWrapper.getWidth(ViewWrapper.java:140)
at b4a.example.spotlight._show(spotlight.java:509)
at b4a.OpenMuseum.main._lingua_click(main.java:421)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:5714)
at android.widget.TextView.performClick(TextView.java:10926)
at android.view.View$PerformClick.run(View.java:22589)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
** Activity (main) Pause, UserClosed = true **
--------- beginning of system
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
 

GaryK4

Member
Licensed User
Longtime User
Is it possible to use an Activity.AddMenuItem3 as the view for Spotlight to be linked to?

When I do report_click, I want the Spotlight menu to appear.
Activity.AddMenuItem3("Reports","report",LoadBitmap(File.DirAssets,"box_blue.png"),True)
 

ilan

Expert
Licensed User
Longtime User
You want to call the spmenu from a menu button? It should be posibble but i guess your menu will disappear. And also not all devices has a menu button. Using menus today is maybe not a good idea. I can access my menu only with a long press on it. I even didnot knew it is possible so will risk that people will not find the menu and wont be able to access those options.

Better to use button instead.
 

GaryK4

Member
Licensed User
Longtime User
You want to call the spmenu from a menu button? It should be posibble but i guess your menu will disappear. And also not all devices has a menu button. Using menus today is maybe not a good idea. I can access my menu only with a long press on it. I even didnot knew it is possible so will risk that people will not find the menu and wont be able to access those options.

Better to use button instead.

I think you misread my post. I am adding an Icon on the StdActionBar using AddMenuItem3. I am NOT trying to use a devices menu button.

I don't know if it is possible to add a button to the StdActionBar. I was hoping an Icon serve as a button for Spotlight with the correct coding.
 

Paulo Rosa

Member
Licensed 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,
 
Top