B4J Question ABMaterial - multiple themes and selection

codie01

Active Member
Licensed User
Longtime User
Hi All,

I am getting a theme not found error:

I abmShared I have the following process globals:

B4X:
Sub Process_Globals
    Public MyTheme As ABMTheme    
    Public MyDarkTheme As ABMTheme

I have two themes in ABMShared as Follows:

'------------------------------------------------------------------------------------
'dark theme
'------------------------------------------------------------------------------------
'button themes ---------------------------------
MyDarkTheme.AddButtonTheme("buttonTheme1") '/used as chips in browsers
MyDarkTheme.Button("buttonTheme1").BackColor = ABM.COLOR_GREY
MyDarkTheme.Button("buttonTheme1").BackColorIntensity = ABM.INTENSITY_DARKEN3
MyDarkTheme.Button("buttonTheme1").ForeColor = ABM.COLOR_WHITE
MyDarkTheme.Button("buttonTheme1").ZDepth = ABM.ZDEPTH_REMOVE

'cell themes -----------------------------------
MyDarkTheme.AddCellTheme("cellThemeright3") 'used on images
MyDarkTheme.Cell("cellThemeright3").Align = ABM.CELL_ALIGN_RIGHT

'------------------------------------------------------------------------------------
'light theme
'------------------------------------------------------------------------------------

'/planner theme
MyTheme.AddPlannerTheme("sectionPlanner")
MyTheme.Planner("sectionPlanner").MenuColor = ABM.COLOR_BLUEGREY
MyTheme.Planner("sectionPlanner").MenuColorIntensity = ABM.INTENSITY_DARKEN3
MyTheme.Planner("sectionPlanner").MenuTextColor = ABM.COLOR_WHITE
MyTheme.Planner("sectionPlanner").DayBorderColor = ABM.COLOR_BLUEGREY
MyTheme.Planner("sectionPlanner").DayColor = ABM.COLOR_BLUEGREY
MyTheme.Planner("sectionPlanner").DayTextColor = ABM.COLOR_BLACK
MyTheme.Planner("sectionPlanner").BackColor = ABM.COLOR_BLUEGREY
MyTheme.Planner("sectionPlanner").HourColor = ABM.COLOR_BLUEGREY
MyTheme.Planner("sectionPlanner").BorderColor = ABM.COLOR_BLACK
MyTheme.Planner("sectionPlanner").HourColorIntensity = ABM.INTENSITY_LIGHTEN2
MyTheme.Planner("sectionPlanner").HourTextColor = ABM.COLOR_BLACK
MyTheme.Planner("sectionPlanner").HourAltColor = ABM.COLOR_WHITE
MyTheme.Planner("sectionPlanner").HourAltTextColor = ABM.COLOR_BLACK
MyTheme.Planner("sectionPlanner").HourMinutesUsedColors(0,ABM.COLOR_BLUEGREY)
MyTheme.Planner("sectionPlanner").HourMinutesUsedColorsIntensity(0,ABM.INTENSITY_DARKEN4)
MyTheme.Planner("sectionPlanner").HourMinutesUsedColors(1,ABM.COLOR_BLUEGREY)
MyTheme.Planner("sectionPlanner").HourMinutesUsedColorsIntensity(1,ABM.INTENSITY_DARKEN2)
MyTheme.Planner("sectionPlanner").HourMinutesUsedColors(2,ABM.COLOR_BLUEGREY)
MyTheme.Planner("sectionPlanner").HourMinutesUsedColorsIntensity(2,ABM.INTENSITY_NORMAL)
MyTheme.Planner("sectionPlanner").HourMinutesUsedColors(3,ABM.COLOR_BLUEGREY)
MyTheme.Planner("sectionPlanner").HourMinutesUsedColorsIntensity(3,ABM.INTENSITY_LIGHTEN2)
MyTheme.Planner("sectionPlanner").HourMinutesNotAvailableColorIntensity = ABM.INTENSITY_DARKEN3

I then select the theme based on cookie setting, however I get "ERROR: No theme found with the name 'MyDarkTheme'. Using the first theme found." when I try to call it with the following code:

Page Routines (Module)

public Sub ConnectPage()
If myDarken = "N" Then
page.SetActiveTheme("MyTheme")
Else
page.SetActiveTheme("MyDarkTheme")
End If
I have added the themes as follows:

