B4A Library [Class] Floating Windows

Hello,

With this class, you can create floating windows, move them with the finger, dock them, stick them to an edge, maximize them, customize their action bar... You fill them as you fill a panel.

This class needs the Reflection library.

img1.jpg puzzle.png

v1.1:
The class has been splitted in two: ClsFloatingWindow and ClsActionBar.
This version includes a lot of changes.

v1.2:
Fixed bugs
Added a resize button
Added new functions and parameters
Added animations for docking areas and sticky edges
Changed the parameters returned by the custom buttons so as to be consistent with the ready-made buttons
Improved management of overlapping special areas
Improved the formula used to detect a move

v1.21:
Fixed a conflict between StillVisible and the special areas

v1.22:
Fixed two bugs in CheckSpecialAreas (thanks to Awama)

v1.23:
Fixed five bugs (yes, five... :()

v1.24:
Updated the ActionBar class required by this class.

v1.25:
Fixed a bug in the computation of covered areas while docking a window;
Updated the ActionBar class required by this class;
No more warnings with B4A v2.7.

v1.26:
Updated the ActionBar class required by this class.

Fred
 

Attachments

  • FloatingWindows v1.26.zip
    32.6 KB · Views: 1,719
Last edited:

Ondra

Member
Licensed User
Longtime User
APP from GP is useless for me, because I need code. My program is very similar to this class. I need add only that function. Because in this program panels covers each other, I need all of them visible all the time. But still maintain move and resize functions :)
 

Informatix

Expert
Licensed User
Longtime User
Hi !
It is nice work man :) I am trying to do something simillar, but I need to stick panels each other, if the gap beetween panels would be smaller than for exp. 5dip. But because all objects are inserted dynamically, I cannot find way, how to detect collision of the objects. Have you any idea, please ?
I will be glad for any advice ;-)
Since panels are rectangles, it's very simple to detect collisions: check whether the coordinates of the first panel are between the coordinates of the other panel. For example, if X1 or X1+Width1 is between X2 and X2+Width, and Y1 or Y1+Height is between Y2 and Y2+Height, then you know that the first panel si colliding the second panel.
 

TheMightySwe

Active Member
Licensed User
Longtime User

Thraka

Member
Licensed User
Longtime User
Does anyone have layout issues with this class? It seems AutoScaleAll in the layout script on some of my views and depending on the device, will push items off the size of the window. I'm not sure what to do.

I'm using anchors to do the layout. The layout script only has AutoScaleAll in it. If I do a non-anchored layout and use the layout script completely, things look fine.
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
Does anyone have layout issues with this class? It seems AutoScaleAll in the layout script on some of my views and depending on the device, will push items off the size of the window. I'm not sure what to do.

I'm using anchors to do the layout. The layout script only has AutoScaleAll in it. If I do a non-anchored layout and use the layout script completely, things look fine.
The floating windows are made of several panels and these panels are resized in a classic manner: by changing their height or width, so I can't see an obvious reason why these panels should not work properly. But I admit I don't use AutoScaleAll and anchors so I didn't check any compatibility. Anyway, you have the source code of the class, so try some changes and let me know if you find a fix.
 

Thraka

