Android Question is there a good solution for Display EMOJI in

Discussion in 'Android Questions' started by Ju Yang, Dec 5, 2015.

  1. Ju Yang

    Ju Yang Active Member Licensed User

    ASP.NET(Web),B4A,B4i and B4J?


    We are making a CRM with chat module using B4X, and have ASP.NET(Web),B4A,B4i and B4J platform,

    How to make a good solution for Display EMOJI in all those platforms?

    help! thank all guys very much! ~_~
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    This forum is not for ASP.Net questions.

    Emojis are Unicode characters. You can use UTF32 to create such characters:

    Code:
    Sub Activity_Create(FirstTime As Boolean)
       
    Activity.LoadLayout("1")
       EditText1.Text = UTS(
    0x1F600) &  UTS(0x1F601) &  UTS(0x1F602)
    End Sub


    Sub UTS (codepoint As Int) As String
      
    Dim bc As ByteConverter
      
    Dim b() As Byte = bc.IntsToBytes(Array As Int(codepoint))
      
    Return BytesToString(b, 04"UTF32")
    End Sub
    You need to add a reference to ByteConverter library in B4A and B4J, and iRandomAccessFile in B4i.

    It will work in B4A, B4J and B4i:
    [​IMG]
    [​IMG]
    [​IMG]


    B4J

    The desktop font doesn't support emojis. So you need to include a custom font, such as: https://github.com/MorbZ/OpenSansEmoji
    Code:
    Sub AppStart (Form1 As Form, Args() As String)
       MainForm = Form1
       MainForm.SetFormStyle(
    "UNIFIED")
       MainForm.Show
       MainForm.RootPane.LoadLayout(
    "1")
       fx.LoadFont(
    File.DirAssets, "OpenSansEmoji.ttf"32)
       Label1.Style = Label1.Style & 
    "-fx-font-family: OpenSansEmoji;"
       Label1.Text = UTS(
    0x1F600) &  UTS(0x1F601) &  UTS(0x1F602)
       TextField1.Style = TextField1.Style & 
    "-fx-font-family: OpenSansEmoji;"
       TextField1.Text = UTS(
    0x1F600) &  UTS(0x1F601) &  UTS(0x1F602)
    End Sub

    Sub UTS (codepoint As Int) As String
      
    Dim bc As ByteConverter
      
    Dim b() As Byte = bc.IntsToBytes(Array As Int(codepoint))
      
    Return BytesToString(b, 04"UTF32")
    End Sub
     
  3. KMatle

    KMatle Expert Licensed User

    Oh - this is how it works- I was wondering why UTF8 doesn't work :D
     
    DonManfred likes this.
  4. Ju Yang

    Ju Yang Active Member Licensed User

    But we need all platforms' EMOJI image is same, like iOS EMOJI. how to implement?
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    You need to find a font file that includes these images. The images are most probably copyrighted.
     
  6. Kwame Twum

    Kwame Twum Active Member Licensed User

    I tried naming my emojis like below.
    emoj.png
    then I tried parsing the filename to an Int (without the extension) using the sub below:
    Code:
    Sub emo_Click(Thumbnail As Panel)
        
    Dim coda As String = Thumbnail.Tag
        coda = c.GetFileName(coda).Replace(
    ".png","")
        coda = 
    "0x" & coda : Log(coda)            'This prints 0x1F601 to the logs for the first emoji
        Dim code As Int = Bit.ParseInt(coda,16)
        txt.Text = txt.Text & UTS(code)            
    'I get java.lang.NumberFormatException: Invalid int: "0x1F601" on this line
    End Sub
    What could I be doing wrong?
     
    Last edited: Mar 4, 2016
  7. Erel

    Erel Administrator Staff Member Licensed User

    Don't add 0x to the string. 0x is used with numeric literals.
     
    Kwame Twum likes this.
  8. LucaMs

    LucaMs Expert Licensed User

    Hi, Erel,

    the code you posted in #2 (function UTS) works as expected on my tablet (Android 4.4.2) but does not work on my smartphone (Android 4.0.4) - it shows a "space": is it due to the different Android versions?
     
  9. LucaMs

    LucaMs Expert Licensed User

    Can I ask how do you replace the default characters with those images?
     
  10. DonManfred

    DonManfred Expert Licensed User

    Instead of bumping such a old thread you should have created a new thread!
     
  11. LucaMs

    LucaMs Expert Licensed User

    This was my choice, my decision.
     
    Jmu5667 likes this.
  12. Leni Berry

    Leni Berry Active Member Licensed User

    How to convert this output
    Yes, i can display emoji icon from this UTS function into textboxt. but how to translate this emoji into string that can be save to database?
     
  13. Leni Berry

    Leni Berry Active Member Licensed User

    my mistake... database show me '????' because i set this charset for the connection database.

    mysqli_set_charset($connection,"utf8");

    just remove this charset. everything back to normal...
     
    hani bassam and Kwame Twum like 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