Page Routines (Module)

public Sub BuildTheme()
' start with the base theme defined in ABMShared
MyTheme.AddABMTheme(ABMShared.MyTheme)
MyDarkTheme.AddABMTheme(ABMShared.MyDarkTheme)
' add extra page specific theme stuff
What Am i doing wrong!

Thanks
 
Last edited:

alwaysbusy

Expert
Licensed User
Longtime User
Please use code tags.

Just to remove the confusion, I would rename ABMShared.MyTheme into ABMShared.MyLightTheme for example. Let's consider the MyTheme as the current Page theme.

The page only can have one theme at the time: Page.MyTheme. But a Page can hold several themes (like your Light and Dark one).
But you have to make the Page aware it will use multiple themes.

Try this:
In Class_Globals add a list to hold all your themes:
B4X:
Private themes As List

In BuildTheme() add both themes:
B4X:
themes.Initialize
themes.add( ABMShared.MyLightTheme) 'Initialized as MyLightTheme.Initialize("MyLightTheme")
themes.add( ABMShared.MyDarkTheme) 'Initialized as MyLightTheme.Initialize("MyDarkTheme")

In BuildPage() Initialize the Page for using multiple themes:
B4X:
page.InitializeWithThemes(Name, "/ws/" & ABMShared.AppName & "/" & Name, False, ABMShared.SessionMaxInactiveIntervalSeconds, themes)

In ConnectPage, use one of your themes:
B4X:
If myDarken = "N" Then
     page.SetActiveTheme("MyLightTheme")
Else
     page.SetActiveTheme("MyDarkTheme")
End If

Alwaysbusy
 
Upvote 0

codie01

Active Member
Licensed User
Longtime User
Thank you Alwaysbusy,

Do you have an example of how they should be setup in ABMShared. Currently I have :

B4X:
Sub Process_Globals
    Public MyTheme As ABMTheme   
    Public myDarkTheme As ABMTheme

B4X:
Sub BuildTheme(themeName As String)
    '------------------------------------------------------------------------------------
    'dark theme
    '------------------------------------------------------------------------------------
    myDarkTheme.Initialize(themeName)
   
    'definitions ------------------------------------
    myDarkTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_DARKEN4, "#263A4C", 1.0)
    myDarkTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_DARKEN3, "#354A5E", 1.0)
    myDarkTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_DARKEN2, "#455B71", 1.0)
    myDarkTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_DARKEN1, "#566D84", 1.0)
    myDarkTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_NORMAL, "#6A8096", 1.0)
    myDarkTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_LIGHTEN1, "#8094A9", 1.0)
    myDarkTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_LIGHTEN2, "#97A9BC", 1.0)
    myDarkTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_LIGHTEN3, "#B0BFCE", 1.0)
    myDarkTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_LIGHTEN4, "#CBD6E1", 1.0)
    myDarkTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_LIGHTEN5, "#E8EEF4", 1.0)

    'background color ------------------------------
    myDarkTheme.Page.BackColor = "GREY"
    myDarkTheme.Page.BackColorIntensity = ABM.INTENSITY_DARKEN3

    'other component themes left out --------------

    '------------------------------------------------------------------------------------
    'light theme
    '------------------------------------------------------------------------------------

    MyTheme.Initialize("MyTheme")
   
    MyTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_DARKEN4, "#263A4C", 1.0)
    MyTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_DARKEN3, "#354A5E", 1.0)
    MyTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_DARKEN2, "#455B71", 1.0)
    MyTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_DARKEN1, "#566D84", 1.0)
    MyTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_NORMAL, "#6A8096", 1.0)
    MyTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_LIGHTEN1, "#8094A9", 1.0)
    MyTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_LIGHTEN2, "#97A9BC", 1.0)
    MyTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_LIGHTEN3, "#B0BFCE", 1.0)
    MyTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_LIGHTEN4, "#CBD6E1", 1.0)
    MyTheme.Page.AddColorDefinition("dragonfly", ABM.INTENSITY_LIGHTEN5, "#E8EEF4", 1.0)

   'other component themes left out --------------

End Sub

Thanks!
 
Last edited:
Upvote 0
Top