2015-10-23 14:22:43 +02:00
|
|
|
package juloo.keyboard2;
|
|
|
|
|
2021-01-16 21:57:51 +01:00
|
|
|
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;
|
2015-10-23 14:22:43 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
2022-06-05 20:14:16 +02:00
|
|
|
public class Emoji
|
2015-10-23 14:22:43 +02:00
|
|
|
{
|
2022-06-06 00:23:45 +02:00
|
|
|
private final String _name;
|
2022-06-05 20:14:16 +02:00
|
|
|
private final KeyValue _kv;
|
2021-12-19 19:44:27 +01:00
|
|
|
private final String _desc;
|
2015-10-23 14:22:43 +02:00
|
|
|
|
2021-05-09 12:14:56 +02:00
|
|
|
private static HashMap<String, Emoji> emojis_by_name = new HashMap<String, Emoji>();
|
|
|
|
|
2021-12-19 19:44:27 +01:00
|
|
|
protected Emoji(String name, String bytecode, String desc)
|
|
|
|
{
|
2022-06-06 00:23:45 +02:00
|
|
|
_name = name;
|
|
|
|
_kv = new KeyValue(bytecode, KeyValue.KIND_STRING, 0, 0);
|
2021-12-19 19:44:27 +01:00
|
|
|
_desc = desc;
|
2021-05-09 12:14:56 +02:00
|
|
|
emojis_by_name.put(name, this);
|
2021-12-19 19:44:27 +01:00
|
|
|
}
|
2015-10-23 14:22:43 +02:00
|
|
|
|
2022-06-05 20:14:16 +02:00
|
|
|
public String name()
|
|
|
|
{
|
2022-06-06 00:23:45 +02:00
|
|
|
return _name;
|
2022-06-05 20:14:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public KeyValue kv()
|
|
|
|
{
|
|
|
|
return _kv;
|
|
|
|
}
|
|
|
|
|
2021-12-19 19:44:27 +01:00
|
|
|
public String getDescription()
|
|
|
|
{
|
|
|
|
return (_desc);
|
|
|
|
}
|
2015-10-23 14:22:43 +02:00
|
|
|
|
2021-01-16 21:57:51 +01:00
|
|
|
public static int num_groups = 0;
|
|
|
|
|
|
|
|
private static Emoji[][] emojis_by_group = new Emoji[][]{};
|
2015-10-23 14:22:43 +02:00
|
|
|
|
2021-12-19 19:44:27 +01:00
|
|
|
public static Emoji getEmojiByName(String name)
|
|
|
|
{
|
2021-05-09 12:14:56 +02:00
|
|
|
return emojis_by_name.get(name);
|
2021-12-19 19:44:27 +01:00
|
|
|
}
|
2015-10-26 20:48:07 +01:00
|
|
|
|
2021-12-19 19:44:27 +01:00
|
|
|
public static Emoji[] getEmojisByGroup(int group_id)
|
|
|
|
{
|
|
|
|
return (emojis_by_group[group_id]);
|
|
|
|
}
|
2015-10-23 14:22:43 +02:00
|
|
|
|
2021-01-16 21:57:51 +01:00
|
|
|
/* Read the list of emojis from a raw file. Will initialize only once. */
|
|
|
|
public static void init(Resources res)
|
|
|
|
{
|
|
|
|
if (num_groups > 0)
|
|
|
|
return;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ArrayList<Emoji[]> groups = new ArrayList<Emoji[]>();
|
|
|
|
InputStream inputStream = res.openRawResource(R.raw.emojis);
|
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
|
|
|
String line;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
line = reader.readLine();
|
|
|
|
if (line == null)
|
|
|
|
break;
|
|
|
|
int group_len = Integer.parseInt(line);
|
|
|
|
Emoji[] grp = new Emoji[group_len];
|
|
|
|
for (int i = 0; i < group_len; i++)
|
|
|
|
{
|
|
|
|
line = reader.readLine();
|
|
|
|
String[] f = line.split(" ", 3);
|
|
|
|
grp[i] = new Emoji(f[0], f[1], f[2]);
|
|
|
|
}
|
|
|
|
groups.add(grp);
|
|
|
|
}
|
|
|
|
num_groups = groups.size();
|
|
|
|
emojis_by_group = groups.toArray(new Emoji[0][]);
|
|
|
|
}
|
|
|
|
catch (IOException e) {}
|
|
|
|
}
|
2015-10-23 14:22:43 +02:00
|
|
|
}
|