abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2/KeyValue.java
blob: 9c25673bf3e2005d510b376c9898d0ebfdc65793 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package juloo.keyboard2;

import android.view.KeyEvent;
import java.util.HashMap;

class KeyValue
{
	public static final int	EVENT_NONE = -1;
	public static final int	EVENT_BACKSPACE = -2;
	public static final int	EVENT_DELETE = -3;

	public static final int FLAG_KEEP_ON = 1;
	public static final int FLAG_LOCK = (1 << 1);
	public static final int FLAG_CTRL = (1 << 2);
	public static final int FLAG_SHIFT = (1 << 3);
	public static final int FLAG_ALT = (1 << 4);
	public static final int FLAG_NOCHAR = (1 << 5);
	public static final int FLAG_LOCKED = (1 << 8);

	private String		_name;
	private String		_symbol;
	private char		_char;
	private int			_eventCode;
	private int			_flags;

	public String		getName()
	{
		return (_name);
	}

	public String		getSymbol(boolean upperCase)
	{
		if (upperCase)
			return (_symbol.toUpperCase());
		return (_symbol);
	}

	public char			getChar(boolean upperCase)
	{
		if (upperCase)
			return (Character.toUpperCase(_char));
		return (_char);
	}

	public int			getEventCode()
	{
		return (_eventCode);
	}

	public int			getFlags()
	{
		return (_flags);
	}

	private static HashMap<String, KeyValue> keys = new HashMap<String, KeyValue>();

	private KeyValue(String name)
	{
		this(name, name, name.charAt(0), EVENT_NONE, 0);
	}

	private KeyValue(String name, String symbol, char c)
	{
		this(name, symbol, c, EVENT_NONE, 0);
	}

	private KeyValue(String name, String symbol, int eventCode)
	{
		this(name, symbol, '\0', eventCode, 0);
	}

	private KeyValue(String name, String symbol, char c, int eventCode, int flags)
	{
		_name = name;
		_symbol = symbol;
		_char = c;
		_eventCode = eventCode;
		_flags = flags;
		KeyValue.keys.put(name, this);
	}

	public static KeyValue	getKeyByName(String name)
	{
		return (KeyValue.keys.get(name));
	}

	static
	{
		String chars = "abcdefghijklmnopqrstuvwxyz"
			+ "àçéèêë"
			+ "0123456789<>"
			+ "&é\"'(-_)=°+"
			+ "~#{[|`\\^@]}"
			+ "^$ù*,;:!¨£%µ?./§";
		for (int i = 0; i < chars.length(); i++)
			new KeyValue(chars.substring(i, i + 1));

		new KeyValue("shift", "⇧", 'S', EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_LOCK | FLAG_SHIFT);
		new KeyValue("ctrl", "Ctrl", 'C', EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_CTRL);
		new KeyValue("alt", "Alt", 'A', EVENT_NONE, FLAG_KEEP_ON | FLAG_NOCHAR | FLAG_ALT);

		new KeyValue("backspace", "⌫", EVENT_BACKSPACE);
		new KeyValue("delete", "⌦", EVENT_DELETE);

		new KeyValue("enter", "↵", KeyEvent.KEYCODE_ENTER);
		new KeyValue("up", "↑", KeyEvent.KEYCODE_DPAD_UP);
		new KeyValue("right", "→", KeyEvent.KEYCODE_DPAD_RIGHT);
		new KeyValue("down", "↓", KeyEvent.KEYCODE_DPAD_DOWN);
		new KeyValue("left", "←", KeyEvent.KEYCODE_DPAD_LEFT);
		new KeyValue("page_up", "⇞", KeyEvent.KEYCODE_PAGE_DOWN);
		new KeyValue("page_down", "⇟", KeyEvent.KEYCODE_PAGE_UP);
		new KeyValue("home", "↖", KeyEvent.KEYCODE_HOME);
		new KeyValue("end", "↗", KeyEvent.KEYCODE_MOVE_END);

		new KeyValue("tab", "↹", '\t');
		new KeyValue("space", " ", ' ');
	}
}