B4A Library SmartString(Auto adjusting text size)

Smart String is no longer supported, please check out T8TextSize lib
http://b4x.com/android/forum/threads/t8textsize-library-smart-string.56851/

Hello every one

ScreenShot1.png
ScreenShot2.png


This library is for adjusting the text size automatically or manual with the following features:

1.SingleLine1


This sub tries to increase or decrease the single line text size and preserve the aspect ratio as Long As the height of the text Is Not greater than the height of the view.in other word you can increase your text size until you have space in width and height,and the text will be single line always and your aspect ratio is always preserved(IT’S ACCURACY IS ACCEPTABLE BUT IS NOT 100%)

NOTE1: The text size can not be changed with every 1dip

NOTE2: Your text in base layout should not be larger than 1 line



2.SingleLine2

This sub tries to fit your text in the view and then set maximum size if you have space in width and height of the view.and it’s always will be one line.this sub is similar to singleline1 but with two difference


1-Aspect ratio was not preserved and text can fit in the view

2-your text in base layout can be longer than one line but after set singleline2 it will be 1 line



3.Multiline1

This sub increase or decrease your text size as long as you have space in width and height and number of lines is smaller than your given maximum lines number

4.Multiline2

This sub increase or decrease your text size as long as you have space in width and height this sub not related to number of lines

NOTE: This sub has an argument named CanBeLarger.by using this option you can have more control over the size of your text if it’s not be larger than view spaces then the text size will not be increased.in other word this option is useful when you want to keep your base text size in larger devices

5.SetManualSize

with this sub you can give a scale rate for base layout and then your text size will be larger in large devices and be smaller in small devices with your given scale rate.

NOTE:This sub don’t preserve your aspect ratio and not depended on available spaces in width or height in other word you are free to do what do you want

6.SetSameStyle

With this sub You can Set any changes on a view and apply that textsize and font to same viewes with same height and width

This option is for decrease cpu , ram , battery usage with reduce calculates

7.SetExactLineNumber

Set your text to given line number without any change in text size

8.Ellipsize,SetLineSpace,SetPadding

This library is a collection of tools for strings
and you can ellipsize(cut) your text or set spaces between lines or fit the text in every position that you want Such as top or center



9.RichString1 – 4

This sub help you to use richstring library simpler with just call this subs



IMPORTANT NOTE1: If you use multiline1 or multiline2 and set your line space larger or smaller than default.your text size will be adapted but the position of text in your view will not be able to auto padding but you can set it manualy with SetPadding sub.this issue may be solved in next update

IMPORTANT NOTE2:Please don’t use this automatic text size library for adjust every text in your activity

Because this library adjusting text size with calculate and can be a reason for decrease free ram.In other word if you use this sub too much and always then maybe your ram free space decreased or cpu usage be high in weak devices

You have two solutions for solve this problem:

1-you can use SameStyle sub for decrease calculates

2-or Use activity first time option I think



AND AT LAST

This is my first library and may have many bug.please help and report any bug to solve it in next updates

*Required Libraries:
Java object , StringUtils ,RichString



Update 1.1:Fixed an issue with singleline2 and post updated
Update 1.2:Fixed an issue with B4A 4.30
 

Attachments

  • SmartString1.1+sample.zip
    207.8 KB · Views: 800
  • SmartString1.2+Sample.zip
    68.9 KB · Views: 932
Last edited:

Theera

Well-Known Member
Licensed User
Longtime User
Is there strategy of colorful text each letter?
 

R Rioja

Member
Licensed User
Longtime User
Please explain ViewWidth and BaseTextSize. Also, I tried to leave Font blank but I get errors. Please show a sample code for using default font. Thank you very much.
 

ArminKH

Well-Known Member
Please explain ViewWidth and BaseTextSize. Also, I tried to leave Font blank but I get errors. Please show a sample code for using default font. Thank you very much.
view width : the width of your target view which you want to set that text size when you are designing your app
for example : you add a label named Label1 on variant 320*480(on designer) from designer and your view on this variant have 60dip on width
base text size : your designing text size.(for example : the text size on designer before width and height changed on other device)
And if you want to set default font pass that option to "".
regards
 

R Rioja

Member
Licensed User
Longtime User
For me, "hard copy" documentation is easier to deal with than on-line or anything else. So when I find a good library, I write my own documentation and keep it all in a binder. Attached is my preliminary doc for the SmartString library. Please review it and if you are interested let me know if there is anything to add/correct/modify etc.
Thanks,
Robert
[email protected]
 

Attachments

  • SmartString.pdf
    297.4 KB · Views: 464

ArminKH

Well-Known Member
For me, "hard copy" documentation is easier to deal with than on-line or anything else. So when I find a good library, I write my own documentation and keep it all in a binder. Attached is my preliminary doc for the SmartString library. Please review it and if you are interested let me know if there is anything to add/correct/modify etc.
Thanks,
Robert
[email protected]
Thank u robert for your hard work this is great
But for some reson thats not possible to correct the library
Maybe somebody wants to know why?
Ok,beacause the base core and the name of this library will be changed and also some possiblities will be add to this lib
I'm so surprized because you are very intrested to this lib also more than me
Thank u robert i will contact u after changing on my codes
Good luck
 

ArminKH

Well-Known Member
If any body need some posiiblities can write there
 

R Rioja

Member
Licensed User
Longtime User
ArminKH, I did not mean that corrections should be made to the library. I meant corrections to my doc.
Robert
 

incendio

Well-Known Member
Licensed User
Longtime User
Hi, thanks for the library.

I have tried this library, but stuck when using smartstring singleline2 in my class.

My codes is something like this
B4X:
MyClass.Initialize(Me,myPanel,"event_name")

SingleLine2 need an activity but there is no activity in MyClass. Is there a solution for this?
 
Top