B4A Library [Class] SlidingSidebar

Hello,

With this class, you can put an hidden sidebar on one of the four sides of the screen and reveal it when needed. It can open with a button, like in the Facebook app, with a handle, as the standard Android slidingdrawer, or with a swipe gesture, like in Prixing. Many options are available to suit all needs.

List of functions:
Initialize(Parent As Panel, SidebarSize As Int, SidebarPosition As Byte, AnimType As Byte, OpenDuration As Int, CloseDuration As Int)
SetOnChangeListeners(Module As Object, SubOnFullyOpen As String, SubOnFullyClosed As String, SubOnMove As String)
Sidebar() As Panel
ContentPanel() As Panel
SetInterpolator(Value As Float)
OpenSidebar()
CloseSidebar()
IsSidebarVisible()
As Boolean
SetOpenCloseButton(Btn As View)
AddOpenCloseHandle(Hdl As View, Position As Int, Width As Int, Height As Int, FinalMovement As Byte)
EnableSwipeGesture(Enabled As Boolean, GestureAreaSize As Int, FinalMovement As Byte)
LoadDrawable(Name As String) As Object

Since September 3rd 2014, the SlidingSidebar class is completely free.

img1.png img2.png img3.png

v1.1: Fixed three bugs and optimized the animation function
 

Attachments

  • SlidingSidebar v1.1 Dw.zip
    38.1 KB · Views: 1,862
Last edited:

Informatix

Expert
Licensed User
Longtime User
I'm using your class and some people report an error connected to it (see below). On the majority of phones this error doesn't happen. I have a S4 (5.0.1), a S4 mini (4.4) and a S3 mini (4.1) to test and on none of these phones the error shows up.

Can you please tell me how to solve this?
Can you please tell me how to reproduce it (so i can work on it on my testing phones)?

Thanks for helping :)

B4X:
An error has occurred in sub.clsslidingbar_vv7 (java line: 926)
android.content.res.Resources
$NotFoundException:Resource ID #0x0

or:

B4X:
An error has occured in
sub:clsslidingsidebar_loaddrawable(java line: 925)
android.content.res.Resources$NotFoundExeption:
Resource ID #0x0
That means you try to load a resource that does not exist on the device. Solution: either you choose a resource that exists on all Android platforms, or you don't use a system resource and you embed the image in your assets.
 

An Schi

Well-Known Member
Licensed User
Which images are needed by your class i would have to put to assets?
If i put them to assets, will i have to change their paths in your class?
 

Informatix

Expert
Licensed User
Longtime User
Which images are needed by your class i would have to put to assets?
If i put them to assets, will i have to change their paths in your class?
My class contains the LoadDrawable function but does not load any resource with it and does not require any image (in fact, this function should be in the demo code and not in the class). It's your code that loads the resource with LoadDrawable and use it. So you know better than me what to fix and where.
 

An Schi

Well-Known Member
Licensed User
As i said - the error doesn't show up on my phones, so it is hard for me to know where to fix o_O
I'm not at my PC, but if i remember correctly the only thing i have in my code is something with 'left-shadow', which indeed i did copy from your demo.
When i'm at home i will go through my code again and check where "i" try to load images ;)

Thx for your support
 

An Schi

Well-Known Member
Licensed User
How can i include the "jog_tab_bar_right_end_normal" into my app or assets or whatever, so it is not depending on the android system?
Can i create it as my "own" drawable somehow?
 

An Schi

Well-Known Member
Licensed User
Ok, i have it. I tried putting it to different places but get errors everytime.
Sorry for being so noobish or blind - but where do i have to put it and how do i load it?
 

An Schi

Well-Known Member
Licensed User
I have it working! Used Erels tutorial for nine patch ;)

Thanks Informatix for creating and sharing this and thanks for giving support after 4 years!! :)
Donation is on the way! ;)
 

desof

Well-Known Member
Licensed User
Longtime User
How can I make the menu emerge when I press a button that is elsewhere on the screen, for example in the center?

Example
Implement pop-up menu appearance when Botton1 is pressed

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private Button1 As Button
    Dim FakeActionBar, UnderActionBar As Panel
    Dim PanelWithSidebar As ClsSlidingSidebar
    Dim lvMenu As ListView
    Dim lblInfo As Label
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("test")
   
    Button1.SetBackgroundImage(LoadBitmap(File.DirAssets, "menu.png"))
   
'    Dim BarSize As Int: BarSize = 60dip
'    FakeActionBar.Initialize("")
'    FakeActionBar.Color = Colors.RGB(20, 20, 100) 'Dark blue
'    Activity.AddView(FakeActionBar, 0, 0, 100%x, BarSize)
''   
'    Dim LightCyan As Int: LightCyan = Colors.RGB(0, 95, 170)
'    UnderActionBar.Initialize("")
'    UnderActionBar.Color = LightCyan
'    Activity.AddView(UnderActionBar, 0, BarSize, 100%x, 100%y - BarSize)
''   
'    PanelWithSidebar.Initialize(UnderActionBar, 190dip, 2, 1, 500, 500)
'    PanelWithSidebar.ContentPanel.Color = LightCyan
'    PanelWithSidebar.Sidebar.Background = PanelWithSidebar.LoadDrawable("popup_inline_error")
'    PanelWithSidebar.SetOnChangeListeners(Me, "Menu_onFullyOpen", "Menu_onFullyClosed", "Menu_onMove")
'
'    lvMenu.Initialize("lvMenu")
'    lvMenu.AddSingleLine("1st option")
'    lvMenu.AddSingleLine("2nd option")
'    lvMenu.AddSingleLine("3rd option")
'    lvMenu.SingleLineLayout.Label.TextColor = Colors.Black
'    lvMenu.Color = Colors.Transparent
'    lvMenu.ScrollingBackgroundColor = Colors.Transparent
'    PanelWithSidebar.Sidebar.AddView(lvMenu, 20dip, 25dip, -1, -1)
'
''    lblInfo.Initialize("")
''    lblInfo.Text = "Click the button to open/close the sliding menu."
''    lblInfo.TextColor = Colors.Black
''    lblInfo.TextSize = 24
''    PanelWithSidebar.ContentPanel.AddView(lblInfo, 30dip, 30dip, 100%x - 60dip, 100%y - 60dip)
'
''    btnMenu.Initialize("")
''    btnMenu.SetBackgroundImage(LoadBitmap(File.DirAssets, "menu.png"))
'    FakeActionBar.AddView(Button1, 100%x - BarSize, 0, BarSize, BarSize)
'    PanelWithSidebar.SetOpenCloseButton(Button1)
End Sub
 
Last edited:
Top