Android Question "left menu" remains open

AnandGupta

Expert
Licensed User
Longtime User
Well, looking at video we can see there is some problem. Can we have a look at the code ?
May be a small sample project demonstrating the same .

Regards,

Anand
 
Upvote 0

By-Cod3rs

Member
Licensed User
Well, looking at video we can see there is some problem. Can we have a look at the code ?
May be a small sample project demonstrating the same .

Regards,

Anand
B4X:
#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: False
#End Region

Sub Process_Globals

End Sub

Sub Globals
  
    Private sm As SlidingMenu
    Private btactionmenu As ImageView
    Private paction As Panel

    Private ic1Menu As ImageView
    Private ic2Menu As ImageView
    Private lb1Menu As Label
    Private lb2Menu As Label
    Private lbEmailMenu As Label
    Private lbLetraGrandeMenu As Label
    Private lbNomeMenu As Label
    Private pBranco1Menu As Panel
    Private pBranco2Menu As Panel
    Private pFundo1Menu As Panel
    Private pFundo2Menu As Panel
    Private pRedondoMenu As Panel
    Private pVerdeMenu As Panel
    Private ic3Menu As ImageView
    Private ic4Menu As ImageView
    Private lb3Menu As Label
    Private lb4Menu As Label
    Private pBranco3Menu As Panel
    Private pBranco4Menu As Panel
    Private pFundo3Menu As Panel
    Private pFundo4Menu As Panel
    Private ic5Menu As ImageView
    Private ic6Menu As ImageView
    Private lb5Menu As Label
    Private lb6Menu As Label
    Private pBranco5Menu As Panel
    Private pBranco6Menu As Panel
    Private pFundo5Menu As Panel
    Private pFundo6Menu As Panel
    Private lbTituloMain As Label
    Private pVerdeMain As Panel
'    Private icVenda As ImageView
'    Private lbResumoMain As Label
'    Private lbVendaMain As Label
'    Private pBrancoMain As Panel
    Private pInvisivelMain As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
  
  
    SetStatusBarColor(Colors.RGB(86,177,100))

  
    Activity.LoadLayout("Database_Ayarlar_Formu")
  
  
    'CARREGA MENU LATERAL E O LAYOUT DELE
    sm.Initialize("sm")
    Dim offset As Int = 22%x
    sm.BehindOffset = offset
    sm.Mode = sm.LEFT
    sm.Menu.LoadLayout("Anasayfa_css")
  

    Dim jo As JavaObject = sm

    Dim Gradient1 As GradientDrawable
    Dim Clrs(2) As Int
    Clrs(0) = Colors.ARGB(0,0,0,0)
    Clrs(1) = Colors.ARGB(50,0,0,0)
    Gradient1.Initialize("LEFT_RIGHT", Clrs)
    jo.RunMethod("setShadowDrawable", Array(Gradient1))
    jo.RunMethod("setShadowWidth", Array(4%x))
  
  
    'FACILITA O MOVIMENTO PARA ABRIR O MENU ARRASTANDO NA TELA INVEZ DE APERTAR O BOTÃO MENU
    Dim jo As JavaObject = sm
    jo.RunMethod("setTouchmodeMarginThreshold", Array(50%x))
  
    'PEGAMOS O EVENTO DE ABRIR (SABER QUANDO O MENU ESTIVER ABERTO)
    Dim jo2 As JavaObject = sm
    Dim event As Object = jo2.CreateEventFromUI("com.jeremyfeinstein.slidingmenu.lib.SlidingMenu$OnOpenListener", "Open", Null)
    jo2.RunMethod("setOnOpenListener", Array(event))


    'PEGAMOS O EVENTO DE FECHAR (SABER QUANDO O MENU ESTIVER ABERTO)
    Dim jo3 As JavaObject = sm
    Dim event As Object = jo3.CreateEventFromUI("com.jeremyfeinstein.slidingmenu.lib.SlidingMenu$OnCloseListener", "Close", Null)
    jo3.RunMethod("setOnCloseListener", Array(event))

    Carrega_Imagens


End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub




Sub Carrega_Imagens

    AjustaImageView(btactionmenu,File.DirAssets,"menu.png")
    AjustaImageView(ic1Menu,File.DirAssets,"Anasayfa.png")
    AjustaImageView(ic2Menu,File.DirAssets,"Raporlar.png")
    AjustaImageView(ic3Menu,File.DirAssets,"Tanimlamalar.png")
    AjustaImageView(ic4Menu,File.DirAssets,"Ayarlar.png")
    AjustaImageView(ic5Menu,File.DirAssets,"OturumuKapat.png")
    AjustaImageView(ic6Menu,File.DirAssets,"Hata_Bildir.png")
'    AjustaImageView(icVenda,File.DirAssets,"Hata_Bildir.png")
  
End Sub

'AJUSTA OS ICONES PARA NÃO FICAREM ESTICADOS
Sub AjustaImageView(Imv As ImageView, Dir As String, FileName As String)
    Private bmp As Bitmap = LoadBitmap(Dir, FileName)
    Dim Delta, Height, Width As Int
    If bmp.Width / bmp.Height > Imv.Width / Imv.Height Then
        Height = bmp.Height / bmp.Width * Imv.Width
        Delta = (Imv.Height - Height) / 2
        Imv.Height = Height
        Imv.Top = Imv.Top + Delta
    Else
        Width = bmp.Width / bmp.Height * Imv.Height
        Delta = (Imv.Width - Width) / 2
        Imv.Width = Width
        Imv.Left = Imv.Left + Delta
    End If
    Imv.Gravity = Gravity.FILL
    Imv.Bitmap = bmp
End Sub



Sub btactionmenu_Click
    pInvisivelMain_Click
End Sub







Sub Open_Event (MethodName As String, Args() As Object) As Object
    Log("DAC Menu Acildi")
    Return False
End Sub


Sub Close_Event (MethodName As String, Args() As Object) As Object
    Log("DAC Menu Kapandi")
    Return False
End Sub


'PEGA O BOTÃO VOLTAR DO APARELHO E FECHA O MENU SE TIVER ABERTO
Sub Activity_KeyPress(KeyCode As Int) As Boolean
  
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        If sm.Visible Then
            sm.HideMenus
            Return True
        End If
    End If

  
    Return False
End Sub

Sub SetStatusBarColor(clr As Int)
    Dim p As Phone
    If p.SdkVersion >= 21 Then
        Dim jo As JavaObject
        jo.InitializeContext
        Dim window As JavaObject = jo.RunMethodJO("getWindow", Null)
        window.RunMethod("addFlags", Array (0x80000000))
        window.RunMethod("clearFlags", Array (0x04000000))
        window.RunMethod("setStatusBarColor", Array(clr))
    End If
End Sub


Sub pInvisivelMain_Click
    sm.ShowMenu
End Sub

Sub lb1Menu_Click
    StartActivity(Anasayfa)
    ToastMessageShow("Anasayfa Açıldı",True)
End Sub

Sub lb2Menu_Click
    StartActivity(Raporlar_Code)
    ToastMessageShow("Raporlar Açıldı",True)
End Sub

Sub lb4Menu_Click
    StartActivity(Ayarlar_Code)
    ToastMessageShow("Araç Teslim Açıldı!",True)
End Sub
 
Upvote 0

AnandGupta

Expert
Licensed User
Longtime User
Thanks for the code.
Copy pasting them in a new project gave many errors so I could not check the problem.
I have attached the exported zip file of the project.

If you can fix the missing errors then I can check the problem.

Regards,

Anand
 

Attachments

  • leftmenuremainsopen.zip
    8.7 KB · Views: 173
  • 2019-07-01_233842.png
    2019-07-01_233842.png
    61.1 KB · Views: 195
Upvote 0

By-Cod3rs

Member
Licensed User
Thanks for the code.
Copy pasting them in a new project gave many errors so I could not check the problem.
I have attached the exported zip file of the project.

If you can fix the missing errors then I can check the problem.

Regards,

Anand
^ Thanks Anand,

I have solved the problem. "sm.Hidemenu" I have eliminated the problem by adding a command.

Thank you for your time.
 
Upvote 0
Top