B4J Question In B4J Using B4XPages , How to Avoid Flicker When Displaying Only One Page Out of Multiple Pages?

JGParamo

Member
Licensed User
With reference to the related thread (https://www.b4x.com/android/forum/t...ening-when-b4xpages-showpage-is-called.139647), by not using B4XPages.ShowPageAndRemovePreviousPages to call other pages flicker can be avoided but has the drawback of creating multiple open windows/pages on the process. I seems that if I want only one window (or page) to be opened, what is left for me to use are multiple pane views for that page, with pane containing the other encapsulated views. Hiding and showing each pane as desired won't result to any flicker but this approach looks like defeating the purpose of B4XPages due to the resulting coding required. Aside from using panes, any idea on how to make use of B4XPages but get rid of the flickering effect due to page switching?
 
Last edited:

MicroDrie

Well-Known Member
Licensed User
containing the other encapsulated views
It's hard to help you without an example program. B4XPages.ShowPageAndRemovePreviousPages destroyed the page. But if the encapsulated view is "dynamic" you can try to hide the view only with a B4XPages.ClosePage and show it again with B4XPages.ShowPage
 
Upvote 0

JGParamo

Member
Licensed User
Uploading here the Main, B4XMainPage, and the B4XTiledMenuPage I have coded. My apology for the possibly inefficient code style I have :)..

Main:
AppType=JavaFX
Build1=Default,b4j.OpMnTimizer
File1=bg.png
File10=KKSFinder.png
File11=KKSFinder-mouse-enter.png
File12=KKSFinderPage.bjl
File13=MainPage.bjl
File14=menu btn.png
File15=MenuDrawer.bjl
File16=MntProcedures.png
File17=MntProcedures-mouse-enter.png
File18=MntProceduresPage.bjl
File19=OpMnTimizer_app_manual.chm
File2=bknight.png
File20=OpnProcedures.png
File21=OpnProcedures-mouse-enter.png
File22=OpnProceduresPage.bjl
File23=PlantOverview.png
File24=PlantOverview-mouse-enter.png
File25=SEC logo w-bg.png
File26=SEC logo wo-bg.png
File27=SEC Plant.png
File28=SEC title.png
File29=SEC wo-bg.ico
File3=config.png
File30=SEC_splash.png
File31=SEC12DatabookPage.bjl
File32=sparks.png
File33=Sticker avatar.png
File34=TiledMenuPage.bjl
File35=UserSettings.png
File36=UserSettings-mouse-enter.png
File37=UserSettingsPage.bjl
File4=config-mouse-enter.png
File5=ConfigurationPage.bjl
File6=Databook.png
File7=Databook-mouse-enter.png
File8=fireworks01.mp3
File9=fireworks02.mp3
FileGroup1=Default Group
FileGroup10=Default Group
FileGroup11=Default Group
FileGroup12=Default Group
FileGroup13=Default Group
FileGroup14=Default Group
FileGroup15=Default Group
FileGroup16=Default Group
FileGroup17=Default Group
FileGroup18=Default Group
FileGroup19=Default Group
FileGroup2=Default Group
FileGroup20=Default Group
FileGroup21=Default Group
FileGroup22=Default Group
FileGroup23=Default Group
FileGroup24=Default Group
FileGroup25=Default Group
FileGroup26=Default Group
FileGroup27=Default Group
FileGroup28=Default Group
FileGroup29=Default Group
FileGroup3=Default Group
FileGroup30=Default Group
FileGroup31=Default Group
FileGroup32=Default Group
FileGroup33=Default Group
FileGroup34=Default Group
FileGroup35=Default Group
FileGroup36=Default Group
FileGroup37=Default Group
FileGroup4=Default Group
FileGroup5=Default Group
FileGroup6=Default Group
FileGroup7=Default Group
FileGroup8=Default Group
FileGroup9=Default Group
Group=Default Group
Library1=b4xdrawer
Library10=xui views
Library2=b4xpages
Library3=b4xpreferencesdialog
Library4=b4xtable
Library5=cssutils
Library6=jcore
Library7=jdateutils
Library8=jfx
Library9=jsql
Module1=|relative|..\B4XConfiguration
Module10=|relative|..\CodeLibrary
Module11=|relative|..\Fireworks
Module12=|relative|..\InlineEditing
Module13=|relative|..\xCustomButton
Module2=|relative|..\B4XKKSFinder
Module3=|relative|..\B4XMainPage
Module4=|relative|..\B4XMntProcedures
Module5=|relative|..\B4XOpnProcedures
Module6=|relative|..\B4XPageIndicator
Module7=|relative|..\B4XSEC12Databook
Module8=|relative|..\B4XTiledMenuPage
Module9=|relative|..\B4XUserSettings
NumberOfFiles=37
NumberOfLibraries=10
NumberOfModules=13
Version=9.3
@EndOfDesignText@
#Region Project Attributes
    #MainFormWidth: 800
    #MainFormHeight: 600
    #AdditionalJar: sqlite-jdbc-3.7.2
#End Region

Sub Process_Globals
    Private fx As JFX
    Public MainForm As Form
    Public SplashForm As Form
    Public AnnivForm As Form
    Public SplashHidden As Boolean = True
    Public FirstStart As Boolean = True
    Public WindowMaximized As Boolean = False
    Public WkSelected, YrSelected As String
    Public Left, Top, formWidth, formHeight, ScreenWidth, ScreenHeight As Double
    Public OpenWindows As Byte = 0
    Private fwImage As ImageView
    Private fire As Fireworks
    Private AnnivLabel1, AnnivLabel2 As Label
    Public PageNameCalling As String
End Sub

Sub AppStart (myForm As Form, Args() As String)
    MainForm = myForm
    SetMainFormNormalStyle
    ResizeFormOnScreen
    CenterFormOnScreen
    MainForm.Show
    Dim PagesManager As B4XPagesManager
    PagesManager.Initialize(MainForm)
 

End Sub

'Sub SetMainFormNoBorderStyle
'    MainForm.SetFormStyle("TRANSPARENT")
'End Sub

Sub ShowAnnivScreen(AutoClose As Boolean, ox As Double, oy As Double, ow As Double, oh As Double, days As Int, yrs As Int)
    AnnivForm.Initialize("AnnivForm", MainForm.WindowWidth, MainForm.WindowHeight)
    AnnivForm.SetFormStyle("TRANSPARENT")
    AnnivForm.BackColor = fx.Colors.Transparent
    AnnivForm.AlwaysOnTop = True
    AnnivForm.Show
    AnnivForm.RootPane.Alpha = 0
 
    CSSUtils.SetBackgroundImage(AnnivForm.RootPane, File.DirAssets, "bknight.png")
 
    If Not(AutoClose) Then
        AnnivForm.WindowLeft = ox
        AnnivForm.WindowTop = oy
        AnnivForm.WindowWidth = ow
        AnnivForm.WindowHeight = oh
    Else
        AnnivForm.WindowLeft = MainForm.WindowLeft
        AnnivForm.WindowTop = MainForm.WindowTop
    End If
 
    AnnivLabel1.Initialize("AnnivLabel1")
    AnnivLabel2.Initialize("AnnivLabel2")
    AnnivLabel1.Font = fx.DefaultFont(40)
    AnnivLabel2.Font = fx.DefaultFont(40)
 
    Dim yrAnniv As String = yrs & " yrs"
    Select yrs
        Case 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, _
             30, 34, 35, 36, 37, 38, 39, 40, 44, 45, 46, 47, 48, 49, 50, _
             54, 55, 56, 57, 58, 59, 60
            yrAnniv = yrs & "th"
        Case 1, 21, 31, 41, 51
            yrAnniv = yrs & "st"
        Case 2, 22, 32, 42, 52
            yrAnniv = yrs & "nd"
        Case 3, 23, 33, 43, 53
            yrAnniv = yrs & "rd"
    End Select
 
    If days = 0 Then
        AnnivLabel1.Text = "Today is April 27, " & DateTime.GetYear(DateTime.Now)
        AnnivLabel2.Text = "Happy " & yrAnniv & " Anniversary - My Corporation!!!"
    Else If Abs(days) > 0 And Abs(days)  <= 5 Then
        AnnivLabel1.Text = "April 27, " & DateTime.GetYear(DateTime.Now)
        AnnivLabel2.Text = "Happy " & yrAnniv & " Anniversary - My Corporation!!!"
    Else
        AnnivLabel1.Text = "April 27, " & DateTime.GetYear(DateTime.Now)
        AnnivLabel2.Text = "My Corporation " & yrAnniv & " Anniversary!!!"
    End If
 
    AnnivForm.RootPane.AddNode(AnnivLabel1, 0, 0, AnnivLabel1.Width, AnnivLabel1.Height)
    AnnivForm.RootPane.AddNode(AnnivLabel2, 0, 0, AnnivLabel2.Width, AnnivLabel2.Height)
    Sleep(0)
    AnnivLabel1.Left = (AnnivForm.RootPane.Width/2)-(AnnivLabel1.Width/2)
    AnnivLabel1.Top = (AnnivForm.RootPane.Height/3) - AnnivLabel1.Height - 10
    AnnivLabel2.Left = (AnnivForm.RootPane.Width/2)-(AnnivLabel2.Width/2)
    AnnivLabel2.Top = (AnnivForm.RootPane.Height/3) - 5
 
    fwImage.Initialize("")
    AnnivForm.RootPane.AddNode(fwImage, 0, 0, AnnivForm.Width, AnnivForm.Height)
    fire.Initialize(fwImage, AnnivForm, 20)
    AnnivForm.RootPane.SetAlphaAnimated(2000, 1)
    Sleep(0)
    LoopAnnivText
    Wait For (AnnivForm.RootPane) AnnivForm_AnimationCompleted
    If AutoClose Then
        Sleep(3000)
        AnnivForm.RootPane.SetAlphaAnimated(3000, 0)
        Sleep(0)
        Wait For (AnnivForm.RootPane) AnnivForm_AnimationCompleted
        fire.Stop
        fwImage.RemoveNodeFromParent
        AnnivForm.Close
    End If
