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:
Sure
B4X:
standout.Snotif.SetInfo("Hallo","Float",Me) ' Me is Main Activity
I've been trying your solution for long time with no luck, could you please show me how to do it?

B4X:
#Region  Project Attributes
    #ApplicationLabel: Floating StandOut Example 1
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region
' remenber Add on Manifest this permission:
'    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private PanelMain As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("main")
    
    standout.Snotif.Initialize
    standout.Snotif.Icon = "icon"
    standout.Snotif.SetInfo("Title","Body",Me)
    standout.Snotif.Notify(1)
    FloatingStandOut.PathImage=File.DirAssets
    FloatingStandOut.NameFileImage="image2.png"
    FloatingStandOut.X=50%x
    FloatingStandOut.Y=50%y
    FloatingStandOut.SetStartActivity(True,True,False)
    FloatingStandOut.SetStopFloating(True,True,True)
End Sub

Sub Activity_Resume
    FloatingStandOut.Stop
End Sub

Sub Activity_Pause (UserClosed As Boolean)
'    FloatingStandOut.Start(Me)
End Sub

Sub Button1_Click
    Dim Permission As SpecialPermission
    Permission.Initialize
    If Permission.GetPermission Then
        FloatingStandOut.Start(Me)
    Else
        Permission.OpenSettingPermission
    End If
    
    Activity.Finish
End Sub
 

Star-Dust

Expert
Licensed User
Longtime User
I've been trying your solution for long time with no luck, could you please show me how to do it?

B4X:
#Region  Project Attributes
    #ApplicationLabel: Floating StandOut Example 1
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region
' remenber Add on Manifest this permission:
'    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private PanelMain As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    Activity.LoadLayout("main")
   
    standout.Snotif.Initialize
    standout.Snotif.Icon = "icon"
    standout.Snotif.SetInfo("Title","Body",Me)
    standout.Snotif.Notify(1)
    FloatingStandOut.PathImage=File.DirAssets
    FloatingStandOut.NameFileImage="image2.png"
    FloatingStandOut.X=50%x
    FloatingStandOut.Y=50%y
    FloatingStandOut.SetStartActivity(True,True,False)
    FloatingStandOut.SetStopFloating(True,True,True)
End Sub

Sub Activity_Resume
    FloatingStandOut.Stop
End Sub

Sub Activity_Pause (UserClosed As Boolean)
'    FloatingStandOut.Start(Me)
End Sub

Sub Button1_Click
    Dim Permission As SpecialPermission
    Permission.Initialize
    If Permission.GetPermission Then
        FloatingStandOut.Start(Me)
    Else
        Permission.OpenSettingPermission
    End If
   
    Activity.Finish
End Sub
Dear friend,

You added too much stuff and got the opposite result. I didn't write to you to initialize or activate the notification.
In any case, you are definitely making mistakes.

The command to communicate which Task to start is in the service startup.
B4X:
FloatingStandOut.Start (MyActivity)


While if you want there when you click the image opens the activity indicated in the start, the command is this.
B4X:
FloatingStandOut.SetStartActivity (True, True, False)

The first True indicates that with a single click the activity opens, the second true that with 2 clicks the activity will open, the third Boolean relates to the long click.
The example already does this, you don't have to change it. If you change it opt for a different thing.
 
The quoted code is exactly the provided example, I just added the highlighted lines to set the notification info with no success..
I just want you please to show me how to set the notification info in the provided example.
Thanks,
 

Star-Dust

Expert
Licensed User
Longtime User
Sorry, I misunderstood the question. English is not my main language.

I have researched it thoroughly, it is not possible to change the service notification, because it is already started and generates error.

I will try to post an update in the next few days that will allow you to make this change before the service starts
 

Star-Dust

Expert
Licensed User
Longtime User
Update 0.08
This library had not been updated for three years. The time has come to do it​
With version 0.08 it is possible to change the Title and the Body of the notification.​
You can get the full version by making a donation.​

Example:
B4X:
    Activity.LoadLayout("main")

    FloatingStandOut.PathImage=File.DirAssets
    FloatingStandOut.NameFileImage="image2.png"
    FloatingStandOut.X=50%x
    FloatingStandOut.Y=50%y
    FloatingStandOut.SetStartActivity(True,True,False)
    FloatingStandOut.SetStopFloating(True,True,True)
    FloatingStandOut.NotificationTitle="Title"  ' <------ New
    FloatingStandOut.NotificationBody="Body"   ' <------ New
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
Update 0.08 DEMO
This library had not been updated for three years. The time has come to do it​

And I only saw this NOW?!?!?
I remember when @JordiCP first launched his "original" lib and I had issues making it work on a low end Android 5 (?) device, and so we collaborated (mostly I just tested out his stuff until it worked)...
You have done an amazing job!
 

Star-Dust

Expert
Licensed User
Longtime User
Update rel 0.09
Fixed bug that prevented memorizing the last position
 
Top