B4J Tutorial [ABMaterial] Reserve a row ( Google maps example)

res2.jpg


When the page is first shown, it looks like this:

res1.jpg


There are times when (someone) wishes the map could be shown full screen, as in the first image above...:

Since the buildpage uses a container for the grid, page.cell(3,1) (3 wide) and the Gmap in page.cell(3,2) (9 wide), I desired a method to show the map full screen when desired (click on the Icon next to REFRESH to toggle ).

The only way around this, I found was to reserve a row, page.cell(2,1) (12 wide).
B4X:
Buildpage...
   page.AddRowsM( 1,False,  10,  3, "rowtheme").AddCellsOSMP(1,0,0,0, 3,3,3,  2 , 0,  0,0,"cnter") .AddCellsOSMP(3,0,0,0,3,3,3, 5,  5, 0, 0,"cnter") ' top row with buttons
    page.AddRowsM(1 ,False, 0,0,"") .AddCellsOSMP(1,0,0,0,12,12,12,0,0,0,0,  "") ' reserved row for full screen Gmap
    page.AddRows(3 ,False, "") .AddCellsOSMP(1,0,0,0,3,3,3,0,0,0,0,  "").AddCellsOSMP(1,0,0,0,9,9,9,0,0,10,0,  "") ' some spare rows....

The ToggleMap_Clicked method:

B4X:
Sub btntogmap_Clicked(Target As String)

    Dim hgt As Int =  750 ' default height
    Try
        Dim browwh As String = ABM.GetBrowserWidthHeight(page)
        Log(" page info: "&browwh)
        Dim idx As Int = browwh.IndexOf(";")
        Dim hgt As Int = browwh.SubString(idx+1)
        Log("map hgt: "&hgt)
    Catch
        Log("Last error init map: "&LastException.Message)
    End Try

' set full screen or normal view
' remove component and add Gmap to the correct row, cell
    If maptog Then  ' global var
       maptog = False
       page.Cell(2,1).RemoveAllComponents
       gm1.Initialize(page,"gm1",  0,0 ,  14,  hgt-130 ,ABM.GOOGLEMAPTYPE_SATELLITE,0)
       page.Cell(3,2).AddComponent(gm1)
    Else
       maptog = True
       page.Cell(3,2).RemoveAllComponents
       gm1.Initialize(page,"gm1",  0,0 ,  14,  hgt-130 ,ABM.GOOGLEMAPTYPE_SATELLITE,0)
       page.Cell(2,1).AddComponent(gm1)
    
    End If
    LoadCases(1,False)
    gm1.Refresh
    page.Refresh

End Sub
 

Harris

Expert
Licensed User
Is the yellow list a container? If so, maybe changing its visibility could do the trick (untested)

"Since the buildpage uses a container for the grid, page.cell(3,1) (3 wide) and the Gmap in page.cell(3,2) (9 wide)"


Yes, it is a container. Sorry, I use Grid and Table in the same context. It is 3 wide, map is 9 wide.

I tried setting its' visibility (to hide), but a refreshed Gmap, page and container - I could not get the Gmap to show full width of page! Frigged around endlessly with this construct. I have seen this in the past (myself), if I hide (or remove) the component from cell(1,1), then cell(1,2) would consume the full width of the page. Not here thou, the Gmap would still only show 9 wide.

This is what DROVE me (nuts) to the example posted (dog with a bone - can't let it go...).

Is there any harm with removing a component, then re-initing it like I have done (potentially over and over again)? I have tried it many, many times with no ill effects (that I see).

Does RemoveCompont (removeall) actually destroy the object? I don't want to trap myself; or anyone else who may make (ill-use) of this example.

I was going to ask if we had a SideBar "left" we could invoke, but you are (always) busy with other important matters.

Note: Dummy reserved row uses AddRowsM to set top and bottom margin to 0 (otherwise 20 by default)
page.AddRowsM(1 ,False, 0,0,"") .AddCellsOSMP(1,0,0,0,12,12,12,0,0,0,0, "") ' reserved row for full screen Gmap


Thanks for your concern.
 
Last edited:

alwaysbusy

Expert
Licensed User
Just to be sure I'm not missing something...

I mean is the first control in page.cell(3,1) a ABMContainer (with all the yellow stuff in it)?

e.g.

B4X:
Dim myCont as ABMContainer

' add everyting in the yellow part to this container

page.cell(3,1).AddComponent(myCont)

if so, then maybe using:
B4X:
myCont.Visibility = ABM.VISIBILITY_HIDE_ALL ' or ABM.VISIBILITY_ALL to show it again.
myCont.Refresh
 
Last edited:

alwaysbusy

Expert
Licensed User
Is there any harm with removing a component, then re-initing it like I have done (potentially over and over again)? I have tried it many, many times with no ill effects (that I see).
It can't hurt I think. It is a bit resource consuming (has to send the whole object + initialization javascript over again to the browser), but in your case, this does no great implications as it happens on a user interaction anyway. If my above described thing could work, it only has to send the visibility.

Does RemoveCompont (removeall) actually destroy the object?
Yes
 

Harris

Expert
Licensed User
Yes, True, a container - many of my other examples use this same construct (containers are the way to build stuff).

Tried all that. Even after hide (and refresh), since that had no affect, tried remove component, and refresh (cell should be blank). that had no effect.
I tried all the usual suspects - as we have gone thru since version 1.0.

After hours (truly), trying all we know (hide, show, remove component, etc), I gave up and said - what the heck, use a blank row and switch back and forth.
I understand the need to refresh - showing, hiding, creating new, altering, etc... Nothing worked (after hours screwing with it).

Is there a (potential) problem with this? (other than server hits - if that exists)?

Thanks
 

Harris

Expert
Licensed User
We are stomping each other... Just got your response...
 

Harris

Expert
Licensed User
Thanks. My concern was a memory leak. Not so much a browser or server hit.
I once read you said one should not re-init components - unexpected results may occur.

But, if they were removed first (in my mind) - then it was like the first time (a virgen ). Nes pa?

Edit: I think you already answered this above...
 
Last edited:

alwaysbusy

Expert
Licensed User
Just for a test: what happens if you do
I once read you said one should not re-init components - unexpected results may occur.
This is true for a component that still exists in the browser and has not been removed. In your case, you handled it correctly.

Can you mail me the .bas file (zipped) for this page? I can't think of a reason why the visibility shouldn't work.
 

Harris

Expert
Licensed User
Just for a test: what happens if you do

This is true for a component that still exists in the browser and has not been removed. In your case, you handled it correctly.

Can you mail me the .bas file (zipped) for this page? I can't think of a reason why the visibility shouldn't work.
I could, but it relies on my db (and project). Could send you the whole thing (project and Mysql DB - you have most of it now as was sent in the past, (but many changes)

I agree, if you remove (or hide) a component in cell 1, regardless of it's size, then the following cells should (or use to) consume the page width. Not here! Thats what thru me off!

Here is the bas...
 

Attachments

  • locationPage.bas
    62.9 KB · Views: 225
Top