End Sub

Private Sub LoopAnnivText
    Dim i, j As Int = 0
    Dim continueloop As Boolean = True
    Do While continueloop
        i = i + 1
        If i > 6 Then i = 1
        Select i
            Case 1
                AnnivLabel1.TextColor = fx.Colors.Green
                AnnivLabel2.TextColor = fx.Colors.Red
            Case 2
                AnnivLabel1.TextColor = fx.Colors.White
                AnnivLabel2.TextColor = fx.Colors.Green
            Case 3
                AnnivLabel1.TextColor = fx.Colors.Red
                AnnivLabel2.TextColor = fx.Colors.White
            Case 4
                AnnivLabel1.TextColor = fx.Colors.White
                AnnivLabel2.TextColor = fx.Colors.Red
            Case 5
                AnnivLabel1.TextColor = fx.Colors.Green
                AnnivLabel2.TextColor = fx.Colors.White
            Case 6
                AnnivLabel1.TextColor = fx.Colors.Red
                AnnivLabel2.TextColor = fx.Colors.Green
        End Select
        Sleep(500)
        j = j + 1
        If j = 1000 Then continueloop = False
    Loop
End Sub

Sub SetMainFormNormalStyle
    MainForm.SetFormStyle("DECORATED")
End Sub

Sub ResizeFormOnScreen
    ScreenWidth = fx.PrimaryScreen.MaxX - fx.PrimaryScreen.MinX
    ScreenHeight = fx.PrimaryScreen.MaxY - fx.PrimaryScreen.MinY
 
    MainForm.WindowWidth = ScreenWidth * 5 / 7
    MainForm.WindowHeight = ScreenHeight * 6 / 7
    formWidth = MainForm.WindowWidth
    formHeight = MainForm.WindowHeight

End Sub

Sub CenterFormOnScreen
    ScreenWidth = fx.PrimaryScreen.MaxX - fx.PrimaryScreen.MinX
    ScreenHeight = fx.PrimaryScreen.MaxY - fx.PrimaryScreen.MinY
 
    MainForm.WindowTop = fx.PrimaryScreen.MinY +  (ScreenHeight - MainForm.WindowHeight) / 2
    MainForm.WindowLeft = fx.PrimaryScreen.MinX + (ScreenWidth - MainForm.WindowWidth) / 2
    Left = MainForm.WindowLeft
    Top = MainForm.WindowTop
    formWidth = MainForm.WindowWidth
    formHeight = MainForm.WindowHeight
End Sub

Sub ShowSplashScreen(AutoClose As Boolean, ox As Double, oy As Double, ow As Double, oh As Double)
 
    SplashForm.Initialize("SplashForm", ow, oh)
    SplashForm.SetFormStyle("TRANSPARENT")
    SplashForm.BackColor = fx.Colors.Transparent
    CSSUtils.SetBackgroundImage(SplashForm.RootPane, File.DirAssets, "SEC_splash.png")

    If Not(AutoClose) Then
        SplashForm.WindowLeft = ox
        SplashForm.WindowTop = oy
        SplashForm.WindowWidth = ow
        SplashForm.WindowHeight = oh
    Else
        SplashForm.WindowLeft = MainForm.WindowLeft
        SplashForm.WindowTop = MainForm.WindowTop

    End If
 
    SplashForm.AlwaysOnTop = True
    SplashForm.Show
    SplashForm.AlwaysOnTop = True
    SplashHidden = False
    SplashForm.RootPane.Alpha = 0
    SplashForm.RootPane.SetAlphaAnimated(1000, 1)
    Wait For (SplashForm.RootPane) SplashForm_AnimationCompleted

    If AutoClose Then
        Sleep(3000)
        HideSplashForm
    End If
End Sub

Sub SplashForm_MouseClicked (EventData As MouseEvent)
    HideSplashForm
End Sub

Sub AnnivForm_MouseClicked (EventData As MouseEvent)
    fire.Stop
    fwImage.RemoveNodeFromParent
    AnnivForm.Close
End Sub

Sub HideSplashForm
    If Not(SplashHidden) Then
        SplashForm.RootPane.SetAlphaAnimated(500, 0)
        Wait For (SplashForm.RootPane) SplashForm_AnimationCompleted
        SplashForm.Close
        SplashHidden = True
    End If
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Log(LastException)
    Return True
End Sub


'Template version: B4J-1.0
#Region Delegates
Sub MainForm_FocusChanged (HasFocus As Boolean)
    B4XPages.Delegate.MainForm_FocusChanged(HasFocus)
End Sub

Sub MainForm_Resize (Width As Double, Height As Double)
    B4XPages.Delegate.MainForm_Resize(Width, Height)
End Sub

Sub MainForm_Closed
    B4XPages.Delegate.MainForm_Closed
End Sub

Sub MainForm_CloseRequest (EventData As Event)
    B4XPages.Delegate.MainForm_CloseRequest(EventData)
End Sub

Public Sub MainForm_IconifiedChanged (Iconified As Boolean)
    B4XPages.Delegate.MainForm_IconifiedChanged(Iconified)
End Sub
#End Region

B4XMainPage:
B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=9.85
@EndOfDesignText@
#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 MainPageVw As B4XView
    Private MainPane As B4XView
    Private xui As XUI
    Private SplashB4XimgVw As B4XImageView
    Private ox, oy As Double

    Public TiledMenuPageVw As B4XTiledMenuPage
    Public OpnProceduresPageVw As B4XOpnProcedures
    Public MntProceduresPageVw As B4XMntProcedures
    Public KKSFinderPageVw As B4XKKSFinder
    Public SEC12DatabookPageVw As B4XSEC12Databook
    Public UserSettingsPageVw As B4XUserSettings
    Public ConfigPageVw As B4XConfiguration

    #If B4J
    Private ProgLbl As xCustomButton
    #End If

    Public ProjectTitle As String
    Private DetalyeLbl As B4XView
    Private PlantOverviewLbl As B4XView
    Private OpnProceduresLbl As B4XView
    Private MntProceduresLbl As B4XView
    Private KKSFinderLbl As B4XView
    Private SEC12DatabookLbl As B4XView
    Private UserSettingsLbl As B4XView
    Private ExitAppLbl As B4XView
  
    Public DetalyeLblText As String
    Public B4XPageIndicatorCount As Int
    Public B4XPageIndicator1 As B4XPageIndicator


    Private MenuDrawer As B4XDrawer
    Private DrawerMenuPnl As B4XView
    Private OpenMenuBtnImgVw As ImageView
    Private OpenMenuBtnIcon As B4XBitmap
  
    Private MainpageTitle As String
    Private TitleLbl As B4XView
    Private TitleImageVw As B4XView
    Private DateTimeTimer As Timer
    Private DateTimePnl As B4XView
    Private DateTimeLbl As B4XView
End Sub