Member
Licensed User
Longtime User
I did strip out a lot of stuff from the class to simplify, removed the docking stuff for example. It's very basic now. Just size the dialog, set the content pop it up. So I'm not sure why it happens either. :( It's really hard to make popups look similar on different form factors. The bane of android I guess.
 

Informatix

Expert
Licensed User
Longtime User
I did strip out a lot of stuff from the class to simplify, removed the docking stuff for example. It's very basic now. Just size the dialog, set the content pop it up. So I'm not sure why it happens either. :( It's really hard to make popups look similar on different form factors. The bane of android I guess.
A lot of people complains about the difficulty with Android to have the same layout on all devices, properly sized. Personaly, I never had any problem because I always created layouts for the smallest screen that should display them and, by using either the dip or % unit depending on what I want to achieve, I got exactly the same layout on all devices, whatever maybe the screen ratio, the resolution or the density. I never used anchors or other "automatic" functions. I don't mean it's always simple, but I do not really understand why that seems so difficult for many developers. A thing is sure: if you want to have a lot of troubles to create a layout for different devices, add AutoScaleAll to your script. This function is evil ! :)
 

winjiadh

Active Member
Licensed User
Longtime User
I have a question,
how can you just let it copy itself? like this code
B4X:
Sub Globals
    Dim Win As ClsFloatingWindow
End Sub
Sub Entering_DockA(Window As ClsFloatingWindow, DockRect As Rect)
       ColorWindow(DockRect)
    Win.AddView(Win,200dip, 100%y - 90dip,90dip,90dip, True )
End Sub
In Demo sample, I drag the win to panel,how to copy a new win ?
thabk you
 

Informatix

Expert
Licensed User
Longtime User
I have a question,
how can you just let it copy itself? like this code
B4X:
Sub Globals
    Dim Win As ClsFloatingWindow
End Sub
Sub Entering_DockA(Window As ClsFloatingWindow, DockRect As Rect)
       ColorWindow(DockRect)
    Win.AddView(Win,200dip, 100%y - 90dip,90dip,90dip, True )
End Sub
In Demo sample, I drag the win to panel,how to copy a new win ?
thabk you
I'm not sure to understand the question. If you want to copy an existing window, then create a new one and copy the settings.
 

winjiadh

Active Member
Licensed User
Longtime User
Right
I want to copy an existing FloatingWindow, How to create a new one and copy the settings?
use the avitvity?
I want move the FloatingWindow into the DockA,and the same time rebuild a new FloatingWindow,same as the moveing FloatingWindow
I use the code like this
B4X:
Sub Globals
    Dim Win As ClsFloatingWindow
    Dim pnl(6) As Panel
    Dim lbl As Label
End Sub
and in the sub Entering_DockA, I add the code
B4X:
Sub Entering_DockA(Window As ClsFloatingWindow, DockRect As Rect)
    ColorWindow(DockRect)
Activity.AddView(Win,200dip, 100%y - 90dip,90dip,90dip, True )
End Sub
but
Parsing code. 0.11
Compiling code. Error
Error compiling program.
Error description: Too many parameters.
Occurred on line: 141
Activity.AddView(Win,200dip, 100%y - 90dip,90dip,90dip, True )
Word: _c
need you help,thanks
 

Informatix

Expert
Licensed User
Longtime User
Right
I want to copy an existing FloatingWindow, How to create a new one and copy the settings?
use the avitvity?
I want move the FloatingWindow into the DockA,and the same time rebuild a new FloatingWindow,same as the moveing FloatingWindow
I use the code like this
B4X:
Sub Globals
    Dim Win As ClsFloatingWindow
    Dim pnl(6) As Panel
    Dim lbl As Label
End Sub
and in the sub Entering_DockA, I add the code
B4X:
Sub Entering_DockA(Window As ClsFloatingWindow, DockRect As Rect)
    ColorWindow(DockRect)
Activity.AddView(Win,200dip, 100%y - 90dip,90dip,90dip, True )
End Sub
but
Parsing code. 0.11
Compiling code. Error
Error compiling program.
Error description: Too many parameters.
Occurred on line: 141
Activity.AddView(Win,200dip, 100%y - 90dip,90dip,90dip, True )
Word: _c
need you help,thanks
I'm sorry but I can only repeat what I said: create a new window with the same settings. There's no Copy or Clone function.
 

winjiadh

Active Member
Licensed User
Longtime User
yes,my english is poor
can you tell me how did I can do
"create a new window with the same settings"
thanks
 

winjiadh

Active Member
Licensed User
Longtime User
thanks
I know how to create a new window
but I have a other question
in your sample, I run the FloatWinDemo2.b4a
in the code
B4X:
Sub After_Undock(Window As ClsFloatingWindow)
    ' We return to the initial size and title
    Win.Resize(90dip, 90dip)
    Win.SetTitleText("Drag me")
    ' We center the window in the docking area
    Win.Move(Win.getLeft + 10dip, Win.getTop + 10dip, True)
    Win.Close
End Sub
I add the "win.close"
But running
when I move the window from dock the Error on
only use the win.hide
can you tell me how to use the win.close
 
Last edited:
Top