B4A Library SD: Floating Button StandOut

(No WRAP, but B4A)
I've been in a new challenge. I reworked a little release published by @JordiCP. Find Here

He entered the Java code taken by GitHub (see https://github.com/henrychuangtw/Android-ChatHead) and wrapped it with "#IF JAVA" inside a B4A module.

With his permission I extended a bit of the B4A code and retouched the Java code (for that little I remember Java) and I realized one thing I longed for: A flying button that always stands out even on other Apps On the Desktop.

You can get the full version by making a donation..

SD_FloatingStandOut

Author:
Star-Dust
Version: 0.09
  • FloatingStandOut
    Code module
    Subs in this code module will be accessible from all modules.
    • Fields:
      • ActiveService As Boolean
      • ENABLEDROP As Boolean
      • EventClick As String
      • EventDoubleClick As String
      • EventLongClick As String
      • EventMove As String
      • HALF_STICK_TO_BORDER As Boolean
      • HeightImage As Int
      • NameFileImage As String
      • NotificationBody As String
      • NotificationTitle As String
      • PathImage As String
      • StartActivity_OnClick As Boolean
      • StartActivity_OnDoubleClick As Boolean
      • StartActivity_OnLongClick As Boolean
      • STICK_TO_BORDER As Boolean
      • StopFloating_OnClick As Boolean
      • StopFloating_OnDoubleClick As Boolean
      • StopFloating_OnLongClick As Boolean
      • WhiteCircle As Boolean
      • WidthImage As Int
      • X As Int
      • Y As Int
    • Functions:
      • Process_Globals As String
      • SetEvent (EventName As String) As String
        SetEvent("FL")
        Sub FL_OnClick(X as int, Y as int)
        Sub FL_OnDoubleClick(X as int, Y as int)
        Sub FL_OnLongClick(X as int, Y as int)
        Sub FL_OnMove(X as int, Y as int)
      • SetImageBitmap (img As Bitmap) As String
      • SetStartActivity (OnClick As Boolean, OnDoubleClick As Boolean, OnLongClick As Boolean) As String
      • SetStopFloating (OnClick As Boolean, OnDoubleClick As Boolean, OnLongClick As Boolean) As String
      • Start (Me_CallBack As Object) As String
        Es. Start(Me,Application.PackageName)
      • Stop As String
  • SpecialPermission
    • Functions:
      • ActivatePermissionResumable As ResumableSub
      • Class_Globals As String
      • GetPermission As Boolean
      • Initialize As String
        Inizializza l'oggetto. Puoi aggiungere parametri a questo metodo,se necessario.
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • OpenSettingPermission As String
      • SdkVersion As Int
  • chElement
    • Fields:
      • active As Boolean
      • id As Int
      • instance As JavaObject
      • IsInitialized As Boolean
        Verifica se l'oggetto sia stato inizializzato.
      • ttype As chType
      • xpos As Int
      • ypos As Int
    • Functions:
      • Initialize
        Inizializza i campi al loro valore predefinito.
  • standout
    • Fields:
      • CallBack As Object
      • Snotif As Notification
    • Functions:
      • process_globals


N.B. Don't forget ADD to Manifest
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

request permission SDK 23+
B4X:
    Dim Permission As SpecialPermission
    Permission.Initialize
    If Permission.GetPermission Then
        FloatingStandOut.Start(Me)
    Else
        Permission.OpenSettingPermission
    End If

With resumable sub
B4X:
Sub RequestPermission
    Dim Permission As SpecialPermission
    Permission.Initialize
    Log(Permission.GetPermission)
    Wait For (Permission.ActivatePermissionResumable) Complete (Success As Boolean)
    If Success Then FloatingStandOut.Start(Me)
End Sub
 

Attachments

  • sample1.zip
    48.5 KB · Views: 963
  • sample2.zip
    26.8 KB · Views: 1,012
  • SD_FloatingStandOut 0.09.zip
    21.2 KB · Views: 203
Last edited:

DonManfred

Expert
Licensed User
Longtime User
close the notification in the status bar?
i dont think as the notification is a notification for a foregroundservice. Stop the foregroundservice to remove the icon.
Stopping the foreground service stops the Standout-feature too so it would make the lib useless.
 

diegoferreira

Member
Licensed User
Longtime User
sorry, i mean set it invisible or edit it.. i'm trying to make a custom notification for my app, but when the floating is active it show me 2 notifications in the status bar.

Thanks.
 

Star-Dust

Expert
Licensed User
Longtime User
Now I'm on vacation, just come back I'll make the customizable notification image. As explained by Don Manfred, it can not be eliminated because the service could otherwise be killed
 

Star-Dust

Expert
Licensed User
Longtime User
Here you find the original code, if you delete the service the button will no longer float point.
but if you can do it you can do your own update of the library :p:p

I came back next week:D
 

Shivito1

Active Member
Licensed User
The examples work but when I try to add it to my existing app I get error.

Here is the error:

B4X:
java.lang.RuntimeException: Unable to start service b4a.example.standout@60cdb94 with Intent { cmp=com.subreaderFree/b4a.example.standout launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } }: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3755)
    at android.app.ActivityThread.-wrap23(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1744)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6780)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:216)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:163)
    at b4a.example.standout.handleStart(standout.java:113)
    at b4a.example.standout.onStartCommand(standout.java:81)
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3738)
    ... 8 more
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:131)
    at b4a.example.standout._init_elements(standout.java:314)
    at b4a.example.standout._service_start(standout.java:552)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
    ... 12 more
Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@b54dda6 -- permission denied for window type 2002
    at android.view.ViewRootImpl.setView(ViewRootImpl.java:921)
    at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:342)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:97)
    at b4a.example.standout$CustomImageView.sharedConstructing(standout.java:633)
    at b4a.example.standout$CustomImageView.<init>(standout.java:604)
    at b4a.example.standout.newInstance2(standout.java:771)
    ... 18 more