Public Sub Initialize
    ProjectTitle = "OpMnTimizer - Operation and Maintenance Work Helper App"
    DetalyeLblText = "MY CORPORATION"
    B4XPageIndicatorCount = 7
    CodeLibrary.LoadAssets
    CodeLibrary.InitializeSQLite
    TiledMenuPageVw.Initialize
    OpnProceduresPageVw.Initialize
    MntProceduresPageVw.Initialize
    KKSFinderPageVw.Initialize
    SEC12DatabookPageVw.Initialize
    UserSettingsPageVw.Initialize
    ConfigPageVw.Initialize
End Sub

Private Sub SetMainpageTitle
    MainpageTitle = "PLANT OVERVIEW"
    TitleLbl.Text = MainpageTitle
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (PageView As B4XView)
    Log("MainPage Create")
    MainPageVw = PageView
    MainPageVw.LoadLayout("MainPage")
  
    #if b4j
    CodeLibrary.SetMinMaxWindowSize(B4XPages.GetNativeParent(Me))
    CodeLibrary.SetMoveListener(B4XPages.GetNativeParent(Me))
  
    Log("OpenWindows :" & Main.OpenWindows)
    If Not(Main.FirstStart) Then
        CodeLibrary.SetPageSizeAndLocation(B4XPages.GetNativeParent(Me))
    End If
    #End If

    CreateDrawerMenu
  
    B4XPages.SetTitle(Me, "")
    MainPane.Visible = False
    SetMainpageTitle

    B4XPageIndicator1.Count = 6
    B4XPageIndicator1.CurrentPage = 0
  
    CheckIfAnniv
  
    SplashB4XimgVw.Load(File.DirAssets, "SEC_splash.png")
    SplashB4XimgVw.mBackgroundColor = xui.Color_Transparent
    SplashB4XimgVw.ResizeMode = "FILL_HEIGHT"
    SplashB4XimgVw.mBase.SetVisibleAnimated(0, True)
    Sleep(3000)
    SplashB4XimgVw.mBase.SetVisibleAnimated(1000, False)
    B4XPages.AddPage("TiledMenu Page", TiledMenuPageVw)
    B4XPages.AddPage("OpnProcedures Page", OpnProceduresPageVw)
    B4XPages.AddPage("MntProcedures Page", MntProceduresPageVw)
    B4XPages.AddPage("KKSFinder Page", KKSFinderPageVw)
    B4XPages.AddPage("SEC12Databook Page", SEC12DatabookPageVw)
    B4XPages.AddPage("UserSettings Page", UserSettingsPageVw)
    B4XPages.AddPage("Config Page", ConfigPageVw)
    Sleep(800)
    HideSplash
  
    CreateDrawerMenuBtn

    B4XPages.SetTitle(Me, ProjectTitle)
    TitleLbl.Text = MainpageTitle
    DetalyeLbl.Text = DetalyeLblText
  
    TiledMenuCbtn_Click

  
End Sub

Private Sub CreateDrawerMenu
    MenuDrawer.Initialize(Me, "MenuDrawerEvent", MainPageVw, 335dip)
    MenuDrawer.CenterPanel.LoadLayout("MainPage")
    MenuDrawer.LeftPanel.LoadLayout("MenuDrawer")
End Sub

Private Sub CreateDrawerMenuBtn
    OpenMenuBtnIcon = xui.LoadBitmapResize(File.DirAssets, "menu btn.png", 23dip, 25dip, True)
    OpenMenuBtnImgVw.Initialize("imgOpenMenuBtn")
    #if b4j
    OpenMenuBtnImgVw.SetImage(OpenMenuBtnIcon)
    OpenMenuBtnImgVw.PickOnBounds = True
  
    #End If
    MenuDrawer.CenterPanel.AddView(OpenMenuBtnImgVw, 10dip, 15dip, 23dip, 25dip)
  
'    OpenMenuBtnTiledImgVw.Initialize("imgOpenMenuBtnTiled")
'    OpenMenuBtnTiledImgVw.SetImage(CodeLibrary.FontAwesomeToBitmap(Chr(0xF009), 28))
'    MenuDrawer.CenterPanel.AddView(OpenMenuBtnTiledImgVw, OpenMenuBtnImgVw.Width * 2, 15dip, 23dip, 25dip)
'    OpenMenuBtnTiledImgVw.PickOnBounds = True

End Sub

Private Sub HideSplash
    If SplashB4XimgVw.mBase.Visible Then
        SplashB4XimgVw.mBase.Visible = False
        MainPane.BringToFront
        MainPane.Visible = True
    End If
End Sub

Private Sub ShowDrawerMenu
    If MenuDrawer.LeftOpen = False Then
        MenuDrawer.LeftOpen = True
    End If
End Sub

Private Sub HideDrawerMenu
    If MenuDrawer.LeftOpen = True Then
        MenuDrawer.LeftOpen = False
    End If
End Sub

Private Sub TodayIsAnniv As Boolean
    Dim annivNow As Boolean
    DateTime.DateFormat = "yyyy-MM-dd"
    Dim myDate As String = DateTime.Date(DateTime.Now).SubString2(5,10)
    If myDate = "04-27" Then
        annivNow =  True
    Else
        annivNow = False
    End If
    Return annivNow
End Sub

Private Sub TodayIsNearAnniv As Boolean
    Dim annivNear As Boolean
    Dim days As Int
    DateTime.DateFormat = "yyyy-MM-dd"
    Dim AnnivThisYr As Long = DateTime.DateParse(DateTime.GetYear(DateTime.Now) & "-04-27")
    If AnnivThisYr > DateTime.Now Then
        days = - DateTime.GetDayOfYear(AnnivThisYr - DateTime.Now)
    Else
        days = DateTime.GetDayOfYear(DateTime.Now - AnnivThisYr) - 1
    End If
    If Abs(days) > 0 And Abs(days) <= 5 Then
        annivNear =  True
    Else
        annivNear = False
    End If
    Return annivNear
End Sub

Private Sub CheckDateForAnniv
    Dim days, yrs As Int
    DateTime.DateFormat = "yyyy-MM-dd"
    Dim DateNgHandog As Long = DateTime.DateParse("2016-04-27")
    Dim AnnivThisYr As Long = DateTime.DateParse(DateTime.GetYear(DateTime.Now) & "-04-27")
    If AnnivThisYr > DateTime.Now Then
        days = - DateTime.GetDayOfYear(AnnivThisYr - DateTime.Now)
    Else
        days = DateTime.GetDayOfYear(DateTime.Now - AnnivThisYr) - 1
    End If
    yrs = DateTime.GetYear(DateTime.Now) -  DateTime.GetYear(DateNgHandog)
    ShowAnnivGreeting(days, yrs)
End Sub

Private Sub AppPage_Tick
    DateTime.DateFormat = "yyyy MMM d, EEE  HH:mm:ss"
    DateTimeLbl.Text = DateTime.Date(DateTime.Now)
    DateTimePnl.Width = DateTimeLbl.Width + 15
End Sub

Private Sub CheckIfTimerIsInitialized
    If Not(DateTimeTimer.IsInitialized) Then
        DateTimeTimer.Initialize("AppPage", 200)
        DateTimeTimer.Enabled = True
    End If
End Sub

Private Sub B4XPage_Appear
    Log("MainPage Appear")
    #If B4J
    Main.PageNameCalling = "MainPage"
    Main.OpenWindows = Main.OpenWindows + 1
    CheckIfTimerIsInitialized
    If Not(Main.FirstStart) Then
        CodeLibrary.SetPageSizeAndLocation(B4XPages.GetNativeParent(Me))
        CodeLibrary.CheckIfPageWindowIsMaximized(B4XPages.GetNativeParent(Me))
    End If
    Main.FirstStart = False
    #End If
    HideSplashForm
    HideDrawerMenu
    B4XPageIndicator1.CurrentPageMonitor
End Sub

Private Sub B4XPage_Disappear
    Log("MainPage Disappear")
    #if b4j
    Main.OpenWindows = Main.OpenWindows - 1
    #End If
    HideSplashForm
    HideDrawerMenu
End Sub

Private Sub B4XPage_Foreground
    Log("MainPage Foreground")
    #if b4j
    Main.PageNameCalling = "MainPage"
    If Main.FirstStart Then
      
    Else
      
    End If
    #End If
End Sub

Private Sub B4XPage_Background
    Log("MainPage Background")
End Sub

Private Sub B4XPage_Resize (Width As Int, Height As Int)
    HideSplashForm
    Log("MainPage Resize " & Width & " / " & Height)
    MenuDrawer.Resize(MainPageVw.Width, MainPageVw.Height)
    #if b4j
    CodeLibrary.GetPageSizeAndLocation(B4XPages.GetNativeParent(Me))
    CodeLibrary.CheckIfPageWindowIsMaximized(B4XPages.GetNativeParent(Me))
  
    #End If
