B4A Library [LIB] [B4A] BMTypeWriter

Hello everyone, here I bring you a tool to create the writing effect.
It is basic but functional.

Thank you for viewing this library.

BMTypeWriter.gif



BMTypeWriter

Author:
Version:
1
  • BMTypeWriter
    Create a simple TypeWriter Effect on any TextView
    Example:

    Writer1.Initialize(Me, "Writer1")
    Writer1.Text = $"Hi, my name is B4X Writer!"$
    Writer1.start
    'To listen to the animation you must use the event :
    Sub Writer1_Writer(Text as String)
    Log(Text)
    End Sub
    • Events:
      • Pause
      • Stop
      • Writer (Text As String)
    • Fields:
      • mCallBack As Object
      • mEventName As String
    • Functions:
      • Class_Globals As String
      • getInterval As Int
      • getText As String
      • Initialize (CallBack As Object, EventName As String) As String
        Initializes the object. You can add parameters to this method if needed.
      • IsInitialized As Boolean
        Prueba si acaso el objeto ha sido inicializado.
      • pause As String
        Pause the typing animation.
      • reset
        Start from the beginning the typing animation.
      • setInterval (Interval As Int) As String
      • setText (Text As String) As String
      • start As String
        Start the typing animation.
      • stop As String
        Stop the typing animation and delete the string.
    • Properties:
      • Interval As Int
      • Text As String



Example:
    Writer1.Initialize(Me, "Writer1")
    Writer1.Text = $"Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.!"$
    Writer1.Interval = 100
 

    Writer1.start

B4X:
Sub Writer1_Writer(Text as String)
    Log(Text)
End Sub
 

Attachments

  • [LIB] BMTypWriter.zip
    4.3 KB · Views: 202
Last edited:

omo

Active Member
Licensed User
Longtime User
Hello everyone, here I bring you a tool to create the writing effect.
It is basic but functional.

Thank you for viewing this library.

View attachment 139106


BMTypeWriter

Author:
Version:
1
  • BMTypeWriter
    Create a simple TypeWriter Effect on any TextView
    Example:

    Writer1.Initialize(Me, "Writer1")
    Writer1.Text = $"Hi, my name is B4X Writer!"$
    Writer1.start
    'To listen to the animation you must use the event :
    Sub Writer1_Writer(Text as String)
    Log(Text)
    End Sub
    • Events:
      • Pause
      • Stop
      • Writer (Text As String)
    • Fields:
      • mCallBack As Object
      • mEventName As String
    • Functions:
      • Class_Globals As String
      • getInterval As Int
      • getText As String
      • Initialize (CallBack As Object, EventName As String) As String
        Initializes the object. You can add parameters to this method if needed.
      • IsInitialized As Boolean
        Prueba si acaso el objeto ha sido inicializado.
      • pause As String
        Pause the typing animation.
      • reset
        Start from the beginning the typing animation.
      • setInterval (Interval As Int) As String
      • setText (Text As String) As String
      • start As String
        Start the typing animation.
      • stop As String
        Stop the typing animation and delete the string.
    • Properties:
      • Interval As Int
      • Text As String



Example:
    Writer1.Initialize(Me, "Writer1")
    Writer1.Text = $"Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.!"$
    Writer1.Interval = 100
 

    Writer1.start

B4X:
Sub Writer1_Writer(Text as String)
    Log(Text)
End Sub
Brian, well done for this your simple but effective library. I need B4X solution, but this library is only b4a. Do you have equivalent solution published/unpublished that can work with b4j/B4i also? I know how to acheive this with webview and JavaScript, but don't want to follow that route if there is better alternative
 

Brian Michael

Active Member
Licensed User
Hi, sorry i just work with B4A but here is the code, so you can use it and modify as you need:

B4X:
'BMTypeWriter
'Version 1.0
'By: Brian Michael
'Free Library for B4X Community!

#Event:Writer (Text as String)
#RaisesSynchronousEvents: Writer

#Event:Stop
#RaisesSynchronousEvents: Stop

#Event:Pause
#RaisesSynchronousEvents: Pause

'Create a simple TypeWriter Effect on any TextView
'Example:
'<code>
'    Writer1.Initialize(Me, "Writer1")
'    Writer1.Text = $"Hi, my name is B4X Writer!"$
'    Writer1.start
'    'To listen to the animation you must use the event :
'    Sub Writer1_Writer(Text as String)
'        Log(Text)
'    End Sub
'</code>
Sub Class_Globals
    Private mLettersList As List
    Private mInterval As Int = 300
    Private mText As String = ""
    Private mTmr As Timer
    Public mEventName As String
    Public mCallBack As Object
    Private Position As Int = 0
    Private temp_text As String = ""
    
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(CallBack As Object, EventName As String)
    mCallBack = CallBack
    mEventName = EventName
    mLettersList.Initialize
    mTmr.Initialize("mTmr",mInterval)
End Sub

Private Sub mTmr_Tick
    If Position <= mLettersList.Size - 1 Then
        temp_text = temp_text & mLettersList.Get(Position)
        Position = Position + 1
        If SubExists(mCallBack, mEventName & "_Writer") Then
            CallSub2(mCallBack, mEventName & "_Writer", temp_text)
        End If
    End If
End Sub

'Start from the beginning the typing animation.
Public Sub reset
    mTmr.Enabled = False
    Position = 0
    temp_text = ""
    Sleep(0)
    mTmr.Enabled = True
End Sub

'Start the typing animation.
Public Sub start
    mTmr.Enabled = True
End Sub

'Pause the typing animation.
Public Sub pause
    mTmr.Enabled = False
    If SubExists(mCallBack, mEventName & "_Pause") Then
        CallSub(mCallBack, mEventName & "_Pause")
    End If
End Sub

'Stop the typing animation and delete the string.
Public Sub stop
    mTmr.Enabled = False
    Position = 0
    temp_text = ""
    If SubExists(mCallBack, mEventName & "_Stop") Then
        CallSub(mCallBack, mEventName & "_Stop")
    End If

End Sub

#Region ----------Methods-------------------

Public Sub setInterval(Interval As Int)
    mInterval = Interval
    mTmr.Interval = mInterval
End Sub

Public Sub getInterval As Int
    Return mInterval
End Sub

Public Sub setText(Text As String)
    mText = Text
    For i = 0 To mText.Length - 1
        mLettersList.Add(mText.SubString2(i,i+1))
    Next
End Sub

Public Sub getText() As String
    Return mText
End Sub

#End Region
 
  • Like
Reactions: omo

omo

Active Member
Licensed User
Longtime User
Many thanks to you @ Brian, I purposely don't want to stress you since I have plan B which I have already implemented and working well. However, it will be useful for other members and me whenever needs arise from time to time. Thank you so much, once again, Brian; I really appreciate
 
Top