Android Question Bottom Drawer not working at B4Xpages

AndroidMadhu

Active Member
Licensed User
Hello,
I am following the below example to integrate Bottom Drawer at B4Xpages.

https://www.b4x.com/android/forum/threads/bottom-popup-drawer.111706/#content
While integration I am facing the below error:
B4X:
Error occurred on line: 263 (B4XMainPage)
java.lang.RuntimeException: Object should first be initialized (B4XView).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:88)
at anywheresoftware.b4a.objects.B4XViewWrapper.getHeight(B4XViewWrapper.java:144)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at b4a.example.b4xmainpage._showpanel(b4xmainpage.java:385)
at b4a.example.b4xmainpage$ResumableSub_B4XPage_Appear.resume(b4xmainpage.java:124)
at b4a.example.b4xmainpage._b4xpage_appear(b4xmainpage.java:74)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA$2.run(BA.java:387)
at android.os.Handler.handleCallback(Handler.java:873)



The below is the Code base :

B4X:
Sub CreatePanel
Root.LoadLayout("MainPage")
Overlay = xui.CreatePanel("overlay")

Overlay.Visible = False
Dim p As Panel = Overlay
p.Elevation = 5dip
Root.AddView(Overlay, 0, 0, 100%x, 100%y)
Overlay.LoadLayout("Overlay")
pnlBottom.LoadLayout("Layout1")
pnlBottom.SetColorAndBorder(xui.Color_Red, 0, 0, 15dip)
End Sub

Sub showPanel
Dim Duration As Int = 300
Overlay.SetVisibleAnimated(Duration, True)'OverlayVisible
Dim pnlBottomVisibleHeight As Int = pnlBottom.Height - 8dip 'hide bottom round corners
pnlBottom.SetLayoutAnimated(0, 0, pnlBottom.Parent.Height, pnlBottom.Width, pnlBottom.Height)
pnlBottom.SetLayoutAnimated(Duration, 0, pnlBottom.Parent.Height - pnlBottomVisibleHeight, pnlBottom.Width, pnlBottom.Height)

End Sub

Please advice

Thanks
 

Cableguy

Expert
Licensed User
Longtime User
I think the issue is your overlay panel is never initialized...
Where are you declaring overlay as panel?
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
Are you sure that you called CreatePanel before calling ShowPanel?
Are you sure that pnlBottom was added to "Overlay" layout?
1. I think Yes. I have called CreatePanel before calling ShowPanel
2. I am not sure. I have replaced Root in place of Activity only. rest I am running the as is code.
I am running as is as per the below link....
https://www.b4x.com/android/forum/threads/bottom-popup-drawer.111706/#content

The code is running fine at B4A. But I am facing issue at B4XPages.

Thanks
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
See demo B4XPage B4A or B4J:


1611009917811.png
1611009809318.png


Regards.
 

Attachments

  • B4A-B4XBottomSheet.zip
    12.1 KB · Views: 232
  • B4J-B4XBottomSheet.zip
    5.2 KB · Views: 212
Last edited:
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Some corrections:

Overlay background color

Root.AddView(Overlay, 0, 0, Root.Width, Root.Height)
Overlay.LoadLayout("Overlay")
Overlay.Color = 0x64808080

Capture layout resize event (width and height)

Private Sub B4XPage_Resize (Width As Int, Height As Int)
Overlay.Width = Width
Overlay.Height = Height
End Sub
 
Upvote 0

AndroidMadhu

Active Member
Licensed User
@oparra .... I have run your code. It is running fine.
But when I am including the same at my project it is giving error at below line :
B4X:
pnlBottom.LoadLayout("Drawer") ----> Getting error at this line

Below is the full code base :
B4X:
Sub CreatePanel

Root.LoadLayout("MainPage")
B4XPages.SetTitle(Me, "B4XBottomSheet")

Overlay = xui.CreatePanel("overlay")

#If B4A
Dim p As Panel = Overlay
p.Elevation = 5dip
#End If

Root.AddView(Overlay, 0, 0, Root.Width, Root.Height)
Overlay.LoadLayout("Overlay")

