blob: 549f88dec831ad7b3793ebc2655c95e7383fdc43 (
plain)
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
|
package juloo.keyboard2;
import android.content.res.Resources;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class Emoji
{
private final KeyValue _kv;
protected Emoji(String bytecode)
{
this._kv = new KeyValue(bytecode, KeyValue.Kind.String, 0, 0);
}
public KeyValue kv()
{
return _kv;
}
private final static List<Emoji> _all = new ArrayList<>();
private final static List<List<Emoji>> _groups = new ArrayList<>();
private final static HashMap<String, Emoji> _stringMap = new HashMap<>();
public static void init(Resources res)
{
if (!_all.isEmpty())
return;
try
{
InputStream inputStream = res.openRawResource(R.raw.emojis);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
// Read emoji (until empty line)
while (!(line = reader.readLine()).isEmpty())
{
Emoji e = new Emoji(line);
_all.add(e);
_stringMap.put(line, e);
}
// Read group indices
if ((line = reader.readLine()) != null)
{
String[] tokens = line.split(" ");
int last = 0;
for (int i = 1; i < tokens.length; i++)
{
int next = Integer.parseInt(tokens[i]);
_groups.add(_all.subList(last, next));
last = next;
}
_groups.add(_all.subList(last, _all.size()));
}
}
catch (IOException e) { Logs.exn("Emoji.init() failed", e); }
}
public static int getNumGroups()
{
return _groups.size();
}
public static List<Emoji> getEmojisByGroup(int groupIndex)
{
return _groups.get(groupIndex);
}
public static Emoji getEmojiByString(String value)
{
return _stringMap.get(value);
}
}
|