** Service (standout) Create **
java.io.FileNotFoundException: icon.png
    at android.content.res.AssetManager.openAsset(Native Method)
    at android.content.res.AssetManager.open(AssetManager.java:423)
    at android.content.res.AssetManager.open(AssetManager.java:397)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:202)
    at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize(CanvasWrapper.java:500)
    at anywheresoftware.b4a.keywords.Common.LoadBitmap(Common.java:1160)
    at b4a.example.standout._service_create(standout.java:479)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:163)
    at b4a.example.standout.onCreate(standout.java:66)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3531)
    at android.app.ActivityThread.-wrap6(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1729)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6780)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
java.lang.RuntimeException: Unable to create service b4a.example.standout: java.lang.RuntimeException: java.io.FileNotFoundException: icon.png
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3541)
    at android.app.ActivityThread.-wrap6(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1729)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6780)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: icon.png
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:216)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:163)
    at b4a.example.standout.onCreate(standout.java:66)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3531)
    ... 8 more
Caused by: java.io.FileNotFoundException: icon.png
    at android.content.res.AssetManager.openAsset(Native Method)
    at android.content.res.AssetManager.open(AssetManager.java:423)
    at android.content.res.AssetManager.open(AssetManager.java:397)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:202)
    at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize(CanvasWrapper.java:500)
    at anywheresoftware.b4a.keywords.Common.LoadBitmap(Common.java:1160)
    at b4a.example.standout._service_create(standout.java:479)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
    ... 11 more
 

Star-Dust

Expert
Licensed User
Longtime User
Set a image file.
B4X:
FloatingStandOut.PathImage=File.DirAssets
FloatingStandOut.NameFileImage="imagename.png"
 

Star-Dust

Expert
Licensed User
Longtime User
0.05 release update
Handles special permission requests from the SDK23 + and other changes for SDK26 +

Add this method:
  • GetPermission As Boolean ' Verify special permission - SDK 23+
  • SDK_Version As int ' Get SDK version
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
0.06 release update
Handles special permission requests from the SDK23 + and other changes for SDK26 +

Add this method:
  • GetPermission As Boolean ' Verify special permission - SDK 23+
  • SDK_Version As int' Get SDK version
  • OpenSettingPermission ' Opening setting permission panel
  • ActivatePermissionResumable ' Check the permissions, open the setting panel if there are no permissions.
    Use resumable sub, then return control to the app while waiting for the setting result

request permission SDK 23+
B4X:
    Dim Permission As SpecialPermission
    Permission.Initialize
    If Permission.GetPermission Then
        FloatingStandOut.Start(Me)
    Else
        Permission.OpenSettingPermission
    End If

With resumable sub
B4X:
Sub RequestPermission
    Dim Permission As SpecialPermission
    Permission.Initialize
    Log(Permission.GetPermission)
    Wait For (Permission.ActivatePermissionResumable) Complete (Success As Boolean)
    If Success Then    FloatingStandOut.Start(Me)
End Sub
 
Last edited:

sseaand

Member
Licensed User
Longtime User
I have the error java.lang.RuntimeException: Cannot change properties after call to SetInfo. Initialize the notification again.
 

Star-Dust

Expert
Licensed User
Longtime User
Have you downloaded the latest version?
 

sseaand

Member
Licensed User
Longtime User
Yes, version 0.06. And can you add notification options, to disable it or change notification text?
 

Star-Dust

Expert
Licensed User
Longtime User
Yes, version 0.06. And can you add notification options, to disable it or change notification text?
No, notification is necessary. I will see in the next update if you can customize the message.
 
Top