pnlBottom.LoadLayout("Drawer")
pnlBottom.SetColorAndBorder(xui.Color_White, 0, 0, 15dip)

Overlay.Visible = False
End Sub

Please advice

Thanks
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
@oparra .... I have run your code. It is running fine.
But when I am including the same at my project it is giving error at below line :
B4X:
pnlBottom.LoadLayout("Drawer") ----> Getting error at this line

Below is the full code base :
B4X:
Sub CreatePanel

Root.LoadLayout("MainPage")
B4XPages.SetTitle(Me, "B4XBottomSheet")

Overlay = xui.CreatePanel("overlay")

#If B4A
Dim p As Panel = Overlay
p.Elevation = 5dip
#End If

Root.AddView(Overlay, 0, 0, Root.Width, Root.Height)
Overlay.LoadLayout("Overlay")

pnlBottom.LoadLayout("Drawer")
pnlBottom.SetColorAndBorder(xui.Color_White, 0, 0, 15dip)

Overlay.Visible = False
End Sub

Please advice

Thanks

1,.- You must initialize the layouts in "B4XPage_Created".

B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    B4XPages.SetTitle(Me, "B4XBottomSheet")
    
    Overlay = xui.CreatePanel("overlay")

    #If B4A
    Dim p As Panel = Overlay
    p.Elevation = 5dip
    #End If
    
    Root.AddView(Overlay, 0, 0, Root.Width, Root.Height)
    Overlay.LoadLayout("Overlay")
    
    pnlBottom.LoadLayout("Drawer")
    pnlBottom.SetColorAndBorder(xui.Color_White, 0, 0, 15dip)
    
    Overlay.Visible = False
    
End Sub


2. Should be shown and hidden with "ToggleDrawerState"

B4X:
Sub ToggleDrawerState

    Dim Duration As Int = 300
    
    OverlayVisible = Not(OverlayVisible)
    Overlay.SetVisibleAnimated(Duration, OverlayVisible)
    
    Dim pnlBottomVisibleHeight As Int = pnlBottom.Height - 8dip 'hide bottom round corners
    
    If OverlayVisible Then
        pnlBottom.SetLayoutAnimated(0, 0, pnlBottom.Parent.Height, pnlBottom.Width, pnlBottom.Height)
        pnlBottom.SetLayoutAnimated(Duration, 0, pnlBottom.Parent.Height - pnlBottomVisibleHeight, pnlBottom.Width, pnlBottom.Height)
    Else
        pnlBottom.SetLayoutAnimated(0, 0, pnlBottom.Parent.Height - pnlBottomVisibleHeight, pnlBottom.Width, pnlBottom.Height)
        pnlBottom.SetLayoutAnimated(Duration, 0, pnlBottom.Parent.Height, pnlBottom.Width, pnlBottom.Height)
    End If
    
End Sub
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Just call "CreatePanel" when Root and Layout initializes.

Root = Root1
Root.LoadLayout("MainPage")

See with CreatePanel:

B4X:
#Region Shared Files
'#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private pnlBottom As B4XView
    Private Overlay As B4XView
    Private OverlayVisible As Boolean
End Sub

Public Sub Initialize
    
End Sub

'This event will be called once, before the page becomes visible.

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    B4XPages.SetTitle(Me, "B4XBottomSheet")

    CreatePanel
    
End Sub

Private Sub CreatePanel
    Overlay = xui.CreatePanel("overlay")

    #If B4A
    Dim p As Panel = Overlay
    p.Elevation = 5dip
    #End If
    
    Root.AddView(Overlay, 0, 0, Root.Width, Root.Height)
    Overlay.LoadLayout("Overlay")
    Overlay.Color = 0x7E808080
    
    pnlBottom.LoadLayout("Drawer")
    pnlBottom.SetColorAndBorder(xui.Color_White, 0, 0, 15dip)
    
    Overlay.Visible = False
End Sub

