B4A Library JustifyTextView Wrapper

Discussion in 'Additional libraries, classes and official updates' started by jahswani, Jun 21, 2015.

Similar threads

B4A Tutorial [java] Custom View with Designer Support (Java library)
B4A Library ChatMessageView
B4A Library Google VR
B4A Library PanoramaImageView
B4A Library CircularProgress
  1. jahswani

    jahswani Active Member Licensed User

    JustifyTextView With this library you can justify the text in a textView.
    Author:
    Fodouop Jahswant
    Version: 1
    • JustifyTextView
      Fields:
      • ba As BA
      Methods:
      • AddToParent (Parent As ViewGroup, left As Int, top As Int, width As Int, height As Int)
      • BringToFront
      • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
      • Initialize (EventName As String)
        Initializes the view.
        Example :
        Dim MyView As JustifyTextView
        MyView.Initialize("MyView")
        Activity.AddView(MyView,0,0,100%x,100%y)
      • Invalidate
      • Invalidate2 (arg0 As Rect)
      • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
      • IsInitialized As Boolean
      • RemoveView
      • RequestFocus As Boolean
      • SendToBack
      • SetBackgroundImage (arg0 As Bitmap)
      • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
      • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
      • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
      • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
      • SetText (st As String, wrap As Boolean)

        st: String to Justify.
        wrap: Set to true or false depending on what you want.
        Example
        Dim From As String
        From = File.ReadString(File.DirInternal, "from.txt")
        MyView.SetText(From,False)
      Properties:
      • Background As Drawable
      • Color As Int [write only]
      • Enabled As Boolean
      • Height As Int
      • Left As Int
      • Tag As Object
      • TextSize As Int [write only]
      • Top As Int
      • Visible As Boolean
      • Width As Int
    1.png 2.png
     

    Attached Files:

    Last edited: Jun 21, 2015
  2. DonManfred

    DonManfred Expert Licensed User

    Well done
     
    jahswani likes this.
  3. jahswani

    jahswani Active Member Licensed User

    Thanks bro.
     
  4. DonManfred

    DonManfred Expert Licensed User

    shouldnt the method not named setText instead of sSetText?
     
  5. jahswani

    jahswani Active Member Licensed User

    35 minutes later :
    Sure just updated.
     
  6. DonManfred

    DonManfred Expert Licensed User

    you need to update the xml2bb documentation too :D
     
  7. jahswani

    jahswani Active Member Licensed User

    Done ! Sir.
     
  8. MarcoRome

    MarcoRome Expert Licensed User

    Great Job ;)
     
    jahswani likes this.
  9. DonManfred

    DonManfred Expert Licensed User

    i dont believe that... There is still standing
    in the documentation in post #1 ;)
     
  10. mshafiee110

    mshafiee110 Member Licensed User

    Hi @jahswani
    this is great.tnx


    I have a question,can you set gravity in your lib?(because in rtl language words are the opposite )
     
  11. jahswani

    jahswani Active Member Licensed User

    No Sorry
     
    mshafiee110 likes this.
  12. MarcoRome

    MarcoRome Expert Licensed User

    Hi @jahswani
    A question.
    Is it possibile change color to text ?
    Because on some devices the text is displayed, for example on a white background turns gray, and the text on some devices and hard to read.
    It would be a good thing if you had a chance to set the font color.
     
  13. Johan Schoeman

    Johan Schoeman Expert Licensed User

    It can be done - he just needs to add a bit of code to the original Github project and a bit of code to the wrapper. It is a TextView so the color of the text can be set very easily.
     
    MarcoRome likes this.
  14. Anser

    Anser Active Member Licensed User

    If it can be done then it is going to be very useful. I couldn't find any other views/library for B4A that could justify the contents of a label/Text view. A very useful and missing feature that plays a vital role in the aesthetic part of an app.
     
  15. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Use the attached and amended Library files. To change the color just do
    Code:
    MyView.JustifyTextColor = Colors.Cyan
    MyView.setPadding(
    10,10,10,10)

    1.png


    2.png
    JustifyTextView
    Author:
    Github: Nikhil Lohia, Original wrap: Fodouop Jahswant, Amended: Johan Schoeman
    Version: 1
    • JustifyTextView
      Fields:
      • ba As BA
      Methods:
      • BringToFront
      • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
      • Initialize (EventName As String)
      • Invalidate
      • Invalidate2 (arg0 As Rect)
      • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
      • IsInitialized As Boolean
      • RemoveView
      • RequestFocus As Boolean
      • SendToBack
      • SetBackgroundImage (arg0 As Bitmap)
      • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
      • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
      • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
      • SetText (paramString As String, paramBoolean As Boolean)
      • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
      • setPadding (left As Int, top As Int, right As Int, bottom As Int)
      Properties:
      • Background As Drawable
      • Color As Int [write only]
      • Enabled As Boolean
      • Height As Int
      • JustifyTextColor As Int [write only]
      • Left As Int
      • Parent As Object [read only]
      • Tag As Object
      • TextSize As Int [write only]
      • Top As Int
      • Visible As Boolean
      • Width As Int
     

    Attached Files:

    Last edited: Jul 23, 2016
  16. Anser

    Anser Active Member Licensed User

    Hi Johan,

    Nice work.

    Will it be possible to consider the gravity too ? Or will it be meaningless when the text is already justified ?
    I was thinking about the Gravity.CENTER_HORIZONTAL + Gravity.CENTER_VERTICAL
     
  17. jahswani

    jahswani Active Member Licensed User

    Thanks...I hate the way i'm no more too active.I have to complete a huge project...
     
  18. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Try with this....

    4.png

    Sample Code:
    Code:
    #Region  Project Attributes
        
    #ApplicationLabel: LibEx
        
    #VersionCode: 1
        
    #VersionName:
        
    'SupportedOrientations possible values: unspecified, landscape or portrait.
        #SupportedOrientations: unspecified
        
    #CanInstallToExternalStorage: False
    #End Region

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

    Sub Process_Globals
        
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.

    End Sub

    Sub Globals
        
    'These global variables will be redeclared each time the activity is created.
        'These variables can only be accessed from this module.
         Dim From As String
        
    Private MyView As JustifyTextView
        
    Dim sv As ScrollView
        
    Private btn1 As Button
        
    Private btn2 As Button
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example
        sv.Initialize(1900dip)
        
    Activity.AddView(sv,0,0,100%x,300%y)
        sv.Panel.LoadLayout(
    "Layout1")
        
    If File.Exists(File.DirInternal,"from.txt") = False Then
        
    File.Copy(File.DirAssets,"from.txt",File.DirInternal,"from.txt")
        
    End If
        From = 
    File.ReadString(File.DirInternal, "from.txt")
        MyView.SetText(From,
    False)
        
    'MyView.TextSize = 10
       
        MyView.JustifyTextColor = 
    Colors.Cyan
        MyView.setPadding(
    10,10,10,10)
        MyView.JustifyTextGravity = MyView.GRAVITY_RIGHT
       
    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub

    Sub btn2_Click
        MyView.JustifyTextColor = 
    Colors.Red
        MyView.SetText(From,
    False)
    End Sub
    Sub btn1_Click
        MyView.JustifyTextColor = 
    Colors.Yellow
        MyView.SetText(From,
    True)
    End Sub
    Library:

    JustifyTextView
    Author:
    Github: Nikhil Lohia, Original wrap: Fodouop Jahswant, Amended: Johan Schoeman
    Version: 1
    • JustifyTextView
      Fields:
      • GRAVITY_BOTTOM As Int
      • GRAVITY_CENTER_HORIZONTAL As Int
      • GRAVITY_CENTER_VERTICAL As Int
      • GRAVITY_FILL_HORIZONTAL As Int
      • GRAVITY_FILL_VERTICAL As Int
      • GRAVITY_LEFT As Int
      • GRAVITY_NONE As Int
      • GRAVITY_RIGHT As Int
      • GRAVITY_TOP As Int
      • ba As BA
      Methods:
      • BringToFront
      • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
      • Initialize (EventName As String)
      • Invalidate
      • Invalidate2 (arg0 As Rect)
      • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
      • IsInitialized As Boolean
      • RemoveView
      • RequestFocus As Boolean
      • SendToBack
      • SetBackgroundImage (arg0 As Bitmap)
      • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
      • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
      • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
      • SetText (paramString As String, paramBoolean As Boolean)
      • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
      • setPadding (left As Int, top As Int, right As Int, bottom As Int)
      Properties:
      • Background As Drawable
      • Color As Int [write only]
      • Enabled As Boolean
      • Height As Int
      • JustifyTextColor As Int [write only]
      • JustifyTextGravity As Int [write only]
      • Left As Int
      • Parent As Object [read only]
      • Tag As Object
      • TextSize As Int [write only]
      • Top As Int
      • Visible As Boolean
      • Width As Int
     

    Attached Files:

    MarcoRome and Anser like this.
  19. Johan Schoeman

    Johan Schoeman Expert Licensed User

    Maybe post #18 will do it for you...
     
    MarcoRome, DonManfred and Anser like this.
  20. MarcoRome

    MarcoRome Expert Licensed User

    Thank @Johan Schoeman for this fantastic new functions.

    All work, but if i use with UltimateListView i have this error:

    I have this code in ULV ( nothing of special )
    Code:
    Sub Item_LayoutDettagli(LayoutName As String, LayoutPanel As Panel)
     
            
    Dim lbl1 As Label
            lbl1.Initialize(
    "")
            lbl1.TextColor = 
    Colors.Black
            lbl1.TextSize = FontSize
            lbl1.Typeface = 
    Typeface.DEFAULT_BOLD
            lbl1.Gravity = 
    Gravity.TOP
            LayoutPanel.AddView(lbl1, 
    00, LayoutPanel.Width, 25dip)


            
    Dim Giustifica1 As JustifyTextView
            Giustifica1.Initialize(
    "Giustifica1")
             LayoutPanel.AddView(Giustifica1, Padding, 
    26dip, LayoutPanel.Width - (Padding * 2), LayoutPanel.Height + (Padding * 2))
          
    End Sub

    Sub Item_ContentDettagli(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)

        
    Dim lbl_titolo As Label = LayoutPanel.GetView(0)
        lbl_titolo.Text = dettagli.Get(
    "log_Titolo" & Position)
        lbl_titolo.Tag = 
    ""

            
    Dim Giustifica1 As JustifyTextView = LayoutPanel.GetView(1)
            Giustifica1.SetText(dettagli.Get(
    "log_valore" & Position), True'<----- HERE ERROR
      
    End Sub
    With "old" library this error i havent..... ( same code ).
    Any idea ??
    Thank you
     
Loading...