B4J Code Snippet Sharing the goodness: Useful methods

Hi

Mashy's B4J Overview

I'm new to b4j and have just finished my project in it which is a helper for me in relation to php generation. I shared my creation here. As I am working on an updated version, I needed some functionality on the listview,e.g. returning all items as a map, search for a text or searching for a tag property. Whilst this will start with code on a listview, I intend to collect my snippets here.

B4X:
'Description: add two lines to a listview
'Tag: listview, add two lines
Sub ListViewAddTwoLines(lv As ListView, Line1 As String, Line2 As String, Value As Object)
   Dim ap As AnchorPane
   ap.Initialize("")
   Dim lbl1, lbl2 As Label
   lbl1.Initialize("")
   lbl1.Text = Line1                
   lbl1.Font = fx.DefaultFont(14)
   lbl2.Initialize("")
   lbl2.Text = Line2
   lbl2.Font = fx.DefaultFont(12)
   ap.AddNode(lbl1, 0, 0, lv.Width, 20dip)
   ap.AddNode(lbl2, 0, 25dip, lv.Width, 20dip)
   lv.Items.Add(ap)
   lbl1.Tag = Value
End Sub

B4X:
'Description: add a single line to a listview
'Tag: listview, add single line
Sub ListViewAddOneLine(lv As ListView, Line1 As String, Value As Object)
  Dim ap As AnchorPane
  ap.Initialize("")
  Dim lbl1 As Label
  lbl1.Initialize("")
  lbl1.Text = Line1                
  lbl1.Font = fx.DefaultFont(14)
  lbl1.Tag = Value
  ap.AddNode(lbl1, 0, 0, lv.Width, 20dip)
  lv.Items.Add(ap)
End Sub

B4X:
'Description: search for tag from a listview and return boolean
'Tag: b4j, listview, text, search
Sub ListViewTagExist(lstView As ListView, searchTag As String) As Boolean
    Dim l As List
    Dim i As Int
    Dim t As Int
    Dim m As Map
    Dim txt As String
    searchTag = searchTag.ToLowerCase
    ' get all items as a list
    l = ListViewGetItems(lstView)
    t = l.Size - 1
    For i = 0 To t
        m = l.Get(i)
        txt = m.Get("tag")
        txt = txt.ToLowerCase
        If txt = searchTag Then
            Return True
        End If
    Next
    Return False
End Sub

B4X:
'Description: search for text from a listview and return boolean
'Tag: b4j, listview, text, search
Sub ListViewTextExist(lstView As ListView, searchText As String) As Boolean
    Dim l As List
    Dim i As Int
    Dim t As Int
    Dim m As Map
    Dim txt As String
    searchText = searchText.ToLowerCase
    ' get all items as a list
    l = ListViewGetItems(lstView)
    t = l.Size - 1
    For i = 0 To t
        m = l.Get(i)
        txt = m.Get("text")
        txt = txt.ToLowerCase
        If txt = searchText Then
            Return True
        End If
    Next
    Return False
End Sub

B4X:
'Description: return all items in the listview as a list of maps
'Tag: listview, b4j, map, anchorpane
Sub ListViewGetItems(lstView As ListView) As List
    Dim lstTarget As List
    Dim ap As AnchorPane
    Dim title As Label
    Dim m As Map
    Dim l As List
    l.Initialize
    ' get all the items from the list
    lstTarget = lstView.items
    ' loop through each item
    For I = 0 To lstTarget.Size - 1
        ap = lstTarget.Get(I)
        title = ap.GetNode(0)
        m.Initialize
        m.Put("tag", title.tag)
        m.Put("text", title.Text)
        l.Add(m)
    Next
    Return l
End Sub

B4X:
'Description: return a tag and text of selected listview item as a map
'Tag: listview, map, tag, text
Sub ListViewGetSelected(lstView As ListView) As Map
    Dim m As Map
    m.Initialize
    Dim fsel As Int = lstView.SelectedIndex
    If fsel = -1 Then
        m.Put("tag", "")
        m.Put("text", "")
        m.Put("index","-1")
    Else
        ' get the selected item
        Dim ap As AnchorPane = lstView.SelectedItem
        Dim title As Label = ap.GetNode(0)
        m.Put("tag", title.tag)
        m.Put("text", title.Text)
        m.Put("index", fsel)
    End If
    Return m
End Sub
 
Last edited:

Mashiane

Expert
Licensed User
Longtime User
'Description: Save Base64 string to an image file
'Tag: base64, image, stringUtils
B4X:
'convert the base64 string to an image
private Sub Base64StringToImage(s As String) As Image
    Dim su As StringUtils
    Dim bytes() As Byte = su.DecodeBase64(s)
    Dim inp As InputStream
    inp.InitializeFromBytesArray(bytes, 0, bytes.Length)
    Dim bmp As Image
    bmp.Initialize2(inp)
    inp.Close
    Return bmp
End Sub

'save the image
public Sub Save(dataURL As String,imgDir As String, imgFile As String)
    Try
        'clean up the image first
        dataURL = dataURL.Replace("data:image/jpeg;base64,","")
        Dim img As Image = Base64StringToImage(dataURL)
        Dim outp As OutputStream = File.OpenOutput(imgDir, imgFile,False)
        img.WriteToStream(outp)
        outp.Close
    Catch
    End Try
End Sub
 

Mashiane

Expert
Licensed User
Longtime User
Automatic Type object creation from a delimited string.

Why: I wanted to create a type from a delimited string, kinda lazy to type

B4X:
'Description: Create a Type Object from a delimited string
'Tags: delimited string, type object
Sub MvStringToType(Delim As String, TypeName As String, EnumName As String, MvStr As String) As String
    MvStr = MvStr.Replace("'","")
    MvStr = MvStr.Replace(QUOTE,"")
    Dim sb As StringBuilder
    sb.initialize
    sb.Append("Type ").Append(TypeName).Append("(")
    Dim items() As String = StrParse(Delim,MvStr)
    For Each strItem As String In items
        strItem = strItem.Trim
        sb.Append(strItem).Append(" As String,")
    Next
    sb = RemDelimSB(",",sb)
    sb.Append(")").Append(CRLF)
    sb.Append("Public ").Append(EnumName).Append(" As ").Append(TypeName).Append(CRLF)
    sb.Append(EnumName).Append(".Initialize").Append(CRLF)
    For Each strItem As String In items
        strItem = strItem.Trim
        sb.Append(EnumName).Append(".").Append(strItem).Append(" = ")
        sb.Append(InQuotes(strItem)).append(CRLF)
    Next
    Return sb.tostring
End Sub

Usage..

B4X:
Dim sString As String = "moveToLeft_moveFromRight', 'moveToRight_moveFromLeft', 'moveToTop_moveFromBottom', 'moveToBottom_moveFromTop', 'fade_moveFromRight', 'fade_moveFromLeft', 'fade_moveFromBottom', 'fade_moveFromTop', 'moveToLeftFade_moveFromRightFade', 'moveToRightFade_moveFromLeftFade', 'moveToTopFade_moveFromBottomFade', 'moveToBottomFade_moveFromTopFade', 'moveToLeftEasing_moveFromRight', 'moveToRightEasing_moveFromLeft', 'moveToTopEasing_moveFromBottom', 'moveToBottomEasing_moveFromTop', 'scaleDown_moveFromRight', 'scaleDown_moveFromLeft', 'scaleDown_moveFromBottom', 'scaleDown_moveFromTop', 'scaleDown_scaleUpDown', 'scaleDownUp_scaleUp', 'moveToLeft_scaleUp', 'moveToRight_scaleUp', 'moveToTop_scaleUp', 'moveToBottom_scaleUp', 'scaleDownCenter_scaleUpCenter', 'rotateRightSideFirst_moveFromRight', 'rotateLeftSideFirst_moveFromLeft', 'rotateTopSideFirst_moveFromTop', 'rotateBottomSideFirst_moveFromBottom', 'flipOutRight_flipInLeft', 'flipOutLeft_flipInRight', 'flipOutTop_flipInBottom', 'flipOutBottom_flipInTop', 'rotateFall_scaleUp', 'rotateOutNewspaper_rotateInNewspaper', 'rotatePushLeft_moveFromRight', 'rotatePushRight_moveFromLeft', 'rotatePushTop_moveFromBottom', 'rotatePushBottom_moveFromTop', 'rotatePushLeft_rotatePullRight', 'rotatePushRight_rotatePullLeft', 'rotatePushTop_rotatePullBottom', 'rotatePushBottom_page', 'rotateFoldLeft_moveFromRightFade', 'rotateFoldRight_moveFromLeftFade', 'rotateFoldTop_moveFromBottomFade', 'rotateFoldBottom_moveFromTopFade', 'moveToRightFade_rotateUnfoldLeft', 'moveToLeftFade_rotateUnfoldRight', 'moveToBottomFade_rotateUnfoldTop', 'moveToTopFade_rotateUnfoldBottom', 'rotateRoomLeftOut_rotateRoomLeftIn', 'rotateRoomRightOut_rotateRoomRightIn', 'rotateRoomTopOut_rotateRoomTopIn', 'rotateRoomBottomOut_rotateRoomBottomIn', 'rotateCubeLeftOut_rotateCubeLeftIn', 'rotateCubeRightOut_rotateCubeRightIn', 'rotateCubeTopOut_rotateCubeTopIn', 'rotateCubeBottomOut_rotateCubeBottomIn', 'rotateCarouselLeftOut_rotateCarouselLeftIn', 'rotateCarouselRightOut_rotateCarouselRightIn', 'rotateCarouselTopOut_rotateCarouselTopIn', 'rotateCarouselBottomOut_rotateCarouselBottomIn', 'rotateSidesOut_rotateSidesInDelay', 'rotateSlideOut_rotateSlideIn', 'random'"
    Log(jMash.MvStringToType(",","TransitionObject","EnumTransition",sString))

