D
Deleted member 103
Guest
Hello,
With this class I can customize the lyrics of Label and Button, and it actually works very well.
In Google Report comes but from time to time this crash report.
Class clsTextResizer:
It would be nice if someone might find the mistake.
With this class I can customize the lyrics of Label and Button, and it actually works very well.
In Google Report comes but from time to time this crash report.
Class clsTextResizer:
B4X:
Sub Class_Globals
Private bmp As Bitmap
Private cvs As Canvas
Private stu As StringUtils
Private dt As Float
Private h, Height As Int
Private w, Width As Int
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
bmp.InitializeMutable(1dip, 1dip)
cvs.Initialize2(bmp)
End Sub
#Region TextSize vom Label, EditText und Button ändern
'Der Parameter "Scale" bei Buttons nicht verwendet!
Public Sub SetTextSize(obj As View, txt As String, scale As Float, singleline As Boolean)
'Log("SetTextSize: txt=" & txt & " :obj=" & obj)
'WICHTIG! Die Width darf nicht weniger als null sein!
If obj.Width < 1dip Then Return
setSingleLine(obj, singleline)
If obj Is Button Then
Dim btn As Button = obj
Height = btn.Height - 14dip
Width = btn.Width - 10dip
SetButtonTextSize(btn, txt)
Else
Dim lbl As Label = obj
Height = lbl.Height * scale
Width = lbl.Width - 5dip
SetLabelTextSize(lbl, txt)
End If
End Sub
'Sets the TextView to single line
Public Sub setSingleLine(TextView As View, SingleLine As Boolean)
Dim jo = TextView As JavaObject
jo.RunMethod("setSingleLine", Array As Object(SingleLine))
End Sub
Private Sub SetButtonTextSize(btn As Button, txt As String)
btn.TextSize = 6
dt = btn.TextSize
h = stu.MeasureMultilineTextHeight(btn, txt)
w = cvs.MeasureStringWidth(txt, btn.Typeface, dt)
Do While h <= Height
dt = dt + 1
btn.TextSize = dt
h = stu.MeasureMultilineTextHeight(btn, txt)
w = cvs.MeasureStringWidth(txt, btn.Typeface, dt)
If w >= Width Or h > Height Then
btn.TextSize = dt - 2
Exit
End If
Loop
End Sub
Private Sub SetLabelTextSize(lbl As Label, txt As String)
lbl.TextSize = 6
dt = lbl.TextSize
h = stu.MeasureMultilineTextHeight(lbl, txt)
w = cvs.MeasureStringWidth(txt, lbl.Typeface, dt)
Do While h <= Height
dt = dt + 1
lbl.TextSize = dt
h = stu.MeasureMultilineTextHeight(lbl, txt)
w = cvs.MeasureStringWidth(txt, lbl.Typeface, dt)
' Log(txt & ": w=" & w & " ;h=" & h)
' Log(txt & ": Width=" & Width & " ;Height=" & Height)
If w > Width Or h > Height Then
lbl.TextSize = dt - 1
Exit
End If
Loop
End Sub
#End Region
12. Okt. 09:06 in der App-Version 25
Samsung Galaxy J1 Ace (j1acevelte), Android 5.1
Bericht 1 von 2
java.lang.IllegalArgumentException:
at android.text.Layout.<init> (Layout.java:142)
at android.text.StaticLayout.<init> (StaticLayout.java:107)
at android.text.StaticLayout.<init> (StaticLayout.java:93)
at android.text.StaticLayout.<init> (StaticLayout.java:71)
at android.text.StaticLayout.<init> (StaticLayout.java:51)
at anywheresoftware.b4a.objects.StringUtils.MeasureMultilineTextHeight (StringUtils.java:50)
at fg.MasterOfRegolarity.clstextresizer._vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv6 (clstextresizer.java:84)
at fg.MasterOfRegolarity.clstextresizer._vvvvvvvvvvvvvvvvvvvvv3 (clstextresizer.java:171)
at fg.MasterOfRegolarity.main._activity_create (main.java:525)
at java.lang.reflect.Method.invoke (Native Method)
at java.lang.reflect.Method.invoke (Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2 (BA.java:191)
at fg.MasterOfRegolarity.main.afterFirstLayout (main.java:104)
at fg.MasterOfRegolarity.main.access$000 (main.java:17)
at fg.MasterOfRegolarity.main$WaitForLayout.run (main.java:82)
at android.os.Handler.handleCallback (Handler.java:739)
at android.os.Handler.dispatchMessage (Handler.java:95)
at android.os.Looper.loop (Looper.java:145)
at android.app.ActivityThread.main (ActivityThread.java:6934)
at java.lang.reflect.Method.invoke (Native Method)
at java.lang.reflect.Method.invoke (Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1199)
It would be nice if someone might find the mistake.