-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmojiHandler.java
100 lines (83 loc) · 2.17 KB
/
EmojiHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package may.will.emojitextview;
import java.io.UnsupportedEncodingException;
import org.apache.commons.lang.StringEscapeUtils;
import android.util.Base64;
import android.util.Log;
/**
* Simple Library for escaping and unescaping of emoji characters
*
* @author Will5
*/
public class EmojiHandler {
public static String decodeJava(String text) {
return StringEscapeUtils.unescapeJava(text);
}
public static String encodeJava(String text) {
return StringEscapeUtils.escapeJava(text);
}
public String decodeHtml(String emoji) {
return StringEscapeUtils.unescapeHtml(emoji);
}
public String encodeHtml(String emoji) {
return StringEscapeUtils.escapeHtml(emoji);
}
public String base64Encode(String text) {
try {
byte[] data = text.getBytes("UTF-8");
return Base64.encodeToString(data, Base64.DEFAULT);
} catch (UnsupportedEncodingException e) {
return text;
}
}
public String base64Decode(String text) {
try {
byte[] data = Base64.decode(text, Base64.DEFAULT);
return new String(data, "UTF-8");
} catch (UnsupportedEncodingException e) {
return text;
}
}
public String encodeToUNICODE(String text) {
String encoding = "UNICODE";
try {
byte[] bytes = (text).getBytes();
return new String(bytes, encoding);
} catch (UnsupportedEncodingException e) {
Log.i("UE", encoding);
return text;
}
}
public String encodeToUSASCII(String text) {
String encoding = "US-ASCII";
try {
byte[] bytes = (text).getBytes();
return new String(bytes, encoding);
} catch (UnsupportedEncodingException e) {
Log.i("UE", encoding);
return text;
}
}
public String encodeToUTF8(String text) {
String encoding = "UTF-8";
try {
byte[] bytes = (text).getBytes();
return new String(bytes, encoding);
} catch (UnsupportedEncodingException e) {
Log.i("UE", encoding);
return text;
}
}
public String encodeToUTF16(String text) {
String encoding = "UTF-16";
try {
byte[] bytes = (text).getBytes();
return new String(bytes, encoding);
} catch (UnsupportedEncodingException e) {
Log.i("UE", encoding);
return text;
}
}
public static String toUnicode(char c) {
return String.format("\\u%04x", (int) c);
}
}