Output (better to save to a file for very long types)

B4X:
Type TransitionObject(moveToLeft_moveFromRight As String,moveToRight_moveFromLeft As String,moveToTop_moveFromBottom As String,moveToBottom_moveFromTop As String,fade_moveFromRight As String,fade_moveFromLeft As String,fade_moveFromBottom As String,fade_moveFromTop As String,moveToLeftFade_moveFromRightFade As String,moveToRightFade_moveFromLeftFade As String,moveToTopFade_moveFromBottomFade As String,moveToBottomFade_moveFromTopFade As String,moveToLeftEasing_moveFromRight As String,moveToRightEasing_moveFromLeft As String,moveToTopEasing_moveFromBottom As String,moveToBottomEasing_moveFromTop As String,scaleDown_moveFromRight As String,scaleDown_moveFromLeft As String,scaleDown_moveFromBottom As String,scaleDown_moveFromTop As String,scaleDown_scaleUpDown As String,scaleDownUp_scaleUp As String,moveToLeft_scaleUp As String,moveToRight_scaleUp As String,moveToTop_scaleUp As String,moveToBottom_scaleUp As String,scaleDownCenter_scaleUpCenter As String,rotateRightSideFirst_moveFromRight...
Public EnumTransition As TransitionObject
EnumTransition.Initialize
EnumTransition.moveToLeft_moveFromRight = "moveToLeft_moveFromRight"
EnumTransition.moveToRight_moveFromLeft = "moveToRight_moveFromLeft"
EnumTransition.moveToTop_moveFromBottom = "moveToTop_moveFromBottom"
EnumTransition.moveToBottom_moveFromTop = "moveToBottom_moveFromTop"
EnumTransition.fade_moveFromRight = "fade_moveFromRight"
EnumTransition.fade_moveFromLeft = "fade_moveFromLeft"
EnumTransition.fade_moveFromBottom = "fade_moveFromBottom"
EnumTransition.fade_moveFromTop = "fade_moveFromTop"
EnumTransition.moveToLeftFade_moveFromRightFade = "moveToLeftFade_moveFromRightFade"
EnumTransition.moveToRightFade_moveFromLeftFade = "moveToRightFade_moveFromLeftFade"
EnumTransition.moveToTopFade_moveFromBottomFade = "moveToTopFade_moveFromBottomFade"
EnumTransition.moveToBottomFade_moveFromTopFade = "moveToBottomFade_moveFromTopFade"
EnumTransition.moveToLeftEasing_moveFromRight = "moveToLeftEasing_moveFromRight"
EnumTransition.moveToRightEasing_moveFromLeft = "moveToRightEasing_moveFromLeft"
EnumTransition.moveToTopEasing_moveFromBottom = "moveToTopEasing_moveFromBottom"
EnumTransition.moveToBottomEasing_moveFromTop = "moveToBottomEasing_moveFromTop"
EnumTransition.scaleDown_moveFromRight = "scaleDown_moveFromRight"
EnumTransition.scaleDown_moveFromLeft = "scaleDown_moveFromLeft"
EnumTransition.scaleDown_moveFromBottom = "scaleDown_moveFromBottom"
EnumTransition.scaleDown_moveFromTop = "scaleDown_moveFromTop"
EnumTransition.scaleDown_scaleUpDown = "scaleDown_scaleUpDown"
 

Mashiane

Expert
Licensed User
Longtime User
'Description: Get the column header position in a tableview TV is tableview
'Tag:Tableview, column header position
B4X:
'get the column position
Sub ColumnPos(colName As String) As Int
    Dim colCnt As Int
    colTot = TV.ColumnsCount - 1
    For colCnt = 0 To colTot
        Dim colName1 As String = TV.GetColumnHeader(colCnt)
        If colName.EqualsIgnoreCase(colName1) Then
            Return colCnt
        End If
    Next
    Return -1   
End Sub
 

Mashiane

Expert
Licensed User
Longtime User
'Description: Set the tableview header to an icon
'Tags: TableView, header icon

icons.png


Usage

B4X:
etvCRUD.TableViewSetColumnHeaderIcon("Update",0xF0C7)
        etvCRUD.TableViewSetColumnHeaderIcon("Search",0xF002)

B4X:
Sub TableViewSetColumnHeaderIcon(colName As String, colIcon As String)
    'find the column position in the tableview
    Dim idxPos As Int = ColumnPos(colName)
    If idxPos = -1 Then Return
    Dim btnAction As Button
    btnAction.Initialize("")
    btnAction.PrefWidth = "14"
    btnAction.PrefHeight = "14"
    btnAction.Enabled = True
    'btnAction.MouseCursor = fx.Cursors.HAND
    btnAction.Font = awesome
    btnAction.Text = Chr(colIcon)
    CSSUtils.SetBackgroundColor(btnAction, fx.Colors.Transparent)
    CSSUtils.SetBorder(btnAction,0,fx.colors.transparent,0)
    TableViewSetColumnGraphic(idxPos,btnAction)
End Sub

private Sub TableViewSetColumnGraphic(Index As Int, xNode As Node)
    Dim jo As JavaObject = TV
    Dim column As JavaObject = jo.RunMethodJO("getColumns", Null).RunMethod("get", Array(Index))
    column.RunMethod("setGraphic", Array(xNode))
End Sub
 
Last edited:

Mashiane

Expert
Licensed User
Longtime User
B4X:
'Description:get the table structure from the pragma statement
tag: table structure for CreateTable
Sub GetTableStructure(jSQL As SQL, tblName As String) As Map
    Dim fld As Map
    fld.Initialize
    Dim fields As List = DBUtils.ExecuteMaps(jSQL,"PRAGMA table_info ('" & tblName & "')",Null)
    For Each fldm As Map In fields
        Dim fldname As String = fldm.GetDefault("name","")
        Dim fldtype As String = fldm.GetDefault("type","")
        fld.put(fldname,fldtype)
    Next
    Return fld
End Sub

'Description: get the table primary key field name from the pragma statement
'tag: table, primary key
Sub GetTablePrimaryKey(jSQL As SQL, tblName As String) As String
    Dim fields As List = DBUtils.ExecuteMaps(jSQL,"PRAGMA table_info ('" & tblName & "')",Null)
    For Each fldm As Map In fields
        Dim fldname As String = fldm.GetDefault("name","")
        Dim fldpk As String = fldm.GetDefault("pk","")
        If fldpk = "1" Then Return fldname
    Next
    Return ""
End Sub

pragma.png
 

Mashiane

Expert
Licensed User
Longtime User
B4X:
'Description: Quickly clone a table with its data
'Tag: clone table
Sub CloneTable(jSQL As SQL, prevTable As String, newTable As String) As Boolean
    If jSQL.IsInitialized = False Then Return False
    jSQL.ExecNonQuery("PRAGMA foreign_keys=off;")
    Try
        jSQL.BeginTransaction
        jSQL.ExecNonQuery($"CREATE TABLE [${newTable}] AS SELECT * FROM [${prevTable}];"$)      
        jSQL.TransactionSuccessful
    Catch
        jSQL.Rollback
        Log("CloneTable: " & LastException)
    End Try
    jSQL.ExecNonQuery("PRAGMA foreign_keys=on;")
    'check if table exists
    Return TableExists(jSQL,newTable)
End Sub

NB: Whilst this does the job, it DOES NOT keep the primary key definition on the new table
 

Mashiane

Expert
Licensed User
Longtime User
B4X:
'Description: get indexes of the table using pragma for AddIndexes
'Tag: indexes
Sub GetTableIndexes(jSQL As SQL, tblName As String) As Map
    Dim fld As Map
    fld.initialize
    Dim fields As List = ExecuteMaps(jSQL, $"PRAGMA INDEX_LIST ('${tblName}')"$,Null)
    For Each fldm As Map In fields
        Dim fldname As String = fldm.GetDefault("name","")
        Dim unique As String = fldm.GetDefault("unique","")
        Dim bunique As Boolean = False
        If unique = "1" Then bunique = True
        'clean the name
        fldname = fldname.replace(tblName,"")
        fldname = fldname.replace(tblName.tolowercase,"")
        fldname = fldname.tolowercase
        fld.put(fldname,bunique)
    Next
    Return fld
End Sub

B4X:
'Description: Clone a table maintaining its primary key and field types [STRUCTURE ONLY]
'Tag: clone a table, primary key
Sub CloneTable(jSQL As SQL, prevTable As String, newTable As String) As Boolean
    'get the structure of the table
    Dim flds As Map = GetTableStructure(jSQL,prevTable)
    'get the primary key
    Dim pkey As String = GetTablePrimaryKey(jSQL,prevTable)
    'get the indexes of the table
    Dim idxs As Map = GetTableIndexes(jSQL,prevTable)
   
    CreateTable(jSQL,newTable,flds,pkey,pkey)
    'add the indexes
    AddIndexes(jSQL,newTable,idxs)
    Return TableExists(jSQL,newTable)
End Sub

Sub AddIndexes(jSQL As SQL,TableName As String, FieldsAndTypes As Map)
    IsDone = False
    jSQL.ExecNonQuery("PRAGMA foreign_keys=off;")
    Try
        jSQL.begintransaction
        FieldsAndTypes = DeDuplicateMap(FieldsAndTypes)
        Dim i As Int
        For i = 0 To FieldsAndTypes.Size - 1
            Dim sb As StringBuilder
            Dim field As String
            Dim unique As Boolean
            field = FieldsAndTypes.GetKeyAt(i)
            unique = FieldsAndTypes.GetValueAt(i)
            If field.Length > 0 Then
                sb.Initialize
                sb.Append("CREATE ")
                If unique = True Then sb.Append("UNIQUE ")
                sb.Append("INDEX IF NOT EXISTS [").Append(TableName).Append(field).Append("]")
                sb.Append(" ON [").Append(TableName).Append("] ([").Append(field).Append("])")
                jSQL.ExecNonQuery(sb.tostring)
            End If
        Next
        jSQL.TransactionSuccessful
        IsDone = True       
    Catch
        jSQL.Rollback
        Log("AddIndexes: " & LastException)
        IsDone = False
    End Try
    jSQL.ExecNonQuery("PRAGMA foreign_keys=on;")
End Sub
 

Mashiane

Expert
Licensed User
Longtime User
Based on the methods in post $47 and #46, the sub to remove a column can be..

B4X:
'Description: Remove a column from sqlite table keeping the primary key and table structure
'Tag: remove a column from a table
Sub RemoveColumn(jsql As SQL, TableName As String, FldName As String) As Boolean
    'get the structure of the table
    Dim flds As Map = GetTableStructure(jsql,TableName)
    'get the primary key
    Dim pkey As String = GetTablePrimaryKey(jsql,TableName)
    'get the indexes of the table
    Dim idxs As Map = GetTableIndexes(jsql,TableName)
      
    'remove the fldname to be deleted
    flds.Remove(FldName)
    flds.Remove(FldName.ToLowerCase)
    'remove the indexes
    idxs.Remove(FldName)
    idxs.Remove(FldName.ToLowerCase)
    'create a new table with the updated fields
    CreateTable(jsql,TableName & "_old",flds,pkey,pkey)
    'add the indexes
    AddIndexes(jsql,TableName & "_old",idxs)
    'get the new field names created
    Dim newFlds As StringBuilder
    newFlds.Initialize
    For Each strFld As String In flds.Keys
        newFlds.Append("[").Append(strFld).Append("],")
    Next
    newFlds = jMash.RemDelimSB(",",newFlds)
    'copy the data from original to old table
    jsql.ExecNonQuery("PRAGMA foreign_keys=off;")
    jsql.BeginTransaction
    Try
        'copy records to new table from original table
        jsql.ExecNonQuery("INSERT INTO [" & TableName & "_old] (" & newFlds & ") SELECT " & newFlds & " FROM [" & TableName & "]")
        ' drop the original table
        jsql.ExecNonQuery("DROP TABLE [" & TableName & "]")
        'rename the old to new table
        jsql.ExecNonQuery("ALTER TABLE [" & TableName & "_old] RENAME TO [" & TableName & "]")
        jsql.TransactionSuccessful
    Catch
        jsql.Rollback
        Log("RemoveColumn: " & LastException)
    End Try   
    jsql.ExecNonQuery("PRAGMA foreign_keys=on;")
    'does the column exists
    Return Not(ColumnExists(jsql,TableName,FldName))
End Sub
 

Mashiane

Expert
Licensed User
Longtime User
'Description: Get a tables indexes and column names using PRAGMA statements
'Tag: sqlite, table index, columns
B4X:
'get indexes of the table
Sub GetTableIndexesWithColumns(jSQL As SQL, tblName As String) As Map
    Dim fld As Map
    fld.initialize
    Dim fields As List = ExecuteMaps(jSQL, $"PRAGMA INDEX_LIST ('${tblName}')"$,Null)
    For Each fldm As Map In fields
        Dim fldname As String = fldm.GetDefault("name","")
        Dim unique As String = fldm.GetDefault("unique","")
        Dim bunique As Boolean = False
        If unique = "1" Then bunique = True
        'go deeper and get the column names for this index
        Dim idxcols As List = ExecuteMaps(jSQL,$"PRAGMA index_info('${fldname}');"$,Null)
        Dim idxcolNames As List
        idxcolNames.Initialize
        For Each idxm As Map In idxcols
            Dim idxcolName As String = idxm.GetDefault("name","")
            idxcolNames.Add(idxcolName)
        Next
        Dim nidx As Map = CreateMap("unique":bunique,"columns":idxcolNames)
        fld.Put(fldname,nidx)
    Next
    Return fld
End Sub
 

icefairy333

Active Member
Licensed User
Longtime User
Automatic Type object creation from a delimited string.

Why: I wanted to create a type from a delimited string, kinda lazy to type

B4X:
'Description: Create a Type Object from a delimited string
'Tags: delimited string, type object
Sub MvStringToType(Delim As String, TypeName As String, EnumName As String, MvStr As String) As String
    MvStr = MvStr.Replace("'","")
    MvStr = MvStr.Replace(QUOTE,"")
    Dim sb As StringBuilder
    sb.initialize
    sb.Append("Type ").Append(TypeName).Append("(")
    Dim items() As String = StrParse(Delim,MvStr)
    For Each strItem As String In items
        strItem = strItem.Trim
        sb.Append(strItem).Append(" As String,")
    Next
    sb = RemDelimSB(",",sb)
    sb.Append(")").Append(CRLF)
    sb.Append("Public ").Append(EnumName).Append(" As ").Append(TypeName).Append(CRLF)
    sb.Append(EnumName).Append(".Initialize").Append(CRLF)
    For Each strItem As String In items
        strItem = strItem.Trim
        sb.Append(EnumName).Append(".").Append(strItem).Append(" = ")
        sb.Append(InQuotes(strItem)).append(CRLF)
    Next
    Return sb.tostring
End Sub

Usage..

B4X:
Dim sString As String = "moveToLeft_moveFromRight', 'moveToRight_moveFromLeft', 'moveToTop_moveFromBottom', 'moveToBottom_moveFromTop', 'fade_moveFromRight', 'fade_moveFromLeft', 'fade_moveFromBottom', 'fade_moveFromTop', 'moveToLeftFade_moveFromRightFade', 'moveToRightFade_moveFromLeftFade', 'moveToTopFade_moveFromBottomFade', 'moveToBottomFade_moveFromTopFade', 'moveToLeftEasing_moveFromRight', 'moveToRightEasing_moveFromLeft', 'moveToTopEasing_moveFromBottom', 'moveToBottomEasing_moveFromTop', 'scaleDown_moveFromRight', 'scaleDown_moveFromLeft', 'scaleDown_moveFromBottom', 'scaleDown_moveFromTop', 'scaleDown_scaleUpDown', 'scaleDownUp_scaleUp', 'moveToLeft_scaleUp', 'moveToRight_scaleUp', 'moveToTop_scaleUp', 'moveToBottom_scaleUp', 'scaleDownCenter_scaleUpCenter', 'rotateRightSideFirst_moveFromRight', 'rotateLeftSideFirst_moveFromLeft', 'rotateTopSideFirst_moveFromTop', 'rotateBottomSideFirst_moveFromBottom', 'flipOutRight_flipInLeft', 'flipOutLeft_flipInRight', 'flipOutTop_flipInBottom', 'flipOutBottom_flipInTop', 'rotateFall_scaleUp', 'rotateOutNewspaper_rotateInNewspaper', 'rotatePushLeft_moveFromRight', 'rotatePushRight_moveFromLeft', 'rotatePushTop_moveFromBottom', 'rotatePushBottom_moveFromTop', 'rotatePushLeft_rotatePullRight', 'rotatePushRight_rotatePullLeft', 'rotatePushTop_rotatePullBottom', 'rotatePushBottom_page', 'rotateFoldLeft_moveFromRightFade', 'rotateFoldRight_moveFromLeftFade', 'rotateFoldTop_moveFromBottomFade', 'rotateFoldBottom_moveFromTopFade', 'moveToRightFade_rotateUnfoldLeft', 'moveToLeftFade_rotateUnfoldRight', 'moveToBottomFade_rotateUnfoldTop', 'moveToTopFade_rotateUnfoldBottom', 'rotateRoomLeftOut_rotateRoomLeftIn', 'rotateRoomRightOut_rotateRoomRightIn', 'rotateRoomTopOut_rotateRoomTopIn', 'rotateRoomBottomOut_rotateRoomBottomIn', 'rotateCubeLeftOut_rotateCubeLeftIn', 'rotateCubeRightOut_rotateCubeRightIn', 'rotateCubeTopOut_rotateCubeTopIn', 'rotateCubeBottomOut_rotateCubeBottomIn', 'rotateCarouselLeftOut_rotateCarouselLeftIn', 'rotateCarouselRightOut_rotateCarouselRightIn', 'rotateCarouselTopOut_rotateCarouselTopIn', 'rotateCarouselBottomOut_rotateCarouselBottomIn', 'rotateSidesOut_rotateSidesInDelay', 'rotateSlideOut_rotateSlideIn', 'random'"
    Log(jMash.MvStringToType(",","TransitionObject","EnumTransition",sString))

Output (better to save to a file for very long types)

B4X:
Type TransitionObject(moveToLeft_moveFromRight As String,moveToRight_moveFromLeft As String,moveToTop_moveFromBottom As String,moveToBottom_moveFromTop As String,fade_moveFromRight As String,fade_moveFromLeft As String,fade_moveFromBottom As String,fade_moveFromTop As String,moveToLeftFade_moveFromRightFade As String,moveToRightFade_moveFromLeftFade As String,moveToTopFade_moveFromBottomFade As String,moveToBottomFade_moveFromTopFade As String,moveToLeftEasing_moveFromRight As String,moveToRightEasing_moveFromLeft As String,moveToTopEasing_moveFromBottom As String,moveToBottomEasing_moveFromTop As String,scaleDown_moveFromRight As String,scaleDown_moveFromLeft As String,scaleDown_moveFromBottom As String,scaleDown_moveFromTop As String,scaleDown_scaleUpDown As String,scaleDownUp_scaleUp As String,moveToLeft_scaleUp As String,moveToRight_scaleUp As String,moveToTop_scaleUp As String,moveToBottom_scaleUp As String,scaleDownCenter_scaleUpCenter As String,rotateRightSideFirst_moveFromRight...
Public EnumTransition As TransitionObject
EnumTransition.Initialize
EnumTransition.moveToLeft_moveFromRight = "moveToLeft_moveFromRight"
EnumTransition.moveToRight_moveFromLeft = "moveToRight_moveFromLeft"
EnumTransition.moveToTop_moveFromBottom = "moveToTop_moveFromBottom"
EnumTransition.moveToBottom_moveFromTop = "moveToBottom_moveFromTop"
EnumTransition.fade_moveFromRight = "fade_moveFromRight"
EnumTransition.fade_moveFromLeft = "fade_moveFromLeft"
EnumTransition.fade_moveFromBottom = "fade_moveFromBottom"
EnumTransition.fade_moveFromTop = "fade_moveFromTop"
EnumTransition.moveToLeftFade_moveFromRightFade = "moveToLeftFade_moveFromRightFade"
EnumTransition.moveToRightFade_moveFromLeftFade = "moveToRightFade_moveFromLeftFade"
EnumTransition.moveToTopFade_moveFromBottomFade = "moveToTopFade_moveFromBottomFade"
EnumTransition.moveToBottomFade_moveFromTopFade = "moveToBottomFade_moveFromTopFade"
EnumTransition.moveToLeftEasing_moveFromRight = "moveToLeftEasing_moveFromRight"
EnumTransition.moveToRightEasing_moveFromLeft = "moveToRightEasing_moveFromLeft"
EnumTransition.moveToTopEasing_moveFromBottom = "moveToTopEasing_moveFromBottom"
EnumTransition.moveToBottomEasing_moveFromTop = "moveToBottomEasing_moveFromTop"
EnumTransition.scaleDown_moveFromRight = "scaleDown_moveFromRight"
EnumTransition.scaleDown_moveFromLeft = "scaleDown_moveFromLeft"
EnumTransition.scaleDown_moveFromBottom = "scaleDown_moveFromBottom"
EnumTransition.scaleDown_moveFromTop = "scaleDown_moveFromTop"
EnumTransition.scaleDown_scaleUpDown = "scaleDown_scaleUpDown"

B4X:
Public Sub genTypeByMap(m As Map,typName As String)
    If m=Null Or m.IsInitialized=False Then Return
    typName=typName&"Model"
    Dim sbType As StringBuilder
    sbType.Initialize
    sbType.Append($"Type ${typName}("$)
    For Each k As String In m.Keys
        Dim obj As Object=m.Get(k)
        If obj<>Null Then
            Dim objType As String=GetType(obj)
            objType=objType.SubString(objType.LastIndexOf(".")+1).ToLowerCase
            Select objType
                Case "integer"
                    sbType.Append(k).Append(" As Int,")
                Case "double"
                    sbType.Append(k).Append(" As Double,")
                Case "long"
                    sbType.Append(k).Append(" As Long,")
                Case "boolean"
                    sbType.Append(k).Append(" As Boolean,")
                Case "string"
                    sbType.Append(k).Append(" As String,")
                Case Else
                    sbType.Append(k).Append(" As Object,")
            End Select
        Else
            sbType.Append(k).Append(" As Object,")
        End If
    Next
    sbType.Remove(sbType.Length-1,sbType.Length)
    sbType.Append(")")
End Sub
 

Mashiane

Expert
Licensed User
Longtime User
'Description: UpdateMaps is like InsertMaps in DButils but for running updates
'you pass it a list of maps, each map has "qry" and an "args" where qry is the query to execute and args is a list of values
'Tags: SQLite, UpdateMaps
B4X:
Public Sub UpdateMaps(jSQL As SQL, TableName As String, ListOfMaps As List) As Boolean
    'Small check for a common error where the same map is used in a loop
    If ListOfMaps.Size > 1 And ListOfMaps.Get(0) = ListOfMaps.Get(1) Then
        Log("Same Map found twice in list. Each item in the list should include a different map object.")
        Return False
    End If
    jSQL.BeginTransaction
    Try
        For i1 = 0 To ListOfMaps.Size - 1
            Dim qrymap As Map = ListOfMaps.Get(i1)
            If qrymap.IsInitialized Then
                Dim qry As String = qrymap.Get("qry")
                Dim args As List = qrymap.Get("args")
                jSQL.ExecNonQuery2(qry,  args)
            End If
        Next
        jSQL.TransactionSuccessful
        Return True
    Catch
        Log("UpdateMaps: " & LastException)
        jSQL.Rollback
        Return False
    End Try
End Sub
 

Mashiane

Expert
Licensed User
Longtime User
'Description: Useful with UpdateMaps to create a Map for each record to be updated.
'Tags: SQLite, UpdateMaps, you can then add each map to the list to use with UpdateMaps
'Usage: Dim upmap As Map = DBUtils.UpdateRecordMap("Fields",CreateMap("underscore":iunderscore),CreateMap("id":fid))

B4X:
Public Sub UpdateRecordMap(TableName As String, Fields As Map, WhereFieldEquals As Map) As Map
    Dim out As Map
    If WhereFieldEquals.Size = 0 Then
        Log("WhereFieldEquals map empty!")
        Return out
    End If
    If Fields.Size = 0 Then
        Log("Fields empty")
        Return out
    End If
    Fields = DeDuplicateMap(Fields)
    WhereFieldEquals = DeDuplicateMap(WhereFieldEquals)
    Dim sb As StringBuilder
    Try
        sb.Initialize
        sb.Append("UPDATE ").Append(EscapeField(TableName)).Append(" SET ")
        Dim args As List
        args.Initialize
        For i=0 To Fields.Size-1
            If i<>Fields.Size-1 Then
                sb.Append(EscapeField(Fields.GetKeyAt(i))).Append("=?,")
            Else
                sb.Append(EscapeField(Fields.GetKeyAt(i))).Append("=?")
            End If
            args.Add(Fields.GetValueAt(i))
        Next
    
        sb.Append(" WHERE ")
        For i = 0 To WhereFieldEquals.Size - 1
            If i > 0 Then
                sb.Append(" AND ")
            End If
            Dim skey As String = WhereFieldEquals.GetKeyAt(i)
            skey = $"lower(${skey})"$
            sb.Append(skey).Append(" = ?")
            Dim svalue As String = WhereFieldEquals.GetValueAt(i)
            svalue = svalue.ToLowerCase
            args.Add(svalue)
        Next
        out = CreateMap("qry":sb.tostring,"args":args)
        Return out
    Catch
        Return out
    End Try
End Sub
 

Mashiane

Expert
Licensed User
Longtime User
'Description: Get time lapsed from a DateTime String
'tags: TimeAgo
'usage: dim ta as string = TimeAgo("2018-04-25 14:00:00")
B4X:
Sub TimeAgo(dt As String) As String
    If dt.IndexOf(" ") = -1 Then Return ""
    Dim diff As Period
    diff.Initialize
    DateTime.DateFormat="yyyy-MM-dd"
    DateTime.TimeFormat="HH:mm:ss"
    Dim mtime() As String = Regex.split(" ", dt)
    Dim dd As String = mtime(0)
    Dim tt As String = mtime(1)
    Dim pd As Long = DateTime.DateTimeParse(dd,tt)
    diff = DateUtils.PeriodBetween(pd,DateTime.now)
    Dim ta As String
    If diff.Years <> 0 Then
        ta = $"${diff.years} year(s) ago"$
        Return ta
    End If
    If diff.Months <> 0 Then
        ta = $"${diff.months} month(s) ago"$
        Return ta
    End If
    If diff.Days <> 0 Then
        ta = $"${diff.days} day(s) ago"$
        Return ta
    End If
    If diff.Hours <> 0 Then
        ta = $"${diff.hours} hour(s) ago"$
        Return ta
    End If
    If diff.Minutes <> 0 Then
        ta = $"${diff.minutes} minute(s) ago"$
        Return ta
    End If
    If diff.Seconds <> 0 Then
        ta = $"${diff.seconds} second(s) ago"$
        Return ta
    End If
End Sub
 

Mashiane

Expert
Licensed User
Longtime User
HTML Color Constants

B4X:
Public Const COLOR_LIGHTSLATEGREY As String = "#778899"
    Public Const COLOR_DARKVIOLET As String = "#9400D3"
    Public Const COLOR_CYAN As String = "#00FFFF"
    Public Const COLOR_DARKSLATEBLUE As String = "#483D8B"
    Public Const COLOR_BISQUE As String = "#FFE4C4"
    Public Const COLOR_LIGHTGREY As String = "#D3D3D3"
    Public Const COLOR_KHAKI As String = "#F0E68C"
    Public Const COLOR_DARKGRAY As String = "#A9A9A9"
    Public Const COLOR_SADDLEBROWN As String = "#8B4513"
    Public Const COLOR_BLANCHEDALMOND As String = "#FFEBCD"
    Public Const COLOR_DARKBLUE As String = "#00008B"
    Public Const COLOR_LIGHTCORAL As String = "#F08080"
    Public Const COLOR_ORANGERED As String = "#FF4500"
    Public Const COLOR_MOCCASIN As String = "#FFE4B5"
    Public Const COLOR_AZURE As String = "#F0FFFF"
    Public Const COLOR_LIGHTGOLDENRODYELLOW As String = "#FAFAD2"
    Public Const COLOR_SKYBLUE As String = "#87CEEB"
    Public Const COLOR_DEEPSKYBLUE As String = "#00BFFF"
    Public Const COLOR_CHARTREUSE As String = "#7FFF00"
    Public Const COLOR_MEDIUMPURPLE As String = "#9370DB"
    Public Const COLOR_LIGHTYELLOW As String = "#FFFFE0"
    Public Const COLOR_VIOLET As String = "#EE82EE"
    Public Const COLOR_PALEVIOLETRED As String = "#DB7093"
    Public Const COLOR_DIMGREY As String = "#696969"
    Public Const COLOR_ROSYBROWN As String = "#BC8F8F"
    Public Const COLOR_HONEYDEW As String = "#F0FFF0"
    Public Const COLOR_MEDIUMBLUE As String = "#0000CD"
    Public Const COLOR_DARKSEAGREEN As String = "#8FBC8F"
    Public Const COLOR_LIMEGREEN As String = "#32CD32"
    Public Const COLOR_PALETURQUOISE As String = "#AFEEEE"
    Public Const COLOR_MEDIUMORCHID As String = "#BA55D3"
    Public Const COLOR_BURLYWOOD As String = "#DEB887"
    Public Const COLOR_SILVER As String = "#C0C0C0"
    Public Const COLOR_PAPAYAWHIP As String = "#FFEFD5"
    Public Const COLOR_CHOCOLATE As String = "#D2691E"
    Public Const COLOR_LIGHTSTEELBLUE As String = "#B0C4DE"
    Public Const COLOR_PINK As String = "#FFC0CB"
    Public Const COLOR_DARKGREEN As String = "#006400"
    Public Const COLOR_SIENNA As String = "#A0522D"
    Public Const COLOR_SEASHELL As String = "#FFF5EE"
    Public Const COLOR_THISTLE As String = "#D8BFD8"
    Public Const COLOR_YELLOW As String = "#FFFF00"
    Public Const COLOR_LIGHTSEAGREEN As String = "#20B2AA"
    Public Const COLOR_CORNSILK As String = "#FFF8DC"
    Public Const COLOR_BLUEVIOLET As String = "#8A2BE2"
    Public Const COLOR_TOMATO As String = "#FF6347"
    Public Const COLOR_CORNFLOWERBLUE As String = "#6495ED"
    Public Const COLOR_SANDYBROWN As String = "#F4A460"
    Public Const COLOR_GOLD As String = "#FFD700"
    Public Const COLOR_SPRINGGREEN As String = "#00FF7F"
    Public Const COLOR_GRAY As String = "#808080"
    Public Const COLOR_SLATEGREY As String = "#708090"
    Public Const COLOR_MEDIUMVIOLETRED As String = "#C71585"
    Public Const COLOR_CRIMSON As String = "#DC143C"
    Public Const COLOR_DARKCYAN As String = "#008B8B"
    Public Const COLOR_IVORY As String = "#FFFFF0"
    Public Const COLOR_DARKMAGENTA As String = "#8B008B"
    Public Const COLOR_WHEAT As String = "#F5DEB3"
    Public Const COLOR_INDIANRED As String = "#CD5C5C"
    Public Const COLOR_DARKORCHID As String = "#9932CC"
    Public Const COLOR_WHITESMOKE As String = "#F5F5F5"
    Public Const COLOR_MINTCREAM As String = "#F5FFFA"
    Public Const COLOR_LIGHTPINK As String = "#FFB6C1"
    Public Const COLOR_BLACK As String = "#000000"
    Public Const COLOR_TEAL As String = "#008080"
    Public Const COLOR_CADETBLUE As String = "#5F9EA0"
    Public Const COLOR_BEIGE As String = "#F5F5DC"
    Public Const COLOR_DARKKHAKI As String = "#BDB76B"
    Public Const COLOR_BLUE As String = "#0000FF"
    Public Const COLOR_DARKSLATEGRAY As String = "#2F4F4F"
    Public Const COLOR_ROYALBLUE As String = "#4169E1"
    Public Const COLOR_SEAGREEN As String = "#2E8B57"
    Public Const COLOR_PURPLE As String = "#800080"
    Public Const COLOR_ORCHID As String = "#DA70D6"
    Public Const COLOR_FORESTGREEN As String = "#228B22"
    Public Const COLOR_DARKSALMON As String = "#E9967A"
    Public Const COLOR_PALEGREEN As String = "#98FB98"
    Public Const COLOR_NAVY As String = "#000080"
    Public Const COLOR_LIGHTSLATEGRAY As String = "#778899"
    Public Const COLOR_REBECCAPURPLE As String = "#663399"
    Public Const COLOR_GREENYELLOW As String = "#ADFF2F"
    Public Const COLOR_RED As String = "#FF0000"
    Public Const COLOR_AQUA As String = "#00FFFF"
    Public Const COLOR_WHITE As String = "#FFFFFF"
    Public Const COLOR_DODGERBLUE As String = "#1E90FF"
    Public Const COLOR_LIGHTBLUE As String = "#ADD8E6"
    Public Const COLOR_OLIVE As String = "#808000"
    Public Const COLOR_CORAL As String = "#FF7F50"
    Public Const COLOR_PEACHPUFF As String = "#FFDAB9"
    Public Const COLOR_DARKOLIVEGREEN As String = "#556B2F"
    Public Const COLOR_DARKTURQUOISE As String = "#00CED1"
    Public Const COLOR_DARKGREY As String = "#A9A9A9"
    Public Const COLOR_LAVENDER As String = "#E6E6FA"
    Public Const COLOR_LIGHTGRAY As String = "#D3D3D3"
    Public Const COLOR_GAINSBORO As String = "#DCDCDC"
    Public Const COLOR_TAN As String = "#D2B48C"
    Public Const COLOR_PLUM As String = "#DDA0DD"
    Public Const COLOR_MIDNIGHTBLUE As String = "#191970"
    Public Const COLOR_POWDERBLUE As String = "#B0E0E6"
    Public Const COLOR_DIMGRAY As String = "#696969"
    Public Const COLOR_LEMONCHIFFON As String = "#FFFACD"
    Public Const COLOR_SALMON As String = "#FA8072"
    Public Const COLOR_LIGHTGREEN As String = "#90EE90"
    Public Const COLOR_BROWN As String = "#A52A2A"
    Public Const COLOR_GOLDENROD As String = "#DAA520"
    Public Const COLOR_STEELBLUE As String = "#4682B4"
    Public Const COLOR_LIGHTSALMON As String = "#FFA07A"
    Public Const COLOR_DARKRED As String = "#8B0000"
    Public Const COLOR_SNOW As String = "#FFFAFA"
    Public Const COLOR_OLIVEDRAB As String = "#6B8E23"
    Public Const COLOR_YELLOWGREEN As String = "#9ACD32"
    Public Const COLOR_INDIGO As String = "#4B0082"
    Public Const COLOR_LAWNGREEN As String = "#7CFC00"
    Public Const COLOR_MAGENTA As String = "#FF00FF"
    Public Const COLOR_AQUAMARINE As String = "#7FFFD4"
    Public Const COLOR_FLORALWHITE As String = "#FFFAF0"
    Public Const COLOR_ANTIQUEWHITE As String = "#FAEBD7"
    Public Const COLOR_HOTPINK As String = "#FF69B4"
    Public Const COLOR_TURQUOISE As String = "#40E0D0"
    Public Const COLOR_PERU As String = "#CD853F"
    Public Const COLOR_FUCHSIA As String = "#FF00FF"
    Public Const COLOR_FIREBRICK As String = "#B22222"
    Public Const COLOR_ALICEBLUE As String = "#F0F8FF"
    Public Const COLOR_DARKGOLDENROD As String = "#B8860B"
    Public Const COLOR_NAVAJOWHITE As String = "#FFDEAD"
    Public Const COLOR_LAVENDERBLUSH As String = "#FFF0F5"
    Public Const COLOR_MEDIUMSPRINGGREEN As String = "#00FA9A"
    Public Const COLOR_SLATEGRAY As String = "#708090"
    Public Const COLOR_MISTYROSE As String = "#FFE4E1"
    Public Const COLOR_LINEN As String = "#FAF0E6"
    Public Const COLOR_DARKORANGE As String = "#FF8C00"
    Public Const COLOR_SLATEBLUE As String = "#6A5ACD"
    Public Const COLOR_LIGHTCYAN As String = "#E0FFFF"
    Public Const COLOR_LIGHTSKYBLUE As String = "#87CEFA"
    Public Const COLOR_MEDIUMSEAGREEN As String = "#3CB371"
    Public Const COLOR_MEDIUMTURQUOISE As String = "#48D1CC"
    Public Const COLOR_DEEPPINK As String = "#FF1493"
    Public Const COLOR_GHOSTWHITE As String = "#F8F8FF"
    Public Const COLOR_GREEN As String = "#008000"
    Public Const COLOR_LIME As String = "#00FF00"
    Public Const COLOR_MEDIUMAQUAMARINE As String = "#66CDAA"
    Public Const COLOR_OLDLACE As String = "#FDF5E6"
    Public Const COLOR_GREY As String = "#808080"
    Public Const COLOR_ORANGE As String = "#FFA500"
    Public Const COLOR_DARKSLATEGREY As String = "#2F4F4F"
    Public Const COLOR_MEDIUMSLATEBLUE As String = "#7B68EE"
    Public Const COLOR_MAROON As String = "#800000"
    Public Const COLOR_PALEGOLDENROD As String = "#EEE8AA"

You can define a list too and then use .Get..

B4X:
Colors.Initialize
    Colors.add(COLOR_LIGHTSLATEGREY)
    Colors.add(COLOR_DARKVIOLET)
    Colors.add(COLOR_CYAN)
    Colors.add(COLOR_DARKSLATEBLUE)
    Colors.add(COLOR_BISQUE)
    Colors.add(COLOR_LIGHTGREY)
    Colors.add(COLOR_KHAKI)
    Colors.add(COLOR_DARKGRAY)
    Colors.add(COLOR_SADDLEBROWN)
    Colors.add(COLOR_BLANCHEDALMOND)
    Colors.add(COLOR_DARKBLUE)
    Colors.add(COLOR_LIGHTCORAL)
    Colors.add(COLOR_ORANGERED)
    Colors.add(COLOR_MOCCASIN)
    Colors.add(COLOR_AZURE)
    Colors.add(COLOR_LIGHTGOLDENRODYELLOW)
    Colors.add(COLOR_SKYBLUE)
    Colors.add(COLOR_DEEPSKYBLUE)
    Colors.add(COLOR_CHARTREUSE)
    Colors.add(COLOR_MEDIUMPURPLE)
    Colors.add(COLOR_LIGHTYELLOW)
    Colors.add(COLOR_VIOLET)
    Colors.add(COLOR_PALEVIOLETRED)
    Colors.add(COLOR_DIMGREY)
    Colors.add(COLOR_ROSYBROWN)
    Colors.add(COLOR_HONEYDEW)
    Colors.add(COLOR_MEDIUMBLUE)
    Colors.add(COLOR_DARKSEAGREEN)
    Colors.add(COLOR_LIMEGREEN)
    Colors.add(COLOR_PALETURQUOISE)
    Colors.add(COLOR_MEDIUMORCHID)
    Colors.add(COLOR_BURLYWOOD)
    Colors.add(COLOR_SILVER)
    Colors.add(COLOR_PAPAYAWHIP)
    Colors.add(COLOR_CHOCOLATE)
    Colors.add(COLOR_LIGHTSTEELBLUE)
    Colors.add(COLOR_PINK)
    Colors.add(COLOR_DARKGREEN)
    Colors.add(COLOR_SIENNA)
    Colors.add(COLOR_SEASHELL)
    Colors.add(COLOR_THISTLE)
    Colors.add(COLOR_YELLOW)
    Colors.add(COLOR_LIGHTSEAGREEN)
    Colors.add(COLOR_CORNSILK)
    Colors.add(COLOR_BLUEVIOLET)
    Colors.add(COLOR_TOMATO)
    Colors.add(COLOR_CORNFLOWERBLUE)
    Colors.add(COLOR_SANDYBROWN)
    Colors.add(COLOR_GOLD)
    Colors.add(COLOR_SPRINGGREEN)
    Colors.add(COLOR_GRAY)
    Colors.add(COLOR_SLATEGREY)
    Colors.add(COLOR_MEDIUMVIOLETRED)
    Colors.add(COLOR_CRIMSON)
    Colors.add(COLOR_DARKCYAN)
    Colors.add(COLOR_IVORY)
    Colors.add(COLOR_DARKMAGENTA)
    Colors.add(COLOR_WHEAT)
    Colors.add(COLOR_INDIANRED)
    Colors.add(COLOR_DARKORCHID)
    Colors.add(COLOR_WHITESMOKE)
    Colors.add(COLOR_MINTCREAM)
    Colors.add(COLOR_LIGHTPINK)
    Colors.add(COLOR_BLACK)
    Colors.add(COLOR_TEAL)
    Colors.add(COLOR_CADETBLUE)
    Colors.add(COLOR_BEIGE)
    Colors.add(COLOR_DARKKHAKI)
    Colors.add(COLOR_BLUE)
    Colors.add(COLOR_DARKSLATEGRAY)
    Colors.add(COLOR_ROYALBLUE)
    Colors.add(COLOR_SEAGREEN)
    Colors.add(COLOR_PURPLE)
    Colors.add(COLOR_ORCHID)
    Colors.add(COLOR_FORESTGREEN)
    Colors.add(COLOR_DARKSALMON)
    Colors.add(COLOR_PALEGREEN)
    Colors.add(COLOR_NAVY)
    Colors.add(COLOR_LIGHTSLATEGRAY)
    Colors.add(COLOR_REBECCAPURPLE)
    Colors.add(COLOR_GREENYELLOW)
    Colors.add(COLOR_RED)
    Colors.add(COLOR_AQUA)
    Colors.add(COLOR_WHITE)
    Colors.add(COLOR_DODGERBLUE)
    Colors.add(COLOR_LIGHTBLUE)
    Colors.add(COLOR_OLIVE)
    Colors.add(COLOR_CORAL)
    Colors.add(COLOR_PEACHPUFF)
    Colors.add(COLOR_DARKOLIVEGREEN)
    Colors.add(COLOR_DARKTURQUOISE)
    Colors.add(COLOR_DARKGREY)
    Colors.add(COLOR_LAVENDER)
    Colors.add(COLOR_LIGHTGRAY)
    Colors.add(COLOR_GAINSBORO)
    Colors.add(COLOR_TAN)
    Colors.add(COLOR_PLUM)
    Colors.add(COLOR_MIDNIGHTBLUE)
    Colors.add(COLOR_POWDERBLUE)
    Colors.add(COLOR_DIMGRAY)
    Colors.add(COLOR_LEMONCHIFFON)
    Colors.add(COLOR_SALMON)
    Colors.add(COLOR_LIGHTGREEN)
    Colors.add(COLOR_BROWN)
    Colors.add(COLOR_GOLDENROD)
    Colors.add(COLOR_STEELBLUE)
    Colors.add(COLOR_LIGHTSALMON)
    Colors.add(COLOR_DARKRED)
    Colors.add(COLOR_SNOW)
    Colors.add(COLOR_OLIVEDRAB)
    Colors.add(COLOR_YELLOWGREEN)
    Colors.add(COLOR_INDIGO)
    Colors.add(COLOR_LAWNGREEN)
    Colors.add(COLOR_MAGENTA)
    Colors.add(COLOR_AQUAMARINE)
    Colors.add(COLOR_FLORALWHITE)
    Colors.add(COLOR_ANTIQUEWHITE)
    Colors.add(COLOR_HOTPINK)
    Colors.add(COLOR_TURQUOISE)
    Colors.add(COLOR_PERU)
    Colors.add(COLOR_FUCHSIA)
    Colors.add(COLOR_FIREBRICK)
    Colors.add(COLOR_ALICEBLUE)
    Colors.add(COLOR_DARKGOLDENROD)
    Colors.add(COLOR_NAVAJOWHITE)
    Colors.add(COLOR_LAVENDERBLUSH)
    Colors.add(COLOR_MEDIUMSPRINGGREEN)
    Colors.add(COLOR_SLATEGRAY)
    Colors.add(COLOR_MISTYROSE)
    Colors.add(COLOR_LINEN)
    Colors.add(COLOR_DARKORANGE)
    Colors.add(COLOR_SLATEBLUE)
    Colors.add(COLOR_LIGHTCYAN)
    Colors.add(COLOR_LIGHTSKYBLUE)
    Colors.add(COLOR_MEDIUMSEAGREEN)
    Colors.add(COLOR_MEDIUMTURQUOISE)
    Colors.add(COLOR_DEEPPINK)
    Colors.add(COLOR_GHOSTWHITE)
    Colors.add(COLOR_GREEN)
    Colors.add(COLOR_LIME)
    Colors.add(COLOR_MEDIUMAQUAMARINE)
    Colors.add(COLOR_OLDLACE)
    Colors.add(COLOR_GREY)
    Colors.add(COLOR_ORANGE)
    Colors.add(COLOR_DARKSLATEGREY)
    Colors.add(COLOR_MEDIUMSLATEBLUE)
    Colors.add(COLOR_MAROON)
    Colors.add(COLOR_PALEGOLDENROD)

Or rather a color map

B4X:
Dim ColorMap As Map
ColorMap.Initialize
ColorMap.put("lightslategrey","#778899")
ColorMap.put("darkviolet","#9400D3")
ColorMap.put("cyan","#00FFFF")
ColorMap.put("darkslateblue","#483D8B")
ColorMap.put("bisque","#FFE4C4")
ColorMap.put("lightgrey","#D3D3D3")
ColorMap.put("khaki","#F0E68C")
ColorMap.put("darkgray","#A9A9A9")
ColorMap.put("saddlebrown","#8B4513")
ColorMap.put("blanchedalmond","#FFEBCD")
ColorMap.put("darkblue","#00008B")
ColorMap.put("lightcoral","#F08080")
ColorMap.put("orangered","#FF4500")
ColorMap.put("moccasin","#FFE4B5")
ColorMap.put("azure","#F0FFFF")
ColorMap.put("lightgoldenrodyellow","#FAFAD2")
ColorMap.put("skyblue","#87CEEB")
ColorMap.put("deepskyblue","#00BFFF")
ColorMap.put("chartreuse","#7FFF00")
ColorMap.put("mediumpurple","#9370DB")
ColorMap.put("lightyellow","#FFFFE0")
ColorMap.put("violet","#EE82EE")
ColorMap.put("palevioletred","#DB7093")
ColorMap.put("dimgrey","#696969")
ColorMap.put("rosybrown","#BC8F8F")
ColorMap.put("honeydew","#F0FFF0")
ColorMap.put("mediumblue","#0000CD")
ColorMap.put("darkseagreen","#8FBC8F")
ColorMap.put("limegreen","#32CD32")
ColorMap.put("paleturquoise","#AFEEEE")
ColorMap.put("mediumorchid","#BA55D3")
ColorMap.put("burlywood","#DEB887")
ColorMap.put("silver","#C0C0C0")
ColorMap.put("papayawhip","#FFEFD5")
ColorMap.put("chocolate","#D2691E")
ColorMap.put("lightsteelblue","#B0C4DE")
ColorMap.put("pink","#FFC0CB")
ColorMap.put("darkgreen","#006400")
ColorMap.put("sienna","#A0522D")
ColorMap.put("seashell","#FFF5EE")
ColorMap.put("thistle","#D8BFD8")
ColorMap.put("yellow","#FFFF00")
ColorMap.put("lightseagreen","#20B2AA")
ColorMap.put("cornsilk","#FFF8DC")
ColorMap.put("blueviolet","#8A2BE2")
ColorMap.put("tomato","#FF6347")
ColorMap.put("cornflowerblue","#6495ED")
ColorMap.put("sandybrown","#F4A460")
ColorMap.put("gold","#FFD700")
ColorMap.put("springgreen","#00FF7F")
ColorMap.put("gray","#808080")
ColorMap.put("slategrey","#708090")
ColorMap.put("mediumvioletred","#C71585")
ColorMap.put("crimson","#DC143C")
ColorMap.put("darkcyan","#008B8B")
ColorMap.put("ivory","#FFFFF0")
ColorMap.put("darkmagenta","#8B008B")
ColorMap.put("wheat","#F5DEB3")
ColorMap.put("indianred","#CD5C5C")
ColorMap.put("darkorchid","#9932CC")
ColorMap.put("whitesmoke","#F5F5F5")
ColorMap.put("mintcream","#F5FFFA")
ColorMap.put("lightpink","#FFB6C1")
ColorMap.put("black","#000000")
ColorMap.put("teal","#008080")
ColorMap.put("cadetblue","#5F9EA0")
ColorMap.put("beige","#F5F5DC")
ColorMap.put("darkkhaki","#BDB76B")
ColorMap.put("blue","#0000FF")
ColorMap.put("darkslategray","#2F4F4F")
ColorMap.put("royalblue","#4169E1")
ColorMap.put("seagreen","#2E8B57")
ColorMap.put("purple","#800080")
ColorMap.put("orchid","#DA70D6")
ColorMap.put("forestgreen","#228B22")
ColorMap.put("darksalmon","#E9967A")
ColorMap.put("palegreen","#98FB98")
ColorMap.put("navy","#000080")
ColorMap.put("lightslategray","#778899")
ColorMap.put("rebeccapurple","#663399")
ColorMap.put("greenyellow","#ADFF2F")
ColorMap.put("red","#FF0000")
ColorMap.put("aqua","#00FFFF")
ColorMap.put("white","#FFFFFF")
ColorMap.put("dodgerblue","#1E90FF")
ColorMap.put("lightblue","#ADD8E6")
ColorMap.put("olive","#808000")
ColorMap.put("coral","#FF7F50")
ColorMap.put("peachpuff","#FFDAB9")
ColorMap.put("darkolivegreen","#556B2F")
ColorMap.put("darkturquoise","#00CED1")
ColorMap.put("darkgrey","#A9A9A9")
ColorMap.put("lavender","#E6E6FA")
ColorMap.put("lightgray","#D3D3D3")
ColorMap.put("gainsboro","#DCDCDC")
ColorMap.put("tan","#D2B48C")
ColorMap.put("plum","#DDA0DD")
ColorMap.put("midnightblue","#191970")
ColorMap.put("powderblue","#B0E0E6")
ColorMap.put("dimgray","#696969")
ColorMap.put("lemonchiffon","#FFFACD")
ColorMap.put("salmon","#FA8072")
ColorMap.put("lightgreen","#90EE90")
ColorMap.put("brown","#A52A2A")
ColorMap.put("goldenrod","#DAA520")
ColorMap.put("steelblue","#4682B4")
ColorMap.put("lightsalmon","#FFA07A")
ColorMap.put("darkred","#8B0000")
ColorMap.put("snow","#FFFAFA")
ColorMap.put("olivedrab","#6B8E23")
ColorMap.put("yellowgreen","#9ACD32")
ColorMap.put("indigo","#4B0082")
ColorMap.put("lawngreen","#7CFC00")
ColorMap.put("magenta","#FF00FF")
ColorMap.put("aquamarine","#7FFFD4")
ColorMap.put("floralwhite","#FFFAF0")
ColorMap.put("antiquewhite","#FAEBD7")
ColorMap.put("hotpink","#FF69B4")
ColorMap.put("turquoise","#40E0D0")
ColorMap.put("peru","#CD853F")
ColorMap.put("fuchsia","#FF00FF")
ColorMap.put("firebrick","#B22222")
ColorMap.put("aliceblue","#F0F8FF")
ColorMap.put("darkgoldenrod","#B8860B")
ColorMap.put("navajowhite","#FFDEAD")
ColorMap.put("lavenderblush","#FFF0F5")
ColorMap.put("mediumspringgreen","#00FA9A")
ColorMap.put("slategray","#708090")
ColorMap.put("mistyrose","#FFE4E1")
ColorMap.put("linen","#FAF0E6")
ColorMap.put("darkorange","#FF8C00")
ColorMap.put("slateblue","#6A5ACD")
ColorMap.put("lightcyan","#E0FFFF")
ColorMap.put("lightskyblue","#87CEFA")
ColorMap.put("mediumseagreen","#3CB371")
ColorMap.put("mediumturquoise","#48D1CC")
ColorMap.put("deeppink","#FF1493")
ColorMap.put("ghostwhite","#F8F8FF")
ColorMap.put("green","#008000")
ColorMap.put("lime","#00FF00")
ColorMap.put("mediumaquamarine","#66CDAA")
ColorMap.put("oldlace","#FDF5E6")
ColorMap.put("grey","#808080")
ColorMap.put("orange","#FFA500")
ColorMap.put("darkslategrey","#2F4F4F")
ColorMap.put("mediumslateblue","#7B68EE")
ColorMap.put("maroon","#800000")
ColorMap.put("palegoldenrod","#EEE8AA")
 
Last edited:

Mashiane

Expert
Licensed User
Longtime User
The HTML colors can also be created as an Object / Map.

B4X:
function HTMLColorsMap() {
    var colors = new Object();
colors.lightslategrey = '#778899';
colors.darkviolet = '#9400D3';
colors.cyan = '#00FFFF';
colors.darkslateblue = '#483D8B';
colors.bisque = '#FFE4C4';
colors.lightgrey = '#D3D3D3';
colors.khaki = '#F0E68C';
colors.darkgray = '#A9A9A9';
colors.saddlebrown = '#8B4513';
colors.blanchedalmond = '#FFEBCD';
colors.darkblue = '#00008B';
colors.lightcoral = '#F08080';
colors.orangered = '#FF4500';
colors.moccasin = '#FFE4B5';
colors.azure = '#F0FFFF';
colors.lightgoldenrodyellow = '#FAFAD2';
colors.skyblue = '#87CEEB';
colors.deepskyblue = '#00BFFF';
colors.chartreuse = '#7FFF00';
colors.mediumpurple = '#9370DB';
colors.lightyellow = '#FFFFE0';
colors.violet = '#EE82EE';
colors.palevioletred = '#DB7093';
colors.dimgrey = '#696969';
colors.rosybrown = '#BC8F8F';
colors.honeydew = '#F0FFF0';
colors.mediumblue = '#0000CD';
colors.darkseagreen = '#8FBC8F';
colors.limegreen = '#32CD32';
colors.paleturquoise = '#AFEEEE';
colors.mediumorchid = '#BA55D3';
colors.burlywood = '#DEB887';
colors.silver = '#C0C0C0';
colors.papayawhip = '#FFEFD5';
colors.chocolate = '#D2691E';
colors.lightsteelblue = '#B0C4DE';
colors.pink = '#FFC0CB';
colors.darkgreen = '#006400';
colors.sienna = '#A0522D';
colors.seashell = '#FFF5EE';
colors.thistle = '#D8BFD8';
colors.yellow = '#FFFF00';
colors.lightseagreen = '#20B2AA';
colors.cornsilk = '#FFF8DC';
colors.blueviolet = '#8A2BE2';
colors.tomato = '#FF6347';
colors.cornflowerblue = '#6495ED';
colors.sandybrown = '#F4A460';
colors.gold = '#FFD700';
colors.springgreen = '#00FF7F';
colors.gray = '#808080';
colors.slategrey = '#708090';
colors.mediumvioletred = '#C71585';
colors.crimson = '#DC143C';
colors.darkcyan = '#008B8B';
colors.ivory = '#FFFFF0';
colors.darkmagenta = '#8B008B';
colors.wheat = '#F5DEB3';
colors.indianred = '#CD5C5C';
colors.darkorchid = '#9932CC';
colors.whitesmoke = '#F5F5F5';
colors.mintcream = '#F5FFFA';
colors.lightpink = '#FFB6C1';
colors.black = '#000000';
colors.teal = '#008080';
colors.cadetblue = '#5F9EA0';
colors.beige = '#F5F5DC';
colors.darkkhaki = '#BDB76B';
colors.blue = '#0000FF';
colors.darkslategray = '#2F4F4F';
colors.royalblue = '#4169E1';
colors.seagreen = '#2E8B57';
colors.purple = '#800080';
colors.orchid = '#DA70D6';
colors.forestgreen = '#228B22';
colors.darksalmon = '#E9967A';
colors.palegreen = '#98FB98';
colors.navy = '#000080';
colors.lightslategray = '#778899';
colors.rebeccapurple = '#663399';
colors.greenyellow = '#ADFF2F';
colors.red = '#FF0000';
colors.aqua = '#00FFFF';
colors.white = '#FFFFFF';
colors.dodgerblue = '#1E90FF';
colors.lightblue = '#ADD8E6';
colors.olive = '#808000';
colors.coral = '#FF7F50';
colors.peachpuff = '#FFDAB9';
colors.darkolivegreen = '#556B2F';
colors.darkturquoise = '#00CED1';
colors.darkgrey = '#A9A9A9';
colors.lavender = '#E6E6FA';
colors.lightgray = '#D3D3D3';
colors.gainsboro = '#DCDCDC';
colors.tan = '#D2B48C';
colors.plum = '#DDA0DD';
colors.midnightblue = '#191970';
colors.powderblue = '#B0E0E6';
colors.dimgray = '#696969';
colors.lemonchiffon = '#FFFACD';
colors.salmon = '#FA8072';
colors.lightgreen = '#90EE90';
colors.brown = '#A52A2A';
colors.goldenrod = '#DAA520';
colors.steelblue = '#4682B4';
colors.lightsalmon = '#FFA07A';
colors.darkred = '#8B0000';
colors.snow = '#FFFAFA';
colors.olivedrab = '#6B8E23';
colors.yellowgreen = '#9ACD32';
colors.indigo = '#4B0082';
colors.lawngreen = '#7CFC00';
colors.magenta = '#FF00FF';
colors.aquamarine = '#7FFFD4';
colors.floralwhite = '#FFFAF0';
colors.antiquewhite = '#FAEBD7';
colors.hotpink = '#FF69B4';
colors.turquoise = '#40E0D0';
colors.peru = '#CD853F';
colors.fuchsia = '#FF00FF';
colors.firebrick = '#B22222';
colors.aliceblue = '#F0F8FF';
colors.darkgoldenrod = '#B8860B';
colors.navajowhite = '#FFDEAD';
colors.lavenderblush = '#FFF0F5';
colors.mediumspringgreen = '#00FA9A';
colors.slategray = '#708090';
colors.mistyrose = '#FFE4E1';
colors.linen = '#FAF0E6';
colors.darkorange = '#FF8C00';
colors.slateblue = '#6A5ACD';
colors.lightcyan = '#E0FFFF';
colors.lightskyblue = '#87CEFA';
colors.mediumseagreen = '#3CB371';
colors.mediumturquoise = '#48D1CC';
colors.deeppink = '#FF1493';
colors.ghostwhite = '#F8F8FF';
colors.green = '#008000';
colors.lime = '#00FF00';
colors.mediumaquamarine = '#66CDAA';
colors.oldlace = '#FDF5E6';
colors.grey = '#808080';
colors.orange = '#FFA500';
colors.darkslategrey = '#2F4F4F';
colors.mediumslateblue = '#7B68EE';
colors.maroon = '#800000';
colors.palegoldenrod = '#EEE8AA';
return colors;
}
 

Mashiane

Expert
Licensed User
Longtime User
Quicky create an a->zz list in lowercase...

B4X:
Sub AplhaLimits As List
    Dim lst As List
    lst.Initialize
    Dim sCnt As Int = Asc("a")
    Dim sTot As Int = Asc("z")
    For a = sCnt To sTot
        Dim strc As String = Chr(a)
        lst.Add(strc)
    Next
    For a = sCnt To sTot
        For b = sCnt To sTot
            Dim strc As String = Chr(a) & Chr(b)
            lst.Add(strc)
        Next
    Next
    Return lst
End Sub
 

AnandGupta

Expert
Licensed User
Longtime User
Mashiane,

You have and are doing great contribution for the community. Now to get all the function in a list, in one place, something like StartDust did https://www.b4x.com/android/forum/threads/panoramica-star-dust.86164/, can you post a list in your first message ?

My humble request to get all function names with description in one place. Do not take it if extra effort required.
Thanks a lot for your hard work.

Regards,

Anand
 

Mashiane

Expert
Licensed User
Longtime User
Top