B4A Library JustifyTextView Wrapper

JustifyTextView With this library you can justify the text in a textView.
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
 

Attachments

  • justifyEx.zip
    8.6 KB · Views: 556
  • justifyLib.zip
    8.1 KB · Views: 588
Last edited:

mshafiee110

Active Member
Licensed User
Longtime 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 )
 

MarcoRome

Expert
Licensed User
Longtime 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.
 

Johan Schoeman

Expert
Licensed User
Longtime 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.
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.
 

Anser

Well-Known Member
Licensed User
Longtime 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.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Use the attached and amended Library files. To change the color just do
B4X:
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
 

Attachments

  • b4aexample.zip
    8.7 KB · Views: 255
  • JustifyTextViewLibFiles.zip
    8.7 KB · Views: 299
Last edited:

Anser

Well-Known Member
Licensed User
Longtime 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
 

Johan Schoeman

Expert
Licensed User
Longtime 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
Try with this....

4.png


Sample Code:
B4X:
#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
 

Attachments

  • b4aexample.zip
    8.7 KB · Views: 245
  • JustifyTextViewLibFiles.zip
    9.2 KB · Views: 267

Johan Schoeman

Expert
Licensed User
Longtime User

MarcoRome

Expert
Licensed User
Longtime User
Thank @Johan Schoeman for this fantastic new functions.

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

Error occurred on line: 1201 (act_mediazioni_tab)
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.example.justifyexample.TextViewEx.setText(java.lang.String, boolean)' on a null object reference
at justifywrapper.justifyWrapper.SetText(justifyWrapper.java:105)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:748)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:343)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at flm.b4a.ultimatelistview.b.getView(SourceFile:562)
at android.widget.AbsListView.obtainView(AbsListView.java:2847)
at android.widget.ListView.makeAndAddView(ListView.java:1931)
at android.widget.ListView.fillDown(ListView.java:715)
at android.widget.ListView.fillFromTop(ListView.java:781)
at android.widget.ListView.layoutChildren(ListView.java:1707)
at flm.b4a.ultimatelistview.UltimateListView.layoutChildren(SourceFile:549)
at android.widget.AbsListView.onLayout(AbsListView.java:2645)
at android.view.View.layout(View.java:16992)
at android.view.ViewGroup.layout(ViewGroup.java:5409)
at anywheresoftware.b4a.BALayout.onLayout(BALayout.java:43)
at android.view.View.layout(View.java:16992)
at android.view.ViewGroup.layout(ViewGroup.java:5409)
at anywheresoftware.b4a.BALayout.onLayout(BALayout.java:43)
at android.view.View.layout(View.java:16992)
at android.view.ViewGroup.layout(ViewGroup.java:5409)
at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1695)
at android.view.View.layout(View.java:16992)
at android.view.ViewGroup.layout(ViewGroup.java:5409)
at anywheresoftware.b4a.BALayout.onLayout(BALayout.java:43)
at android.view.View.layout(View.java:16992)
at android.view.ViewGroup.layout(ViewGroup.java:5409)
at anywheresoftware.b4a.BALayout.onLayout(BALayout.java:43)
at android.view.View.layout(View.java:16992)
at android.view.ViewGroup.layout(ViewGroup.java:5409)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:16992)
at android.view.ViewGroup.layout(ViewGroup.java:5409)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1187)
at android.view.View.layout(View.java:16992)
at android.view.ViewGroup.layout(ViewGroup.java:5409)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:16992)
at android.view.ViewGroup.layout(ViewGroup.java:5409)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1702)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1556)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1465)
at android.view.View.layout(View.java:16992)
at android.view.ViewGroup.layout(ViewGroup.java:5409)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:16992)
at android.view.ViewGroup.layout(ViewGroup.java:5409)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2464)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2167)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1301)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7016)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
at android.view.Choreographer.doCallbacks(Choreographer.java:590)
at android.view.Choreographer.doFrame(Choreographer.java:560)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Lo
Message longer than Log limit (4000). Message was truncated.

I have this code in ULV ( nothing of special )
B4X:
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, 0, 0, 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
 
Top