End Sub

Private Sub TiledMenuCbtn_Click
    B4XPages.ShowPageAndRemovePreviousPages("TiledMenu Page")
    #if b4j
    Main.OpenWindows = Main.OpenWindows - 1
  
    #End If
End Sub

Private Sub ShowAnnivGreeting (days As Int, yrs As Int)
    Try
        #if b4j
        Main.ShowAnnivScreen(True, B4XPages.GetNativeParent(Me).WindowLeft, _
        B4XPages.GetNativeParent(Me).WindowTop, _
        B4XPages.GetNativeParent(Me).WindowWidth, _
        B4XPages.GetNativeParent(Me).WindowHeight, days, yrs)
      
        #End If
    Catch
        Log(LastException)
    End Try
End Sub

Private Sub AppClosingMsgBx As Object
    HideSplashForm
    CheckIfAnniv
    Dim icon As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "SEC logo w-bg.png", 60dip, 60dip, True)
    Dim myMsgBx As Object = xui.Msgbox2Async("Are you sure on closing this App?", "App Alert", "Yes", "No", "", icon)
    Return myMsgBx
End Sub

Private Sub CheckAppClosing
    Wait For (AppClosingMsgBx) Msgbox_Result (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Log("Closing the application through menu exit button")
        CodeLibrary.CloseAllSQLiteConnections
        ExitApplication
    Else
        B4XPages.ShowPageAndRemovePreviousPages("MainPage")
    End If
End Sub

Private Sub CheckIfAnniv
    If TodayIsAnniv Or TodayIsNearAnniv Then
        CheckDateForAnniv
    End If
End Sub

Private Sub ProgLbl_Click
    CodeLibrary.AboutProgrammer
    HideSplashForm
    CheckIfAnniv
End Sub

Private Sub SplashxBtn_Click
    Try
        #if b4j
        Dim SplashImgVw As B4XBitmap
        SplashImgVw = xui.LoadBitmap(File.DirAssets, "SEC_splash.png")
        Dim H, W, ratio As Double
        H = SplashImgVw.Height
        W = SplashImgVw.Width
        ratio = W/H
        If Main.SplashHidden Then
            Dim leftpos, width As Double
            width = B4XPages.GetNativeParent(Me).WindowHeight * ratio
            leftpos = B4XPages.GetNativeParent(Me).WindowLeft + _
                        (B4XPages.GetNativeParent(Me).Windowwidth/2 -width/2)
            Main.ShowSplashScreen(False, leftpos, B4XPages.GetNativeParent(Me).WindowTop, width, B4XPages.GetNativeParent(Me).WindowHeight)
            Main.SplashHidden = False
        Else
            HideSplashForm
        End If     
        #End If
    Catch
        Log(LastException)
    End Try
End Sub

Private Sub B4XPage_CloseRequest As ResumableSub
    Dim closerequestresult As Boolean = False
    #if b4j
    If Main.OpenWindows <= 1 Then
        Wait For (AppClosingMsgBx) Msgbox_Result (Result As Int)
        If Result = xui.DialogResponse_Positive Then
            Log("Exiting the application through close button")
            CodeLibrary.CloseAllSQLiteConnections
            ExitApplication
            closerequestresult = True
        Else
            B4XPages.ShowPageAndRemovePreviousPages("MainPage")
            Main.OpenWindows = Main.OpenWindows - 1
            closerequestresult = False
        End If
    Else
        Main.OpenWindows = Main.OpenWindows - 1
        closerequestresult = True
    End If
    #End If
    Return closerequestresult
End Sub

Private Sub HideSplashForm
    #if b4j
    If Not(Main.SplashHidden) Then
        Main.SplashHidden = True
        Main.SplashForm.Close
    End If
    #End If
End Sub

Private Sub MainForm_FocusChanged (HasFocus As Boolean)
    HideSplashForm
End Sub

#If B4J

Private Sub TitlePnl_MousePressed (EventData As MouseEvent)
    ox = EventData.X
    oy = EventData.Y
End Sub

Private Sub MovePageOnMouseDrag (eventdata As MouseEvent)
    Dim jo As JavaObject = eventdata
    B4XPages.GetNativeParent(Me).WindowLeft = jo.RunMethod("getScreenX", Null) - ox
    B4XPages.GetNativeParent(Me).WindowTop = jo.RunMethod("getScreenY", Null) - oy
End Sub

Private Sub TitlePnl_MouseDragged (EventData As MouseEvent)
    MovePageOnMouseDrag (EventData)
End Sub

Private Sub TitleLbl_MousePressed (EventData As MouseEvent)
    ox = EventData.X
    oy = EventData.Y
End Sub

Private Sub TitleLbl_MouseDragged (EventData As MouseEvent)
    MovePageOnMouseDrag (EventData)
End Sub

Private Sub AspectsPnl_MousePressed (EventData As MouseEvent)
    ox = EventData.X
    oy = EventData.Y
End Sub

Private Sub AspectsPnl_MouseDragged (EventData As MouseEvent)
    MovePageOnMouseDrag (EventData)
End Sub

Private Sub PlantOverviewLbl_MouseEntered (EventData As MouseEvent)
'    PlantOverviewLbl.Color = xui.Color_ARGB(200, 255, 225, 150)
  
End Sub

Private Sub PlantOverviewLbl_MouseExited (EventData As MouseEvent)
'    PlantOverviewLbl.Color = xui.Color_Transparent
  
End Sub

Private Sub OpnProceduresLbl_MouseEntered (EventData As MouseEvent)
    OpnProceduresLbl.Color = xui.Color_ARGB(200, 255, 225, 150)
  
End Sub

Private Sub OpnProceduresLbl_MouseExited (EventData As MouseEvent)
    OpnProceduresLbl.Color = xui.Color_Transparent

End Sub

Private Sub MntProceduresLbl_MouseEntered (EventData As MouseEvent)
    MntProceduresLbl.Color = xui.Color_ARGB(200, 255, 225, 150)
  
End Sub

Private Sub MntProceduresLbl_MouseExited (EventData As MouseEvent)
    MntProceduresLbl.Color = xui.Color_Transparent
  
End Sub

Private Sub SEC12DatabookLbl_MouseEntered (EventData As MouseEvent)
    SEC12DatabookLbl.Color = xui.Color_ARGB(200, 255, 225, 150)

End Sub

Private Sub SEC12DatabookLbl_MouseExited (EventData As MouseEvent)
    SEC12DatabookLbl.Color = xui.Color_Transparent

End Sub

Private Sub KKSFinderLbl_MouseEntered (EventData As MouseEvent)
    KKSFinderLbl.Color = xui.Color_ARGB(200, 255, 225, 150)
  
End Sub

Private Sub KKSFinderLbl_MouseExited (EventData As MouseEvent)
    KKSFinderLbl.Color = xui.Color_Transparent
  
End Sub

Private Sub UserSettingsLbl_MouseEntered (EventData As MouseEvent)
    UserSettingsLbl.Color = xui.Color_ARGB(200, 255, 225, 150)
  
End Sub

Private Sub UserSettingsLbl_MouseExited (EventData As MouseEvent)
    UserSettingsLbl.Color = xui.Color_Transparent
  
End Sub

Private Sub ExitAppLbl_MouseEntered (EventData As MouseEvent)
    ExitAppLbl.Color = xui.Color_ARGB(200, 255, 225, 150)
End Sub

Private Sub ExitAppLbl_MouseExited (EventData As MouseEvent)
    ExitAppLbl.Color = xui.Color_Transparent
End Sub

Private Sub PlantOverviewLbl_MouseClicked (EventData As MouseEvent)
    B4XPages.ShowPage("MainPage")
End Sub

Private Sub OpnProceduresLbl_MouseClicked (EventData As MouseEvent)
    B4XPages.ShowPage("OpnProcedures Page")
End Sub

Private Sub MntProceduresLbl_MouseClicked (EventData As MouseEvent)
    B4XPages.ShowPage("MntProcedures Page")
End Sub

Private Sub KKSFinderLbl_MouseClicked (EventData As MouseEvent)
    B4XPages.ShowPage("KKSFinder Page")
End Sub

Private Sub SEC12DatabookLbl_MouseClicked (EventData As MouseEvent)
    B4XPages.ShowPage("SEC12Databook Page")
End Sub

Private Sub UserSettingsLbl_MouseClicked (EventData As MouseEvent)
    B4XPages.ShowPage("UserSettings Page")
End Sub

Private Sub imgOpenMenuBtn_MouseClicked (EventData As MouseEvent)
    HideSplashForm
    ShowDrawerMenu
End Sub

Private Sub DrawerMenuImg_MouseClicked (EventData As MouseEvent)
    HideSplashForm
    ShowDrawerMenu
End Sub

Private Sub ExitAppLbl_MouseClicked (EventData As MouseEvent)
    CheckAppClosing
End Sub

Private Sub TitleImageVw_MouseClicked (EventData As MouseEvent)
    Log("Title Image Mouse Click at " & EventData.X & "," & EventData.Y)
    HideSplashForm
    HideDrawerMenu
End Sub

Private Sub DetalyeLbl_MouseClicked (EventData As MouseEvent)
    HideSplashForm
End Sub

Private Sub TitlePnl_MouseClicked (EventData As MouseEvent)
    HideSplashForm
    HideDrawerMenu
End Sub

Private Sub TitleLbl_MouseClicked (EventData As MouseEvent)
    HideSplashForm
End Sub

Private Sub AspectsPnl_MouseClicked (EventData As MouseEvent)
    HideSplashForm
End Sub

Private Sub MainForm_MouseClicked (EventData As MouseEvent)
    HideSplashForm
End Sub

Private Sub MainForm_MousePressed (EventData As MouseEvent)
    HideSplashForm
End Sub

Private Sub DrawerMenuPnl_MouseClicked (EventData As MouseEvent)
    HideSplashForm
    HideDrawerMenu
End Sub

Private Sub OpenMenuBtnILbl_MouseClicked (EventData As MouseEvent)
    HideSplashForm
    ShowDrawerMenu
End Sub

Private Sub MainPane_MouseClicked (EventData As MouseEvent)
    HideSplashForm
    HideDrawerMenu
End Sub

Private Sub TitleLbl_MouseEntered (EventData As MouseEvent)
  
End Sub

Private Sub AspectsPnl_MouseEntered (EventData As MouseEvent)
  
End Sub

Private Sub MainForm_MouseDragged (EventData As MouseEvent)
  
End Sub

Private Sub AboutPnl_MouseEntered (EventData As MouseEvent)
  
End Sub

Private Sub TitlePnl_MouseEntered (EventData As MouseEvent)
  
End Sub

Private Sub TitleImageVw_MouseEntered (EventData As MouseEvent)
  
End Sub

Private Sub DateTimeLbl_MouseEntered (EventData As MouseEvent)
  
End Sub

Private Sub DateTimePnl_MouseEntered (EventData As MouseEvent)
  
End Sub

Private Sub PrkEntriesPnl_MouseEntered (EventData As MouseEvent)
  
End Sub

#End If

B4XTiledMenuPage:
B4J=true
Group=Default Group
ModulesStructureVersion=1
Type=Class
Version=8.9
@EndOfDesignText@
Sub Class_Globals
    Private TiledMenuPageVw As B4XView
    Private xui As XUI
  
    Private ox, oy As Double
  
    Private DateTimeLbl As B4XView
    Private DateTimeTimer As Timer
    Private DateTimePnl As B4XView
    Private PlantOverviewBtnPnl As B4XView
    Private OpnProceduresBtnPnl As B4XView
    Private MntProceduresBtnPnl As B4XView
    Private KKSFinderBtnPnl As B4XView
    Private SEC12DatabookBtnPnl As B4XView
    Private UserSettingBtnPnl As B4XView
    Private MainPane As B4XView
    Private TitlePnl As B4XView
    Private ConfigBtnPnl As B4XView
End Sub

'You can add more parameters here.
Public Sub Initialize As Object

     Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (PageView As B4XView)
    Log("TiledMenuPage Create")
    TiledMenuPageVw = PageView
    TiledMenuPageVw.LoadLayout("TiledMenuPage")

    SetPageSize
  
    #if b4j
    Log("OpenWindows :" & Main.OpenWindows)
  
    #End If
  
    B4XPages.SetTitle(Me, B4XPages.MainPage.ProjectTitle)
    SetConctrolsLocation
    UpdateBtns

End Sub

Private Sub SetPageSize
    CodeLibrary.SetMoveListener(B4XPages.GetNativeParent(Me))
    #if b4j
    CodeLibrary.SetMinMaxWindowSize(B4XPages.GetNativeParent(Me))
    CodeLibrary.SetPageSizeAndLocation(B4XPages.GetNativeParent(Me))
    CodeLibrary.CheckIfPageWindowIsMaximized(B4XPages.GetNativeParent(Me))
  
    #End If
End Sub

Private Sub SetConctrolsLocation
    OpnProceduresBtnPnl.RemoveViewFromParent
    PlantOverviewBtnPnl.RemoveViewFromParent
    MntProceduresBtnPnl.RemoveViewFromParent
    KKSFinderBtnPnl.RemoveViewFromParent
    SEC12DatabookBtnPnl.RemoveViewFromParent
    UserSettingBtnPnl.RemoveViewFromParent
  
    OpnProceduresBtnPnl.Width = MainPane.Width / 4
    OpnProceduresBtnPnl.Height = MainPane.Height / 4
    OpnProceduresBtnPnl.Top = (TitlePnl.Height) + (OpnProceduresBtnPnl.Height / 3)
    OpnProceduresBtnPnl.Left = (MainPane.Width / 2) - (OpnProceduresBtnPnl.Width / 2)
    MainPane.AddView( _
    OpnProceduresBtnPnl, _
    OpnProceduresBtnPnl.Left, _
    OpnProceduresBtnPnl.Top, _
    OpnProceduresBtnPnl.Width, _
    OpnProceduresBtnPnl.Height)

    PlantOverviewBtnPnl.Width = OpnProceduresBtnPnl.Width
    PlantOverviewBtnPnl.Height = OpnProceduresBtnPnl.Height
    PlantOverviewBtnPnl.Top = OpnProceduresBtnPnl.Top
    PlantOverviewBtnPnl.Left = OpnProceduresBtnPnl.Left - PlantOverviewBtnPnl.Width - (OpnProceduresBtnPnl.Width /8)
    MainPane.AddView( _
    PlantOverviewBtnPnl, _
    PlantOverviewBtnPnl.Left, _
    PlantOverviewBtnPnl.Top, _
    PlantOverviewBtnPnl.Width, _
    PlantOverviewBtnPnl.Height)
  
    MntProceduresBtnPnl.Width = OpnProceduresBtnPnl.Width
    MntProceduresBtnPnl.Height = OpnProceduresBtnPnl.Height
    MntProceduresBtnPnl.Top = OpnProceduresBtnPnl.Top
    MntProceduresBtnPnl.Left = OpnProceduresBtnPnl.Left + OpnProceduresBtnPnl.Width + (OpnProceduresBtnPnl.Width /8)
    MainPane.AddView( _
    MntProceduresBtnPnl, _
    MntProceduresBtnPnl.Left, _
    MntProceduresBtnPnl.Top, _
    MntProceduresBtnPnl.Width, _
    MntProceduresBtnPnl.Height)
  
    KKSFinderBtnPnl.Height = OpnProceduresBtnPnl.Height
    KKSFinderBtnPnl.Width = OpnProceduresBtnPnl.Width
    KKSFinderBtnPnl.Top = PlantOverviewBtnPnl.Top + PlantOverviewBtnPnl.Height + (PlantOverviewBtnPnl.Height / 8)
    KKSFinderBtnPnl.Left = PlantOverviewBtnPnl.Left
    MainPane.AddView( _
    KKSFinderBtnPnl, _
    KKSFinderBtnPnl.Left, _
    KKSFinderBtnPnl.Top, _
    KKSFinderBtnPnl.Width, _
    KKSFinderBtnPnl.Height)
  
    SEC12DatabookBtnPnl.Height = OpnProceduresBtnPnl.Height
    SEC12DatabookBtnPnl.Width = OpnProceduresBtnPnl.Width
    SEC12DatabookBtnPnl.Top = KKSFinderBtnPnl.Top
    SEC12DatabookBtnPnl.Left = OpnProceduresBtnPnl.Left
    MainPane.AddView( _
    SEC12DatabookBtnPnl, _
    SEC12DatabookBtnPnl.Left, _
    SEC12DatabookBtnPnl.Top, _
    SEC12DatabookBtnPnl.Width, _
    SEC12DatabookBtnPnl.Height)
  
    UserSettingBtnPnl.Height = OpnProceduresBtnPnl.Height
    UserSettingBtnPnl.Width = OpnProceduresBtnPnl.Width
    UserSettingBtnPnl.Top = KKSFinderBtnPnl.Top
    UserSettingBtnPnl.Left = MntProceduresBtnPnl.Left
    MainPane.AddView( _
    UserSettingBtnPnl, _
    UserSettingBtnPnl.Left, _
    UserSettingBtnPnl.Top, _
    UserSettingBtnPnl.Width, _
    UserSettingBtnPnl.Height)
End Sub

 Private Sub AppPage_Tick
    DateTime.DateFormat = "yyyy MMM d, EEE  HH:mm:ss"
    DateTimeLbl.Text = DateTime.Date(DateTime.Now)
    DateTimePnl.Width = DateTimeLbl.Width + 15
End Sub

Private Sub CheckIfTimerIsInitialized
    If Not(DateTimeTimer.IsInitialized) Then
        DateTimeTimer.Initialize("AppPage", 200)
        DateTimeTimer.Enabled = True
    End If
End Sub

Private Sub B4XPage_Appear
    Log("TiledMenuPage Appear")
    #if b4j
    Main.OpenWindows = Main.OpenWindows + 1
  
    #End If
    CheckIfTimerIsInitialized
    SetPageSize
    HideSplashForm
End Sub

Private Sub B4XPage_Disappear
    Log("TiledMenuPage Disappear")
    #if b4j
    Main.OpenWindows = Main.OpenWindows - 1
  
    #End If
    HideSplashForm
End Sub

Private Sub B4XPage_Foreground
    Log("TiledMenuPage Foreground")
    HideSplashForm
 End Sub

Private Sub B4XPage_Background
    Log("TiledMenuPage Background")
    #if b4j
    Main.OpenWindows = Main.OpenWindows - 1
  
    #End If
    HideSplashForm
End Sub

Private Sub B4XPage_Resize (Width As Int, Height As Int)
    HideSplashForm
    Log("TiledMenuPage Resize " & Width & " / " & Height)
    #if b4j
    CodeLibrary.GetPageSizeAndLocation(B4XPages.GetNativeParent(Me))
    CodeLibrary.CheckIfPageWindowIsMaximized(B4XPages.GetNativeParent(Me))
  
    #End If
    SetConctrolsLocation
    UpdateBtns
End Sub

Private Sub UpdateBtns
    For i = 1 To 6
        MouseMouseExitedBtn(i)
    Next
End Sub

 Private Sub AppClosingMsgBx As Object
    HideSplashForm
    Dim icon As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "SEC logo w-bg.png", 60dip, 60dip, True)
    Dim myMsgBx As Object = xui.Msgbox2Async("Are you sure on closing this App?", "App Alert", "Yes", "No", "", icon)
    Return myMsgBx
