B4A Library SmartString(Auto adjusting text size)

Discussion in 'Additional libraries, classes and official updates' started by ArminKH, Sep 26, 2014.

?

Is this library useful?

  1. Yes

    83.6%
  2. Maybe

    12.3%
  3. No

    4.1%
  1. ArminKH

    ArminKH Well-Known Member

    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
     

    Attached Files:

    Last edited: Aug 2, 2015
    fazelsbr, Mashiane, GudEvil and 19 others like this.
  2. cambopad

    cambopad Active Member Licensed User

    Really cool! I will try it!
     
    ArminKH likes this.
  3. Theera

    Theera Well-Known Member Licensed User

    Is there strategy of colorful text each letter?
     
    ArminKH likes this.
  4. ArminKH

    ArminKH Well-Known Member

    NOT directly
    You can split your string with space then return start word index and end word index then use richstring for each letter
     
    omidaghakhani1368 likes this.
  5. MhdBoy

    MhdBoy Member Licensed User

    very useful
    please insert strong method
     
    ArminKH likes this.
  6. cd37ycs

    cd37ycs Member Licensed User

    Really cool!
     
    ArminKH likes this.
  7. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    Woooow it's wonderful
     
    ArminKH likes this.
  8. elrinconin

    elrinconin Member Licensed User

    Wooow , it`s very good code.
     
    ArminKH likes this.
  9. ArminKH

    ArminKH Well-Known Member

    this lib has a bug On b4a 4.3
    Please download updated version friday
     
    elrinconin likes this.
  10. ArminKH

    ArminKH Well-Known Member

    Library Updated to version 1.20
    Fixed an issue with b4a 4.30
     
    cimperia and elrinconin like this.
  11. R Rioja

    R Rioja Member Licensed 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.
     
  12. ArminKH

    ArminKH Well-Known Member

    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
     
  13. R Rioja

    R Rioja Member Licensed User

    Thank you
     
    ArminKH likes this.
  14. JakeBullet70

    JakeBullet70 Well-Known Member Licensed User

    Great lib!!!!
     
    ArminKH likes this.
  15. R Rioja

    R Rioja Member Licensed 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
    robrioja@gmail.com
     

    Attached Files:

    ArminKH likes this.
  16. ArminKH

    ArminKH Well-Known Member

    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
     
  17. ArminKH

    ArminKH Well-Known Member

    If any body need some posiiblities can write there
     
  18. JakeBullet70

    JakeBullet70 Well-Known Member Licensed User

    arminkh, you made a really good lib!!!
     
    ArminKH likes this.
  19. R Rioja

    R Rioja Member Licensed User

    ArminKH, I did not mean that corrections should be made to the library. I meant corrections to my doc.
    Robert
     
    ArminKH likes this.
  20. incendio

    incendio Well-Known Member Licensed 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
    Code:
    MyClass.Initialize(Me,myPanel,"event_name")
    SingleLine2 need an activity but there is no activity in MyClass. Is there a solution for this?
     
    ArminKH likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice