system topmost window

peacemaker

Expert
Licensed User
Longtime User
It needs help with experiment.

System window can be shown over all.
But updating the label text is wrong, when the activity is closed.

Any ideas ?
 

Attachments

  • system_windows_sample_project.zip
    6.2 KB · Views: 233

mc73

Well-Known Member
Licensed User
Longtime User
The label text is wrong because the activity is paused. You should use a service. Meanwhile, I see labels overlap during running, so here's a code which produces perhaps better results:
B4X:
'Activity module
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim tim As Timer
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.
    Dim btnStart As Button
    'Dim p As Label'Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    
    btnStart.Initialize("btnStart")
    btnStart.Text = "Start Kiosk"
    Activity.AddView(btnStart, 10dip, 10dip, 100dip, 100dip)
    
    tim.Initialize("tim", 1000)
    
End Sub
Private Sub ShowSystemWindow(myText As String)
    
    Dim r As Reflector
    r.Target = r.GetContext
    Dim cwm As Object = r.RunMethod2("getSystemService", "window", "java.lang.String")
    Dim p As Label 
    p.Initialize("p")
    p.Text=myText
    Dim lp As Object
    Dim i As String = "java.lang.int"
    'full screen: lp = r.CreateObject2("android.view.WindowManager$LayoutParams", Array As Object(-1, -1, 2010, 65832, -1), Array As String(i, i, i, i, i))
    'small window test lp = r.CreateObject2("android.view.WindowManager$LayoutParams", Array As Object(50, 50, 2006, 65832, -1), Array As String(i, i, i, i, i))
    'p.Text = "99%"
    lp = r.CreateObject2("android.view.WindowManager$LayoutParams", Array As Object(100, 40, -160, -240, 2010, 65832, -1), Array As String(i, i, i, i, i, i, i))
    r.Target = cwm
    r.RunMethod4("addView", Array As Object(p, lp), _
        Array As String("android.view.View", "android.view.ViewGroup$LayoutParams"))
    
End Sub
Sub Activity_Resume
'tim.Enabled = False ??
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub tim_Tick
ShowSystemWindow(Rnd(1,100))
End Sub

Sub btnStart_Click
    
    If btnStart.Text="Start Kiosk" Then
        btnStart.Text="Stop Kiosk"
        tim.Enabled = True
    Else
        btnStart.Text="Start Kiosk"
        tim.Enabled =False
    End If
End Sub

Sub p_click

    Msgbox("notification click","ok")

End Sub
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Hmmm, service's timer adds the system windows one by one.
But actually, it needs to remove the previous one before showing the new.

But how to save the existing window ID to remove it from the service ?
 
Last edited:
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
interesting in adding views and creating windows using reflection

I found this old thread,
the projst failed on me due to permission missing to open such a window

anyone has an updated code ?
I'm trying to create a window outside of an activity (like the standout lib) and add view and objects to it,

any idea ?
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Forgotten the manifest permission:
AddPermission(android.permission.SYSTEM_ALERT_WINDOW)

It's really possible to create such window, but need not only create, but update also - but i don't know how.
I was trying to remove the window by "RemoveView" ViewGroup | Android Developers, but....failed
 
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
its working fine

thanks, its working fine now,

btw this line remove the view correctly :
B4X:
r.RunMethod4("removeView",Array As Object(p), Array As String("android.view.View"))
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
But firstly "p" needs to be saved to be removed later, how to save the activity object in service and later to use for remove ?
 
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
saving the view

sure, I just put P (in my code its a panel, with many objects on it)
in the global sub

I keep P initialized all the time, and the remove just remove it from the view and later put it back
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Pls, piece of Dim code. Do you use a service for upding the window ?
 
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
sorry still not able to do that, I have an idea on how to do that, if you create all the objects using reflections add them using reflection to the reflector it might work
 
Upvote 0
Top