End Sub

Private Sub CheckAppClosing
    Wait For (AppClosingMsgBx) Msgbox_Result (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Log("Closing the application through menu exit button")
        CodeLibrary.CloseAllSQLiteConnections
        ExitApplication
    Else
        B4XPages.ShowPageAndRemovePreviousPages("TiledMenu Page")
    End If
End Sub

Private Sub B4XPage_CloseRequest As ResumableSub
    Dim closerequestresult As Boolean = False
    #if b4j
    If Main.OpenWindows <= 1 Then
        Wait For (AppClosingMsgBx) Msgbox_Result (Result As Int)
        If Result = xui.DialogResponse_Positive Then
            Log("Exiting the application through close button")
            CodeLibrary.CloseAllSQLiteConnections
            ExitApplication
            closerequestresult = True
        Else
            B4XPages.ShowPageAndRemovePreviousPages("TiledMenu Page")
            Main.OpenWindows = Main.OpenWindows - 1
            closerequestresult = False
        End If
    Else
        Main.OpenWindows = Main.OpenWindows - 1
        closerequestresult = True
    End If
  
    #End If
    Return closerequestresult
End Sub

Private Sub HideSplashForm
    #if b4j
    If Not(Main.SplashHidden) Then
        Main.SplashHidden = True
        Main.SplashForm.Close
    End If
  
    #End If
End Sub

Private Sub ProgLbl_Click
    CodeLibrary.AboutProgrammer
    HideSplashForm
End Sub

Private Sub ShowAnnivGreeting (days As Int, yrs As Int)
    Try
        #if b4j
        Main.ShowAnnivScreen(True, B4XPages.GetNativeParent(Me).WindowLeft, _
        B4XPages.GetNativeParent(Me).WindowTop, _
        B4XPages.GetNativeParent(Me).WindowWidth, _
        B4XPages.GetNativeParent(Me).WindowHeight, days, yrs)
      
        #End If
    Catch
        Log(LastException)
    End Try
End Sub

Private Sub CheckDateForAnniv
    Dim days, yrs As Int
    DateTime.DateFormat = "yyyy-MM-dd"
    Dim DateNgHandog As Long = DateTime.DateParse("2016-04-27")
    Dim AnnivThisYr As Long = DateTime.DateParse(DateTime.GetYear(DateTime.Now) & "-04-27")
    If AnnivThisYr > DateTime.Now Then
        days = - DateTime.GetDayOfYear(AnnivThisYr - DateTime.Now)
    Else
        days = DateTime.GetDayOfYear(DateTime.Now - AnnivThisYr) - 1
    End If
    yrs = DateTime.GetYear(DateTime.Now) -  DateTime.GetYear(DateNgHandog)
    ShowAnnivGreeting(days, yrs)
End Sub

Private Sub MouseEnteredBtn (BtnNumber As Byte)
    Select BtnNumber
        Case 1
            Dim BtnImg As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "PlantOverview-mouse-enter.png", PlantOverviewBtnPnl.Width, PlantOverviewBtnPnl.Height, False)
            Dim BtnImgVw As ImageView
            BtnImgVw.Initialize("imgPlantOverviewBtn")
            #if b4j
            BtnImgVw.SetImage(BtnImg)
            BtnImgVw.PickOnBounds = True
          
            #End If
            PlantOverviewBtnPnl.RemoveAllViews
            PlantOverviewBtnPnl.AddView(BtnImgVw, 0, 0, PlantOverviewBtnPnl.Width, PlantOverviewBtnPnl.Height)
        Case 2
            Dim BtnImg As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "OpnProcedures-mouse-enter.png", OpnProceduresBtnPnl.Width, OpnProceduresBtnPnl.Height, False)
            Dim BtnImgVw As ImageView
            BtnImgVw.Initialize("imgOpnProcBtn")
            #if b4j
            BtnImgVw.SetImage(BtnImg)
            BtnImgVw.PickOnBounds = True
          
            #End If
            OpnProceduresBtnPnl.RemoveAllViews
            OpnProceduresBtnPnl.AddView(BtnImgVw, 0, 0, OpnProceduresBtnPnl.Width, OpnProceduresBtnPnl.Height)
        Case 3
            Dim BtnImg As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "MntProcedures-mouse-enter.png", MntProceduresBtnPnl.Width, MntProceduresBtnPnl.Height, False)
            Dim BtnImgVw As ImageView
            BtnImgVw.Initialize("imgMntProcBtn")
            #if b4j
            BtnImgVw.SetImage(BtnImg)
            BtnImgVw.PickOnBounds = True
          
            #End If
            MntProceduresBtnPnl.RemoveAllViews
            MntProceduresBtnPnl.AddView(BtnImgVw, 0, 0, MntProceduresBtnPnl.Width, MntProceduresBtnPnl.Height)
        Case 4
            Dim BtnImg As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "KKSFinder-mouse-enter.png", KKSFinderBtnPnl.Width, KKSFinderBtnPnl.Height, False)
            Dim BtnImgVw As ImageView
            BtnImgVw.Initialize("imgKKSBtn")
            #if b4j
            BtnImgVw.SetImage(BtnImg)
            BtnImgVw.PickOnBounds = True
          
            #End If
            KKSFinderBtnPnl.RemoveAllViews
            KKSFinderBtnPnl.AddView(BtnImgVw, 0, 0, KKSFinderBtnPnl.Width, KKSFinderBtnPnl.Height)
        Case 5
            Dim BtnImg As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "Databook-mouse-enter.png", SEC12DatabookBtnPnl.Width, SEC12DatabookBtnPnl.Height, False)
            Dim BtnImgVw As ImageView
            BtnImgVw.Initialize("imgSECDatabookBtn")
            #if b4j
            BtnImgVw.SetImage(BtnImg)
            BtnImgVw.PickOnBounds = True
          
            #End If
            SEC12DatabookBtnPnl.RemoveAllViews
            SEC12DatabookBtnPnl.AddView(BtnImgVw, 0, 0, SEC12DatabookBtnPnl.Width, SEC12DatabookBtnPnl.Height)
        Case 6
            Dim BtnImg As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "UserSettings-mouse-enter.png", UserSettingBtnPnl.Width, UserSettingBtnPnl.Height, False)
            Dim BtnImgVw As ImageView
            BtnImgVw.Initialize("imgUserBtn")
            #if b4j
            BtnImgVw.SetImage(BtnImg)
            BtnImgVw.PickOnBounds = True
          
            #End If
            UserSettingBtnPnl.RemoveAllViews
            UserSettingBtnPnl.AddView(BtnImgVw, 0, 0, UserSettingBtnPnl.Width, UserSettingBtnPnl.Height)
        Case 7
            Dim BtnImg As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "config-mouse-enter.png", ConfigBtnPnl.Width, ConfigBtnPnl.Height, False)
            Dim BtnImgVw As ImageView
            BtnImgVw.Initialize("imgConfigBtn")
            #if b4j
            BtnImgVw.SetImage(BtnImg)
            BtnImgVw.PickOnBounds = True
          
            #End If
            ConfigBtnPnl.RemoveAllViews
            ConfigBtnPnl.AddView(BtnImgVw, 0, 0, ConfigBtnPnl.Width, ConfigBtnPnl.Height)
    End Select
