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, 0, 4, "UTF32")
End Sub
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, 0, 4, "UTF32")
End Sub
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
Can I ask how do you replace the default characters with those images?I tried naming my emojis like below.
View attachment 42177
then I tried parsing the filename to an Int (without the extension) using the sub below:
B4X: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?
This was my choice, my decision.Instead of bumping such a old thread you should have created a new thread!
This forum is not for ASP.Net questions.
Emojis are Unicode characters. You can use UTF32 to create such characters:
You need to add a reference to ByteConverter library in B4A and B4J, and iRandomAccessFile in B4i.B4X: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, 0, 4, "UTF32") End Sub
It will work in B4A, B4J and B4i:
![]()
![]()
![]()
B4J
The desktop font doesn't support emojis. So you need to include a custom font, such as: https://github.com/MorbZ/OpenSansEmoji
B4X: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, 0, 4, "UTF32") End Sub
my mistake... database show me '????' because i set this charset for the connection database.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?