-
Notifications
You must be signed in to change notification settings - Fork 8
/
EmojiUtil.java
executable file
·86 lines (66 loc) · 1.78 KB
/
EmojiUtil.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
import java.nio.CharBuffer;
import java.util.HashMap;
import java.util.Locale;
import java.util.regex.Pattern;
import android.annotation.SuppressLint;
public class EmojiUtil {
HashMap<String, String> unicode;
Pattern p;
private final int CarrierID = 0; // 0:Docomo, 1:KDDI. 2: Softbank
// Emoji data
/**
* Docomo Hex: E63E-E73D Dec: 58942-59197
*
* AU Hex: E488-EB7B Dec: 58504-60283
*
* Softbank Hex: E04A-E22A Dec: 57418-57898
*/
private EmojiUtil() {
p = Pattern.compile("[&][#][\\w]{4,}[;]");
}
private static EmojiUtil instance = null;
public static EmojiUtil getInstance() {
if (instance == null) {
instance = new EmojiUtil();
}
return instance;
}
public String DecToHexString(int dec) {
return Integer.toHexString(dec).toUpperCase(Locale.JAPANESE);
}
@SuppressLint("DefaultLocale")
public String ConvertFromBinary(String html) {
CharBuffer ss = CharBuffer.wrap(html);
StringBuffer ostr = new StringBuffer();
for (int i = 0; i < ss.length(); i++) {
if ((ss.get(i) >= 0x0020) && (ss.get(i) <= 0x007e)) {
ostr.append(ss.get(i)); // No.
} else // Yes.
{
String hex = Integer.toHexString(ss.get(i) & 0xFFFF).toLowerCase(); // Get
if (hex != "a") {
String tmp = "";
switch (CarrierID) {
case 0:
tmp = DocomoEmoji.unicode.get(hex);
break;
case 1:
tmp = KddiEmoji.unicode.get(DecToHexString(Integer.parseInt(hex)));
break;
case 2:
tmp = SoftbankEmoji.unicode.get(DecToHexString(Integer.parseInt(hex)));
break;
default:
break;
}
if (tmp != null) {
ostr.append(tmp);
} else {
ostr.append(ss.get(i));
}
}
}
}
return (new String(ostr));
}
}