End Sub

Private Sub MouseMouseExitedBtn (BtnNumber As Byte)
    Select BtnNumber
        Case 1
            Dim BtnImg As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "PlantOverview.png", PlantOverviewBtnPnl.Width, PlantOverviewBtnPnl.Height, False)
            Dim BtnImgVw As ImageView
            BtnImgVw.Initialize("imgPlantOverviewBtn")
            #if b4j
            BtnImgVw.SetImage(BtnImg)
            BtnImgVw.PickOnBounds = True
          
            #End If
            PlantOverviewBtnPnl.RemoveAllViews
            PlantOverviewBtnPnl.AddView(BtnImgVw, 0, 0, PlantOverviewBtnPnl.Width, PlantOverviewBtnPnl.Height)
        Case 2
            Dim BtnImg As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "OpnProcedures.png", OpnProceduresBtnPnl.Width, OpnProceduresBtnPnl.Height, False)
            Dim BtnImgVw As ImageView
            BtnImgVw.Initialize("imgOpnProcBtn")
            #if b4j
            BtnImgVw.SetImage(BtnImg)
            BtnImgVw.PickOnBounds = True
          
            #End If
            OpnProceduresBtnPnl.RemoveAllViews
            OpnProceduresBtnPnl.AddView(BtnImgVw, 0, 0, OpnProceduresBtnPnl.Width, OpnProceduresBtnPnl.Height)
        Case 3
            Dim BtnImg As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "MntProcedures.png", MntProceduresBtnPnl.Width, MntProceduresBtnPnl.Height, False)
            Dim BtnImgVw As ImageView
            BtnImgVw.Initialize("imgMntProcBtn")
            #if b4j
            BtnImgVw.SetImage(BtnImg)
            BtnImgVw.PickOnBounds = True
          
            #End If
            MntProceduresBtnPnl.RemoveAllViews
            MntProceduresBtnPnl.AddView(BtnImgVw, 0, 0, MntProceduresBtnPnl.Width, MntProceduresBtnPnl.Height)
        Case 4
            Dim BtnImg As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "KKSFinder.png", KKSFinderBtnPnl.Width, KKSFinderBtnPnl.Height, False)
            Dim BtnImgVw As ImageView
            BtnImgVw.Initialize("imgKKSBtn")
            #if b4j
            BtnImgVw.SetImage(BtnImg)
            BtnImgVw.PickOnBounds = True
          
            #End If
            KKSFinderBtnPnl.RemoveAllViews
            KKSFinderBtnPnl.AddView(BtnImgVw, 0, 0, KKSFinderBtnPnl.Width, KKSFinderBtnPnl.Height)
        Case 5
            Dim BtnImg As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "Databook.png", SEC12DatabookBtnPnl.Width, SEC12DatabookBtnPnl.Height, False)
            Dim BtnImgVw As ImageView
            BtnImgVw.Initialize("imgSECDatabookBtn")
            #if b4j
            BtnImgVw.SetImage(BtnImg)
            BtnImgVw.PickOnBounds = True
          
            #End If
            SEC12DatabookBtnPnl.RemoveAllViews
            SEC12DatabookBtnPnl.AddView(BtnImgVw, 0, 0, SEC12DatabookBtnPnl.Width, SEC12DatabookBtnPnl.Height)
        Case 6
            Dim BtnImg As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "UserSettings.png", UserSettingBtnPnl.Width, UserSettingBtnPnl.Height, False)
            Dim BtnImgVw As ImageView
            BtnImgVw.Initialize("imgUserBtn")
            #if b4j
            BtnImgVw.SetImage(BtnImg)
            BtnImgVw.PickOnBounds = True
          
            #End If
            UserSettingBtnPnl.RemoveAllViews
            UserSettingBtnPnl.AddView(BtnImgVw, 0, 0, UserSettingBtnPnl.Width, UserSettingBtnPnl.Height)
        Case 7
            Dim BtnImg As B4XBitmap = xui.LoadBitmapResize(File.DirAssets, "config.png",  ConfigBtnPnl.Width,  ConfigBtnPnl.Height, False)
            Dim BtnImgVw As ImageView
            BtnImgVw.Initialize("imgConfigBtn")
            #if b4j
            BtnImgVw.SetImage(BtnImg)
            BtnImgVw.PickOnBounds = True
          
            #End If
            ConfigBtnPnl.RemoveAllViews
            ConfigBtnPnl.AddView(BtnImgVw, 0, 0,  ConfigBtnPnl.Width,  ConfigBtnPnl.Height)
    End Select