Sub ToggleDrawerState
    Dim Duration As Int = 300
    
    OverlayVisible = Not(OverlayVisible)
    Overlay.SetVisibleAnimated(Duration, OverlayVisible)
    
    Dim pnlBottomVisibleHeight As Int = pnlBottom.Height - 8dip 'hide bottom round corners
    
    If OverlayVisible Then
        pnlBottom.SetLayoutAnimated(0, 0, pnlBottom.Parent.Height, pnlBottom.Width, pnlBottom.Height)
        pnlBottom.SetLayoutAnimated(Duration, 0, pnlBottom.Parent.Height - pnlBottomVisibleHeight, pnlBottom.Width, pnlBottom.Height)
    Else
        pnlBottom.SetLayoutAnimated(0, 0, pnlBottom.Parent.Height - pnlBottomVisibleHeight, pnlBottom.Width, pnlBottom.Height)
        pnlBottom.SetLayoutAnimated(Duration, 0, pnlBottom.Parent.Height, pnlBottom.Width, pnlBottom.Height)
    End If
    
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub btn_Click
    ToggleDrawerState
End Sub

Private Sub Overlay_Touch (Action As Int, X As Float, Y As Float)
    If Action = Overlay.TOUCH_ACTION_DOWN Then
        ToggleDrawerState
    End If
End Sub

Private Sub B4XPage_Resize (Width As Int, Height As Int)
    Overlay.Width = Width
    Overlay.Height = Height
End Sub
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
check if parent view is initialized.

B4X:
#Region Shared Files
'#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private pnlBottom As B4XView
    Private Overlay As B4XView
    Private OverlayVisible As Boolean
End Sub

Public Sub Initialize
    
End Sub

'This event will be called once, before the page becomes visible.

Private Sub B4XPage_Created (Root1 As B4XView)
    
    Root = Root1
    Root.LoadLayout("MainPage")
    B4XPages.SetTitle(Me, "B4XBottomSheet")
    CreatePanel(Root)
    
End Sub

Private Sub CreatePanel( View As B4XView )
    
    If Not(View.IsInitialized) Then Return
    
    Overlay = xui.CreatePanel("overlay")

    #If B4A
    Dim p As Panel = Overlay
    p.Elevation = 5dip
    #End If
    
    View.AddView(Overlay, 0, 0, Root.Width, Root.Height)
    Overlay.LoadLayout("Overlay")
    Overlay.Color = 0x7E808080
    
    pnlBottom.LoadLayout("Drawer")
    pnlBottom.SetColorAndBorder(xui.Color_White, 0, 0, 15dip)
    
    Overlay.Visible = False
End Sub

Sub ToggleDrawerState
    If Not(Overlay.IsInitialized) Then Return
    Dim Duration As Int = 300
    
    OverlayVisible = Not(OverlayVisible)
    Overlay.SetVisibleAnimated(Duration, OverlayVisible)
    
    Dim pnlBottomVisibleHeight As Int = pnlBottom.Height - 8dip 'hide bottom round corners
    
    If OverlayVisible Then
        pnlBottom.SetLayoutAnimated(0, 0, pnlBottom.Parent.Height, pnlBottom.Width, pnlBottom.Height)
        pnlBottom.SetLayoutAnimated(Duration, 0, pnlBottom.Parent.Height - pnlBottomVisibleHeight, pnlBottom.Width, pnlBottom.Height)
    Else
        pnlBottom.SetLayoutAnimated(0, 0, pnlBottom.Parent.Height - pnlBottomVisibleHeight, pnlBottom.Width, pnlBottom.Height)
        pnlBottom.SetLayoutAnimated(Duration, 0, pnlBottom.Parent.Height, pnlBottom.Width, pnlBottom.Height)
    End If
    
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub btn_Click
    ToggleDrawerState
End Sub

Private Sub Overlay_Touch (Action As Int, X As Float, Y As Float)
    If Action = Overlay.TOUCH_ACTION_DOWN Then
        ToggleDrawerState
    End If
End Sub

Private Sub B4XPage_Resize (Width As Int, Height As Int)
    If Overlay.IsInitialized Then
        Overlay.Width = Width
        Overlay.Height = Height
    End If
End Sub
 
Upvote 0
Top