B4A Library LabelExtras - advanced click handling

Discussion in 'Additional libraries, classes and official updates' started by warwound, Jan 30, 2013.

  1. urikupfer

    urikupfer Member Licensed User

    Hi Martin
    Thanks for the answer , I am using the function "fromHtml(html string)" , just to convert the html string to text , something like reach text,
    but from the link you gave me I saw the answer :" This class processes HTML strings into displayable styled text. Not all HTML tags are supported."
    Uri
     
  2. android6dft

    android6dft New Member Licensed User

    Code as Sub

    Take a look at the code I mixed the latest versions of AHViewPager, Scrollview and LabelExtras but it seems a lag in parsing or displaying the page contains html codes. Add more html codes and images to it to see the amplified effect.
    Can you please check and guide in this issue? I only want the text formatting not required link/click identification. Attached the full project folder.
    Thanks.

    Full project files: https://www.dropbox.com/s/hud71asx02qcl2t/WORKING.zip
     
    Last edited: Jul 5, 2013
  3. ferya

    ferya Member Licensed User

    How to manage ClickableSpan in case of more than one label?
     
  4. warwound

    warwound Expert Licensed User

    Have you read post #35 and #37 in this thread?

    You can use the ClickableSpan Initialize2 method and listen for the Click2 event - this enables you to assign any object/value to each ClickableSpan as it's Tag.
    So assign a unique Tag to each ClickableSpan and in the Click2 event use the Tag to establish which ClickableSpan was clicked.

    Martin.
     
  5. ferya

    ferya Member Licensed User

    Thank you very much.
     
  6. ferya

    ferya Member Licensed User

    Sorry but I have another problem
    I cant use eastern language characters,I changed your text as bellow but it dos not do anything.
    Also I checked it in html method.
    Code:
    SpannableStringBuilder1.Initialize("این یک آزمایش است")' plain String."&CRLF&"It contains no HTML tags and has NOT been passed to the Html.FromHtml method."&CRLF&"A click listener will be added to the word 'plain' in the first sentence.")
        Dim ClickableSpan1 As ClickableSpan
        ClickableSpan1.Initialize(
    "ClickableSpan1"Colors.Magenta, True)
        SpannableStringBuilder1.SetSpan(ClickableSpan1, 
    814, Spanned1.SPAN_EXCLUSIVE_EXCLUSIVE)
    thank you in advance
     
  7. warwound

    warwound Expert Licensed User

    What do you mean by 'it does not do anything'?

    Do these foreign characters display on the android device but they are not clickable?
    Or do these characters simply fail to display?

    If you take a Label and set the Label text to these characters do you see them correctly displayed?

    Martin.
     
  8. ferya

    ferya Member Licensed User

    Hi,
    They displayed well but they are not clickable.
    Also the color has changed.
     
  9. warwound

    warwound Expert Licensed User

    Can you put together a small n simple test project - and upload it.
    I'll take a look and see what i establish is not working correctly.

    Martin.
     
  10. ferya

    ferya Member Licensed User

    Please see the attached.
    consider I have a commented line that started whit "A" key if you uncomment it program works.
    Code:
    's="Aکارگه <b>سلام</b> <b>خوبی</b> چه خبر "&CRLF
    but in my label whole chars must be other language.
    thank you Martin.
     

    Attached Files:

  11. warwound

    warwound Expert Licensed User

    Hmmm...

    I tried your project on my old ZTE Blade that's running CyanogenMod Gingerbread 2.3 and it worked as expected.
    I then added an asterix between the two bold spans of text and again it worked as expected, each bold span of text raising the correct ClickableSpan Click event (see attached demobold_labelextras_blade.png).
    Note that the text is correctly aligned as 'right to left' text.

    Next i tried your project on my Galaxy Tab2 running Jelly Bean 4.1.1, the text is aligned as 'left to right' text and no clicks are detected (see attached demobold_labelextras_tab2.png).

    Appending the character A to the string caused the bold spans to be clickable but they were still displayed as 'left to right' text.
    Appending a space (instead of an A) to the string caused the bold spans to be not clickable.

    I then tried surrounding your text in an HTML SPAN element:

    Code:
    s="<span>کارگه <b>سلام</b> * <b>خوبی</b> چه خبر </span>"&CRLF
    The bold spans were no longer clickable.
    Using an HTML P element was the same - the bold spans were not clickable.

    I tried adding a new method to the Html object:

    Code:
    /**
        * Returns displayable styled text from the provided HTML 
    string specifying the character encoding of the string.
        */
       
    public static CharSequence FromHtml3(String HtmlString, String Encoding) throws UnsupportedEncodingException {
         
    return android.text.Html.fromHtml(new String(HtmlString.getBytes(), Encoding));
       
    }
    And updating the b4a code to use this new method:

    Code:
    Dim s As String
       s=
    "کارگه <b>سلام</b> * <b>خوبی</b> چه خبر "&CRLF

       
    '   s="Aکارگه <b>سلام</b> * <b>خوبی</b> چه خبر "&CRLF

       
    Dim HtmlString As String=s


       SpannableStringBuilder1.Initialize(Html1.FromHtml3(HtmlString, 
    "UTF-8"))
    This made no difference, the results were exactly as before.

    Finally i tried appending the character A to the string and then removing it from the SpannableStringBuilder:

    Code:
    s="Aکارگه <b>سلام</b> * <b>خوبی</b> چه خبر "&CRLF
    Dim HtmlString As String=s
    SpannableStringBuilder1.Initialize(Html1.FromHtml(HtmlString))
    SpannableStringBuilder1.Delete(
    01)
    The A is removed but now the bold spans are no longer clickable.

    So the problem is likely to be device specific and (more accurately) android version specific i think.
    It works perfectly on Gingerbread 2.3, the text is displayed as right to left text and the bold spans are clickable.
    On Jelly Bean the only way that i could make the bold spans clickable was to display a single english character (A) with the foreign text.

    I'm not sure what to suggest next :(.

    Martin.
     

    Attached Files:

  12. ferya

    ferya Member Licensed User

    Hi,
    Really hanks for your try.
    I tested on galaxytab2 and note2.
    please inform me if you could find a way.
    best regards
     
  13. ferya

    ferya Member Licensed User

    Hi Martin
    I checked program with Hebrew characters and it has same problem.
     

    Attached Files:

  14. warwound

    warwound Expert Licensed User

    Hi again.

    I just tried the Hebrew example on an unbranded 5" chinese tablet running ICS 4.0.4 and it worked.

    So i tried the previous example (demobold.zip) on the same tablet - it didn't work.

    Next i started a Froyo (2.2) emulator and would you believe BOTH example projects work perfectly.
    The text displays as left to right, not right to left so maybe not perfect - but the clickable spans do raise the click event.

    I'd guess that support for these languages is entirely dependant on the firmware of the device.
    Some firmware has support for these languages and some doesn't.
    BUT that doesn't explain how the actual text is displayed using the correct font yet the clickable spans do not raise a click event.

    Martin.
     
  15. lazreg

    lazreg Active Member Licensed User

    what's about Marquee label ?
     
    Harris likes this.
  16. warwound

    warwound Expert Licensed User

    Well there is no official list of HTML tags that are supported.

    There's an old article here that documents supported tags: http://commonsware.com/blog/Android/2010/05/26/html-tags-supported-by-textview.html
    But that's dated May 2010!.

    The general view is to look at the android source code for the HTML class - look at the version that's relevant for your application - and see if you can work out what tags are currently supported.

    Nowhere do i see marquee listed as a supported tag, you could try it and see if it works but it seems likely that it won't work.

    Martin.
     
    fredo likes this.
  17. lazreg

    lazreg Active Member Licensed User


    thanks
    yes i found a marquee label in the forum ...
    here
    http://www.basic4ppc.com/android/forum/threads/scrolling-labels.8831/#post-198540
    in two directions right to left - and left to right
    thanks to Klaus
    Right to left Marquee Label
    http://www.basic4ppc.com/android/forum/attachments/scrollinglabels-zip.20150/
     
  18. coslad

    coslad Well-Known Member Licensed User

    hi, i tried your code and it works , but i can't find a way to save the edit text with the image and read it back,i thought to usa same place holder, can you help me? many thanks

    Correct me , i can save with this code :

    Code:
    str = html1.CharSequenceFromEditTextToHtml(EditText1)
    File.WriteString(File.DirRootExternal,"html.txt",str)
    But i can't read it , plaese help me ! Thanks
     
    Last edited: Oct 4, 2014
  19. coslad

    coslad Well-Known Member Licensed User

    HI

    i solved with this code :

    Code:
    appoggio=File.ReadString(File.DirRootExternal,"html.txt")
    sp.Initialize(html1.FromHtml2(appoggio, 
    "ImageGetter""TagHandler"))
    EditText1.Text=sp
     
  20. Juan Pablo da Rocha

    Juan Pablo da Rocha Member Licensed User

    Hi! Thanks for this library, it's very useful.

    I could use some simple HTML tags and Works fine. Is it possible to use "Font size"?

    Thanks in advance
    Juan Pablo
     
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