End Sub

#if b4j

Private Sub ExitAppLbl_MouseClicked (EventData As MouseEvent)
    CheckAppClosing
End Sub

Private Sub DateTimeLbl_MouseClicked (EventData As MouseEvent)
    CheckDateForAnniv
End Sub

Private Sub DateTimePnl_MouseClicked (EventData As MouseEvent)
    CheckDateForAnniv
End Sub

Private Sub TitlePnl_MousePressed (EventData As MouseEvent)
    ox = EventData.X
    oy = EventData.Y
End Sub

Private Sub MovePageOnMouseDrag (eventdata As MouseEvent)
    Dim jo As JavaObject = eventdata
    B4XPages.GetNativeParent(Me).WindowLeft = jo.RunMethod("getScreenX", Null) - ox
    B4XPages.GetNativeParent(Me).WindowTop = jo.RunMethod("getScreenY", Null) - oy
End Sub

Private Sub TitlePnl_MouseDragged (EventData As MouseEvent)
    MovePageOnMouseDrag (EventData)
End Sub

Private Sub PlantOverviewBtnPnl_MouseClicked (EventData As MouseEvent)
    B4XPages.ShowPageAndRemovePreviousPages("MainPage")
    Main.OpenWindows = Main.OpenWindows - 1
End Sub

Private Sub PlantOverviewBtnPnl_MouseEntered (EventData As MouseEvent)
    MouseEnteredBtn(1)
 End Sub

Private Sub PlantOverviewBtnPnl_MouseExited (EventData As MouseEvent)
    MouseMouseExitedBtn(1)
End Sub

Private Sub OpnProceduresBtnPnl_MouseClicked (EventData As MouseEvent)
    B4XPages.ShowPageAndRemovePreviousPages("OpnProcedures Page")
    Main.OpenWindows = Main.OpenWindows - 1
End Sub

Private Sub OpnProceduresBtnPnl_MouseEntered (EventData As MouseEvent)
    MouseEnteredBtn(2)
End Sub

Private Sub OpnProceduresBtnPnl_MouseExited (EventData As MouseEvent)
    MouseMouseExitedBtn(2)
End Sub

Private Sub MntProceduresBtnPnl_MouseClicked (EventData As MouseEvent)
    B4XPages.ShowPageAndRemovePreviousPages("MntProcedures Page")
    Main.OpenWindows = Main.OpenWindows - 1
End Sub

Private Sub MntProceduresBtnPnl_MouseEntered (EventData As MouseEvent)
    MouseEnteredBtn(3)
End Sub

Private Sub MntProceduresBtnPnl_MouseExited (EventData As MouseEvent)
    MouseMouseExitedBtn(3)
End Sub

Private Sub KKSFinderBtnPnl_MouseClicked (EventData As MouseEvent)
    B4XPages.ShowPageAndRemovePreviousPages("KKSFinder Page")
    Main.OpenWindows = Main.OpenWindows - 1
End Sub

Private Sub KKSFinderBtnPnl_MouseEntered (EventData As MouseEvent)
    MouseEnteredBtn(4)
End Sub

Private Sub KKSFinderBtnPnl_MouseExited (EventData As MouseEvent)
    MouseMouseExitedBtn(4)
End Sub

Private Sub SEC12DatabookBtnPnl_MouseClicked (EventData As MouseEvent)
    B4XPages.ShowPageAndRemovePreviousPages("SEC12Databook Page")
    Main.OpenWindows = Main.OpenWindows - 1
End Sub

Private Sub SEC12DatabookBtnPnl_MouseEntered (EventData As MouseEvent)
    MouseEnteredBtn(5)
End Sub

Private Sub SEC12DatabookBtnPnl_MouseExited (EventData As MouseEvent)
    MouseMouseExitedBtn(5)
End Sub

Private Sub UserSettingBtnPnl_MouseClicked (EventData As MouseEvent)
    B4XPages.ShowPageAndRemovePreviousPages("UserSettings Page")
    Main.OpenWindows = Main.OpenWindows - 1
End Sub

Private Sub UserSettingBtnPnl_MouseEntered (EventData As MouseEvent)
    MouseEnteredBtn(6)
End Sub

Private Sub UserSettingBtnPnl_MouseExited (EventData As MouseEvent)
    MouseMouseExitedBtn(6)
End Sub

Private Sub ConfigBtnPnl_MouseEntered (EventData As MouseEvent)
    MouseEnteredBtn(7)
End Sub

Private Sub ConfigBtnPnl_MouseExited (EventData As MouseEvent)
    MouseMouseExitedBtn(7)
End Sub

Private Sub ConfigBtnPnl_MouseClicked (EventData As MouseEvent)
    Dim MsgBx As Object = xui.Msgbox2Async( _
                    $"Continue with App configuration/setup?"$, _
                    "App Alert", "Yes", "No", "", Null)
    Wait For (MsgBx) Msgbox_Result (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Log("Show Config Page")
        B4XPages.ShowPageAndRemovePreviousPages("Config Page")
        Main.OpenWindows = Main.OpenWindows - 1
    End If
End Sub

#End If
 
Last edited:
Upvote 0

JGParamo

Member
Licensed User
Show the next page and then close the current one. Does it flicker?
I tried this code below but PlantOverviewBtnPnl_MouseClicked returns an exception shown here.

PlantOverviewBtnPnl_MouseClicked:
Private Sub PlantOverviewBtnPnl_MouseClicked (EventData As MouseEvent)
    'B4XPages.ShowPageAndRemovePreviousPages("MainPage")
    B4XPages.ShowPage("MainPage")
    B4XPages.ClosePage("TiledMenu Page")
    Main.OpenWindows = Main.OpenWindows - 1
End Sub

PlantOverviewBtnPnl_MouseClicked Exception:
MainPage Create
OpenWindows :0
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
MainPage Foreground
MainPage Appear
Showing page: 1  Circle image left position at: 442
MainPage Resize 960 / 620
TiledMenuPage Create
OpenWindows :1
Form moved to 195 : 55
Form moved to 195 : 55
MainPage Disappear
TiledMenuPage Appear
TiledMenuPage Resize 960 / 620
(Exception) Not initialized
b4xpagesmanager._closepage (java line: 207)
java.lang.NullPointerException
    at b4j.OpMnTimizer.b4xpagesmanager._closepage(b4xpagesmanager.java:207)
    at b4j.OpMnTimizer.b4xpages._closepage(b4xpages.java:50)
    at b4j.OpMnTimizer.b4xtiledmenupage._plantoverviewbtnpnl_mouseclicked(b4xtiledmenupage.java:897)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:109)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:96)
    at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:109)
    at anywheresoftware.b4j.objects.NodeWrapper$1.handle(NodeWrapper.java:1)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Scene$ClickGenerator.postProcess(Scene.java:3470)
    at javafx.scene.Scene$ClickGenerator.access$8100(Scene.java:3398)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3766)
    at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:397)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:434)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:410)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:433)
    at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
    at com.sun.glass.ui.View.notifyMouse(View.java:941)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:185)
    at java.lang.Thread.run(Thread.java:748)
 
Upvote 0

JGParamo

Member
Licensed User
We cannot do anything with the code you posted. There is a link at the top of B4XMainPage that allows you to export the project.
As it is not possible to attach large zip file in this thread, let me use my OneDrive link, here's the Project.zip file.
 
Last edited:
Upvote 0

MicroDrie

Well-Known Member
Licensed User
What I notice for "flicker" is only the very first time that a B4XPage is displayed what appears to be look like a screen rebuilding. I wonder why from a B4XPage, that is managed and under the control of the B4XPage manager, you are calling routines in Main who are outside the control B4XPage manager.

Why aren't those routines just on the B4XMainPage which can be call from other B4XPages?
 
Upvote 0

JGParamo

Member
Licensed User
I didn't get any error when clicking on the Planet Overview button.
No error when the Project is executed as I have retracted back to my original code, as shown.
PlantOverviewBtnPnl_MouseClicked:
Private Sub PlantOverviewBtnPnl_MouseClicked (EventData As MouseEvent)
    B4XPages.ShowPageAndRemovePreviousPages("MainPage")
    Main.OpenWindows = Main.OpenWindows - 1
End Sub

But error shows if the code is:
PlantOverviewBtnPnl_MouseClicked:
Private Sub PlantOverviewBtnPnl_MouseClicked (EventData As MouseEvent)
    'B4XPages.ShowPageAndRemovePreviousPages("MainPage")
    B4XPages.ShowPage("MainPage")
    B4XPages.ClosePage("TiledMenu Page")
    Main.OpenWindows = Main.OpenWindows - 1
End Sub
 
Upvote 0

JGParamo

Member
Licensed User
What I notice for "flicker" is only the very first time that a B4XPage is displayed what appears to be look like a screen rebuilding. I wonder why from a B4XPage, that is managed and under the control of the B4XPage manager, you are calling routines in Main who are outside the control B4XPage manager.

Why aren't those routines just on the B4XMainPage which can be call from other B4XPages?
My codes were just the result of the way how I figure out calling each B4XPage for the other B4XPages (each B4XPage has distinct content not similar with the other B4XPages, variables values passing between Main, B4XMainPage, and other B4XPages through global public B4XViews and variables). Having all those calls in the B4XMainPage could result to lots of codes in the B4XMainPage, so individual B4XPage helps on this as form of modularization a.k.a. divide and conquer. I don't have formal training with coding styles so my work my be not that structured or efficient. The issue may just be the perceived flickering due opening and closing of B4XPages (desktop windows) when using B4XPages.ShowPageAndRemovePreviousPages method as it is intended to display only one page window. If this opening and closing of windows is inherent when using B4XPages.ShowPageAndRemovePreviousPages, any suggestions, code improvements or work-around in this flicker issue will be greatly appreciated.
 
Last edited:
Upvote 0

MicroDrie

Well-Known Member
Licensed User
I don't have formal training with coding styles so my work my be not that structured or efficient.
We can all learn something every day from the many examples, other people's mistakes how not to do it and many solutions offered on this forum. Just using the right search terms is more important than a formal education in programming because I never learned about how to use debugging.

Having all those calls in the B4XMainPage could result to lots of codes in the B4XMainPage, so individual B4XPage helps on this as form of modularization a.k.a. divide and conquer.
In the forum it is very common to use the B4XMainPage as "Home" page. However, you can also choose to use a B4XHomePage as the "Home" page and put your B4X Globals variables and shared subroutines in B4XMainPage.

If you want to give the user the possibility to work with only one window, you can use the following show modal form code:
Show modal form:
Public Sub ShowModal
    Dim frm As Form = B4XPages.GetNativeParent(Me)
    frm.WindowLeft = 400
    frm.WindowTop = 100
    frm.ShowAndWait
End Sub
 
Upvote 0

JGParamo

Member
Licensed User
Show modal form:
Public Sub ShowModal
    Dim frm As Form = B4XPages.GetNativeParent(Me)
    frm.WindowLeft = 400
    frm.WindowTop = 100
    frm.ShowAndWait
End Sub
I've previously used a form that contains a B4XPage such as that in my Main code module. Using frm.ShowAndWait doesn't allow succeeding methods to execute as it waits for the window to close first, as I have observed.
 
Last edited:
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Using frm.ShowAndWait don't allow succeeding methods to execute as it waits for the window to close first, as I have observed.
That is exactly the purpose of a model page, the user must first finish or abort the activity while he cannot switch between other pages. It could be handy in cases when a change on the modal pages must lead to necessary updates in other B4Xpages with closing the modal page.
 
Upvote 0
Top